Class TlsDatabase
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
TlsDatabase.TlsDatabaseImpl
,TlsFileDatabase.TlsFileDatabaseImpl
GTlsDatabase
is used to look up certificates and other information
from a certificate or key store. It is an abstract base class which
TLS library specific subtypes override.
A GTlsDatabase
may be accessed from multiple threads by the TLS backend.
All implementations are required to be fully thread-safe.
Most common client applications will not directly interact with
GTlsDatabase
. It is used internally by TlsConnection
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
TlsDatabase.Builder<B extends TlsDatabase.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
The class forGTlsDatabase
.static class
The TlsDatabaseImpl type represents a native instance of the abstract TlsDatabase class.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionTlsDatabase
(MemorySegment address) Create a TlsDatabase proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected TlsDatabase
asParent()
Returns this instance as if it were its parent type.static TlsDatabase.Builder
<? extends TlsDatabase.Builder> builder()
ATlsDatabase.Builder
object constructs aTlsDatabase
with the specified properties.createCertificateHandle
(TlsCertificate certificate) Create a handle string for the certificate.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the TlsDatabase classlookupCertificateForHandle
(String handle_, @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable Cancellable cancellable) Look up a certificate by its handle.void
lookupCertificateForHandleAsync
(String handle_, @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously look up a certificate by its handle in the database.Finish an asynchronous lookup of a certificate by its handle.lookupCertificateIssuer
(TlsCertificate certificate, @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable Cancellable cancellable) Look up the issuer ofcertificate
in the database.void
lookupCertificateIssuerAsync
(TlsCertificate certificate, @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously look up the issuer ofcertificate
in the database.Finish an asynchronous lookup issuer operation.lookupCertificatesIssuedBy
(byte[] issuerRawDn, @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable Cancellable cancellable) Look up certificates issued by this issuer in the database.void
lookupCertificatesIssuedByAsync
(byte[] issuerRawDn, @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously look up certificates issued by this issuer in the database.Finish an asynchronous lookup of certificates.verifyChain
(TlsCertificate chain, String purpose, @Nullable SocketConnectable identity, @Nullable TlsInteraction interaction, Set<TlsDatabaseVerifyFlags> flags, @Nullable Cancellable cancellable) Determines the validity of a certificate chain, outside the context of a TLS session.verifyChain
(TlsCertificate chain, String purpose, @Nullable SocketConnectable identity, @Nullable TlsInteraction interaction, TlsDatabaseVerifyFlags flags, @Nullable Cancellable cancellable) Determines the validity of a certificate chain, outside the context of a TLS session.void
verifyChainAsync
(TlsCertificate chain, String purpose, @Nullable SocketConnectable identity, @Nullable TlsInteraction interaction, Set<TlsDatabaseVerifyFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously determines the validity of a certificate chain after looking up and adding any missing certificates to the chain.void
verifyChainAsync
(TlsCertificate chain, String purpose, @Nullable SocketConnectable identity, @Nullable TlsInteraction interaction, TlsDatabaseVerifyFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously determines the validity of a certificate chain after looking up and adding any missing certificates to the chain.verifyChainFinish
(AsyncResult result) Finish an asynchronous verify chain operation.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
TlsDatabase
Create a TlsDatabase proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
createCertificateHandle
Create a handle string for the certificate. The database will only be able to create a handle for certificates that originate from the database. In cases where the database cannot create a handle for a certificate,null
will be returned.This handle should be stable across various instances of the application, and between applications. If a certificate is modified in the database, then it is not guaranteed that this handle will continue to point to it.
- Parameters:
certificate
- certificate for which to create a handle.- Returns:
- a newly allocated string containing the handle.
-
lookupCertificateForHandle
public TlsCertificate lookupCertificateForHandle(String handle_, @Nullable @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Look up a certificate by its handle.The handle should have been created by calling g_tls_database_create_certificate_handle() on a
GTlsDatabase
object of the same TLS backend. The handle is designed to remain valid across instantiations of the database.If the handle is no longer valid, or does not point to a certificate in this database, then
null
will be returned.This function can block, use g_tls_database_lookup_certificate_for_handle_async() to perform the lookup operation asynchronously.
- Parameters:
handle_
- a certificate handleinteraction
- used to interact with the user if necessaryflags
- Flags which affect the lookup.cancellable
- aGCancellable
, ornull
- Returns:
- a newly allocated
GTlsCertificate
, ornull
. Use g_object_unref() to release the certificate. - Throws:
GErrorException
- seeGError
-
lookupCertificateForHandleAsync
public void lookupCertificateForHandleAsync(String handle_, @Nullable @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously look up a certificate by its handle in the database. See g_tls_database_lookup_certificate_for_handle() for more information.- Parameters:
handle_
- a certificate handleinteraction
- used to interact with the user if necessaryflags
- Flags which affect the lookup.cancellable
- aGCancellable
, ornull
callback
- callback to call when the operation completes
-
lookupCertificateForHandleFinish
Finish an asynchronous lookup of a certificate by its handle. See g_tls_database_lookup_certificate_for_handle() for more information.If the handle is no longer valid, or does not point to a certificate in this database, then
null
will be returned.- Parameters:
result
- aGAsyncResult
.- Returns:
- a newly allocated
GTlsCertificate
object. Use g_object_unref() to release the certificate. - Throws:
GErrorException
- seeGError
-
lookupCertificateIssuer
public TlsCertificate lookupCertificateIssuer(TlsCertificate certificate, @Nullable @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Look up the issuer ofcertificate
in the database. TheGTlsCertificate
:issuer property ofcertificate
is not modified, and the two certificates are not hooked into a chain.This function can block. Use g_tls_database_lookup_certificate_issuer_async() to perform the lookup operation asynchronously.
Beware this function cannot be used to build certification paths. The issuer certificate returned by this function may not be the same as the certificate that would actually be used to construct a valid certification path during certificate verification. RFC 4158 explains why an issuer certificate cannot be naively assumed to be part of the the certification path (though GLib's TLS backends may not follow the path building strategies outlined in this RFC). Due to the complexity of certification path building, GLib does not provide any way to know which certification path will actually be used when verifying a TLS certificate. Accordingly, this function cannot be used to make security-related decisions. Only GLib itself should make security decisions about TLS certificates.
- Parameters:
certificate
- aGTlsCertificate
interaction
- used to interact with the user if necessaryflags
- flags which affect the lookup operationcancellable
- aGCancellable
, ornull
- Returns:
- a newly allocated issuer
GTlsCertificate
, ornull
. Use g_object_unref() to release the certificate. - Throws:
GErrorException
- seeGError
-
lookupCertificateIssuerAsync
public void lookupCertificateIssuerAsync(TlsCertificate certificate, @Nullable @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously look up the issuer ofcertificate
in the database. See g_tls_database_lookup_certificate_issuer() for more information.- Parameters:
certificate
- aGTlsCertificate
interaction
- used to interact with the user if necessaryflags
- flags which affect the lookup operationcancellable
- aGCancellable
, ornull
callback
- callback to call when the operation completes
-
lookupCertificateIssuerFinish
Finish an asynchronous lookup issuer operation. See g_tls_database_lookup_certificate_issuer() for more information.- Parameters:
result
- aGAsyncResult
.- Returns:
- a newly allocated issuer
GTlsCertificate
, ornull
. Use g_object_unref() to release the certificate. - Throws:
GErrorException
- seeGError
-
lookupCertificatesIssuedBy
public List<TlsCertificate> lookupCertificatesIssuedBy(byte[] issuerRawDn, @Nullable @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Look up certificates issued by this issuer in the database.This function can block, use g_tls_database_lookup_certificates_issued_by_async() to perform the lookup operation asynchronously.
- Parameters:
issuerRawDn
- aGByteArray
which holds the DER encoded issuer DN.interaction
- used to interact with the user if necessaryflags
- Flags which affect the lookup operation.cancellable
- aGCancellable
, ornull
- Returns:
- a newly allocated list of
GTlsCertificate
objects. Use g_object_unref() on each certificate, and g_list_free() on the release the list. - Throws:
GErrorException
- seeGError
-
lookupCertificatesIssuedByAsync
public void lookupCertificatesIssuedByAsync(byte[] issuerRawDn, @Nullable @Nullable TlsInteraction interaction, TlsDatabaseLookupFlags flags, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously look up certificates issued by this issuer in the database. See g_tls_database_lookup_certificates_issued_by() for more information.The database may choose to hold a reference to the issuer byte array for the duration of this asynchronous operation. The byte array should not be modified during this time.
- Parameters:
issuerRawDn
- aGByteArray
which holds the DER encoded issuer DN.interaction
- used to interact with the user if necessaryflags
- Flags which affect the lookup operation.cancellable
- aGCancellable
, ornull
callback
- callback to call when the operation completes
-
lookupCertificatesIssuedByFinish
public List<TlsCertificate> lookupCertificatesIssuedByFinish(AsyncResult result) throws GErrorException Finish an asynchronous lookup of certificates. See g_tls_database_lookup_certificates_issued_by() for more information.- Parameters:
result
- aGAsyncResult
.- Returns:
- a newly allocated list of
GTlsCertificate
objects. Use g_object_unref() on each certificate, and g_list_free() on the release the list. - Throws:
GErrorException
- seeGError
-
verifyChain
public Set<TlsCertificateFlags> verifyChain(TlsCertificate chain, String purpose, @Nullable @Nullable SocketConnectable identity, @Nullable @Nullable TlsInteraction interaction, Set<TlsDatabaseVerifyFlags> flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Determines the validity of a certificate chain, outside the context of a TLS session.chain
is a chain ofGTlsCertificate
objects each pointing to the next certificate in the chain by itsGTlsCertificate
:issuer property.purpose
describes the purpose (or usage) for which the certificate is being used. Typicallypurpose
will be set toG_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER
which means that the certificate is being used to authenticate a server (and we are acting as the client).The
identity
is used to ensure the server certificate is valid for the expected peer identity. If the identity does not match the certificate,TlsCertificateFlags.BAD_IDENTITY
will be set in the return value. Ifidentity
isnull
, that bit will never be set in the return value. The peer identity may also be used to check for pinned certificates (trust exceptions) in the database. These may override the normal verification process on a host-by-host basis.Currently there are no
flags
, andTlsDatabaseVerifyFlags.NONE
should be used.If
chain
is found to be valid, then the return value will be 0. Ifchain
is found to be invalid, then the return value will indicate at least one problem found. If the function is unable to determine whetherchain
is valid (for example, becausecancellable
is triggered before it completes) then the return value will beTlsCertificateFlags.GENERIC_ERROR
anderror
will be set accordingly.error
is not set whenchain
is successfully analyzed but found to be invalid.GLib guarantees that if certificate verification fails, at least one error will be set in the return value, 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 mask
TlsCertificateFlags.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.Prior to GLib 2.48, GLib's default TLS backend modified
chain
to represent the certification path built byGTlsDatabase
during certificate verification by adjusting theGTlsCertificate
:issuer property of each certificate inchain
. Since GLib 2.48, this no longer occurs, so you cannot rely onGTlsCertificate
:issuer to represent the actual certification path used during certificate verification.Because TLS session context is not used,
GTlsDatabase
may not perform as many checks on the certificates asGTlsConnection
would. For example, certificate constraints may not be honored, and revocation checks may not be performed. The best way to verify TLS certificates used by a TLS connection is to letGTlsConnection
handle the verification.The TLS backend may attempt to look up and add missing certificates to the chain. This may involve HTTP requests to download missing certificates.
This function can block. Use g_tls_database_verify_chain_async() to perform the verification operation asynchronously.
- Parameters:
chain
- aGTlsCertificate
chainpurpose
- the purpose that this certificate chain will be used for.identity
- the expected peer identityinteraction
- used to interact with the user if necessaryflags
- additional verify flagscancellable
- aGCancellable
, ornull
- Returns:
- the appropriate
GTlsCertificateFlags
which represents the result of verification. - Throws:
GErrorException
- seeGError
-
verifyChain
public Set<TlsCertificateFlags> verifyChain(TlsCertificate chain, String purpose, @Nullable @Nullable SocketConnectable identity, @Nullable @Nullable TlsInteraction interaction, TlsDatabaseVerifyFlags flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Determines the validity of a certificate chain, outside the context of a TLS session.chain
is a chain ofGTlsCertificate
objects each pointing to the next certificate in the chain by itsGTlsCertificate
:issuer property.purpose
describes the purpose (or usage) for which the certificate is being used. Typicallypurpose
will be set toG_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER
which means that the certificate is being used to authenticate a server (and we are acting as the client).The
identity
is used to ensure the server certificate is valid for the expected peer identity. If the identity does not match the certificate,TlsCertificateFlags.BAD_IDENTITY
will be set in the return value. Ifidentity
isnull
, that bit will never be set in the return value. The peer identity may also be used to check for pinned certificates (trust exceptions) in the database. These may override the normal verification process on a host-by-host basis.Currently there are no
flags
, andTlsDatabaseVerifyFlags.NONE
should be used.If
chain
is found to be valid, then the return value will be 0. Ifchain
is found to be invalid, then the return value will indicate at least one problem found. If the function is unable to determine whetherchain
is valid (for example, becausecancellable
is triggered before it completes) then the return value will beTlsCertificateFlags.GENERIC_ERROR
anderror
will be set accordingly.error
is not set whenchain
is successfully analyzed but found to be invalid.GLib guarantees that if certificate verification fails, at least one error will be set in the return value, 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 mask
TlsCertificateFlags.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.Prior to GLib 2.48, GLib's default TLS backend modified
chain
to represent the certification path built byGTlsDatabase
during certificate verification by adjusting theGTlsCertificate
:issuer property of each certificate inchain
. Since GLib 2.48, this no longer occurs, so you cannot rely onGTlsCertificate
:issuer to represent the actual certification path used during certificate verification.Because TLS session context is not used,
GTlsDatabase
may not perform as many checks on the certificates asGTlsConnection
would. For example, certificate constraints may not be honored, and revocation checks may not be performed. The best way to verify TLS certificates used by a TLS connection is to letGTlsConnection
handle the verification.The TLS backend may attempt to look up and add missing certificates to the chain. This may involve HTTP requests to download missing certificates.
This function can block. Use g_tls_database_verify_chain_async() to perform the verification operation asynchronously.
- Parameters:
chain
- aGTlsCertificate
chainpurpose
- the purpose that this certificate chain will be used for.identity
- the expected peer identityinteraction
- used to interact with the user if necessaryflags
- additional verify flagscancellable
- aGCancellable
, ornull
- Returns:
- the appropriate
GTlsCertificateFlags
which represents the result of verification. - Throws:
GErrorException
- seeGError
-
verifyChainAsync
public void verifyChainAsync(TlsCertificate chain, String purpose, @Nullable @Nullable SocketConnectable identity, @Nullable @Nullable TlsInteraction interaction, Set<TlsDatabaseVerifyFlags> flags, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously determines the validity of a certificate chain after looking up and adding any missing certificates to the chain. See g_tls_database_verify_chain() for more information.- Parameters:
chain
- aGTlsCertificate
chainpurpose
- the purpose that this certificate chain will be used for.identity
- the expected peer identityinteraction
- used to interact with the user if necessaryflags
- additional verify flagscancellable
- aGCancellable
, ornull
callback
- callback to call when the operation completes
-
verifyChainAsync
public void verifyChainAsync(TlsCertificate chain, String purpose, @Nullable @Nullable SocketConnectable identity, @Nullable @Nullable TlsInteraction interaction, TlsDatabaseVerifyFlags flags, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously determines the validity of a certificate chain after looking up and adding any missing certificates to the chain. See g_tls_database_verify_chain() for more information.- Parameters:
chain
- aGTlsCertificate
chainpurpose
- the purpose that this certificate chain will be used for.identity
- the expected peer identityinteraction
- used to interact with the user if necessaryflags
- additional verify flagscancellable
- aGCancellable
, ornull
callback
- callback to call when the operation completes
-
verifyChainFinish
Finish an asynchronous verify chain operation. See g_tls_database_verify_chain() for more information.If
chain
is found to be valid, then the return value will be 0. Ifchain
is found to be invalid, then the return value will indicate the problems found. If the function is unable to determine whetherchain
is valid or not (eg, becausecancellable
is triggered before it completes) then the return value will beTlsCertificateFlags.GENERIC_ERROR
anderror
will be set accordingly.error
is not set whenchain
is successfully analyzed but found to be invalid.- Parameters:
result
- aGAsyncResult
.- Returns:
- the appropriate
GTlsCertificateFlags
which represents the result of verification. - Throws:
GErrorException
- seeGError
-
builder
ATlsDatabase.Builder
object constructs aTlsDatabase
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withTlsDatabase.Builder.build()
.
-