PKCS8_PKEY_SET0(3)

πŸ“¦ version 4.1.0, in opensuse-leap 16.0

✨ PKCS8_PKEY_SET0(3) ✨

okay so bestie, welcome to the PKCS8_PKEY_SET0(3) manpage from the Library Functions Manual πŸ’– this one is all about changing and inspecting PKCS#8 PrivateKeyInfo objects, and ngl it's lowkey iconic. no cap, it's giving crypto realness. let's get into it before I start crying tears of joy 😭✨


🌸 NAME 🌸

these four functions β€” PKCS8_pkey_set0, PKCS8_pkey_get0, PKCS8_pkey_add1_attr_by_NID, and PKCS8_pkey_get0_attrs β€” are here to change and inspect PKCS#8 PrivateKeyInfo objects. periodt. πŸ’…


πŸ“š SYNOPSIS πŸ“š

#include <openssl/x509.h>

int
PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *keyinfo, ASN1_OBJECT *aobj,
    int version, int ptype, void *pval, unsigned char *data, int len);

int
PKCS8_pkey_get0(const ASN1_OBJECT **paobj, const unsigned char **pdata,
    int *plen, const X509_ALGOR **palgor,
    const PKCS8_PRIV_KEY_INFO *keyinfo);

int
PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *keyinfo, int nid,
    int type, const unsigned char *data, int len);

const STACK_OF(X509_ATTRIBUTE) *
PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *keyinfo);

πŸ’– DESCRIPTION πŸ’–

🌟 PKCS8_pkey_set0() β€” the glow-up function 🌟

okay so PKCS8_pkey_set0() initializes the keyinfo object. the algorithm gets set to aobj with the associated parameter type ptype and parameter value pval using X509_ALGOR_set0(3), replacing any previous information about the algorithm. unless data is NULL, the encoded private key is set to the len bytes starting at data using ASN1_STRING_set0(3). if data is NULL, the key data remains unchanged. if the version argument is greater than or equal to 0, it replaces any existing version; otherwise, the version remains unchanged. and if keyinfo contains any attributes, they remain unchanged.

bestie, this is the important part: PKCS8_pkey_set0() is not performing any validation on the key data. so like, it's giving trust fall. don't pass garbage unless you're ready for chaos. πŸ’€

that's the whole vibe. slay. πŸ’–

πŸ” PKCS8_pkey_get0() β€” the inspector πŸ”

PKCS8_pkey_get0() retrieves some information from the keyinfo object. internal pointers to the algorithm OID, the AlgorithmIdentifier, and the encoded private key are stored in *paobj, *palgor, and *pdata, respectively. NULL pointers can be passed for any of these three arguments if the respective information is not needed. unless pdata is NULL, *plen is set to the number of bytes in *pdata. iykyk. πŸ¦‹

πŸŽ€ PKCS8_pkey_add1_attr_by_NID() β€” the attribute adder πŸŽ€

PKCS8_pkey_add1_attr_by_NID() creates a new X.501 Attribute object using X509_ATTRIBUTE_create_by_NID(3) and appends it to the attributes of keyinfo. that's it, that's the whole vibe. πŸ’…


🫢 RETURN VALUES 🫢

  • PKCS8_pkey_set0() and PKCS8_pkey_add1_attr_by_NID() return 1 for success or 0 for failure. no in-between, bestie. πŸ’€
  • PKCS8_pkey_get0() always returns 1. iconic behavior, honestly. πŸ‘‘
  • PKCS8_pkey_get0_attrs() returns an internal pointer to the array of attributes associated with keyinfo or NULL if no attributes are set. so if you get NULL, it's not a bug, it's just no attributes. periodt. ✨

🌈 SEE ALSO 🌈

go read these when you're done, bestie β€” they're all part of the same friend group:


⭐ HISTORY ⭐

  • PKCS8_pkey_set0() and PKCS8_pkey_get0() first appeared in OpenSSL 1.0.0 and have been available since OpenBSD 4.9. vintage, but make it slay. πŸ’œ
  • PKCS8_pkey_add1_attr_by_NID() and PKCS8_pkey_get0_attrs() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.4. newer icons, same slay. 🌸

and that's the tea, bestie πŸ“ this page is from Debian, dated September 2, 2024, and it's the PKCS8_PKEY_SET0(3) manual page. now go forth and manage your PKCS#8 keys like the main character you are. slay πŸ’‹βœ¨

πŸ“¦ where this page comes from