gnutls_certifi...et_x509_key_mem(3)

πŸ’– NAME πŸ’–

gnutls_certificate_set_x509_key_mem β€” bestie, it's the API function that pairs your cert with your private key, straight from memory ✨

This one lives in the gnutls manual, and honestly? She's a baddie.


🌸 SYNOPSIS 🌸

#include <gnutls/gnutls.h>

int gnutls_certificate_set_x509_key_mem(gnutls_certificate_credentials_t
res, const gnutls_datum_t * cert, const gnutls_datum_t * key,
gnutls_x509_crt_fmt_t type);

πŸŽ€ ARGUMENTS πŸŽ€

  • gnutls_certificate_credentials_t res β€” okay so this is a gnutls_certificate_credentials_t type. That's the whole vibe. She's the credentials girlie you're loading stuff into πŸ’…
  • const gnutls_datum_t * cert β€” this holds a certificate list (path) for the specified private key. Not just one cert, bestie, a whole list, iykyk πŸ¦‹
  • const gnutls_datum_t * key β€” this is the private key, or NULL. Yes, NULL is allowed, stay with me πŸ”₯
  • gnutls_x509_crt_fmt_t type β€” this is PEM or DER. That's it. Pick your fighter πŸ’€

✨ DESCRIPTION ✨

So what does this do? It sets a certificate/private key pair inside the gnutls_certificate_credentials_t type. Iconic behaviour, honestly.

And here's the cute part: this function may be called more than once, in case multiple keys/certificates exist for the server. She's not a one-and-done girlie, she's flexible 🫢

Heads up though β€” note that the keyUsage (2.5.29.15) PKIX extension in X.509 certificates is supported. Which means certificates intended for signing cannot be used for ciphersuites that require encryption. So don't try it. The extension said no and she meant it 😭

Another thing, and this one matters: if the certificate and the private key are given in PEM encoding, then the strings that hold their values must be null terminated. Null terminate them. Please. For me. πŸŽ€

The key may be NULL if you are using a sign callback β€” see gnutls_sign_callback_set() for that whole situation 🌈

And now the plot twist: this function by default returns zero on success and a negative value on error. But β€” since 3.5.6, when the flag GNUTLS_CERTIFICATE_API_V2 is set using gnutls_certificate_set_flags(), it returns an index (greater or equal to zero). That index can be used by other functions to refer to the added key-pair. Main character behaviour tbh πŸ‘‘


πŸ’œ RETURNS πŸ’œ

On success this function returns zero, and otherwise a negative value on error (see above for modifying that behavior). Lowkey simple, highkey important πŸ’–


πŸ™ˆ REPORTING BUGS πŸ™ˆ

Found a bug? Tell the girlies.

Report bugs to <bugs@gnutls.org>.

Home page: https://www.gnutls.org


Copyright Β© 2001-2023 Free Software Foundation, Inc., and others.

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. Slay, and also legally binding πŸŽ€


🌈 SEE ALSO 🌈

The full documentation for gnutls is maintained as a Texinfo manual. If the /usr/share/doc/gnutls/ directory does not contain the HTML form, visit:

https://www.gnutls.org/manual/

And that's the whole page, bestie 🫢 this was gnutls_certifi...et_x509_key_mem(3) from the gnutls manual, version 3.8.13 β€” go forth and null-terminate your PEM strings, no cap πŸ’…βœ¨

πŸ“¦ where this page comes from