P11SAK(1)

🌸 NAME 🌸

p11sak — manage token keys in a PKCS #11 token repository. 💖 (it's the openCryptoki girlie, hiii)


✨ SYNOPSIS ✨

p11sak command [ARGUMENTS] [OPTIONS]

p11sak --help|-h
p11sak --version|-v

🦋 DESCRIPTION 🦋

okay so bestie. The p11sak tool is literally here to manage token keys and certificates in a PKCS #11 token repository. She's a flexible key management queen and she can generate, list, remove, update, copy, import, and export symmetric keys (DES, 3DES, generic, SHA-HMAC, AES, AES-XTS) and asymmetric keys (RSA, DH, DSA, EC, EC-Edwards, EC-Montgomery, IBM Dilithium, IBM Kyber, IBM ML-DSA, IBM ML-KEM, ML-DSA, ML-KEM). no cap. 💅

She can also list the keys together with their PKCS #11 attributes and their values — but heads up, not all attributes may be displayed if a key is sensitive. 🙈 rude but valid.

She ALSO supports import, export, copy, and listing of certificates. And get this: public keys inside certificates and private keys can be extracted and added to the token repository as brand-new public key objects. iconic behavior honestly. 👑

Note: p11sak only operates on token keys (i.e. CKA_TOKEN=TRUE), and never on session keys (CKA_TOKEN=FALSE). Token keys are stored persistently in the token's repository. Session keys are not stored persistently and only exist as long as the session is alive. So like… any session keys generated or imported by the p11sak tool would not exist anymore once the p11sak tool has exited. poof. gone. 💀

🌈 COMMANDS 🌈

The p11sak tool supports various commands to generate, list, remove, update, import, and export token keys and certificates in a PKCS #11 token repository. ✨

🔑 Generating symmetric and asymmetric keys 🔑

p11sak generate-key|gen-key|gen KEYTYPE [ARGUMENTS] [OPTIONS]

Use the generate-key|gen-key|gen command to generate a token key of the specified KEYTYPE with the respective ARGUMENTS and OPTIONS. Possible values for the KEYTYPE argument are:

des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem

See below for a detailed description of the arguments and options. The --help|-h option also shows the arguments and options available. (iykyk 🫶)

🍓 Generating DES/3DES keys 🍓

p11sak generate-key|gen-key|gen des|3des --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] --label|-L LABEL --attr|-a
ATTRS [--id|-i ID] [--help|-h]

Use the generate-key|gen-key|gen command with the des|3des KEYTYPE argument to generate a DES or 3DES key (CKK_DES or CKK_DES3). The --label|-L LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS option can be used to set the boolean attributes of the key (see below for the detailed description of the attributes). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key. 🎀

🧚 Generating generic secret keys 🧚

p11sak generate-key|gen-key|gen generic KEYBITS --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL --attr|-a ATTRS [--id|-i ID] [--help|-h]

Use the generate-key|gen-key|gen generic KEYBITS command and KEYTYPE argument to generate a generic secret key (CKK_GENERIC_SECRET) with the key size in bits as specified by the KEYBITS argument. The --label|-L LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS option can be used to set the boolean attributes of the key (see below for the detailed description of the attributes). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key. 💜

🌸 Generating SHA-HMAC keys 🌸

p11sak generate-key|gen-key|gen sha-1-hmac|sha224-hmac|sha256-hmac|
sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|
sha3-256-hmac|sha3-384-hmac|sha3-512-hmac KEYBITS --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL --attr|-a ATTRS [--id|-i ID] [--help|-h]

Use the generate-key|gen-key|gen shannn-hmac KEYBITS command and KEYTYPE argument to generate a SHA-HMAC key (CKK_SHAnnn_HMAC) with the key size in bits as specified by the KEYBITS argument. The --label|-L LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS option can be used to set the boolean attributes of the key (see below for the detailed description of the attributes). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key. 🔥

⭐ Generating AES keys ⭐

p11sak generate-key|gen-key|gen aes 128|192|256 --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL --attr|-a ATTRS [--id|-i ID] [--help|-h]

Use the generate-key|gen-key|gen aes 128|192|256 command and KEYTYPE argument to generate a AES key (CKK_AES) with 128-, 192-, or 256-bit length, respectively. The --label|-L LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS option can be used to set the boolean attributes of the key (see below for the detailed description of the attributes). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key. ✨

🦋 Generating AES-XTS keys 🦋

p11sak generate-key|gen-key|gen aes-xts 128|256 --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL --attr|-a ATTRS [--id|-i ID] [--help|-h]

Use the generate-key|gen-key|gen aes-xts 128|256 command and KEYTYPE argument to generate a AES-XTS key (CKK_AES_XTS) with 128- or 256-bit length, respectively. The --label|-L LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS option can be used to set the boolean attributes of the key (see below for the detailed description of the attributes). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key. 🌈

👑 Generating RSA keys 👑

p11sak generate-key|gen-key|gen rsa KEYBITS [PUBL-EXP] --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen rsa KEYBITS command and KEYTYPE argument to generate an RSA key (CKK_RSA) with the key size in bits as specified by the KEYBITS argument. The key size must be from 512 to 16384 and a multiple of 8 bits. Typical key sizes are 512, 1024, 2048, 4096, or 8192. Not all RSA key sizes might be supported by all tokens. The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS option can be used to set the boolean attributes of the key (see below for the detailed description of the attributes). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key. Furthermore, the optional PUBL-EXP argument allows the user to specify the exponent used for generating the RSA key. The default is set to 65537 according to the PKCS #11 standard. 💅

🎀 Generating DH keys 🎀

p11sak generate-key|gen-key|gen dh GROUP|DH-PARAM-PEM-FILE [PRIV-BITS]
--slot|-s SLOTID [--pin|-p PIN] [--force-pin-prompt] [--no-login|-N]
[--so] --label|-L LABEL|PUB-LABEL:PRIV-LABEL --attr|-a
ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i ID] [--help|-h]

Use the generate-key|gen-key|gen dh GROUP|DH-PARAM-PEM-FILE command and KEYTYPE argument to generate a DH key (CKK_DH), where GROUP specifies the Diffie-Hellman FFC group name or DH-PARAM-PEM-FILE specifies the name of a DH parameters PEM file. The following arguments can be used for respective groups:

ffdhe2048|ffdhe3072|ffdhe4096|ffdhe6144|ffdhe8192|modp1536|modp2048|modp3072|modp4096|modp6144|modp8192

Note: Not all groups are supported by all tokens and key generation fails when the specified GROUP is not supported. Also, not all groups are supported by all OpenSSL versions. If the p11sak tool is compiled against an OpenSSL version that does not support certain groups, then those groups are not accepted for the GROUP argument. 😭

Alternatively, specify a DH parameters PEM file as DH-PARAM-PEM-FILE argument. You can for example generate DH parameters using the OpenSSL command line tool as follows: openssl dhparam <numbits> -out <pem-file> -outform PEM. See the OpenSSL man page for details about this command. 🫶

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS option can be used to set the boolean attributes of the key (see below for the detailed description of the attributes). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key. Furthermore, the optional PRIV-BITS argument allows the user to specify the size of the private key in bits. ✨

🍓 Generating DSA keys 🍓

p11sak generate-key|gen-key|gen dsa DSA-PARAM-PEM-FILE --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen dsa DSA-PARAM-PEM-FILE command and KEYTYPE argument to generate a DSA key (CKK_DSA), where DSA-PARAM-PEM-FILE specifies the name of a DSA parameters PEM file. You can for example generate DSA parameters using the OpenSSL command line tool as follows: openssl dsaparam <numbits> -out <pem-file> -outform PEM. See the OpenSSL man page for details about this command. 💜

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS option can be used to set the boolean attributes of the key (see below for the detailed description of the attributes). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key. 🌸

💫 Generating EC keys 💫

p11sak generate-key|gen-key|gen ec CURVE --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

...so yeah, to make an EC key (that's CKK_EC bestie 💖) you hit it with the generate-key|gen-key|gen ec CURVE command and the KEYTYPE argument, where CURVE is literally just the name of the elliptic curve you want your key built on. The curves you can pick from for their respective curves are:

prime256v1|prime192|secp224|secp384r1|secp521r1|secp265k1|brainpoolP160r1|brainpoolP160t1|brainpoolP192r1|brainpoolP192t1|brainpoolP224r1|brainpoolP224t1|brainpoolP256r1|brainpoolP256t1|brainpoolP320r1|brainpoolP320t1|brainpoolP384r1|brainpoolP384t1|brainpoolP512r1|brainpoolP512t1|curve25519|curve448|ed25519|ed448|bls12-381

Ok but real talk 👀 — if you use an Edwards or Montgomery curve for the EC key type, that only works for the EP11 token, and it produces an EC key that is non-PKCS#11-standard. So it's giving ✨special✨ but also giving "not spec-compliant", iykyk.

Note: Not all curves will be supported by all tokens, and key generation will fail when the specified CURVE is not supported. No cap, it just dies. 😭

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS option is how you set the boolean attributes of the key (detailed description of the attributes is further down, keep scrolling bestie 🫶). Bonus: you can optionally set individual key attributes for the public and the private key separately, by separating them with a colon (:). And the --id|-i ID option sets the value of the CKA_ID attribute of the key. Iconic.


✨ Generating EC-Edwards keys ✨

p11sak generate-key|gen-key|gen ec-edwards CURVE --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen ec-edwards CURVE command and the KEYTYPE argument to generate an EC-Edwards key (CKK_EC_EDWARDS), where CURVE says which edwards curve gets used to create that EC-Edwards key. The arguments you can use for respective curves are: ed25519|ed448. Just those two, periodt. 💅

Note: Not all curves will be supported by all tokens, and key generation will fail when the specified CURVE is not supported.

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key, and the --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS option sets the boolean attributes of the key (details below, promise). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option sets the value of the CKA_ID attribute of the key. 🎀


🌸 Generating EC-Montgomery keys 🌸

p11sak generate-key|gen-key|gen ec-montgomery CURVE --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen ec-montgomery CURVE command and the KEYTYPE argument to generate an EC-Montgomery key (CKK_EC_MONTGOMERY), where CURVE specifies the montgomery curve used to create the EC-Montgomery key. The arguments you can use for respective curves: curve25519|curve448. That's the whole menu, bestie. 🌈

Note: Not all curves are supported by all tokens and key generation fails when the specified CURVE is not supported.

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key and the --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS option sets the boolean attributes of the key (detailed description below, we get there 😌). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option sets the value of the CKA_ID attribute of the key.


🧚 Generating IBM Dilithium keys 🧚

p11sak generate-key|gen-key|gen ibm-dilithium VERSION --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen ibm-dilithium VERSION command and the KEYTYPE argument to generate an IBM Dilithium key (CKK_IBM_PQC_DILITHIUM), where VERSION specifies the version of the IBM Dilithium keypair. The arguments you can use for respective keys: r2_65|r2_87|r3_44|r3_65|r3_87

Note: Not all IBM Dilithium versions are supported by all tokens and key generation fails when the specified VERSION is not supported.

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key and the --attr|-a ATTRS option sets the boolean attributes of the key (see below for the detailed description of the attributes, it's all there 💜). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option sets the value of the CKA_ID attribute of the key.


👑 Generating IBM Kyber keys 👑

p11sak generate-key|gen-key|gen ibm-kyber VERSION --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen ibm-kyber VERSION command and the KEYTYPE argument to generate an IBM Kyber key (CKK_IBM_PQC_KYBER), where VERSION specifies the version of the IBM Kyber keypair. The arguments you can use for respective keys: r2_768|r2_1024

Note: Not all IBM Kyber versions are supported by all tokens and key generation fails when the specified VERSION is not supported.

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key and the --attr|-a ATTRS option sets the boolean attributes of the key (detailed description of the attributes is below, don't skip it 🙈). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option sets the value of the CKA_ID attribute of the key.


💀 Generating IBM ML-DSA keys 💀

p11sak generate-key|gen-key|gen ibm-ml-dsa VERSION --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen ibm-ml-dsa VERSION command and the KEYTYPE argument to generate an IBM ML-DSA key (CKK_IBM_ML_DSA), where VERSION specifies the version of the IBM ML-DSA keypair. The arguments you can use for respective keys: 44|65|87

Note: Not all IBM ML-DSA versions will be supported by all tokens, and key generation will fail when the specified VERSION is not supported.

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key and the --attr|-a ATTRS option sets the boolean attributes of the key (detailed description of the attributes lives below, we're getting to it 🫶). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option sets the value of the CKA_ID attribute of the key.


⭐ Generating IBM ML-KEM keys ⭐

p11sak generate-key|gen-key|gen ibm-ml-kem VERSION --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen ibm-ml-kem VERSION command and the KEYTYPE argument to generate an IBM ML-KEM key (CKK_IBM_ML_KEM), where VERSION specifies the version of the IBM ML-KEM keypair. The arguments you can use for respective keys: 512|768|1024

Note: Not all IBM ML-KEM versions will be supported by all tokens, and key generation will fail when the specified VERSION is not supported.

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key and the --attr|-a ATTRS option sets the boolean attributes of the key (detailed description of the attributes is further down, stay with me 💖). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option sets the value of the CKA_ID attribute of the key.


🦋 Generating ML-DSA keys 🦋

p11sak generate-key|gen-key|gen ml-dsa VERSION --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen ml-dsa VERSION command and the KEYTYPE argument to generate an ML-DSA key (CKK_ML_DSA), where VERSION specifies the version of the ML-DSA keypair. The arguments you can use for respective keys: 44|65|87

Note: Not all ML-DSA versions will be supported by all tokens, and key generation will fail when the specified VERSION is not supported.

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key and the --attr|-a ATTRS option sets the boolean attributes of the key (detailed description of the attributes is below, bestie, I promise ✨). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option sets the value of the CKA_ID attribute of the key.


🍓 Generating ML-KEM keys 🍓

p11sak generate-key|gen-key|gen ml-kem VERSION --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L
LABEL|PUB-LABEL:PRIV-LABEL --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS [--id|-i
ID] [--help|-h]

Use the generate-key|gen-key|gen ml-kem VERSION command and the KEYTYPE argument to generate an ML-KEM key (CKK_ML_KEM), where VERSION specifies the version of the ML-KEM keypair. The arguments you can use for respective keys: 512|768|1024

Note: Not all ML-KEM versions will be supported by all tokens, and key generation will fail when the specified VERSION is not supported.

The --label|-L LABEL|PUB-LABEL:PRIV-LABEL option sets the CKA_LABEL attribute of the key and the --attr|-a ATTRS option sets the boolean attributes of the key (see below for the detailed description of the attributes, it's coming 🎀). Optionally, set individual key attributes for public and private key separated by a colon (:). The --id|-i ID option sets the value of the CKA_ID attribute of the key.


🌈 Listing symmetric and asymmetric keys 🌈

p11sak list-key|ls-key|ls [KEYTYPE] --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL] [--id|-i
ID] [--attr|-a ATTRS] [--long|-l] [--detailed-uri] [--hsm-mkvp|-m]
[--ep11-session-id|-e] [--sort|-S SORT-SPEC] [--help|-h]

Use the list-key|ls-key|ls command with the optional KEYTYPE argument to list symmetric or asymmetric keys. And listen — you can also list public, private, secret, or all keys, irrespective of the key type. Main character behaviour honestly. 💅

Possible values for the KEYTYPE argument are:

des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|public|private|secret|all

If KEYTYPE is omitted, then all key types are listed. Every single one. Go off, king. 👑

Okay so you filter which keys show up with --label|-L LABEL, --id|-i ID, and/or --attr|-a ATTRS. And bestie, the LABEL spec takes wildcards — * and ? — which is giving ✨main character✨. Wanna use a literal wildcard character that should NOT be treated as a wildcard? Escape it with a backslash: \* or \?. And a backslash that should NOT be treated as an escape character? Escape that too: \\. Yes, it's backslashes all the way down, we love a recursive moment 🌀. The ID has to be a hex string (not prefixed with 0x, do not @ me) of any number of bytes.

By default the keys are listed in a short, tabular format showing only the boolean attributes, the key type (CKA_KEY_TYPE) and the key label (CKA_LABEL). The attributes get denoted with the same single letters used with the --attr|-a ATTRS|PUB-ATTRS:PRIV-ATTRS option — consistent queen 💅. When --long|-l is specified, the keys are listed in long format, displaying the values of all attributes defined for the key type, including non-boolean attributes. When --hsm-mkvp|-m is specified, the HSM master key verification patterns (MKVPs) of the keys are displayed — and this is only possible for secure key tokens, such as the CCA and EP11 tokens. When --ep11-session-id|-e is specified, the EP11 session-IDs of the keys are displayed, which is only possible for EP11 tokens. Niche but iconic 🎀.

By default the keys are displayed in the order as they are retrieved from the PKCS #11 implementation. Wanna control the order? Specify --sort|-S SORT-SPEC. You can sort the keys by label, key type, object class, and/or key size. For details, see the description of the --sort|-S SORT-SPEC option below. Go off, sort queen 👑


🗑️ Deleting symmetric and asymmetric keys

p11sak remove-key|rm-key|rm [KEYTYPE] --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL] [--id|-i
ID] [--attr|-a ATTRS] [--long|-l] [--force|-f] [--help|-h]

Use the remove-key|rm-key|rm command plus the optional KEYTYPE argument to remove symmetric or asymmetric keys. Public, private, secret, or all keys can also be selected for removal irrespective of the key type. Equal opportunity deletion fr fr 😭.

Possible values for the KEYTYPE argument are: des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|public|private|secret|all. If KEYTYPE is omitted, then all key types are selected for removal. Everything. Gone. The whole roster. 💀

Specify the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options to filter the list of keys to remove. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes.

The user is prompted to confirm the removal of the key. To suppress the prompt, use the --force|-f option. (It's giving "are you SURE bestie" and honestly, respect 🫶)


✍️ Setting or updating attributes of symmetric and asymmetric keys

p11sak set-key-attr|set-key|set [KEYTYPE] --slot|-s SLOTID [--pin|-p
PIN] [--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL]
[--id|-i ID] [--attr|-a ATTRS] [--force|-f] [--new-attr|-A ATTRS]
[--new-label|-l LABEL] [--new-id|-I ID] [--help|-h]

Use the set-key-attrs | set-key | set command plus the optional KEYTYPE argument to set or update boolean attributes of symmetric or asymmetric keys. Public, private, secret, or all keys can also be selected for updating irrespective of the key type. Glow-up era ✨.

Possible values for the KEYTYPE argument are: des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|public|private|secret|all. If KEYTYPE is omitted, then all key types are selected for updating.

Specify the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options to filter the list of keys to set or update. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes.

Use the --new-attr|-A ATTRS option to specify the boolean attributes of the key you want to update (see below for detailed description of the attributes). Attributes that are not specified are not changed — no surprise edits, we respect boundaries 🫶. Use the --new-label|-l LABEL option to specify the new label, or the --new-id|-I ID option to specify the new ID to set for the key. At least one of the --new-attr|-A ATTRS, --new-label|-l LABEL, or --new-id|-I ID options must be specified. No vibes-only invocations, you gotta actually ask for something.

The user is prompted to confirm the updating of the key. To suppress the prompt, use the --force|-f option.


📋 Coyping symmetric and asymmetric keys

(Not me catching the typo — it's canon now, we're keeping it 💀💖)

p11sak copy-key|copy|cp [KEYTYPE] --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL] [--id|-i
ID] [--attr|-a ATTRS] [--force|-f] [--new-attr|-A ATTRS] [--new-label|-l
LABEL] [--new-id|-I ID] [--help|-h]

Use the copy-key | copy | cp command and the optional KEYTYPE argument to copy symmetric or asymmetric keys and optionally set or change boolean attributes, the label, or ID of the copied keys. Public, private, secret, or all keys can also be copied irrespective of the key type. Duplication era, it's giving clone high 👯

Possible values for the KEYTYPE argument are: des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|public|private|secret|all. If KEYTYPE is omitted, then all key types are selected for copying.

Specify the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options to filter the list of keys to copy. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes.

Use the --new-attr|-A ATTRS option to specify the boolean attributes of the copied key you want to set or update (see below for detailed description of the attributes). Attributes that are not specified are not changed. Use the --new-label|-l LABEL option to specify the new label, or the --new-id|-I ID option to specify the new ID to set for the copied key.

The user is prompted to confirm the copying of the key. To suppress the prompt, use the --force|-f option.


📥 Importing symmetric and asymmetric keys from a file

p11sak import-key|import|imp KEYTYPE [KIND] --slot|-s SLOTID [--pin|-p
PIN] [--force-pin-prompt] [--no-login|-N] [--so] --label|-L LABEL
[--id|-i ID] [--force|-f] [--attr|-a ATTRS] --file|-F FILENAME
[--pem-password|-P PASSWORD] [--force-pem-pwd-prompt] [--opaque|-o]
[--oqsprovider-pem] [--help|-h]

Use the import-key|import|imp command and KEYTYPE argument to import an symmetric or asymmetric key from a file. When importing an asymmetric key, the KIND argument is required and specifies to either import a private or public key. Required arguments, no skipping bestie 📥

Possible values for the KEYTYPE argument are: des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|public|private|secret|all.

The --label|-L LABEL option sets the CKA_LABEL attribute of the key and the --attr|-a ATTRS can be used to set the boolean attributes of the key (see below for detailed description of the attributes). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the key.

The --file|-F FILENAME option specifies the file name of the file that contains the key to be imported. For symmetric keys, this is a binary file containing the key material in clear. In clear!! 😭 For asymmetric keys, this is an OpenSSL PEM file containing a public or private key. PEM files can optionally be password protected. Specify the PEM password with the --pem-password|-P PASSWORD option or environment variable P11SAK_PEM_PASSWORD. If the PEM file is password protected, but no PEM password is specified, you are prompted for the PEM password. Specify the --opaque|-o option to import an opaque secure key blob. Not all tokens support this.

Specify the --oqsprovider-pem option when the key material in the PEM file is in the oqsprovider format. This option is only valid for the ibm-dilithium keytype. PEM files in oqsprovider format are only supported when the oqsprovider from https://github.com/open-quantum-safe/oqs-provider has been configured with OpenSSL 3.0 or later.

⚠️ This is an experimental feature, it may change in an incompatible way in the future! Post-quantum but make it chaotic 🧪✨

📤 Exporting symmetric and asymmetric keys to a file

p11sak export-key|export|exp [KEYTYPE] --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL] [--id|-i
ID] [--attr|-a ATTRS] [--force|-f] --file|-F FILENAME
[--encrypted-pem|-e] [--pem-password|-P PASSWORD]
[--force-pem-pwd-prompt] [--opaque|-o] [--spki|-S] [--uri-pem|-u]
[--uri-pin-value] [--uri-pin-source FILENAME] [--oqsprovider-pem]
[--help|-h]

Use the export-key|export|exp command and the optional KEYTYPE argument to export symmetric or asymmetric keys to a file. Public, private, secret, or all keys can also be selected for export irrespective of the key type. Pack your bags, key, you're going on tour 🧳

Possible values for the KEYTYPE argument are: des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|public|private|secret|all. If KEYTYPE is omitted, then all key types are selected for export.

  • --label/-L LABEL, --id/-i ID, and/or --attr/-a ATTRS — okay so these three are your ✨filter squad✨, they narrow down which keys actually get exported. Wildcards (* and ?) are welcome in the LABEL spec, no cap. BUT — and this is the plot twist — if you want a literal wildcard character that should not be treated as a wildcard, you gotta escape it with a backslash (\* or \?). And a backslash that should not be treated as an escape character must itself be escaped (\\). Yes bestie, it's giving escape-ception 💀. The ID has to be a hex string (not prefixed with 0x) of any number of bytes.
  • --file/-F FILENAME — this is where the exported keys go. For symmetric keys, it's a binary file where the key material is written in clear. For asymmetric keys, it's an OpenSSL PEM file where the public or private keys get written. If multiple asymmetric keys match your filter, they're all appended to that PEM file. But if multiple symmetric keys match — or a mixture of asymmetric and symmetric — you get prompted to confirm overwriting the previously created file, unless you hit it with --force/-f 💅

Private keys in PEM files can optionally be password protected. Say --encrypted-pem/-e and the exported private keys get encrypted using AES-CBC and an AES 256 bit key derived from a password via PBKDF2. 🌸 Give it the PEM password with --pem-password/-P PASSWORD or the environment variable P11SAK_PEM_PASSWORD — otherwise it's prompt o'clock, sorry babe.

--opaque/-o exports the opaque secure key blobs of the key. Fair warning: not all tokens support this 🙈

--spki/-S exports the Subject Public Key Info (SPKI) from the CKA_PUBLIC_KEY_INFO attribute of an asymmetric private key instead of its private key material. This one is private-keys-only, no exceptions.

--oqsprovider-pem — use this when the key material is to be exported in oqsprovider format into the PEM file. Only valid for the ibm-dilithium keytype, bestie. And PEM files in oqsprovider format are only supported when the oqsprovider from https://github.com/open-quantum-safe/oqs-provider has been configured with OpenSSL 3.0 or later.

⚠️ This is an experimental feature, it may change in an incompatible way in the future! Don't get attached, she's still growing 😭
📌 Note: Not all keys can be exported, because its attribute setting may forbid revealing the values of certain attributes. To allow exporting of a secret (CKO_SECRET_KEY) or private (CKO_PRIVATE_KEY) key, attribute CKA_SENSITIVE must be CK_FALSE and attribute CKA_EXTRACTABLE must be CK_TRUE. Secret or private keys that contain an opaque secure key blob (attribute CKA_IBM_OPAQUE) can also not be exported in clear, even if the attributes would allow it. For such keys only the opaque secure key blob can be exported, by using the --opaque/-o option.

--uri-pem/-u exports the PKCS#11 URI of the key in PEM form instead of the key material. Such a URI-PEM file can then be used with the pkcs11-provider from https://github.com/latchset/pkcs11-provider. 🔥 By default the PKCS#11 URI does not contain the PKCS#11 user pin. Specify --uri-pin-value to include the PKCS#11 user pin in the URI using the pin-value query attribute.

🚨 This reveals the PKCS#11 user pin in clear — use with care!

Alternatively, specify --uri-pin-source FILENAME to include the pin-source query attribute in the URI, referencing the file name you gave. The PKCS#11 user pin value is written into that file as part of the export operation.

🚨 Again: this reveals the PKCS#11 user pin in clear, use with care!

Adjust the file permissions of the specified pin-source file so that it can only be read by the desired user(s). By default the file permissions are set so that only the owner user can read and write that file, but no one else (i.e. 0600). Slay but securely 🎀


🦋 Extracting the public key of private key objects 🦋

       p11sak extract-pubkey|extr-pubkey|expub [KEYTYPE] --slot|-s SLOTID
       [--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so] [--label|-L
       LABEL] [--id|-i ID] [--attr|-a ATTRS] [--new-attr|-A ATTRS]
       [--new-label|-l LABEL] [--new-id|-I ID] [--force|-f] [--help|-h]

Use the extract-pubkey|extr-pubkey|expub command plus the optional KEYTYPE argument to pull the public key out of private key objects and save it as a shiny new token object. ✨

Possible values for the KEYTYPE argument are: rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|private|all. If KEYTYPE is omitted, then all private key types are selected for export. 💖

  • --label/-L LABEL, --id/-i ID, and/or --attr/-a ATTRS — filter which private keys you're extracting the public keys from. Wildcards (* and ?) work in the LABEL spec. A wildcard character that should not be treated as a wildcard must be escaped using a backslash (\* or \?). And a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes. Same rules as always, bestie, you know the drill 🫶
  • --new-attr/-A ATTRS — sets the boolean attributes of the public key object you want (detailed description of the attributes is below, further down the page 👀).
  • --new-label/-l LABEL — the new label, obviously. If no new label is specified, the label of the public key object is derived from the private key label by appending _pubkey. Cute little naming convention, lowkey obsessed 🌸
  • --new-id/-I ID — sets an ID for the extracted public key object.

The user is prompted to confirm the extraction of the public key from the private key objects. To suppress the prompt, use the --force/-f option. 🫡


🧚 Exporting a key by wrapping it with a key encrypting key 🧚

       p11sak wrap-key|wrap WRAP-MECH [KEYTYPE] --slot|-s SLOTID [--pin|-p PIN]
       [--force-pin-prompt] [--no-login|-N] [--so] [--kek-label|-K LABEL]
       [--kek-id|-k ID] [--label|-L LABEL] [--id|-i ID] [--attr|-a ATTRS]
       [--force|-f] --file|-F FILENAME [--raw|-R] [options specific for
       WRAP-MECH] [--help|-h]

Use the wrap-key|wrap command and the WRAP-MECH argument to export symmetric or asymmetric keys by wrapping them with a key encrypting key. Dependent on the key wrapping mechanism, additional options may be supported to specify mechanism parameters. The optional KEYTYPE argument can filter the list of keys to export by key type. Heads up: only private and secret keys can be wrapped. 🔐

Possible values for the KEYTYPE argument are: des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|private|secret|all. If KEYTYPE is omitted, then all key types are selected for wrapping.

Possible values for the WRAP-MECH argument are:

  • aes-cbc-pad: Use mechanism CKM_AES_CBC_PAD for key wrapping. Wrapping and unwrapping is done with an AES key. Use the --iv/-I IV option to specify the initialization vector (IV) for the AES-CBC operation.
  • aeskw-kwp: Use mechanism CKM_AES_KEY_WRAP_KWP for key wrapping. Wrapping and unwrapping is done with an AES key. Use the --iv/-I IV option to specify the initialization vector (IV) for the AESKW-KWP operation.
  • aeskw-pkcs7: Use mechanism CKM_AES_KEY_WRAP_PKCS7 for key wrapping. Wrapping and unwrapping is done with an AES key. Use the --iv/-I IV option to specify the initialization vector (IV) for the AESKW-PKCS7 operation.
  • rsa-pkcs: Use mechanism CKM_RSA_PKCS for key wrapping. Wrapping is done with an RSA public key, unwrapping is done with the corresponding RSA private key. Only keys whose key material size is up to the KEK's RSA modulus size minus 11 bytes can be wrapped with this mechanism. Math is math, babe 📐
  • rsa-oaep: Use mechanism CKM_RSA_PKCS_OAEP for key wrapping. Wrapping is done with an RSA public key, unwrapping is done with the corresponding RSA private key. Only keys whose key material size is up to the KEK's RSA modulus size minus 2 times the hash-alg digest size bytes minus 2 bytes wrapped with this mechanism. Use the --hash-alg HASH-ALG, --mgf-alg MGF-ALG, and --source-data SOURCE-DATA, options to specify the OAEP mechanism parameters.
  • rsa-aeskw: Use mechanism CKM_RSA_AES_KEY_WRAP for key wrapping. Wrapping is done with an RSA public key, unwrapping is done with the corresponding RSA private key. Use the --aes-key-size AES-KEYBITS option to specify the key size of the temporary AES key, and the --hash-alg HASH-ALG, --mgf-alg MGF-ALG, and --source-data SOURCE-DATA, options to specify the OAEP mechanism parameters.
  • ecdh-aeskw, ecdh-cof-aeskw, and ecdh-x-aeskw: Use mechanisms CKM_ECDH_AES_KEY_WRAP, CKM_ECDH_COF_AES_KEY_WRAP, and CKM_ECDH_X_AES_KEY_WRAP respectively for key wrapping. Wrapping is done with an EC or EC-Montgomery public key (for ecdh-aeskw), an EC public key (for ecdh-cof-aeskw), or an EC-Montgomery public key (for ecdh-x-aeskw). Unwrapping is done with the corresponding EC or EC-Montgomery private key (for ecdh-aeskw), an EC private key (for ecdh-cof-aeskw), or an EC-Montgomery private key (for ecdh-x-aeskw). Use the --aes-key-size AES-KEYBITS option to specify the key size of the temporary AES key, and the --kdf-alg KDF-ALG, and --shared-data SHARED-DATA, options to specify the ECDH mechanism parameters.
  • --kek-label/-K LABEL, and/or --kek-id/-k ID — pick your key encrypting key (KEK). 👑 Only keys with the right object class and key type that actually fit the wrapping mechanism get selected. If multiple key objects match, you're prompted to confirm which key object to use. If --force/-f is specified, then the first matching key object is used. Wildcards (* and ?) work in the LABEL spec — to specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes.
  • --label/-L LABEL, --id/-i ID, and/or --attr/-a ATTRS — filter the list of keys to wrap. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes. 💜

--file|-F FILENAME is the option that tells p11sak where to drop the wrapped key material, bestie. Default vibe? It's a PEM file using a p11sak-specific type, with a header that carries all the tea about the wrapping mechanism and mechanism parameters (if there are any). ✨

But if you pass --raw|-R, we're not doing PEM anymore — the file is a raw binary file and the raw wrapped key material gets written straight into it. 🫶

And here's the group-chat-relevant bit: if multiple keys match your filter, the keys get appended to the PEM file you gave with --file|-F FILENAME. But if --raw|-R is on and multiple keys match, you get prompted to confirm that you want to overwrite the previously created file — unless you specified --force|-f, in which case it just goes. 💅

Note: not all keys can be wrapped, because their attribute setting may forbid extracting the key material. To allow exporting of a secret (CKO_SECRET_KEY) or private (CKO_PRIVATE_KEY) key, the attribute CKA_EXTRACTABLE must be CK_TRUE. Also, a token may not support all wrapping mechanisms, nor all mechanism parameter combinations, and not all tokens may support wrapping all key types. On top of that, a token might limit the support of wrapping a key with a weaker key encrypting key. 😭

🎀 Importing a key by unwrapping it with a key encrypting key

p11sak unwrap-key|unwrap [WRAP-MECH] [KEYTYPE] --slot|-s SLOTID
[--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so]
[--kek-label|-K LABEL] [--kek-id|-k ID] [--label|-L LABEL] [--id|-i ID]
[--attr|-a ATTRS] [--force|-f] --file|-F FILENAME [--raw|-R] [options
specific for WRAP-MECH] [--help|-h]

Use the unwrap-key|unwrap command, plus the optional WRAP-MECH and KEYTYPE arguments, to import symmetric or asymmetric keys by unwrapping them with a key encrypting key. 🦋 Depending on the key wrapping mechanism, extra options may be supported so you can specify mechanism parameters. And heads up: only private and secret keys can be unwrapped.

The WRAP-MECH and KEYTYPE arguments — and the wrapping-mechanism-specific options for mechanism parameters — are only required if you specified --raw|-R. Otherwise, all of that info gets read from the PEM file you named with --file|-F FILENAME. 📖

Possible values for the WRAP-MECH argument are:

  • aes-cbc-pad — Use mechanism CKM_AES_CBC_PAD for key wrapping. Wrapping and unwrapping is done with an AES key. Use the --iv|-I IV option to specify the initialization vector (IV) for the AES-CBC operation. 🔥
  • aeskw-kwp — Use mechanism CKM_AES_KEY_WRAP_KWP for key wrapping. Wrapping and unwrapping is done with an AES key. Use the --iv|-I IV option to specify the initialization vector (IV) for the AESKW-KWP operation. ✨
  • aeskw-pkcs7 — Use mechanism CKM_AES_KEY_WRAP_PKCS7 for key wrapping. Wrapping and unwrapping is done with an AES key. Use the --iv|-I IV option to specify the initialization vector (IV) for the AESKW-PKCS7 operation. 💖
  • rsa-pkcs — Use mechanism CKM_RSA_PKCS for key wrapping. Wrapping is done with an RSA public key, unwrapping is done with the corresponding RSA private key. Only keys whose key material size is up to the KEK's RSA modulus size minus 11 bytes can be wrapped with this mechanism. 🧮
  • rsa-oaep — Use mechanism CKM_RSA_PKCS_OAEP for key wrapping. Wrapping is done with an RSA public key, unwrapping is done with the corresponding RSA private key. Only keys whose key material size is up to the KEK's RSA modulus size minus 2 times the hash-alg digest size bytes minus 2 bytes wrapped with this mechanism. Use the --hash-alg HASH-ALG, --mgf-alg MGF-ALG, and --source-data SOURCE-DATA, options to specify the OAEP mechanism parameters. 💅
  • rsa-aeskw — Use mechanism CKM_RSA_AES_KEY_WRAP for key wrapping. Wrapping is done with an RSA public key, unwrapping is done with the corresponding RSA private key. Use the --aes-key-size AES-KEYBITS option to specify the key size of the temporary AES key, and the --hash-alg HASH-ALG, --mgf-alg MGF-ALG, and --source-data SOURCE-DATA, options to specify the OAEP mechanism parameters. 👑
  • ecdh-aeskw, ecdh-cof-aeskw, and ecdh-x-aeskw — Use mechanisms CKM_ECDH_AES_KEY_WRAP, CKM_ECDH_COF_AES_KEY_WRAP, and CKM_ECDH_X_AES_KEY_WRAP respectively for key wrapping. Wrapping is done with an EC or EC-Montgomery public key (for ecdh-aeskw), an EC public key (for ecdh-cof-aeskw), or an EC-Montgomery public key (for ecdh-x-aeskw). Unwrapping is done with the corresponding EC or EC-Montgomery private key (for ecdh-aeskw), an EC private key (for ecdh-cof-aeskw), or an EC-Montgomery private key (for ecdh-x-aeskw). Use the --aes-key-size AES-KEYBITS option to specify the key size of the temporary AES key, and the --kdf-alg KDF-ALG, and --shared-data SHARED-DATA, options to specify the ECDH mechanism parameters. 🌈

Possible values for the KEYTYPE argument are: des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem. No cap, that's the whole list. 🍓

Specify the --kek-label|-K LABEL, and/or the --kek-id|-k ID option to select the key encrypting key (KEK). Only keys with the right object class and key type that fit the wrapping mechanism are selected. If multiple key objects match, you get prompted to confirm which key object you want to use. If the --force|-f option is specified, then the first matching key object is used. 🫡

You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes. 💀

The --label|-L LABEL option sets the CKA_LABEL attribute of the unwrapped key, and the --attr|-a ATTRS option can be used to set the boolean attributes of the unwrapped key (see below for detailed description of the attributes). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the unwrapped key. 🎀

The --file|-F FILENAME option specifies the file name of the file containing the wrapped key material. By default this is a PEM file using a p11sak-specific type and a header that contains information about the wrapping mechanism and mechanism parameters (if any). If option --raw|-R is specified then the file is a raw binary file and the raw wrapped key material is contained. In this case, arguments WRAP-MECH and KEYTYPE, as well as wrapping mechanism specific options to specify mechanism parameters, are required. ⭐

Note: a token may not support all wrapping mechanisms, nor all mechanism parameter combinations. Also, not all tokens may support to unwrap all key types. 🙈

🌸 Listing certificates

p11sak list-cert|ls-cert|lsc [CERTTYPE] --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL] [--id|-i
ID] [--attr|-a ATTRS] [--long|-l] [--detailed-uri] [--sort|-S SORT-SPEC]
[--help|-h]

Use the list-cert|ls-cert|lsc command and the optional CERTTYPE argument to list certificates. 📜

Possible values for the CERTTYPE argument are: x509. If CERTTYPE is omitted, then x509 certificates are listed by default, because no other certificate types are supported. That's the whole menu, bestie. 💅

Specify the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options to filter the list of certificates to display. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes. ✨

By default, the certificates are listed in a short, tabular format showing only the boolean attributes, the certificate type (CKA_CERTIFICATE_TYPE) and the certificate label (CKA_LABEL). The attributes are denoted using the same single letters as used with the --attr|-a ATTRS option. When option --long|-l is specified, the certificates are listed in long format, displaying the values of all attributes defined for the certificate type, including non-boolean attributes. 👑

By default, the certificates are displayed in the order as they are retrieved from the PKCS #11 implementation. To display the certificates in a certain order, specify the --sort|-S SORT-SPEC option. You can sort the certificates by label and/or subject common name (CN). For details, see the description of the --sort|-S SORT-SPEC option below. 🦋


🧚 Deleting certificates

p11sak remove-cert|rm-cert|rmc [CERTTYPE] --slot|-s SLOTID [--pin|-p
PIN] [--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL]
[--id|-i ID] [--attr|-a ATTRS] [--force|-f] [--help|-h]

Use the remove-cert|rm-cert|rmc command and the optional CERTTYPE argument to remove certificates from the repository. 🗑️

Possible values for the CERTTYPE argument are: x509. If CERTTYPE is omitted, then x509 is used by default, because no other certificate types are supported. 💜

Specify the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options to filter the list of certificates to remove. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes. 🌟

The user is prompted to confirm the removal of the certificate. To suppress the prompt, use the --force|-f option. 😭


💖 Setting or updating attributes of certificates

p11sak set-cert-attr|set-cert|setc [CERTTYPE] --slot|-s SLOTID [--pin|-p
PIN] [--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL]
[--id|-i ID] [--attr|-a ATTRS] [--force|-f] [--new-attr|-A ATTRS]
[--new-label|-l LABEL] [--new-id|-I ID] [--help|-h]

Use the set-cert-attrs | set-cert | sect command and the optional CERTTYPE argument to set or update boolean attributes of certificates. ✨

Possible values for the CERTTYPE argument are: x509. If CERTTYPE is omitted, x509 is used by default, because no other certificate types are supported. 🎀

Okay so filtering the certs you wanna touch — you do that with the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options, and they narrow down the list of certificates to set or update. Wildcards (* and ?) are totally allowed in the LABEL specification 💫. But bestie, listen: if you want a wildcard character that should not be treated as a wildcard, you gotta escape it with a backslash (\* or \?). And a backslash that should not be treated as an escape character also needs escaping (\\). Yes, it's backslashes all the way down, iykyk. The ID has to be specified as a hex string — not prefixed with 0x — of any number of bytes.

Then, to actually change stuff: use the --new-attr|-A ATTRS option to specify the boolean attributes of the certificate you want to update (there's a detailed description of the attributes below, don't worry ✨). Attributes you don't specify are simply not changed — no sneaky edits, we respect boundaries. Use the --new-label|-l LABEL option for the new label, or the --new-id|-I ID option for the new ID to set on the certificate. And heads up: at least one of the --new-attr|-A ATTRS, --new-label|-l LABEL, or --new-id|-I ID options must be specified. Pick at least one, bestie, you can't just vibe in there with nothing.

The user is prompted to confirm the updating of the certificate. Wanna skip that lil check-in? Use the --force|-f option 💅.


🎀 Coyping certificates 🎀

p11sak copy-cert|copyc|cpc [CERTTYPE] --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL] [--id|-i
ID] [--attr|-a ATTRS] [--force|-f] [--new-attr|-A ATTRS] [--new-label|-l
LABEL] [--new-id|-I ID] [--help|-h]

Use the copy-cert | copyc | cpc command plus the optional CERTTYPE argument to copy certificates, and optionally set or change boolean attributes, the label, or ID of the copied certificates 🦋.

Possible values for the CERTTYPE argument are: x509. If CERTTYPE is omitted, then x509 is used by default, because no other certificate type is supported. (One option. It's giving "we only do one thing and we do it well" 💅.)

Specify the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options to filter the list of certificates to copy. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes.

Use the --new-attr|-A ATTRS option to specify the boolean attributes of the copied certificates you want to set or update (see below for detailed description of the attributes 👀). Attributes that are not specified are not changed. Use the --new-label|-l LABEL option to specify the new label, or the --new-id|-I ID option to specify the new ID to set for the copied certificate.

The user is prompted to confirm the copying of the certificate. To suppress the prompt, use the --force|-f option.


🌸 Importing x.509 certificates from a file 🌸

p11sak import-cert|importc|impc CERTTYPE --slot|-s SLOTID [--pin|-p PIN]
[--force-pin-prompt] [--no-login|-N] [--so] --label|-L LABEL [--id|-i
ID] [--attr|-a ATTRS] --file|-F FILENAME [--ca-cert|-C] [--help|-h]

Use the import-cert|importc|impc command and CERTTYPE argument to import an x.509 certificate from a file 📥✨.

Possible values for the CERTTYPE argument are: x509. If CERTTYPE is omitted, then x509 is used by default, because no other certificate type is supported.

The --label|-L LABEL option sets the CKA_LABEL attribute of the certificate, and the --attr|-a ATTRS can be used to set the boolean attributes of the certificate (see below for detailed description of the attributes. Applicable attributes for certificates are P M B Y T). The --id|-i ID option can be used to set the value of the CKA_ID attribute of the certificate.

The --file|-F FILENAME option specifies the file name of the file that contains the certificate to be imported. Supported input formats are PEM and binary (DER-encoded). The format is automatically detected — no, you don't have to tell it, it just knows 🧚.

The --ca-cert|-C option flags the certificate as a Certificate Authority (CA) certificate. And if the certificate has the BasicConstraints CA flag on, it is also flagged as Certificate Authority (CA) certificate. Either way, it's a CA, periodt 👑.


🌈 Exporting certificates to a file 🌈

p11sak export-cert|exportc|expc [CERTTYPE] --slot|-s SLOTID [--pin|-p
PIN] [--force-pin-prompt] [--no-login|-N] [--so] [--label|-L LABEL]
[--id|-i ID] [--attr|-a ATTRS] [--force|-f] --file|-F FILENAME
[--der|-D] [--uri-pem|-u] [--uri-pin-value] [--uri-pin-source FILENAME]
[--help|-h]

Use the export-cert|exportc|expc command and the optional CERTTYPE argument to export x.509 public key certificates to a file 📤💖.

Possible values for the CERTTYPE argument are: x509. If CERTTYPE is omitted, then x509 is used by default, because no other certificate types are supported.

Specify the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options to filter the list of certificates to export. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes.

The --file|-F FILENAME option specifies the file name of the file to which the certificates to be exported are written to. This can be an OpenSSL PEM file or binary (DER-encoded) file. If it's a PEM file, multiple certificates can be exported to the same file 🎉. If it's a binary file, each subsequent export overwrites the previous data in the output file — no stacking, no take-backs. You are prompted to confirm to overwrite the previously created file, unless the --force|-f option is specified.

Specify the --der|-D option to export the certificate(s) in binary (DER-encoded) form. Default is PEM format.

Specify the --uri-pem|-u option to export the PKCS#11 URI of the certificate in PEM form instead of the certificate material. Such an URI-PEM file can then be used with the pkcs11-provider from https://github.com/latchset/pkcs11-provider 🔗.

By default, the PKCS#11 URI does not contain the PKCS#11 user pin.

⚠️ Specify option --uri-pin-value to include the PKCS#11 user pin in the URI using the pin-value query attribute. This reveals the PKCS#11 user pin in clear, use with care! 😭

Alternatively, specify option --uri-pin-source FILENAME to include the pin-source query attribute in the URI, referencing the file name specified with this option. The PKCS#11 user pin value is written into that file as part of the export operation. This reveals the PKCS#11 user pin in clear, use with care! 😭 Adjust the file permissions of the specified pin-source file so that it can only be read by the desired user(s). By default the file permissions are set so that only the owner user can read and write that file, but no one else (i.e. 0600). Locked down, as it should be 🔒💅.


⭐ Extracting the public key of certificates ⭐

p11sak extract-cert-pubkey|extrc-pubkey|excpub [CERTTYPE] --slot|-s
SLOTID [--pin|-p PIN] [--force-pin-prompt] [--no-login|-N] [--so]
[--label|-L LABEL] [--id|-i ID] [--attr|-a ATTRS] [--new-attr|-A ATTRS]
[--new-label|-l LABEL] [--new-id|-I ID] [--force|-f] [--help|-h]

Use the extract-cert-pubkey|extrc-pubkey|excpub command and the optional CERTTYPE argument to extract the public key from certificates and save it as new token object 🔑✨.

Possible values for the CERTTYPE argument are: x509. If CERTTYPE is omitted, then x509 is used by default, because no other certificate types are supported.

Specify the --label|-L LABEL, the --id|-i ID, and/or the --attr|-a ATTRS options to filter the certificates of which the public keys are to be extracted. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). The ID must be specified as hex string (not prefixed with 0x) of any number of bytes.

Use the --new-attr|-A ATTRS option to specify the boolean attributes of the public key object you want to set (see below for detailed description of the attributes). Use the --new-label|-l LABEL option to specify the new label. If no new label is specified, the label of the public key object is derived from the certificate label by appending _pubkey — cute lil auto-naming moment 🏷️.

Use the --new-id|-I ID option to set an ID for the extracted public key object.

The user is prompted to confirm the extraction of the public key from the certificate. To suppress the prompt, use the --force|-f option 🫶.

✨ ARGUMENTS ✨

okay bestie, these are the lil' argument types the commands eat. each one is a whole vibe check for what you're generating, importing, or selecting. 💅

💖 KEYTYPE 💖

Picks the symmetric or asymmetric key that's getting generated, imported, or selected. The possible values are literally: des|3des|generic|sha-1-hmac|sha224-hmac|sha256-hmac|sha384-hmac|sha512-hmac|sha512/224-hmac|sha512/256-hmac|sha3-224-hmac|sha3-256-hmac|sha3-384-hmac|sha3-512-hmac|aes|aes-xts|rsa|dh|dsa|ec|ec-edwards|ec-montgomery|ibm-dilithium|ibm-kyber|ibm-ml-dsa|ibm-ml-kem|ml-dsa|ml-kem|public|private|secret|all.

The public|private|secret|all argument can only be used with commands that use the KEYTYPE argument as a filter, like the list-key command, the remove-key command, the set-key-attrs command, or the export-key command. iykyk ✨

💖 CERTTYPE 💖

Selects the type of certificate to be imported, exported, listed, copied, updated, removed, or selected for public key extraction. Possible values are: x509. If no certificate type is specified, certificate type x509 is used, because currently no other certificate types are supported. periodt.

💖 KEYBITS 💖

Specifies the size of the key in bits. For the aes key type, possible values are 128|192|256. For the aes-xts key type, possible values are 128|256. For the rsa key type, the key size must be from 512 to 16384 and a multiple of 8 bits. Typical key sizes are 512, 1024, 2048, 4096, or 8192. Not all RSA key sizes might be supported by all tokens. no cap.

💖 PUBL-EXP 💖

Specifies the public exponent for an RSA key. If not specified, the default is 65537 according to the PKCS #11 standard. iconic.

💖 PRIV-BITS 💖

Specifies the size of the private key in bits for an DH key. 💅

💖 GROUP 💖

Specifies the Diffie-Hellman FFC group name for an DH key. Possible values are ffdhe2048|ffdhe3072|ffdhe4096|ffdhe6144|ffdhe8192|modp1536|modp2048|modp3072|modp4096|modp6144|modp8192.

Note: Not all groups are supported by all tokens and key generation fails when the specified GROUP is not supported. Also, not all groups are supported by all OpenSSL versions. If the p11sak tool is compiled against an OpenSSL version that does not support certain groups, then those groups are not accepted for the GROUP argument. so like, vibe check your OpenSSL first bestie 😭

💖 DH-PARAM-PEM-FILE 💖

Specifies the DH parameters PEM file name. You can for example generate DH parameters using the OpenSSL command line tool as follows: openssl dhparam <numbits> -out <pem-file> -outform PEM . See the OpenSSL man page for details about this command.

💖 DSA-PARAM-PEM-FILE 💖

Specifies the DSA parameters PEM file name. You can for example generate DSA parameters using the OpenSSL command line tool as follows: openssl dsaparam <numbits> -out <pem-file> -outform PEM . See the OpenSSL man page for details about this command.

💖 CURVE 💖

Specifies the curve for an EC, EC-Edwards, or EC-Montgomery key. For the EC key type possible values are: prime256v1|prime192|secp224|secp384r1|secp521r1|secp265k1|brainpoolP160r1|brainpoolP160t1|brainpoolP192r1|brainpoolP192t1|brainpoolP224r1|brainpoolP224t1|brainpoolP256r1|brainpoolP256t1|brainpoolP320r1|brainpoolP320t1|brainpoolP384r1|brainpoolP384t1|brainpoolP512r1|brainpoolP512t1|curve25519|curve448|ed25519|ed448|bls12-381. Note that using an Edwards or Montgomery curve for the EC key type only works for the EP11 token and produces a non-PKCS#11-standard EC key. For the EC-Edwards key type possible values are: ed25519|ed448. For the EC-Montgomery key type possible values are: curve25519|curve448.

💖 VERSION 💖

Specifies the version for an IBM Dilithium, IBM Kyber, IBM ML-DSA, IBM ML-KEM, ML-DSA, or ML-KEM key. For the ibm-dilithium key type, possible values are r2_65|r2_87|r3_44|r3_65|r3_87. For the ibm-kyber key type, possible values are r2_768|r2_1024. For the ibm-ml-dsa and ml-dsa key types, possible values are 44|65|87. For the ibm-ml-kem and ml-kem key types, possible values are 512|768|1024.

💖 KIND 💖

Specifies the kind of the asymmetric key to import. Possible values are public|private.

💖 WRAP-MECH 💖

Specifies the wrapping mechanism for use with exporting or importing a key by wrapping it with a key encrypting key. Possible values are aes-cbc-pad|aeskw-kwp|aeskw-pkcs7|rsa-pkcs|rsa-oaep|rsa-aeskw|ecdh-aeskw|ecdh-cof-aeskw|ecdh-x-aeskw. Dependent on the key wrapping mechanism, additional options may be supported to specify mechanism parameters. See sections Exporting a key by wrapping it with a key encrypting key and Importing a key by unwrapping it with a key encrypting key under COMMANDS for a description of the wrapping mechanism and its mechanism parameter options.


✨ OPTIONS ✨

okay so these are the flags you can pass, and they're all kinda important. don't skip any bestie 💖

  • --slot, -s SLOT — Specifies the slot number of the token to use.
  • --pin, -p PIN — Specifies the token user PIN to login with.

Alternatively, the PKCS11_USER_PIN environment variable may be used to provide the token user PIN. If neither this option is specified nor the environment variable is set, you are prompted for the PIN.

  • --force-pin-prompt — Enforce the p11sak tool to prompt for the token user PIN (regardless if it has been specified elsewhere)
  • --no-login, -N — Do not login the session. This means that only public token objects (CKA_PRIVATE=FALSE) can be accessed.
  • --so — Login as SO (security officer). Option --pin|-p PIN must specify the SO pin, or if the --pin|-p PIN option is not specified, environment variable PKCS11_SO_PIN is used. If PKCS11_SO_PIN is not set, you are prompted for the SO PIN. SO can only access public token objects (CKA_PRIVATE=FALSE), but SO can set attribute CKA_TRUSTED to TRUE for secret key objects, public key objects, and certificate objects.
  • --label, -L LABEL|PUB-LABEL:PRIV-LABEL — Specifies the key label attribute value (CKA_LABEL).
    • For commands such as the list-key command, the remove-key command, the set-key-attrs command, the export-key command, and the wrap-key command, specify the label to filter the list of keys to operate on. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\).
    • For generation of asymmetric keys, the specified label is appended by :pub and :prv for the public and private key objects. Optionally, a user can set different labels for the public and private key objects by specifying them separated by a colon (:), e.g. pub-label:priv-label. The label string in front of the colon is used as label for the public key object, the label string after the colon is used for the private key object. To set the public and private key label the exact same, use pub-label:=. The equal sign (=) means to use the same label string for the private key objects as for the public key object. In case a colon character or a equal sign is supposed to appear within a label string, it must be escaped using a back slash (\), e.g. abc\:xyz results in abx:xyz where the colon is not treated as separator character. Note that the shell may interpret escape characters as well, so better quote the LABEL|PUB-LABEL:PRIV-LABEL specification.
  • --id, -i ID — Specifies the key ID attribute value (CKA_ID) as hex string (not prefixed with 0x) of any number of bytes.
    • For commands such as the list-key command, the remove-key command, the set-key-attrs command, the export-key command, and the wrap-key command, specify the key ID to filter the list of keys to operate on.
    • For generation of asymmetric keys, the same ID is set for both, the public and the private key.
  • --attr, -a ATTRS|PUB-ATTRS:PRIV-ATTRS — For the generate-key command, the import-key command, and the unwrap-key command, specify the boolean attributes that are to be set for the new key(s). For commands such as the list-key command, the remove-key command, the set-key-attrs command, the export-key command, and the wrap-key command, specify the attribute values to filter the list of keys to operate on.
Note: Not all boolean attributes are applicable to all key types and/or commands and are silently ignored if not applicable.
  • The respective attributes are set to TRUE when the corresponding letter is specified in uppercase, or FALSE when the corresponding letter is specified in lowercase. Attributes (except CKA_TOKEN and CKA_SENSITIVE, see below) that are not specified get the default value as defined by the PKCS #11 standard or the used PKCS #11 token implementation when generating keys, or are not updated when setting the attributes of an existing key.
  • Attribute CKA_TOKEN is always set to TRUE when generating a key. The p11sak tool always generates token keys, since session keys are not persistent, and thus would no longer exist after the session that the p11sak tool has opened for generating the key is closed when it exists.
  • When generating or importing a key with the p11sak tool, attribute CKA_SENSITIVE defaults to TRUE for secret keys or the private key of asymmetric key pairs. However, this can be overridden by specifying the respective uppercase or lowercase letter for the CKA_SENSITIVE attribute in the attribute string, as desired.
Note: The default setting for the CKA_SENSITIVE attribute is defined by the p11sak tool, and might be different from the default setting that would be chosen by the used PKCS #11 implementation.
  • The following letters are associated with the respective CK_ATTRIBUTE:
    • P — CKA_PRIVATE
    • L — CKA_LOCAL (read only)
    • M — CKA_MODIFIABLE
    • B — CKA_COPYABLE
    • Y — CKA_DESTROYABLE
    • R — CKA_DERIVE
    • E — CKA_ENCRYPT
    • D — CKA_DECRYPT
    • G — CKA_SIGN
    • C — CKA_SIGN_RECOVER
    • V — CKA_VERIFY
    • O — CKA_VERIFY_RECOVER
    • W — CKA_WRAP
    • U — CKA_UNWRAP
    • S — CKA_SENSITIVE
    • A — CKA_ALWAYS_SENSITIVE (read only)
    • X — CKA_EXTRACTABLE
    • N — CKA_NEVER_EXTRACTABLE (read only)
    • T — CKA_TRUSTED (can only be set to TRUE by SO user)
    • I — CKA_WRAP_WITH_TRUSTED
    • H — CKA_ALWAYS_AUTHENTICATE (for keys of class CKO_PRIVATE_KEY only, can only be set to TRUE if CKA_PRIVATE is also TRUE)
  • J — CKA_ENCAPSULATE
  • Q — CKA_DECAPSULATE
  • K — CKA_IBM_PROTKEY_EXTRACTABLE (IBM specific, not all tokens support this)
  • Z — CKA_IBM_PROTKEY_NEVER_EXTRACTABLE (IBM specific, not all tokens support this, read only)

Okay so for multiple attributes, bestie, you just slap a set of these letters together with no blanks in between, like 'MlD'. Uppercase letter = TRUE, lowercase letter = FALSE. ✨ From the Example above, 'MlD' corresponds to: CKA_MODIFIABLE=TRUE, CKA_LOCAL=FALSE, CKA_DECRYPT=TRUE. Iconic, right? 💅

And for generating asymmetric keys you set individual key attributes for the public and private key separated by a colon (:). The attributes in front of the colon go to the public key, the ones after the colon go to the private key. No colon at all? Then the same attribute set is used for both, public and private. Want a config for only the public key? The string must end with the colon. And respectively, for private key only, the string must start with the colon. 🎀


✨ OPTIONS (continued, bestie, we're SO close) ✨

  • --new-attr|-A ATTRS — Specifies the boolean attributes to set or update for a key with the set-key-attr or copy-key commands. 👀 See the description of the --attr|-a option above for the list of letters that are associated with the respective CK_ATTRIBUTE. Go look, it's right there.
  • --new-label|-L LABEL — Specifies the new label attribute value (CKA_LABEL) to set for the key. New name, new me, periodt. 💖
  • --new-id|-I ID — Specifies the new ID attribute value (CKA_ID) as a hex string (not prefixed with 0x) of any number of bytes to set for the key. No 0x bestie, I said what I said. 🚫
  • --long|-l — Prints the list-key output in long format, displaying the values of all attributes defined for the key type, including the non-boolean ones. If you leave --long|-l out, the output is in a short, tabular format, showing only the boolean attributes, the key type (CKA_KEY_TYPE) and the key label (CKA_LABEL). Short and sweet vs. the full lore. ✨
  • --detailed-uri — Displayes a detailed PKCS #11 URI. (yes, "Displayes", the original said it like that, I'm not touching it, it's iconic 🫶)
  • --hsm-mkvp|-m — Shows the HSM master key verification patterns (MKVPs) of the key objects. 🧚 This option is only valid for secure key tokens, such as the CCA and EP11 tokens.
  • --ep11-session-id|-e — Shows the EP11 session-IDs of the key objects. This option is only valid for EP11 tokens.
  • --sort|-S SORT-SPEC — Sort the keys by label, key type, object class, and/or key size. Sort certificates by label and/or subject common name (CN). 🦋 Specify a sort selection of up to 4 fields, each field represented by its corresponding letter, separated by comma (,):
    • l — sort by label (keys and certificates) (CKA_LABEL)
    • k — sort by key type (keys only) (CKA_KEY_TYPE)
    • c — sort by object class (keys only) (CKA_CLASS, secret key, private key, public key)
    • s — sort by key size (keys only) (CKA_VALUE_LEN, or derived from other key type specific attribute)
    • n — sort by common name (certificates only)

The sort order can be appended to the field designator by a colon (:) and its corresponding letter:

  • a — ascending order (default)
  • d — descending order

Example: l:a,k:d sorts by label in ascending order and then by key type in descending order. Chef's kiss, so tidy. 👑

  • --force|-f — Suppress the prompt whether the user wants to remove, update, or export the keys matching the specified KEYTYPE, label, and ID filter (if specified). For the wrap-key command and the command, and the unwrap-key command, also supress the prompt for a confirmation to use a key as KEK. (again, "supress" — keeping it exactly, no cap 💀) Just do it, no questions asked energy.
  • --file|-F FILENAME — This one is a whole saga depending on which command you're on, so buckle up bestie:

For the import-key command, this option specifies the file name of the file that contains the key to be imported. For symmetric keys, this is a binary file containing the key material in clear. For asymmetric keys, this is an OpenSSL PEM file containing a public or private key. PEM files used for importing keys can be password protected. Specify the PEM password with the --pem-password|-P PASSWORD option or environment variable P11SAK_PEM_PASSWORD. If the PEM file is password protected, but no PEM password is specified, you are prompted for the PEM password. 🔐

For the export-key command, this option specifies the file name of the file to which the keys to be exported are written to. For symmetric keys, this is a binary file where the key material in clear is written to. For asymmetric keys, this is an OpenSSL PEM file where the public or private keys are written to. If multiple asymmetric keys match the filter, the keys are appended to the PEM file specified with this option. If multiple symmetric keys or a mixture of asymmetric and symmetric keys match the filter, you are prompted to confirm to overwrite the previously created file, unless the --force|-f option is specified. 😭

For the wrap-key command, this option specifies the file name of the file to which the wrapped key material is written to. By default this is a PEM file using a p11sak specific type and a header that contains information about the wrapping mechanism and mechanism parameters (if any). If option --raw|-R is specified then the file is a raw binary file and the raw wrapped key material is written to it. If multiple keys match the filter, the keys are appended to the PEM file specified with the --file|-F FILENAME option. If option --raw|-R is specified, and multiple keys match the filter, you are prompted to confirm to overwrite the previously created file, unless the --force|-f option is specified.

For the unwrap-key command, this option specifies the file name of the file containing the wrapped key material. By default this is a PEM file using a p11sak-specific type and a header that contains information about the wrapping mechanism and mechanism parameters (if any). If option --raw|-R is specified then the file is a raw binary file and the raw wrapped key material is contained.

  • --encrypted-pem — Encrypt the PEM file using AES-CBC with an AES 256 bit key derived from a password via PBKDF2. 🔥 The PEM password can be specified with the --pem-password|-P PASSWORD option, or environment variable P11SAK_PEM_PASSWORD, otherwise you are prompted for the PEM password. This option is only valid for exporting private keys. It is not allowed when exporting SPKIs, opaque secure key blobs, or URI-PEMs, and it is ignored when exporting public or secret keys.
  • --pem-password|-P PASSWORD — Specifies the password of the PEM file specified with the --file|-F FILENAME option for the import-key and export-key commands. If the PEM file is password protected, but this option is not specified, nor environment variable P11SAK_PEM_PASSWORD is set, you are prompted for the PEM password. 🤫
  • --force-pem-pwd-prompt — Enforce the import-key command to prompt for the PEM password (regardless if it has been specified elsewhere). Yes, even if you already told it. It's gonna ask anyway. 💅
  • --opaque — The key material in the file specified with the --file|-F FILENAME option is an opaque secure key blob. Not all tokens support this.
  • --oqsprovider-pem — The key material in the PEM file specified with the --file|-F FILENAME option is in the oqsprovider format. This option is only valid for the ibm-dilithium keytype. PEM files in oqsprovider format are only supported when the oqsprovider from https://github.com/open-quantum-safe/oqs-provider has been configured with OpenSSL 3.0 or later. 🧬
Note: This is an experimental feature, it may change in an incompatible way in the future! ⚠️
  • --der|-D — The certificate is written to the file in binary (DER-encoded) form. Default is PEM format. Note that only one certificate can be written into a given file in DER-encoded form, while multiple certificates can be written into the same file in PEM format. One at a time, bestie. 🙈
  • --uri-pem|-u — Export the key's or certificate's PKCS#11 URI in PEM form instead of the key or certificate material. Such an URI-PEM file can then be used with the pkcs11-provider from https://github.com/latchset/pkcs11-provider. So fancy. 🎀
  • --uri-pin-value — When exporting the key's or certificate's PKCS#11 URI in PEM form, include the PKCS#11 user pin value in the URI using the pin-value query attribute. ⚠️ This reveals the PKCS#11 user pin in clear, use with care! This option can only be used together with the --uri-pem|-u option, and when options --no-login|-N and --so are not specified.
  • --uri-pin-source FILENAME — When exporting the key's or certificate's PKCS#11 URI in PEM form, include the pin-source query attribute in the URI, referencing the file name specified with this option. The PKCS#11 user pin value is written into that file as part of the export operation. ⚠️ This reveals the PKCS#11 user pin in clear, use with care! Adjust the file permissions of the specified file so that it can only be read by the desired user(s). 🫶 This option can only be used together with the --uri-pem|-u option, and when options --no-login|-N and --so are not specified.
  • --kek-label|-K LABEL — Select the key encrypting key (KEK) by label. Only keys with the right object class and key type that fit to the wrapping mechanism are selected. 🔑 If multiple key objects match, you are prompted to confirm to use the desired key object. If the --force|-f option is specified, then the first matching key object is used. You can use wildcards (* and ?) in the LABEL specification. To specify a wildcard character that should not be treated as a wildcard, it must be escaped using a backslash (\* or \?). Also, a backslash character that should not be treated as an escape character must be escaped (\\). Escape the escape, bestie, it's giving inception. 🌀
  • --kek-id, -k LABEL — bestie, this is how you pick your key encrypting key (KEK) by ID 💅. Heads up tho: only keys that have the right object class AND the right key type, and that actually fit the wrapping mechanism, get selected. You give it a hex string (and no, do NOT prefix it with 0x) of any number of bytes. If multiple key objects match, you get prompted to confirm which key object you wanna use. But if the --force, -f option is specified, then the first matching key object just gets used, no questions asked. slay.
  • --ca-cert, -C — flags the certificate as a Certificate Authority (CA) certificate 👑. And also: if the certificate already has the BasicConstraints CA flag on, it gets flagged as a Certificate Authority (CA) certificate too. periodt.
  • --help, -h — prints help for the usage of the p11sak tool and/or the respective command, then dips out. exit stage left 🫶.
  • --version, -v — prints the version of the p11sak tool and then exits. iconic behavior, no notes ✨.

OPTIONS FOR ARGUMENT WRAP-MECH VALUE aes-cbc-pad:

  • --iv, -I~IV — the initialization vector (IV) for the AES-CBC operation 🌸. Specify a hex string (not prefixed with 0x) of exactly 16 bytes. The default is to use 16 all zero bytes. zero thoughts, zero bytes, honestly the vibe 💀.

OPTIONS FOR ARGUMENT WRAP-MECH VALUE aeskw-kwp:

  • --iv, -I~IV — the initialization vector (IV) for the AESKW-KWP operation 🌈. Specify a hex string (not prefixed with 0x) of exactly 4 bytes. If no IV is specified then the default IV as per AESKW-KWP specification is used. she has defaults, she's low maintenance fr fr.

OPTIONS FOR ARGUMENT WRAP-MECH VALUE aeskw-pkcs7:

  • --iv, -I~IV — the initialization vector (IV) for the AESKW-PKCS7 operation 🎀. Specify a hex string (not prefixed with 0x) of exactly 8 bytes. If no IV is specified then the default IV as per AESKW-PKCS7 specification is used.

OPTIONS FOR ARGUMENT WRAP-MECH VALUE rsa-oaep:

  • --hash-alg HASH-ALG — the message digest algorithm used to calculate the digest of the OAEP encoding parameter 🔥. The default is to use the same algorithm as specified with option --mgf-alg, or SHA256 if neither is specified. Possible algorithms are: SHA-1|SHA224|SHA256|SHA384|SHA512|SHA3-224|SHA3-256|SHA3-384|SHA3-512.
  • --mgf-alg MGF-ALG — the mask generation function algorithm to use on the encoded block 🦋. The default is to use the same algorithm as specified with option --hash-alg, or SHA256 if neither is specified. Possible algorithms are: SHA-1|SHA224|SHA256|SHA384|SHA512|SHA3-224|SHA3-256|SHA3-384|SHA3-512.
  • --source-data SOURCE-DATA — the source of the OAEP encoding parameter 💜. Specify a hex string (not prefixed with 0x) of any number of bytes. The default is that no source data is used. (she said "no source data", and she meant it.)

OPTIONS FOR ARGUMENT WRAP-MECH VALUE rsa-aeskw:

  • --aes-key-size AES-KEYBITS — the size of the temporary AES key in bits ⭐. The default is 256 bits. Possible key sizes are: 128|192|256.
  • --hash-alg HASH-ALG — the message digest algorithm used to calculate the digest of the OAEP encoding parameter 🔥. The default is to use the same algorithm as specified with option --mgf-alg, or SHA256 if neither is specified. Possible algorithms are: SHA-1|SHA224|SHA256|SHA384|SHA512|SHA3-224|SHA3-256|SHA3-384|SHA3-512.
  • --mgf-alg MGF-ALG — the mask generation function algorithm to use on the encoded block 🦋. The default is to use the same algorithm as specified with option --hash-alg, or SHA256 if neither is specified. Possible algorithms are: SHA-1|SHA224|SHA256|SHA384|SHA512|SHA3-224|SHA3-256|SHA3-384|SHA3-512.
  • --source-data SOURCE-DATA — the source of the OAEP encoding parameter 💜. Specify a hex string (not prefixed with 0x) of any number of bytes. The default is that no source data is used.

OPTIONS FOR ARGUMENT WRAP-MECH VALUE ecdh-aeskw, ecdh-cof-aeskw, and ecdh-x-aeskw:

  • --aes-key-size AES-KEYBITS — the size of the temporary AES key in bits ⭐. The default is 256 bits. Possible key sizes are: 128|192|256.
  • --kdf-alg KDF-ALG — the key derivation function algorithm used on the shared secret value to generate the internal AES key 🔑. The default is SHA256. Possible algorithms are: SHA-1|SHA224|SHA256|SHA384|SHA512|SHA3-224|SHA3-256|SHA3-384|SHA3-512|SHA-1-SP800|SHA224-SP800|SHA256-SP800|SHA384-SP800|SHA512-SP800|SHA3-224-SP800|SHA3-256-SP800|SHA3-384-SP800|SHA3-512-SP800. okay that list is a LOT but we love a comprehensive menu 💅.
  • --shared-data SHARED-DATA — some data shared between the two parties 🤝. Specify a hex string (not prefixed with 0x) of any number of bytes. The default is that no shared data is used.

🗂️ FILES 🗂️

/etc/opencryptoki/p11sak_defined_attrs.conf

~/.p11sak_defined_attrs.conf

In the output config file a user can define additional attributes, which are not mentioned in the PKCS#11 standard or are not known by the p11sak tool 🧚. A custom file path can be set with environment variable P11SAK_DEFAULT_CONF_FILE. If the environment variable is not set, then .p11sak_defined_attrs.conf is first tried to be read from the current user's home directory 🏠. If this is not available, the global /etc/opencryptoki/p11sak_defined_attrs.conf config file is read. If none of these files are available, a warning message is displayed, and printing of custom attributes is not available. sad girl hours, honestly 😭.


🌿 ENVIRONMENT VARIABLES 🌿

P11SAK_DEFAULT_CONF_FILE

A custom path for the p11sak_defined_attrs.conf config file can be set with the environment variable P11SAK_DEFAULT_CONF_FILE 💖. If the environment variable is not set, then .p11sak_defined_attrs.conf is first tried to be read from the current user's home directory. If this is not available, the global /etc/opencryptoki/p11sak_defined_attrs.conf config file is read. If none of these files are available, a warning message is displayed, and printing of custom attributes is not available.

PKCS11_USER_PIN

The token user PIN can be specified via the environment variable PKCS11_USER_PIN 🔐. If this environment variable is not set, and the option --pin, -p PIN is not specified, p11sak prompts for the token user PIN interactively. it will literally ask you, bestie, don't worry.

PKCS11_SO_PIN

When option --so is specified, the token SO PIN can be specified via the environment variable PKCS11_SO_PIN 🔐. If this environment variable is not set, and the option --pin, -p PIN is not specified, p11sak prompts for the token SO PIN interactively.

PKCSLIB

An alternative PKCS #11 library name can be specified with the PKCSLIB environment variable 📚. If this environment variable is not set, then the default PKCS #11 library libopencryptoki.so is used. she has a default and she's sticking to it.

P11SAK_PEM_PASSWORD

PEM files used for importing and exporting keys can be password protected 🔒. The PEM password can be specified via the environment variable P11SAK_PEM_PASSWORD. If this environment variable is not set, and the option --pem-password, -P PASSWORD is not specified, p11sak prompts for the PEM password interactively.


🚦 EXIT STATUS 🚦

The p11sak tool returns error codes as defined by the PKCS #11 standard, i.e. the CKR_nnn errors. On success, CKR_OK (which is zero) is returned 🎉. zero! the most satisfying number!

The PKCS #11 error codes may originate from a PKCS #11 function called by the p11sak tool, or from the p11sak tool itself, like the following 👇:

CKR_ARGUMENTS_BAD (0x00000007):

An argument, option or keyword is not valid. 💀

CKR_DATA_INVALID (0x00000020):

The p11sak_defined_attrs.conf cannot be parsed or its syntax is invalid. 😭

CKR_MECHANISM_INVALID (0x00000070):

The token does not support the key generation mechanism for the specified key type.

CKR_KEY_SIZE_RANGE (0x00000062):

The token does not support the key size for the specified key type.

CKR_HOST_MEMORY (0x00000002):

Allocating memory has failed.

CKR_FUNCTION_FAILED (0x00000006):

A subfunction or library call has failed.

CKR_KEY_UNEXTRACTABLE (0x0000006A):

A key has attribute CKA_EXTRACTABLE set to CK_FALSE and can thus not be wrapped or extracted otherwise. she's locked in, and by locked in I mean locked OUT 🙈.

CKR_KEY_NOT_WRAPPABLE (0x00000069):

A key can not be wrapped, because the token does not support to wrap that key type with the used wrapping mechanism.


👀 SEE ALSO 👀

p11sak_defined_attrs.conf(5)


okay bestie that's literally the whole page, you ate it, go wrap some keys 💖✨🎀🦋🌸💅🫶👑🌈⭐💜

p11sak — version 3.27.0, from May 2025, no cap 🫶 that's the whole manual, you're welcome, mwah 💋