chiark / gitweb /
dirmngr: Fix final close of LISTEN_FD.
[gnupg2.git] / doc / dirmngr.texi
1 @c Copyright (C) 2002 Klar"alvdalens Datakonsult AB
2 @c Copyright (C) 2004, 2005, 2006, 2007 g10 Code GmbH
3 @c This is part of the GnuPG manual.
4 @c For copying conditions, see the file gnupg.texi.
5
6 @include defs.inc
7
8 @node Invoking DIRMNGR
9 @chapter Invoking DIRMNGR
10 @cindex DIRMNGR command options
11 @cindex command options
12 @cindex options, DIRMNGR command
13
14 @manpage dirmngr.8
15 @ifset manverb
16 .B dirmngr
17 \- CRL and OCSP daemon
18 @end ifset
19
20 @mansect synopsis
21 @ifset manverb
22 .B  dirmngr
23 .RI [ options ]
24 .I command
25 .RI [ args ]
26 @end ifset
27
28 @mansect description
29 Since version 2.1 of GnuPG, @command{dirmngr} takes care of accessing
30 the OpenPGP keyservers.  As with previous versions it is also used as
31 a server for managing and downloading certificate revocation lists
32 (CRLs) for X.509 certificates, downloading X.509 certificates, and
33 providing access to OCSP providers.  Dirmngr is invoked internally by
34 @command{gpg}, @command{gpgsm}, or via the @command{gpg-connect-agent}
35 tool.
36
37 @manpause
38 @noindent
39 @xref{Option Index},for an index to @command{DIRMNGR}'s commands and
40 options.
41 @mancont
42
43 @menu
44 * Dirmngr Commands::      List of all commands.
45 * Dirmngr Options::       List of all options.
46 * Dirmngr Configuration:: Configuration files.
47 * Dirmngr Signals::       Use of signals.
48 * Dirmngr Examples::      Some usage examples.
49 * Dirmngr Protocol::      The protocol dirmngr uses.
50 @end menu
51
52
53 @node Dirmngr Commands
54 @section Commands
55 @mansect commands
56
57 Commands are not distinguished from options except for the fact that
58 only one command is allowed.
59
60 @table @gnupgtabopt
61 @item --version
62 @opindex version
63 Print the program version and licensing information.  Note that you cannot
64 abbreviate this command.
65
66 @item --help, -h
67 @opindex help
68 Print a usage message summarizing the most useful command-line options.
69 Note that you cannot abbreviate this command.
70
71 @item --dump-options
72 @opindex dump-options
73 Print a list of all available options and commands.  Note that you cannot
74 abbreviate this command.
75
76 @item --server
77 @opindex server
78 Run in server mode and wait for commands on the @code{stdin}.  The
79 default mode is to create a socket and listen for commands there.
80 This is only used for testing.
81
82 @item --daemon
83 @opindex daemon
84 Run in background daemon mode and listen for commands on a socket.
85 This is the way @command{dirmngr} is started on demand by the other
86 GnuPG components.  To force starting @command{dirmngr} it is in
87 general best to use @code{gpgconf --launch dirmngr}.
88
89 @item --supervised
90 @opindex supervised
91 Run in the foreground, sending logs to stderr, and listening on file
92 descriptor 3, which must already be bound to a listening socket.  This
93 is useful when running under systemd or other similar process
94 supervision schemes.  This option is not supported on Windows.
95
96 @item --list-crls
97 @opindex list-crls
98 List the contents of the CRL cache on @code{stdout}. This is probably
99 only useful for debugging purposes.
100
101 @item --load-crl @var{file}
102 @opindex load-crl
103 This command requires a filename as additional argument, and it will
104 make Dirmngr try to import the CRL in @var{file} into it's cache.
105 Note, that this is only possible if Dirmngr is able to retrieve the
106 CA's certificate directly by its own means.  In general it is better
107 to use @code{gpgsm}'s @code{--call-dirmngr loadcrl filename} command
108 so that @code{gpgsm} can help dirmngr.
109
110 @item --fetch-crl @var{url}
111 @opindex fetch-crl
112 This command requires an URL as additional argument, and it will make
113 dirmngr try to retrieve and import the CRL from that @var{url} into
114 it's cache.  This is mainly useful for debugging purposes.  The
115 @command{dirmngr-client} provides the same feature for a running dirmngr.
116
117 @item --shutdown
118 @opindex shutdown
119 This commands shuts down an running instance of Dirmngr.  This command
120 has currently no effect.
121
122 @item --flush
123 @opindex flush
124 This command removes all CRLs from Dirmngr's cache.  Client requests
125 will thus trigger reading of fresh CRLs.
126
127 @end table
128
129
130 @mansect options
131 @node Dirmngr Options
132 @section Option Summary
133
134 Note that all long options with the exception of @option{--options}
135 and @option{--homedir} may also be given in the configuration file
136 after stripping off the two leading dashes.
137
138 @table @gnupgtabopt
139
140 @item --options @var{file}
141 @opindex options
142 Reads configuration from @var{file} instead of from the default
143 per-user configuration file.  The default configuration file is named
144 @file{dirmngr.conf} and expected in the home directory.
145
146 @item --homedir @var{dir}
147 @opindex options
148 Set the name of the home directory to @var{dir}.  This option is only
149 effective when used on the command line.  The default is
150 the directory named @file{.gnupg} directly below the home directory
151 of the user unless the environment variable @code{GNUPGHOME} has been set
152 in which case its value will be used.  Many kinds of data are stored within
153 this directory.
154
155
156 @item -v
157 @item --verbose
158 @opindex v
159 @opindex verbose
160 Outputs additional information while running.
161 You can increase the verbosity by giving several
162 verbose commands to @sc{dirmngr}, such as @option{-vv}.
163
164
165 @item --log-file @var{file}
166 @opindex log-file
167 Append all logging output to @var{file}.  This is very helpful in
168 seeing what the agent actually does.  Use @file{socket://} to log to
169 socket.
170
171 @item --debug-level @var{level}
172 @opindex debug-level
173 Select the debug level for investigating problems.  @var{level} may be a
174 numeric value or by a keyword:
175
176 @table @code
177 @item none
178 No debugging at all.  A value of less than 1 may be used instead of
179 the keyword.
180 @item basic
181 Some basic debug messages.  A value between 1 and 2 may be used
182 instead of the keyword.
183 @item advanced
184 More verbose debug messages.  A value between 3 and 5 may be used
185 instead of the keyword.
186 @item expert
187 Even more detailed messages.  A value between 6 and 8 may be used
188 instead of the keyword.
189 @item guru
190 All of the debug messages you can get. A value greater than 8 may be
191 used instead of the keyword.  The creation of hash tracing files is
192 only enabled if the keyword is used.
193 @end table
194
195 How these messages are mapped to the actual debugging flags is not
196 specified and may change with newer releases of this program. They are
197 however carefully selected to best aid in debugging.
198
199 @item --debug @var{flags}
200 @opindex debug
201 Set debugging flags.  This option is only useful for debugging and its
202 behavior may change with a new release.  All flags are or-ed and may
203 be given in C syntax (e.g. 0x0042) or as a comma separated list of
204 flag names.  To get a list of all supported flags the single word
205 "help" can be used.
206
207 @item --debug-all
208 @opindex debug-all
209 Same as @code{--debug=0xffffffff}
210
211 @item --gnutls-debug @var{level}
212 @opindex gnutls-debug
213 Enable debugging of GNUTLS at @var{level}.
214
215 @item --debug-wait @var{n}
216 @opindex debug-wait
217 When running in server mode, wait @var{n} seconds before entering the
218 actual processing loop and print the pid.  This gives time to attach a
219 debugger.
220
221 @item --disable-check-own-socket
222 @opindex disable-check-own-socket
223 On some platforms @command{dirmngr} is able to detect the removal of
224 its socket file and shutdown itself.  This option disable this
225 self-test for debugging purposes.
226
227 @item -s
228 @itemx --sh
229 @itemx -c
230 @itemx --csh
231 @opindex s
232 @opindex sh
233 @opindex c
234 @opindex csh
235 Format the info output in daemon mode for use with the standard Bourne
236 shell respective the C-shell. The default is to guess it based on the
237 environment variable @code{SHELL} which is in almost all cases
238 sufficient.
239
240 @item --force
241 @opindex force
242 Enabling this option forces loading of expired CRLs; this is only
243 useful for debugging.
244
245 @item --use-tor
246 @opindex use-tor
247 This option switches Dirmngr and thus GnuPG into ``Tor mode'' to route
248 all network access via Tor (an anonymity network).  Certain other
249 features are disabled if this mode is active.
250
251 @item --standard-resolver
252 @opindex standard-resolver
253 This option forces the use of the system's standard DNS resolver code.
254 This is mainly used for debugging.  Note that on Windows a standard
255 resolver is not used and all DNS access will return the error ``Not
256 Implemented'' if this function is used.
257
258 @item --recursive-resolver
259 @opindex recursive-resolver
260 When possible use a recursive resolver instead of a stub resolver.
261
262 @item --resolver-timeout @var{n}
263 Set the timeout for the DNS resolver to N seconds.  The default are 30
264 seconds.
265
266 @item --allow-version-check
267 @opindex allow-version-check
268 Allow Dirmngr to connect to @code{https://versions.gnupg.org} to get
269 the list of current software versions.  On debian-packaged versions,
270 this option does nothing since software updates should be handled by
271 the distribution.  See the option @option{--query-swdb} of the command
272 @command{gpgconf} for more details.  Note, that regardless of this
273 option a version check can always be triggered using this command:
274
275 @example
276        gpg-connect-agent --dirmngr 'loadswdb --force' /bye
277 @end example
278
279
280 @item --keyserver @var{name}
281 @opindex keyserver
282 Use @var{name} as your keyserver.  This is the server that @command{gpg}
283 communicates with to receive keys, send keys, and search for
284 keys.  The format of the @var{name} is a URI:
285 `scheme:[//]keyservername[:port]' The scheme is the type of keyserver:
286 "hkp" for the HTTP (or compatible) keyservers, "ldap" for the LDAP
287 keyservers, or "mailto" for the Graff email keyserver. Note that your
288 particular installation of GnuPG may have other keyserver types
289 available as well. Keyserver schemes are case-insensitive. After the
290 keyserver name, optional keyserver configuration options may be
291 provided.  These are the same as the @option{--keyserver-options} of
292 @command{gpg}, but apply only to this particular keyserver.
293
294 Most keyservers synchronize with each other, so there is generally no
295 need to send keys to more than one server. The keyserver
296 @code{hkp://keys.gnupg.net} uses round robin DNS to give a different
297 keyserver each time you use it.
298
299 If exactly two keyservers are configured and only one is a Tor hidden
300 service (.onion), Dirmngr selects the keyserver to use depending on
301 whether Tor is locally running or not.  The check for a running Tor is
302 done for each new connection.
303
304 If no keyserver is explicitly configured, dirmngr will use the
305 built-in default of hkps://hkps.pool.sks-keyservers.net.
306
307 @item --nameserver @var{ipaddr}
308 @opindex nameserver
309 In ``Tor mode'' Dirmngr uses a public resolver via Tor to resolve DNS
310 names.  If the default public resolver, which is @code{8.8.8.8}, shall
311 not be used a different one can be given using this option.  Note that
312 a numerical IP address must be given (IPv6 or IPv4) and that no error
313 checking is done for @var{ipaddr}.
314
315 @item --disable-ipv4
316 @item --disable-ipv6
317 @opindex disable-ipv4
318 @opindex disable-ipv6
319 Disable the use of all IPv4 or IPv6 addresses.
320
321 @item --disable-ldap
322 @opindex disable-ldap
323 Entirely disables the use of LDAP.
324
325 @item --disable-http
326 @opindex disable-http
327 Entirely disables the use of HTTP.
328
329 @item --ignore-http-dp
330 @opindex ignore-http-dp
331 When looking for the location of a CRL, the to be tested certificate
332 usually contains so called @dfn{CRL Distribution Point} (DP) entries
333 which are URLs describing the way to access the CRL.  The first found DP
334 entry is used.  With this option all entries using the @acronym{HTTP}
335 scheme are ignored when looking for a suitable DP.
336
337 @item --ignore-ldap-dp
338 @opindex ignore-ldap-dp
339 This is similar to @option{--ignore-http-dp} but ignores entries using
340 the @acronym{LDAP} scheme.  Both options may be combined resulting in
341 ignoring DPs entirely.
342
343 @item --ignore-ocsp-service-url
344 @opindex ignore-ocsp-service-url
345 Ignore all OCSP URLs contained in the certificate.  The effect is to
346 force the use of the default responder.
347
348 @item --honor-http-proxy
349 @opindex honor-http-proxy
350 If the environment variable @env{http_proxy} has been set, use its
351 value to access HTTP servers.
352
353 @item --http-proxy @var{host}[:@var{port}]
354 @opindex http-proxy
355 @efindex http_proxy
356 Use @var{host} and @var{port} to access HTTP servers.  The use of this
357 option overrides the environment variable @env{http_proxy} regardless
358 whether @option{--honor-http-proxy} has been set.
359
360
361 @item --ldap-proxy @var{host}[:@var{port}]
362 @opindex ldap-proxy
363 Use @var{host} and @var{port} to connect to LDAP servers.  If @var{port}
364 is omitted, port 389 (standard LDAP port) is used.  This overrides any
365 specified host and port part in a LDAP URL and will also be used if host
366 and port have been omitted from the URL.
367
368 @item --only-ldap-proxy
369 @opindex only-ldap-proxy
370 Never use anything else but the LDAP "proxy" as configured with
371 @option{--ldap-proxy}.  Usually @command{dirmngr} tries to use other
372 configured LDAP server if the connection using the "proxy" failed.
373
374
375 @item --ldapserverlist-file @var{file}
376 @opindex ldapserverlist-file
377 Read the list of LDAP servers to consult for CRLs and certificates from
378 file instead of the default per-user ldap server list file. The default
379 value for @var{file} is @file{dirmngr_ldapservers.conf}.
380
381 This server list file contains one LDAP server per line in the format
382
383 @sc{hostname:port:username:password:base_dn}
384
385 Lines starting with a  @samp{#} are comments.
386
387 Note that as usual all strings entered are expected to be UTF-8 encoded.
388 Obviously this will lead to problems if the password has originally been
389 encoded as Latin-1.  There is no other solution here than to put such a
390 password in the binary encoding into the file (i.e. non-ascii characters
391 won't show up readable).@footnote{The @command{gpgconf} tool might be
392 helpful for frontends as it enables editing this configuration file using
393 percent-escaped strings.}
394
395
396 @item --ldaptimeout @var{secs}
397 @opindex ldaptimeout
398 Specify the number of seconds to wait for an LDAP query before timing
399 out. The default is currently 100 seconds.  0 will never timeout.
400
401
402 @item --add-servers
403 @opindex add-servers
404 This option makes dirmngr add any servers it discovers when validating
405 certificates against CRLs to the internal list of servers to consult for
406 certificates and CRLs.
407
408 This option is useful when trying to validate a certificate that has
409 a CRL distribution point that points to a server that is not already
410 listed in the ldapserverlist. Dirmngr will always go to this server and
411 try to download the CRL, but chances are high that the certificate used
412 to sign the CRL is located on the same server. So if dirmngr doesn't add
413 that new server to list, it will often not be able to verify the
414 signature of the CRL unless the @code{--add-servers} option is used.
415
416 Note: The current version of dirmngr has this option disabled by default.
417
418
419 @item --allow-ocsp
420 @opindex allow-ocsp
421 This option enables OCSP support if requested by the client.
422
423 OCSP requests are rejected by default because they may violate the
424 privacy of the user; for example it is possible to track the time when
425 a user is reading a mail.
426
427
428 @item --ocsp-responder @var{url}
429 @opindex ocsp-responder
430 Use @var{url} as the default OCSP Responder if the certificate does
431 not contain information about an assigned responder.  Note, that
432 @code{--ocsp-signer} must also be set to a valid certificate.
433
434 @item --ocsp-signer @var{fpr}|@var{file}
435 @opindex ocsp-signer
436 Use the certificate with the fingerprint @var{fpr} to check the
437 responses of the default OCSP Responder.  Alternatively a filename can be
438 given in which case the response is expected to be signed by one of the
439 certificates described in that file.  Any argument which contains a
440 slash, dot or tilde is considered a filename.  Usual filename expansion
441 takes place: A tilde at the start followed by a slash is replaced by the
442 content of @env{HOME}, no slash at start describes a relative filename
443 which will be searched at the home directory.  To make sure that the
444 @var{file} is searched in the home directory, either prepend the name
445 with "./" or use a name which contains a dot.
446
447 If a response has been signed by a certificate described by these
448 fingerprints no further check upon the validity of this certificate is
449 done.
450
451 The format of the @var{FILE} is a list of SHA-1 fingerprint, one per
452 line with optional colons between the bytes.  Empty lines and lines
453 prefix with a hash mark are ignored.
454
455
456 @item --ocsp-max-clock-skew @var{n}
457 @opindex ocsp-max-clock-skew
458 The number of seconds a skew between the OCSP responder and them local
459 clock is accepted.  Default is 600 (10 minutes).
460
461 @item --ocsp-max-period @var{n}
462 @opindex ocsp-max-period
463 Seconds a response is at maximum considered valid after the time given
464 in the thisUpdate field.  Default is 7776000 (90 days).
465
466 @item --ocsp-current-period @var{n}
467 @opindex ocsp-current-period
468 The number of seconds an OCSP response is considered valid after the
469 time given in the NEXT_UPDATE datum.  Default is 10800 (3 hours).
470
471
472 @item --max-replies @var{n}
473 @opindex max-replies
474 Do not return more that @var{n} items in one query.  The default is
475 10.
476
477 @item --ignore-cert-extension @var{oid}
478 @opindex ignore-cert-extension
479 Add @var{oid} to the list of ignored certificate extensions.  The
480 @var{oid} is expected to be in dotted decimal form, like
481 @code{2.5.29.3}.  This option may be used more than once.  Critical
482 flagged certificate extensions matching one of the OIDs in the list
483 are treated as if they are actually handled and thus the certificate
484 won't be rejected due to an unknown critical extension.  Use this
485 option with care because extensions are usually flagged as critical
486 for a reason.
487
488 @item --hkp-cacert @var{file}
489 Use the root certificates in @var{file} for verification of the TLS
490 certificates used with @code{hkps} (keyserver access over TLS).  If
491 the file is in PEM format a suffix of @code{.pem} is expected for
492 @var{file}.  This option may be given multiple times to add more
493 root certificates.  Tilde expansion is supported.
494
495 If no @code{hkp-cacert} directive is present, dirmngr will make a
496 reasonable choice: if the keyserver in question is the special pool
497 @code{hkps.pool.sks-keyservers.net}, it will use the bundled root
498 certificate for that pool.  Otherwise, it will use the system CAs.
499
500 @end table
501
502
503 @c
504 @c Dirmngr Configuration
505 @c
506 @mansect files
507 @node Dirmngr Configuration
508 @section Configuration
509
510 Dirmngr makes use of several directories when running in daemon mode:
511 There are a few configuration files whih control the operation of
512 dirmngr.  By default they may all be found in the current home
513 directory (@pxref{option --homedir}).
514
515 @table @file
516
517 @item dirmngr.conf
518 @efindex dirmngr.conf
519 This is the standard configuration file read by @command{dirmngr} on
520 startup.  It may contain any valid long option; the leading two dashes
521 may not be entered and the option may not be abbreviated.  This file
522 is also read after a @code{SIGHUP} however not all options will
523 actually have an effect.  This default name may be changed on the
524 command line (@pxref{option --options}).  You should backup this file.
525
526 @item /etc/gnupg/trusted-certs
527 This directory should be filled with certificates of Root CAs you
528 are trusting in checking the CRLs and signing OCSP Responses.
529
530 Usually these are the same certificates you use with the applications
531 making use of dirmngr.  It is expected that each of these certificate
532 files contain exactly one @acronym{DER} encoded certificate in a file
533 with the suffix @file{.crt} or @file{.der}.  @command{dirmngr} reads
534 those certificates on startup and when given a SIGHUP.  Certificates
535 which are not readable or do not make up a proper X.509 certificate
536 are ignored; see the log file for details.
537
538 Applications using dirmngr (e.g. gpgsm) can request these
539 certificates to complete a trust chain in the same way as with the
540 extra-certs directory (see below).
541
542 Note that for OCSP responses the certificate specified using the option
543 @option{--ocsp-signer} is always considered valid to sign OCSP requests.
544
545 @item /etc/gnupg/extra-certs
546 This directory may contain extra certificates which are preloaded
547 into the internal cache on startup. Applications using dirmngr (e.g. gpgsm)
548 can request cached certificates to complete a trust chain.
549 This is convenient in cases you have a couple intermediate CA certificates
550 or certificates usually used to sign OCSP responses.
551 These certificates are first tried before going
552 out to the net to look for them.  These certificates must also be
553 @acronym{DER} encoded and suffixed with @file{.crt} or @file{.der}.
554
555 @item ~/.gnupg/crls.d
556 This directory is used to store cached CRLs.  The @file{crls.d}
557 part will be created by dirmngr if it does not exists but you need to
558 make sure that the upper directory exists.
559
560 @end table
561 @manpause
562
563 To be able to see what's going on you should create the configure file
564 @file{~/gnupg/dirmngr.conf} with at least one line:
565
566 @example
567 log-file ~/dirmngr.log
568 @end example
569
570 To be able to perform OCSP requests you probably want to add the line:
571
572 @example
573 allow-ocsp
574 @end example
575
576 To make sure that new options are read and that after the installation
577 of a new GnuPG versions the installed dirmngr is running, you may want
578 to kill an existing dirmngr first:
579
580 @example
581 gpgconf --kill dirmngr
582 @end example
583
584 You may check the log file to see whether all desired root
585 certificates have been loaded correctly.
586
587
588 @c
589 @c Dirmngr Signals
590 @c
591 @mansect signals
592 @node Dirmngr Signals
593 @section Use of signals
594
595 A running @command{dirmngr} may be controlled by signals, i.e. using
596 the @command{kill} command to send a signal to the process.
597
598 Here is a list of supported signals:
599
600 @table @gnupgtabopt
601
602 @item SIGHUP
603 @cpindex SIGHUP
604 This signal flushes all internally cached CRLs as well as any cached
605 certificates.  Then the certificate cache is reinitialized as on
606 startup.  Options are re-read from the configuration file.  Instead of
607 sending this signal it is better to use
608 @example
609 gpgconf --reload dirmngr
610 @end example
611
612 @item SIGTERM
613 @cpindex SIGTERM
614 Shuts down the process but waits until all current requests are
615 fulfilled.  If the process has received 3 of these signals and requests
616 are still pending, a shutdown is forced.  You may also use
617 @example
618 gpgconf --kill dirmngr
619 @end example
620 instead of this signal
621
622 @item SIGINT
623 @cpindex SIGINT
624 Shuts down the process immediately.
625
626
627 @item SIGUSR1
628 @cpindex SIGUSR1
629 This prints some caching statistics to the log file.
630
631 @end table
632
633
634
635 @c
636 @c  Examples
637 @c
638 @mansect examples
639 @node Dirmngr Examples
640 @section Examples
641
642 Here is an example on how to show dirmngr's internal table of OpenPGP
643 keyserver addresses.  The output is intended for debugging purposes
644 and not part of a defined API.
645
646 @example
647   gpg-connect-agent --dirmngr 'keyserver --hosttable' /bye
648 @end example
649
650 To inhibit the use of a particular host you have noticed in one of the
651 keyserver pools, you may use
652
653 @example
654  gpg-connect-agent --dirmngr 'keyserver --dead pgpkeys.bnd.de' /bye
655 @end example
656
657 The description of the @code{keyserver} command can be printed using
658
659 @example
660  gpg-connect-agent --dirmngr 'help keyserver' /bye
661 @end example
662
663
664
665 @c
666 @c  Assuan Protocol
667 @c
668 @manpause
669 @node Dirmngr Protocol
670 @section Dirmngr's Assuan Protocol
671
672 Assuan is the IPC protocol used to access dirmngr.  This is a
673 description of the commands implemented by dirmngr.
674
675 @menu
676 * Dirmngr LOOKUP::      Look up a certificate via LDAP
677 * Dirmngr ISVALID::     Validate a certificate using a CRL or OCSP.
678 * Dirmngr CHECKCRL::    Validate a certificate using a CRL.
679 * Dirmngr CHECKOCSP::   Validate a certificate using OCSP.
680 * Dirmngr CACHECERT::   Put a certificate into the internal cache.
681 * Dirmngr VALIDATE::    Validate a certificate for debugging.
682 @end menu
683
684 @node Dirmngr LOOKUP
685 @subsection Return the certificate(s) found
686
687 Lookup certificate.  To allow multiple patterns (which are ORed)
688 quoting is required: Spaces are to be translated into "+" or into
689 "%20"; obviously this requires that the usual escape quoting rules
690 are applied.  The server responds with:
691
692 @example
693   S: D <DER encoded certificate>
694   S: END
695   S: D <second DER encoded certificate>
696   S: END
697   S: OK
698 @end example
699
700 In this example 2 certificates are returned.  The server may return
701 any number of certificates; OK will also be returned when no
702 certificates were found.  The dirmngr might return a status line
703
704 @example
705   S: S TRUNCATED <n>
706 @end example
707
708
709 To indicate that the output was truncated to N items due to a
710 limitation of the server or by an arbitrary set limit.
711
712 The option @option{--url} may be used if instead of a search pattern a
713 complete URL to the certificate is known:
714
715 @example
716   C: LOOKUP --url CN%3DWerner%20Koch,o%3DIntevation%20GmbH,c%3DDE?userCertificate
717 @end example
718
719 If the option @option{--cache-only} is given, no external lookup is done
720 so that only certificates from the cache are returned.
721
722 With the option @option{--single}, the first and only the first match
723 will be returned.  Unless option @option{--cache-only} is also used, no
724 local lookup will be done in this case.
725
726
727
728 @node Dirmngr ISVALID
729 @subsection Validate a certificate using a CRL or OCSP
730
731 @example
732   ISVALID [--only-ocsp] [--force-default-responder] @var{certid}|@var{certfpr}
733 @end example
734
735 Check whether the certificate described by the @var{certid} has been
736 revoked.  Due to caching, the Dirmngr is able to answer immediately in
737 most cases.
738
739 The @var{certid} is a hex encoded string consisting of two parts,
740 delimited by a single dot.  The first part is the SHA-1 hash of the
741 issuer name and the second part the serial number.
742
743 Alternatively the certificate's SHA-1 fingerprint @var{certfpr} may be
744 given in which case an OCSP request is done before consulting the CRL.
745 If the option @option{--only-ocsp} is given, no fallback to a CRL check
746 will be used.  If the option @option{--force-default-responder} is
747 given, only the default OCSP responder will be used and any other
748 methods of obtaining an OCSP responder URL won't be used.
749
750 @noindent
751 Common return values are:
752
753 @table @code
754 @item GPG_ERR_NO_ERROR (0)
755 This is the positive answer: The certificate is not revoked and we have
756 an up-to-date revocation list for that certificate.  If OCSP was used
757 the responder confirmed that the certificate has not been revoked.
758
759 @item GPG_ERR_CERT_REVOKED
760 This is the negative answer: The certificate has been revoked.  Either
761 it is in a CRL and that list is up to date or an OCSP responder informed
762 us that it has been revoked.
763
764 @item GPG_ERR_NO_CRL_KNOWN
765 No CRL is known for this certificate or the CRL is not valid or out of
766 date.
767
768 @item GPG_ERR_NO_DATA
769 The OCSP responder returned an ``unknown'' status.  This means that it
770 is not aware of the certificate's status.
771
772 @item GPG_ERR_NOT_SUPPORTED
773 This is commonly seen if OCSP support has not been enabled in the
774 configuration.
775 @end table
776
777 If DirMngr has not enough information about the given certificate (which
778 is the case for not yet cached certificates), it will will inquire the
779 missing data:
780
781 @example
782   S: INQUIRE SENDCERT <CertID>
783   C: D <DER encoded certificate>
784   C: END
785 @end example
786
787 A client should be aware that DirMngr may ask for more than one
788 certificate.
789
790 If Dirmngr has a certificate but the signature of the certificate
791 could not been validated because the root certificate is not known to
792 dirmngr as trusted, it may ask back to see whether the client trusts
793 this the root certificate:
794
795 @example
796   S: INQUIRE ISTRUSTED <CertHexfpr>
797   C: D 1
798   C: END
799 @end example
800
801 Only this answer will let Dirmngr consider the certificate as valid.
802
803
804 @node Dirmngr CHECKCRL
805 @subsection Validate a certificate using a CRL
806
807 Check whether the certificate with FINGERPRINT (SHA-1 hash of the
808 entire X.509 certificate blob) is valid or not by consulting the CRL
809 responsible for this certificate.  If the fingerprint has not been
810 given or the certificate is not known, the function inquires the
811 certificate using:
812
813 @example
814   S: INQUIRE TARGETCERT
815   C: D <DER encoded certificate>
816   C: END
817 @end example
818
819 Thus the caller is expected to return the certificate for the request
820 (which should match FINGERPRINT) as a binary blob.  Processing then
821 takes place without further interaction; in particular dirmngr tries
822 to locate other required certificate by its own mechanism which
823 includes a local certificate store as well as a list of trusted root
824 certificates.
825
826 @noindent
827 The return code is 0 for success; i.e. the certificate has not been
828 revoked or one of the usual error codes from libgpg-error.
829
830 @node Dirmngr CHECKOCSP
831 @subsection Validate a certificate using OCSP
832
833 @example
834   CHECKOCSP [--force-default-responder] [@var{fingerprint}]
835 @end example
836
837 Check whether the certificate with @var{fingerprint} (the SHA-1 hash of
838 the entire X.509 certificate blob) is valid by consulting the appropriate
839 OCSP responder.  If the fingerprint has not been given or the
840 certificate is not known by Dirmngr, the function inquires the
841 certificate using:
842
843 @example
844   S: INQUIRE TARGETCERT
845   C: D <DER encoded certificate>
846   C: END
847 @end example
848
849 Thus the caller is expected to return the certificate for the request
850 (which should match @var{fingerprint}) as a binary blob.  Processing
851 then takes place without further interaction; in particular dirmngr
852 tries to locate other required certificates by its own mechanism which
853 includes a local certificate store as well as a list of trusted root
854 certificates.
855
856 If the option @option{--force-default-responder} is given, only the
857 default OCSP responder is used.  This option is the per-command variant
858 of the global option @option{--ignore-ocsp-service-url}.
859
860
861 @noindent
862 The return code is 0 for success; i.e. the certificate has not been
863 revoked or one of the usual error codes from libgpg-error.
864
865 @node Dirmngr CACHECERT
866 @subsection Put a certificate into the internal cache
867
868 Put a certificate into the internal cache.  This command might be
869 useful if a client knows in advance certificates required for a test and
870 wants to make sure they get added to the internal cache.  It is also
871 helpful for debugging.  To get the actual certificate, this command
872 immediately inquires it using
873
874 @example
875   S: INQUIRE TARGETCERT
876   C: D <DER encoded certificate>
877   C: END
878 @end example
879
880 Thus the caller is expected to return the certificate for the request
881 as a binary blob.
882
883 @noindent
884 The return code is 0 for success; i.e. the certificate has not been
885 successfully cached or one of the usual error codes from libgpg-error.
886
887 @node Dirmngr VALIDATE
888 @subsection Validate a certificate for debugging
889
890 Validate a certificate using the certificate validation function used
891 internally by dirmngr.  This command is only useful for debugging.  To
892 get the actual certificate, this command immediately inquires it using
893
894 @example
895   S: INQUIRE TARGETCERT
896   C: D <DER encoded certificate>
897   C: END
898 @end example
899
900 Thus the caller is expected to return the certificate for the request
901 as a binary blob.
902
903
904 @mansect see also
905 @ifset isman
906 @command{gpgsm}(1),
907 @command{dirmngr-client}(1)
908 @end ifset
909 @include see-also-note.texi
910
911 @c
912 @c !!! UNDER CONSTRUCTION !!!
913 @c
914 @c
915 @c @section Verifying a Certificate
916 @c
917 @c There are several ways to request services from Dirmngr.  Almost all of
918 @c them are done using the Assuan protocol.  What we describe here is the
919 @c Assuan command CHECKCRL as used for example by the dirmnr-client tool if
920 @c invoked as
921 @c
922 @c @example
923 @c   dirmngr-client foo.crt
924 @c @end example
925 @c
926 @c This command will send an Assuan request to an already running Dirmngr
927 @c instance.  foo.crt is expected to be a standard X.509 certificate and
928 @c dirmngr will receive the Assuan command
929 @c
930 @c @example
931 @c    CHECKCRL @var [{fingerprint}]
932 @c @end example
933 @c
934 @c @var{fingerprint} is optional and expected to be the SHA-1 has of the
935 @c DER encoding of the certificate under question.  It is to be HEX
936 @c encoded.  The rationale for sending the fingerprint is that it allows
937 @c dirmngr to reply immediately if it has already cached such a request.  If
938 @c this is not the case and no certificate has been found in dirmngr's
939 @c internal certificate storage, dirmngr will request the certificate using
940 @c the Assuan inquiry
941 @c
942 @c @example
943 @c       INQUIRE TARGETCERT
944 @c @end example
945 @c
946 @c The caller (in our example dirmngr-client) is then expected to return
947 @c the certificate for the request (which should match @var{fingerprint})
948 @c as a binary blob.
949 @c
950 @c Dirmngr now passes control to @code{crl_cache_cert_isvalid}.  This
951 @c function checks whether a CRL item exists for target certificate.  These
952 @c CRL items are kept in a database of already loaded and verified CRLs.
953 @c This mechanism is called the CRL cache.  Obviously timestamps are kept
954 @c there with each item to cope with the expiration date of the CRL.  The
955 @c possible return values are: @code{0} to indicate that a valid CRL is
956 @c available for the certificate and the certificate itself is not listed
957 @c in this CRL, @code{GPG_ERR_CERT_REVOKED} to indicate that the certificate is
958 @c listed in the CRL or @code{GPG_ERR_NO_CRL_KNOWN} in cases where no CRL or no
959 @c information is available.  The first two codes are immediately returned to
960 @c the caller and the processing of this request has been done.
961 @c
962 @c Only the @code{GPG_ERR_NO_CRL_KNOWN} needs more attention: Dirmngr now
963 @c calls @code{clr_cache_reload_crl} and if this succeeds calls
964 @c @code{crl_cache_cert_isvald) once more.  All further errors are
965 @c immediately returned to the caller.
966 @c
967 @c @code{crl_cache_reload_crl} is the actual heart of the CRL management.
968 @c It locates the corresponding CRL for the target certificate, reads and
969 @c verifies this CRL and stores it in the CRL cache.  It works like this:
970 @c
971 @c * Loop over all crlDPs in the target certificate.
972 @c     * If the crlDP is invalid immediately terminate the loop.
973 @c     * Loop over all names in the current crlDP.
974 @c         * If the URL scheme is unknown or not enabled
975 @c           (--ignore-http-dp, --ignore-ldap-dp) continues with
976 @c           the next name.
977 @c         * @code{crl_fetch} is called to actually retrieve the CRL.
978 @c           In case of problems this name is ignore and we continue with
979 @c           the next name.  Note that @code{crl_fetch} does only return
980 @c           a descriptor for the CRL for further reading so does the CRL
981 @c           does not yet end up in memory.
982 @c         * @code{crl_cache_insert} is called with that descriptor to
983 @c           actually read the CRL into the cache. See below for a
984 @c           description of this function.  If there is any error (e.g. read
985 @c           problem, CRL not correctly signed or verification of signature
986 @c           not possible), this descriptor is rejected and we continue
987 @c           with the next name.  If the CRL has been successfully loaded,
988 @c           the loop is terminated.
989 @c * If no crlDP has been found in the previous loop use a default CRL.
990 @c   Note, that if any crlDP has been found but loading of the CRL failed,
991 @c   this condition is not true.
992 @c     * Try to load a CRL from all configured servers (ldapservers.conf)
993 @c       in turn.  The first server returning a CRL is used.
994 @c     * @code(crl_cache_insert) is then used to actually insert the CRL
995 @c       into the cache.  If this failed we give up immediately without
996 @c       checking the rest of the servers from the first step.
997 @c * Ready.
998 @c
999 @c
1000 @c The @code{crl_cache_insert} function takes care of reading the bulk of
1001 @c the CRL, parsing it and checking the signature.  It works like this: A
1002 @c new database file is created using a temporary file name.  The CRL
1003 @c parsing machinery is started and all items of the CRL are put into
1004 @c this database file.  At the end the issuer certificate of the CRL
1005 @c needs to be retrieved.  Three cases are to be distinguished:
1006 @c
1007 @c  a) An authorityKeyIdentifier with an issuer and serialno exits: The
1008 @c     certificate is retrieved using @code{find_cert_bysn}.  If
1009 @c     the certificate is in the certificate cache, it is directly
1010 @c     returned. Then the requester (i.e. the client who requested the
1011 @c     CRL check) is asked via the Assuan inquiry ``SENDCERT'' whether
1012 @c     he can provide this certificate.  If this succeed the returned
1013 @c     certificate gets cached and returned.  Note, that dirmngr does not
1014 @c     verify in any way whether the expected certificate is returned.
1015 @c     It is in the interest of the client to return a useful certificate
1016 @c     as otherwise the service request will fail due to a bad signature.
1017 @c     The last way to get the certificate is by looking it up at
1018 @c     external resources.  This is done using the @code{ca_cert_fetch}
1019 @c     and @code{fetch_next_ksba_cert} and comparing the returned
1020 @c     certificate to match the requested issuer and seriano (This is
1021 @c     needed because the LDAP layer may return several certificates as
1022 @c     LDAP as no standard way to retrieve by serial number).
1023 @c
1024 @c  b) An authorityKeyIdentifier with a key ID exists: The certificate is
1025 @c     retrieved using @code{find_cert_bysubject}.  If the certificate is
1026 @c     in the certificate cache, it is directly returned.  Then the
1027 @c     requester is asked via the Assuan inquiry ``SENDCERT_SKI'' whether
1028 @c     he can provide this certificate.  If this succeed the returned
1029 @c     certificate gets cached and returned.  Note, that dirmngr does not
1030 @c     verify in any way whether the expected certificate is returned.
1031 @c     It is in the interest of the client to return a useful certificate
1032 @c     as otherwise the service request will fail due to a bad signature.
1033 @c     The last way to get the certificate is by looking it up at
1034 @c     external resources.  This is done using the @code{ca_cert_fetch}
1035 @c     and @code{fetch_next_ksba_cert} and comparing the returned
1036 @c     certificate to match the requested subject and key ID.
1037 @c
1038 @c  c) No authorityKeyIdentifier exits: The certificate is retrieved
1039 @c     using @code{find_cert_bysubject} without the key ID argument.  If
1040 @c     the certificate is in the certificate cache the first one with a
1041 @c     matching subject is is directly returned.  Then the requester is
1042 @c     asked via the Assuan inquiry ``SENDCERT'' and an exact
1043 @c     specification of the subject whether he can
1044 @c     provide this certificate.  If this succeed the returned
1045 @c     certificate gets cached and returned.  Note, that dirmngr does not
1046 @c     verify in any way whether the expected certificate is returned.
1047 @c     It is in the interest of the client to return a useful certificate
1048 @c     as otherwise the service request will fail due to a bad signature.
1049 @c     The last way to get the certificate is by looking it up at
1050 @c     external resources.  This is done using the @code{ca_cert_fetch}
1051 @c     and @code{fetch_next_ksba_cert} and comparing the returned
1052 @c     certificate to match the requested subject; the first certificate
1053 @c     with a matching subject is then returned.
1054 @c
1055 @c If no certificate was found, the function returns with the error
1056 @c GPG_ERR_MISSING_CERT.  Now the signature is verified.  If this fails,
1057 @c the erro is returned.  On success the @code{validate_cert_chain} is
1058 @c used to verify that the certificate is actually valid.
1059 @c
1060 @c Here we may encounter a recursive situation:
1061 @c @code{validate_cert_chain} needs to look at other certificates and
1062 @c also at CRLs to check whether these other certificates and well, the
1063 @c CRL issuer certificate itself are not revoked.  FIXME: We need to make
1064 @c sure that @code{validate_cert_chain} does not try to lookup the CRL we
1065 @c are currently processing. This would be a catch-22 and may indicate a
1066 @c broken PKI.  However, due to overlapping expiring times and imprecise
1067 @c clocks this may actually happen.
1068 @c
1069 @c For historical reasons the Assuan command ISVALID is a bit different
1070 @c to CHECKCRL but this is mainly due to different calling conventions.
1071 @c In the end the same fucntionality is used, albeit hidden by a couple
1072 @c of indirection and argument and result code mangling.  It furthere
1073 @c ingetrages OCSP checking depending on options are the way it is
1074 @c called.  GPGSM still uses this command but might eventuall switch over
1075 @c to CHECKCRL and CHECKOCSP so that ISVALID can be retired.
1076 @c
1077 @c
1078 @c @section Validating a certificate
1079 @c
1080 @c We describe here how the internal function @code{validate_cert_chain}
1081 @c works. Note that mainly testing purposes this functionality may be
1082 @c called directly using @cmd{dirmngr-client --validate @file{foo.crt}}.
1083 @c
1084 @c The function takes the target certificate and a mode argument as
1085 @c parameters and returns an error code and optionally the closes
1086 @c expiration time of all certificates in the chain.
1087 @c
1088 @c We first check that the certificate may be used for the requested
1089 @c purpose (i.e. OCSP or CRL signing).  If this is not the case
1090 @c GPG_ERR_WRONG_KEY_USAGE is returned.
1091 @c
1092 @c The next step is to find the trust anchor (root certificate) and to
1093 @c assemble the chain in memory: Starting with the target certificate,
1094 @c the expiration time is checked against the current date, unknown
1095 @c critical extensions are detected and certificate policies are matched
1096 @c (We only allow 2.289.9.9 but I have no clue about that OID and from
1097 @c where I got it - it does not even seem to be assigned - debug cruft?).
1098 @c
1099 @c Now if this certificate is a self-signed one, we have reached the
1100 @c trust anchor.  In this case we check that the signature is good, the
1101 @c certificate is allowed to act as a CA, that it is a trusted one (by
1102 @c checking whether it is has been put into the trusted-certs
1103 @c configuration directory) and finally prepend into to our list
1104 @c representing the certificate chain.  This steps ends then.
1105 @c
1106 @c If it is not a self-signed certificate, we check that the chain won't
1107 @c get too long (current limit is 100), if this is the case we terminate
1108 @c with the error GPG_ERR_BAD_CERT_CHAIN.
1109 @c
1110 @c Now the issuer's certificate is looked up: If an
1111 @c authorityKeyIdentifier is available, this one is used to locate the
1112 @c certificate either using issuer and serialnumber or subject DN
1113 @c (i.e. the issuer's DN) and the keyID.  The functions
1114 @c @code{find_cert_bysn) and @code{find_cert_bysubject} are used
1115 @c respectively. The have already been described above under the
1116 @c description of @code{crl_cache_insert}.  If no certificate was found
1117 @c or with no authorityKeyIdentifier, only the cache is consulted using
1118 @c @code{get_cert_bysubject}.  The latter is is done under the assumption
1119 @c that a matching certificate has explicitly been put into the
1120 @c certificate cache.  If the issuer's certificate could not be found,
1121 @c the validation terminates with the error code @code{GPG_ERR_MISSING_CERT}.
1122 @c
1123 @c If the issuer's certificate has been found, the signature of the
1124 @c actual certificate is checked and in case this fails the error
1125 @c #code{GPG_ERR_BAD_CERT_CHAIN} is returned.  If the signature checks out, the
1126 @c maximum chain length of the issuing certificate is checked as well as
1127 @c the capability of the certificate (i.e. whether he may be used for
1128 @c certificate signing).  Then the certificate is prepended to our list
1129 @c representing the certificate chain.  Finally the loop is continued now
1130 @c with the issuer's certificate as the current certificate.
1131 @c
1132 @c After the end of the loop and if no error as been encountered
1133 @c (i.e. the certificate chain has been assempled correctly), a check is
1134 @c done whether any certificate expired or a critical policy has not been
1135 @c met.  In any of these cases the validation terminates with an
1136 @c appropriate error.
1137 @c
1138 @c Finally the function @code{check_revocations} is called to verify no
1139 @c certificate in the assempled chain has been revoked: This is an
1140 @c recursive process because a CRL has to be checked for each certificate
1141 @c in the chain except for the root certificate, of which we already know
1142 @c that it is trusted and we avoid checking a CRL here due to common
1143 @c setup problems and the assumption that a revoked root certifcate has
1144 @c been removed from the list of trusted certificates.
1145 @c
1146 @c
1147 @c
1148 @c
1149 @c @section Looking up certificates through LDAP.
1150 @c
1151 @c This describes the LDAP layer to retrieve certificates.
1152 @c the functions @code{ca_cert_fetch} and @code{fetch_next_ksba_cert} are
1153 @c used for this.  The first one starts a search and the second one is
1154 @c used to retrieve certificate after certificate.
1155 @c
1156
1157