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