gnutls_certificate_set_retrieve_function2 - Linux


Overview

gnutls_certificate_set_retrieve_function2 in gnutls sets a certificate retrieval function to be called to retrieve the certificate.

Syntax

gnutls_certificate_set_retrieve_function2(cert, callback)

The syntax for gnutls_certificate_set_retrieve_function2 function in gnutls for C++ is:

static void gnutls_certificate_set_retrieve_function2(gnutls_certificate_t cert, gnutls_certificate_retrieve_function_t callback)

The following code sample shows you how to use the gnutls_certificate_set_retrieve_function2 function:

void func(gnutls_certificate_t cert, gnutls_session_t session)
{
  if (!gnutls_certificate_is_x509(cert))
    return;

  gnutls_datum_t cert_pem;
  gnutls_x509_crt_get_pem2(cert->certificate,
                        GNUTLS_X509_FMT_PEM,
                        &cert_pem);
  gnutls_certificate_set_retrieve_function(cert, func);
  // Transfer ownership.
  GNUTLS_FREE(cert_pem.data);
}

Options/Flags

The following options are available:

  • cert: the certificate structure to set the callback for.
  • callback: the callback to set, taking a certificate and session as arguments.

Examples

Here is an example of using the gnutls_certificate_set_retrieve_function2 function:

gnutls_certificate_t cert;
gnutls_certificate_set_retrieve_function2(cert, retrieve_certificate_callback);

Common Issues

None.

Integration

This function can be used in conjunction with other GnuTLS functions to create a custom TLS/SSL implementation.

Related Commands

  • gnutls_certificate_set_retrieve_function
  • gnutls_x509_crt_init