Fix i18n bug.
[gnupg.git] / doc / gpg-agent.texi
blob27946c0258e0b30043548765363ab655af5083bc
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.
5 @node Invoking GPG-AGENT
6 @chapter Invoking GPG-AGENT
7 @cindex GPG-AGENT command options
8 @cindex command options
9 @cindex options, GPG-AGENT command
11 @manpage gpg-agent.1
12 @ifset manverb
13 .B gpg-agent
14 \- Secret key management for GnuPG
15 @end ifset
17 @mansect synopsis
18 @ifset manverb
19 .B  gpg-agent
20 .RB [ \-\-homedir
21 .IR dir ]
22 .RB [ \-\-options
23 .IR file ]
24 .RI [ options ]  
25 .br
26 .B  gpg-agent
27 .RB [ \-\-homedir
28 .IR dir ]
29 .RB [ \-\-options
30 .IR file ]
31 .RI [ options ]  
32 .B  \-\-server 
33 .br
34 .B  gpg-agent
35 .RB [ \-\-homedir
36 .IR dir ]
37 .RB [ \-\-options
38 .IR file ]
39 .RI [ options ]  
40 .B  \-\-daemon 
41 .RI [ command_line ]
42 @end ifset
44 @mansect description
45 @command{gpg-agent} is a daemon to manage secret (private) keys
46 independently from any protocol.  It is used as a backend for
47 @command{gpg} and @command{gpgsm} as well as for a couple of other
48 utilities.
50 @noindent
51 The usual way to run the agent is from the @code{~/.xsession} file:
53 @example
54 eval $(gpg-agent --daemon)
55 @end example
57 @noindent
58 If you don't use an X server, you can also put this into your regular
59 startup file @code{~/.profile} or @code{.bash_profile}.  It is best not
60 to run multiple instance of the @command{gpg-agent}, so you should make
61 sure that only one is running: @command{gpg-agent} uses an environment
62 variable to inform clients about the communication parameters. You can
63 write the content of this environment variable to a file so that you can
64 test for a running agent.  Here is an example using Bourne shell synax:
66 @smallexample
67 gpg-agent --daemon --enable-ssh-support \
68           --write-env-file "$@{HOME@}/.gpg-agent-info"
69 @end smallexample
71 This code should only be run once per user session to initially fire up
72 the agent.  In the example the optional support for the included Secure
73 Shell agent is enabled and the information about the agent is written to
74 a file in the HOME directory.  Note that by running gpg-agent without
75 arguments you may test whether an agent is already running; however such
76 a test may lead to a race condition, thus it is not suggested.
78 @noindent
79 The second script needs to be run for each interactive session:
81 @smallexample
82 if [ -f "$@{HOME@}/.gpg-agent-info" ]; then
83   . "$@{HOME@}/.gpg-agent-info"
84   export GPG_AGENT_INFO
85   export SSH_AUTH_SOCK
86   export SSH_AGENT_PID
88 @end smallexample
90 @noindent
91 It reads the data out of the file and exports the variables.  If you
92 don't use Secure Shell, you don't need the last two export statements.
94 @noindent
95 You should always add the following lines to your @code{.bashrc} or
96 whatever initialization file is used for all shell invocations:
98 @smallexample
99 GPG_TTY=$(tty)
100 export GPG_TTY
101 @end smallexample
103 @noindent
104 It is important that this environment variable always reflects the
105 output of the @code{tty} command.  For W32 systems this option is not
106 required.
108 Please make sure that a proper pinentry program has been installed
109 under the default filename (which is system dependant) or use the
110 option @option{pinentry-program} to specify the full name of that program.
111 It is often useful to install a symbolic link from the actual used
112 pinentry (e.g. @file{/usr/bin/pinentry-gtk}) to the expected
113 one (e.g. @file{/usr/bin/pinentry}).
115 @manpause
116 @noindent
117 @xref{Option Index},for an index to @command{GPG-AGENT}'s commands and options.
118 @mancont
120 @menu
121 * Agent Commands::      List of all commands.
122 * Agent Options::       List of all options.
123 * Agent Configuration:: Configuration files.
124 * Agent Signals::       Use of some signals.
125 * Agent Examples::      Some usage examples.
126 * Agent Protocol::      The protocol the agent uses.
127 @end menu
129 @mansect commands
130 @node Agent Commands
131 @section Commands
133 Commands are not distinguished from options except for the fact that
134 only one command is allowed.
136 @table @gnupgtabopt
137 @item --version
138 @opindex version
139 Print the program version and licensing information.  Not that you can
140 abbreviate this command.
142 @item --help
143 @itemx -h
144 @opindex help
145 Print a usage message summarizing the most useful command-line options.
146 Not that you can abbreviate this command.
148 @item --dump-options
149 @opindex dump-options
150 Print a list of all available options and commands.  Not that you can
151 abbreviate this command.
153 @item --server
154 @opindex server
155 Run in server mode and wait for commands on the @code{stdin}.  The
156 default mode is to create a socket and listen for commands there.
158 @item --daemon [@var{command line}]
159 @opindex daemon
160 Start the gpg-agent as a daemon; that is, detach it from the console
161 and run it in the background.  Because @command{gpg-agent} prints out
162 important information required for further use, a common way of
163 invoking gpg-agent is: @code{eval $(gpg-agent --daemon)} to setup the
164 environment variables.  The option @option{--write-env-file} is
165 another way commonly used to do this.  Yet another way is creating
166 a new process as a child of gpg-agent: @code{gpg-agent --daemon
167 /bin/sh}.  This way you get a new shell with the environment setup
168 properly; if you exit from this shell, gpg-agent terminates as well.
169 @end table
171 @mansect options
172 @node Agent Options
173 @section Option Summary
175 @table @gnupgtabopt
177 @anchor{option --options}
178 @item --options @var{file}
179 @opindex options
180 Reads configuration from @var{file} instead of from the default
181 per-user configuration file.  The default configuration file is named
182 @file{gpg-agent.conf} and expected in the @file{.gnupg} directory directly
183 below the home directory of the user.
185 @anchor{option --homedir}
186 @include opt-homedir.texi
189 @item -v
190 @item --verbose
191 @opindex v
192 @opindex verbose
193 Outputs additional information while running.
194 You can increase the verbosity by giving several
195 verbose commands to @command{gpgsm}, such as @samp{-vv}.
197 @item -q
198 @item --quiet
199 @opindex q
200 @opindex quiet
201 Try to be as quiet as possible.
203 @item --batch
204 @opindex batch
205 Don't invoke a pinentry or do any other thing requiring human interaction.
207 @item --faked-system-time @var{epoch}
208 @opindex faked-system-time
209 This option is only useful for testing; it sets the system time back or
210 forth to @var{epoch} which is the number of seconds elapsed since the year
211 1970.
213 @item --debug-level @var{level}
214 @opindex debug-level
215 Select the debug level for investigating problems. @var{level} may be
216 one of:
218    @table @code
219    @item none
220    no debugging at all.
221    @item basic  
222    some basic debug messages
223    @item advanced
224    more verbose debug messages
225    @item expert
226    even more detailed messages
227    @item guru
228    all of the debug messages you can get
229    @end table
231 How these messages are mapped to the actual debugging flags is not
232 specified and may change with newer releases of this program. They are
233 however carefully selected to best aid in debugging.
235 @item --debug @var{flags}
236 @opindex debug
237 This option is only useful for debugging and the behaviour may change at
238 any time without notice.  FLAGS are bit encoded and may be given in
239 usual C-Syntax. The currently defined bits are:
241 @table @code
242 @item 0  (1)
243 X.509 or OpenPGP protocol related data
244 @item 1  (2)  
245 values of big number integers 
246 @item 2  (4)
247 low level crypto operations
248 @item 5  (32)
249 memory allocation
250 @item 6  (64)
251 caching
252 @item 7  (128)
253 show memory statistics.
254 @item 9  (512)
255 write hashed data to files named @code{dbgmd-000*}
256 @item 10 (1024)
257 trace Assuan protocol
258 @item 12 (4096)
259 bypass all certificate validation
260 @end table
262 @item --debug-all
263 @opindex debug-all
264 Same as @code{--debug=0xffffffff}
266 @item --debug-wait @var{n}
267 @opindex debug-wait
268 When running in server mode, wait @var{n} seconds before entering the
269 actual processing loop and print the pid.  This gives time to attach a
270 debugger.
272 @item --no-detach
273 @opindex no-detach
274 Don't detach the process from the console.  This is mainly useful for
275 debugging.
277 @item -s
278 @itemx --sh
279 @itemx -c
280 @itemx --csh
281 @opindex s
282 @opindex sh
283 @opindex c
284 @opindex csh
285 Format the info output in daemon mode for use with the standard Bourne
286 shell or the C-shell respectively.  The default is to guess it based on
287 the environment variable @code{SHELL} which is correct in almost all
288 cases.
290 @item --write-env-file @var{file}
291 @opindex write-env-file
292 Often it is required to connect to the agent from a process not being an
293 inferior of @command{gpg-agent} and thus the environment variable with
294 the socket name is not available.  To help setting up those variables in
295 other sessions, this option may be used to write the information into
296 @var{file}.  If @var{file} is not specified the default name
297 @file{$@{HOME@}/.gpg-agent-info} will be used.  The format is suitable
298 to be evaluated by a Bourne shell like in this simple example:
300 @example
301 eval $(cat @var{file})
302 eval $(cut -d= -f 1 < @var{file} | xargs echo export)
303 @end example
307 @item --no-grab
308 @opindex no-grab
309 Tell the pinentry not to grab the keyboard and mouse.  This option
310 should in general not be used to avoid X-sniffing attacks.
312 @item --log-file @var{file}
313 @opindex log-file
314 Append all logging output to @var{file}.  This is very helpful in
315 seeing what the agent actually does.
317 @anchor{option --allow-mark-trusted}
318 @item --allow-mark-trusted
319 @opindex allow-mark-trusted
320 Allow clients to mark keys as trusted, i.e. put them into the
321 @file{trustlist.txt} file.  This is by default not allowed to make it
322 harder for users to inadvertently accept Root-CA keys.
324 @item --ignore-cache-for-signing
325 @opindex ignore-cache-for-signing
326 This option will let @command{gpg-agent} bypass the passphrase cache for all
327 signing operation.  Note that there is also a per-session option to
328 control this behaviour but this command line option takes precedence.
330 @item --default-cache-ttl @var{n}
331 @opindex default-cache-ttl
332 Set the time a cache entry is valid to @var{n} seconds.  The default is
333 600 seconds.
335 @item --default-cache-ttl-ssh @var{n}
336 @opindex default-cache-ttl
337 Set the time a cache entry used for SSH keys is valid to @var{n}
338 seconds.  The default is 1800 seconds.
340 @item --max-cache-ttl @var{n}
341 @opindex max-cache-ttl
342 Set the maximum time a cache entry is valid to @var{n} seconds.  After
343 this time a cache entry will be expired even if it has been accessed
344 recently.  The default is 2 hours (7200 seconds).
346 @item --max-cache-ttl-ssh @var{n}
347 @opindex max-cache-ttl-ssh
348 Set the maximum time a cache entry used for SSH keys is valid to @var{n}
349 seconds.  After this time a cache entry will be expired even if it has
350 been accessed recently.  The default is 2 hours (7200 seconds).
352 @item --enforce-passphrase-constraints
353 @opindex enforce-passphrase-constraints
354 Enforce the passphrase constraints by not allowing the user to bypass
355 them using the ``Take it anyway'' button.
357 @item --min-passphrase-len @var{n}
358 @opindex min-passphrase-len
359 Set the minimal length of a passphrase.  When entering a new passphrase
360 shorter than this value a warning will be displayed.  Defaults to 8.
362 @item --min-passphrase-nonalpha @var{n}
363 @opindex min-passphrase-nonalpha
364 Set the minimal number of digits or special characters required in a
365 passphrase.  When entering a new passphrase with less than this number
366 of digits or special characters a warning will be displayed.  Defaults
367 to 1.
369 @item --check-passphrase-pattern @var{file}
370 @opindex check-passphrase-pattern
371 Check the passphrase against the pattern given in @var{file}.  When
372 entering a new passphrase matching one of these pattern a warning will
373 be displayed. @var{file} should be an absolute filename.  The default is
374 not to use any pattern file. 
376 Security note: It is known that checking a passphrase against a list of
377 pattern or even against a complete dictionary is not very effective to
378 enforce good passphrases.  Users will soon figure up ways to bypass such
379 a policy.  A better policy is to educate users on good security
380 behavior and optionally to run a passphrase cracker regularly on all
381 users passphrases to catch the very simple ones.
383 @item --max-passphrase-days @var{n}
384 @opindex max-passphrase-days 
385 Ask the user to change the passphrase if @var{n} days have passed since
386 the last change.  With @option{--enforce-passphrase-constraints} set the
387 user may not bypass this check.
389 @item --enable-passphrase-history
390 @opindex enable-passphrase-history
391 This option does nothing yet.
393 @item --pinentry-program @var{filename}
394 @opindex pinentry-program
395 Use program @var{filename} as the PIN entry.  The default is installation
396 dependent and can be shown with the @code{--version} command.
398 @item --pinentry-touch-file @var{filename}
399 @opindex pinentry-touch-file
400 By default the filename of the socket gpg-agent is listening for
401 requests is passed to Pinentry, so that it can touch that file before
402 exiting (it does this only in curses mode).  This option changes the
403 file passed to Pinentry to @var{filename}.  The special name
404 @code{/dev/null} may be used to completely disable this feature.  Note
405 that Pinentry will not create that file, it will only change the
406 modification and access time.
409 @item --scdaemon-program @var{filename}
410 @opindex scdaemon-program
411 Use program @var{filename} as the Smartcard daemon.  The default is
412 installation dependent and can be shown with the @code{--version}
413 command.
415 @item --disable-scdaemon
416 @opindex disable-scdaemon
417 Do not make use of the scdaemon tool.  This option has the effect of
418 disabling the ability to do smartcard operations.  Note, that enabling
419 this option at runtime does not kill an already forked scdaemon.
421 @item --use-standard-socket
422 @itemx --no-use-standard-socket
423 @opindex use-standard-socket
424 @opindex no-use-standard-socket
425 By enabling this option @command{gpg-agent} will listen on the socket
426 named @file{S.gpg-agent}, located in the home directory, and not create
427 a random socket below a temporary directory.  Tools connecting to
428 @command{gpg-agent} should first try to connect to the socket given in
429 environment variable @var{GPG_AGENT_INFO} and then fall back to this
430 socket.  This option may not be used if the home directory is mounted as
431 a remote file system.  Note, that @option{--use-standard-socket} is the
432 default on Windows systems.
435 @item --display @var{string}
436 @itemx --ttyname @var{string}
437 @itemx --ttytype @var{string}
438 @itemx --lc-ctype @var{string}
439 @itemx --lc-messages @var{string}
440 @itemx --xauthority @var{string}
441 @opindex display 
442 @opindex ttyname 
443 @opindex ttytype 
444 @opindex lc-ctype 
445 @opindex lc-messages
446 @opindex xauthority
447 These options are used with the server mode to pass localization
448 information.
450 @item --keep-tty
451 @itemx --keep-display
452 @opindex keep-tty
453 @opindex keep-display
454 Ignore requests to change the current @code{tty} or X window system's
455 @code{DISPLAY} variable respectively.  This is useful to lock the
456 pinentry to pop up at the @code{tty} or display you started the agent.
458 @anchor{option --enable-ssh-support}
459 @item --enable-ssh-support
460 @opindex enable-ssh-support
462 Enable emulation of the OpenSSH Agent protocol.
464 In this mode of operation, the agent does not only implement the
465 gpg-agent protocol, but also the agent protocol used by OpenSSH
466 (through a separate socket).  Consequently, it should be possible to use
467 the gpg-agent as a drop-in replacement for the well known ssh-agent.
469 SSH Keys, which are to be used through the agent, need to be added to
470 the gpg-agent initially through the ssh-add utility.  When a key is
471 added, ssh-add will ask for the password of the provided key file and
472 send the unprotected key material to the agent; this causes the
473 gpg-agent to ask for a passphrase, which is to be used for encrypting
474 the newly received key and storing it in a gpg-agent specific
475 directory.
477 Once a key has been added to the gpg-agent this way, the gpg-agent
478 will be ready to use the key.
480 Note: in case the gpg-agent receives a signature request, the user might
481 need to be prompted for a passphrase, which is necessary for decrypting
482 the stored key.  Since the ssh-agent protocol does not contain a
483 mechanism for telling the agent on which display/terminal it is running,
484 gpg-agent's ssh-support will use the TTY or X display where gpg-agent
485 has been started.  To switch this display to the current one, the
486 following command may be used:
488 @smallexample
489 echo UPDATESTARTUPTTY | gpg-connect-agent
490 @end smallexample
494 @end table
496 All the long options may also be given in the configuration file after
497 stripping off the two leading dashes.
500 @mansect files
501 @node Agent Configuration
502 @section Configuration
504 There are a few configuration files needed for the operation of the
505 agent. By default they may all be found in the current home directory
506 (@pxref{option --homedir}).
508 @table @file
510 @item gpg-agent.conf
511 @cindex gpg-agent.conf
512   This is the standard configuration file read by @command{gpg-agent} on
513   startup.  It may contain any valid long option; the leading
514   two dashes may not be entered and the option may not be abbreviated.
515   This file is also read after a @code{SIGHUP} however only a few
516   options will actually have an effect.  This default name may be
517   changed on the command line (@pxref{option --options}).
519 @item trustlist.txt
520   This is the list of trusted keys.  Comment lines, indicated by a leading
521   hash mark, as well as empty lines are ignored.  To mark a key as trusted
522   you need to enter its fingerprint followed by a space and a capital
523   letter @code{S}.  Colons may optionally be used to separate the bytes of
524   a fingerprint; this allows to cut and paste the fingerprint from a key
525   listing output.  If the line is prefixed with a @code{!} the key is
526   explicitly marked as not trusted.
527   
528   Here is an example where two keys are marked as ultimately trusted
529   and one as not trusted:
530   
531   @example
532   # CN=Wurzel ZS 3,O=Intevation GmbH,C=DE
533   A6935DD34EF3087973C706FC311AA2CCF733765B S
534   
535   # CN=PCA-1-Verwaltung-02/O=PKI-1-Verwaltung/C=DE
536   DC:BD:69:25:48:BD:BB:7E:31:6E:BB:80:D3:00:80:35:D4:F8:A6:CD S 
538   # CN=Root-CA/O=Schlapphuete/L=Pullach/C=DE
539   !14:56:98:D3:FE:9C:CA:5A:31:6E:BC:81:D3:11:4E:00:90:A3:44:C2 S
540   @end example
541   
542 Before entering a key into this file, you need to ensure its
543 authenticity.  How to do this depends on your organisation; your
544 administrator might have already entered those keys which are deemed
545 trustworthy enough into this file.  Places where to look for the
546 fingerprint of a root certificate are letters received from the CA or
547 the website of the CA (after making 100% sure that this is indeed the
548 website of that CA).  You may want to consider allowing interactive
549 updates of this file by using the @xref{option --allow-mark-trusted}.
550 This is however not as secure as maintaining this file manually.  It is
551 even advisable to change the permissions to read-only so that this file
552 can't be changed inadvertently.
554 As a special feature a line @code{include-default} will include a global
555 list of trusted certificates (e.g. @file{/etc/gnupg/trustlist.txt}).
556 This global list is also used if the local list is not available.
558 It is possible to add further flags after the @code{S} for use by the
559 caller:
561 @table @code
562 @item relax
563 Relax checking of some root certificate requirements.  This is for
564 example required if the certificate is missing the basicConstraints
565 attribute (despite that it is a MUST for CA certificates).
567 @item cm
568 If validation of a certificate finally issued by a CA with this flag set
569 fails, try again using the chain validation model.
571 @end table
573   
574 @item sshcontrol
576 This file is used when support for the secure shell agent protocol has
577 been enabled (@pxref{option --enable-ssh-support}). Only keys present
578 in this file are used in the SSH protocol.  The @command{ssh-add} tool
579 may be used to add new entries to this file; you may also add them
580 manually.  Comment lines, indicated by a leading hash mark, as well as
581 empty lines are ignored.  An entry starts with optional whitespace,
582 followed by the keygrip of the key given as 40 hex digits, optionally
583 followed by the caching TTL in seconds and another optional field for
584 arbitrary flags.  A non-zero TTL overrides the global default as
585 set by @option{--default-cache-ttl-ssh}.
587 The keygrip may be prefixed with a @code{!} to disable an entry entry.
588     
589 The following example lists exactly one key.  Note that keys available
590 through a OpenPGP smartcard in the active smartcard reader are
591 implicitly added to this list; i.e. there is no need to list them.
592   
593   @example
594   # Key added on 2005-02-25 15:08:29
595   5A6592BF45DC73BD876874A28FD4639282E29B52 0
596   @end example
598 @item private-keys-v1.d/
600   This is the directory where gpg-agent stores the private keys.  Each
601   key is stored in a file with the name made up of the keygrip and the
602   suffix @file{key}.
605 @end table
607 Note that on larger installations, it is useful to put predefined
608 files into the directory @file{/etc/skel/.gnupg/} so that newly created
609 users start up with a working configuration.  For existing users the
610 a small helper script is provided to create these files (@pxref{addgnupghome}).
615 @c Agent Signals
617 @mansect signals
618 @node Agent Signals
619 @section Use of some signals.
620 A running @command{gpg-agent} may be controlled by signals, i.e. using
621 the @command{kill} command to send a signal to the process. 
623 Here is a list of supported signals:
625 @table @gnupgtabopt
627 @item SIGHUP
628 @cpindex SIGHUP
629 This signal flushes all cached passphrases and if the program has been
630 started with a configuration file, the configuration file is read again.
631 Only certain options are honored: @code{quiet}, @code{verbose},
632 @code{debug}, @code{debug-all}, @code{debug-level}, @code{no-grab},
633 @code{pinentry-program}, @code{default-cache-ttl}, @code{max-cache-ttl},
634 @code{ignore-cache-for-signing}, @code{allow-mark-trusted} and
635 @code{disable-scdaemon}.  @code{scdaemon-program} is also supported but
636 due to the current implementation, which calls the scdaemon only once,
637 it is not of much use unless you manually kill the scdaemon.
640 @item SIGTERM
641 @cpindex SIGTERM
642 Shuts down the process but waits until all current requests are
643 fulfilled.  If the process has received 3 of these signals and requests
644 are still pending, a shutdown is forced.
646 @item SIGINT
647 @cpindex SIGINT
648 Shuts down the process immediately.
650 @item SIGUSR1
651 @cpindex SIGUSR1
652 Dump internal information to the log file.
654 @item SIGUSR2
655 @cpindex SIGUSR2
656 This signal is used for internal purposes.
658 @end table
660 @c 
661 @c  Examples
663 @mansect examples
664 @node Agent Examples
665 @section Examples
667 The usual way to invoke @command{gpg-agent} is
669 @example
670 $ eval $(gpg-agent --daemon)
671 @end example
673 An alternative way is by replacing @command{ssh-agent} with
674 @command{gpg-agent}.  If for example @command{ssh-agent} is started as
675 part of the Xsession initialization, you may simply replace
676 @command{ssh-agent} by a script like:
678 @cartouche
679 @example
680 #!/bin/sh
682 exec /usr/local/bin/gpg-agent --enable-ssh-support --daemon \
683       --write-env-file $@{HOME@}/.gpg-agent-info "$@@"
684 @end example
685 @end cartouche
687 @noindent
688 and add something like (for Bourne shells)
690 @cartouche
691 @example
692   if [ -f "$@{HOME@}/.gpg-agent-info" ]; then
693     . "$@{HOME@}/.gpg-agent-info"
694     export GPG_AGENT_INFO
695     export SSH_AUTH_SOCK
696     export SSH_AGENT_PID
697   fi
698 @end example
699 @end cartouche
701 @noindent
702 to your shell initialization file (e.g. @file{~/.bashrc}).
704 @c 
705 @c  Assuan Protocol
707 @manpause
708 @node Agent Protocol
709 @section Agent's Assuan Protocol
711 Note: this section does only document the protocol, which is used by
712 GnuPG components; it does not deal with the ssh-agent protocol.
714 The @command{gpg-agent} should be started by the login shell and set an
715 environment variable to tell clients about the socket to be used.
716 Clients should deny to access an agent with a socket name which does
717 not match its own configuration.  An application may choose to start
718 an instance of the gpgagent if it does not figure that any has been
719 started; it should not do this if a gpgagent is running but not
720 usable.  Because @command{gpg-agent} can only be used in background mode, no
721 special command line option is required to activate the use of the
722 protocol.
724 To identify a key we use a thing called keygrip which is the SHA-1 hash
725 of an canoncical encoded S-Expression of the the public key as used in
726 Libgcrypt.  For the purpose of this interface the keygrip is given as a
727 hex string.  The advantage of using this and not the hash of a
728 certificate is that it will be possible to use the same keypair for
729 different protocols, thereby saving space on the token used to keep the
730 secret keys.
732 @menu
733 * Agent PKDECRYPT::       Decrypting a session key
734 * Agent PKSIGN::          Signing a Hash
735 * Agent GENKEY::          Generating a Key
736 * Agent IMPORT::          Importing a Secret Key
737 * Agent EXPORT::          Exporting a Secret Key
738 * Agent ISTRUSTED::       Importing a Root Certificate
739 * Agent GET_PASSPHRASE::  Ask for a passphrase
740 * Agent GET_CONFIRMATION:: Ask for confirmation
741 * Agent HAVEKEY::         Check whether a key is available
742 * Agent LEARN::           Register a smartcard
743 * Agent PASSWD::          Change a Passphrase
744 * Agent UPDATESTARTUPTTY:: Change the Standard Display
745 * Agent GETEVENTCOUNTER:: Get the Event Counters
746 * Agent GETINFO::         Return information about the process
747 @end menu
749 @node Agent PKDECRYPT
750 @subsection Decrypting a session key
752 The client asks the server to decrypt a session key.  The encrypted
753 session key should have all information needed to select the
754 appropriate secret key or to delegate it to a smartcard.
756 @example
757   SETKEY <keyGrip>
758 @end example
760 Tell the server about the key to be used for decryption.  If this is
761 not used, @command{gpg-agent} may try to figure out the key by trying to
762 decrypt the message with each key available.
764 @example
765   PKDECRYPT
766 @end example
768 The agent checks whether this command is allowed and then does an
769 INQUIRY to get the ciphertext the client should then send the cipher
770 text.
772 @example
773     S: INQUIRE CIPHERTEXT
774     C: D (xxxxxx
775     C: D xxxx)
776     C: END
777 @end example
778     
779 Please note that the server may send status info lines while reading the
780 data lines from the client.  The data send is a SPKI like S-Exp with
781 this structure:
783 @example
784      (enc-val   
785        (<algo>
786          (<param_name1> <mpi>)
787            ...
788          (<param_namen> <mpi>)))
789 @end example
791 Where algo is a string with the name of the algorithm; see the libgcrypt
792 documentation for a list of valid algorithms.  The number and names of
793 the parameters depend on the algorithm.  The agent does return an error
794 if there is an inconsistency.
796 If the decryption was successful the decrypted data is returned by
797 means of "D" lines. 
799 Here is an example session:
801 @example
802    C: PKDECRYPT
803    S: INQUIRE CIPHERTEXT
804    C: D (enc-val elg (a 349324324) 
805    C: D    (b 3F444677CA)))
806    C: END
807    S: # session key follows
808    S: D (value 1234567890ABCDEF0)
809    S: OK descryption successful
810 @end example         
813 @node Agent PKSIGN
814 @subsection Signing a Hash
816 The client ask the agent to sign a given hash value.  A default key
817 will be chosen if no key has been set.  To set a key a client first
818 uses:
820 @example
821    SIGKEY <keyGrip>
822 @end example
824 This can be used multiple times to create multiple signature, the list
825 of keys is reset with the next PKSIGN command or a RESET.  The server
826 test whether the key is a valid key to sign something and responds with
827 okay.
829 @example
830    SETHASH --hash=<name>|<algo> <hexstring>
831 @end example
833 The client can use this command to tell the server about the data <hexstring>
834 (which usually is a hash) to be signed. <algo> is the decimal encoded hash
835 algorithm number as used by Libgcrypt.  Either <algo> or --hash=<name>
836 must be given.  Valid names for <name> are:
838 @table @code
839 @item sha1
840 @item sha256
841 @item rmd160
842 @item md5
843 @item tls-md5sha1
844 @end table
846 @noindent
847 The actual signing is done using
849 @example
850    PKSIGN <options>
851 @end example
853 Options are not yet defined, but my later be used to choosen among
854 different algorithms.  The agent does then some checks, asks for the
855 passphrase and as a result the server returns the signature as an SPKI
856 like S-expression in "D" lines:
858 @example  
859      (sig-val   
860        (<algo>
861          (<param_name1> <mpi>)
862            ...
863          (<param_namen> <mpi>)))
864 @end example
867 The operation is affected by the option
869 @example
870    OPTION use-cache-for-signing=0|1
871 @end example
873 The default of @code{1} uses the cache.  Setting this option to @code{0}
874 will lead @command{gpg-agent} to ignore the passphrase cache.  Note, that there is
875 also a global command line option for @command{gpg-agent} to globally disable the
876 caching.
879 Here is an example session:
881 @example
882    C: SIGKEY <keyGrip>
883    S: OK key available
884    C: SIGKEY <keyGrip>
885    S: OK key available
886    C: PKSIGN
887    S: # I did ask the user whether he really wants to sign
888    S: # I did ask the user for the passphrase
889    S: INQUIRE HASHVAL
890    C: D ABCDEF012345678901234
891    C: END
892    S: # signature follows
893    S: D (sig-val rsa (s 45435453654612121212))
894    S: OK
895 @end example
898 @node Agent GENKEY
899 @subsection Generating a Key
901 This is used to create a new keypair and store the secret key inside the
902 active PSE --- which is in most cases a Soft-PSE.  An not yet defined
903 option allows to choose the storage location.  To get the secret key out
904 of the PSE, a special export tool has to be used.
906 @example
907    GENKEY 
908 @end example
910 Invokes the key generation process and the server will then inquire
911 on the generation parameters, like:
913 @example
914    S: INQUIRE KEYPARM
915    C: D (genkey (rsa (nbits  1024)))
916    C: END
917 @end example
919 The format of the key parameters which depends on the algorithm is of
920 the form:
922 @example
923     (genkey
924       (algo
925         (parameter_name_1 ....)
926           ....
927         (parameter_name_n ....)))
928 @end example
930 If everything succeeds, the server returns the *public key* in a SPKI
931 like S-Expression like this:
933 @example
934      (public-key
935        (rsa
936          (n <mpi>)
937          (e <mpi>)))
938 @end example
940 Here is an example session:
942 @example
943    C: GENKEY
944    S: INQUIRE KEYPARM
945    C: D (genkey (rsa (nbits  1024)))
946    C: END
947    S: D (public-key
948    S: D   (rsa (n 326487324683264) (e 10001)))
949    S  OK key created
950 @end example
952 @node Agent IMPORT
953 @subsection Importing a Secret Key
955 This operation is not yet supportted by GpgAgent.  Specialized tools
956 are to be used for this.
958 There is no actual need because we can expect that secret keys
959 created by a 3rd party are stored on a smartcard.  If we have
960 generated the key ourself, we do not need to import it.
962 @node Agent EXPORT
963 @subsection Export a Secret Key
965 Not implemented.
967 Should be done by an extra tool.
969 @node Agent ISTRUSTED
970 @subsection Importing a Root Certificate
972 Actually we do not import a Root Cert but provide a way to validate
973 any piece of data by storing its Hash along with a description and
974 an identifier in the PSE.  Here is the interface desription:
976 @example
977     ISTRUSTED <fingerprint>
978 @end example
980 Check whether the OpenPGP primary key or the X.509 certificate with the
981 given fingerprint is an ultimately trusted key or a trusted Root CA
982 certificate.  The fingerprint should be given as a hexstring (without
983 any blanks or colons or whatever in between) and may be left padded with
984 00 in case of an MD5 fingerprint.  GPGAgent will answer with:
986 @example
987     OK
988 @end example
990 The key is in the table of trusted keys.
992 @example
993     ERR 304 (Not Trusted)
994 @end example
996 The key is not in this table.
998 Gpg needs the entire list of trusted keys to maintain the web of
999 trust; the following command is therefore quite helpful:
1001 @example
1002     LISTTRUSTED
1003 @end example
1005 GpgAgent returns a list of trusted keys line by line:
1007 @example
1008     S: D 000000001234454556565656677878AF2F1ECCFF P
1009     S: D 340387563485634856435645634856438576457A P
1010     S: D FEDC6532453745367FD83474357495743757435D S
1011     S: OK
1012 @end example
1014 The first item on a line is the hexified fingerprint where MD5
1015 ingerprints are @code{00} padded to the left and the second item is a
1016 flag to indicate the type of key (so that gpg is able to only take care
1017 of PGP keys).  P = OpenPGP, S = S/MIME.  A client should ignore the rest
1018 of the line, so that we can extend the format in the future.
1020 Finally a client should be able to mark a key as trusted:
1022 @example
1023    MARKTRUSTED @var{fingerprint} "P"|"S"
1024 @end example
1026 The server will then pop up a window to ask the user whether she
1027 really trusts this key. For this it will probably ask for a text to
1028 be displayed like this:
1030 @example
1031    S: INQUIRE TRUSTDESC
1032    C: D Do you trust the key with the fingerprint @@FPR@@
1033    C: D bla fasel blurb.
1034    C: END
1035    S: OK
1036 @end example
1038 Known sequences with the pattern @@foo@@ are replaced according to this
1039 table:
1041 @table @code
1042 @item @@FPR16@@ 
1043 Format the fingerprint according to gpg rules for a v3 keys.
1044 @item @@FPR20@@ 
1045 Format the fingerprint according to gpg rules for a v4 keys.
1046 @item @@FPR@@
1047 Choose an appropriate format to format the fingerprint.
1048 @item @@@@ 
1049 Replaced by a single @code{@@}
1050 @end table
1052 @node Agent GET_PASSPHRASE
1053 @subsection Ask for a passphrase
1055 This function is usually used to ask for a passphrase to be used for
1056 conventional encryption, but may also be used by programs which need
1057 special handling of passphrases.  This command uses a syntax which helps
1058 clients to use the agent with minimum effort.
1060 @example
1061   GET_PASSPHRASE [--data] [--check] [--no-ask] [--repeat[=N]] [--qualitybar] @var{cache_id} [@var{error_message} @var{prompt} @var{description}]
1062 @end example
1064 @var{cache_id} is expected to be a string used to identify a cached
1065 passphrase.  Use a @code{X} to bypass the cache.  With no other
1066 arguments the agent returns a cached passphrase or an error.  By
1067 convention either the hexified fingerprint of the key shall be used for
1068 @var{cache_id} or an arbitrary string prefixed with the name of the
1069 calling application and a colon: Like @code{gpg:somestring}.
1070   
1071 @var{error_message} is either a single @code{X} for no error message or
1072 a string to be shown as an error message like (e.g. "invalid
1073 passphrase").  Blanks must be percent escaped or replaced by @code{+}'.
1075 @var{prompt} is either a single @code{X} for a default prompt or the
1076 text to be shown as the prompt.  Blanks must be percent escaped or
1077 replaced by @code{+}.
1079 @var{description} is a text shown above the entry field.  Blanks must be
1080 percent escaped or replaced by @code{+}.
1082 The agent either returns with an error or with a OK followed by the hex
1083 encoded passphrase.  Note that the length of the strings is implicitly
1084 limited by the maximum length of a command.  If the option
1085 @option{--data} is used, the passphrase is not returned on the OK line
1086 but by regular data lines; this is the preferred method.
1088 If the option @option{--check} is used, the standard passphrase
1089 constraints checks are applied.  A check is not done if the passphrase
1090 has been found in the cache.
1092 If the option @option{--no-ask} is used and the passphrase is not in the
1093 cache the user will not be asked to enter a passphrase but the error
1094 code @code{GPG_ERR_NO_DATA} is returned.  
1096 If the option @option{--qualitybar} is used and a minimum passphrase
1097 length has been configured, a visual indication of the entered
1098 passphrase quality is shown.
1100 @example
1101   CLEAR_PASSPHRASE @var{cache_id}
1102 @end example
1104 may be used to invalidate the cache entry for a passphrase.  The
1105 function returns with OK even when there is no cached passphrase.
1108 @node Agent GET_CONFIRMATION
1109 @subsection Ask for confirmation
1111 This command may be used to ask for a simple confirmation by
1112 presenting a text and 2 bottonts: Okay and Cancel.
1114 @example
1115   GET_CONFIRMATION @var{description}
1116 @end example
1118 @var{description}is displayed along with a Okay and Cancel
1119 button. Blanks must be percent escaped or replaced by @code{+}.  A
1120 @code{X} may be used to display confirmation dialog with a default
1121 text.
1123 The agent either returns with an error or with a OK.  Note, that the
1124 length of @var{description} is implicitly limited by the maximum
1125 length of a command.
1129 @node Agent HAVEKEY
1130 @subsection Check whether a key is available
1132 This can be used to see whether a secret key is available.  It does
1133 not return any information on whether the key is somehow protected.
1135 @example
1136   HAVEKEY @var{keygrip}
1137 @end example
1139 The Agent answers either with OK or @code{No_Secret_Key} (208).  The
1140 caller may want to check for other error codes as well.
1143 @node Agent LEARN
1144 @subsection Register a smartcard
1146 @example
1147   LEARN [--send]
1148 @end example
1150 This command is used to register a smartcard.  With the --send
1151 option given the certificates are send back.
1154 @node Agent PASSWD
1155 @subsection Change a Passphrase
1157 @example
1158   PASSWD @var{keygrip}
1159 @end example
1161 This command is used to interactively change the passphrase of the key
1162 indentified by the hex string @var{keygrip}.
1165 @node Agent UPDATESTARTUPTTY
1166 @subsection Change the standard display
1168 @example
1169   UPDATESTARTUPTTY
1170 @end example
1172 Set the startup TTY and X-DISPLAY variables to the values of this
1173 session.  This command is useful to direct future pinentry invocations
1174 to another screen.  It is only required because there is no way in the
1175 ssh-agent protocol to convey this information.
1178 @node Agent GETEVENTCOUNTER
1179 @subsection Get the Event Counters
1181 @example
1182   GETEVENTCOUNTER
1183 @end example
1185 This function return one status line with the current values of the
1186 event counters.  The event counters are useful to avoid polling by
1187 delaying a poll until something has changed.  The values are decimal
1188 numbers in the range @code{0} to @code{UINT_MAX} and wrapping around to
1189 0.  The actual values should not be relied upon; they shall only be used
1190 to detect a change.
1192 The currently defined counters are are:
1193 @table @code
1194 @item ANY
1195 Incremented with any change of any of the other counters.
1196 @item KEY
1197 Incremented for added or removed private keys.
1198 @item CARD
1199 Incremented for changes of the card readers stati.
1200 @end table
1202 @node Agent GETINFO
1203 @subsection  Return information about the process
1205 This is a multipurpose function to return a variety of information.
1207 @example
1208 GETINFO @var{what}
1209 @end example
1211 The value of @var{what} specifies the kind of information returned:
1212 @table @code
1213 @item version
1214 Return the version of the program.
1215 @item pid
1216 Return the process id of the process.
1217 @item socket_name
1218 Return the name of the socket used to connect the agent.
1219 @item ssh_socket_name
1220 Return the name of the socket used for SSH connections.  If SSH support
1221 has not been enabled the error @code{GPG_ERR_NO_DATA} will be returned.
1222 @end table
1225 @mansect see also
1226 @ifset isman
1227 @command{gpg2}(1), 
1228 @command{gpgsm}(1), 
1229 @command{gpg-connect-agent}(1),
1230 @command{scdaemon}(1)
1231 @end ifset
1232 @include see-also-note.texi