gnutls_certifi..._x509_key_file2(3)

✨ gnutls_certifi..._x509_key_file2(3) ✨

okay bestie, gather round πŸ’– this one lives in the gnutls manual, and it's literally the glow-up version of loading your cert + key combo. let's get into it 🫢


🌸 NAME 🌸

gnutls_certificate_set_x509_key_file2 β€” it's an API function, bestie, and it's giving "load my certificate and my private key, pls and thank u" πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <gnutls/gnutls.h>

int
gnutls_certificate_set_x509_key_file2(gnutls_certificate_credentials_t
res, const char * certfile, const char * keyfile, gnutls_x509_crt_fmt_t
type, const char * pass, unsigned int flags);

πŸ¦‹ ARGUMENTS πŸ¦‹

  • gnutls_certificate_credentials_t res β€” it's a gnutls_certificate_credentials_t type, that's the whole vibe ✨
  • const char * certfile β€” a file holding the certificate list (path) for the private key you're pairing it with, either in PKCS7 format or just a list of certificates πŸ“œ
  • const char * keyfile β€” a file with the private key inside 🀫
  • gnutls_x509_crt_fmt_t type β€” it's PEM or DER, pick your fighter πŸ’…
  • const char * pass β€” the password of the key πŸ”‘
  • unsigned int flags β€” an ORed sequence of gnutls_pkcs_encrypt_flags_t 🚩

πŸ‘‘ DESCRIPTION πŸ‘‘

So this function sets a certificate/private key pair inside the gnutls_certificate_credentials_t type. Iconic. And no cap, you can call it more than once β€” that's for when a server has multiple keys/certificates and it's serving looks πŸ’…

For clients that need to send more than just their own end entity certificate β€” like, say, also an intermediate CA cert β€” then the certfile must contain the ordered certificate chain. ordered, bestie, don't be chaotic 🌈

Also, heads up: the names in the certificate you provide will be considered when it's picking the right certificate to use, in case you've got multiple certificate/key pairs. it's a whole selection situation πŸ‘€

This function can also accept URLs at keyfile and certfile. In that case it'll use the private key and certificate that the URLs point to. The supported URLs are the ones indicated by gnutls_url_is_supported(), iykyk. And here's the tea: before GnuTLS 3.4.0, when a URL was specified, the pass part was ignored and a PIN callback had to be registered β€” but that is no longer the case in current releases. glow-up confirmed πŸ’–

In case the certfile is provided as a PKCS 11 URL, then the certificate and its present issuers in the token get imported, which means it's forming the required trust chain πŸ”—

⚠️ okay this part is important: if that function fails to load, the res structure is at an undefined state, and it must not be reused to load other keys or certificates. dead it. do not recycle. πŸ’€

And another thing β€” by default this function 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 index behavior fr fr πŸ‘‘


⭐ RETURNS ⭐

On success this function returns zero, and otherwise a negative value on error β€” see above for how to modify that behavior πŸ’–


πŸ› REPORTING BUGS πŸ›

Found a bug? Report it 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. (respect the notice bestie, it's the rules 🫢)


🌈 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 came out of gnutls version 3.8.13, and the page name is that iconic gnutls_certifi..._x509_key_file2(3) title you saw at the top. mwah, go forth and load your keypairs responsibly πŸŽ€βœ¨

πŸ“¦ where this page comes from