NNG_TLS_CONFIG_CERT_KEY_FILE(3tls)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

πŸ’– NAME πŸ’–

nng_tls_config_cert_key_file β€” bestie, this loads your own cert AND your private key straight out of a file πŸŽ€


✨ SYNOPSIS ✨

#include <nng/nng.h>
#include <nng/supplemental/tls/tls.h>

int nng_tls_config_cert_key_file(nng_tls_config *cfg, const char *path,
    const char *pass);

🌸 DESCRIPTION 🌸

Okay so nng_tls_config_cert_key_file() is the glow-up function: it loads a certificate (or a whole certificate chain, she's flexible πŸ’…) plus a private key from the file you point at with path.

That file has to be both things at once β€” the PEM encoded certificate and its associated private key, all cozy in the same file (https://tools.ietf.org/html/rfc7468 if you wanna read the PEM lore, iykyk). These are what get used whenever TLS sessions are established using cfg. The file may also carry extra certificates that lead up the validation chain, and the leaf certificate has to come first πŸ‘‘. And no, you do not need to include the self-signed root β€” the peer already has to have that in order to do its own validation, so it's giving redundant. Skip it, queen.

Now the private key β€” she might be encrypted with a password, and if she is, you hand that password over in pass. If the key isn't encrypted, you pass NULL for pass. That's it, that's the whole vibe check.

On servers πŸ–₯️, you can literally call this function multiple times for the same configuration. Not a bug, it's a feature β€” it's useful for specifying different parameters to be used for different cryptographic algorithms. Slay.


πŸ’« RETURN VALUES πŸ’«

This function returns 0 on success, and non-zero otherwise. That's the whole story.


😭 ERRORS 😭

  • NNG_ENOMEM β€” insufficient memory is available. She's out of RAM, tragic.
  • NNG_EBUSY β€” the configuration cfg is already in use, and cannot be modified. Locked in, sorry bestie.
  • NNG_EINVAL β€” the contents of path are invalid.
  • NNG_ENOENT β€” the file named by path does not exist. Nowhere to be found, ghosted fr fr πŸ’€
  • NNG_EPERM β€” the file named by path cannot be opened. Permission said no πŸ™ˆ

πŸ¦‹ SEE ALSO πŸ¦‹


a lil sign-off from your fav: this was the NNG_TLS_CO...T_KEY_FILE(3tls) page from the NNG Reference Manual, dated 2026-06-30. go set up some TLS and be iconic about it ✨🫢

πŸ“¦ where this page comes from