gnutls_certificate_set_x509_key - Linux


Overview

gnutls_certificate_set_x509_key associates an X.509 key to a GnuTLS certificate handle. This operation is used in conjunction with gnutls_certificate_set_x509 to set up the certificate and key pair for a given operation.

Syntax

gnutls_certificate_set_x509_key(cert, x509_key)

Parameters

  • cert: Certificate handle, returned by gnutls_certificate_allocate().
  • x509_key: X.509 key handle, returned by gnutls_x509_crl_allocate() or gnutls_x509_privkey_import().

Options/Flags

None.

Examples

Associate a certificate and a private key:

#include <gnutls/gnutls.h>

int main() {
  gnutls_certificate_t cert;
  gnutls_x509_privkey_t x509_key;

  gnutls_certificate_allocate(&cert, GNUTLS_CERT_X509);
  gnutls_x509_privkey_import("cert.pem", GNUTLS_X509_FMT_PEM, NULL, &x509_key);
  gnutls_certificate_set_x509(cert, "cert.pem", GNUTLS_X509_FMT_PEM);
  gnutls_certificate_set_x509_key(cert, x509_key);

  // ...

  return 0;
}

Common Issues

  • Ensure that the certificate and key match and are valid.
  • The key must be compatible with the certificate.

Integration

Can be used with other GnuTLS functions to set up SSL/TLS connections.

Related Commands

  • gnutls_certificate_allocate()
  • gnutls_x509_crl_allocate()
  • gnutls_x509_privkey_import()