## GTlsDatabase

GTlsDatabase — TLS database type

## Functions

GTlsCertificateFlags | g_tls_database_verify_chain ()
void | g_tls_database_verify_chain_async ()
GTlsCertificateFlags | g_tls_database_verify_chain_finish ()
GTlsCertificate * | g_tls_database_lookup_certificate_issuer ()
void | g_tls_database_lookup_certificate_issuer_async ()
GTlsCertificate * | g_tls_database_lookup_certificate_issuer_finish ()
GList * | g_tls_database_lookup_certificates_issued_by ()
void | g_tls_database_lookup_certificates_issued_by_async ()
GList * | g_tls_database_lookup_certificates_issued_by_finish ()
gchar * | g_tls_database_create_certificate_handle ()
GTlsCertificate * | g_tls_database_lookup_certificate_for_handle ()
void | g_tls_database_lookup_certificate_for_handle_async ()
GTlsCertificate * | g_tls_database_lookup_certificate_for_handle_finish ()

## Types and Values

| GTlsDatabase
struct | GTlsDatabaseClass
enum | GTlsDatabaseVerifyFlags
#define | G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER
#define | G_TLS_DATABASE_PURPOSE_AUTHENTICATE_CLIENT
enum | GTlsDatabaseLookupFlags

## Object Hierarchy

        GEnum
        ╰── GTlsDatabaseLookupFlags
        GFlags
        ╰── GTlsDatabaseVerifyFlags
        GObject
        ╰── GTlsDatabase

## Known Derived Interfaces

GTlsDatabase is required by GTlsFileDatabase.

## Includes

    #include <gio/gio.h>

## Description

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 GTlsConnection.

## Functions

### g_tls_database_verify_chain ()

    GTlsCertificateFlags
    g_tls_database_verify_chain (GTlsDatabase *self,
                                 GTlsCertificate *chain,
                                 const gchar *purpose,
                                 GSocketConnectable *identity,
                                 GTlsInteraction *interaction,
                                 GTlsDatabaseVerifyFlags flags,
                                 GCancellable *cancellable,
                                 GError **error);

Determines the validity of a certificate chain after looking up and adding any missing certificates to the chain.

`chain` is a chain of GTlsCertificate objects each pointing to the next certificate in the chain by its “issuer” property. The chain may initially consist of one or more certificates. After the verification process is complete, `chain` may be modified by adding missing certificates, or removing extra certificates. If a certificate anchor was found, then it is added to the `chain` .

`purpose` describes the purpose (or usage) for which the certificate is being used. Typically `purpose` will be set to G_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 check for pinned certificates (trust exceptions) in the database. These will override the normal verification process on a host by host basis.

Currently there are no `flags` , and `G_TLS_DATABASE_VERIFY_NONE` should be used.

If `chain` is found to be valid, then the return value will be 0. If `chain` is found to be invalid, then the return value will indicate the problems found. If the function is unable to determine whether `chain` is valid or not (eg, because `cancellable` is triggered before it completes) then the return value will be `G_TLS_CERTIFICATE_GENERIC_ERROR` and `error` will be set accordingly. `error` is not set when `chain` is successfully analyzed but found to be invalid.

This function can block, use `g_tls_database_verify_chain_async()` to perform the verification operation asynchronously.

#### Parameters

self | a GTlsDatabase |
chain | a GTlsCertificate chain |
purpose | the purpose that this certificate chain will be used for. |
identity | the expected peer identity. | [nullable]
interaction | used to interact with the user if necessary. | [nullable]
flags | additional verify flags |
cancellable | a GCancellable, or `NULL`. | [nullable]
error | a GError, or `NULL`. | [nullable]

#### Returns

the appropriate GTlsCertificateFlags which represents the result of verification.

Since: 2.30

### g_tls_database_verify_chain_async ()

    void
    g_tls_database_verify_chain_async (GTlsDatabase *self,
                                       GTlsCertificate *chain,
                                       const gchar *purpose,
                                       GSocketConnectable *identity,
                                       GTlsInteraction *interaction,
                                       GTlsDatabaseVerifyFlags flags,
                                       GCancellable *cancellable,
                                       GAsyncReadyCallback callback,
                                       gpointer user_data);

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

self | a GTlsDatabase |
chain | a GTlsCertificate chain |
purpose | the purpose that this certificate chain will be used for. |
identity | the expected peer identity. | [nullable]
interaction | used to interact with the user if necessary. | [nullable]
flags | additional verify flags |
cancellable | a GCancellable, or `NULL`. | [nullable]
callback | callback to call when the operation completes |
user_data | the data to pass to the callback function |

Since: 2.30

### g_tls_database_verify_chain_finish ()

    GTlsCertificateFlags
    g_tls_database_verify_chain_finish (GTlsDatabase *self,
                                        GAsyncResult *result,
                                        GError **error);

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. If `chain` is found to be invalid, then the return value will indicate the problems found. If the function is unable to determine whether `chain` is valid or not (eg, because `cancellable` is triggered before it completes) then the return value will be `G_TLS_CERTIFICATE_GENERIC_ERROR` and `error` will be set accordingly. `error` is not set when `chain` is successfully analyzed but found to be invalid.

#### Parameters

self | a GTlsDatabase |
result | a GAsyncResult. |
error | a GError pointer, or `NULL` |

#### Returns

the appropriate GTlsCertificateFlags which represents the result of verification.

Since: 2.30

### g_tls_database_lookup_certificate_issuer ()

    GTlsCertificate *
    g_tls_database_lookup_certificate_issuer
                                   (GTlsDatabase *self,
                                    GTlsCertificate *certificate,
                                    GTlsInteraction *interaction,
                                    GTlsDatabaseLookupFlags flags,
                                    GCancellable *cancellable,
                                    GError **error);

Look up the issuer of `certificate` in the database.

The “issuer” property of `certificate` 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.

#### Parameters

self | a GTlsDatabase |
certificate | a GTlsCertificate |
interaction | used to interact with the user if necessary. | [nullable]
flags | flags which affect the lookup operation |
cancellable | a GCancellable, or `NULL`. | [nullable]
error | a GError, or `NULL`. | [nullable]

#### Returns

a newly allocated issuer GTlsCertificate, or `NULL`. Use `g_object_unref()` to release the certificate.

[transfer full]

Since: 2.30

### g_tls_database_lookup_certificate_issuer_async ()

    void
    g_tls_database_lookup_certificate_issuer_async
                                   (GTlsDatabase *self,
                                    GTlsCertificate *certificate,
                                    GTlsInteraction *interaction,
                                    GTlsDatabaseLookupFlags flags,
                                    GCancellable *cancellable,
                                    GAsyncReadyCallback callback,
                                    gpointer user_data);

Asynchronously look up the issuer of `certificate` in the database. See `g_tls_database_lookup_certificate_issuer()` for more information.

#### Parameters

self | a GTlsDatabase |
certificate | a GTlsCertificate |
interaction | used to interact with the user if necessary. | [nullable]
flags | flags which affect the lookup operation |
cancellable | a GCancellable, or `NULL`. | [nullable]
callback | callback to call when the operation completes |
user_data | the data to pass to the callback function |

Since: 2.30

### g_tls_database_lookup_certificate_issuer_finish ()

    GTlsCertificate *
    g_tls_database_lookup_certificate_issuer_finish
                                   (GTlsDatabase *self,
                                    GAsyncResult *result,
                                    GError **error);

Finish an asynchronous lookup issuer operation. See `g_tls_database_lookup_certificate_issuer()` for more information.

#### Parameters

self | a GTlsDatabase |
result | a GAsyncResult. |
error | a GError pointer, or `NULL` |

#### Returns

a newly allocated issuer GTlsCertificate, or `NULL`. Use `g_object_unref()` to release the certificate.

[transfer full]

Since: 2.30

### g_tls_database_lookup_certificates_issued_by ()

    GList *
    g_tls_database_lookup_certificates_issued_by
                                   (GTlsDatabase *self,
                                    GByteArray *issuer_raw_dn,
                                    GTlsInteraction *interaction,
                                    GTlsDatabaseLookupFlags flags,
                                    GCancellable *cancellable,
                                    GError **error);

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

self | a GTlsDatabase |
issuer_raw_dn | a GByteArray which holds the DER encoded issuer DN. |
interaction | used to interact with the user if necessary. | [nullable]
flags | Flags which affect the lookup operation. |
cancellable | a GCancellable, or `NULL`. | [nullable]
error | a GError, or `NULL`. | [nullable]

#### Returns

a newly allocated list of GTlsCertificate objects. Use `g_object_unref()` on each certificate, and `g_list_free()` on the release the list.

[transfer full][element-type GTlsCertificate]

Since: 2.30

### g_tls_database_lookup_certificates_issued_by_async ()

    void
    g_tls_database_lookup_certificates_issued_by_async
                                   (GTlsDatabase *self,
                                    GByteArray *issuer_raw_dn,
                                    GTlsInteraction *interaction,
                                    GTlsDatabaseLookupFlags flags,
                                    GCancellable *cancellable,
                                    GAsyncReadyCallback callback,
                                    gpointer user_data);

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 of this asynchronous operation. The byte array should not be modified during this time.

#### Parameters

self | a GTlsDatabase |
issuer_raw_dn | a GByteArray which holds the DER encoded issuer DN. |
interaction | used to interact with the user if necessary. | [nullable]
flags | Flags which affect the lookup operation. |
cancellable | a GCancellable, or `NULL`. | [nullable]
callback | callback to call when the operation completes |
user_data | the data to pass to the callback function |

Since: 2.30

### g_tls_database_lookup_certificates_issued_by_finish ()

    GList *
    g_tls_database_lookup_certificates_issued_by_finish
                                   (GTlsDatabase *self,
                                    GAsyncResult *result,
                                    GError **error);

Finish an asynchronous lookup of certificates. See `g_tls_database_lookup_certificates_issued_by()` for more information.

#### Parameters

self | a GTlsDatabase |
result | a GAsyncResult. |
error | a GError pointer, or `NULL` |

#### Returns

a newly allocated list of GTlsCertificate objects. Use `g_object_unref()` on each certificate, and `g_list_free()` on the release the list.

[transfer full][element-type GTlsCertificate]

Since: 2.30

### g_tls_database_create_certificate_handle ()

    gchar *
    g_tls_database_create_certificate_handle
                                   (GTlsDatabase *self,
                                    GTlsCertificate *certificate);

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

self | a GTlsDatabase |
certificate | certificate for which to create a handle. |

#### Returns

a newly allocated string containing the handle.

[nullable]

Since: 2.30

### g_tls_database_lookup_certificate_for_handle ()

    GTlsCertificate *
    g_tls_database_lookup_certificate_for_handle
                                   (GTlsDatabase *self,
                                    const gchar *handle,
                                    GTlsInteraction *interaction,
                                    GTlsDatabaseLookupFlags flags,
                                    GCancellable *cancellable,
                                    GError **error);

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

self | a GTlsDatabase |
handle | a certificate handle |
interaction | used to interact with the user if necessary. | [nullable]
flags | Flags which affect the lookup. |
cancellable | a GCancellable, or `NULL`. | [nullable]
error | a GError, or `NULL`. | [nullable]

#### Returns

a newly allocated GTlsCertificate, or `NULL`. Use `g_object_unref()` to release the certificate.

[transfer full][nullable]

Since: 2.30

### g_tls_database_lookup_certificate_for_handle_async ()

    void
    g_tls_database_lookup_certificate_for_handle_async
                                   (GTlsDatabase *self,
                                    const gchar *handle,
                                    GTlsInteraction *interaction,
                                    GTlsDatabaseLookupFlags flags,
                                    GCancellable *cancellable,
                                    GAsyncReadyCallback callback,
                                    gpointer user_data);

Asynchronously look up a certificate by its handle in the database. See `g_tls_database_lookup_certificate_for_handle()` for more information.

#### Parameters

self | a GTlsDatabase |
handle | a certificate handle |
interaction | used to interact with the user if necessary. | [nullable]
flags | Flags which affect the lookup. |
cancellable | a GCancellable, or `NULL`. | [nullable]
callback | callback to call when the operation completes |
user_data | the data to pass to the callback function |

Since: 2.30

### g_tls_database_lookup_certificate_for_handle_finish ()

    GTlsCertificate *
    g_tls_database_lookup_certificate_for_handle_finish
                                   (GTlsDatabase *self,
                                    GAsyncResult *result,
                                    GError **error);

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

self | a GTlsDatabase |
result | a GAsyncResult. |
error | a GError pointer, or `NULL` |

#### Returns

a newly allocated GTlsCertificate object. Use `g_object_unref()` to release the certificate.

[transfer full]

Since: 2.30

## Types and Values

### GTlsDatabase

    typedef struct _GTlsDatabase GTlsDatabase;

Abstract base class for the backend-specific database types.

Since: 2.30

### struct GTlsDatabaseClass

    struct GTlsDatabaseClass {
      GObjectClass parent_class;

      /* virtual methods */

      GTlsCertificateFlags  (*verify_chain)                         (GTlsDatabase            *self,
                                                                     GTlsCertificate         *chain,
                                                                     const gchar             *purpose,
                                                                     GSocketConnectable      *identity,
                                                                     GTlsInteraction         *interaction,
                                                                     GTlsDatabaseVerifyFlags  flags,
                                                                     GCancellable            *cancellable,
                                                                     GError                 **error);

      void                  (*verify_chain_async)                   (GTlsDatabase            *self,
                                                                     GTlsCertificate         *chain,
                                                                     const gchar             *purpose,
                                                                     GSocketConnectable      *identity,
                                                                     GTlsInteraction         *interaction,
                                                                     GTlsDatabaseVerifyFlags  flags,
                                                                     GCancellable            *cancellable,
                                                                     GAsyncReadyCallback      callback,
                                                                     gpointer                 user_data);

      GTlsCertificateFlags  (*verify_chain_finish)                  (GTlsDatabase            *self,
                                                                     GAsyncResult            *result,
                                                                     GError                 **error);

      gchar*                (*create_certificate_handle)            (GTlsDatabase            *self,
                                                                     GTlsCertificate         *certificate);

      GTlsCertificate*      (*lookup_certificate_for_handle)        (GTlsDatabase            *self,
                                                                     const gchar             *handle,
                                                                     GTlsInteraction         *interaction,
                                                                     GTlsDatabaseLookupFlags  flags,
                                                                     GCancellable            *cancellable,
                                                                     GError                 **error);

      void                  (*lookup_certificate_for_handle_async)  (GTlsDatabase            *self,
                                                                     const gchar             *handle,
                                                                     GTlsInteraction         *interaction,
                                                                     GTlsDatabaseLookupFlags  flags,
                                                                     GCancellable            *cancellable,
                                                                     GAsyncReadyCallback      callback,
                                                                     gpointer                 user_data);

      GTlsCertificate*      (*lookup_certificate_for_handle_finish) (GTlsDatabase            *self,
                                                                     GAsyncResult            *result,
                                                                     GError                 **error);

      GTlsCertificate*      (*lookup_certificate_issuer)            (GTlsDatabase            *self,
                                                                     GTlsCertificate         *certificate,
                                                                     GTlsInteraction         *interaction,
                                                                     GTlsDatabaseLookupFlags  flags,
                                                                     GCancellable            *cancellable,
                                                                     GError                 **error);

      void                  (*lookup_certificate_issuer_async)      (GTlsDatabase            *self,
                                                                     GTlsCertificate         *certificate,
                                                                     GTlsInteraction         *interaction,
                                                                     GTlsDatabaseLookupFlags  flags,
                                                                     GCancellable            *cancellable,
                                                                     GAsyncReadyCallback      callback,
                                                                     gpointer                 user_data);

      GTlsCertificate*      (*lookup_certificate_issuer_finish)     (GTlsDatabase            *self,
                                                                     GAsyncResult            *result,
                                                                     GError                 **error);

      GList*                (*lookup_certificates_issued_by)        (GTlsDatabase            *self,
                                                                     GByteArray              *issuer_raw_dn,
                                                                     GTlsInteraction         *interaction,
                                                                     GTlsDatabaseLookupFlags  flags,
                                                                     GCancellable            *cancellable,
                                                                     GError                 **error);

      void                  (*lookup_certificates_issued_by_async)  (GTlsDatabase            *self,
                                                                     GByteArray              *issuer_raw_dn,
                                                                     GTlsInteraction         *interaction,
                                                                     GTlsDatabaseLookupFlags  flags,
                                                                     GCancellable            *cancellable,
                                                                     GAsyncReadyCallback      callback,
                                                                     gpointer                 user_data);

      GList*                (*lookup_certificates_issued_by_finish) (GTlsDatabase            *self,
                                                                     GAsyncResult            *result,
                                                                     GError                 **error);
    };

The class for GTlsDatabase. Derived classes should implement the various virtual methods. _async and _finish methods have a default implementation that runs the corresponding sync method in a thread.

#### Members

`verify_chain` () | Virtual method implementing `g_tls_database_verify_chain()`. |
`verify_chain_async` () | Virtual method implementing `g_tls_database_verify_chain_async()`. |
`verify_chain_finish` () | Virtual method implementing `g_tls_database_verify_chain_finish()`. |
`create_certificate_handle` () | Virtual method implementing `g_tls_database_create_certificate_handle()`. |
`lookup_certificate_for_handle` () | Virtual method implementing `g_tls_database_lookup_certificate_for_handle()`. |
`lookup_certificate_for_handle_async` () | Virtual method implementing `g_tls_database_lookup_certificate_for_handle_async()`. |
`lookup_certificate_for_handle_finish` () | Virtual method implementing `g_tls_database_lookup_certificate_for_handle_finish()`. |
`lookup_certificate_issuer` () | Virtual method implementing `g_tls_database_lookup_certificate_issuer()`. |
`lookup_certificate_issuer_async` () | Virtual method implementing `g_tls_database_lookup_certificate_issuer_async()`. |
`lookup_certificate_issuer_finish` () | Virtual method implementing `g_tls_database_lookup_certificate_issuer_finish()`. |
`lookup_certificates_issued_by` () | Virtual method implementing `g_tls_database_lookup_certificates_issued_by()`. |
`lookup_certificates_issued_by_async` () | Virtual method implementing `g_tls_database_lookup_certificates_issued_by_async()`. |
`lookup_certificates_issued_by_finish` () | Virtual method implementing `g_tls_database_lookup_certificates_issued_by_finish()`. |

Since: 2.30

### enum GTlsDatabaseVerifyFlags

Flags for `g_tls_database_verify_chain()`.

#### Members

G_TLS_DATABASE_VERIFY_NONE | No verification flags |

Since: 2.30

### G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER

    #define G_TLS_DATABASE_PURPOSE_AUTHENTICATE_SERVER "1.3.6.1.5.5.7.3.1"

The purpose used to verify the server certificate in a TLS connection. This is the most common purpose in use. Used by TLS clients.

### G_TLS_DATABASE_PURPOSE_AUTHENTICATE_CLIENT

    #define G_TLS_DATABASE_PURPOSE_AUTHENTICATE_CLIENT "1.3.6.1.5.5.7.3.2"

The purpose used to verify the client certificate in a TLS connection. Used by TLS servers.

### enum GTlsDatabaseLookupFlags

Flags for `g_tls_database_lookup_certificate_for_handle()`, `g_tls_database_lookup_certificate_issuer()`, and `g_tls_database_lookup_certificates_issued_by()`.

#### Members

G_TLS_DATABASE_LOOKUP_NONE | No lookup flags |
G_TLS_DATABASE_LOOKUP_KEYPAIR | Restrict lookup to certificates that have a private key. |

Since: 2.30