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
@c man begin DESCRIPTION
13
@command{gpg-agent} is a daemon to manage secret (private) keys
14
independelty from any protocol. It is used as a backend for
15
@command{gpg} and @command{gpgsm} as well as for a couple of other
19
The usual way to run the agent is from the @code{~/.xsession} file:
22
eval `gpg-agent --daemon`
26
If you don't use an X server, you can also put this into your regular
27
startup file @code{~/.profile} or @code{.bash_profile}. It is best not
28
to run multiple instance of the @command{gpg-agent}, so you should make sure that
29
only is running: @command{gpg-agent} uses an environment variable to inform
30
clients about the communication parameters. You can write the
31
content of this environment variable to a file so that you can test for
32
a running agent. This short script may do the job:
35
if test -f $HOME/.gpg-agent-info && \
36
kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null; then
37
GPG_AGENT_INFO=`cat $HOME/.gpg-agent-info`
40
eval `gpg-agent --daemon`
41
echo $GPG_AGENT_INFO >$HOME/.gpg-agent-info
46
You should always add the following lines to your @code{.bashrc} or
47
whatever initialization file is used for all shell invocations:
55
It is important that this environment variable always reflects the
56
output of the @code{tty} command. For W32 systems this option is not
59
Please make sure that a proper pinentry program has been installed
60
under the default filename (which is system dependant) or use the
61
option @code{pinentry-pgm} to specify the full name of that program.
62
It is often useful to install a symbolic link from the actual used
63
pinentry (e.g. @file{/usr/bin/pinentry-gtk}) to the expected
64
one (e.g. @file{/usr/bin/pinentry}).
69
@xref{Option Index}, for an index to @command{GPG-AGENT}'s commands and options.
72
* Agent Commands:: List of all commands.
73
* Agent Options:: List of all options.
74
* Agent Signals:: Use of some signals.
75
* Agent Examples:: Some usage examples.
76
* Agent Protocol:: The protocol the agent uses.
84
Commands are not distinguished from options execpt for the fact that
85
only one one command is allowed.
90
Print the program version and licensing information. Not that you can
91
abbreviate this command.
95
Print a usage message summarizing the most usefule command-line options.
96
Not that you can abbreviate this command.
100
Print a list of all available options and commands. Not that you can
101
abbreviate this command.
105
Run in server mode and wait for commands on the @code{stdin}. The
106
default mode is to create a socket and listen for commands there.
110
Run the program in the background. This option is required to prevent
111
it from being accidently running in the background. A common way to do
115
$ eval `gpg-agent --daemon`
122
@section Option Summary
126
@item --options @var{file}
128
Reads configuration from @var{file} instead of from the default
129
per-user configuration file. The default configuration file is named
130
@file{gpg-agent.conf} and expected in the @file{.gnupg} directory directly
131
below the home directory of the user.
133
@item --homedir @var{dir}
135
Set the name of the home directory to @var{dir}. If his option is not
136
used, the home directory defaults to @file{~/.gnupg}. It is only
137
recognized when given on the command line. It also overrides any home
138
directory stated through the environment variable @env{GNUPGHOME} or
139
(on W32 systems) by means on the Registry entry
140
@var{HKCU\Software\GNU\GnuPG:HomeDir}.
146
Outputs additional information while running.
147
You can increase the verbosity by giving several
148
verbose commands to @sc{gpgsm}, such as @samp{-vv}.
154
Try to be as quiet as possible.
158
Don't invoke a pinentry or do any other thing requiring human interaction.
160
@item --faked-system-time @var{epoch}
161
@opindex faked-system-time
162
This option is only useful for testing; it sets the system time back or
163
forth to @var{epoch} which is the number of seconds elapsed since the year
166
@item --debug-level @var{level}
168
Select the debug level for investigating problems. @var{level} may be
175
some basic debug messages
177
more verbose debug messages
179
even more detailed messages
181
all of the debug messages you can get
184
How these messages are mapped to the actual debugging flags is not
185
specified and may change with newer releaes of this program. They are
186
however carefully selected to best aid in debugging.
188
@item --debug @var{flags}
190
This option is only useful for debugging and the behaviour may change at
191
any time without notice. FLAGS are bit encoded and may be given in
192
usual C-Syntax. The currently defined bits are:
196
X.509 or OpenPGP protocol related data
198
values of big number integers
200
low level crypto operations
206
show memory statistics.
208
write hashed data to files named @code{dbgmd-000*}
210
trace Assuan protocol
212
bypass all certificate validation
217
Same as @code{--debug=0xffffffff}
219
@item --debug-wait @var{n}
221
When running in server mode, wait @var{n} seconds before entering the
222
actual processing loop and print the pid. This gives time to attach a
227
Don't detach the process from the console. This is manly usefule for
238
Format the info output in daemon mode for use with the standard Bourne
239
shell respective the C-shell . The default ist to guess it based on the
240
environment variable @code{SHELL} which is in almost all cases
245
Tell the pinentryo not to grab the keyboard and mouse. This option
246
should in general not be used to avaoid X-sniffing attacks.
248
@item --log-file @var{file}
250
Append all logging output to @var{file}. This is very helpful in
251
seeing what the agent actually does.
255
Don't allow multiple connections. This option is in general not very
258
@item --allow-mark-trusted
259
@opindex allow-mark-trusted
260
Allow clients to mark keys as trusted, i.e. put them into the
261
@code{trustlist.txt} file. This is by default not allowed to make it
262
harder for users to inadvertly accept Root-CA keys.
264
@item --ignore-cache-for-signing
265
@opindex ignore-cache-for-signing
266
This option will let @command{gpg-agent} bypass the passphrase cache for all
267
signing operation. Note that there is also a per-session option to
268
control this behaviour but this command line option takes precedence.
270
@item --default-cache-ttl @var{n}
271
@opindex default-cache-ttl
272
Set the time a cache entry is valid to @var{n} seconds. The default are
275
@item --max-cache-ttl @var{n}
276
@opindex max-cache-ttl
277
Set the maximum time a cache entry is valid to @var{n} seconds. After
278
this time a cache entry will get expired even if it has been accessed
279
recently. The default are 2 hours (7200 seconds).
281
@item --pinentry-program @var{filename}
282
@opindex pinentry-program
283
Use program @var{filename} as the PIN entry. The default is installation
284
dependend and can be shown with the @code{--version} command.
286
@item --scdaemon-program @var{filename}
287
@opindex scdaemon-program
288
Use program @var{filename} as the Smartcard daemon. The default is
289
installation dependend and can be shown with the @code{--version}
292
@item --use-standard-socket
293
@itemx --no-use-standard-socket
294
@opindex use-standard-socket
295
@opindex no-use-standard-socket
296
By enabling this option @command{gpg-agent} will listen on the socket
297
named @file{S.gpg-agent}, located in the home directory, and not create
298
a random socket below a temporary directory. Tools connecting to
299
@command{gpg-agent} should first try to connect to the socket given in
300
environment variable @var{GPG_AGENT_INFO} and the fall back to this
301
socket. This option may not be used if the home directory is mounted as
302
a remote file system.
305
Note, that as of now, W32 systems default to this option.
308
@item --display @var{string}
309
@itemx --ttyname @var{string}
310
@itemx --ttytype @var{string}
311
@itemx --lc-type @var{string}
312
@itemx --lc-messages @var{string}
318
These options are used with the server mode to pass localization
322
@itemx --keep-display
324
@opindex keep-display
325
Ignore requests to change change the current @sc{tty} respective the X
326
window system's @code{DISPLAY} variable. This is useful to lock the
327
pinentry to pop up at the @sc{tty} or display you started the agent.
332
All the long options may also be given in the configuration file after
333
stripping off the two leading dashes.
339
@section Use of some signals.
340
A running @command{gpg-agent} may be controlled by signals, i.e. using
341
the @command{kill} command to send a signal to the process.
343
Here is a list of supported signals:
349
This signals flushes all chached passphrases and when the program was
350
started with a configuration file, the configuration file is read again.
351
Only certain options are honored: @code{quiet}, @code{verbose},
352
@code{debug}, @code{debug-all}, @code{no-grab}, @code{pinentry-program},
353
@code{default-cache-ttl} and @code{ignore-cache-for-signing}.
354
@code{scdaemon-program} is also supported but due to the current
355
implementation, which calls the scdaemon only once, it is not of much
361
Shuts down the process but waits until all current requests are
362
fulfilled. If the process has received 3 of these signals and requests
363
are still pending, a shutdown is forced.
367
Shuts down the process immediately.
374
These signals are used for internal purposes.
384
@c man begin EXAMPLES
387
$ eval `gpg-agent --daemon`
397
@section Agent's Assuan Protocol
399
The @command{gpg-agent} should be started by the login shell and set an
400
environment variable to tell clients about the socket to be used.
401
Clients should deny to access an agent with a socket name which does
402
not match its own configuration. An application may choose to start
403
an instance of the gpgagent if it does not figure that any has been
404
started; it should not do this if a gpgagent is running but not
405
usable. Because @command{gpg-agent} can only be used in background mode, no
406
special command line option is required to activate the use of the
409
To identify a key we use a thing called keygrip which is the SHA-1 hash
410
of an canoncical encoded S-Expression of the the public key as used in
411
Libgcrypt. For the purpose of this interface the keygrip is given as a
412
hex string. The advantage of using this and not the hash of a
413
certificate is that it will be possible to use the same keypair for
414
different protocols, thereby saving space on the token used to keep the
418
* Agent PKDECRYPT:: Decrypting a session key
419
* Agent PKSIGN:: Signing a Hash
420
* Agent GENKEY:: Generating a Key
421
* Agent IMPORT:: Importing a Secret Key
422
* Agent EXPORT:: Exporting a Secret Key
423
* Agent ISTRUSTED:: Importing a Root Certificate
424
* Agent GET_PASSPHRASE:: Ask for a passphrase
425
* Agent GET_CONFIRMATION:: Ask for confirmation
426
* Agent HAVEKEY:: Check whether a key is available
427
* Agent LEARN:: Register a smartcard
428
* Agent PASSWD:: Change a Passphrase
431
@node Agent PKDECRYPT
432
@subsection Decrypting a session key
434
The client asks the server to decrypt a session key. The encrypted
435
session key should have all information needed to select the
436
appropriate secret key or to delegate it to a smartcard.
442
Tell the server about the key to be used for decryption. If this is
443
not used, @command{gpg-agent} may try to figure out the key by trying to
444
decrypt the message with each key available.
450
The agent checks whether this command is allowed and then does an
451
INQUIRY to get the ciphertext the client should then send the cipher
455
S: INQUIRE CIPHERTEXT
461
Please note that the server may send status info lines while reading the
462
data lines from the client. The data send is a SPKI like S-Exp with
468
(<param_name1> <mpi>)
470
(<param_namen> <mpi>)))
473
Where algo is a string with the name of the algorithm; see the libgcrypt
474
documentation for a list of valid algorithms. The number and names of
475
the parameters depend on the algorithm. The agent does return an error
476
if there is an inconsistency.
478
If the decryption was successful the decrypted data is returned by
481
Here is an example session:
485
S: INQUIRE CIPHERTEXT
486
C: D (enc-val elg (a 349324324)
487
C: D (b 3F444677CA)))
489
S: # session key follows
490
S: D 1234567890ABCDEF0
491
S: OK descryption successful
496
@subsection Signing a Hash
498
The client ask the agent to sign a given hash value. A default key
499
will be chosen if no key has been set. To set a key a client first
506
This can be used multiple times to create multiple signature, the list
507
of keys is reset with the next PKSIGN command or a RESET. The server
508
test whether the key is a valid key to sign something and responds with
515
The client can use this command to tell the server about the data
516
(which usually is a hash) to be signed.
518
The actual signing is done using
524
Options are not yet defined, but my later be used to choosen among
525
different algorithms (e.g. pkcs 1.5)
527
The agent does then some checks, asks for the passphrase and
528
if SETHASH has not been used asks the client for the data to sign:
532
C: D ABCDEF012345678901234
536
As a result the server returns the signature as an SPKI like S-Exp
542
(<param_name1> <mpi>)
544
(<param_namen> <mpi>)))
548
The operation is affected by the option
551
OPTION use-cache-for-signing=0|1
554
The default of @code{1} uses the cache. Setting this option to @code{0}
555
will lead @command{gpg-agent} to ignore the passphrase cache. Note, that there is
556
also a global command line option for @command{gpg-agent} to globally disable the
560
Here is an example session:
568
S: # I did ask the user whether he really wants to sign
569
S: # I did ask the user for the passphrase
571
C: D ABCDEF012345678901234
573
S: # signature follows
574
S: D (sig-val rsa (s 45435453654612121212))
580
@subsection Generating a Key
582
This is used to create a new keypair and store the secret key inside the
583
active PSE -w which is in most cases a Soft-PSE. An not yet defined
584
option allows to choose the storage location. To get the secret key out
585
of the PSE, a special export tool has to be used.
591
Invokes the key generation process and the server will then inquire
592
on the generation parameters, like:
596
C: D (genkey (rsa (nbits 1024)))
600
The format of the key parameters which depends on the algorithm is of
606
(parameter_name_1 ....)
608
(parameter_name_n ....)))
611
If everything succeeds, the server returns the *public key* in a SPKI
612
like S-Expression like this:
621
Here is an example session:
626
C: D (genkey (rsa (nbits 1024)))
629
S: D (rsa (n 326487324683264) (e 10001)))
634
@subsection Importing a Secret Key
636
This operation is not yet supportted by GpgAgent. Specialized tools
637
are to be used for this.
639
There is no actual need because we can expect that secret keys
640
created by a 3rd party are stored on a smartcard. If we have
641
generated the key ourself, we do not need to import it.
644
@subsection Export a Secret Key
648
Should be done by an extra tool.
650
@node Agent ISTRUSTED
651
@subsection Importing a Root Certificate
653
Actually we do not import a Root Cert but provide a way to validate
654
any piece of data by storing its Hash along with a description and
655
an identifier in the PSE. Here is the interface desription:
658
ISTRUSTED <fingerprint>
661
Check whether the OpenPGP primary key or the X.509 certificate with the
662
given fingerprint is an ultimately trusted key or a trusted Root CA
663
certificate. The fingerprint should be given as a hexstring (without
664
any blanks or colons or whatever in between) and may be left padded with
665
00 in case of an MD5 fingerprint. GPGAgent will answer with:
671
The key is in the table of trusted keys.
674
ERR 304 (Not Trusted)
677
The key is not in this table.
679
Gpg needs the entire list of trusted keys to maintain the web of
680
trust; the following command is therefore quite helpful:
686
GpgAgent returns a list of trusted keys line by line:
689
S: D 000000001234454556565656677878AF2F1ECCFF P
690
S: D 340387563485634856435645634856438576457A P
691
S: D FEDC6532453745367FD83474357495743757435D S
695
The first item on a line is the hexified fingerprint where MD5
696
ingerprints are @code{00} padded to the left and the second item is a
697
flag to indicate the type of key (so that gpg is able to only take care
698
of PGP keys). P = OpenPGP, S = S/MIME. A client should ignore the rest
699
of the line, so that we can extend the format in the future.
701
Finally a client should be able to mark a key as trusted:
704
MARKTRUSTED @var{fingerprint} "P"|"S"
707
The server will then pop up a window to ask the user whether she
708
really trusts this key. For this it will probably ask for a text to
709
be displayed like this:
713
C: D Do you trust the key with the fingerprint @@FPR@@
714
C: D bla fasel blurb.
719
Known sequences with the pattern @@foo@@ are replaced according to this
724
Format the fingerprint according to gpg rules for a v3 keys.
726
Format the fingerprint according to gpg rules for a v4 keys.
728
Choose an appropriate format to format the fingerprint.
730
Replaced by a single @code{@@}
733
@node Agent GET_PASSPHRASE
734
@subsection Ask for a passphrase
736
This function is usually used to ask for a passphrase to be used for
737
conventional encryption, but may also be used by programs which need
738
special handling of passphrases. This command uses a syntax which helps
739
clients to use the agent with minimum effort.
742
GET_PASSPHRASE @var{cache_id} [@var{error_message} @var{prompt} @var{description}]
745
@var{cache_id} is expected to be a hex string used for caching a
746
passphrase. Use a @code{X} to bypass the cache. With no other
747
arguments the agent returns a cached passphrase or an error.
749
@var{error_message} is either a single @code{X} for no error message or
750
a string to be shown as an error message like (e.g. "invalid
751
passphrase"). Blanks must be percent escaped or replaced by @code{+}'.
753
@var{prompt} is either a single @code{X} for a default prompt or the
754
text to be shown as the prompt. Blanks must be percent escaped or
755
replaced by @code{+}.
757
@var{description} is a text shown above the entry field. Blanks must be
758
percent escaped or replaced by @code{+}.
760
The agent either returns with an error or with a OK followed by the
761
hex encoded passphrase. Note that the length of the strings is
762
implicitly limited by the maximum length of a command.
765
CLEAR_PASSPHRASE @var{cache_id}
768
may be used to invalidate the cache entry for a passphrase. The
769
function returns with OK even when there is no cached passphrase.
772
@node Agent GET_CONFIRMATION
773
@subsection Ask for confirmation
775
This command may be used to ask for a simple confirmation by
776
presenting a text and 2 bottonts: Okay and Cancel.
779
GET_CONFIRMATION @var{description}
782
@var{description}is displayed along with a Okay and Cancel
783
button. Blanks must be percent escaped or replaced by @code{+}. A
784
@code{X} may be used to display confirmation dialog with a default
787
The agent either returns with an error or with a OK. Note, that the
788
length of @var{description} is implicitly limited by the maximum
794
@subsection Check whether a key is available
796
This can be used to see whether a secret key is available. It does
797
not return any information on whether the key is somehow protected.
800
HAVEKEY @var{keygrip}
803
The Agent answers either with OK or @code{No_Secret_Key} (208). The
804
caller may want to check for other error codes as well.
808
@subsection Register a smartcard
814
This command is used to register a smartcard. With the --send
815
option given the certificates are send back.
819
@subsection Change a Passphrase
825
This command is used to interactively change the passphrase of the key
826
indentified by the hex string @var{keygrip}.