Class TlsConnection.Builder<B extends TlsConnection.Builder<B>>
- Type Parameters:
B
- the type of the Builder that is returned
- All Implemented Interfaces:
BuilderInterface
- Enclosing class:
TlsConnection
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Finish building theTlsConnection
object.Emitted during the TLS handshake after the peer certificate has been received.setAdvertisedProtocols
(String[] advertisedProtocols) The list of application-layer protocols that the connection advertises that it is willing to speak.setBaseIoStream
(IOStream baseIoStream) TheGIOStream
that the connection wraps.setCertificate
(TlsCertificate certificate) The connection's certificate; see g_tls_connection_set_certificate().setDatabase
(TlsDatabase database) The certificate database to use when verifying this TLS connection.setInteraction
(TlsInteraction interaction) AGTlsInteraction
object to be used when the connection or certificate database need to interact with the user.setRehandshakeMode
(TlsRehandshakeMode rehandshakeMode) Deprecated.setRequireCloseNotify
(boolean requireCloseNotify) Whether or not proper TLS close notification is required.setUseSystemCertdb
(boolean useSystemCertdb) Deprecated.Methods inherited from class org.gnome.gobject.GObject.Builder
onNotify
Methods inherited from class io.github.jwharm.javagi.gobject.Builder
addBuilderProperty, connect, connect, connectSignals, getArena, getNames, getValues
-
Constructor Details
-
Builder
protected Builder()Default constructor for aBuilder
object.
-
-
Method Details
-
build
Finish building theTlsConnection
object. This will callGObject.withProperties(org.gnome.glib.Type, java.lang.String[], org.gnome.gobject.Value[])
to create a new GObject instance, which is then cast toTlsConnection
.- Overrides:
build
in classIOStream.Builder<B extends TlsConnection.Builder<B>>
- Returns:
- a new instance of
TlsConnection
with the properties that were set in the Builder object.
-
setAdvertisedProtocols
The list of application-layer protocols that the connection advertises that it is willing to speak. See g_tls_connection_set_advertised_protocols().- Parameters:
advertisedProtocols
- the value for theadvertised-protocols
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setBaseIoStream
TheGIOStream
that the connection wraps. The connection holds a reference to this stream, and may run operations on the stream from other threads throughout its lifetime. Consequently, after theGIOStream
has been constructed, application code may only run its own operations on this stream when noGIOStream
operations are running.- Parameters:
baseIoStream
- the value for thebase-io-stream
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setCertificate
The connection's certificate; see g_tls_connection_set_certificate().- Parameters:
certificate
- the value for thecertificate
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setDatabase
The certificate database to use when verifying this TLS connection. If no certificate database is set, then the default database will be used. See g_tls_backend_get_default_database().When using a non-default database,
GTlsConnection
must fall back to using theGTlsDatabase
to perform certificate verification using g_tls_database_verify_chain(), which means certificate verification will not be able to make use of TLS session context. This may be less secure. For example, if you create your ownGTlsDatabase
that just wraps the defaultGTlsDatabase
, you might expect that you have not changed anything, but this is not true because you may have altered the behavior ofGTlsConnection
by causing it to use g_tls_database_verify_chain(). See the documentation of g_tls_database_verify_chain() for more details on specific security checks that may not be performed. Accordingly, setting a non-default database is discouraged except for specialty applications with unusual security requirements.- Parameters:
database
- the value for thedatabase
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setInteraction
AGTlsInteraction
object to be used when the connection or certificate database need to interact with the user. This will be used to prompt the user for passwords where necessary.- Parameters:
interaction
- the value for theinteraction
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setRehandshakeMode
Deprecated.The rehandshaking mode. See g_tls_connection_set_rehandshake_mode().- Parameters:
rehandshakeMode
- the value for therehandshake-mode
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setRequireCloseNotify
Whether or not proper TLS close notification is required. See g_tls_connection_set_require_close_notify().- Parameters:
requireCloseNotify
- the value for therequire-close-notify
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
setUseSystemCertdb
Deprecated.Whether or not the system certificate database will be used to verify peer certificates. See g_tls_connection_set_use_system_certdb().- Parameters:
useSystemCertdb
- the value for theuse-system-certdb
property- Returns:
- the
Builder
instance is returned, to allow method chaining
-
onAcceptCertificate
Emitted during the TLS handshake after the peer certificate has been received. You can examinepeerCert
's certification path by calling g_tls_certificate_get_issuer() on it.For a client-side connection,
peerCert
is the server's certificate, and the signal will only be emitted if the certificate was not acceptable according toconn
'sGTlsClientConnection
:validation_flags. If you would like the certificate to be accepted despiteerrors
, returntrue
from the signal handler. Otherwise, if no handler accepts the certificate, the handshake will fail withTlsError.BAD_CERTIFICATE
.GLib guarantees that if certificate verification fails, this signal will be emitted with at least one error will be set in
errors
, but it does not guarantee that all possible errors will be set. Accordingly, you may not safely decide to ignore any particular type of error. For example, it would be incorrect to ignoreTlsCertificateFlags.EXPIRED
if you want to allow expired certificates, because this could potentially be the only error flag set even if other problems exist with the certificate.For a server-side connection,
peerCert
is the certificate presented by the client, if this was requested via the server'sGTlsServerConnection
:authentication_mode. On the server side, the signal is always emitted when the client presents a certificate, and the certificate will only be accepted if a handler returnstrue
.Note that if this signal is emitted as part of asynchronous I/O in the main thread, then you should not attempt to interact with the user before returning from the signal handler. If you want to let the user decide whether or not to accept the certificate, you would have to return
false
from the signal handler on the first attempt, and then after the connection attempt returns aTlsError.BAD_CERTIFICATE
, you can interact with the user, and if the user decides to accept the certificate, remember that fact, create a new connection, and returntrue
from the signal handler the next time.If you are doing I/O in another thread, you do not need to worry about this, and can simply block in the signal handler until the UI thread returns an answer.
- Parameters:
handler
- the signal handler- Returns:
- the
Builder
instance is returned, to allow method chaining - See Also:
-