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 @c Note that we use this texinfo file for all versions of GnuPG:
6 @c 2.0 and 2.1. The macro "gpgtwoone" controls parts which are only
7 @c valid for GnuPG 2.1 and later.
10 @node Invoking GPG-AGENT
11 @chapter Invoking GPG-AGENT
12 @cindex GPG-AGENT command options
13 @cindex command options
14 @cindex options, GPG-AGENT command
19 \- Secret key management for GnuPG
50 @command{gpg-agent} is a daemon to manage secret (private) keys
51 independently from any protocol. It is used as a backend for
52 @command{gpg} and @command{gpgsm} as well as for a couple of other
56 The agent is usualy started on demand by @command{gpg}, @command{gpgsm},
57 @command{gpgconf} or @command{gpg-connect-agent}. Thus there is no
58 reason to start it manually. In case you want to use the included
59 Secure Shell Agent you may start the agent using:
62 gpg-connect-agent /bye
68 The usual way to run the agent is from the @code{~/.xsession} file:
71 eval $(gpg-agent --daemon)
74 If you don't use an X server, you can also put this into your regular
75 startup file @code{~/.profile} or @code{.bash_profile}. It is best not
76 to run multiple instance of the @command{gpg-agent}, so you should make
77 sure that only one is running: @command{gpg-agent} uses an environment
78 variable to inform clients about the communication parameters. You can
79 write the content of this environment variable to a file so that you can
80 test for a running agent. Here is an example using Bourne shell syntax:
83 gpg-agent --daemon --enable-ssh-support \
84 --write-env-file "$@{HOME@}/.gpg-agent-info"
87 This code should only be run once per user session to initially fire up
88 the agent. In the example the optional support for the included Secure
89 Shell agent is enabled and the information about the agent is written to
90 a file in the HOME directory. Note that by running gpg-agent without
91 arguments you may test whether an agent is already running; however such
92 a test may lead to a race condition, thus it is not suggested.
95 The second script needs to be run for each interactive session:
98 if [ -f "$@{HOME@}/.gpg-agent-info" ]; then
99 . "$@{HOME@}/.gpg-agent-info"
100 export GPG_AGENT_INFO
106 It reads the data out of the file and exports the variables. If you
107 don't use Secure Shell, you don't need the last two export statements.
111 You should always add the following lines to your @code{.bashrc} or
112 whatever initialization file is used for all shell invocations:
120 It is important that this environment variable always reflects the
121 output of the @code{tty} command. For W32 systems this option is not
124 Please make sure that a proper pinentry program has been installed
125 under the default filename (which is system dependant) or use the
126 option @option{pinentry-program} to specify the full name of that program.
127 It is often useful to install a symbolic link from the actual used
128 pinentry (e.g. @file{/usr/bin/pinentry-gtk}) to the expected
129 one (e.g. @file{/usr/bin/pinentry}).
133 @xref{Option Index},for an index to @command{GPG-AGENT}'s commands and options.
137 * Agent Commands:: List of all commands.
138 * Agent Options:: List of all options.
139 * Agent Configuration:: Configuration files.
140 * Agent Signals:: Use of some signals.
141 * Agent Examples:: Some usage examples.
142 * Agent Protocol:: The protocol the agent uses.
149 Commands are not distinguished from options except for the fact that
150 only one command is allowed.
155 Print the program version and licensing information. Note that you cannot
156 abbreviate this command.
161 Print a usage message summarizing the most useful command-line options.
162 Note that you cannot abbreviate this command.
165 @opindex dump-options
166 Print a list of all available options and commands. Note that you cannot
167 abbreviate this command.
171 Run in server mode and wait for commands on the @code{stdin}. The
172 default mode is to create a socket and listen for commands there.
174 @item --daemon [@var{command line}]
176 Start the gpg-agent as a daemon; that is, detach it from the console
177 and run it in the background. Because @command{gpg-agent} prints out
178 important information required for further use, a common way of
179 invoking gpg-agent is: @code{eval $(gpg-agent --daemon)} to setup the
180 environment variables. The option @option{--write-env-file} is
181 another way commonly used to do this. Yet another way is creating
182 a new process as a child of gpg-agent: @code{gpg-agent --daemon
183 /bin/sh}. This way you get a new shell with the environment setup
184 properly; if you exit from this shell, gpg-agent terminates as well.
189 @section Option Summary
193 @anchor{option --options}
194 @item --options @var{file}
196 Reads configuration from @var{file} instead of from the default
197 per-user configuration file. The default configuration file is named
198 @file{gpg-agent.conf} and expected in the @file{.gnupg} directory directly
199 below the home directory of the user.
201 @anchor{option --homedir}
202 @include opt-homedir.texi
208 Outputs additional information while running.
209 You can increase the verbosity by giving several
210 verbose commands to @command{gpgsm}, such as @samp{-vv}.
215 Try to be as quiet as possible.
219 Don't invoke a pinentry or do any other thing requiring human interaction.
221 @item --faked-system-time @var{epoch}
222 @opindex faked-system-time
223 This option is only useful for testing; it sets the system time back or
224 forth to @var{epoch} which is the number of seconds elapsed since the year
227 @item --debug-level @var{level}
229 Select the debug level for investigating problems. @var{level} may be
230 a numeric value or a keyword:
234 No debugging at all. A value of less than 1 may be used instead of
237 Some basic debug messages. A value between 1 and 2 may be used
238 instead of the keyword.
240 More verbose debug messages. A value between 3 and 5 may be used
241 instead of the keyword.
243 Even more detailed messages. A value between 6 and 8 may be used
244 instead of the keyword.
246 All of the debug messages you can get. A value greater than 8 may be
247 used instead of the keyword. The creation of hash tracing files is
248 only enabled if the keyword is used.
251 How these messages are mapped to the actual debugging flags is not
252 specified and may change with newer releases of this program. They are
253 however carefully selected to best aid in debugging.
255 @item --debug @var{flags}
257 This option is only useful for debugging and the behaviour may change at
258 any time without notice. FLAGS are bit encoded and may be given in
259 usual C-Syntax. The currently defined bits are:
263 X.509 or OpenPGP protocol related data
265 values of big number integers
267 low level crypto operations
273 show memory statistics.
275 write hashed data to files named @code{dbgmd-000*}
277 trace Assuan protocol
279 bypass all certificate validation
284 Same as @code{--debug=0xffffffff}
286 @item --debug-wait @var{n}
288 When running in server mode, wait @var{n} seconds before entering the
289 actual processing loop and print the pid. This gives time to attach a
294 Don't detach the process from the console. This is mainly useful for
303 Format the info output in daemon mode for use with the standard Bourne
304 shell or the C-shell respectively. The default is to guess it based on
305 the environment variable @code{SHELL} which is correct in almost all
308 @item --write-env-file @var{file}
309 @opindex write-env-file
310 Often it is required to connect to the agent from a process not being an
311 inferior of @command{gpg-agent} and thus the environment variable with
312 the socket name is not available. To help setting up those variables in
313 other sessions, this option may be used to write the information into
314 @var{file}. If @var{file} is not specified the default name
315 @file{$@{HOME@}/.gpg-agent-info} will be used. The format is suitable
316 to be evaluated by a Bourne shell like in this simple example:
319 eval $(cat @var{file})
320 eval $(cut -d= -f 1 < @var{file} | xargs echo export)
327 Tell the pinentry not to grab the keyboard and mouse. This option
328 should in general not be used to avoid X-sniffing attacks.
330 @anchor{option --log-file}
331 @item --log-file @var{file}
333 Append all logging output to @var{file}. This is very helpful in seeing
334 what the agent actually does. If neither a log file nor a log file
335 descriptor has been set on a Windows platform, the Registry entry
336 @code{HKCU\Software\GNU\GnuPG:DefaultLogFile}, if set, is used to specify
340 @anchor{option --allow-mark-trusted}
341 @item --allow-mark-trusted
342 @opindex allow-mark-trusted
343 Allow clients to mark keys as trusted, i.e. put them into the
344 @file{trustlist.txt} file. This is by default not allowed to make it
345 harder for users to inadvertently accept Root-CA keys.
348 @anchor{option --allow-loopback-pinentry}
349 @item --allow-loopback-pinentry
350 @opindex allow-loopback-pinentry
351 Allow clients to use the loopback pinentry features; see the option
352 @option{pinentry-mode} for details.
355 @item --ignore-cache-for-signing
356 @opindex ignore-cache-for-signing
357 This option will let @command{gpg-agent} bypass the passphrase cache for all
358 signing operation. Note that there is also a per-session option to
359 control this behaviour but this command line option takes precedence.
361 @item --default-cache-ttl @var{n}
362 @opindex default-cache-ttl
363 Set the time a cache entry is valid to @var{n} seconds. The default is
366 @item --default-cache-ttl-ssh @var{n}
367 @opindex default-cache-ttl
368 Set the time a cache entry used for SSH keys is valid to @var{n}
369 seconds. The default is 1800 seconds.
371 @item --max-cache-ttl @var{n}
372 @opindex max-cache-ttl
373 Set the maximum time a cache entry is valid to @var{n} seconds. After
374 this time a cache entry will be expired even if it has been accessed
375 recently or has been set using @command{gpg-preset-passphrase}. The
376 default is 2 hours (7200 seconds).
378 @item --max-cache-ttl-ssh @var{n}
379 @opindex max-cache-ttl-ssh
380 Set the maximum time a cache entry used for SSH keys is valid to
381 @var{n} seconds. After this time a cache entry will be expired even
382 if it has been accessed recently or has been set using
383 @command{gpg-preset-passphrase}. The default is 2 hours (7200
386 @item --enforce-passphrase-constraints
387 @opindex enforce-passphrase-constraints
388 Enforce the passphrase constraints by not allowing the user to bypass
389 them using the ``Take it anyway'' button.
391 @item --min-passphrase-len @var{n}
392 @opindex min-passphrase-len
393 Set the minimal length of a passphrase. When entering a new passphrase
394 shorter than this value a warning will be displayed. Defaults to 8.
396 @item --min-passphrase-nonalpha @var{n}
397 @opindex min-passphrase-nonalpha
398 Set the minimal number of digits or special characters required in a
399 passphrase. When entering a new passphrase with less than this number
400 of digits or special characters a warning will be displayed. Defaults
403 @item --check-passphrase-pattern @var{file}
404 @opindex check-passphrase-pattern
405 Check the passphrase against the pattern given in @var{file}. When
406 entering a new passphrase matching one of these pattern a warning will
407 be displayed. @var{file} should be an absolute filename. The default is
408 not to use any pattern file.
410 Security note: It is known that checking a passphrase against a list of
411 pattern or even against a complete dictionary is not very effective to
412 enforce good passphrases. Users will soon figure up ways to bypass such
413 a policy. A better policy is to educate users on good security
414 behavior and optionally to run a passphrase cracker regularly on all
415 users passphrases to catch the very simple ones.
417 @item --max-passphrase-days @var{n}
418 @opindex max-passphrase-days
419 Ask the user to change the passphrase if @var{n} days have passed since
420 the last change. With @option{--enforce-passphrase-constraints} set the
421 user may not bypass this check.
423 @item --enable-passphrase-history
424 @opindex enable-passphrase-history
425 This option does nothing yet.
427 @item --pinentry-program @var{filename}
428 @opindex pinentry-program
429 Use program @var{filename} as the PIN entry. The default is installation
432 @item --pinentry-touch-file @var{filename}
433 @opindex pinentry-touch-file
434 By default the filename of the socket gpg-agent is listening for
435 requests is passed to Pinentry, so that it can touch that file before
436 exiting (it does this only in curses mode). This option changes the
437 file passed to Pinentry to @var{filename}. The special name
438 @code{/dev/null} may be used to completely disable this feature. Note
439 that Pinentry will not create that file, it will only change the
440 modification and access time.
443 @item --scdaemon-program @var{filename}
444 @opindex scdaemon-program
445 Use program @var{filename} as the Smartcard daemon. The default is
446 installation dependent and can be shown with the @command{gpgconf}
449 @item --disable-scdaemon
450 @opindex disable-scdaemon
451 Do not make use of the scdaemon tool. This option has the effect of
452 disabling the ability to do smartcard operations. Note, that enabling
453 this option at runtime does not kill an already forked scdaemon.
456 @item --disable-check-own-socket
457 @opindex disable-check-own-socket
458 @command{gpg-agent} employs a periodic self-test to detect a stolen
459 socket. This usually means a second instance of @command{gpg-agent}
460 has taken over the socket and @command{gpg-agent} will then terminate
461 itself. This option may be used to disable this self-test for
465 @item --use-standard-socket
466 @itemx --no-use-standard-socket
467 @opindex use-standard-socket
468 @opindex no-use-standard-socket
469 By enabling this option @command{gpg-agent} will listen on the socket
470 named @file{S.gpg-agent}, located in the home directory, and not create
471 a random socket below a temporary directory. Tools connecting to
472 @command{gpg-agent} should first try to connect to the socket given in
473 environment variable @var{GPG_AGENT_INFO} and then fall back to this
474 socket. This option may not be used if the home directory is mounted on
475 a remote file system which does not support special files like fifos or
478 Note, that @option{--use-standard-socket} is the default on all
479 systems since GnuPG 2.1.
482 Note, that @option{--use-standard-socket} is the default on
485 The default may be changed at build time. It is
486 possible to test at runtime whether the agent has been configured for
487 use with the standard socket by issuing the command @command{gpg-agent
488 --use-standard-socket-p} which returns success if the standard socket
489 option has been enabled.
491 @item --display @var{string}
492 @itemx --ttyname @var{string}
493 @itemx --ttytype @var{string}
494 @itemx --lc-ctype @var{string}
495 @itemx --lc-messages @var{string}
496 @itemx --xauthority @var{string}
503 These options are used with the server mode to pass localization
507 @itemx --keep-display
509 @opindex keep-display
510 Ignore requests to change the current @code{tty} or X window system's
511 @code{DISPLAY} variable respectively. This is useful to lock the
512 pinentry to pop up at the @code{tty} or display you started the agent.
514 @anchor{option --enable-ssh-support}
515 @item --enable-ssh-support
516 @opindex enable-ssh-support
518 Enable the OpenSSH Agent protocol.
520 In this mode of operation, the agent does not only implement the
521 gpg-agent protocol, but also the agent protocol used by OpenSSH
522 (through a separate socket). Consequently, it should be possible to use
523 the gpg-agent as a drop-in replacement for the well known ssh-agent.
525 SSH Keys, which are to be used through the agent, need to be added to
526 the gpg-agent initially through the ssh-add utility. When a key is
527 added, ssh-add will ask for the password of the provided key file and
528 send the unprotected key material to the agent; this causes the
529 gpg-agent to ask for a passphrase, which is to be used for encrypting
530 the newly received key and storing it in a gpg-agent specific
533 Once a key has been added to the gpg-agent this way, the gpg-agent
534 will be ready to use the key.
536 Note: in case the gpg-agent receives a signature request, the user might
537 need to be prompted for a passphrase, which is necessary for decrypting
538 the stored key. Since the ssh-agent protocol does not contain a
539 mechanism for telling the agent on which display/terminal it is running,
540 gpg-agent's ssh-support will use the TTY or X display where gpg-agent
541 has been started. To switch this display to the current one, the
542 following command may be used:
545 gpg-connect-agent updatestartuptty /bye
548 Although all GnuPG components try to start the gpg-agent as needed, this
549 is not possible for the ssh support because ssh does not know about it.
550 Thus if no GnuPG tool which accesses the agent has been run, there is no
551 guarantee that ssh is abale to use gpg-agent for authentication. To fix
552 this you may start gpg-agent if needed using this simple command:
555 gpg-connect-agent /bye
558 Adding the @option{--verbose} shows the progress of starting the agent.
562 All the long options may also be given in the configuration file after
563 stripping off the two leading dashes.
567 @node Agent Configuration
568 @section Configuration
570 There are a few configuration files needed for the operation of the
571 agent. By default they may all be found in the current home directory
572 (@pxref{option --homedir}).
577 @cindex gpg-agent.conf
578 This is the standard configuration file read by @command{gpg-agent} on
579 startup. It may contain any valid long option; the leading
580 two dashes may not be entered and the option may not be abbreviated.
581 This file is also read after a @code{SIGHUP} however only a few
582 options will actually have an effect. This default name may be
583 changed on the command line (@pxref{option --options}).
584 You should backup this file.
587 This is the list of trusted keys. You should backup this file.
589 Comment lines, indicated by a leading hash mark, as well as empty
590 lines are ignored. To mark a key as trusted you need to enter its
591 fingerprint followed by a space and a capital letter @code{S}. Colons
592 may optionally be used to separate the bytes of a fingerprint; this
593 allows to cut and paste the fingerprint from a key listing output. If
594 the line is prefixed with a @code{!} the key is explicitly marked as
597 Here is an example where two keys are marked as ultimately trusted
598 and one as not trusted:
601 # CN=Wurzel ZS 3,O=Intevation GmbH,C=DE
602 A6935DD34EF3087973C706FC311AA2CCF733765B S
604 # CN=PCA-1-Verwaltung-02/O=PKI-1-Verwaltung/C=DE
605 DC:BD:69:25:48:BD:BB:7E:31:6E:BB:80:D3:00:80:35:D4:F8:A6:CD S
607 # CN=Root-CA/O=Schlapphuete/L=Pullach/C=DE
608 !14:56:98:D3:FE:9C:CA:5A:31:6E:BC:81:D3:11:4E:00:90:A3:44:C2 S
611 Before entering a key into this file, you need to ensure its
612 authenticity. How to do this depends on your organisation; your
613 administrator might have already entered those keys which are deemed
614 trustworthy enough into this file. Places where to look for the
615 fingerprint of a root certificate are letters received from the CA or
616 the website of the CA (after making 100% sure that this is indeed the
617 website of that CA). You may want to consider allowing interactive
618 updates of this file by using the @xref{option --allow-mark-trusted}.
619 This is however not as secure as maintaining this file manually. It is
620 even advisable to change the permissions to read-only so that this file
621 can't be changed inadvertently.
623 As a special feature a line @code{include-default} will include a global
624 list of trusted certificates (e.g. @file{/etc/gnupg/trustlist.txt}).
625 This global list is also used if the local list is not available.
627 It is possible to add further flags after the @code{S} for use by the
634 Relax checking of some root certificate requirements. As of now this
635 flag allows the use of root certificates with a missing basicConstraints
636 attribute (despite that it is a MUST for CA certificates) and disables
637 CRL checking for the root certificate.
640 If validation of a certificate finally issued by a CA with this flag set
641 fails, try again using the chain validation model.
648 This file is used when support for the secure shell agent protocol has
649 been enabled (@pxref{option --enable-ssh-support}). Only keys present in
650 this file are used in the SSH protocol. You should backup this file.
652 The @command{ssh-add} tool may be used to add new entries to this file;
653 you may also add them manually. Comment lines, indicated by a leading
654 hash mark, as well as empty lines are ignored. An entry starts with
655 optional whitespace, followed by the keygrip of the key given as 40 hex
656 digits, optionally followed by the caching TTL in seconds and another
657 optional field for arbitrary flags. A non-zero TTL overrides the global
658 default as set by @option{--default-cache-ttl-ssh}.
660 The only flag support is @code{confirm}. If this flag is found for a
661 key, each use of the key will pop up a pinentry to confirm the use of
662 that key. The flag is automatically set if a new key was loaded into
663 @code{gpg-agent} using the option @option{-c} of the @code{ssh-add}
666 The keygrip may be prefixed with a @code{!} to disable an entry entry.
668 The following example lists exactly one key. Note that keys available
669 through a OpenPGP smartcard in the active smartcard reader are
670 implicitly added to this list; i.e. there is no need to list them.
673 # Key added on: 2011-07-20 20:38:46
674 # Fingerprint: 5e:8d:c4:ad:e7:af:6e:27:8a:d6:13:e4:79:ad:0b:81
675 34B62F25E277CF13D3C6BCEBFD3F85D08F0A864B 0 confirm
678 @item private-keys-v1.d/
680 This is the directory where gpg-agent stores the private keys. Each
681 key is stored in a file with the name made up of the keygrip and the
682 suffix @file{key}. You should backup all files in this directory
683 and take great care to keep this backup closed away.
688 Note that on larger installations, it is useful to put predefined
689 files into the directory @file{/etc/skel/.gnupg/} so that newly created
690 users start up with a working configuration. For existing users the
691 a small helper script is provided to create these files (@pxref{addgnupghome}).
700 @section Use of some signals.
701 A running @command{gpg-agent} may be controlled by signals, i.e. using
702 the @command{kill} command to send a signal to the process.
704 Here is a list of supported signals:
710 This signal flushes all cached passphrases and if the program has been
711 started with a configuration file, the configuration file is read
712 again. Only certain options are honored: @code{quiet},
713 @code{verbose}, @code{debug}, @code{debug-all}, @code{debug-level},
714 @code{no-grab}, @code{pinentry-program}, @code{default-cache-ttl},
715 @code{max-cache-ttl}, @code{ignore-cache-for-signing},
716 @code{allow-mark-trusted}, @code{disable-scdaemon}, and
717 @code{disable-check-own-socket}. @code{scdaemon-program} is also
718 supported but due to the current implementation, which calls the
719 scdaemon only once, it is not of much use unless you manually kill the
725 Shuts down the process but waits until all current requests are
726 fulfilled. If the process has received 3 of these signals and requests
727 are still pending, a shutdown is forced.
731 Shuts down the process immediately.
735 Dump internal information to the log file.
739 This signal is used for internal purposes.
750 The usual way to invoke @command{gpg-agent} is
753 $ eval $(gpg-agent --daemon)
756 An alternative way is by replacing @command{ssh-agent} with
757 @command{gpg-agent}. If for example @command{ssh-agent} is started as
758 part of the Xsession initialization, you may simply replace
759 @command{ssh-agent} by a script like:
765 exec /usr/local/bin/gpg-agent --enable-ssh-support --daemon \
766 --write-env-file $@{HOME@}/.gpg-agent-info "$@@"
771 and add something like (for Bourne shells)
775 if [ -f "$@{HOME@}/.gpg-agent-info" ]; then
776 . "$@{HOME@}/.gpg-agent-info"
777 export GPG_AGENT_INFO
784 to your shell initialization file (e.g. @file{~/.bashrc}).
791 @section Agent's Assuan Protocol
793 Note: this section does only document the protocol, which is used by
794 GnuPG components; it does not deal with the ssh-agent protocol.
796 The @command{gpg-agent} should be started by the login shell and set an
797 environment variable to tell clients about the socket to be used.
798 Clients should deny to access an agent with a socket name which does
799 not match its own configuration. An application may choose to start
800 an instance of the gpgagent if it does not figure that any has been
801 started; it should not do this if a gpgagent is running but not
802 usable. Because @command{gpg-agent} can only be used in background mode, no
803 special command line option is required to activate the use of the
806 To identify a key we use a thing called keygrip which is the SHA-1 hash
807 of an canonical encoded S-Expression of the public key as used in
808 Libgcrypt. For the purpose of this interface the keygrip is given as a
809 hex string. The advantage of using this and not the hash of a
810 certificate is that it will be possible to use the same keypair for
811 different protocols, thereby saving space on the token used to keep the
815 The @command{gpg-agent} may send status messages during a command or when
816 returning from a command to inform a client about the progress or result of an
817 operation. For example, the @var{INQUIRE_MAXLEN} status message may be sent
818 during a server inquire to inform the client of the maximum usable length of
819 the inquired data (which should not be exceeded).
823 * Agent PKDECRYPT:: Decrypting a session key
824 * Agent PKSIGN:: Signing a Hash
825 * Agent GENKEY:: Generating a Key
826 * Agent IMPORT:: Importing a Secret Key
827 * Agent EXPORT:: Exporting a Secret Key
828 * Agent ISTRUSTED:: Importing a Root Certificate
829 * Agent GET_PASSPHRASE:: Ask for a passphrase
830 * Agent CLEAR_PASSPHRASE:: Expire a cached passphrase
832 * Agent PRESET_PASSPHRASE:: Set a passphrase for a keygrip
834 * Agent GET_CONFIRMATION:: Ask for confirmation
835 * Agent HAVEKEY:: Check whether a key is available
836 * Agent LEARN:: Register a smartcard
837 * Agent PASSWD:: Change a Passphrase
838 * Agent UPDATESTARTUPTTY:: Change the Standard Display
839 * Agent GETEVENTCOUNTER:: Get the Event Counters
840 * Agent GETINFO:: Return information about the process
841 * Agent OPTION:: Set options for the session
844 @node Agent PKDECRYPT
845 @subsection Decrypting a session key
847 The client asks the server to decrypt a session key. The encrypted
848 session key should have all information needed to select the
849 appropriate secret key or to delegate it to a smartcard.
855 Tell the server about the key to be used for decryption. If this is
856 not used, @command{gpg-agent} may try to figure out the key by trying to
857 decrypt the message with each key available.
863 The agent checks whether this command is allowed and then does an
864 INQUIRY to get the ciphertext the client should then send the cipher
868 S: INQUIRE CIPHERTEXT
874 Please note that the server may send status info lines while reading the
875 data lines from the client. The data send is a SPKI like S-Exp with
881 (<param_name1> <mpi>)
883 (<param_namen> <mpi>)))
886 Where algo is a string with the name of the algorithm; see the libgcrypt
887 documentation for a list of valid algorithms. The number and names of
888 the parameters depend on the algorithm. The agent does return an error
889 if there is an inconsistency.
891 If the decryption was successful the decrypted data is returned by
894 Here is an example session:
898 S: INQUIRE CIPHERTEXT
899 C: D (enc-val elg (a 349324324)
900 C: D (b 3F444677CA)))
902 S: # session key follows
904 S: D (value 1234567890ABCDEF0)
905 S: OK descryption successful
908 The “PADDING” status line is only send if gpg-agent can tell what kind
909 of padding is used. As of now only the value 0 is used to indicate
910 that the padding has been removed.
914 @subsection Signing a Hash
916 The client ask the agent to sign a given hash value. A default key
917 will be chosen if no key has been set. To set a key a client first
924 This can be used multiple times to create multiple signature, the list
925 of keys is reset with the next PKSIGN command or a RESET. The server
926 test whether the key is a valid key to sign something and responds with
930 SETHASH --hash=<name>|<algo> <hexstring>
933 The client can use this command to tell the server about the data <hexstring>
934 (which usually is a hash) to be signed. <algo> is the decimal encoded hash
935 algorithm number as used by Libgcrypt. Either <algo> or --hash=<name>
936 must be given. Valid names for <name> are:
947 The actual signing is done using
953 Options are not yet defined, but my later be used to choose among
954 different algorithms. The agent does then some checks, asks for the
955 passphrase and as a result the server returns the signature as an SPKI
956 like S-expression in "D" lines:
961 (<param_name1> <mpi>)
963 (<param_namen> <mpi>)))
967 The operation is affected by the option
970 OPTION use-cache-for-signing=0|1
973 The default of @code{1} uses the cache. Setting this option to @code{0}
974 will lead @command{gpg-agent} to ignore the passphrase cache. Note, that there is
975 also a global command line option for @command{gpg-agent} to globally disable the
979 Here is an example session:
987 S: # I did ask the user whether he really wants to sign
988 S: # I did ask the user for the passphrase
990 C: D ABCDEF012345678901234
992 S: # signature follows
993 S: D (sig-val rsa (s 45435453654612121212))
999 @subsection Generating a Key
1001 This is used to create a new keypair and store the secret key inside the
1002 active PSE --- which is in most cases a Soft-PSE. An not yet defined
1003 option allows to choose the storage location. To get the secret key out
1004 of the PSE, a special export tool has to be used.
1008 GENKEY [--no-protection] [--preset] [<cache_nonce>]
1015 Invokes the key generation process and the server will then inquire
1016 on the generation parameters, like:
1020 C: D (genkey (rsa (nbits 1024)))
1024 The format of the key parameters which depends on the algorithm is of
1030 (parameter_name_1 ....)
1032 (parameter_name_n ....)))
1035 If everything succeeds, the server returns the *public key* in a SPKI
1036 like S-Expression like this:
1045 Here is an example session:
1050 C: D (genkey (rsa (nbits 1024)))
1053 S: D (rsa (n 326487324683264) (e 10001)))
1058 The @option{--no-protection} option may be used to prevent prompting for a
1059 passphrase to protect the secret key while leaving the secret key unprotected.
1060 The @option{--preset} option may be used to add the passphrase to the cache
1061 using the default cache parameters.
1065 @subsection Importing a Secret Key
1067 This operation is not yet supported by GpgAgent. Specialized tools
1068 are to be used for this.
1070 There is no actual need because we can expect that secret keys
1071 created by a 3rd party are stored on a smartcard. If we have
1072 generated the key ourself, we do not need to import it.
1075 @subsection Export a Secret Key
1079 Should be done by an extra tool.
1081 @node Agent ISTRUSTED
1082 @subsection Importing a Root Certificate
1084 Actually we do not import a Root Cert but provide a way to validate
1085 any piece of data by storing its Hash along with a description and
1086 an identifier in the PSE. Here is the interface description:
1089 ISTRUSTED <fingerprint>
1092 Check whether the OpenPGP primary key or the X.509 certificate with the
1093 given fingerprint is an ultimately trusted key or a trusted Root CA
1094 certificate. The fingerprint should be given as a hexstring (without
1095 any blanks or colons or whatever in between) and may be left padded with
1096 00 in case of an MD5 fingerprint. GPGAgent will answer with:
1102 The key is in the table of trusted keys.
1105 ERR 304 (Not Trusted)
1108 The key is not in this table.
1110 Gpg needs the entire list of trusted keys to maintain the web of
1111 trust; the following command is therefore quite helpful:
1117 GpgAgent returns a list of trusted keys line by line:
1120 S: D 000000001234454556565656677878AF2F1ECCFF P
1121 S: D 340387563485634856435645634856438576457A P
1122 S: D FEDC6532453745367FD83474357495743757435D S
1126 The first item on a line is the hexified fingerprint where MD5
1127 fingerprints are @code{00} padded to the left and the second item is a
1128 flag to indicate the type of key (so that gpg is able to only take care
1129 of PGP keys). P = OpenPGP, S = S/MIME. A client should ignore the rest
1130 of the line, so that we can extend the format in the future.
1132 Finally a client should be able to mark a key as trusted:
1135 MARKTRUSTED @var{fingerprint} "P"|"S"
1138 The server will then pop up a window to ask the user whether she
1139 really trusts this key. For this it will probably ask for a text to
1140 be displayed like this:
1143 S: INQUIRE TRUSTDESC
1144 C: D Do you trust the key with the fingerprint @@FPR@@
1145 C: D bla fasel blurb.
1150 Known sequences with the pattern @@foo@@ are replaced according to this
1155 Format the fingerprint according to gpg rules for a v3 keys.
1157 Format the fingerprint according to gpg rules for a v4 keys.
1159 Choose an appropriate format to format the fingerprint.
1161 Replaced by a single @code{@@}
1164 @node Agent GET_PASSPHRASE
1165 @subsection Ask for a passphrase
1167 This function is usually used to ask for a passphrase to be used for
1168 conventional encryption, but may also be used by programs which need
1169 special handling of passphrases. This command uses a syntax which helps
1170 clients to use the agent with minimum effort.
1173 GET_PASSPHRASE [--data] [--check] [--no-ask] [--repeat[=N]] [--qualitybar] @var{cache_id} [@var{error_message} @var{prompt} @var{description}]
1176 @var{cache_id} is expected to be a string used to identify a cached
1177 passphrase. Use a @code{X} to bypass the cache. With no other
1178 arguments the agent returns a cached passphrase or an error. By
1179 convention either the hexified fingerprint of the key shall be used for
1180 @var{cache_id} or an arbitrary string prefixed with the name of the
1181 calling application and a colon: Like @code{gpg:somestring}.
1183 @var{error_message} is either a single @code{X} for no error message or
1184 a string to be shown as an error message like (e.g. "invalid
1185 passphrase"). Blanks must be percent escaped or replaced by @code{+}'.
1187 @var{prompt} is either a single @code{X} for a default prompt or the
1188 text to be shown as the prompt. Blanks must be percent escaped or
1189 replaced by @code{+}.
1191 @var{description} is a text shown above the entry field. Blanks must be
1192 percent escaped or replaced by @code{+}.
1194 The agent either returns with an error or with a OK followed by the hex
1195 encoded passphrase. Note that the length of the strings is implicitly
1196 limited by the maximum length of a command. If the option
1197 @option{--data} is used, the passphrase is not returned on the OK line
1198 but by regular data lines; this is the preferred method.
1200 If the option @option{--check} is used, the standard passphrase
1201 constraints checks are applied. A check is not done if the passphrase
1202 has been found in the cache.
1204 If the option @option{--no-ask} is used and the passphrase is not in the
1205 cache the user will not be asked to enter a passphrase but the error
1206 code @code{GPG_ERR_NO_DATA} is returned.
1208 If the option @option{--qualitybar} is used and a minimum passphrase
1209 length has been configured, a visual indication of the entered
1210 passphrase quality is shown.
1213 CLEAR_PASSPHRASE @var{cache_id}
1216 may be used to invalidate the cache entry for a passphrase. The
1217 function returns with OK even when there is no cached passphrase.
1221 @node Agent CLEAR_PASSPHRASE
1222 @subsection Remove a cached passphrase
1224 Use this command to remove a cached passphrase.
1228 CLEAR_PASSPHRASE [--mode=normal] <cache_id>
1231 CLEAR_PASSPHRASE <cache_id>
1236 The @option{--mode=normal} option can be used to clear a @var{cache_id} that
1237 was set by gpg-agent.
1243 @node Agent PRESET_PASSPHRASE
1244 @subsection Set a passphrase for a keygrip
1246 This command adds a passphrase to the cache for the specified @var{keygrip}.
1249 PRESET_PASSPHRASE [--inquire] <string_or_keygrip> <timeout> [<hexstring>]
1252 The passphrase is a hexidecimal string when specified. When not specified, the
1253 passphrase will be retrieved from the pinentry module unless the
1254 @option{--inquire} option was specified in which case the passphrase will be
1255 retrieved from the client.
1257 The @var{timeout} parameter keeps the passphrase cached for the specified
1258 number of seconds. A value of @code{-1} means infinate while @code{0} means
1259 the default (currently only a timeout of -1 is allowed, which means to never
1266 @node Agent GET_CONFIRMATION
1267 @subsection Ask for confirmation
1269 This command may be used to ask for a simple confirmation by
1270 presenting a text and 2 buttons: Okay and Cancel.
1273 GET_CONFIRMATION @var{description}
1276 @var{description}is displayed along with a Okay and Cancel
1277 button. Blanks must be percent escaped or replaced by @code{+}. A
1278 @code{X} may be used to display confirmation dialog with a default
1281 The agent either returns with an error or with a OK. Note, that the
1282 length of @var{description} is implicitly limited by the maximum
1283 length of a command.
1288 @subsection Check whether a key is available
1290 This can be used to see whether a secret key is available. It does
1291 not return any information on whether the key is somehow protected.
1294 HAVEKEY @var{keygrips}
1297 The agent answers either with OK or @code{No_Secret_Key} (208). The
1298 caller may want to check for other error codes as well. More than one
1299 keygrip may be given. In this case the command returns success if at
1300 least one of the keygrips corresponds to an available secret key.
1304 @subsection Register a smartcard
1310 This command is used to register a smartcard. With the --send
1311 option given the certificates are send back.
1315 @subsection Change a Passphrase
1319 PASSWD [--cache-nonce=<c>] [--passwd-nonce=<s>] [--preset] @var{keygrip}
1322 PASSWD @var{keygrip}
1326 This command is used to interactively change the passphrase of the key
1327 identified by the hex string @var{keygrip}.
1330 The @option{--preset} option may be used to add the new passphrase to the
1331 cache using the default cache parameters.
1335 @node Agent UPDATESTARTUPTTY
1336 @subsection Change the standard display
1342 Set the startup TTY and X-DISPLAY variables to the values of this
1343 session. This command is useful to direct future pinentry invocations
1344 to another screen. It is only required because there is no way in the
1345 ssh-agent protocol to convey this information.
1348 @node Agent GETEVENTCOUNTER
1349 @subsection Get the Event Counters
1355 This function return one status line with the current values of the
1356 event counters. The event counters are useful to avoid polling by
1357 delaying a poll until something has changed. The values are decimal
1358 numbers in the range @code{0} to @code{UINT_MAX} and wrapping around to
1359 0. The actual values should not be relied upon; they shall only be used
1362 The currently defined counters are are:
1365 Incremented with any change of any of the other counters.
1367 Incremented for added or removed private keys.
1369 Incremented for changes of the card readers stati.
1373 @subsection Return information about the process
1375 This is a multipurpose function to return a variety of information.
1381 The value of @var{what} specifies the kind of information returned:
1384 Return the version of the program.
1386 Return the process id of the process.
1388 Return the name of the socket used to connect the agent.
1389 @item ssh_socket_name
1390 Return the name of the socket used for SSH connections. If SSH support
1391 has not been enabled the error @code{GPG_ERR_NO_DATA} will be returned.
1395 @subsection Set options for the session
1397 Here is a list of session options which are not yet described with
1398 other commands. The general syntax for an Assuan option is:
1401 OPTION @var{key}=@var{value}
1405 Supported @var{key}s are:
1408 @item agent-awareness
1409 This may be used to tell gpg-agent of which gpg-agent version the
1410 client is aware of. gpg-agent uses this information to enable
1411 features which might break older clients.
1414 Change the session's environment to be used for the
1415 Pinentry. Valid values are:
1419 Delete envvar @var{name}
1421 Set envvar @var{name} to the empty string
1422 @item @var{name}=@var{value}
1423 Set envvar @var{name} to the string @var{value}.
1426 @item use-cache-for-signing
1427 See Assuan command @code{PKSIGN}.
1429 @item allow-pinentry-notify
1430 This does not need any value. It is used to enable the
1431 PINENTRY_LAUNCHED inquiry.
1435 This option is used to change the operation mode of the pinentry. The
1436 following values are defined:
1440 This is the default mode which pops up a pinentry as needed.
1443 Instead of popping up a pinentry, return the error code
1444 @code{GPG_ERR_CANCELED}.
1447 Instead of popping up a pinentry, return the error code
1448 @code{GPG_ERR_NO_PIN_ENTRY}.
1451 Use a loopback pinentry. This fakes a pinentry by using inquiries
1452 back to the caller to ask for a passphrase. This option may only be
1453 set if the agent has been configured for that.
1454 Use the @xref{option --allow-loopback-pinentry}.
1460 @item cache-ttl-opt-preset
1461 This option sets the cache TTL for new entries created by GENKEY and
1462 PASSWD commands when using the @option{--preset} option. It it is not
1463 used a default value is used.
1468 Instead of using the standard S2K count (which is computed on the
1469 fly), the given S2K count is used for new keys or when changing the
1470 passphrase of a key. Values below 65536 are considered to be 0. This
1471 option is valid for the entire session or until reset to 0. This
1472 option is useful if the key is later used on boxes which are either
1473 much slower or faster than the actual box.
1483 @command{gpg-connect-agent}(1),
1484 @command{scdaemon}(1)
1486 @include see-also-note.texi