PKCS8_PKEY_SET0(3)
β¨ 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()andPKCS8_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 withkeyinfoorNULLif no attributes are set. so if you getNULL, 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:
ASN1_STRING_set0(3)EVP_PKCS82PKEY(3)OBJ_nid2obj(3)PKCS8_PRIV_KEY_INFO_new(3)STACK_OF(3)X509_ALGOR_new(3)X509_ATTRIBUTE_create_by_NID(3)X509_ATTRIBUTE_new(3)
β HISTORY β
PKCS8_pkey_set0()andPKCS8_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()andPKCS8_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
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms