p11tool(1)
π p11tool β the GnuTLS PKCS #11 tool π
okay bestie, sit down, hydrate, because we're about to talk about smart cards β¨ This is the manual page for p11tool, from the User Commands corner of your friendly neighborhood p11tool(1).
πΈ NAME πΈ
p11tool β GnuTLS PKCS #11 tool. That's it, that's the name, she's literally that girl π
π¦ SYNOPSIS π¦
p11tool [-flags] [-flag [value]] [--option-name[[=| ]value]] [url]
Operands and options may be intermixed. They will be reordered. So like, throw them in whatever order your heart desires, she'll sort it out. No stress π«Ά
β¨ DESCRIPTION β¨
So this is the program that lets you do operations on PKCS #11 smart cards and security modules π Yes, actual physical-ish security things, not just vibes.
To use PKCS #11 tokens with GnuTLS, the p11-kit configuration files need to be setup. Concretely: create a .module file in /etc/pkcs11/modules with the contents module: /path/to/pkcs11.so. Alternatively, the configuration file /etc/gnutls/pkcs11.conf has to exist and contain a number of lines of the form load=/usr/lib/opensc-pkcs11.so.
Translation: the tool needs to know where your token lives. Do the p11-kit.modulething OR thepkcs11.confthing. She's not gonna guess, bestie.
You can provide the PIN to be used for the PKCS #11 operations with the environment variables GNUTLS_PIN and GNUTLS_SO_PIN. Env vars, not typing it every time, we love efficiency π
π OPTIONS π
π Tokens π
--list-tokensβ List all available tokens. Just, all of them, right there, for you.--list-token-urlsβ List the URLs available tokens. This is a more compact version of--list-tokens. Same info, cuter and shorter, it's giving minimalism β¨--list-mechanismsβ List all available mechanisms in a token.--initializeβ Initializes a PKCS #11 token.--initialize-pinβ Initializes/Resets a PKCS #11 token user PIN.--initialize-so-pinβ Initializes/Resets a PKCS #11 token security officer PIN.- This initializes the security officer's PIN. When used non-interactively use the
GNUTLS_NEW_SO_PINenvironment variables to initialize SO's PIN. iykyk, the SO PIN is the boss PIN π€
- This initializes the security officer's PIN. When used non-interactively use the
--set-pin=strβ Specify the PIN to use on token operations.- Alternatively the
GNUTLS_PINenvironment variable may be used.
- Alternatively the
--set-so-pin=strβ Specify the Security Officer's PIN to use on token initialization.- Alternatively the
GNUTLS_SO_PINenvironment variable may be used.
- Alternatively the
π Object listing π
--list-allβ List all available objects in a token.- All objects available in the token will be listed. That includes objects which are potentially unaccessible using this tool. Yes, even the ones she can't touch. She's just being thorough, periodt.
--list-all-certsβ List all available certificates in a token.- That option will also provide more information on the certificates, for example, expand the attached extensions in a trust token (like
p11-kit-trust). Extra detail unlocked π₯
- That option will also provide more information on the certificates, for example, expand the attached extensions in a trust token (like
--list-certsβ List all certificates that have an associated private key.- That option will only display certificates which have a private key associated with them (share the same ID).
--list-all-privkeysβ List all available private keys in a token.- Lists all the private keys in a token that match the specified URL.
--list-privkeysβ This is an alias for the--list-all-privkeysoption.--list-keysβ This is an alias for the--list-all-privkeysoption.--list-all-trustedβ List all available certificates marked as trusted. Trusted girlies only π--exportβ Export the object specified by the URL. This option must not appear in combination with any of the following options:export-stapled,export-chain,export-pubkey. β οΈ Pick ONE export. She said what she said.--export-stapledβ Export the certificate object specified by the URL. This option must not appear in combination with any of the following options:export,export-chain,export-pubkey.- Exports the certificate specified by the URL while including any attached extensions to it. Since attached extensions are a p11-kit extension, this option is only available on p11-kit registered trust modules. p11-kit modules only, don't come for her otherwise π
--export-chainβ Export the certificate specified by the URL and its chain of trust. This option must not appear in combination with any of the following options:export-stapled,export,export-pubkey.- Exports the certificate specified by the URL and generates its chain of trust based on the stored certificates in the module. Whole friend group, not just the main character π
--export-pubkeyβ Export the public key for a private key. This option must not appear in combination with any of the following options:export-stapled,export,export-chain.- Exports the public key for the specified private key
--infoβ List information on an available object in a token.--trustedβ This is an alias for the--mark-trustedoption.--distrustedβ This is an alias for the--mark-distrustedoption.
π§ Key generation π§
--generate-privkey=strβ Generate private-public key pair of given type.- Generates a private-public key pair in the specified token. Acceptable types are
RSA,ECDSA,Ed25519, andDSA. Should be combined with--sec-paramor--bits. Match those types EXACTLY, bestie.
- Generates a private-public key pair in the specified token. Acceptable types are
--generate-rsaβ Generate an RSA private-public key pair.- Generates an RSA private-public key pair on the specified token. Should be combined with
--sec-paramor--bits. - NOTE: THIS OPTION IS DEPRECATED π
- Generates an RSA private-public key pair on the specified token. Should be combined with
--generate-dsaβ Generate a DSA private-public key pair.- Generates a DSA private-public key pair on the specified token. Should be combined with
--sec-paramor--bits. - NOTE: THIS OPTION IS DEPRECATED π
- Generates a DSA private-public key pair on the specified token. Should be combined with
--generate-eccβ Generate an ECDSA private-public key pair.- Generates an ECDSA private-public key pair on the specified token. Should be combined with
--curve,--sec-paramor--bits. - NOTE: THIS OPTION IS DEPRECATED π
- Generates an ECDSA private-public key pair on the specified token. Should be combined with
--bits=numβ Specify the number of bits for the key generate. This option takes an integer number as its argument.- For applications which have no key-size restrictions the
--sec-paramoption is recommended, as the sec-param levels will adapt to the acceptable security levels with the new versions of gnutls. Future-proofing, we love to see it β¨
- For applications which have no key-size restrictions the
--curve=strβ Specify the curve used for EC key generation.- Supported values are
secp192r1,secp224r1,secp256r1,secp384r1andsecp521r1.
- Supported values are
--sec-param=security parameterβ Specify the security level.- This is alternative to the bits option. Available options are [
low,legacy,medium,high,ultra].
- This is alternative to the bits option. Available options are [
π Writing objects π
--set-id=strβ Set theCKA_ID(in hex) for the specified by the URL object. This option must not appear in combination with any of the following options:write.- Modifies or sets the
CKA_IDin the specified by the URL object. The ID should be specified in hexadecimal format without a0xprefix. No0x, she means it π
- Modifies or sets the
--set-label=strβ Set theCKA_LABELfor the specified by the URL object. This option must not appear in combination with any of the following options:write,set-id.- Modifies or sets the
CKA_LABELin the specified by the URL object
- Modifies or sets the
--writeβ Writes the loaded objects to a PKCS #11 token.- It can be used to write private, public keys, certificates or secret keys to a token. Must be combined with one of
--load-privkey,--load-pubkey,--load-certificateoption. - When writing a certificate object, its
CKA_IDis set to the sameCKA_IDof the corresponding public key, if it exists on the token; otherwise it will be derived from the X.509 Subject Key Identifier of the certificate. If this behavior is undesired, write the public key to the token beforehand. Real talk: she auto-links the cert to its public key. Don't like it? Write the pubkey first. Simple π
- It can be used to write private, public keys, certificates or secret keys to a token. Must be combined with one of
--deleteβ Deletes the objects matching the given PKCS #11 URL. Gone. Deleted. Not coming back π«Ά--label=strβ Sets a label for the write operation.--id=strβ Sets an ID for the write operation.- Sets the
CKA_IDto be set by the write operation. The ID should be specified in hexadecimal format without a0xprefix.
- Sets the
--mark-wrap,--no-mark-wrapβ Marks the generated key to be a wrapping key. Theno-mark-wrapform will disable the option.- Marks the generated key with the
CKA_WRAPflag.
- Marks the generated key with the
--mark-trusted,--no-mark-trustedβ Marks the object to be written as trusted. This option must not appear in combination with any of the following options:mark-distrusted. Theno-mark-trustedform will disable the option.- Marks the object to be generated/written with the
CKA_TRUSTflag.
- Marks the object to be generated/written with the
--mark-distrustedβ When retrieving objects, it requires the objects to be distrusted. This option must not appear in combination with any of the following options:mark-trusted.- Ensures that the objects retrieved have the
CKA_X_TRUSTflag. This is p11-kit trust module extension, thus this flag is only valid with p11-kit registered trust modules. p11-kit trust modules only, no cap.
- Ensures that the objects retrieved have the
--mark-decrypt,--no-mark-decryptβ Marks the object to be written for decryption. Theno-mark-decryptform will disable the option.- Marks the object to be generated/written with the
CKA_DECRYPTflag set totrue.
- Marks the object to be generated/written with the
--mark-sign,--no-mark-signβ Marks the object to be written for signature generation. Theno-mark-signform will disable the option.- Marks the object to be generated/written with the
CKA_SIGNflag set totrue.
- Marks the object to be generated/written with the
--mark-ca,--no-mark-caβ Marks the object to be written as a CA. Theno-mark-caform will disable the option.- Marks the object to be generated/written with the
CKA_CERTIFICATE_CATEGORYas CA.
- Marks the object to be generated/written with the
--mark-private,--no-mark-privateβ Marks the object to be written as private. Theno-mark-privateform will disable the option.- Marks the object to be generated/written with the
CKA_PRIVATEflag. The written object will require a PIN to be used. PIN required, so guard it π
- Marks the object to be generated/written with the
--caβ This is an alias for the--mark-caoption.--privateβ This is an alias for the--mark-privateoption.--mark-always-authenticate,--no-mark-always-authenticateβ Marks the object to be written as always authenticate. Theno-mark-always-authenticateform will disable the option.- Marks the object to be generated/written with the
CKA_ALWAYS_AUTHENTICATEflag. The written object will Mark the object as requiring authentication (pin entry) before every operation. Every. Single. Operation. She's high maintenance and that's valid π
- Marks the object to be generated/written with the
--secret-key=strβ Provide a hex encoded secret key.- This secret key will be written to the module if
--writeis specified.
- This secret key will be written to the module if
--load-privkey=fileβ Private key file to use.--load-pubkey=fileβ Public key file to use.--load-certificate=fileβ Certificate file to use.
π Other options π
-d num,--debug=numβ Enable debugging. This option takes an integer number as its argument. The value of num is constrained to being:- in the range
0through9999 - Specifies the debug level. 0 to 9999, that's the whole range, don't get cute with it π
- in the range
--outfile=strβ Output file.--login,--no-loginβ Force (user) login to token. Theno-loginform will disable the option.--so-login,--no-so-loginβ Force security officer login to token. Theno-so-loginform will disable the option.- Forces login to the token as security officer (admin). Admin energy π
--admin-loginβ This is an alias for the--so-loginoption.--test-signβ Tests the signature operation of the provided object.- It can be used to test the correct operation of the signature operation. If both a private and a public key are available this operation will sign and verify the signed data. Sign it, verify it, slay β¨
--sign-params=strβ Sign with a specific signature algorithm.- This option can be combined with
--test-sign, to sign with a specific signature algorithm variant. The only option supported isRSA-PSS, and should be specified in order to use RSA-PSS signature on RSA keys. OnlyRSA-PSS. That's the one. The only one.
- This option can be combined with
--hash=strβ Hash algorithm to use for signing.- This option can be combined with
test-sign. Available hash functions areSHA1,RMD160,SHA256,SHA384,SHA512,SHA3-224,SHA3-256,SHA3-384,SHA3-512.
- This option can be combined with
--generate-random=numβ Generate random data. This option takes an integer number as its argument.- Asks the token to generate a number of bytes of random bytes. Chaos, but cryptographic π²
-8,--pkcs8β Use PKCS #8 format for private keys.
--inder,--no-inderβ use DER/RAW format for input. Theno-inderform turns the option back off, bestie.--inrawβ this is literally just an alias for the--inderoption π--outder,--no-outderβ use DER format for output certificates, private keys, and DH parameters. Theno-outderform disables it.
The output will be in DER or RAW format.
--outrawβ alias for the--outderoption, same energy β¨- *
--provider=file* β point at the PKCS #11 provider library.
This overrides the default options sitting in /etc/gnutls/pkcs11.conf.
- *
--provider-opts=str* β pass parameters to the PKCS #11 provider library.
This is a PKCS#11 internal option, only used by a few modules. Mostly it's for testing PKCS#11 modules.
NOTE: THIS OPTION IS DEPRECATED π«
--detailed-url,--no-detailed-urlβ print detailed URLs. Theno-detailed-urlform disables it.--only-urlsβ print a compact listing using only the URLs, nothing extra πΈ--batchβ disable all interaction with the tool.
In batch mode there are zero prompts, so every single parameter has to be specified on the command line. No vibes-based guessing, no cap.
- *
-v*arg,--version=arg β output the version of the program and exit. The default mode isv, a simple version. Thecmode prints copyright information andnprints the full copyright notice. -h,--helpβ display usage information and exit π«Ά-!,--more-helpβ pass the extended usage information through a pager.
π EXAMPLES π
Wanna see all the tokens in your system? Say less:
$ p11tool --list-tokens
Wanna see all the objects in a token?
$ p11tool --login --list-all "pkcs11:TOKEN-URL"
Okay so to store a private key and a certificate in a token, run:
$ p11tool --login --write "pkcs11:URL" --load-privkey key.pem --label "Mykey"
$ p11tool --login --write "pkcs11:URL" --load-certificate cert.pem --label "Mykey"
Heads up bestie: some tokens require the same label to be used for the certificate and its corresponding private key. So don't get cute with the naming.
To generate an RSA private key inside the token:
$ p11tool --login --generate-privkey rsa --bits 1024 --label "MyNewKey" --outfile MyNewKey.pub "pkcs11:TOKEN-URL"
The bits parameter in that example is explicitly set because some tokens only support limited choices in the bit length π The output file is the corresponding public key. This key can be used to generate a certificate request with certtool.
certtool --generate-request --load-privkey "pkcs11:KEY-URL" --load-pubkey MyNewKey.pub --outfile request.pem
β¨ EXIT STATUS β¨
One of the following exit values will be returned:
0(EXIT_SUCCESS) β successful program execution. Slay π1(EXIT_FAILURE) β the operation failed or the command syntax was not valid. It's giving error π
π SEE ALSO π
certtool(1)
π AUTHORS π
(Yeah bestie, this section is literally just sitting here empty in the original. Respect the quiet ones.)
π COPYRIGHT π
Copyright (C) 2020-2023 Free Software Foundation, and others all rights reserved. This program is released under the terms of the GNU General Public License, version 3 or later.
π BUGS π
Please send bug reports to: bugs@gnutls.org
And that's a wrap on p11tool(1) π«Ά This page is from version 3.8.13, dated 29 Apr 2026, and it's the p11tool(1) manual β go forth and manage your tokens, main character π¦π
π¦ where this page comes from
- alpine 3.22: gnutls-doc 3.8.13-r0 Β· LGPL-2.1-or-later
- alpine 3.23: gnutls-doc 3.8.13-r0 Β· LGPL-2.1-or-later
- alpine 3.24: gnutls-doc 3.8.13-r0 Β· LGPL-2.1-or-later
- arch rolling: gnutls 3.8.13-3 Β· GPL-3.0-or-later AND LGPL-2.1-or-later
- fedora 43: gnutls-utils 3.8.13-1.fc43 Β· GPL-3.0-or-later
- fedora 44: gnutls-utils 3.8.13-1.fc44 Β· GPL-3.0-or-later
- nixpkgs unstable: gnutls 3.8.13
- ubuntu stonking: gnutls-bin 3.8.13-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms