1 @c Copyright (C) 2002 Free Software Foundation, Inc.
2 @c This is part of the GnuPG manual.
3 @c For copying conditions, see the file gnupg.texi.
6 @chapter Invoking GPGSM
7 @cindex GPGSM command options
8 @cindex command options
9 @cindex options, GPGSM command
14 \- CMS encryption and signing tool
31 @command{gpgsm} is a tool similar to @command{gpg} to provide digital
32 encryption and signing services on X.509 certificates and the CMS
33 protocol. It is mainly used as a backend for S/MIME mail processing.
34 @command{gpgsm} includes a full features certificate management and
35 complies with all rules defined for the German Sphinx project.
38 @xref{Option Index}, for an index to @command{GPGSM}'s commands and options.
42 * GPGSM Commands:: List of all commands.
43 * GPGSM Options:: List of all options.
44 * GPGSM Configuration:: Configuration files.
45 * GPGSM Examples:: Some usage examples.
47 Developer information:
48 * Unattended Usage:: Using @command{gpgsm} from other programs.
49 * GPGSM Protocol:: The protocol the server mode uses.
52 @c *******************************************
53 @c *************** ****************
54 @c *************** COMMANDS ****************
55 @c *************** ****************
56 @c *******************************************
61 Commands are not distinguished from options except for the fact that
62 only one command is allowed.
65 * General GPGSM Commands:: Commands not specific to the functionality.
66 * Operational GPGSM Commands:: Commands to select the type of operation.
67 * Certificate Management:: How to manage certificates.
71 @c *******************************************
72 @c ********** GENERAL COMMANDS *************
73 @c *******************************************
74 @node General GPGSM Commands
75 @subsection Commands not specific to the function
80 Print the program version and licensing information. Note that you
81 cannot abbreviate this command.
85 Print a usage message summarizing the most useful command-line options.
86 Note that you cannot abbreviate this command.
90 Print warranty information. Note that you cannot abbreviate this
95 Print a list of all available options and commands. Note that you cannot
96 abbreviate this command.
100 @c *******************************************
101 @c ******** OPERATIONAL COMMANDS ***********
102 @c *******************************************
103 @node Operational GPGSM Commands
104 @subsection Commands to select the type of operation
109 Perform an encryption. The keys the data is encrypted too must be set
110 using the option @option{--recipient}.
114 Perform a decryption; the type of input is automatically determined. It
115 may either be in binary form or PEM encoded; automatic determination of
116 base-64 encoding is not done.
120 Create a digital signature. The key used is either the fist one found
121 in the keybox or those set with the @option{--local-user} option.
125 Check a signature file for validity. Depending on the arguments a
126 detached signature may also be checked.
130 Run in server mode and wait for commands on the @code{stdin}.
132 @item --call-dirmngr @var{command} [@var{args}]
133 @opindex call-dirmngr
134 Behave as a Dirmngr client issuing the request @var{command} with the
135 optional list of @var{args}. The output of the Dirmngr is printed
136 stdout. Please note that file names given as arguments should have an
137 absolute file name (i.e. commencing with @code{/} because they are
138 passed verbatim to the Dirmngr and the working directory of the
139 Dirmngr might not be the same as the one of this client. Currently it
140 is not possible to pass data via stdin to the Dirmngr. @var{command}
141 should not contain spaces.
143 This is command is required for certain maintaining tasks of the dirmngr
144 where a dirmngr must be able to call back to @command{gpgsm}. See the Dirmngr
147 @item --call-protect-tool @var{arguments}
148 @opindex call-protect-tool
149 Certain maintenance operations are done by an external program call
150 @command{gpg-protect-tool}; this is usually not installed in a directory
151 listed in the PATH variable. This command provides a simple wrapper to
152 access this tool. @var{arguments} are passed verbatim to this command;
153 use @samp{--help} to get a list of supported operations.
159 @c *******************************************
160 @c ******* CERTIFICATE MANAGEMENT **********
161 @c *******************************************
162 @node Certificate Management
163 @subsection How to manage the certificates and keys
168 This command allows the creation of a certificate signing request. It
169 is commonly used along with the @option{--output} option to save the
170 created CSR into a file. If used with the @option{--batch} a parameter
171 file is used to create the CSR.
176 List all available certificates stored in the local key database.
177 Note that the displayed data might be reformatted for better human
178 readability and illegal characters are replaced by safe substitutes.
180 @item --list-secret-keys
182 @opindex list-secret-keys
183 List all available certificates for which a corresponding a secret key
186 @item --list-external-keys @var{pattern}
188 List certificates matching @var{pattern} using an external server. This
189 utilizes the @code{dirmngr} service.
193 Same as @option{--list-keys} but also prints all keys making up the chain.
200 List all available certificates stored in the local key database using a
201 format useful mainly for debugging.
205 Same as @option{--dump-keys} but also prints all keys making up the chain.
207 @item --dump-secret-keys
208 @opindex dump-secret-keys
209 List all available certificates for which a corresponding a secret key
210 is available using a format useful mainly for debugging.
212 @item --dump-external-keys @var{pattern}
213 @opindex dump-external-keys
214 List certificates matching @var{pattern} using an external server.
215 This utilizes the @code{dirmngr} service. It uses a format useful
216 mainly for debugging.
218 @item --keydb-clear-some-cert-flags
219 @opindex keydb-clear-some-cert-flags
220 This is a debugging aid to reset certain flags in the key database
221 which are used to cache certain certificate stati. It is especially
222 useful if a bad CRL or a weird running OCSP responder did accidentally
223 revoke certificate. There is no security issue with this command
224 because @command{gpgsm} always make sure that the validity of a certificate is
225 checked right before it is used.
227 @item --delete-keys @var{pattern}
229 Delete the keys matching @var{pattern}. Note that there is no command
230 to delete the secret part of the key directly. In case you need to do
231 this, you should run the command @code{gpgsm --dump-secret-keys KEYID}
232 before you delete the key, copy the string of hex-digits in the
233 ``keygrip'' line and delete the file consisting of these hex-digits
234 and the suffix @code{.key} from the @file{private-keys-v1.d} directory
235 below our GnuPG home directory (usually @file{~/.gnupg}).
237 @item --export [@var{pattern}]
239 Export all certificates stored in the Keybox or those specified by the
240 optional @var{pattern}. Those pattern consist of a list of user ids
241 (@pxref{how-to-specify-a-user-id}). When used along with the
242 @option{--armor} option a few informational lines are prepended before
243 each block. There is one limitation: As there is no commonly agreed
244 upon way to pack more than one certificate into an ASN.1 structure,
245 the binary export (i.e. without using @option{armor}) works only for
246 the export of one certificate. Thus it is required to specify a
247 @var{pattern} which yields exactly one certificate. Ephemeral
248 certificate are only exported if all @var{pattern} are given as
249 fingerprints or keygrips.
251 @item --export-secret-key-p12 @var{key-id}
253 Export the private key and the certificate identified by @var{key-id} in
254 a PKCS#12 format. When using along with the @code{--armor} option a few
255 informational lines are prepended to the output. Note, that the PKCS#12
256 format is not very secure and this command is only provided if there is
257 no other way to exchange the private key. (@pxref{option --p12-charset})
259 @item --import [@var{files}]
261 Import the certificates from the PEM or binary encoded files as well as
262 from signed-only messages. This command may also be used to import a
263 secret key from a PKCS#12 file.
267 Read information about the private keys from the smartcard and import
268 the certificates from there. This command utilizes the @command{gpg-agent}
269 and in turn the @command{scdaemon}.
271 @item --passwd @var{user_id}
273 Change the passphrase of the private key belonging to the certificate
274 specified as @var{user_id}. Note, that changing the passphrase/PIN of a
275 smartcard is not yet supported.
280 @c *******************************************
281 @c *************** ****************
282 @c *************** OPTIONS ****************
283 @c *************** ****************
284 @c *******************************************
287 @section Option Summary
289 @command{GPGSM} comes features a bunch of options to control the exact behaviour
290 and to change the default configuration.
293 * Configuration Options:: How to change the configuration.
294 * Certificate Options:: Certificate related options.
295 * Input and Output:: Input and Output.
296 * CMS Options:: How to change how the CMS is created.
297 * Esoteric Options:: Doing things one usually don't want to do.
301 @c *******************************************
302 @c ******** CONFIGURATION OPTIONS **********
303 @c *******************************************
304 @node Configuration Options
305 @subsection How to change the configuration
307 These options are used to change the configuration and are usually found
312 @item --options @var{file}
314 Reads configuration from @var{file} instead of from the default
315 per-user configuration file. The default configuration file is named
316 @file{gpgsm.conf} and expected in the @file{.gnupg} directory directly
317 below the home directory of the user.
319 @include opt-homedir.texi
326 Outputs additional information while running.
327 You can increase the verbosity by giving several
328 verbose commands to @command{gpgsm}, such as @samp{-vv}.
330 @item --policy-file @var{filename}
332 Change the default name of the policy file to @var{filename}.
334 @item --agent-program @var{file}
335 @opindex agent-program
336 Specify an agent program to be used for secret key operations. The
337 default value is the @file{/usr/local/bin/gpg-agent}. This is only used
338 as a fallback when the environment variable @code{GPG_AGENT_INFO} is not
339 set or a running agent can't be connected.
341 @item --dirmngr-program @var{file}
342 @opindex dirmnr-program
343 Specify a dirmngr program to be used for @acronym{CRL} checks. The
344 default value is @file{/usr/sbin/dirmngr}. This is only used as a
345 fallback when the environment variable @code{DIRMNGR_INFO} is not set or
346 a running dirmngr can't be connected.
348 @item --prefer-system-dirmngr
349 @opindex prefer-system-dirmngr
350 If a system wide @command{dirmngr} is running in daemon mode, first try
351 to connect to this one. Fallback to a pipe based server if this does
352 not work. Under Windows this option is ignored because the system dirmngr is
355 @item --disable-dirmngr
356 Entirely disable the use of the Dirmngr.
358 @item --no-secmem-warning
359 @opindex no-secmem-warning
360 Don't print a warning when the so called "secure memory" can't be used.
362 @item --log-file @var{file}
364 When running in server mode, append all logging output to @var{file}.
369 @c *******************************************
370 @c ******** CERTIFICATE OPTIONS ************
371 @c *******************************************
372 @node Certificate Options
373 @subsection Certificate related options
377 @item --enable-policy-checks
378 @itemx --disable-policy-checks
379 @opindex enable-policy-checks
380 @opindex disable-policy-checks
381 By default policy checks are enabled. These options may be used to
384 @item --enable-crl-checks
385 @itemx --disable-crl-checks
386 @opindex enable-crl-checks
387 @opindex disable-crl-checks
388 By default the @acronym{CRL} checks are enabled and the DirMngr is used
389 to check for revoked certificates. The disable option is most useful
390 with an off-line network connection to suppress this check.
392 @item --enable-trusted-cert-crl-check
393 @itemx --disable-trusted-cert-crl-check
394 @opindex enable-trusted-cert-crl-check
395 @opindex disable-trusted-cert-crl-check
396 By default the @acronym{CRL} for trusted root certificates are checked
397 like for any other certificates. This allows a CA to revoke its own
398 certificates voluntary without the need of putting all ever issued
399 certificates into a CRL. The disable option may be used to switch this
400 extra check off. Due to the caching done by the Dirmngr, there won't be
401 any noticeable performance gain. Note, that this also disables possible
402 OCSP checks for trusted root certificates. A more specific way of
403 disabling this check is by adding the ``relax'' keyword to the root CA
404 line of the @file{trustlist.txt}
407 @item --force-crl-refresh
408 @opindex force-crl-refresh
409 Tell the dirmngr to reload the CRL for each request. For better
410 performance, the dirmngr will actually optimize this by suppressing
411 the loading for short time intervals (e.g. 30 minutes). This option
412 is useful to make sure that a fresh CRL is available for certificates
413 hold in the keybox. The suggested way of doing this is by using it
414 along with the option @option{--with-validation} for a key listing
415 command. This option should not be used in a configuration file.
418 @itemx --disable-ocsp
420 @opindex disable-ocsp
421 Be default @acronym{OCSP} checks are disabled. The enable option may
422 be used to enable OCSP checks via Dirmngr. If @acronym{CRL} checks
423 are also enabled, CRLs will be used as a fallback if for some reason an
424 OCSP request won't succeed. Note, that you have to allow OCSP
425 requests in Dirmngr's configuration too (option
426 @option{--allow-ocsp} and configure dirmngr properly. If you don't do
427 so you will get the error code @samp{Not supported}.
429 @item --auto-issuer-key-retrieve
430 @opindex auto-issuer-key-retrieve
431 If a required certificate is missing while validating the chain of
432 certificates, try to load that certificate from an external location.
433 This usually means that Dirmngr is employed to search for the
434 certificate. Note that this option makes a "web bug" like behavior
435 possible. LDAP server operators can see which keys you request, so by
436 sending you a message signed by a brand new key (which you naturally
437 will not have on your local keybox), the operator can tell both your IP
438 address and the time when you verified the signature.
441 @item --validation-model @var{name}
442 @opindex validation-model
443 This option changes the default validation model. The only possible
444 values are "shell" (which is the default) and "chain" which forces the
445 use of the chain model. The chain model is also used if an option in
446 the @file{trustlist.txt} or an attribute of the certificate requests it.
447 However the standard model (shell) is in that case always tried first.
453 @c *******************************************
454 @c *********** INPUT AND OUTPUT ************
455 @c *******************************************
456 @node Input and Output
457 @subsection Input and Output
464 Create PEM encoded output. Default is binary output.
468 Create Base-64 encoded output; i.e. PEM without the header lines.
471 @opindex assume-armor
472 Assume the input data is PEM encoded. Default is to autodetect the
473 encoding but this is may fail.
475 @item --assume-base64
476 @opindex assume-base64
477 Assume the input data is plain base-64 encoded.
479 @item --assume-binary
480 @opindex assume-binary
481 Assume the input data is binary encoded.
483 @anchor{option --p12-charset}
484 @item --p12-charset @var{name}
486 @command{gpgsm} uses the UTF-8 encoding when encoding passphrases for
487 PKCS#12 files. This option may be used to force the passphrase to be
488 encoded in the specified encoding @var{name}. This is useful if the
489 application used to import the key uses a different encoding and thus
490 won't be able to import a file generated by @command{gpgsm}. Commonly
491 used values for @var{name} are @code{Latin1} and @code{CP850}. Note
492 that @command{gpgsm} itself automagically imports any file with a
493 passphrase encoded to the most commonly used encodings.
496 @item --default-key @var{user_id}
498 Use @var{user_id} as the standard key for signing. This key is used if
499 no other key has been defined as a signing key. Note, that the first
500 @option{--local-users} option also sets this key if it has not yet been
501 set; however @option{--default-key} always overrides this.
504 @item --local-user @var{user_id}
505 @item -u @var{user_id}
508 Set the user(s) to be used for signing. The default is the first
509 secret key found in the database.
512 @item --recipient @var{name}
515 Encrypt to the user id @var{name}. There are several ways a user id
516 may be given (@pxref{how-to-specify-a-user-id}).
519 @item --output @var{file}
522 Write output to @var{file}. The default is to write it to stdout.
525 @item --with-key-data
526 @opindex with-key-data
527 Displays extra information with the @code{--list-keys} commands. Especially
528 a line tagged @code{grp} is printed which tells you the keygrip of a
529 key. This string is for example used as the file name of the
532 @item --with-validation
533 @opindex with-validation
534 When doing a key listing, do a full validation check for each key and
535 print the result. This is usually a slow operation because it
536 requires a CRL lookup and other operations.
538 When used along with --import, a validation of the certificate to
539 import is done and only imported if it succeeds the test. Note that
540 this does not affect an already available certificate in the DB.
541 This option is therefore useful to simply verify a certificate.
544 @item --with-md5-fingerprint
545 For standard key listings, also print the MD5 fingerprint of the
550 @c *******************************************
551 @c ************* CMS OPTIONS ***************
552 @c *******************************************
554 @subsection How to change how the CMS is created.
557 @item --include-certs @var{n}
558 @opindex include-certs
559 Using @var{n} of -2 includes all certificate except for the root cert,
560 -1 includes all certs, 0 does not include any certs, 1 includes only
561 the signers cert (this is the default) and all other positive
562 values include up to @var{n} certificates starting with the signer cert.
565 @item --cipher-algo @var{oid}
567 Use the cipher algorithm with the ASN.1 object identifier @var{oid} for
568 encryption. For convenience the strings @code{3DES}, @code{AES} and
569 @code{AES256} may be used instead of their OIDs. The default is
570 @code{3DES} (1.2.840.113549.3.7).
572 @item --digest-algo @code{name}
573 Use @code{name} as the message digest algorithm. Usually this
574 algorithm is deduced from the respective signing certificate. This
575 option forces the use of the given algorithm and may lead to severe
576 interoperability problems.
582 @c *******************************************
583 @c ******** ESOTERIC OPTIONS ***************
584 @c *******************************************
585 @node Esoteric Options
586 @subsection Doing things one usually don't want to do.
591 @item --extra-digest-algo @var{name}
592 @opindex extra-digest-algo
593 Sometimes signatures are broken in that they announce a different digest
594 algorithm than actually used. @command{gpgsm} uses a one-pass data
595 processing model and thus needs to rely on the announced digest
596 algorithms to properly hash the data. As a workaround this option may
597 be used to tell gpg to also hash the data using the algorithm
598 @var{name}; this slows processing down a little bit but allows to verify
599 such broken signatures. If @command{gpgsm} prints an error like
600 ``digest algo 8 has not been enabled'' you may want to try this option,
601 with @samp{SHA256} for @var{name}.
604 @item --faked-system-time @var{epoch}
605 @opindex faked-system-time
606 This option is only useful for testing; it sets the system time back or
607 forth to @var{epoch} which is the number of seconds elapsed since the year
608 1970. Alternatively @var{epoch} may be given as a full ISO time string
609 (e.g. "20070924T154812").
611 @item --with-ephemeral-keys
612 @opindex with-ephemeral-keys
613 Include ephemeral flagged keys in the output of key listings. Note
614 that they are included anyway if the key specification for a listing
615 is given as fingerprint or keygrip.
617 @item --debug-level @var{level}
619 Select the debug level for investigating problems. @var{level} may be
626 some basic debug messages
628 more verbose debug messages
630 even more detailed messages
632 all of the debug messages you can get
635 How these messages are mapped to the actual debugging flags is not
636 specified and may change with newer releases of this program. They are
637 however carefully selected to best aid in debugging.
639 @item --debug @var{flags}
641 This option is only useful for debugging and the behaviour may change
642 at any time without notice; using @code{--debug-levels} is the
643 preferred method to select the debug verbosity. FLAGS are bit encoded
644 and may be given in usual C-Syntax. The currently defined bits are:
648 X.509 or OpenPGP protocol related data
650 values of big number integers
652 low level crypto operations
658 show memory statistics.
660 write hashed data to files named @code{dbgmd-000*}
662 trace Assuan protocol
665 Note, that all flags set using this option may get overridden by
666 @code{--debug-level}.
670 Same as @code{--debug=0xffffffff}
672 @item --debug-allow-core-dump
673 @opindex debug-allow-core-dump
674 Usually @command{gpgsm} tries to avoid dumping core by well written code and by
675 disabling core dumps for security reasons. However, bugs are pretty
676 durable beasts and to squash them it is sometimes useful to have a core
677 dump. This option enables core dumps unless the Bad Thing happened
678 before the option parsing.
680 @item --debug-no-chain-validation
681 @opindex debug-no-chain-validation
682 This is actually not a debugging option but only useful as such. It
683 lets @command{gpgsm} bypass all certificate chain validation checks.
685 @item --debug-ignore-expiration
686 @opindex debug-ignore-expiration
687 This is actually not a debugging option but only useful as such. It
688 lets @command{gpgsm} ignore all notAfter dates, this is used by the regression
691 @item --fixed-passphrase @var{string}
692 @opindex fixed-passphrase
693 Supply the passphrase @var{string} to the gpg-protect-tool. This
694 option is only useful for the regression tests included with this
695 package and may be revised or removed at any time without notice.
697 @item --no-common-certs-import
698 @opindex no-common-certs-import
699 Suppress the import of common certificates on keybox creation.
703 All the long options may also be given in the configuration file after
704 stripping off the two leading dashes.
706 @c *******************************************
707 @c *************** ****************
708 @c *************** USER ID ****************
709 @c *************** ****************
710 @c *******************************************
711 @mansect how to specify a user id
713 @include specify-user-id.texi
716 @c *******************************************
717 @c *************** ****************
718 @c *************** FILES ****************
719 @c *************** ****************
720 @c *******************************************
722 @node GPGSM Configuration
723 @section Configuration files
725 There are a few configuration files to control certain aspects of
726 @command{gpgsm}'s operation. Unless noted, they are expected in the
727 current home directory (@pxref{option --homedir}).
733 This is the standard configuration file read by @command{gpgsm} on
734 startup. It may contain any valid long option; the leading two dashes
735 may not be entered and the option may not be abbreviated. This default
736 name may be changed on the command line (@pxref{option
737 --options}). You should backup this file.
742 This is a list of allowed CA policies. This file should list the
743 object identifiers of the policies line by line. Empty lines and
744 lines starting with a hash mark are ignored. Policies missing in this
745 file and not marked as critical in the certificate will print only a
746 warning; certificates with policies marked as critical and not listed
747 in this file will fail the signature verification. You should backup
750 For example, to allow only the policy 2.289.9.9, the file should look
761 @cindex qualified.txt
762 This is the list of root certificates used for qualified certificates.
763 They are defined as certificates capable of creating legally binding
764 signatures in the same way as handwritten signatures are. Comments
765 start with a hash mark and empty lines are ignored. Lines do have a
766 length limit but this is not a serious limitation as the format of the
767 entries is fixed and checked by gpgsm: A non-comment line starts with
768 optional whitespace, followed by exactly 40 hex character, white space
769 and a lowercased 2 letter country code. Additional data delimited with
770 by a white space is current ignored but might late be used for other
773 Note that even if a certificate is listed in this file, this does not
774 mean that the certificate is trusted; in general the certificates listed
775 in this file need to be listed also in @file{trustlist.txt}.
777 This is a global file an installed in the data directory
778 (e.g. @file{/usr/share/gnupg/qualified.txt}). GnuPG installs a suitable
779 file with root certificates as used in Germany. As new Root-CA
780 certificates may be issued over time, these entries may need to be
781 updated; new distributions of this software should come with an updated
782 list but it is still the responsibility of the Administrator to check
783 that this list is correct.
785 Everytime @command{gpgsm} uses a certificate for signing or verification
786 this file will be consulted to check whether the certificate under
787 question has ultimately been issued by one of these CAs. If this is the
788 case the user will be informed that the verified signature represents a
789 legally binding (``qualified'') signature. When creating a signature
790 using such a certificate an extra prompt will be issued to let the user
791 confirm that such a legally binding signature shall really be created.
793 Because this software has not yet been approved for use with such
794 certificates, appropriate notices will be shown to indicate this fact.
798 This is plain text file with a few help entries used with
799 @command{pinentry} as well as a large list of help items for
800 @command{gpg} and @command{gpgsm}. The standard file has English help
801 texts; to install localized versions use filenames like @file{help.LL.txt}
802 with LL denoting the locale. GnuPG comes with a set of predefined help
803 files in the data directory (e.g. @file{/usr/share/gnupg/help.de.txt})
804 and allows overriding of any help item by help files stored in the
805 system configuration directory (e.g. @file{/etc/gnupg/help.de.txt}).
806 For a reference of the help file's syntax, please see the installed
807 @file{help.txt} file.
811 @cindex com-certs.pem
812 This file is a collection of common certificates used to populated a
813 newly created @file{pubring.kbx}. An administrator may replace this
814 file with a custom one. The format is a concatenation of PEM encoded
815 X.509 certificates. This global file is installed in the data directory
816 (e.g. @file{/usr/share/gnupg/qualified.txt}).
821 Note that on larger installations, it is useful to put predefined files
822 into the directory @file{/etc/skel/.gnupg/} so that newly created users
823 start up with a working configuration. For existing users a small
824 helper script is provided to create these files (@pxref{addgnupghome}).
826 For internal purposes gpgsm creates and maintains a few other files;
827 they all live in in the current home directory (@pxref{option
828 --homedir}). Only @command{gpgsm} may modify these files.
834 This a database file storing the certificates as well as meta
835 information. For debugging purposes the tool @command{kbxutil} may be
836 used to show the internal structure of this file. You should backup
841 This content of this file is used to maintain the internal state of the
842 random number generator across invocations. The same file is used by
843 other programs of this software too.
847 If this file exists and the environment variable @env{GPG_AGENT_INFO} is
848 not set, @command{gpgsm} will first try to connect to this socket for
849 accessing @command{gpg-agent} before starting a new @command{gpg-agent}
850 instance. Under Windows this socket (which in reality be a plain file
851 describing a regular TCP listening port) is the standard way of
852 connecting the @command{gpg-agent}.
857 @c *******************************************
858 @c *************** ****************
859 @c *************** EXAMPLES ****************
860 @c *************** ****************
861 @c *******************************************
867 $ gpgsm -er goo@@bar.net <plaintext >ciphertext
874 @c *******************************************
875 @c *************** **************
876 @c *************** UNATTENDED **************
877 @c *************** **************
878 @c *******************************************
879 @node Unattended Usage
880 @section Unattended Usage
882 @command{gpgsm} is often used as a backend engine by other software. To help
883 with this a machine interface has been defined to have an unambiguous
884 way to do this. This is most likely used with the @code{--server} command
885 but may also be used in the standard operation mode by using the
886 @code{--status-fd} option.
889 * Automated signature checking:: Automated signature checking.
892 @node Automated signature checking,,,Unattended Usage
893 @section Automated signature checking
895 It is very important to understand the semantics used with signature
896 verification. Checking a signature is not as simple as it may sound and
897 so the operation is a bit complicated. In most cases it is required
898 to look at several status lines. Here is a table of all cases a signed
902 @item The signature is valid
903 This does mean that the signature has been successfully verified, the
904 certificates are all sane. However there are two subcases with
905 important information: One of the certificates may have expired or a
906 signature of a message itself as expired. It is a sound practise to
907 consider such a signature still as valid but additional information
908 should be displayed. Depending on the subcase @command{gpgsm} will issue
911 @item signature valid and nothing did expire
912 @code{GOODSIG}, @code{VALIDSIG}, @code{TRUST_FULLY}
913 @item signature valid but at least one certificate has expired
914 @code{EXPKEYSIG}, @code{VALIDSIG}, @code{TRUST_FULLY}
915 @item signature valid but expired
916 @code{EXPSIG}, @code{VALIDSIG}, @code{TRUST_FULLY}
917 Note, that this case is currently not implemented.
920 @item The signature is invalid
921 This means that the signature verification failed (this is an indication
922 of af a transfer error, a program error or tampering with the message).
923 @command{gpgsm} issues one of these status codes sequences:
926 @item @code{GOODSIG}, @code{VALIDSIG} @code{TRUST_NEVER}
929 @item Error verifying a signature
930 For some reason the signature could not be verified, i.e. it can't be
931 decided whether the signature is valid or invalid. A common reason for
932 this is a missing certificate.
937 @c *******************************************
938 @c *************** *****************
939 @c *************** ASSSUAN *****************
940 @c *************** *****************
941 @c *******************************************
944 @section The Protocol the Server Mode Uses.
946 Description of the protocol used to access @command{GPGSM}.
947 @command{GPGSM} does implement the Assuan protocol and in addition
948 provides a regular command line interface which exhibits a full client
949 to this protocol (but uses internal linking). To start
950 @command{gpgsm} as a server the command line the option
951 @code{--server} must be used. Additional options are provided to
952 select the communication method (i.e. the name of the socket).
954 We assume that the connection has already been established; see the
955 Assuan manual for details.
958 * GPGSM ENCRYPT:: Encrypting a message.
959 * GPGSM DECRYPT:: Decrypting a message.
960 * GPGSM SIGN:: Signing a message.
961 * GPGSM VERIFY:: Verifying a message.
962 * GPGSM GENKEY:: Generating a key.
963 * GPGSM LISTKEYS:: List available keys.
964 * GPGSM EXPORT:: Export certificates.
965 * GPGSM IMPORT:: Import certificates.
966 * GPGSM DELETE:: Delete certificates.
967 * GPGSM GETINFO:: Information about the process
972 @subsection Encrypting a Message
974 Before encryption can be done the recipient must be set using the
978 RECIPIENT @var{userID}
981 Set the recipient for the encryption. @var{userID} should be the
982 internal representation of the key; the server may accept any other way
983 of specification. If this is a valid and trusted recipient the server
984 does respond with OK, otherwise the return is an ERR with the reason why
985 the recipient can't be used, the encryption will then not be done for
986 this recipient. If the policy is not to encrypt at all if not all
987 recipients are valid, the client has to take care of this. All
988 @code{RECIPIENT} commands are cumulative until a @code{RESET} or an
989 successful @code{ENCRYPT} command.
992 INPUT FD[=@var{n}] [--armor|--base64|--binary]
995 Set the file descriptor for the message to be encrypted to @var{n}.
996 Obviously the pipe must be open at that point, the server establishes
997 its own end. If the server returns an error the client should consider
998 this session failed. If @var{n} is not given, this commands uses the
999 last file descriptor passed to the application.
1000 @xref{fun-assuan_sendfd, ,the assuan_sendfd function,assuan,the Libassuan
1001 manual}, on how to do descriptor passing.
1003 The @code{--armor} option may be used to advice the server that the
1004 input data is in @acronym{PEM} format, @code{--base64} advices that a
1005 raw base-64 encoding is used, @code{--binary} advices of raw binary
1006 input (@acronym{BER}). If none of these options is used, the server
1007 tries to figure out the used encoding, but this may not always be
1011 OUTPUT FD[=@var{n}] [--armor|--base64]
1014 Set the file descriptor to be used for the output (i.e. the encrypted
1015 message). Obviously the pipe must be open at that point, the server
1016 establishes its own end. If the server returns an error he client
1017 should consider this session failed.
1019 The option armor encodes the output in @acronym{PEM} format, the
1020 @code{--base64} option applies just a base 64 encoding. No option
1021 creates binary output (@acronym{BER}).
1023 The actual encryption is done using the command
1029 It takes the plaintext from the @code{INPUT} command, writes to the
1030 ciphertext to the file descriptor set with the @code{OUTPUT} command,
1031 take the recipients from all the recipients set so far. If this command
1032 fails the clients should try to delete all output currently done or
1033 otherwise mark it as invalid. @command{GPGSM} does ensure that there won't be any
1034 security problem with leftover data on the output in this case.
1036 This command should in general not fail, as all necessary checks have
1037 been done while setting the recipients. The input and output pipes are
1042 @subsection Decrypting a message
1044 Input and output FDs are set the same way as in encryption, but
1045 @code{INPUT} refers to the ciphertext and output to the plaintext. There
1046 is no need to set recipients. @command{GPGSM} automatically strips any
1047 @acronym{S/MIME} headers from the input, so it is valid to pass an
1048 entire MIME part to the INPUT pipe.
1050 The encryption is done by using the command
1056 It performs the decrypt operation after doing some check on the internal
1057 state. (e.g. that all needed data has been set). Because it utilizes
1058 the GPG-Agent for the session key decryption, there is no need to ask
1059 the client for a protecting passphrase - GpgAgent takes care of this by
1060 requesting this from the user.
1064 @subsection Signing a Message
1066 Signing is usually done with these commands:
1069 INPUT FD[=@var{n}] [--armor|--base64|--binary]
1072 This tells @command{GPGSM} to read the data to sign from file descriptor @var{n}.
1075 OUTPUT FD[=@var{m}] [--armor|--base64]
1078 Write the output to file descriptor @var{m}. If a detached signature is
1079 requested, only the signature is written.
1085 Sign the data set with the INPUT command and write it to the sink set by
1086 OUTPUT. With @code{--detached}, a detached signature is created
1089 The key used for signing is the default one or the one specified in
1090 the configuration file. To get finer control over the keys, it is
1091 possible to use the command
1097 to the signer's key. @var{userID} should be the
1098 internal representation of the key; the server may accept any other way
1099 of specification. If this is a valid and trusted recipient the server
1100 does respond with OK, otherwise the return is an ERR with the reason why
1101 the key can't be used, the signature will then not be created using
1102 this key. If the policy is not to sign at all if not all
1103 keys are valid, the client has to take care of this. All
1104 @code{SIGNER} commands are cumulative until a @code{RESET} is done.
1105 Note that a @code{SIGN} does not reset this list of signers which is in
1106 contrats to the @code{RECIPIENT} command.
1110 @subsection Verifying a Message
1112 To verify a mesage the command:
1118 is used. It does a verify operation on the message send to the input FD.
1119 The result is written out using status lines. If an output FD was
1120 given, the signed text will be written to that. If the signature is a
1121 detached one, the server will inquire about the signed material and the
1122 client must provide it.
1125 @subsection Generating a Key
1127 This is used to generate a new keypair, store the secret part in the
1128 @acronym{PSE} and the public key in the key database. We will probably
1129 add optional commands to allow the client to select whether a hardware
1130 token is used to store the key. Configuration options to
1131 @command{GPGSM} can be used to restrict the use of this command.
1137 @command{GPGSM} checks whether this command is allowed and then does an
1138 INQUIRY to get the key parameters, the client should then send the
1139 key parameters in the native format:
1142 S: INQUIRE KEY_PARAM native
1148 Please note that the server may send Status info lines while reading the
1149 data lines from the client. After this the key generation takes place
1150 and the server eventually does send an ERR or OK response. Status lines
1151 may be issued as a progress indicator.
1154 @node GPGSM LISTKEYS
1155 @subsection List available keys
1157 To list the keys in the internal database or using an external key
1158 provider, the command:
1161 LISTKEYS @var{pattern}
1164 is used. To allow multiple patterns (which are ORed during the search)
1165 quoting is required: Spaces are to be translated into "+" or into "%20";
1166 in turn this requires that the usual escape quoting rules are done.
1169 LISTSECRETKEYS @var{pattern}
1172 Lists only the keys where a secret key is available.
1174 The list commands commands are affected by the option
1177 OPTION list-mode=@var{mode}
1183 Use default (which is usually the same as 1).
1185 List only the internal keys.
1187 List only the external keys.
1189 List internal and external keys.
1192 Note that options are valid for the entire session.
1196 @subsection Export certificates
1198 To export certificate from the internal key database the command:
1201 EXPORT [--data [--armor] [--base64]] [--] @var{pattern}
1204 is used. To allow multiple patterns (which are ORed) quoting is
1205 required: Spaces are to be translated into "+" or into "%20"; in turn
1206 this requires that the usual escape quoting rules are done.
1208 If the @option{--data} option has not been given, the format of the
1209 output depends on what was set with the OUTPUT command. When using
1210 @acronym{PEM} encoding a few informational lines are prepended.
1212 If the @option{--data} has been given, a target set via OUTPUT is
1213 ignored and the data is returned inline using standard
1214 @code{D}-lines. This avoids the need for an extra file descriptor. In
1215 this case the options @option{--armor} and @option{--base64} may be used
1216 in the same way as with the OUTPUT command.
1220 @subsection Import certificates
1222 To import certificates into the internal key database, the command
1225 IMPORT [--re-import]
1228 is used. The data is expected on the file descriptor set with the
1229 @code{INPUT} command. Certain checks are performed on the
1230 certificate. Note that the code will also handle PKCS#12 files and
1231 import private keys; a helper program is used for that.
1233 With the option @option{--re-import} the input data is expected to a be
1234 a linefeed separated list of fingerprints. The command will re-import
1235 the corresponding certificates; that is they are made permanent by
1236 removing their ephemeral flag.
1240 @subsection Delete certificates
1242 To delete a certificate the command
1245 DELKEYS @var{pattern}
1248 is used. To allow multiple patterns (which are ORed) quoting is
1249 required: Spaces are to be translated into "+" or into "%20"; in turn
1250 this requires that the usual escape quoting rules are done.
1252 The certificates must be specified unambiguously otherwise an error is
1256 @subsection Return information about the process
1258 This is a multipurpose function to return a variety of information.
1264 The value of @var{what} specifies the kind of information returned:
1267 Return the version of the program.
1269 Return the process id of the process.
1271 Return success if the agent is running.
1272 @item cmd_has_option @var{cmd} @var{opt}
1273 Return success if the command @var{cmd} implements the option @var{opt}.
1274 The leading two dashes usually used with @var{opt} shall not be given.
1280 @command{gpg-agent}(1)
1282 @include see-also-note.texi