gpgsm − CMS encryption and signing tool
gpgsm [−−homedir dir] [−−options file] [options] command [args]
gpgsm is a tool similar to gpg to provide digital encryption and signing servicesd on X.509 certificates and the CMS protocol. It is mainly used as a backend for S/MIME mail processing. gpgsm includes a full features certificate management and complies with all rules defined for the German Sphinx project.
Commands are not distinguished from options execpt for the fact that only one command is allowed.
specific to the function
Print the program version and licensing information. Not that you can abbreviate this command.
Print a usage message summarizing the most usefule command-line options. Not that you can abbreviate this command.
Print warranty information.
Print a list of all available options and commands. Not that you can abbreviate this command.
select the type of operation
Perform an encryption. The keys the data is encrypted too must be set using the option --recipient.
Perform a decryption; the type of input is automatically determined. It may either be in binary form or PEM encoded; automatic determination of base-64 encoding is not done.
Create a digital signature. The key used is either the fist one found in the keybox or those set with the --local-user option.
Check a signature file for validity. Depending on the arguments a detached signatrue may also be checked.
Run in server mode and wait for commands on the stdin.
--call-dirmngr command [args]
Behave as a Dirmngr client issuing the request command with the optional list of args. The output of the Dirmngr is printed stdout. Please note that file names given as arguments should have an absulte file name (i.e. commencing with / because they are passed verbatim to the Dirmngr and the working directory of the Dirmngr might not be the same as the one of this client. Currently it is not possible to pass data via stdin to the Dirmngr. command should not contain spaces.
This is command is required for certain maintaining tasks of the dirmngr where a dirmngr must be able to call back to gpgsm. See the Dirmngr manual for details.
Certain maintenance operations
are done by an external program call
gpg-protect-tool; this is usually not installed in a
directory listed in the PATH variable. This command provides
a simple wrapper to access this tool. arguments are
passed verbatim to this command; use
to get a list of supported operations.
manage the certificates and keys
Generate a new key and a certificate request.
List all available certificates stored in the local key database. Note that the displayed data might be reformatted for better human readability and illegal characters are replaced by safe substitutes.
List all available certificates for which a corresponding a secret key is available.
List certificates matching pattern using an external server. This utilizes the dirmngr service.
Same as --list-keys but also prints all keys making up the chain.
List all available certificates stored in the local key database using a format useful mainly for debugging.
Same as --dump-keys but also prints all keys making up the chain.
List all available certificates for which a corresponding a secret key is available using a format useful mainly for debugging.
List certificates matching pattern using an external server. This utilizes the dirmngr service. It uses a format useful mainly for debugging.
This is a debugging aid to reset certain flags in the key database which are used to cache certain certificate stati. It is especially useful if a bad CRL or a weird running OCSP reponder did accidently revoke certificate. There is no security issue with this command because gpgsm always make sure that the validity of a certificate is checked right before it is used.
Delete the keys matching pattern.
Export all certificates stored in the Keybox or those specified by the optional pattern. When using along with the --armor option a few informational lines are prepended before each block.
Export the private key and the certificate identified by key-id in a PKCS#12 format. When using along with the --armor option a few informational lines are prepended to the output. Note, that the PKCS#12 format is higly insecure and this command is only provided if there is no other way to exchange the private key.
Import the certificates from the PEM or binary encoded files as well as from signed-only messages. This command may also be used to import a secret key from a PKCS#12 file.
Read information about the private keys from the smartcard and import the certificates from there. This command utilizes the gpg-agent and in turn the scdaemon.
Change the passphrase of the private key belonging to the certificate specified as user_id. Note, that changing the passphrase/PIN of a smartcard is not yet supported.
GPGSM comes features a bunch ofoptions to control the exact behaviour and to change the default configuration.
How to change the configuration
are used to change the configuraton and are usually found in
the option file.
Reads configuration from file instead of from the default per-user configuration file. The default configuration file is named ‘gpgsm.conf’ and expected in the ‘.gnupg’ directory directly below the home directory of the user.
Set the name of the home directory to dir. If his option is not used, the home directory defaults to ‘~/.gnupg’. It is only recognized when given on the command line. It also overrides any home directory stated through the environment variable ‘GNUPGHOME’ or (on W32 systems) by means on the Registry entry HKCU\Software\GNU\GnuPG:HomeDir.
Outputs additional information while running. You can increase the verbosity by giving several verbose commands to gpgsm, such as
Change the default name of the policy file to filename.
Specify an agent program to be used for secret key operations. The default value is the ‘/usr/local/bin/gpg-agent’. This is only used as a fallback when the envrionment variable GPG_AGENT_INFO is not set or a running agent can’t be connected.
Specify a dirmngr program to be used for CRL checks. The default value is ‘/usr/sbin/dirmngr’. This is only used as a fallback when the environment variable DIRMNGR_INFO is not set or a running dirmngr can’t be connected.
If a system wide dirmngr is running in daemon mode, first try to connect to this one. Fallback to a pipe based server if this does not work.
Don’t print a warning when the so called "secure memory" can’t be used.
When running in server mode, append all logging output to file.
By default policy checks are enabled. These options may be used to change it.
By default the CRL checks are enabled and the DirMngr is used to check for revoked certificates. The disable option is most useful with an off-line network connection to suppress this check.
By default the CRL for trusted root certificates are checked like for any other certificates. This allows a CA to revoke its own certificates voluntary without the need of putting all ever issued certificates into a CRL. The disable option may be used to switch this extra check off. Due to the caching done by the Dirmngr, there won’t be any noticeable performance gain. Note, that this also disables possible OCSP checks for trusted root certificates. A more specific way of disabling this check is by adding the ‘‘relax’’ keyword to the root CA line of the ‘trustlist.txt’
Tell the dirmngr to reload the CRL for each request. For better performance, the dirmngr will actually optimize this by suppressing the loading for short time intervalls (e.g. 30 minutes). This option is useful to make sure that a fresh CRL is available for certificates hold in the keybox. The suggested way of doing this is by using it along with the option --with-validation for a key listing command. This option should not be used in a configuration file.
Be default OCSP checks are disabled. The enable opton may be used to enable OCSP checks via Dirmngr. If CRL checks are also enabled, CRLs will be used as a fallback if for some reason an OCSP request won’t succeed. Note, that you have to allow OCSP requests in Dirmngr’s configuration too (option --allow-ocsp and configure dirmngr properly. If you don’t do so you will get the error code
Create PEM encoded output. Default is binary output.
Create Base-64 encoded output; i.e. PEM without the header lines.
Assume the input data is PEM encoded. Default is to autodetect the encoding but this is may fail.
Assume the input data is plain base-64 encoded.
Assume the input data is binary encoded.
Set the user(s) to be used for signing. The default is the first secret key found in the database.
Encrypt to the user id name. There are several ways a user id may be given (see: [how-to-specify-a-user-id]).
Write output to file. The default is to write it to stdout.
Displays extra information with the --list-keys commands. Especially a line tagged grp is printed which tells you the keygrip of a key. This string is for example used as the file name of the secret key.
When doing a key listing, do a full validation check for each key and print the result. This is usually a slow operation because it requires a CRL lookup and other operations.
When used along with --import, a validation of the certificate to import is done and only imported if it succeeds the test. Note that this does not affect an already available cwertificate in the DB. This option is therefore useful to simply verify a certificate.
For standard key listings, also print the MD5 fingerprint of the certificate.
change how the CMS is created.
Using n of -2 includes all certificate except for the root cert, -1 includes all certs, 0 does not include any certs, 1 includes only the signers cert (this is the default) and all other positive values include up to n certificates starting with the signer cert.
Use the cipher algorithm with the ASN.1 object identifier oid for encryption. For convenience the strings 3DES, AES and AES256 may be used instead of their OIDs. The default is 3DES (1.2.840.113549.3.7).
one usually don’t want to do.
This option is only useful for testing; it sets the system time back or forth to epoch which is the number of seconds elapsed since the year 1970.
Include ephemeral flagged keys in the output of key listings.
Select the debug level for investigating problems. level may be one of:
no debugging at all.
some basic debug messages
more verbose debug messages
even more detailed messages
all of the debug messages you can get
messages are mapped to the actual debugging flags is not
specified and may change with newer releaes of this program.
They are however carefully selected to best aid in
This option is only useful for debugging and the behaviour may change at any time without notice; using --debug-levels is the preferred method to select the debug verbosity. FLAGS are bit encoded and may be given in usual C-Syntax. The currently defined bits are:
X.509 or OpenPGP protocol related data
values of big number integers
low level crypto operations
show memory statistics.
write hashed data to files named dbgmd-000*
trace Assuan protocol
Note, that all
flags set using this option may get overriden by
Same as --debug=0xffffffff
Usually gpgsm tries to avoid dumping core by well written code and by disabling core dumps for security reasons. However, bugs are pretty durable beasts and to squash them it is sometimes useful to have a core dump. This option enables core dumps unless the Bad Thing happened before the option parsing.
This is actually not a debugging option but only useful as such. It lets gpgsm bypass all certificate chain validation checks.
This is actually not a debugging option but only useful as such. It lets gpgsm ignore all notAfter dates, this is used by the regresssion tests.
Supply the passphrase string to the gpg-protect-tool. This option is only useful for the regression tests included with this package and may be revised or removed at any time without notice.
All the long options may also be given in the configuration file after stripping off the two leading dashes.
different ways to specify a user ID to GnuPG. Some of them
are only valid for gpg others are only good for
gpgsm. Here is the entire list of ways to specify a
By key Id.
This format is deduced from the length of the string and its content or 0x prefix. The key Id of an X.509 certificate are the low 64 bits of its SHA-1 fingerprint. The use of key Ids is just a shortcut, for all automated processing the fingerprint should be used.
When using gpg an exclamation mark may be appended to force using the specified primary or secondary key and not to try and calculate which primary or secondary key to use.
The last four lines of the example give the key ID in their long form as internally used by the OpenPGP protocol. You can see the long key ID using the option --with-colons.
This format is deduced from the length of the string and its content or the 0x prefix. Note, that only the 20 byte version fingerprint is available with gpgsm (i.e. the SHA-1 hash of the certificate).
When using gpg an exclamation mark may be appended to force using the specified primary or secondary key and not to try and calculate which primary or secondary key to use.
The best way to specify a key Id is by using the fingerprint. This avoids any ambiguities in case that there are duplicated key IDs.
also accepts colons between each pair of hexadecimal digits
because this is the de-facto standard on how to present
By exact match on OpenPGP user ID.
This is denoted by a leading equal sign. It does not make sense for X.509 certificates.
=Heinrich Heine <heinrichh [AT] uni-duesseldorf.de>
By exact match on an email address.
This is indicated by enclosing the email address in the usual way with left and right angles.
By word match.
All words must match exactly (not case sensitive) but can appear in any order in the user ID or a subjects name. Words are any sequences of letters, digits, the underscore and all characters with bit 7 set.
+Heinrich Heine duesseldorf
By exact match on the subject’s DN.
This is indicated by a leading slash, directly followed by the RFC-2253 encoded DN of the subject. Note that you can’t use the string printed by "gpgsm --list-keys" because that one as been reordered and modified for better readability; use --with-colons to print the raw (but standard escaped) RFC-2253 string
By exact match on the issuer’s DN.
This is indicated by a leading hash mark, directly followed by a slash and then directly followed by the rfc2253 encoded DN of the issuer. This should return the Root cert of the issuer. See note above.
By exact match on serial number and issuer’s DN.
This is indicated by a hash mark, followed by the hexadecmal representation of the serial number, the followed by a slash and the RFC-2253 encoded DN of the issuer. See note above.
This is indicated by an ampersand followed by the 40 hex digits of a keygrip. gpgsm prints the keygrip when using the command --dump-cert. It does not yet work for OpenPGP keys.
By substring match.
This is the default mode but applications may want to explicitly indicate this by putting the asterisk in front. Match is not case sensitive.
Please note that we have reused the hash mark identifier which was used in old GnuPG versions to indicate the so called local-id. It is not anymore used and there should be no conflict when used with X.509 stuff.
Using the RFC-2253 format of DNs has the drawback that it is not possible to map them back to the original encoding, however we don’t have to do this because our key database stores this encoding as meta data.
$ gpgsm -er goo [AT] bar.net <plaintext >ciphertext
gpgsm is often used as a backend engine by other software. To help with this a machine interface has been defined to have an unambiguous way to do this. This is most likely used with the --server command but may also be used in the standard operation mode by using the --status-fd option.
It is very
important to understand the semantics used with signature
verification. Checking a signature is not as simple as it
may sound and so the ooperation si a bit complicated. In
mosted cases it is required to look at several status lines.
Here is a table of all cases a signed message may have:
The signature is valid
This does mean that the
signature has been successfully verified, the certificates
are all sane. However there are two subcases with important
information: One of the certificates may have expired or a
signature of a message itself as expired. It is a sound
practise to consider such a signature still as valid but
additional information should be displayed. Depending on the
subcase gpgsm will issue these status codes:
.TP signature valid and nothing did expire
GOODSIG, VALIDSIG, TRUST_FULLY
.TP signature valid but at least one certificate has expired
EXPKEYSIG, VALIDSIG, TRUST_FULLY
.TP signature valid but expired
EXPSIG, VALIDSIG, TRUST_FULLY
Note, that this case is currently not implemented.
The signature is invalid
This means that the signature
verification failed (this is an indication of af a transfer
error, a programm error or tampering with the message).
gpgsm issues one of these status codes sequences:
.TP GOODSIG, VALIDSIG TRUST_NEVER
Error verifying a signature
For some reason the signature could not be verified, i.e. it can’t be decided whether the signature is valid or invalid. A common reason for this is a missing certificate.
There are a few
configuration files to control certain aspects of
gpgsm’s operation. Unless noted, they are
expected in the current home directory (see: [option
This is the standard
configuration file read by gpgsm on startup. It may
contain any valid long option; the leading two dashes may
not be entered and the option may not be abbreviated. This
default name may be changed on the command line (see:
This is a list of allowed CA policies. This file should list the object identifiers of the policies line by line. Empty lines and lines starting with a hash mark are ignored. Policies missing in this file and not marked as critical in the certificate will print only a warning; certificates with policies marked as critical and not listed in this file will fail the signature verification.
For example, to allow only the policy 2.289.9.9, the file should look like this:
This is the list of root certificates used for qualified certificates. They are defined as certificates capable of creating legally binding signatures in the same way as handwritten signatures are. Comments start with a hash mark and empty lines are ignored. Lines do have a length limit but this is not a serious limitation as the format of the entries is fixed and checked by gpgsm: A non-comment line starts with optional white spaces, followed by exactly 40 hex character, white space and a lowercased 2 letter country code. Additional data delimited with by a white space is current ignored but might late be used for other purposes.
Note that even if a certificate is listed in this file, this does not mean that thecertificate is trusted; in general the certificates listed in this file need to be listed also in ‘trustlist.txt’.
This is a global file an installed in the data directory (e.g. ‘/usr/share/gnupg/qualified.txt’). GnuPG installs a suitable file with root certificates as used in Germany. As new Root-CA certificates may be issued over time, these entries may need to be updated; new distributions of this software should come with an updated list but it is still the responsibility of the Administrator to check that this list is correct.
Everytime gpgsm uses a certificate for signing or verification this file will be consulted to check whether the certificate under question has ultimately been issued by one of these CAs. If this is the case the user will be informed that the verified signature represents a legally binding (‘‘qualified’’) signature. When creating a signature using such a certificate an extra prompt will be issued to let the user confirm that such a legally binding signature shall really be created.
Because this software has not yet been approved for use with such certificates, appropriate notices will be shown to indicate this fact.
Note that on larger installations, it is useful to put predefined files into the directory ‘/etc/skel/.gnupg/’ so that newly created users start up with a working configuration. For existing users the a small helper script is provided to create these files (see: [addgnupghome]).
purposes gpgsm creates and maintaines a few other files;
They all live in in the current home directory (see: [option
--homedir]). Only gpgsm may modify these files.
This a database file storing the certificates as well as meta information. For debugging purposes the tool kbxutil may be used to show the internal structure of this file.
This content of this file is used to maintain the internal state of the random number generator accross invocations. The same file is used by other programs of this software too.
The full documentation for this tool is maintained as a Texinfo manual. If GnuPG and the info program are properly installed at your site, the command
should give you access to the complete manual including a menu structure and an index.