Imported Upstream version 2.2.37
[platform/upstream/gpg2.git] / doc / gpgsm.texi
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.
4
5 @include defs.inc
6
7 @node Invoking GPGSM
8 @chapter Invoking GPGSM
9 @cindex GPGSM command options
10 @cindex command options
11 @cindex options, GPGSM command
12
13 @manpage gpgsm.1
14 @ifset manverb
15 .B gpgsm
16 \- CMS encryption and signing tool
17 @end ifset
18
19 @mansect synopsis
20 @ifset manverb
21 .B  gpgsm
22 .RB [ \-\-homedir
23 .IR dir ]
24 .RB [ \-\-options
25 .IR file ]
26 .RI [ options ]
27 .I command
28 .RI [ args ]
29 @end ifset
30
31
32 @mansect description
33 @command{gpgsm} is a tool similar to @command{gpg} to provide digital
34 encryption and signing services on X.509 certificates and the CMS
35 protocol.  It is mainly used as a backend for S/MIME mail processing.
36 @command{gpgsm} includes a full featured certificate management and
37 complies with all rules defined for the German Sphinx project.
38
39 @manpause
40 @xref{Option Index}, for an index to @command{GPGSM}'s commands and options.
41 @mancont
42
43 @menu
44 * GPGSM Commands::        List of all commands.
45 * GPGSM Options::         List of all options.
46 * GPGSM Configuration::   Configuration files.
47 * GPGSM Examples::        Some usage examples.
48
49 Developer information:
50 * Unattended Usage::      Using @command{gpgsm} from other programs.
51 * GPGSM Protocol::        The protocol the server mode uses.
52 @end menu
53
54 @c *******************************************
55 @c ***************            ****************
56 @c ***************  COMMANDS  ****************
57 @c ***************            ****************
58 @c *******************************************
59 @mansect commands
60 @node GPGSM Commands
61 @section Commands
62
63 Commands are not distinguished from options except for the fact that
64 only one command is allowed.
65
66 @menu
67 * General GPGSM Commands::        Commands not specific to the functionality.
68 * Operational GPGSM Commands::    Commands to select the type of operation.
69 * Certificate Management::        How to manage certificates.
70 @end menu
71
72
73 @c *******************************************
74 @c **********  GENERAL COMMANDS  *************
75 @c *******************************************
76 @node General GPGSM Commands
77 @subsection Commands not specific to the function
78
79 @table @gnupgtabopt
80 @item --version
81 @opindex version
82 Print the program version and licensing information.  Note that you
83 cannot abbreviate this command.
84
85 @item --help, -h
86 @opindex help
87 Print a usage message summarizing the most useful command-line options.
88 Note that you cannot abbreviate this command.
89
90 @item --warranty
91 @opindex warranty
92 Print warranty information.  Note that you cannot abbreviate this
93 command.
94
95 @item --dump-options
96 @opindex dump-options
97 Print a list of all available options and commands.  Note that you cannot
98 abbreviate this command.
99 @end table
100
101
102 @c *******************************************
103 @c ********  OPERATIONAL COMMANDS  ***********
104 @c *******************************************
105 @node Operational GPGSM Commands
106 @subsection Commands to select the type of operation
107
108 @table @gnupgtabopt
109 @item --encrypt
110 @opindex encrypt
111 Perform an encryption.  The keys the data is encrypted to must be set
112 using the option @option{--recipient}.
113
114 @item --decrypt
115 @opindex decrypt
116 Perform a decryption; the type of input is automatically determined.  It
117 may either be in binary form or PEM encoded; automatic determination of
118 base-64 encoding is not done.
119
120 @item --sign
121 @opindex sign
122 Create a digital signature.  The key used is either the fist one found
123 in the keybox or those set with the @option{--local-user} option.
124
125 @item --verify
126 @opindex verify
127 Check a signature file for validity.  Depending on the arguments a
128 detached signature may also be checked.
129
130 @item --server
131 @opindex server
132 Run in server mode and wait for commands on the @code{stdin}.
133
134 @item --call-dirmngr @var{command} [@var{args}]
135 @opindex call-dirmngr
136 Behave as a Dirmngr client issuing the request @var{command} with the
137 optional list of @var{args}.  The output of the Dirmngr is printed
138 stdout.  Please note that file names given as arguments should have an
139 absolute file name (i.e. commencing with @code{/}) because they are
140 passed verbatim to the Dirmngr and the working directory of the
141 Dirmngr might not be the same as the one of this client.  Currently it
142 is not possible to pass data via stdin to the Dirmngr.  @var{command}
143 should not contain spaces.
144
145 This is command is required for certain maintaining tasks of the dirmngr
146 where a dirmngr must be able to call back to @command{gpgsm}.  See the Dirmngr
147 manual for details.
148
149 @item --call-protect-tool @var{arguments}
150 @opindex call-protect-tool
151 Certain maintenance operations are done by an external program call
152 @command{gpg-protect-tool}; this is usually not installed in a directory
153 listed in the PATH variable.  This command provides a simple wrapper to
154 access this tool.  @var{arguments} are passed verbatim to this command;
155 use @samp{--help} to get a list of supported operations.
156
157
158 @end table
159
160
161 @c *******************************************
162 @c *******  CERTIFICATE MANAGEMENT  **********
163 @c *******************************************
164 @node Certificate Management
165 @subsection How to manage the certificates and keys
166
167 @table @gnupgtabopt
168 @item --generate-key
169 @opindex generate-key
170 @itemx --gen-key
171 @opindex gen-key
172 This command allows the creation of a certificate signing request or a
173 self-signed certificate.  It is commonly used along with the
174 @option{--output} option to save the created CSR or certificate into a
175 file.  If used with the @option{--batch} a parameter file is used to
176 create the CSR or certificate and it is further possible to create
177 non-self-signed certificates.
178
179 @item --list-keys
180 @itemx -k
181 @opindex list-keys
182 List all available certificates stored in the local key database.
183 Note that the displayed data might be reformatted for better human
184 readability and illegal characters are replaced by safe substitutes.
185
186 @item --list-secret-keys
187 @itemx -K
188 @opindex list-secret-keys
189 List all available certificates for which a corresponding a secret key
190 is available.
191
192 @item --list-external-keys @var{pattern}
193 @opindex list-keys
194 List certificates matching @var{pattern} using an external server.  This
195 utilizes the @code{dirmngr} service.
196
197 @item --list-chain
198 @opindex list-chain
199 Same as @option{--list-keys} but also prints all keys making up the chain.
200
201
202 @item --dump-cert
203 @itemx --dump-keys
204 @opindex dump-cert
205 @opindex dump-keys
206 List all available certificates stored in the local key database using a
207 format useful mainly for debugging.
208
209 @item --dump-chain
210 @opindex dump-chain
211 Same as @option{--dump-keys} but also prints all keys making up the chain.
212
213 @item --dump-secret-keys
214 @opindex dump-secret-keys
215 List all available certificates for which a corresponding a secret key
216 is available using a format useful mainly for debugging.
217
218 @item --dump-external-keys @var{pattern}
219 @opindex dump-external-keys
220 List certificates matching @var{pattern} using an external server.
221 This utilizes the @code{dirmngr} service.  It uses a format useful
222 mainly for debugging.
223
224 @item --keydb-clear-some-cert-flags
225 @opindex keydb-clear-some-cert-flags
226 This is a debugging aid to reset certain flags in the key database
227 which are used to cache certain certificate stati.  It is especially
228 useful if a bad CRL or a weird running OCSP responder did accidentally
229 revoke certificate.  There is no security issue with this command
230 because @command{gpgsm} always make sure that the validity of a certificate is
231 checked right before it is used.
232
233 @item --delete-keys @var{pattern}
234 @opindex delete-keys
235 Delete the keys matching @var{pattern}.  Note that there is no command
236 to delete the secret part of the key directly.  In case you need to do
237 this, you should run the command @code{gpgsm --dump-secret-keys KEYID}
238 before you delete the key, copy the string of hex-digits in the
239 ``keygrip'' line and delete the file consisting of these hex-digits
240 and the suffix @code{.key} from the @file{private-keys-v1.d} directory
241 below our GnuPG home directory (usually @file{~/.gnupg}).
242
243 @item --export [@var{pattern}]
244 @opindex export
245 Export all certificates stored in the Keybox or those specified by the
246 optional @var{pattern}. Those pattern consist of a list of user ids
247 (@pxref{how-to-specify-a-user-id}).  When used along with the
248 @option{--armor} option a few informational lines are prepended before
249 each block.  There is one limitation: As there is no commonly agreed
250 upon way to pack more than one certificate into an ASN.1 structure,
251 the binary export (i.e. without using @option{armor}) works only for
252 the export of one certificate.  Thus it is required to specify a
253 @var{pattern} which yields exactly one certificate.  Ephemeral
254 certificate are only exported if all @var{pattern} are given as
255 fingerprints or keygrips.
256
257 @item --export-secret-key-p12 @var{key-id}
258 @opindex export-secret-key-p12
259 Export the private key and the certificate identified by @var{key-id}
260 using the PKCS#12 format.  When used with the @code{--armor} option a few
261 informational lines are prepended to the output.  Note, that the PKCS#12
262 format is not very secure and proper transport security should be used
263 to convey the exported key.  (@xref{option --p12-charset}.)
264
265 @item --export-secret-key-p8 @var{key-id}
266 @itemx --export-secret-key-raw @var{key-id}
267 @opindex export-secret-key-p8
268 @opindex export-secret-key-raw
269 Export the private key of the certificate identified by @var{key-id}
270 with any encryption stripped.  The @code{...-raw} command exports in
271 PKCS#1 format; the @code{...-p8} command exports in PKCS#8 format.
272 When used with the @code{--armor} option a few informational lines are
273 prepended to the output.  These commands are useful to prepare a key
274 for use on a TLS server.
275
276 @item --import [@var{files}]
277 @opindex import
278 Import the certificates from the PEM or binary encoded files as well as
279 from signed-only messages.  This command may also be used to import a
280 secret key from a PKCS#12 file.
281
282 @item --learn-card
283 @opindex learn-card
284 Read information about the private keys from the smartcard and import
285 the certificates from there.  This command utilizes the @command{gpg-agent}
286 and in turn the @command{scdaemon}.
287
288 @item --change-passphrase @var{user_id}
289 @opindex change-passphrase
290 @itemx --passwd @var{user_id}
291 @opindex passwd
292 Change the passphrase of the private key belonging to the certificate
293 specified as @var{user_id}.  Note, that changing the passphrase/PIN of a
294 smartcard is not yet supported.
295
296 @end table
297
298
299 @c *******************************************
300 @c ***************            ****************
301 @c ***************  OPTIONS   ****************
302 @c ***************            ****************
303 @c *******************************************
304 @mansect options
305 @node GPGSM Options
306 @section Option Summary
307
308 @command{GPGSM} features a bunch of options to control the exact behaviour
309 and to change the default configuration.
310
311 @menu
312 * Configuration Options::   How to change the configuration.
313 * Certificate Options::     Certificate related options.
314 * Input and Output::        Input and Output.
315 * CMS Options::             How to change how the CMS is created.
316 * Esoteric Options::        Doing things one usually do not want to do.
317 @end menu
318
319
320 @c *******************************************
321 @c ********  CONFIGURATION OPTIONS  **********
322 @c *******************************************
323 @node Configuration Options
324 @subsection How to change the configuration
325
326 These options are used to change the configuration and are usually found
327 in the option file.
328
329 @table @gnupgtabopt
330
331 @anchor{gpgsm-option --options}
332 @item --options @var{file}
333 @opindex options
334 Reads configuration from @var{file} instead of from the default
335 per-user configuration file.  The default configuration file is named
336 @file{gpgsm.conf} and expected in the @file{.gnupg} directory directly
337 below the home directory of the user.
338
339 @include opt-homedir.texi
340
341
342 @item -v
343 @item --verbose
344 @opindex v
345 @opindex verbose
346 Outputs additional information while running.
347 You can increase the verbosity by giving several
348 verbose commands to @command{gpgsm}, such as @samp{-vv}.
349
350 @item --keyserver @var{string}
351 @opindex keyserver
352 This is a deprecated option.  It was used to add an LDAP server to use
353 for X.509 certificate and CRL lookup.  The alias @option{--ldapserver}
354 existed from version 2.2.28 to 2.2.33 but is now entirely ignored.
355
356 LDAP servers must be given in the configuration for @command{dirmngr}.
357
358
359 @item --policy-file @var{filename}
360 @opindex policy-file
361 Change the default name of the policy file to @var{filename}.
362
363 @item --agent-program @var{file}
364 @opindex agent-program
365 Specify an agent program to be used for secret key operations.  The
366 default value is determined by running the command @command{gpgconf}.
367 Note that the pipe symbol (@code{|}) is used for a regression test
368 suite hack and may thus not be used in the file name.
369
370 @item --dirmngr-program @var{file}
371 @opindex dirmngr-program
372 Specify a dirmngr program to be used for @acronym{CRL} checks.  The
373 default value is @file{@value{BINDIR}/dirmngr}.
374
375 @item --prefer-system-dirmngr
376 @opindex prefer-system-dirmngr
377 This option is obsolete and ignored.
378
379 @item --disable-dirmngr
380 Entirely disable the use of the Dirmngr.
381
382 @item --no-autostart
383 @opindex no-autostart
384 Do not start the gpg-agent or the dirmngr if it has not yet been
385 started and its service is required.  This option is mostly useful on
386 machines where the connection to gpg-agent has been redirected to
387 another machines.  If dirmngr is required on the remote machine, it
388 may be started manually using @command{gpgconf --launch dirmngr}.
389
390 @item --no-secmem-warning
391 @opindex no-secmem-warning
392 Do not print a warning when the so called "secure memory" cannot be used.
393
394 @item --log-file @var{file}
395 @opindex log-file
396 When running in server mode, append all logging output to @var{file}.
397 Use @file{socket://} to log to socket.
398
399 @end table
400
401
402 @c *******************************************
403 @c ********  CERTIFICATE OPTIONS  ************
404 @c *******************************************
405 @node Certificate Options
406 @subsection Certificate related options
407
408 @table @gnupgtabopt
409
410 @item  --enable-policy-checks
411 @itemx --disable-policy-checks
412 @opindex enable-policy-checks
413 @opindex disable-policy-checks
414 By default policy checks are enabled.  These options may be used to
415 change it.
416
417 @item  --enable-crl-checks
418 @itemx --disable-crl-checks
419 @opindex enable-crl-checks
420 @opindex disable-crl-checks
421 By default the @acronym{CRL} checks are enabled and the DirMngr is
422 used to check for revoked certificates.  The disable option is most
423 useful with an off-line network connection to suppress this check and
424 also to avoid that new certificates introduce a web bug by including a
425 certificate specific CRL DP.  The disable option also disables an
426 issuer certificate lookup via the authorityInfoAccess property of the
427 certificate; the @option{--enable-issuer-key-retrieve} can be used
428 to make use of that property anyway.
429
430 @item  --enable-trusted-cert-crl-check
431 @itemx --disable-trusted-cert-crl-check
432 @opindex enable-trusted-cert-crl-check
433 @opindex disable-trusted-cert-crl-check
434 By default the @acronym{CRL} for trusted root certificates are checked
435 like for any other certificates.  This allows a CA to revoke its own
436 certificates voluntary without the need of putting all ever issued
437 certificates into a CRL.  The disable option may be used to switch this
438 extra check off.  Due to the caching done by the Dirmngr, there will not be
439 any noticeable performance gain.  Note, that this also disables possible
440 OCSP checks for trusted root certificates.  A more specific way of
441 disabling this check is by adding the ``relax'' keyword to the root CA
442 line of the @file{trustlist.txt}
443
444
445 @item --force-crl-refresh
446 @opindex force-crl-refresh
447 Tell the dirmngr to reload the CRL for each request.  For better
448 performance, the dirmngr will actually optimize this by suppressing
449 the loading for short time intervals (e.g. 30 minutes). This option
450 is useful to make sure that a fresh CRL is available for certificates
451 hold in the keybox.  The suggested way of doing this is by using it
452 along with the option @option{--with-validation} for a key listing
453 command.  This option should not be used in a configuration file.
454
455 @item --enable-issuer-based-crl-check
456 @opindex enable-issuer-based-crl-check
457 Run a CRL check even for certificates which do not have any CRL
458 distribution point.  This requires that a suitable LDAP server has
459 been configured in Dirmngr and that the CRL can be found using the
460 issuer.  This option reverts to what GnuPG did up to version 2.2.20.
461 This option is in general not useful.
462
463 @item  --enable-ocsp
464 @itemx --disable-ocsp
465 @opindex enable-ocsp
466 @opindex disable-ocsp
467 By default @acronym{OCSP} checks are disabled.  The enable option may
468 be used to enable OCSP checks via Dirmngr.  If @acronym{CRL} checks
469 are also enabled, CRLs will be used as a fallback if for some reason an
470 OCSP request will not succeed.  Note, that you have to allow OCSP
471 requests in Dirmngr's configuration too (option
472 @option{--allow-ocsp}) and configure Dirmngr properly.  If you do not do
473 so you will get the error code @samp{Not supported}.
474
475 @item --auto-issuer-key-retrieve
476 @opindex auto-issuer-key-retrieve
477 If a required certificate is missing while validating the chain of
478 certificates, try to load that certificate from an external location.
479 This usually means that Dirmngr is employed to search for the
480 certificate.  Note that this option makes a "web bug" like behavior
481 possible.  LDAP server operators can see which keys you request, so by
482 sending you a message signed by a brand new key (which you naturally
483 will not have on your local keybox), the operator can tell both your IP
484 address and the time when you verified the signature.
485
486
487 @anchor{gpgsm-option --validation-model}
488 @item --validation-model @var{name}
489 @opindex validation-model
490 This option changes the default validation model.  The only possible
491 values are "shell" (which is the default), "chain" which forces the
492 use of the chain model and "steed" for a new simplified model.  The
493 chain model is also used if an option in the @file{trustlist.txt} or
494 an attribute of the certificate requests it.  However the standard
495 model (shell) is in that case always tried first.
496
497 @item --ignore-cert-extension @var{oid}
498 @opindex ignore-cert-extension
499 Add @var{oid} to the list of ignored certificate extensions.  The
500 @var{oid} is expected to be in dotted decimal form, like
501 @code{2.5.29.3}.  This option may be used more than once.  Critical
502 flagged certificate extensions matching one of the OIDs in the list
503 are treated as if they are actually handled and thus the certificate
504 will not be rejected due to an unknown critical extension.  Use this
505 option with care because extensions are usually flagged as critical
506 for a reason.
507
508 @end table
509
510 @c *******************************************
511 @c ***********  INPUT AND OUTPUT  ************
512 @c *******************************************
513 @node Input and Output
514 @subsection Input and Output
515
516 @table @gnupgtabopt
517 @item --armor
518 @itemx -a
519 @opindex armor
520 Create PEM encoded output.  Default is binary output.
521
522 @item --base64
523 @opindex base64
524 Create Base-64 encoded output; i.e. PEM without the header lines.
525
526 @item --assume-armor
527 @opindex assume-armor
528 Assume the input data is PEM encoded.  Default is to autodetect the
529 encoding but this is may fail.
530
531 @item --assume-base64
532 @opindex assume-base64
533 Assume the input data is plain base-64 encoded.
534
535 @item --assume-binary
536 @opindex assume-binary
537 Assume the input data is binary encoded.
538
539 @anchor{option --p12-charset}
540 @item --p12-charset @var{name}
541 @opindex p12-charset
542 @command{gpgsm} uses the UTF-8 encoding when encoding passphrases for
543 PKCS#12 files.  This option may be used to force the passphrase to be
544 encoded in the specified encoding @var{name}.  This is useful if the
545 application used to import the key uses a different encoding and thus
546 will not be able to import a file generated by @command{gpgsm}.  Commonly
547 used values for @var{name} are @code{Latin1} and @code{CP850}.  Note
548 that @command{gpgsm} itself automagically imports any file with a
549 passphrase encoded to the most commonly used encodings.
550
551
552 @item --default-key @var{user_id}
553 @opindex default-key
554 Use @var{user_id} as the standard key for signing.  This key is used if
555 no other key has been defined as a signing key.  Note, that the first
556 @option{--local-users} option also sets this key if it has not yet been
557 set; however @option{--default-key} always overrides this.
558
559
560 @item --local-user @var{user_id}
561 @item -u @var{user_id}
562 @opindex local-user
563 Set the user(s) to be used for signing.  The default is the first
564 secret key found in the database.
565
566
567 @item --recipient @var{name}
568 @itemx -r
569 @opindex recipient
570 Encrypt to the user id @var{name}.  There are several ways a user id
571 may be given (@pxref{how-to-specify-a-user-id}).
572
573
574 @item --output @var{file}
575 @itemx -o @var{file}
576 @opindex output
577 Write output to @var{file}.  The default is to write it to stdout.
578
579
580 @anchor{gpgsm-option --with-key-data}
581 @item --with-key-data
582 @opindex with-key-data
583 Displays extra information with the @code{--list-keys} commands.  Especially
584 a line tagged @code{grp} is printed which tells you the keygrip of a
585 key.  This string is for example used as the file name of the
586 secret key.  Implies @code{--with-colons}.
587
588 @anchor{gpgsm-option --with-validation}
589 @item --with-validation
590 @opindex with-validation
591 When doing a key listing, do a full validation check for each key and
592 print the result.  This is usually a slow operation because it
593 requires a CRL lookup and other operations.
594
595 When used along with @option{--import}, a validation of the certificate to
596 import is done and only imported if it succeeds the test.  Note that
597 this does not affect an already available certificate in the DB.
598 This option is therefore useful to simply verify a certificate.
599
600
601 @item --with-md5-fingerprint
602 For standard key listings, also print the MD5 fingerprint of the
603 certificate.
604
605 @item --with-keygrip
606 Include the keygrip in standard key listings.  Note that the keygrip is
607 always listed in @option{--with-colons} mode.
608
609 @item --with-secret
610 @opindex with-secret
611 Include info about the presence of a secret key in public key listings
612 done with @code{--with-colons}.
613
614 @end table
615
616 @c *******************************************
617 @c *************  CMS OPTIONS  ***************
618 @c *******************************************
619 @node CMS Options
620 @subsection How to change how the CMS is created
621
622 @table @gnupgtabopt
623 @item --include-certs @var{n}
624 @opindex include-certs
625 Using @var{n} of -2 includes all certificate except for the root cert,
626 -1 includes all certs, 0 does not include any certs, 1 includes only the
627 signers cert and all other positive values include up to @var{n}
628 certificates starting with the signer cert.  The default is -2.
629
630 @item --cipher-algo @var{oid}
631 @opindex cipher-algo
632 Use the cipher algorithm with the ASN.1 object identifier @var{oid} for
633 encryption.  For convenience the strings @code{3DES}, @code{AES} and
634 @code{AES256} may be used instead of their OIDs.  The default is
635 @code{AES} (2.16.840.1.101.3.4.1.2).
636
637 @item --digest-algo @code{name}
638 Use @code{name} as the message digest algorithm.  Usually this
639 algorithm is deduced from the respective signing certificate.  This
640 option forces the use of the given algorithm and may lead to severe
641 interoperability problems.
642
643 @end table
644
645
646
647 @c *******************************************
648 @c ********  ESOTERIC OPTIONS  ***************
649 @c *******************************************
650 @node Esoteric Options
651 @subsection Doing things one usually do not want to do
652
653
654 @table @gnupgtabopt
655
656 @item --extra-digest-algo @var{name}
657 @opindex extra-digest-algo
658 Sometimes signatures are broken in that they announce a different digest
659 algorithm than actually used.  @command{gpgsm} uses a one-pass data
660 processing model and thus needs to rely on the announced digest
661 algorithms to properly hash the data.  As a workaround this option may
662 be used to tell @command{gpgsm} to also hash the data using the algorithm
663 @var{name}; this slows processing down a little bit but allows verification of
664 such broken signatures.  If @command{gpgsm} prints an error like
665 ``digest algo 8 has not been enabled'' you may want to try this option,
666 with @samp{SHA256} for @var{name}.
667
668 @item --compliance @var{string}
669 @opindex compliance
670 Set the compliance mode.  Valid values are shown when using "help" for
671 @var{string}.
672
673 @item --min-rsa-length @var{n}
674 @opindex min-rsa-length
675 This option adjusts the compliance mode "de-vs" for stricter key size
676 requirements.  For example, a value of 3000 turns rsa2048 and dsa2048
677 keys into non-VS-NfD compliant keys.
678
679 @item --require-compliance
680 @opindex require-compliance
681 To check that data has been encrypted according to the rules of the
682 current compliance mode, a gpgsm user needs to evaluate the status
683 lines.  This is allows frontends to handle compliance check in a more
684 flexible way.  However, for scripted use the required evaluation of
685 the status-line requires quite some effort; this option can be used
686 instead to make sure that the gpgsm process exits with a failure if
687 the compliance rules are not fulfilled.  Note that this option has
688 currently an effect only in "de-vs" mode.
689
690 @item --ignore-cert-with-oid @var{oid}
691 @opindex ignore-cert-with-oid
692 Add @var{oid} to the list of OIDs to be checked while reading
693 certificates from smartcards. The @var{oid} is expected to be in
694 dotted decimal form, like @code{2.5.29.3}.  This option may be used
695 more than once.  As of now certificates with an extended key usage
696 matching one of those OIDs are ignored during a @option{--learn-card}
697 operation and not imported.  This option can help to keep the local
698 key database clear of unneeded certificates stored on smartcards.
699
700 @item --faked-system-time @var{epoch}
701 @opindex faked-system-time
702 This option is only useful for testing; it sets the system time back or
703 forth to @var{epoch} which is the number of seconds elapsed since the year
704 1970.  Alternatively @var{epoch} may be given as a full ISO time string
705 (e.g. "20070924T154812").
706
707 @item --with-ephemeral-keys
708 @opindex with-ephemeral-keys
709 Include ephemeral flagged keys in the output of key listings.  Note
710 that they are included anyway if the key specification for a listing
711 is given as fingerprint or keygrip.
712
713 @item --compatibility-flags @var{flags}
714 @opindex compatibility-flags
715 Set compatibility flags to work around problems due to non-compliant
716 certificates or data.  The @var{flags} are given as a comma separated
717 list of flag names and are OR-ed together.  The special flag "none"
718 clears the list and allows to start over with an empty list.  To get a
719 list of available flags the sole word "help" can be used.
720
721 @item --debug-level @var{level}
722 @opindex debug-level
723 Select the debug level for investigating problems. @var{level} may be
724 a numeric value or by a keyword:
725
726 @table @code
727 @item none
728 No debugging at all.  A value of less than 1 may be used instead of
729 the keyword.
730 @item basic
731 Some basic debug messages.  A value between 1 and 2 may be used
732 instead of the keyword.
733 @item advanced
734 More verbose debug messages.  A value between 3 and 5 may be used
735 instead of the keyword.
736 @item expert
737 Even more detailed messages.  A value between 6 and 8 may be used
738 instead of the keyword.
739 @item guru
740 All of the debug messages you can get. A value greater than 8 may be
741 used instead of the keyword.  The creation of hash tracing files is
742 only enabled if the keyword is used.
743 @end table
744
745 How these messages are mapped to the actual debugging flags is not
746 specified and may change with newer releases of this program. They are
747 however carefully selected to best aid in debugging.
748
749 @item --debug @var{flags}
750 @opindex debug
751 This option is only useful for debugging and the behaviour may change
752 at any time without notice; using @code{--debug-levels} is the
753 preferred method to select the debug verbosity.  FLAGS are bit encoded
754 and may be given in usual C-Syntax. The currently defined bits are:
755
756 @table @code
757 @item 0  (1)
758 X.509 or OpenPGP protocol related data
759 @item 1  (2)
760 values of big number integers
761 @item 2  (4)
762 low level crypto operations
763 @item 5  (32)
764 memory allocation
765 @item 6  (64)
766 caching
767 @item 7  (128)
768 show memory statistics
769 @item 9  (512)
770 write hashed data to files named @code{dbgmd-000*}
771 @item 10 (1024)
772 trace Assuan protocol
773 @end table
774
775 Note, that all flags set using this option may get overridden by
776 @code{--debug-level}.
777
778 @item --debug-all
779 @opindex debug-all
780 Same as @code{--debug=0xffffffff}
781
782 @item --debug-allow-core-dump
783 @opindex debug-allow-core-dump
784 Usually @command{gpgsm} tries to avoid dumping core by well written code and by
785 disabling core dumps for security reasons.  However, bugs are pretty
786 durable beasts and to squash them it is sometimes useful to have a core
787 dump.  This option enables core dumps unless the Bad Thing happened
788 before the option parsing.
789
790 @item --debug-no-chain-validation
791 @opindex debug-no-chain-validation
792 This is actually not a debugging option but only useful as such.  It
793 lets @command{gpgsm} bypass all certificate chain validation checks.
794
795 @item --debug-ignore-expiration
796 @opindex debug-ignore-expiration
797 This is actually not a debugging option but only useful as such.  It
798 lets @command{gpgsm} ignore all notAfter dates, this is used by the regression
799 tests.
800
801 @item --passphrase-fd @code{n}
802 @opindex passphrase-fd
803 Read the passphrase from file descriptor @code{n}. Only the first line
804 will be read from file descriptor @code{n}. If you use 0 for @code{n},
805 the passphrase will be read from STDIN. This can only be used if only
806 one passphrase is supplied.
807
808 Note that this passphrase is only used if the option @option{--batch}
809 has also been given.
810
811 @item --pinentry-mode @code{mode}
812 @opindex pinentry-mode
813 Set the pinentry mode to @code{mode}.  Allowed values for @code{mode}
814 are:
815 @table @asis
816   @item default
817   Use the default of the agent, which is @code{ask}.
818   @item ask
819   Force the use of the Pinentry.
820   @item cancel
821   Emulate use of Pinentry's cancel button.
822   @item error
823   Return a Pinentry error (``No Pinentry'').
824   @item loopback
825   Redirect Pinentry queries to the caller.  Note that in contrast to
826   Pinentry the user is not prompted again if he enters a bad password.
827 @end table
828
829 @item --request-origin @var{origin}
830 @opindex request-origin
831 Tell gpgsm to assume that the operation ultimately originated at
832 @var{origin}.  Depending on the origin certain restrictions are applied
833 and the Pinentry may include an extra note on the origin.  Supported
834 values for @var{origin} are: @code{local} which is the default,
835 @code{remote} to indicate a remote origin or @code{browser} for an
836 operation requested by a web browser.
837
838 @item --no-common-certs-import
839 @opindex no-common-certs-import
840 Suppress the import of common certificates on keybox creation.
841
842 @end table
843
844 All the long options may also be given in the configuration file after
845 stripping off the two leading dashes.
846
847 @c *******************************************
848 @c ***************            ****************
849 @c ***************  USER ID   ****************
850 @c ***************            ****************
851 @c *******************************************
852 @mansect how to specify a user id
853 @ifset isman
854 @include specify-user-id.texi
855 @end ifset
856
857 @c *******************************************
858 @c ***************            ****************
859 @c ***************   FILES    ****************
860 @c ***************            ****************
861 @c *******************************************
862 @mansect files
863 @node GPGSM Configuration
864 @section Configuration files
865
866 There are a few configuration files to control certain aspects of
867 @command{gpgsm}'s operation. Unless noted, they are expected in the
868 current home directory (@pxref{option --homedir}).
869
870 @table @file
871
872 @item gpgsm.conf
873 @efindex gpgsm.conf
874 This is the standard configuration file read by @command{gpgsm} on
875 startup.  It may contain any valid long option; the leading two dashes
876 may not be entered and the option may not be abbreviated.  This default
877 name may be changed on the command line (@pxref{gpgsm-option --options}).
878 You should backup this file.
879
880
881 @item policies.txt
882 @efindex policies.txt
883 This is a list of allowed CA policies.  This file should list the
884 object identifiers of the policies line by line.  Empty lines and
885 lines starting with a hash mark are ignored.  Policies missing in this
886 file and not marked as critical in the certificate will print only a
887 warning; certificates with policies marked as critical and not listed
888 in this file will fail the signature verification.  You should backup
889 this file.
890
891 For example, to allow only the policy 2.289.9.9, the file should look
892 like this:
893
894 @c man:.RS
895 @example
896 # Allowed policies
897 2.289.9.9
898 @end example
899 @c man:.RE
900
901 @item qualified.txt
902 @efindex qualified.txt
903 This is the list of root certificates used for qualified certificates.
904 They are defined as certificates capable of creating legally binding
905 signatures in the same way as handwritten signatures are.  Comments
906 start with a hash mark and empty lines are ignored.  Lines do have a
907 length limit but this is not a serious limitation as the format of the
908 entries is fixed and checked by @command{gpgsm}: A non-comment line starts with
909 optional whitespace, followed by exactly 40 hex characters, white space
910 and a lowercased 2 letter country code.  Additional data delimited with
911 by a white space is current ignored but might late be used for other
912 purposes.
913
914 Note that even if a certificate is listed in this file, this does not
915 mean that the certificate is trusted; in general the certificates listed
916 in this file need to be listed also in @file{trustlist.txt}.
917
918 This is a global file an installed in the data directory
919 (e.g. @file{@value{DATADIR}/qualified.txt}).  GnuPG installs a suitable
920 file with root certificates as used in Germany.  As new Root-CA
921 certificates may be issued over time, these entries may need to be
922 updated; new distributions of this software should come with an updated
923 list but it is still the responsibility of the Administrator to check
924 that this list is correct.
925
926 Every time @command{gpgsm} uses a certificate for signing or verification
927 this file will be consulted to check whether the certificate under
928 question has ultimately been issued by one of these CAs.  If this is the
929 case the user will be informed that the verified signature represents a
930 legally binding (``qualified'') signature.  When creating a signature
931 using such a certificate an extra prompt will be issued to let the user
932 confirm that such a legally binding signature shall really be created.
933
934 Because this software has not yet been approved for use with such
935 certificates, appropriate notices will be shown to indicate this fact.
936
937 @item help.txt
938 @efindex help.txt
939 This is plain text file with a few help entries used with
940 @command{pinentry} as well as a large list of help items for
941 @command{gpg} and @command{gpgsm}.  The standard file has English help
942 texts; to install localized versions use filenames like @file{help.LL.txt}
943 with LL denoting the locale.  GnuPG comes with a set of predefined help
944 files in the data directory (e.g. @file{@value{DATADIR}/gnupg/help.de.txt})
945 and allows overriding of any help item by help files stored in the
946 system configuration directory (e.g. @file{@value{SYSCONFDIR}/help.de.txt}).
947 For a reference of the help file's syntax, please see the installed
948 @file{help.txt} file.
949
950
951 @item com-certs.pem
952 @efindex com-certs.pem
953 This file is a collection of common certificates used to populated a
954 newly created @file{pubring.kbx}.  An administrator may replace this
955 file with a custom one.  The format is a concatenation of PEM encoded
956 X.509 certificates.  This global file is installed in the data directory
957 (e.g. @file{@value{DATADIR}/com-certs.pem}).
958
959 @end table
960
961 @c man:.RE
962 Note that on larger installations, it is useful to put predefined files
963 into the directory @file{/etc/skel/.gnupg/} so that newly created users
964 start up with a working configuration.  For existing users a small
965 helper script is provided to create these files (@pxref{addgnupghome}).
966
967 For internal purposes @command{gpgsm} creates and maintains a few other files;
968 they all live in the current home directory (@pxref{option
969 --homedir}).  Only @command{gpgsm} may modify these files.
970
971
972 @table @file
973 @item pubring.kbx
974 @efindex pubring.kbx
975 This a database file storing the certificates as well as meta
976 information.  For debugging purposes the tool @command{kbxutil} may be
977 used to show the internal structure of this file.  You should backup
978 this file.
979
980 @item random_seed
981 @efindex random_seed
982 This content of this file is used to maintain the internal state of the
983 random number generator across invocations.  The same file is used by
984 other programs of this software too.
985
986 @item S.gpg-agent
987 @efindex S.gpg-agent
988 If this file exists
989 @command{gpgsm} will first try to connect to this socket for
990 accessing @command{gpg-agent} before starting a new @command{gpg-agent}
991 instance.  Under Windows this socket (which in reality be a plain file
992 describing a regular TCP listening port) is the standard way of
993 connecting the @command{gpg-agent}.
994
995 @end table
996
997
998 @c *******************************************
999 @c ***************            ****************
1000 @c ***************  EXAMPLES  ****************
1001 @c ***************            ****************
1002 @c *******************************************
1003 @mansect examples
1004 @node GPGSM Examples
1005 @section Examples
1006
1007 @example
1008 $ gpgsm -er goo@@bar.net <plaintext >ciphertext
1009 @end example
1010
1011
1012 @c *******************************************
1013 @c ***************              **************
1014 @c ***************  UNATTENDED  **************
1015 @c ***************              **************
1016 @c *******************************************
1017 @manpause
1018 @node Unattended Usage
1019 @section Unattended Usage
1020
1021 @command{gpgsm} is often used as a backend engine by other software.  To help
1022 with this a machine interface has been defined to have an unambiguous
1023 way to do this.  This is most likely used with the @code{--server} command
1024 but may also be used in the standard operation mode by using the
1025 @code{--status-fd} option.
1026
1027 @menu
1028 * Automated signature checking::  Automated signature checking.
1029 * CSR and certificate creation::  CSR and certificate creation.
1030 @end menu
1031
1032 @node Automated signature checking
1033 @subsection Automated signature checking
1034
1035 It is very important to understand the semantics used with signature
1036 verification.  Checking a signature is not as simple as it may sound and
1037 so the operation is a bit complicated.  In most cases it is required
1038 to look at several status lines.  Here is a table of all cases a signed
1039 message may have:
1040
1041 @table @asis
1042 @item The signature is valid
1043 This does mean that the signature has been successfully verified, the
1044 certificates are all sane.  However there are two subcases with
1045 important information:  One of the certificates may have expired or a
1046 signature of a message itself as expired.  It is a sound practise to
1047 consider such a signature still as valid but additional information
1048 should be displayed.  Depending on the subcase @command{gpgsm} will issue
1049 these status codes:
1050   @table @asis
1051   @item signature valid and nothing did expire
1052   @code{GOODSIG}, @code{VALIDSIG}, @code{TRUST_FULLY}
1053   @item signature valid but at least one certificate has expired
1054   @code{EXPKEYSIG}, @code{VALIDSIG}, @code{TRUST_FULLY}
1055   @item signature valid but expired
1056   @code{EXPSIG}, @code{VALIDSIG}, @code{TRUST_FULLY}
1057   Note, that this case is currently not implemented.
1058   @end table
1059
1060 @item The signature is invalid
1061 This means that the signature verification failed (this is an indication
1062 of a transfer error, a program error or tampering with the message).
1063 @command{gpgsm} issues one of these status codes sequences:
1064   @table @code
1065   @item  @code{BADSIG}
1066   @item  @code{GOODSIG}, @code{VALIDSIG} @code{TRUST_NEVER}
1067   @end table
1068
1069 @item Error verifying a signature
1070 For some reason the signature could not be verified, i.e. it cannot be
1071 decided whether the signature is valid or invalid.  A common reason for
1072 this is a missing certificate.
1073
1074 @end table
1075
1076 @node CSR and certificate creation
1077 @subsection CSR and certificate creation
1078
1079 The command @option{--generate-key} may be used along with the option
1080 @option{--batch} to either create a certificate signing request (CSR)
1081 or an X.509 certificate.  This is controlled by a parameter file; the
1082 format of this file is as follows:
1083
1084 @itemize @bullet
1085 @item Text only, line length is limited to about 1000 characters.
1086 @item UTF-8 encoding must be used to specify non-ASCII characters.
1087 @item Empty lines are ignored.
1088 @item Leading and trailing while space is ignored.
1089 @item A hash sign as the first non white space character indicates
1090 a comment line.
1091 @item Control statements are indicated by a leading percent sign, the
1092 arguments are separated by white space from the keyword.
1093 @item Parameters are specified by a keyword, followed by a colon.  Arguments
1094 are separated by white space.
1095 @item The first parameter must be @samp{Key-Type}, control statements
1096 may be placed anywhere.
1097 @item
1098 The order of the parameters does not matter except for @samp{Key-Type}
1099 which must be the first parameter.  The parameters are only used for
1100 the generated CSR/certificate; parameters from previous sets are not
1101 used.  Some syntactically checks may be performed.
1102 @item
1103 Key generation takes place when either the end of the parameter file
1104 is reached, the next @samp{Key-Type} parameter is encountered or at the
1105 control statement @samp{%commit} is encountered.
1106 @end itemize
1107
1108 @noindent
1109 Control statements:
1110
1111 @table @asis
1112
1113 @item %echo @var{text}
1114 Print @var{text} as diagnostic.
1115
1116 @item %dry-run
1117 Suppress actual key generation (useful for syntax checking).
1118
1119 @item %commit
1120 Perform the key generation.  Note that an implicit commit is done at
1121 the next @asis{Key-Type} parameter.
1122
1123 @c  %certfile <filename>
1124 @c      [Not yet implemented!]
1125 @c      Do not write the certificate to the keyDB but to <filename>.
1126 @c      This must be given before the first
1127 @c      commit to take place, duplicate specification of the same filename
1128 @c      is ignored, the last filename before a commit is used.
1129 @c      The filename is used until a new filename is used (at commit points)
1130 @c      and all keys are written to that file.  If a new filename is given,
1131 @c      this file is created (and overwrites an existing one).
1132 @c      Both control statements must be given.
1133 @end table
1134
1135 @noindent
1136 General Parameters:
1137
1138 @table @asis
1139
1140 @item Key-Type: @var{algo}
1141 Starts a new parameter block by giving the type of the primary
1142 key. The algorithm must be capable of signing.  This is a required
1143 parameter.  The only supported value for @var{algo} is @samp{rsa}.
1144
1145 @item Key-Length: @var{nbits}
1146 The requested length of a generated key in bits.  Defaults to 3072.
1147
1148 @item Key-Grip: @var{hexstring}
1149 This is optional and used to generate a CSR or certificate for an
1150 already existing key.  Key-Length will be ignored when given.
1151
1152 @item Key-Usage: @var{usage-list}
1153 Space or comma delimited list of key usage, allowed values are
1154 @samp{encrypt}, @samp{sign} and @samp{cert}.  This is used to generate
1155 the keyUsage extension.  Please make sure that the algorithm is
1156 capable of this usage.  Default is to allow encrypt and sign.
1157
1158 @item Name-DN: @var{subject-name}
1159 This is the Distinguished Name (DN) of the subject in RFC-2253 format.
1160
1161 @item Name-Email: @var{string}
1162 This is an email address for the altSubjectName.  This parameter is
1163 optional but may occur several times to add several email addresses to
1164 a certificate.
1165
1166 @item Name-DNS: @var{string}
1167 The is an DNS name for the altSubjectName.  This parameter is optional
1168 but may occur several times to add several DNS names to a certificate.
1169
1170 @item Name-URI: @var{string}
1171 This is an URI for the altSubjectName.  This parameter is optional but
1172 may occur several times to add several URIs to a certificate.
1173 @end table
1174
1175 @noindent
1176 Additional parameters used to create a certificate (in contrast to a
1177 certificate signing request):
1178
1179 @table @asis
1180
1181 @item Serial: @var{sn}
1182 If this parameter is given an X.509 certificate will be generated.
1183 @var{sn} is expected to be a hex string representing an unsigned
1184 integer of arbitrary length.  The special value @samp{random} can be
1185 used to create a 64 bit random serial number.
1186
1187 @item Issuer-DN: @var{issuer-name}
1188 This is the DN name of the issuer in RFC-2253 format.  If it is not set
1189 it will default to the subject DN and a special GnuPG extension will
1190 be included in the certificate to mark it as a standalone certificate.
1191
1192 @item Creation-Date: @var{iso-date}
1193 @itemx Not-Before: @var{iso-date}
1194 Set the notBefore date of the certificate.  Either a date like
1195 @samp{1986-04-26} or @samp{1986-04-26 12:00} or a standard ISO
1196 timestamp like @samp{19860426T042640} may be used.  The time is
1197 considered to be UTC.  If it is not given the current date is used.
1198
1199 @item Expire-Date: @var{iso-date}
1200 @itemx Not-After: @var{iso-date}
1201 Set the notAfter date of the certificate.  Either a date like
1202 @samp{2063-04-05} or @samp{2063-04-05 17:00} or a standard ISO
1203 timestamp like @samp{20630405T170000} may be used.  The time is
1204 considered to be UTC.  If it is not given a default value in the not
1205 too far future is used.
1206
1207 @item Signing-Key: @var{keygrip}
1208 This gives the keygrip of the key used to sign the certificate.  If it
1209 is not given a self-signed certificate will be created.  For
1210 compatibility with future versions, it is suggested to prefix the
1211 keygrip with a @samp{&}.
1212
1213 @item Hash-Algo: @var{hash-algo}
1214 Use @var{hash-algo} for this CSR or certificate.  The supported hash
1215 algorithms are: @samp{sha1}, @samp{sha256}, @samp{sha384} and
1216 @samp{sha512}; they may also be specified with uppercase letters.  The
1217 default is @samp{sha256}.
1218
1219 @end table
1220
1221 @c *******************************************
1222 @c ***************           *****************
1223 @c ***************  ASSSUAN  *****************
1224 @c ***************           *****************
1225 @c *******************************************
1226 @node GPGSM Protocol
1227 @section The Protocol the Server Mode Uses
1228
1229 Description of the protocol used to access @command{GPGSM}.
1230 @command{GPGSM} does implement the Assuan protocol and in addition
1231 provides a regular command line interface which exhibits a full client
1232 to this protocol (but uses internal linking).  To start
1233 @command{gpgsm} as a server the command line the option
1234 @code{--server} must be used.  Additional options are provided to
1235 select the communication method (i.e. the name of the socket).
1236
1237 We assume that the connection has already been established; see the
1238 Assuan manual for details.
1239
1240 @menu
1241 * GPGSM ENCRYPT::         Encrypting a message.
1242 * GPGSM DECRYPT::         Decrypting a message.
1243 * GPGSM SIGN::            Signing a message.
1244 * GPGSM VERIFY::          Verifying a message.
1245 * GPGSM GENKEY::          Generating a key.
1246 * GPGSM LISTKEYS::        List available keys.
1247 * GPGSM EXPORT::          Export certificates.
1248 * GPGSM IMPORT::          Import certificates.
1249 * GPGSM DELETE::          Delete certificates.
1250 * GPGSM GETAUDITLOG::     Retrieve an audit log.
1251 * GPGSM GETINFO::         Information about the process
1252 * GPGSM OPTION::          Session options.
1253 @end menu
1254
1255
1256 @node GPGSM ENCRYPT
1257 @subsection Encrypting a Message
1258
1259 Before encryption can be done the recipient must be set using the
1260 command:
1261
1262 @example
1263   RECIPIENT @var{userID}
1264 @end example
1265
1266 Set the recipient for the encryption.  @var{userID} should be the
1267 internal representation of the key; the server may accept any other way
1268 of specification.  If this is a valid and trusted recipient the server
1269 does respond with OK, otherwise the return is an ERR with the reason why
1270 the recipient cannot be used, the encryption will then not be done for
1271 this recipient.  If the policy is not to encrypt at all if not all
1272 recipients are valid, the client has to take care of this.  All
1273 @code{RECIPIENT} commands are cumulative until a @code{RESET} or an
1274 successful @code{ENCRYPT} command.
1275
1276 @example
1277   INPUT FD[=@var{n}] [--armor|--base64|--binary]
1278 @end example
1279
1280 Set the file descriptor for the message to be encrypted to @var{n}.
1281 Obviously the pipe must be open at that point, the server establishes
1282 its own end.  If the server returns an error the client should consider
1283 this session failed.  If @var{n} is not given, this commands uses the
1284 last file descriptor passed to the application.
1285 @xref{fun-assuan_sendfd, ,the assuan_sendfd function,assuan,the Libassuan
1286 manual}, on how to do descriptor passing.
1287
1288 The @code{--armor} option may be used to advise the server that the
1289 input data is in @acronym{PEM} format, @code{--base64} advises that a
1290 raw base-64 encoding is used, @code{--binary} advises of raw binary
1291 input (@acronym{BER}).  If none of these options is used, the server
1292 tries to figure out the used encoding, but this may not always be
1293 correct.
1294
1295 @example
1296   OUTPUT FD[=@var{n}] [--armor|--base64]
1297 @end example
1298
1299 Set the file descriptor to be used for the output (i.e. the encrypted
1300 message). Obviously the pipe must be open at that point, the server
1301 establishes its own end.  If the server returns an error the client
1302 should consider this session failed.
1303
1304 The option @option{--armor} encodes the output in @acronym{PEM} format, the
1305 @option{--base64} option applies just a base-64 encoding.  No option
1306 creates binary output (@acronym{BER}).
1307
1308 The actual encryption is done using the command
1309
1310 @example
1311   ENCRYPT
1312 @end example
1313
1314 It takes the plaintext from the @code{INPUT} command, writes to the
1315 ciphertext to the file descriptor set with the @code{OUTPUT} command,
1316 take the recipients from all the recipients set so far.  If this command
1317 fails the clients should try to delete all output currently done or
1318 otherwise mark it as invalid.  @command{GPGSM} does ensure that there
1319 will not be any
1320 security problem with leftover data on the output in this case.
1321
1322 This command should in general not fail, as all necessary checks have
1323 been done while setting the recipients.  The input and output pipes are
1324 closed.
1325
1326
1327 @node GPGSM DECRYPT
1328 @subsection Decrypting a message
1329
1330 Input and output FDs are set the same way as in encryption, but
1331 @code{INPUT} refers to the ciphertext and @code{OUTPUT} to the plaintext. There
1332 is no need to set recipients.  @command{GPGSM} automatically strips any
1333 @acronym{S/MIME} headers from the input, so it is valid to pass an
1334 entire MIME part to the INPUT pipe.
1335
1336 The decryption is done by using the command
1337
1338 @example
1339   DECRYPT
1340 @end example
1341
1342 It performs the decrypt operation after doing some check on the internal
1343 state (e.g. that all needed data has been set).  Because it utilizes
1344 the GPG-Agent for the session key decryption, there is no need to ask
1345 the client for a protecting passphrase - GpgAgent takes care of this by
1346 requesting this from the user.
1347
1348
1349 @node GPGSM SIGN
1350 @subsection Signing a Message
1351
1352 Signing is usually done with these commands:
1353
1354 @example
1355   INPUT FD[=@var{n}] [--armor|--base64|--binary]
1356 @end example
1357
1358 This tells @command{GPGSM} to read the data to sign from file descriptor @var{n}.
1359
1360 @example
1361   OUTPUT FD[=@var{m}] [--armor|--base64]
1362 @end example
1363
1364 Write the output to file descriptor @var{m}.  If a detached signature is
1365 requested, only the signature is written.
1366
1367 @example
1368   SIGN [--detached]
1369 @end example
1370
1371 Sign the data set with the @code{INPUT} command and write it to the sink set by
1372 @code{OUTPUT}.  With @code{--detached}, a detached signature is created
1373 (surprise).
1374
1375 The key used for signing is the default one or the one specified in
1376 the configuration file.  To get finer control over the keys, it is
1377 possible to use the command
1378
1379 @example
1380   SIGNER @var{userID}
1381 @end example
1382
1383 to set the signer's key.  @var{userID} should be the
1384 internal representation of the key; the server may accept any other way
1385 of specification.  If this is a valid and trusted recipient the server
1386 does respond with OK, otherwise the return is an ERR with the reason why
1387 the key cannot be used, the signature will then not be created using
1388 this key.  If the policy is not to sign at all if not all
1389 keys are valid, the client has to take care of this.  All
1390 @code{SIGNER} commands are cumulative until a @code{RESET} is done.
1391 Note that a @code{SIGN} does not reset this list of signers which is in
1392 contrast to the @code{RECIPIENT} command.
1393
1394
1395 @node GPGSM VERIFY
1396 @subsection Verifying a Message
1397
1398 To verify a message the command:
1399
1400 @example
1401   VERIFY
1402 @end example
1403
1404 is used. It does a verify operation on the message send to the input FD.
1405 The result is written out using status lines.  If an output FD was
1406 given, the signed text will be written to that.  If the signature is a
1407 detached one, the server will inquire about the signed material and the
1408 client must provide it.
1409
1410 @node GPGSM GENKEY
1411 @subsection Generating a Key
1412
1413 This is used to generate a new keypair, store the secret part in the
1414 @acronym{PSE} and the public key in the key database.  We will probably
1415 add optional commands to allow the client to select whether a hardware
1416 token is used to store the key.  Configuration options to
1417 @command{GPGSM} can be used to restrict the use of this command.
1418
1419 @example
1420   GENKEY
1421 @end example
1422
1423 @command{GPGSM} checks whether this command is allowed and then does an
1424 INQUIRY to get the key parameters, the client should then send the
1425 key parameters in the native format:
1426
1427 @example
1428     S: INQUIRE KEY_PARAM native
1429     C: D foo:fgfgfg
1430     C: D bar
1431     C: END
1432 @end example
1433
1434 Please note that the server may send Status info lines while reading the
1435 data lines from the client.  After this the key generation takes place
1436 and the server eventually does send an ERR or OK response.  Status lines
1437 may be issued as a progress indicator.
1438
1439
1440 @node GPGSM LISTKEYS
1441 @subsection List available keys
1442 @anchor{gpgsm-cmd listkeys}
1443
1444 To list the keys in the internal database or using an external key
1445 provider, the command:
1446
1447 @example
1448   LISTKEYS  @var{pattern}
1449 @end example
1450
1451 is used.  To allow multiple patterns (which are ORed during the search)
1452 quoting is required: Spaces are to be translated into "+" or into "%20";
1453 in turn this requires that the usual escape quoting rules are done.
1454
1455 @example
1456   LISTSECRETKEYS @var{pattern}
1457 @end example
1458
1459 Lists only the keys where a secret key is available.
1460
1461 The list commands are affected by the option
1462
1463 @example
1464   OPTION list-mode=@var{mode}
1465 @end example
1466
1467 where mode may be:
1468 @table @code
1469 @item 0
1470 Use default (which is usually the same as 1).
1471 @item 1
1472 List only the internal keys.
1473 @item 2
1474 List only the external keys.
1475 @item 3
1476 List internal and external keys.
1477 @end table
1478
1479 Note that options are valid for the entire session.
1480
1481
1482 @node GPGSM EXPORT
1483 @subsection Export certificates
1484
1485 To export certificate from the internal key database the command:
1486
1487 @example
1488   EXPORT [--data [--armor] [--base64]] [--] @var{pattern}
1489 @end example
1490
1491 is used.  To allow multiple patterns (which are ORed) quoting is
1492 required: Spaces are to be translated into "+" or into "%20"; in turn
1493 this requires that the usual escape quoting rules are done.
1494
1495 If the @option{--data} option has not been given, the format of the
1496 output depends on what was set with the @code{OUTPUT} command.  When using
1497 @acronym{PEM} encoding a few informational lines are prepended.
1498
1499 If the @option{--data} has been given, a target set via @code{OUTPUT} is
1500 ignored and the data is returned inline using standard
1501 @code{D}-lines. This avoids the need for an extra file descriptor.  In
1502 this case the options @option{--armor} and @option{--base64} may be used
1503 in the same way as with the @code{OUTPUT} command.
1504
1505
1506 @node GPGSM IMPORT
1507 @subsection Import certificates
1508
1509 To import certificates into the internal key database, the command
1510
1511 @example
1512   IMPORT [--re-import]
1513 @end example
1514
1515 is used.  The data is expected on the file descriptor set with the
1516 @code{INPUT} command.  Certain checks are performed on the
1517 certificate.  Note that the code will also handle PKCS#12 files and
1518 import private keys; a helper program is used for that.
1519
1520 With the option @option{--re-import} the input data is expected to a be
1521 a linefeed separated list of fingerprints.  The command will re-import
1522 the corresponding certificates; that is they are made permanent by
1523 removing their ephemeral flag.
1524
1525
1526 @node GPGSM DELETE
1527 @subsection Delete certificates
1528
1529 To delete a certificate the command
1530
1531 @example
1532   DELKEYS @var{pattern}
1533 @end example
1534
1535 is used.  To allow multiple patterns (which are ORed) quoting is
1536 required: Spaces are to be translated into "+" or into "%20"; in turn
1537 this requires that the usual escape quoting rules are done.
1538
1539 The certificates must be specified unambiguously otherwise an error is
1540 returned.
1541
1542 @node GPGSM GETAUDITLOG
1543 @subsection Retrieve an audit log
1544 @anchor{gpgsm-cmd getauditlog}
1545
1546 This command is used to retrieve an audit log.
1547
1548 @example
1549 GETAUDITLOG [--data] [--html]
1550 @end example
1551
1552 If @option{--data} is used, the audit log is send using D-lines
1553 instead of being sent to the file descriptor given by an @code{OUTPUT}
1554 command.  If @option{--html} is used, the output is formatted as an
1555 XHTML block. This is designed to be incorporated into a HTML
1556 document.
1557
1558
1559 @node GPGSM GETINFO
1560 @subsection  Return information about the process
1561
1562 This is a multipurpose function to return a variety of information.
1563
1564 @example
1565 GETINFO @var{what}
1566 @end example
1567
1568 The value of @var{what} specifies the kind of information returned:
1569 @table @code
1570 @item version
1571 Return the version of the program.
1572 @item pid
1573 Return the process id of the process.
1574 @item agent-check
1575 Return OK if the agent is running.
1576 @item cmd_has_option @var{cmd} @var{opt}
1577 Return OK if the command @var{cmd} implements the option @var{opt}.
1578 The leading two dashes usually used with @var{opt} shall not be given.
1579 @item offline
1580 Return OK if the connection is in offline mode.  This may be either
1581 due to a @code{OPTION offline=1} or due to @command{gpgsm} being
1582 started with option @option{--disable-dirmngr}.
1583 @end table
1584
1585 @node GPGSM OPTION
1586 @subsection  Session options
1587
1588 The standard Assuan option handler supports these options.
1589
1590 @example
1591 OPTION @var{name}[=@var{value}]
1592 @end example
1593
1594 These @var{name}s are recognized:
1595
1596 @table @code
1597
1598 @item putenv
1599 Change the session's environment to be passed via gpg-agent to
1600 Pinentry.  @var{value} is a string of the form
1601 @code{<KEY>[=[<STRING>]]}.  If only @code{<KEY>} is given the
1602 environment variable @code{<KEY>} is removed from the session
1603 environment, if @code{<KEY>=} is given that environment variable is
1604 set to the empty string, and if @code{<STRING>} is given it is set to
1605 that string.
1606
1607 @item display
1608 @efindex DISPLAY
1609 Set the session environment variable @code{DISPLAY} is set to @var{value}.
1610 @item ttyname
1611 @efindex GPG_TTY
1612 Set the session environment variable @code{GPG_TTY} is set to @var{value}.
1613 @item ttytype
1614 @efindex TERM
1615 Set the session environment variable @code{TERM} is set to @var{value}.
1616 @item lc-ctype
1617 @efindex LC_CTYPE
1618 Set the session environment variable @code{LC_CTYPE} is set to @var{value}.
1619 @item lc-messages
1620 @efindex LC_MESSAGES
1621 Set the session environment variable @code{LC_MESSAGES} is set to @var{value}.
1622 @item xauthority
1623 @efindex XAUTHORITY
1624 Set the session environment variable @code{XAUTHORITY} is set to @var{value}.
1625 @item pinentry-user-data
1626 @efindex PINENTRY_USER_DATA
1627 Set the session environment variable @code{PINENTRY_USER_DATA} is set
1628 to @var{value}.
1629
1630 @item include-certs
1631 This option overrides the command line option
1632 @option{--include-certs}.  A @var{value} of -2 includes all
1633 certificates except for the root certificate, -1 includes all
1634 certificates, 0 does not include any certificates, 1 includes only the
1635 signers certificate and all other positive values include up to
1636 @var{value} certificates starting with the signer cert.
1637
1638 @item list-mode
1639 @xref{gpgsm-cmd listkeys}.
1640
1641 @item list-to-output
1642 If @var{value} is true the output of the list commands
1643 (@pxref{gpgsm-cmd listkeys}) is written to the file descriptor set
1644 with the last @code{OUTPUT} command.  If @var{value} is false the output is
1645 written via data lines; this is the default.
1646
1647 @item with-validation
1648 If @var{value} is true for each listed certificate the validation
1649 status is printed.  This may result in the download of a CRL or the
1650 user being asked about the trustworthiness of a root certificate.  The
1651 default is given by a command line option (@pxref{gpgsm-option
1652 --with-validation}).
1653
1654
1655 @item with-secret
1656 If @var{value} is true certificates with a corresponding private key
1657 are marked by the list commands.
1658
1659 @item validation-model
1660 This option overrides the command line option
1661 @option{validation-model} for the session.
1662 (@xref{gpgsm-option --validation-model}.)
1663
1664 @item with-key-data
1665 This option globally enables the command line option
1666 @option{--with-key-data}.  (@xref{gpgsm-option --with-key-data}.)
1667
1668 @item enable-audit-log
1669 If @var{value} is true data to write an audit log is gathered.
1670 (@xref{gpgsm-cmd getauditlog}.)
1671
1672 @item allow-pinentry-notify
1673 If this option is used notifications about the launch of a Pinentry
1674 are passed back to the client.
1675
1676 @item with-ephemeral-keys
1677 If @var{value} is true ephemeral certificates are included in the
1678 output of the list commands.
1679
1680 @item no-encrypt-to
1681 If this option is used all keys set by the command line option
1682 @option{--encrypt-to} are ignored.
1683
1684 @item offline
1685 If @var{value} is true or @var{value} is not given all network access
1686 is disabled for this session.  This is the same as the command line
1687 option @option{--disable-dirmngr}.
1688
1689 @end table
1690
1691 @mansect see also
1692 @ifset isman
1693 @command{gpg2}(1),
1694 @command{gpg-agent}(1)
1695 @end ifset
1696 @include see-also-note.texi