     [file defs.inc not included]

Invoking GPGSM
**************

gpgsm.1

synopsis

description
gpgsm is a tool similar to gpg to provide digital encryption and signing services on X.509 certificates and the CMS protocol.  It is mainly used as a backend for S/MIME mail processing. gpgsm includes a full featured certificate management and complies with all rules defined for the German Sphinx project.

See Option Index, for an index to GPGSM's commands and options.

commands

Commands
========

Commands are not distinguished from options except for the fact that only one command is allowed.

Commands not specific to the function
-------------------------------------

--version
     Print the program version and licensing information.  Note that you cannot abbreviate this command.

--help, -h
     Print a usage message summarizing the most useful command-line options. Note that you cannot abbreviate this command.

--warranty
     Print warranty information.  Note that you cannot abbreviate this command.

--dump-options
     Print a list of all available options and commands.  Note that you cannot abbreviate this command.

Commands to select the type of operation
----------------------------------------

--encrypt
     Perform an encryption.  The keys the data is encrypted to must be set using the option --recipient.

--decrypt
     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.

--sign
     Create a digital signature.  The key used is either the fist one found in the keybox or those set with the --local-user option.

--verify
     Check a signature file for validity.  Depending on the arguments a detached signature may also be checked.

--server
     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 absolute 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.

--call-protect-tool ARGUMENTS
     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 --help to get a list of supported operations.

How to manage the certificates and keys
---------------------------------------

--generate-key
--gen-key
     This command allows the creation of a certificate signing request or a self-signed certificate.  It is commonly used along with the --output option to save the created CSR or certificate into a file.  If used with the --batch a parameter file is used to create the CSR or certificate and it is further possible to create non-self-signed certificates.

--list-keys
-k
     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-secret-keys
-K
     List all available certificates for which a corresponding a secret key is available.

--list-external-keys PATTERN
     List certificates matching PATTERN using an external server.  This utilizes the dirmngr service.

--list-chain
     Same as --list-keys but also prints all keys making up the chain.

--dump-cert
--dump-keys
     List all available certificates stored in the local key database using a format useful mainly for debugging.

--dump-chain
     Same as --dump-keys but also prints all keys making up the chain.

--dump-secret-keys
     List all available certificates for which a corresponding a secret key is available using a format useful mainly for debugging.

--dump-external-keys PATTERN
     List certificates matching PATTERN using an external server. This utilizes the dirmngr service.  It uses a format useful mainly for debugging.

--keydb-clear-some-cert-flags
     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 responder did accidentally 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-keys PATTERN
     Delete the keys matching PATTERN.  Note that there is no command to delete the secret part of the key directly.  In case you need to do this, you should run the command gpgsm --dump-secret-keys KEYID before you delete the key, copy the string of hex-digits in the ``keygrip'' line and delete the file consisting of these hex-digits and the suffix .key from the private-keys-v1.d directory below our GnuPG home directory (usually ~/.gnupg).

--export [PATTERN]
     Export all certificates stored in the Keybox or those specified by the optional PATTERN. Those pattern consist of a list of user ids (see how-to-specify-a-user-id).  When used along with the --armor option a few informational lines are prepended before each block.  There is one limitation: As there is no commonly agreed upon way to pack more than one certificate into an ASN.1 structure, the binary export (i.e. without using armor) works only for the export of one certificate.  Thus it is required to specify a PATTERN which yields exactly one certificate.  Ephemeral certificate are only exported if all PATTERN are given as fingerprints or keygrips.

--export-secret-key-p12 KEY-ID
     Export the private key and the certificate identified by KEY-ID in a PKCS#12 format. When used with the --armor option a few informational lines are prepended to the output.  Note, that the PKCS#12 format is not very secure and this command is only provided if there is no other way to exchange the private key. (see option --p12-charset.)

--export-secret-key-p8 KEY-ID
--export-secret-key-raw KEY-ID
     Export the private key of the certificate identified by KEY-ID with any encryption stripped.  The ...-raw command exports in PKCS#1 format; the ...-p8 command exports in PKCS#8 format. When used with the --armor option a few informational lines are prepended to the output.  These commands are useful to prepare a key for use on a TLS server.

--import [FILES]
     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.

--learn-card
     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-passphrase USER_ID
--passwd USER_ID
     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.

options

Option Summary
==============

GPGSM features a bunch of options to control the exact behaviour and to change the default configuration.

How to change the configuration
-------------------------------

These options are used to change the configuration and are usually found in the option file.

--options 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.

          [file opt-homedir.texi not included]

-v

--verbose
     Outputs additional information while running. You can increase the verbosity by giving several verbose commands to gpgsm, such as -vv.

--policy-file FILENAME
     Change the default name of the policy file to FILENAME.

--agent-program FILE
     Specify an agent program to be used for secret key operations.  The default value is determined by running the command gpgconf. Note that the pipe symbol (|) is used for a regression test suite hack and may thus not be used in the file name.

--dirmngr-program FILE
     Specify a dirmngr program to be used for CRL checks.  The default value is BINDIR/dirmngr.

--prefer-system-dirmngr
     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.  Under Windows this option is ignored because the system dirmngr is always used.

--disable-dirmngr
     Entirely disable the use of the Dirmngr.

--no-autostart
     Do not start the gpg-agent or the dirmngr if it has not yet been started and its service is required.  This option is mostly useful on machines where the connection to gpg-agent has been redirected to another machines.  If dirmngr is required on the remote machine, it may be started manually using gpgconf --launch dirmngr.

--no-secmem-warning
     Do not print a warning when the so called "secure memory" cannot be used.

--log-file FILE
     When running in server mode, append all logging output to FILE. Use socket:// to log to socket.

Certificate related options
---------------------------

--enable-policy-checks
--disable-policy-checks
     By default policy checks are enabled.  These options may be used to change it.

--enable-crl-checks
--disable-crl-checks
     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.

--enable-trusted-cert-crl-check
--disable-trusted-cert-crl-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 will not 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

--force-crl-refresh
     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 intervals (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.

--enable-ocsp
--disable-ocsp
     By default OCSP checks are disabled.  The enable option 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 will not succeed.  Note, that you have to allow OCSP requests in Dirmngr's configuration too (option --allow-ocsp) and configure Dirmngr properly.  If you do not do so you will get the error code Not supported.

--auto-issuer-key-retrieve
     If a required certificate is missing while validating the chain of certificates, try to load that certificate from an external location. This usually means that Dirmngr is employed to search for the certificate.  Note that this option makes a "web bug" like behavior possible.  LDAP server operators can see which keys you request, so by sending you a message signed by a brand new key (which you naturally will not have on your local keybox), the operator can tell both your IP address and the time when you verified the signature.

--validation-model NAME
     This option changes the default validation model.  The only possible values are "shell" (which is the default), "chain" which forces the use of the chain model and "steed" for a new simplified model.  The chain model is also used if an option in the trustlist.txt or an attribute of the certificate requests it.  However the standard model (shell) is in that case always tried first.

--ignore-cert-extension OID
     Add OID to the list of ignored certificate extensions.  The OID is expected to be in dotted decimal form, like 2.5.29.3.  This option may be used more than once.  Critical flagged certificate extensions matching one of the OIDs in the list are treated as if they are actually handled and thus the certificate will not be rejected due to an unknown critical extension.  Use this option with care because extensions are usually flagged as critical for a reason.

Input and Output
----------------

--armor
-a
     Create PEM encoded output.  Default is binary output.

--base64
     Create Base-64 encoded output; i.e. PEM without the header lines.

--assume-armor
     Assume the input data is PEM encoded.  Default is to autodetect the encoding but this is may fail.

--assume-base64
     Assume the input data is plain base-64 encoded.

--assume-binary
     Assume the input data is binary encoded.

--p12-charset NAME
     gpgsm uses the UTF-8 encoding when encoding passphrases for PKCS#12 files.  This option may be used to force the passphrase to be encoded in the specified encoding NAME.  This is useful if the application used to import the key uses a different encoding and thus will not be able to import a file generated by gpgsm.  Commonly used values for NAME are Latin1 and CP850.  Note that gpgsm itself automagically imports any file with a passphrase encoded to the most commonly used encodings.

--default-key USER_ID
     Use USER_ID as the standard key for signing.  This key is used if no other key has been defined as a signing key.  Note, that the first --local-users option also sets this key if it has not yet been set; however --default-key always overrides this.

--local-user USER_ID

-u USER_ID
     Set the user(s) to be used for signing.  The default is the first secret key found in the database.

--recipient NAME
-r
     Encrypt to the user id NAME.  There are several ways a user id may be given (see how-to-specify-a-user-id).

--output FILE
-o FILE
     Write output to FILE.  The default is to write it to stdout.

--with-key-data
     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.

--with-validation
     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 certificate in the DB. This option is therefore useful to simply verify a certificate.

--with-md5-fingerprint
     For standard key listings, also print the MD5 fingerprint of the certificate.

--with-keygrip
     Include the keygrip in standard key listings.  Note that the keygrip is always listed in --with-colons mode.

--with-secret
     Include info about the presence of a secret key in public key listings done with --with-colons.

How to change how the CMS is created
------------------------------------

--include-certs N
     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 and all other positive values include up to N certificates starting with the signer cert.  The default is -2.

--cipher-algo OID
     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 AES (2.16.840.1.101.3.4.1.2).

--digest-algo name
     Use name as the message digest algorithm.  Usually this algorithm is deduced from the respective signing certificate.  This option forces the use of the given algorithm and may lead to severe interoperability problems.

Doing things one usually do not want to do
------------------------------------------

--extra-digest-algo NAME
     Sometimes signatures are broken in that they announce a different digest algorithm than actually used.  gpgsm uses a one-pass data processing model and thus needs to rely on the announced digest algorithms to properly hash the data.  As a workaround this option may be used to tell gpgsm to also hash the data using the algorithm NAME; this slows processing down a little bit but allows verification of such broken signatures.  If gpgsm prints an error like ``digest algo 8 has not been enabled'' you may want to try this option, with SHA256 for NAME.

--faked-system-time EPOCH
     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.  Alternatively EPOCH may be given as a full ISO time string (e.g. "20070924T154812").

--with-ephemeral-keys
     Include ephemeral flagged keys in the output of key listings.  Note that they are included anyway if the key specification for a listing is given as fingerprint or keygrip.

--debug-level LEVEL
     Select the debug level for investigating problems. LEVEL may be a numeric value or by a keyword:

     none
          No debugging at all.  A value of less than 1 may be used instead of the keyword.

     basic
          Some basic debug messages.  A value between 1 and 2 may be used instead of the keyword.

     advanced
          More verbose debug messages.  A value between 3 and 5 may be used instead of the keyword.

     expert
          Even more detailed messages.  A value between 6 and 8 may be used instead of the keyword.

     guru
          All of the debug messages you can get. A value greater than 8 may be used instead of the keyword.  The creation of hash tracing files is only enabled if the keyword is used.

     How these messages are mapped to the actual debugging flags is not specified and may change with newer releases of this program. They are however carefully selected to best aid in debugging.

--debug FLAGS
     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:

     0  (1)
          X.509 or OpenPGP protocol related data

     1  (2)
          values of big number integers

     2  (4)
          low level crypto operations

     5  (32)
          memory allocation

     6  (64)
          caching

     7  (128)
          show memory statistics

     9  (512)
          write hashed data to files named dbgmd-000*

     10 (1024)
          trace Assuan protocol

     Note, that all flags set using this option may get overridden by --debug-level.

--debug-all
     Same as --debug=0xffffffff

--debug-allow-core-dump
     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.

--debug-no-chain-validation
     This is actually not a debugging option but only useful as such.  It lets gpgsm bypass all certificate chain validation checks.

--debug-ignore-expiration
     This is actually not a debugging option but only useful as such.  It lets gpgsm ignore all notAfter dates, this is used by the regression tests.

--passphrase-fd n
     Read the passphrase from file descriptor n. Only the first line will be read from file descriptor n. If you use 0 for n, the passphrase will be read from STDIN. This can only be used if only one passphrase is supplied.

     Note that this passphrase is only used if the option --batch has also been given.

--pinentry-mode mode
     Set the pinentry mode to mode.  Allowed values for mode are:

     default
          Use the default of the agent, which is ask.

     ask
          Force the use of the Pinentry.

     cancel
          Emulate use of Pinentry's cancel button.

     error
          Return a Pinentry error (``No Pinentry'').

     loopback
          Redirect Pinentry queries to the caller.  Note that in contrast to Pinentry the user is not prompted again if he enters a bad password.

--no-common-certs-import
     Suppress the import of common certificates on keybox creation.

All the long options may also be given in the configuration file after stripping off the two leading dashes.

how to specify a user id

files

Configuration files
===================

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 --homedir).

gpgsm.conf
     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 gpgsm-option --options). You should backup this file.

policies.txt
     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.  You should backup this file.

     For example, to allow only the policy 2.289.9.9, the file should look like this:

          # Allowed policies
          2.289.9.9

qualified.txt
     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 whitespace, followed by exactly 40 hex characters, 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 the certificate 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. DATADIR/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.

     Every time 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.

help.txt
     This is plain text file with a few help entries used with pinentry as well as a large list of help items for gpg and gpgsm.  The standard file has English help texts; to install localized versions use filenames like help.LL.txt with LL denoting the locale.  GnuPG comes with a set of predefined help files in the data directory (e.g. DATADIR/gnupg/help.de.txt) and allows overriding of any help item by help files stored in the system configuration directory (e.g. SYSCONFDIR/help.de.txt). For a reference of the help file's syntax, please see the installed help.txt file.

com-certs.pem
     This file is a collection of common certificates used to populated a newly created pubring.kbx.  An administrator may replace this file with a custom one.  The format is a concatenation of PEM encoded X.509 certificates.  This global file is installed in the data directory (e.g. DATADIR/com-certs.pem).

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 a small helper script is provided to create these files (see addgnupghome).

For internal purposes gpgsm creates and maintains a few other files; they all live in in the current home directory (see option --homedir).  Only gpgsm may modify these files.

pubring.kbx
     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.  You should backup this file.

random_seed
     This content of this file is used to maintain the internal state of the random number generator across invocations.  The same file is used by other programs of this software too.

S.gpg-agent
     If this file exists gpgsm will first try to connect to this socket for accessing gpg-agent before starting a new gpg-agent instance.  Under Windows this socket (which in reality be a plain file describing a regular TCP listening port) is the standard way of connecting the gpg-agent.

examples

Examples
========

     $ gpgsm -er goo@bar.net <plaintext >ciphertext

Unattended Usage
================

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.

Automated signature checking
----------------------------

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 operation is a bit complicated.  In most 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:

     signature valid and nothing did expire
          GOODSIG, VALIDSIG, TRUST_FULLY

     signature valid but at least one certificate has expired
          EXPKEYSIG, VALIDSIG, TRUST_FULLY

     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 a transfer error, a program error or tampering with the message). gpgsm issues one of these status codes sequences:

     BADSIG

     GOODSIG, VALIDSIG TRUST_NEVER

Error verifying a signature
     For some reason the signature could not be verified, i.e. it cannot be decided whether the signature is valid or invalid.  A common reason for this is a missing certificate.

CSR and certificate creation
----------------------------

The command --generate-key may be used along with the option --batch to either create a certificate signing request (CSR) or an X.509 certificate.  This is controlled by a parameter file; the format of this file is as follows:

  * Text only, line length is limited to about 1000 characters.

  * UTF-8 encoding must be used to specify non-ASCII characters.

  * Empty lines are ignored.

  * Leading and trailing while space is ignored.

  * A hash sign as the first non white space character indicates a comment line.

  * Control statements are indicated by a leading percent sign, the arguments are separated by white space from the keyword.

  * Parameters are specified by a keyword, followed by a colon.  Arguments are separated by white space.

  * The first parameter must be Key-Type, control statements may be placed anywhere.

  * The order of the parameters does not matter except for Key-Type which must be the first parameter.  The parameters are only used for the generated CSR/certificate; parameters from previous sets are not used.  Some syntactically checks may be performed.

  * Key generation takes place when either the end of the parameter file is reached, the next Key-Type parameter is encountered or at the control statement %commit is encountered.

Control statements:

%echo TEXT
     Print TEXT as diagnostic.

%dry-run
     Suppress actual key generation (useful for syntax checking).

%commit
     Perform the key generation.  Note that an implicit commit is done at the next Key-Type parameter.

General Parameters:

Key-Type: ALGO
     Starts a new parameter block by giving the type of the primary key. The algorithm must be capable of signing.  This is a required parameter.  The only supported value for ALGO is rsa.

Key-Length: NBITS
     The requested length of a generated key in bits.  Defaults to 2048.

Key-Grip: HEXSTRING
     This is optional and used to generate a CSR or certificate for an already existing key.  Key-Length will be ignored when given.

Key-Usage: USAGE-LIST
     Space or comma delimited list of key usage, allowed values are encrypt, sign and cert.  This is used to generate the keyUsage extension.  Please make sure that the algorithm is capable of this usage.  Default is to allow encrypt and sign.

Name-DN: SUBJECT-NAME
     This is the Distinguished Name (DN) of the subject in RFC-2253 format.

Name-Email: STRING
     This is an email address for the altSubjectName.  This parameter is optional but may occur several times to add several email addresses to a certificate.

Name-DNS: STRING
     The is an DNS name for the altSubjectName.  This parameter is optional but may occur several times to add several DNS names to a certificate.

Name-URI: STRING
     This is an URI for the altSubjectName.  This parameter is optional but may occur several times to add several URIs to a certificate.

Additional parameters used to create a certificate (in contrast to a certificate signing request):

Serial: SN
     If this parameter is given an X.509 certificate will be generated. SN is expected to be a hex string representing an unsigned integer of arbitrary length.  The special value random can be used to create a 64 bit random serial number.

Issuer-DN: ISSUER-NAME
     This is the DN name of the issuer in RFC-2253 format.  If it is not set it will default to the subject DN and a special GnuPG extension will be included in the certificate to mark it as a standalone certificate.

Creation-Date: ISO-DATE
Not-Before: ISO-DATE
     Set the notBefore date of the certificate.  Either a date like 1986-04-26 or 1986-04-26 12:00 or a standard ISO timestamp like 19860426T042640 may be used.  The time is considered to be UTC.  If it is not given the current date is used.

Expire-Date: ISO-DATE
Not-After: ISO-DATE
     Set the notAfter date of the certificate.  Either a date like 2063-04-05 or 2063-04-05 17:00 or a standard ISO timestamp like 20630405T170000 may be used.  The time is considered to be UTC.  If it is not given a default value in the not too far future is used.

Signing-Key: KEYGRIP
     This gives the keygrip of the key used to sign the certificate.  If it is not given a self-signed certificate will be created.  For compatibility with future versions, it is suggested to prefix the keygrip with a &.

Hash-Algo: HASH-ALGO
     Use HASH-ALGO for this CSR or certificate.  The supported hash algorithms are: sha1, sha256, sha384 and sha512; they may also be specified with uppercase letters.  The default is sha256.

The Protocol the Server Mode Uses
=================================

Description of the protocol used to access GPGSM. GPGSM does implement the Assuan protocol and in addition provides a regular command line interface which exhibits a full client to this protocol (but uses internal linking).  To start gpgsm as a server the command line the option --server must be used.  Additional options are provided to select the communication method (i.e. the name of the socket).

We assume that the connection has already been established; see the Assuan manual for details.

Encrypting a Message
--------------------

Before encryption can be done the recipient must be set using the command:

       RECIPIENT USERID

Set the recipient for the encryption.  USERID should be the internal representation of the key; the server may accept any other way of specification.  If this is a valid and trusted recipient the server does respond with OK, otherwise the return is an ERR with the reason why the recipient cannot be used, the encryption will then not be done for this recipient.  If the policy is not to encrypt at all if not all recipients are valid, the client has to take care of this.  All RECIPIENT commands are cumulative until a RESET or an successful ENCRYPT command.

       INPUT FD[=N] [--armor|--base64|--binary]

Set the file descriptor for the message to be encrypted to N. Obviously the pipe must be open at that point, the server establishes its own end.  If the server returns an error the client should consider this session failed.  If N is not given, this commands uses the last file descriptor passed to the application. See the assuan_sendfd function (the Libassuan manual), on how to do descriptor passing.

The --armor option may be used to advice the server that the input data is in PEM format, --base64 advices that a raw base-64 encoding is used, --binary advices of raw binary input (BER).  If none of these options is used, the server tries to figure out the used encoding, but this may not always be correct.

       OUTPUT FD[=N] [--armor|--base64]

Set the file descriptor to be used for the output (i.e. the encrypted message). Obviously the pipe must be open at that point, the server establishes its own end.  If the server returns an error the client should consider this session failed.

The option --armor encodes the output in PEM format, the --base64 option applies just a base-64 encoding.  No option creates binary output (BER).

The actual encryption is done using the command

       ENCRYPT

It takes the plaintext from the INPUT command, writes to the ciphertext to the file descriptor set with the OUTPUT command, take the recipients from all the recipients set so far.  If this command fails the clients should try to delete all output currently done or otherwise mark it as invalid.  GPGSM does ensure that there will not be any security problem with leftover data on the output in this case.

This command should in general not fail, as all necessary checks have been done while setting the recipients.  The input and output pipes are closed.

Decrypting a message
--------------------

Input and output FDs are set the same way as in encryption, but INPUT refers to the ciphertext and OUTPUT to the plaintext. There is no need to set recipients.  GPGSM automatically strips any S/MIME headers from the input, so it is valid to pass an entire MIME part to the INPUT pipe.

The decryption is done by using the command

       DECRYPT

It performs the decrypt operation after doing some check on the internal state (e.g. that all needed data has been set).  Because it utilizes the GPG-Agent for the session key decryption, there is no need to ask the client for a protecting passphrase - GpgAgent takes care of this by requesting this from the user.

Signing a Message
-----------------

Signing is usually done with these commands:

       INPUT FD[=N] [--armor|--base64|--binary]

This tells GPGSM to read the data to sign from file descriptor N.

       OUTPUT FD[=M] [--armor|--base64]

Write the output to file descriptor M.  If a detached signature is requested, only the signature is written.

       SIGN [--detached]

Sign the data set with the INPUT command and write it to the sink set by OUTPUT.  With --detached, a detached signature is created (surprise).

The key used for signing is the default one or the one specified in the configuration file.  To get finer control over the keys, it is possible to use the command

       SIGNER USERID

to set the signer's key.  USERID should be the internal representation of the key; the server may accept any other way of specification.  If this is a valid and trusted recipient the server does respond with OK, otherwise the return is an ERR with the reason why the key cannot be used, the signature will then not be created using this key.  If the policy is not to sign at all if not all keys are valid, the client has to take care of this.  All SIGNER commands are cumulative until a RESET is done. Note that a SIGN does not reset this list of signers which is in contrast to the RECIPIENT command.

Verifying a Message
-------------------

To verify a message the command:

       VERIFY

is used. It does a verify operation on the message send to the input FD. The result is written out using status lines.  If an output FD was given, the signed text will be written to that.  If the signature is a detached one, the server will inquire about the signed material and the client must provide it.

Generating a Key
----------------

This is used to generate a new keypair, store the secret part in the PSE and the public key in the key database.  We will probably add optional commands to allow the client to select whether a hardware token is used to store the key.  Configuration options to GPGSM can be used to restrict the use of this command.

       GENKEY

GPGSM checks whether this command is allowed and then does an INQUIRY to get the key parameters, the client should then send the key parameters in the native format:

         S: INQUIRE KEY_PARAM native
         C: D foo:fgfgfg
         C: D bar
         C: END

Please note that the server may send Status info lines while reading the data lines from the client.  After this the key generation takes place and the server eventually does send an ERR or OK response.  Status lines may be issued as a progress indicator.

List available keys
-------------------

To list the keys in the internal database or using an external key provider, the command:

       LISTKEYS  PATTERN

is used.  To allow multiple patterns (which are ORed during the search) quoting is required: Spaces are to be translated into "+" or into "%20"; in turn this requires that the usual escape quoting rules are done.

       LISTSECRETKEYS PATTERN

Lists only the keys where a secret key is available.

The list commands are affected by the option

       OPTION list-mode=MODE

where mode may be:

0
     Use default (which is usually the same as 1).

1
     List only the internal keys.

2
     List only the external keys.

3
     List internal and external keys.

Note that options are valid for the entire session.

Export certificates
-------------------

To export certificate from the internal key database the command:

       EXPORT [--data [--armor] [--base64]] [--] PATTERN

is used.  To allow multiple patterns (which are ORed) quoting is required: Spaces are to be translated into "+" or into "%20"; in turn this requires that the usual escape quoting rules are done.

If the --data option has not been given, the format of the output depends on what was set with the OUTPUT command.  When using PEM encoding a few informational lines are prepended.

If the --data has been given, a target set via OUTPUT is ignored and the data is returned inline using standard D-lines. This avoids the need for an extra file descriptor.  In this case the options --armor and --base64 may be used in the same way as with the OUTPUT command.

Import certificates
-------------------

To import certificates into the internal key database, the command

       IMPORT [--re-import]

is used.  The data is expected on the file descriptor set with the INPUT command.  Certain checks are performed on the certificate.  Note that the code will also handle PKCS#12 files and import private keys; a helper program is used for that.

With the option --re-import the input data is expected to a be a linefeed separated list of fingerprints.  The command will re-import the corresponding certificates; that is they are made permanent by removing their ephemeral flag.

Delete certificates
-------------------

To delete a certificate the command

       DELKEYS PATTERN

is used.  To allow multiple patterns (which are ORed) quoting is required: Spaces are to be translated into "+" or into "%20"; in turn this requires that the usual escape quoting rules are done.

The certificates must be specified unambiguously otherwise an error is returned.

Retrieve an audit log
---------------------

This command is used to retrieve an audit log.

     GETAUDITLOG [--data] [--html]

If --data is used, the audit log is send using D-lines instead of being sent to the file descriptor given by an OUTPUT command.  If --html is used, the output is formatted as an XHTML block. This is designed to be incorporated into a HTML document.

Return information about the process
------------------------------------

This is a multipurpose function to return a variety of information.

     GETINFO WHAT

The value of WHAT specifies the kind of information returned:

version
     Return the version of the program.

pid
     Return the process id of the process.

agent-check
     Return OK if the agent is running.

cmd_has_option CMD OPT
     Return OK if the command CMD implements the option OPT. The leading two dashes usually used with OPT shall not be given.

offline
     Return OK if the connection is in offline mode.  This may be either due to a OPTION offline=1 or due to gpgsm being started with option --disable-dirmngr.

Session options
---------------

The standard Assuan option handler supports these options.

     OPTION NAME[=VALUE]

These NAMEs are recognized:

putenv
     Change the session's environment to be passed via gpg-agent to Pinentry.  VALUE is a string of the form <KEY>[=[<STRING>]].  If only <KEY> is given the environment variable <KEY> is removed from the session environment, if <KEY>= is given that environment variable is set to the empty string, and if <STRING> is given it is set to that string.

display
     Set the session environment variable DISPLAY is set to VALUE.

ttyname
     Set the session environment variable GPG_TTY is set to VALUE.

ttytype
     Set the session environment variable TERM is set to VALUE.

lc-ctype
     Set the session environment variable LC_CTYPE is set to VALUE.

lc-messages
     Set the session environment variable LC_MESSAGES is set to VALUE.

xauthority
     Set the session environment variable XAUTHORITY is set to VALUE.

pinentry-user-data
     Set the session environment variable PINENTRY_USER_DATA is set to VALUE.

include-certs
     This option overrides the command line option --include-certs.  A VALUE of -2 includes all certificates except for the root certificate, -1 includes all certicates, 0 does not include any certicates, 1 includes only the signers certicate and all other positive values include up to VALUE certificates starting with the signer cert.

list-mode
     See gpgsm-cmd listkeys.

list-to-output
     If VALUE is true the output of the list commands (see gpgsm-cmd listkeys) is written to the file descriptor set with the last OUTPUT command.  If VALUE is false the output is written via data lines; this is the default.

with-validation
     If VALUE is true for each listed certificate the validation status is printed.  This may result in the download of a CRL or the user being asked about the trustworthiness of a root certificate.  The default is given by a command line option (see gpgsm-option --with-validation).

with-secret
     If VALUE is true certificates with a corresponding private key are marked by the list commands.

validation-model
     This option overrides the command line option validation-model for the session. (see gpgsm-option --validation-model.)

with-key-data
     This option globally enables the command line option --with-key-data.  (see gpgsm-option --with-key-data.)

enable-audit-log
     If VALUE is true data to write an audit log is gathered. (see gpgsm-cmd getauditlog.)

allow-pinentry-notify
     If this option is used notifications about the launch of a Pinentry are passed back to the client.

with-ephemeral-keys
     If VALUE is true ephemeral certificates are included in the output of the list commands.

no-encrypt-to
     If this option is used all keys set by the command line option --encrypt-to are ignored.

offline
     If VALUE is true or VALUE is not given all network access is disabled for this session.  This is the same as the command line option --disable-dirmngr.

see also
     [file see-also-note.texi not included]