gnutls_certifi..._rawpk_key_file(3)

πŸ’– gnutls_certificate_set_rawpk_key_file β€” the manual page, but make it make sense πŸ’–

okay bestie, sit down, hydrate, because we're reading a gnutls man page together and honestly? it's giving "raw public keys have no certificate to hide behind" and we're gonna slay it. this is page gnutls_certificate_set_rawpk_key_file(3) from the gnutls manual, and it is lowkey iconic. πŸŽ€


✨ NAME ✨

gnutls_certificate_set_rawpk_key_file β€” API function. that's it, that's the name, she's a function and she's an API one, periodt. πŸ’…


🌸 SYNOPSIS 🌸

here's the summoning circle, copy it exactly, no typos, i'm watching:

#include <gnutls/gnutls.h>

int
gnutls_certificate_set_rawpk_key_file(gnutls_certificate_credentials_t
cred, const char * rawpkfile, const char * privkeyfile,
gnutls_x509_crt_fmt_t format, const char * pass, unsigned int key_usage,
const char ** names, unsigned int names_length, unsigned int
privkey_flags, unsigned int pkcs11_flags);

πŸ¦‹ ARGUMENTS πŸ¦‹

the whole cast, in order, no one gets cut from the group chat:

  • gnutls_certificate_credentials_t cred β€” this is a gnutls_certificate_credentials_t type. it's the lil container everything gets stuffed into.
  • const char * rawpkfile β€” holds a raw public key, in PKIX.SubjectPublicKeyInfo format. raw. unhinged. no certificate wrapper. we love her.
  • const char * privkeyfile β€” a file path pointing at a private key. yes, a path, not the key itself.
  • gnutls_x509_crt_fmt_t format β€” the encoding of the keys. DER or PEM, pick one, choose your fighter.
  • const char * pass β€” an optional password to unlock the private key privkeyfile. optional!! don't come for me if you leave it out.
  • unsigned int key_usage β€” an ORed sequence of GNUTLS_KEY_* flags. ORed, bestie, bitwise, you know the vibe.
  • const char ** names β€” an array of DNS names belonging to the public-key. it's NULL if there are none.
  • unsigned int names_length β€” holds the length of the names list. gotta say how many, she doesn't count for you.
  • unsigned int privkey_flags β€” an ORed sequence of gnutls_pkcs_encrypt_flags_t. these apply to the private key pkey.
  • unsigned int pkcs11_flags β€” one of gnutls_pkcs11_obj_flags. these apply to URLs.

πŸ’œ DESCRIPTION πŸ’œ

so what does this function do? she sets a public/private keypair, read from a file, into the gnutls_certificate_credentials_t type, so it can be used for authentication and/or encryption. main character energy tbh.

⚠️ spki and privkey should match. if they don't, set signatures cannot be validated, and this function returns GNUTLS_E_CERTIFICATE_KEY_MISMATCH. no cap. mismatched keys are a crime scene.

this function should be called once for the client, because there is currently no mechanism to determine which raw public-key to select for the peer when there are multiple present. so like. one and done, babe. multiple raw public keys for the server can be distinguished by setting the names. πŸ‘‘

note here that spki is a raw public-key as defined in RFC7250. meaning: there is no surrounding certificate that holds the public key, and there is therefore no direct mechanism to prove the authenticity of this key. the keypair can be used during a TLS handshake, but its authenticity should be established via a different mechanism (e.g. TOFU or known fingerprint). that's a big deal, so let's say it louder for the people in the back β€” no cert around it, no built-in proof. 🫢

the supported formats are basic unencrypted key, PKCS8, PKCS12, and the openssl format β€” and they will be autodetected. she just knows. ✨

if the raw public-key and the private key are given in PEM encoding, then the strings that hold their values must be null terminated. do not forget the null terminator, i am begging you. 😭

key usage (as defined by X.509 extension (2.5.29.15)) can be explicitly set, because there is no certificate structure around the key to define this value. see for more info gnutls_x509_crt_get_key_usage().

note that this function by default returns zero on success and a negative value on error. 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 in other functions to refer to the added key-pair. a lil receipt, if you will. 🧾


🌈 RETURNS 🌈

  • on success, GNUTLS_E_SUCCESS (0) is returned. slay.
  • in case the key pair does not match, GNUTLS_E_CERTIFICATE_KEY_MISMATCH is returned. πŸ’€
  • in other erroneous cases, a different negative error code is returned.

⭐ SINCE ⭐

3.6.6 β€” she's been around, she's not new here, respect the elders.


πŸ™ˆ REPORTING BUGS πŸ™ˆ

found a bug? do not suffer in silence, bestie:


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. so like, go off, but keep the receipts. πŸ’…


πŸ“ 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!! go forth and set your raw public key files responsibly πŸ¦‹πŸ’–βœ¨ β€” from the gnutls 3.8.13 manual, with love, mwah πŸŽ€

πŸ“¦ where this page comes from