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