2007-06-15 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / doc / gpg-agent.texi
blobed3ff6052084a941762a19a86baec5eaa676a619
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.  This short script may do the job:
66 @smallexample
67 if test -f $HOME/.gpg-agent-info && \
68    kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null; then
69      GPG_AGENT_INFO=`cat $HOME/.gpg-agent-info`
70      export GPG_AGENT_INFO   
71 else
72      eval `gpg-agent --daemon`
73      echo $GPG_AGENT_INFO >$HOME/.gpg-agent-info
75 @end smallexample
77 @noindent
78 Note that the new option @option{--write-env-file} may be used instead.
81 @noindent
82 You should always add the following lines to your @code{.bashrc} or
83 whatever initialization file is used for all shell invocations:
85 @smallexample
86 GPG_TTY=`tty`
87 export GPG_TTY
88 @end smallexample
90 @noindent
91 It is important that this environment variable always reflects the
92 output of the @code{tty} command.  For W32 systems this option is not
93 required.
95 Please make sure that a proper pinentry program has been installed
96 under the default filename (which is system dependant) or use the
97 option @code{pinentry-pgm} to specify the full name of that program.
98 It is often useful to install a symbolic link from the actual used
99 pinentry (e.g. @file{/usr/bin/pinentry-gtk}) to the expected
100 one (e.g. @file{/usr/bin/pinentry}).
102 @manpause
103 @noindent
104 @xref{Option Index},for an index to @command{GPG-AGENT}'s commands and options.
105 @mancont
107 @menu
108 * Agent Commands::      List of all commands.
109 * Agent Options::       List of all options.
110 * Agent Configuration:: Configuration files.
111 * Agent Signals::       Use of some signals.
112 * Agent Examples::      Some usage examples.
113 * Agent Protocol::      The protocol the agent uses.
114 @end menu
116 @mansect commands
117 @node Agent Commands
118 @section Commands
120 Commands are not distinguished from options execpt for the fact that
121 only one one command is allowed.
123 @table @gnupgtabopt
124 @item --version
125 @opindex version
126 Print the program version and licensing information.  Not that you can
127 abbreviate this command.
129 @item --help
130 @itemx -h
131 @opindex help
132 Print a usage message summarizing the most useful command-line options.
133 Not that you can abbreviate this command.
135 @item --dump-options
136 @opindex dump-options
137 Print a list of all available options and commands.  Not that you can
138 abbreviate this command.
140 @item --server
141 @opindex server
142 Run in server mode and wait for commands on the @code{stdin}.  The
143 default mode is to create a socket and listen for commands there.
145 @item --daemon [@var{command line}]
146 @opindex daemon
147 Run the program in the background.  This option is required to prevent
148 it from being accidently running in the background.  A common way to do
149 this is:
150 @example
151 @end example
152 $ eval `gpg-agent --daemon`
153 @end table
156 @mansect options
157 @node Agent Options
158 @section Option Summary
160 @table @gnupgtabopt
162 @anchor{option --options}
163 @item --options @var{file}
164 @opindex options
165 Reads configuration from @var{file} instead of from the default
166 per-user configuration file.  The default configuration file is named
167 @file{gpg-agent.conf} and expected in the @file{.gnupg} directory directly
168 below the home directory of the user.
170 @anchor{option --homedir}
171 @include opt-homedir.texi
174 @item -v
175 @item --verbose
176 @opindex v
177 @opindex verbose
178 Outputs additional information while running.
179 You can increase the verbosity by giving several
180 verbose commands to @command{gpgsm}, such as @samp{-vv}.
182 @item -q
183 @item --quiet
184 @opindex q
185 @opindex quiet
186 Try to be as quiet as possible.
188 @item --batch
189 @opindex batch
190 Don't invoke a pinentry or do any other thing requiring human interaction.
192 @item --faked-system-time @var{epoch}
193 @opindex faked-system-time
194 This option is only useful for testing; it sets the system time back or
195 forth to @var{epoch} which is the number of seconds elapsed since the year
196 1970.
198 @item --debug-level @var{level}
199 @opindex debug-level
200 Select the debug level for investigating problems. @var{level} may be
201 one of:
203    @table @code
204    @item none
205    no debugging at all.
206    @item basic  
207    some basic debug messages
208    @item advanced
209    more verbose debug messages
210    @item expert
211    even more detailed messages
212    @item guru
213    all of the debug messages you can get
214    @end table
216 How these messages are mapped to the actual debugging flags is not
217 specified and may change with newer releaes of this program. They are
218 however carefully selected to best aid in debugging.
220 @item --debug @var{flags}
221 @opindex debug
222 This option is only useful for debugging and the behaviour may change at
223 any time without notice.  FLAGS are bit encoded and may be given in
224 usual C-Syntax. The currently defined bits are:
226 @table @code
227 @item 0  (1)
228 X.509 or OpenPGP protocol related data
229 @item 1  (2)  
230 values of big number integers 
231 @item 2  (4)
232 low level crypto operations
233 @item 5  (32)
234 memory allocation
235 @item 6  (64)
236 caching
237 @item 7  (128)
238 show memory statistics.
239 @item 9  (512)
240 write hashed data to files named @code{dbgmd-000*}
241 @item 10 (1024)
242 trace Assuan protocol
243 @item 12 (4096)
244 bypass all certificate validation
245 @end table
247 @item --debug-all
248 @opindex debug-all
249 Same as @code{--debug=0xffffffff}
251 @item --debug-wait @var{n}
252 @opindex debug-wait
253 When running in server mode, wait @var{n} seconds before entering the
254 actual processing loop and print the pid.  This gives time to attach a
255 debugger.
257 @item --no-detach
258 @opindex no-detach
259 Don't detach the process from the console.  This is manly usefule for
260 debugging.
262 @item -s
263 @itemx --sh
264 @itemx -c
265 @itemx --csh
266 @opindex s
267 @opindex sh
268 @opindex c
269 @opindex csh
270 Format the info output in daemon mode for use with the standard Bourne
271 shell respective the C-shell . The default is to guess it based on the
272 environment variable @code{SHELL} which is in almost all cases
273 sufficient.
275 @item --write-env-file @var{file}
276 @opindex write-env-file
277 Often it is required to connect to the agent from a process not being an
278 inferior of @command{gpg-agent} and thus the environment variable with
279 the socket name is not available.  To help setting up those variables in
280 other sessions, this option may be used to write the information into
281 @var{file}.  If @var{file} is not specified the default name
282 @file{$@{HOME@}/.gpg-agent-info} will be used.  The format is suitable
283 to be evaluated by a Bourne shell like in this simple example:
285 @example
286 eval `cat @var{file}`
287 eval `cut -d= -f 1 < @var{file} | xargs echo export`
288 @end example
292 @item --no-grab
293 @opindex no-grab
294 Tell the pinentryo not to grab the keyboard and mouse.  This option
295 should in general not be used to avaoid X-sniffing attacks.
297 @item --log-file @var{file}
298 @opindex log-file
299 Append all logging output to @var{file}.  This is very helpful in
300 seeing what the agent actually does.
302 @anchor{option --allow-mark-trusted}
303 @item --allow-mark-trusted
304 @opindex allow-mark-trusted
305 Allow clients to mark keys as trusted, i.e. put them into the
306 @file{trustlist.txt} file.  This is by default not allowed to make it
307 harder for users to inadvertly accept Root-CA keys.
309 @item --ignore-cache-for-signing
310 @opindex ignore-cache-for-signing
311 This option will let @command{gpg-agent} bypass the passphrase cache for all
312 signing operation.  Note that there is also a per-session option to
313 control this behaviour but this command line option takes precedence.
315 @item --default-cache-ttl @var{n}
316 @opindex default-cache-ttl
317 Set the time a cache entry is valid to @var{n} seconds.  The default are
318 600 seconds.
320 @item --default-cache-ttl-ssh @var{n}
321 @opindex default-cache-ttl
322 Set the time a cache entry used for SSH keys is valid to @var{n}
323 seconds.  The default are 1800 seconds.
325 @item --max-cache-ttl @var{n}
326 @opindex max-cache-ttl
327 Set the maximum time a cache entry is valid to @var{n} seconds.  After
328 this time a cache entry will get expired even if it has been accessed
329 recently.  The default are 2 hours (7200 seconds).
331 @item --max-cache-ttl-ssh @var{n}
332 @opindex max-cache-ttl-ssh
333 Set the maximum time a cache entry used for SSH keys is valid to @var{n}
334 seconds.  After this time a cache entry will get expired even if it has
335 been accessed recently.  The default are 2 hours (7200 seconds).
337 @item --min-passphrase-len @var{n}
338 @opindex min-passphrase-len
339 Set the minimal length of a passphrase.  When entering a new passphrase
340 shorter than this value a warning will be displayed.  Defaults to 8.
342 @item --pinentry-program @var{filename}
343 @opindex pinentry-program
344 Use program @var{filename} as the PIN entry.  The default is installation
345 dependend and can be shown with the @code{--version} command.
347 @item --pinentry-touch-file @var{filename}
348 @opindex pinentry-touch-file
349 By default the file name of the socket gpg-agent is listening for
350 requests is passed to Pinentry, so that it can touch that file before
351 exiting (it does this only in curses mode).  This option changes the
352 file passed to Pinentry to @var{filename}.  The special name
353 @code{/dev/null} may be used to completely disable this feature.  Note
354 that Pinentry will not create that file, it will only change the
355 modification and access time.
358 @item --scdaemon-program @var{filename}
359 @opindex scdaemon-program
360 Use program @var{filename} as the Smartcard daemon.  The default is
361 installation dependend and can be shown with the @code{--version}
362 command.
364 @item --disable-scdaemon
365 @opindex disable-scdaemon
366 Do not make use of the scdaemon tool.  This option has the effect of
367 disabling the ability to do smartcard operations.  Note, that enabling
368 this option at runtime does not kill an already forked scdaemon.
370 @item --use-standard-socket
371 @itemx --no-use-standard-socket
372 @opindex use-standard-socket
373 @opindex no-use-standard-socket
374 By enabling this option @command{gpg-agent} will listen on the socket
375 named @file{S.gpg-agent}, located in the home directory, and not create
376 a random socket below a temporary directory.  Tools connecting to
377 @command{gpg-agent} should first try to connect to the socket given in
378 environment variable @var{GPG_AGENT_INFO} and the fall back to this
379 socket.  This option may not be used if the home directory is mounted as
380 a remote file system.  
382 @noindent
383 Note, that as of now, W32 systems default to this option.
386 @item --display @var{string}
387 @itemx --ttyname @var{string}
388 @itemx --ttytype @var{string}
389 @itemx --lc-type @var{string}
390 @itemx --lc-messages @var{string}
391 @opindex display 
392 @opindex ttyname 
393 @opindex ttytype 
394 @opindex lc-type 
395 @opindex lc-messages
396 These options are used with the server mode to pass localization
397 information.
399 @item --keep-tty
400 @itemx --keep-display
401 @opindex keep-tty
402 @opindex keep-display
403 Ignore requests to change change the current @code{tty} respective the X
404 window system's @code{DISPLAY} variable.  This is useful to lock the
405 pinentry to pop up at the @code{tty} or display you started the agent.
407 @anchor{option --enable-ssh-support}
408 @item --enable-ssh-support
409 @opindex enable-ssh-support
411 Enable emulation of the OpenSSH Agent protocol.
413 In this mode of operation, the agent does not only implement the
414 gpg-agent protocol, but also the agent protocol used by OpenSSH
415 (through a seperate socket).  Consequently, it should possible to use
416 the gpg-agent as a drop-in replacement for the well known ssh-agent.
418 SSH Keys, which are to be used through the agent, need to be added to
419 the gpg-agent initially through the ssh-add utility.  When a key is
420 added, ssh-add will ask for the password of the provided key file and
421 send the unprotected key material to the agent; this causes the
422 gpg-agent to ask for a passphrase, which is to be used for encrypting
423 the newly received key and storing it in a gpg-agent specific
424 directory.
426 Once, a key has been added to the gpg-agent this way, the gpg-agent
427 will be ready to use the key.
429 Note: in case the gpg-agent receives a signature request, the user might
430 need to be prompted for a passphrase, which is necessary for decrypting
431 the stored key.  Since the ssh-agent protocol does not contain a
432 mechanism for telling the agent on which display/terminal it is running,
433 gpg-agent's ssh-support will use the TTY or X display where gpg-agent
434 has been started.  To switch this display to the current one, the
435 follwing command may be used:
437 @smallexample
438 echo UPDATESTARTUPTTY | gpg-connect-agent
439 @end smallexample
443 @end table
445 All the long options may also be given in the configuration file after
446 stripping off the two leading dashes.
449 @mansect files
450 @node Agent Configuration
451 @section Configuration
453 There are a few configuration files needed for the operation of the
454 agent. By default they may all be found in the current home directory
455 (@pxref{option --homedir}).
457 @table @file
459 @item gpg-agent.conf
460 @cindex gpg-agent.conf
461   This is the standard configuration file read by @command{gpg-agent} on
462   startup.  It may contain any valid long option; the leading
463   two dashes may not be entered and the option may not be abbreviated.
464   This file is also read after a @code{SIGHUP} however only a few
465   options will actually have an effect.  This default name may be
466   changed on the command line (@pxref{option --options}).
468 @item trustlist.txt
469   This is the list of trusted keys.  Comment lines, indicated by a leading
470   hash mark, as well as empty lines are ignored.  To mark a key as trusted
471   you need to enter its fingerprint followed by a space and a capital
472   letter @code{S}.  Colons may optionally be used to separate the bytes of
473   a fingerprint; this allows to cut and paste the fingerprint from a key
474   listing output.
475   
476   Here is an example where two keys are marked as ultimately trusted:
477   
478   @example
479   # CN=Wurzel ZS 3,O=Intevation GmbH,C=DE
480   A6935DD34EF3087973C706FC311AA2CCF733765B S
481   
482   # CN=PCA-1-Verwaltung-02/O=PKI-1-Verwaltung/C=DE
483   DC:BD:69:25:48:BD:BB:7E:31:6E:BB:80:D3:00:80:35:D4:F8:A6:CD S 
484   @end example
485   
486 Before entering a key into this file, you need to ensure its
487 authenticity.  How to do this depends on your organisation; your
488 administrator might have already entered those keys which are deemed
489 trustworthy enough into this file.  Places where to look for the
490 fingerprint of a root certificate are letters received from the CA or
491 the website of the CA (after making 100% sure that this is indeed the
492 website of that CA).  You may want to consider allowing interactive
493 updates of this file by using the @xref{option --allow-mark-trusted}.
494 This is however not as secure as maintaining this file manually.  It is
495 even advisable to change the permissions to read-only so that this file
496 can't be changed inadvertently.
498 It is possible to add further flags after the @code{S} for use by the
499 caller.  The only flag currently defined is @code{relax} to relax
500 checking of some root certificate requirements.
502 As a special feature a line @code{include-default} will include a global
503 list of trusted certificates (e.g. @file{/etc/gnupg/trustlist.txt}).
504 This global list is also used if the local list is not available.
506   
507 @item sshcontrol
509   This file is used when support for the secure shell agent protocol has
510   been enabled (@pxref{option --enable-ssh-support}). Only keys present in
511   this file are used in the SSH protocol.  The @command{ssh-add} tool y be
512   used to add new entries to this file; you may also add them manually.
513   Comment lines, indicated by a leading hash mark, as well as empty lines
514   are ignored.  An entry starts with optional white spaces, followed by
515   the keygrip of the key given as 40 hex digits, optionally followed by
516   the caching TTL in seconds and another optional field for arbitrary
517   flags.  A @code{!} may be prepended to the keygrip to disable this
518   entry.
519     
520   The follwoing example lists exactly one key.  Note that keys available
521   through a OpenPGP smartcard in the active smartcard reader are implictly
522   added to this list; i.e. there is no need to list them.
523   
524   @example
525   # Key added on 2005-02-25 15:08:29
526   5A6592BF45DC73BD876874A28FD4639282E29B52 0
527   @end example
529 @item private-keys-v1.d/
531   This is the directory where gpg-agent stores the private keys.  Each
532   key is stored in a file with the name made up of the keygrip and the
533   suffix @file{key}.
536 @end table
538 Note that on larger installations, it is useful to put predefined
539 files into the directory @file{/etc/skel/.gnupg/} so that newly created
540 users start up with a working configuration.  For existing users the
541 a small helper script is provied to create these files (@pxref{addgnupghome}).
546 @c Agent Signals
548 @mansect signals
549 @node Agent Signals
550 @section Use of some signals.
551 A running @command{gpg-agent} may be controlled by signals, i.e. using
552 the @command{kill} command to send a signal to the process. 
554 Here is a list of supported signals:
556 @table @gnupgtabopt
558 @item SIGHUP
559 @cpindex SIGHUP
560 This signal flushes all chached passphrases and if the program has been
561 started with a configuration file, the configuration file is read again.
562 Only certain options are honored: @code{quiet}, @code{verbose},
563 @code{debug}, @code{debug-all}, @code{debug-level}, @code{no-grab},
564 @code{pinentry-program}, @code{default-cache-ttl}, @code{max-cache-ttl},
565 @code{ignore-cache-for-signing}, @code{allow-mark-trusted} and
566 @code{disable-scdaemon}.  @code{scdaemon-program} is also supported but
567 due to the current implementation, which calls the scdaemon only once,
568 it is not of much use unless you manually kill the scdaemon.
571 @item SIGTERM
572 @cpindex SIGTERM
573 Shuts down the process but waits until all current requests are
574 fulfilled.  If the process has received 3 of these signals and requests
575 are still pending, a shutdown is forced.
577 @item SIGINT
578 @cpindex SIGINT
579 Shuts down the process immediately.
581 @item SIGUSR1
582 @cpindex SIGUSR1
583 Dump internal information to the log file.
585 @item SIGUSR2
586 @cpindex SIGUSR2
587 This signal is used for internal purposes.
589 @end table
591 @c 
592 @c  Examples
594 @mansect examples
595 @node Agent Examples
596 @section Examples
598 The usual way to invoke @command{gpg-agent} is
600 @example
601 $ eval `gpg-agent --daemon`
602 @end example
604 An alternative way is by replacing @command{ssh-agent} with
605 @command{gpg-agent}.  If for example @command{ssh-agent} is started as
606 part of the Xsession intialization you may simply replace
607 @command{ssh-agent} by a script like:
609 @cartouche
610 @example
611 #!/bin/sh
613 exec /usr/local/bin/gpg-agent --enable-ssh-support --daemon \
614       --write-env-file $@{HOME@}/.gpg-agent-info "$@@"
615 @end example
616 @end cartouche
618 @noindent
619 and add something like (for Bourne shells)
621 @cartouche
622 @example
623   if [ -f "$@{HOME@}/.gpg-agent-info" ]; then
624     . "$@{HOME@}/.gpg-agent-info"
625     export GPG_AGENT_INFO
626     export SSH_AUTH_SOCK
627     export SSH_AGENT_PID
628   fi
629 @end example
630 @end cartouche
632 @noindent
633 to your shell initialization file (e.g. @file{~/.bashrc}).
635 @c 
636 @c  Assuan Protocol
638 @manpause
639 @node Agent Protocol
640 @section Agent's Assuan Protocol
642 Note: this section does only document the protocol, which is used by
643 GnuPG components; it does not deal with the ssh-agent protocol.
645 The @command{gpg-agent} should be started by the login shell and set an
646 environment variable to tell clients about the socket to be used.
647 Clients should deny to access an agent with a socket name which does
648 not match its own configuration.  An application may choose to start
649 an instance of the gpgagent if it does not figure that any has been
650 started; it should not do this if a gpgagent is running but not
651 usable.  Because @command{gpg-agent} can only be used in background mode, no
652 special command line option is required to activate the use of the
653 protocol.
655 To identify a key we use a thing called keygrip which is the SHA-1 hash
656 of an canoncical encoded S-Expression of the the public key as used in
657 Libgcrypt.  For the purpose of this interface the keygrip is given as a
658 hex string.  The advantage of using this and not the hash of a
659 certificate is that it will be possible to use the same keypair for
660 different protocols, thereby saving space on the token used to keep the
661 secret keys.
663 @menu
664 * Agent PKDECRYPT::       Decrypting a session key
665 * Agent PKSIGN::          Signing a Hash
666 * Agent GENKEY::          Generating a Key
667 * Agent IMPORT::          Importing a Secret Key
668 * Agent EXPORT::          Exporting a Secret Key
669 * Agent ISTRUSTED::       Importing a Root Certificate
670 * Agent GET_PASSPHRASE::  Ask for a passphrase
671 * Agent GET_CONFIRMATION:: Ask for confirmation
672 * Agent HAVEKEY::         Check whether a key is available
673 * Agent LEARN::           Register a smartcard
674 * Agent PASSWD::          Change a Passphrase
675 * Agent UPDATESTARTUPTTY:: Change the Standard Display
676 * Agent GETEVENTCOUNTER:: Get the Event Counters
677 @end menu
679 @node Agent PKDECRYPT
680 @subsection Decrypting a session key
682 The client asks the server to decrypt a session key.  The encrypted
683 session key should have all information needed to select the
684 appropriate secret key or to delegate it to a smartcard.
686 @example
687   SETKEY <keyGrip>
688 @end example
690 Tell the server about the key to be used for decryption.  If this is
691 not used, @command{gpg-agent} may try to figure out the key by trying to
692 decrypt the message with each key available.
694 @example
695   PKDECRYPT
696 @end example
698 The agent checks whether this command is allowed and then does an
699 INQUIRY to get the ciphertext the client should then send the cipher
700 text.
702 @example
703     S: INQUIRE CIPHERTEXT
704     C: D (xxxxxx
705     C: D xxxx)
706     C: END
707 @end example
708     
709 Please note that the server may send status info lines while reading the
710 data lines from the client.  The data send is a SPKI like S-Exp with
711 this structure:
713 @example
714      (enc-val   
715        (<algo>
716          (<param_name1> <mpi>)
717            ...
718          (<param_namen> <mpi>)))
719 @end example
721 Where algo is a string with the name of the algorithm; see the libgcrypt
722 documentation for a list of valid algorithms.  The number and names of
723 the parameters depend on the algorithm.  The agent does return an error
724 if there is an inconsistency.
726 If the decryption was successful the decrypted data is returned by
727 means of "D" lines. 
729 Here is an example session:
731 @example
732    C: PKDECRYPT
733    S: INQUIRE CIPHERTEXT
734    C: D (enc-val elg (a 349324324) 
735    C: D    (b 3F444677CA)))
736    C: END
737    S: # session key follows
738    S: D (value 1234567890ABCDEF0)
739    S: OK descryption successful
740 @end example         
743 @node Agent PKSIGN
744 @subsection Signing a Hash
746 The client ask the agent to sign a given hash value.  A default key
747 will be chosen if no key has been set.  To set a key a client first
748 uses:
750 @example
751    SIGKEY <keyGrip>
752 @end example
754 This can be used multiple times to create multiple signature, the list
755 of keys is reset with the next PKSIGN command or a RESET.  The server
756 test whether the key is a valid key to sign something and responds with
757 okay.
759 @example
760    SETHASH --hash=<name>|<algo> <hexstring>
761 @end example
763 The client can use this command to tell the server about the data <hexstring>
764 (which usually is a hash) to be signed. <algo> is the decimal encoded hash
765 algorithm number as used by Libgcrypt.  Either <algo> or --hash=<name>
766 must be given.  Valid names for <name> are:
768 @table @code
769 @item sha1
770 @item sha256
771 @item rmd160
772 @item md5
773 @item tls-md5sha1
774 @end table
776 @noindent
777 The actual signing is done using
779 @example
780    PKSIGN <options>
781 @end example
783 Options are not yet defined, but my later be used to choosen among
784 different algorithms.  The agent does then some checks, asks for the
785 passphrase and as a result the server returns the signature as an SPKI
786 like S-expression in "D" lines:
788 @example  
789      (sig-val   
790        (<algo>
791          (<param_name1> <mpi>)
792            ...
793          (<param_namen> <mpi>)))
794 @end example
797 The operation is affected by the option
799 @example
800    OPTION use-cache-for-signing=0|1
801 @end example
803 The default of @code{1} uses the cache.  Setting this option to @code{0}
804 will lead @command{gpg-agent} to ignore the passphrase cache.  Note, that there is
805 also a global command line option for @command{gpg-agent} to globally disable the
806 caching.
809 Here is an example session:
811 @example
812    C: SIGKEY <keyGrip>
813    S: OK key available
814    C: SIGKEY <keyGrip>
815    S: OK key available
816    C: PKSIGN
817    S: # I did ask the user whether he really wants to sign
818    S: # I did ask the user for the passphrase
819    S: INQUIRE HASHVAL
820    C: D ABCDEF012345678901234
821    C: END
822    S: # signature follows
823    S: D (sig-val rsa (s 45435453654612121212))
824    S: OK
825 @end example
828 @node Agent GENKEY
829 @subsection Generating a Key
831 This is used to create a new keypair and store the secret key inside the
832 active PSE -w which is in most cases a Soft-PSE.  An not yet defined
833 option allows to choose the storage location.  To get the secret key out
834 of the PSE, a special export tool has to be used.
836 @example
837    GENKEY 
838 @end example
840 Invokes the key generation process and the server will then inquire
841 on the generation parameters, like:
843 @example
844    S: INQUIRE KEYPARM
845    C: D (genkey (rsa (nbits  1024)))
846    C: END
847 @end example
849 The format of the key parameters which depends on the algorithm is of
850 the form:
852 @example
853     (genkey
854       (algo
855         (parameter_name_1 ....)
856           ....
857         (parameter_name_n ....)))
858 @end example
860 If everything succeeds, the server returns the *public key* in a SPKI
861 like S-Expression like this:
863 @example
864      (public-key
865        (rsa
866          (n <mpi>)
867          (e <mpi>)))
868 @end example
870 Here is an example session:
872 @example
873    C: GENKEY
874    S: INQUIRE KEYPARM
875    C: D (genkey (rsa (nbits  1024)))
876    C: END
877    S: D (public-key
878    S: D   (rsa (n 326487324683264) (e 10001)))
879    S  OK key created
880 @end example
882 @node Agent IMPORT
883 @subsection Importing a Secret Key
885 This operation is not yet supportted by GpgAgent.  Specialized tools
886 are to be used for this.
888 There is no actual need because we can expect that secret keys
889 created by a 3rd party are stored on a smartcard.  If we have
890 generated the key ourself, we do not need to import it.
892 @node Agent EXPORT
893 @subsection Export a Secret Key
895 Not implemented.
897 Should be done by an extra tool.
899 @node Agent ISTRUSTED
900 @subsection Importing a Root Certificate
902 Actually we do not import a Root Cert but provide a way to validate
903 any piece of data by storing its Hash along with a description and
904 an identifier in the PSE.  Here is the interface desription:
906 @example
907     ISTRUSTED <fingerprint>
908 @end example
910 Check whether the OpenPGP primary key or the X.509 certificate with the
911 given fingerprint is an ultimately trusted key or a trusted Root CA
912 certificate.  The fingerprint should be given as a hexstring (without
913 any blanks or colons or whatever in between) and may be left padded with
914 00 in case of an MD5 fingerprint.  GPGAgent will answer with:
916 @example
917     OK
918 @end example
920 The key is in the table of trusted keys.
922 @example
923     ERR 304 (Not Trusted)
924 @end example
926 The key is not in this table.
928 Gpg needs the entire list of trusted keys to maintain the web of
929 trust; the following command is therefore quite helpful:
931 @example
932     LISTTRUSTED
933 @end example
935 GpgAgent returns a list of trusted keys line by line:
937 @example
938     S: D 000000001234454556565656677878AF2F1ECCFF P
939     S: D 340387563485634856435645634856438576457A P
940     S: D FEDC6532453745367FD83474357495743757435D S
941     S: OK
942 @end example
944 The first item on a line is the hexified fingerprint where MD5
945 ingerprints are @code{00} padded to the left and the second item is a
946 flag to indicate the type of key (so that gpg is able to only take care
947 of PGP keys).  P = OpenPGP, S = S/MIME.  A client should ignore the rest
948 of the line, so that we can extend the format in the future.
950 Finally a client should be able to mark a key as trusted:
952 @example
953    MARKTRUSTED @var{fingerprint} "P"|"S"
954 @end example
956 The server will then pop up a window to ask the user whether she
957 really trusts this key. For this it will probably ask for a text to
958 be displayed like this:
960 @example
961    S: INQUIRE TRUSTDESC
962    C: D Do you trust the key with the fingerprint @@FPR@@
963    C: D bla fasel blurb.
964    C: END
965    S: OK
966 @end example
968 Known sequences with the pattern @@foo@@ are replaced according to this
969 table:
971 @table @code
972 @item @@FPR16@@ 
973 Format the fingerprint according to gpg rules for a v3 keys.
974 @item @@FPR20@@ 
975 Format the fingerprint according to gpg rules for a v4 keys.
976 @item @@FPR@@
977 Choose an appropriate format to format the fingerprint.
978 @item @@@@ 
979 Replaced by a single @code{@@}
980 @end table
982 @node Agent GET_PASSPHRASE
983 @subsection Ask for a passphrase
985 This function is usually used to ask for a passphrase to be used for
986 conventional encryption, but may also be used by programs which need
987 special handling of passphrases.  This command uses a syntax which helps
988 clients to use the agent with minimum effort.
990 @example
991   GET_PASSPHRASE [--data] [--check] @var{cache_id} [@var{error_message} @var{prompt} @var{description}]
992 @end example
994 @var{cache_id} is expected to be a string used to identify a cached
995 passphrase.  Use a @code{X} to bypass the cache.  With no other
996 arguments the agent returns a cached passphrase or an error.  By
997 convention either the hexified fingerprint of the key shall be used for
998 @var{cache_id} or an arbitrary string prefixed with the name of the
999 calling application and a colon: Like @code{gpg:somestring}.
1000   
1001 @var{error_message} is either a single @code{X} for no error message or
1002 a string to be shown as an error message like (e.g. "invalid
1003 passphrase").  Blanks must be percent escaped or replaced by @code{+}'.
1005 @var{prompt} is either a single @code{X} for a default prompt or the
1006 text to be shown as the prompt.  Blanks must be percent escaped or
1007 replaced by @code{+}.
1009 @var{description} is a text shown above the entry field.  Blanks must be
1010 percent escaped or replaced by @code{+}.
1012 The agent either returns with an error or with a OK followed by the hex
1013 encoded passphrase.  Note that the length of the strings is implicitly
1014 limited by the maximum length of a command.  If the option
1015 @option{--data} is used, the passphrase is not returned on the OK line
1016 but by regular data lines; this is the preferred method.
1018 If the option @option{--check} is used, the standard passphrase
1019 constraints checks are applied.  A check is not done if the passphrase
1020 has been found in the cache.
1022 @example
1023   CLEAR_PASSPHRASE @var{cache_id}
1024 @end example
1026 may be used to invalidate the cache entry for a passphrase.  The
1027 function returns with OK even when there is no cached passphrase.
1030 @node Agent GET_CONFIRMATION
1031 @subsection Ask for confirmation
1033 This command may be used to ask for a simple confirmation by
1034 presenting a text and 2 bottonts: Okay and Cancel.
1036 @example
1037   GET_CONFIRMATION @var{description}
1038 @end example
1040 @var{description}is displayed along with a Okay and Cancel
1041 button. Blanks must be percent escaped or replaced by @code{+}.  A
1042 @code{X} may be used to display confirmation dialog with a default
1043 text.
1045 The agent either returns with an error or with a OK.  Note, that the
1046 length of @var{description} is implicitly limited by the maximum
1047 length of a command.
1051 @node Agent HAVEKEY
1052 @subsection Check whether a key is available
1054 This can be used to see whether a secret key is available.  It does
1055 not return any information on whether the key is somehow protected.
1057 @example
1058   HAVEKEY @var{keygrip}
1059 @end example
1061 The Agent answers either with OK or @code{No_Secret_Key} (208).  The
1062 caller may want to check for other error codes as well.
1065 @node Agent LEARN
1066 @subsection Register a smartcard
1068 @example
1069   LEARN [--send]
1070 @end example
1072 This command is used to register a smartcard.  With the --send
1073 option given the certificates are send back.
1076 @node Agent PASSWD
1077 @subsection Change a Passphrase
1079 @example
1080   PASSWD @var{keygrip}
1081 @end example
1083 This command is used to interactively change the passphrase of the key
1084 indentified by the hex string @var{keygrip}.
1087 @node Agent UPDATESTARTUPTTY
1088 @subsection Change the standard display
1090 @example
1091   UPDATESTARTUPTTY
1092 @end example
1094 Set the startup TTY and X-DISPLAY variables to the values of this
1095 session.  This command is useful to direct future pinentry invocations
1096 to another screen.  It is only required because there is no way in the
1097 ssh-agent protocol to convey this information.
1100 @node Agent GETEVENTCOUNTER
1101 @subsection Get the Event Counters
1103 @example
1104   GETEVENTCOUNTER
1105 @end example
1107 This function return one status line with the current values of the
1108 event counters.  The event counters are useful to avoid polling by
1109 delaying a poll until something has changed.  The values are decimal
1110 numbers in the range @code{0} to @code{UINT_MAX} and wrapping around to
1111 0.  The actual values should not be relied upon; they shall only be used
1112 to detect a change.
1114 The currently defined counters are are:
1115 @table @code
1116 @item ANY
1117 Incremented with any change of any of the other counters.
1118 @item KEY
1119 Incremented for added or removed private keys.
1120 @item CARD
1121 Incremented for changes of the card readers stati.
1122 @end table
1125 @mansect see also
1126 @ifset isman
1127 @command{gpg2}(1), 
1128 @command{gpgsm}(1), 
1129 @command{gpg-connect-agent}(1),
1130 @command{scdaemon}(1)
1131 @end ifset
1132 @include see-also-note.texi