gnutls_certificate_set_x509_trust_mem - Linux
Overview
gnutls_certificate_set_x509_trust_mem configures a GNUTLS certificate object to trust a certificate chain from a memory buffer.
Syntax
gnutls_certificate_set_x509_trust_mem(cert, data, len)
Options/Flags
| Argument | Description |
|—|—|
| cert
| The GNUTLS certificate object to configure. |
| data
| Pointer to the memory buffer containing the certificate chain. |
| len
| Length of the memory buffer. |
Examples
Example 1: Trust a certificate chain from a buffer
#include <gnutls/gnutls.h>
int main() {
gnutls_certificate_t cert;
gnutls_x509_crt_t cert_chain[] = {
// Certificate 1
// ...
// Certificate N
// ...
};
size_t cert_chain_len = sizeof(cert_chain) / sizeof(cert_chain[0]);
gnutls_certificate_allocate(&cert, GNUTLS_X509);
gnutls_certificate_set_x509_trust_mem(cert, cert_chain, cert_chain_len);
// Use the configured certificate for TLS operations.
// ...
gnutls_certificate_free(cert);
return 0;
}
Common Issues
- Incorrectly formatted certificate chain: The certificate chain in the memory buffer must be in a valid X.509 certificate chain format.
Integration
This command can be used to configure GNUTLS certificate objects for TLS connections where trust must be established based on a certificate chain in memory.
Related Commands
- gnutls_certificate_create
- gnutls_certificate_set_x509_trust_file
- gnutls_certificate_set_x509_trust_dir