| Top |
| GStrv | advertised-protocols | Read / Write |
| GDatagramBased * | base-socket | Read / Write / Construct Only |
| GTlsCertificate * | certificate | Read / Write |
| GTlsDatabase * | database | Read / Write |
| GTlsInteraction * | interaction | Read / Write |
| char * | negotiated-protocol | Read |
| GTlsCertificate * | peer-certificate | Read |
| GTlsCertificateFlags | peer-certificate-errors | Read |
| GTlsRehandshakeMode | rehandshake-mode | Read / Write / Construct |
| gboolean | require-close-notify | Read / Write / Construct |
GDtlsConnection is required by GDtlsClientConnection and GDtlsServerConnection.
GDtlsConnection is the base DTLS connection class type, which wraps a GDatagramBased and provides DTLS encryption on top of it. Its subclasses, GDtlsClientConnection and GDtlsServerConnection, implement client-side and server-side DTLS, respectively.
For TLS support, see GTlsConnection.
As DTLS is datagram based, GDtlsConnection implements GDatagramBased, presenting a datagram-socket-like API for the encrypted connection. This operates over a base datagram connection, which is also a GDatagramBased (“base-socket”).
To close a DTLS connection, use g_dtls_connection_close().
Neither GDtlsServerConnection or GDtlsClientConnection set the peer address
on their base GDatagramBased if it is a GSocket — it is up to the caller to
do that if they wish. If they do not, and g_socket_close() is called on the
base socket, the GDtlsConnection will not raise a G_IO_ERROR_NOT_CONNECTED
error on further I/O.
void g_dtls_connection_set_certificate (GDtlsConnection *conn,GTlsCertificate *certificate);
This sets the certificate that conn
will present to its peer
during the TLS handshake. For a GDtlsServerConnection, it is
mandatory to set this, and that will normally be done at construct
time.
For a GDtlsClientConnection, this is optional. If a handshake fails
with G_TLS_ERROR_CERTIFICATE_REQUIRED, that means that the server
requires a certificate, and if you try connecting again, you should
call this method first. You can call
g_dtls_client_connection_get_accepted_cas() on the failed connection
to get a list of Certificate Authorities that the server will
accept certificates from.
(It is also possible that a server will allow the connection with
or without a certificate; in that case, if you don't provide a
certificate, you can tell that the server requested one by the fact
that g_dtls_client_connection_get_accepted_cas() will return
non-NULL.)
Since: 2.48
GTlsCertificate *
g_dtls_connection_get_certificate (GDtlsConnection *conn);
Gets conn
's certificate, as set by
g_dtls_connection_set_certificate().
Since: 2.48
GTlsCertificate *
g_dtls_connection_get_peer_certificate
(GDtlsConnection *conn);
Gets conn
's peer's certificate after the handshake has completed
or failed. (It is not set during the emission of
“accept-certificate”.)
Since: 2.48
GTlsCertificateFlags
g_dtls_connection_get_peer_certificate_errors
(GDtlsConnection *conn);
Gets the errors associated with validating conn
's peer's
certificate, after the handshake has completed or failed. (It is
not set during the emission of “accept-certificate”.)
Since: 2.48
gboolean g_dtls_connection_get_channel_binding_data (GDtlsConnection *conn,GTlsChannelBindingType type,GByteArray *data,GError **error);
Query the TLS backend for TLS channel binding data of type
for conn
.
This call retrieves TLS channel binding data as specified in RFC
5056, RFC
5929, and related RFCs. The
binding data is returned in data
. The data
is resized by the callee
using GByteArray buffer management and will be freed when the data
is destroyed by g_byte_array_unref(). If data
is NULL, it will only
check whether TLS backend is able to fetch the data (e.g. whether type
is supported by the TLS backend). It does not guarantee that the data
will be available though. That could happen if TLS connection does not
support type
or the binding data is not available yet due to additional
negotiation or input required.
conn |
||
type |
GTlsChannelBindingType type of data to fetch |
|
data |
GByteArray is
filled with the binding data, or |
[out callee-allocates][optional][transfer none] |
error |
a GError pointer, or |
Since: 2.66
void g_dtls_connection_set_require_close_notify (GDtlsConnection *conn,gboolean require_close_notify);
Sets whether or not conn
expects a proper TLS close notification
before the connection is closed. If this is TRUE (the default),
then conn
will expect to receive a TLS close notification from its
peer before the connection is closed, and will return a
G_TLS_ERROR_EOF error if the connection is closed without proper
notification (since this may indicate a network error, or
man-in-the-middle attack).
In some protocols, the application will know whether or not the
connection was closed cleanly based on application-level data
(because the application-level data includes a length field, or is
somehow self-delimiting); in this case, the close notify is
redundant and may be omitted. You
can use g_dtls_connection_set_require_close_notify() to tell conn
to allow an "unannounced" connection close, in which case the close
will show up as a 0-length read, as in a non-TLS
GDatagramBased, and it is up to the application to check that
the data has been fully received.
Note that this only affects the behavior when the peer closes the
connection; when the application calls g_dtls_connection_close_async() on
conn
itself, this will send a close notification regardless of the
setting of this property. If you explicitly want to do an unclean
close, you can close conn
's “base-socket” rather
than closing conn
itself.
Since: 2.48
gboolean
g_dtls_connection_get_require_close_notify
(GDtlsConnection *conn);
Tests whether or not conn
expects a proper TLS close notification
when the connection is closed. See
g_dtls_connection_set_require_close_notify() for details.
Since: 2.48
void g_dtls_connection_set_rehandshake_mode (GDtlsConnection *conn,GTlsRehandshakeMode mode);
g_dtls_connection_set_rehandshake_mode has been deprecated since version 2.60. and should not be used in newly-written code.
Changing the rehandshake mode is no longer required for compatibility. Also, rehandshaking has been removed from the TLS protocol in TLS 1.3.
Since GLib 2.64, changing the rehandshake mode is no longer supported and will have no effect. With TLS 1.3, rehandshaking has been removed from the TLS protocol, replaced by separate post-handshake authentication and rekey operations.
Since: 2.48
GTlsRehandshakeMode
g_dtls_connection_get_rehandshake_mode
(GDtlsConnection *conn);
g_dtls_connection_get_rehandshake_mode has been deprecated since version 2.64. and should not be used in newly-written code.
Changing the rehandshake mode is no longer required for compatibility. Also, rehandshaking has been removed from the TLS protocol in TLS 1.3.
Gets conn
rehandshaking mode. See
g_dtls_connection_set_rehandshake_mode() for details.
Since: 2.48
void g_dtls_connection_set_advertised_protocols (GDtlsConnection *conn,const gchar * const *protocols);
Sets the list of application-layer protocols to advertise that the
caller is willing to speak on this connection. The
Application-Layer Protocol Negotiation (ALPN) extension will be
used to negotiate a compatible protocol with the peer; use
g_dtls_connection_get_negotiated_protocol() to find the negotiated
protocol after the handshake. Specifying NULL for the the value
of protocols
will disable ALPN negotiation.
See IANA TLS ALPN Protocol IDs for a list of registered protocol IDs.
conn |
||
protocols |
a |
[array zero-terminated=1][nullable] |
Since: 2.60
const gchar *
g_dtls_connection_get_negotiated_protocol
(GDtlsConnection *conn);
Gets the name of the application-layer protocol negotiated during the handshake.
If the peer did not use the ALPN extension, or did not advertise a
protocol that matched one of conn
's protocols, or the TLS backend
does not support ALPN, then this will be NULL. See
g_dtls_connection_set_advertised_protocols().
Since: 2.60
GTlsDatabase *
g_dtls_connection_get_database (GDtlsConnection *conn);
Gets the certificate database that conn
uses to verify
peer certificates. See g_dtls_connection_set_database().
Since: 2.48
void g_dtls_connection_set_database (GDtlsConnection *conn,GTlsDatabase *database);
Sets the certificate database that is used to verify peer certificates.
This is set to the default database by default. See
g_tls_backend_get_