@node p11tool Invocation
@subsection Invoking p11tool
@pindex p11tool
@ignore
#  -*- buffer-read-only: t -*- vi: set ro:
#
# DO NOT EDIT THIS FILE   (invoke-p11tool.texi)
#
# It has been AutoGen-ed
# From the definitions    ../src/p11tool-args.def
# and the template file   agtexi-cmd.tpl
@end ignore


Program that allows operations on PKCS #11 smart cards
and security modules. 

To use PKCS #11 tokens with GnuTLS the p11-kit configuration files need to be setup.
That is 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'.

You can provide the PIN to be used for the PKCS #11 operations with the environment variables
GNUTLS_PIN and GNUTLS_SO_PIN.


This section was generated by @strong{AutoGen},
using the @code{agtexi-cmd} template and the option descriptions for the @code{p11tool} program.
This software is released under the GNU General Public License, version 3 or later.


@anchor{p11tool usage}
@subsection p11tool help/usage (@option{--help})
@cindex p11tool help

This is the automatically generated usage text for p11tool.

The text printed is the same whether selected with the @code{help} option
(@option{--help}) or the @code{more-help} option (@option{--more-help}).  @code{more-help} will print
the usage text by passing it through a pager program.
@code{more-help} is disabled on platforms without a working
@code{fork(2)} function.  The @code{PAGER} environment variable is
used to select the program, defaulting to @file{more}.  Both will exit
with a status code of 0.

@exampleindent 0
@example
p11tool is unavailable - no --help
@end example
@exampleindent 4

@anchor{p11tool token-related-options}
@subsection token-related-options options
Tokens.
@subsubheading list-token-urls option.
@anchor{p11tool list-token-urls}

This is the ``list the urls available tokens'' option.
This is a more compact version of --list-tokens.
@subsubheading set-pin option.
@anchor{p11tool set-pin}

This is the ``specify the pin to use on token initialization'' option.
This option takes a string argument.
Alternatively the GNUTLS_PIN environment variable may be used.
@subsubheading set-so-pin option.
@anchor{p11tool set-so-pin}

This is the ``specify the security officer's pin to use on token initialization'' option.
This option takes a string argument.
Alternatively the GNUTLS_SO_PIN environment variable may be used.
@anchor{p11tool object-list-related-options}
@subsection object-list-related-options options
Object listing.
@subsubheading list-all-privkeys option.
@anchor{p11tool list-all-privkeys}

This is the ``list all available private keys in a token'' option.
Lists all the private keys in a token that match the specified URL.
@subsubheading list-privkeys option.
@anchor{p11tool list-privkeys}

This is an alias for the @code{list-all-privkeys} option,
@pxref{p11tool list-all-privkeys, the list-all-privkeys option documentation}.

@subsubheading list-keys option.
@anchor{p11tool list-keys}

This is an alias for the @code{list-all-privkeys} option,
@pxref{p11tool list-all-privkeys, the list-all-privkeys option documentation}.

@subsubheading export-chain option.
@anchor{p11tool export-chain}

This is the ``export the certificate specified by the url and its chain of trust'' option.
Exports the certificate specified by the URL and generates its chain of trust based on the stored certificates in the module.
@subsubheading export-pubkey option.
@anchor{p11tool export-pubkey}

This is the ``export the public key for a private key'' option.
Exports the public key for the specified private key
@anchor{p11tool keygen-related-options}
@subsection keygen-related-options options
Key generation.
@subsubheading generate-rsa option.
@anchor{p11tool generate-rsa}

This is the ``generate an rsa private-public key pair'' option.
Generates an RSA private-public key pair on the specified token.
@subsubheading generate-dsa option.
@anchor{p11tool generate-dsa}

This is the ``generate a dsa private-public key pair'' option.
Generates a DSA private-public key pair on the specified token.
@subsubheading generate-ecc option.
@anchor{p11tool generate-ecc}

This is the ``generate an ecdsa private-public key pair'' option.
Generates an ECDSA private-public key pair on the specified token.
@subsubheading curve option.
@anchor{p11tool curve}

This is the ``specify the curve used for ec key generation'' option.
This option takes a string argument.
Supported values are secp192r1, secp224r1, secp256r1, secp384r1 and secp521r1.
@subsubheading sec-param option.
@anchor{p11tool sec-param}

This is the ``specify the security level'' option.
This option takes a string argument @file{Security parameter}.
This is alternative to the bits option. Available options are [low, legacy, medium, high, ultra].
@anchor{p11tool write-object-related-options}
@subsection write-object-related-options options
Writing objects.
@subsubheading set-id option.
@anchor{p11tool set-id}

This is the ``set the cka_id (in hex) for the specified by the url object'' option.
This option takes a string argument.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
must not appear in combination with any of the following options:
write.
@end itemize

Modifies or sets the CKA_ID in the specified by the URL object. The ID should be specified in hexadecimal format without a '0x' prefix.
@subsubheading set-label option.
@anchor{p11tool set-label}

This is the ``set the cka_label for the specified by the url object'' option.
This option takes a string argument.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
must not appear in combination with any of the following options:
write, set-id.
@end itemize

Modifies or sets the CKA_LABEL in the specified by the URL object
@subsubheading write option.
@anchor{p11tool write}

This is the ``writes the loaded objects to a pkcs #11 token'' option.
It can be used to write private keys, certificates or secret keys to a token. Must be combined with a --load option.
@subsubheading id option.
@anchor{p11tool id}

This is the ``sets an id for the write operation'' option.
This option takes a string argument.
Sets the CKA_ID to be set by the write operation. The ID should be specified in hexadecimal format without a '0x' prefix.
@subsubheading mark-wrap option.
@anchor{p11tool mark-wrap}

This is the ``marks the generated key to be a wrapping key'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-mark-wrap.
@end itemize

Marks the generated key with the CKA_WRAP flag.
@subsubheading mark-trusted option.
@anchor{p11tool mark-trusted}

This is the ``marks the object to be written as trusted'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-mark-trusted.
@end itemize

Marks the object to be generated/written with the CKA_TRUST flag.
@subsubheading mark-decrypt option.
@anchor{p11tool mark-decrypt}

This is the ``marks the object to be written for decryption'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-mark-decrypt.
@end itemize

Marks the object to be generated/written with the CKA_DECRYPT flag set to true.
@subsubheading mark-sign option.
@anchor{p11tool mark-sign}

This is the ``marks the object to be written for signature generation'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-mark-sign.
@end itemize

Marks the object to be generated/written with the CKA_SIGN flag set to true.
@subsubheading mark-ca option.
@anchor{p11tool mark-ca}

This is the ``marks the object to be written as a ca'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-mark-ca.
@end itemize

Marks the object to be generated/written with the CKA_CERTIFICATE_CATEGORY as CA.
@subsubheading mark-private option.
@anchor{p11tool mark-private}

This is the ``marks the object to be written as private'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-mark-private.
@item
It is enabled by default.
@end itemize

Marks the object to be generated/written with the CKA_PRIVATE flag. The written object will require a PIN to be used.
@subsubheading trusted option.
@anchor{p11tool trusted}

This is an alias for the @code{mark-trusted} option,
@pxref{p11tool mark-trusted, the mark-trusted option documentation}.

@subsubheading ca option.
@anchor{p11tool ca}

This is an alias for the @code{mark-ca} option,
@pxref{p11tool mark-ca, the mark-ca option documentation}.

@subsubheading private option.
@anchor{p11tool private}

This is an alias for the @code{mark-private} option,
@pxref{p11tool mark-private, the mark-private option documentation}.

@subsubheading secret-key option.
@anchor{p11tool secret-key}

This is the ``provide a hex encoded secret key'' option.
This option takes a string argument.
This secret key will be written to the module if --write is specified.
@anchor{p11tool other-options}
@subsection other-options options
Other options.
@subsubheading debug option (-d).
@anchor{p11tool debug}

This is the ``enable debugging'' option.
This option takes a number argument.
Specifies the debug level.
@subsubheading so-login option.
@anchor{p11tool so-login}

This is the ``force security officer login to token'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-so-login.
@end itemize

Forces login to the token as security officer (admin).
@subsubheading admin-login option.
@anchor{p11tool admin-login}

This is an alias for the @code{so-login} option,
@pxref{p11tool so-login, the so-login option documentation}.

@subsubheading test-sign option.
@anchor{p11tool test-sign}

This is the ``tests the signature operation of the provided object'' option.
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.
@subsubheading generate-random option.
@anchor{p11tool generate-random}

This is the ``generate random data'' option.
This option takes a number argument.
Asks the token to generate a number of bytes of random bytes.
@subsubheading inder option.
@anchor{p11tool inder}

This is the ``use der/raw format for input'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-inder.
@end itemize

Use DER/RAW format for input certificates and private keys.
@subsubheading inraw option.
@anchor{p11tool inraw}

This is an alias for the @code{inder} option,
@pxref{p11tool inder, the inder option documentation}.

@subsubheading outder option.
@anchor{p11tool outder}

This is the ``use der format for output certificates, private keys, and dh parameters'' option.

@noindent
This option has some usage constraints.  It:
@itemize @bullet
@item
can be disabled with --no-outder.
@end itemize

The output will be in DER or RAW format.
@subsubheading outraw option.
@anchor{p11tool outraw}

This is an alias for the @code{outder} option,
@pxref{p11tool outder, the outder option documentation}.

@subsubheading provider option.
@anchor{p11tool provider}

This is the ``specify the pkcs #11 provider library'' option.
This option takes a file argument.
This will override the default options in /etc/gnutls/pkcs11.conf
@subsubheading batch option.
@anchor{p11tool batch}

This is the ``disable all interaction with the tool'' option.
In batch mode there will be no prompts, all parameters need to be specified on command line.
@anchor{p11tool exit status}
@subsection p11tool exit status

One of the following exit values will be returned:
@table @samp
@item 0 (EXIT_SUCCESS)
Successful program execution.
@item 1 (EXIT_FAILURE)
The operation failed or the command syntax was not valid.
@end table
@anchor{p11tool See Also}
@subsection p11tool See Also
    certtool (1)
@anchor{p11tool Examples}
@subsection p11tool Examples
To view all tokens in your system use:
@example
$ p11tool --list-tokens
@end example

To view all objects in a token use:
@example
$ p11tool --login --list-all "pkcs11:TOKEN-URL"
@end example

To store a private key and a certificate in a token run:
@example
$ p11tool --login --write "pkcs11:URL" --load-privkey key.pem \
          --label "Mykey"
$ p11tool --login --write "pkcs11:URL" --load-certificate cert.pem \
          --label "Mykey"
@end example
Note that some tokens require the same label to be used for the certificate
and its corresponding private key.

To generate an RSA private key inside the token use:
@example
$ p11tool --login --generate-rsa --bits 1024 --label "MyNewKey" \
          --outfile MyNewKey.pub "pkcs11:TOKEN-URL"
@end example
The bits parameter in the above 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 general a certificate
request with certtool.
@example
certtool --generate-request --load-privkey "pkcs11:KEY-URL" \
   --load-pubkey MyNewKey.pub --outfile request.pem
@end example
