Fix signal handling race condition.
[gnupg.git] / doc / scdaemon.texi
blobd8724ced8358813028148e40f4c52598a9486c90
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 SCDAEMON
6 @chapter Invoking the SCDAEMON
7 @cindex SCDAEMON command options
8 @cindex command options
9 @cindex options, SCDAEMON command
11 @manpage scdaemon.1
12 @ifset manverb
13 .B scdaemon
14 \- Smartcard daemon for the GnuPG system
15 @end ifset
17 @mansect synopsis
18 @ifset manverb
19 .B  scdaemon
20 .RB [ \-\-homedir
21 .IR dir ]
22 .RB [ \-\-options
23 .IR file ]
24 .RI [ options ]  
25 .B  \-\-server 
26 .br
27 .B  scdaemon
28 .RB [ \-\-homedir
29 .IR dir ]
30 .RB [ \-\-options
31 .IR file ]
32 .RI [ options ]  
33 .B  \-\-daemon 
34 .RI [ command_line ]
35 @end ifset
38 @mansect description
39 The @command{scdaemon} is a daemon to manage smartcards.  It is usually
40 invoked by @command{gpg-agent} and in general not used directly.
42 @manpause
43 @xref{Option Index}, for an index to @command{scdaemon}'s commands and
44 options.
45 @mancont
47 @menu
48 * Scdaemon Commands::      List of all commands.
49 * Scdaemon Options::       List of all options.
50 * Card applications::      Description of card applications.
51 * Scdaemon Configuration:: Configuration files.
52 * Scdaemon Examples::      Some usage examples.
53 * Scdaemon Protocol::      The protocol the daemon uses.
54 @end menu
56 @mansect commands
58 @node Scdaemon Commands
59 @section Commands
61 Commands are not distinguished from options except for the fact that
62 only one command is allowed.
64 @table @gnupgtabopt
65 @item --version
66 @opindex version
67 Print the program version and licensing information.  Not that you can
68 abbreviate this command.
70 @item --help, -h
71 @opindex help
72 Print a usage message summarizing the most usefule command-line options.
73 Not that you can abbreviate this command.
75 @item --dump-options
76 @opindex dump-options
77 Print a list of all available options and commands.  Not that you can
78 abbreviate this command.
80 @item --server
81 @opindex server
82 Run in server mode and wait for commands on the @code{stdin}.  This is
83 default mode is to create a socket and listen for commands there.
85 @item --multi-server
86 @opindex multi-server
87 Run in server mode and wait for commands on the @code{stdin} as well as
88 on an additional Unix Domain socket.  The server command @code{GETINFO}
89 may be used to get the name of that extra socket.
91 @item --daemon
92 @opindex daemon
93 Run the program in the background.  This option is required to prevent
94 it from being accidently running in the background.
96 @end table
99 @mansect options
101 @node Scdaemon Options
102 @section Option Summary
104 @table @gnupgtabopt
106 @item --options @var{file}
107 @opindex options
108 Reads configuration from @var{file} instead of from the default
109 per-user configuration file.  The default configuration file is named
110 @file{scdaemon.conf} and expected in the @file{.gnupg} directory directly
111 below the home directory of the user.
113 @include opt-homedir.texi
116 @item -v
117 @item --verbose
118 @opindex v
119 @opindex verbose
120 Outputs additional information while running.
121 You can increase the verbosity by giving several
122 verbose commands to @command{gpgsm}, such as @samp{-vv}.
124 @item --debug-level @var{level}
125 @opindex debug-level
126 Select the debug level for investigating problems. @var{level} may be
127 one of:
129 @table @code
130 @item none
131 no debugging at all.
132 @item basic  
133 some basic debug messages
134 @item advanced
135 more verbose debug messages
136 @item expert
137 even more detailed messages
138 @item guru
139 all of the debug messages you can get
140 @end table
142 How these messages are mapped to the actual debugging flags is not
143 specified and may change with newer releases of this program. They are
144 however carefully selected to best aid in debugging.
146 @quotation Note
147 All debugging options are subject to change and thus should not be used
148 by any application program.  As the name says, they are only used as
149 helpers to debug problems.
150 @end quotation
153 @item --debug @var{flags}
154 @opindex debug
155 This option is only useful for debugging and the behaviour may change at
156 any time without notice.  FLAGS are bit encoded and may be given in
157 usual C-Syntax. The currently defined bits are:
159 @table @code
160 @item 0  (1)
161 command I/O
162 @item 1  (2)  
163 values of big number integers 
164 @item 2  (4)
165 low level crypto operations
166 @item 5  (32)
167 memory allocation
168 @item 6  (64)
169 caching
170 @item 7  (128)
171 show memory statistics.
172 @item 9  (512)
173 write hashed data to files named @code{dbgmd-000*}
174 @item 10 (1024)
175 trace Assuan protocol
176 @item 11 (2048)
177 trace APDU I/O to the card.  This may reveal sensitive data.
178 @end table
180 @item --debug-all
181 @opindex debug-all
182 Same as @code{--debug=0xffffffff}
184 @item --debug-wait @var{n}
185 @opindex debug-wait
186 When running in server mode, wait @var{n} seconds before entering the
187 actual processing loop and print the pid.  This gives time to attach a
188 debugger.
190 @item --debug-ccid-driver
191 @opindex debug-wait
192 Enable debug output from the included CCID driver for smartcards.
193 Using this option twice will also enable some tracing of the T=1
194 protocol.  Note that this option may reveal sensitive data.
196 @item --debug-disable-ticker
197 @opindex debug-disable-ticker
198 This option disables all ticker functions like checking for card
199 insertions.
201 @item --debug-allow-core-dump
202 @opindex debug-allow-core-dump
203 For security reasons we won't create a core dump when the process
204 aborts.  For debugging purposes it is sometimes better to allow core
205 dump.  This options enables it and also changes the working directory to
206 @file{/tmp} when running in @option{--server} mode.
209 @item --no-detach
210 @opindex no-detach
211 Don't detach the process from the console.  This is mainly useful for
212 debugging.
214 @item --log-file @var{file}
215 @opindex log-file
216 Append all logging output to @var{file}.  This is very helpful in
217 seeing what the agent actually does.
220 @item --pcsc-driver @var{library}
221 @opindex pcsc-driver
222 Use @var{library} to access the smartcard reader.  The current default
223 is @file{libpcsclite.so}.  Instead of using this option you might also
224 want to install a symbolic link to the default file name
225 (e.g. from @file{libpcsclite.so.1}).
227 @item --ctapi-driver @var{library}
228 @opindex ctapi-driver
229 Use @var{library} to access the smartcard reader.  The current default
230 is @file{libtowitoko.so}.  Note that the use of this interface is
231 deprecated; it may be removed in future releases.
233 @item --disable-ccid 
234 @opindex disable-ccid
235 Disable the integrated support for CCID compliant readers.  This
236 allows to fall back to one of the other drivers even if the internal
237 CCID driver can handle the reader.  Note, that CCID support is only
238 available if libusb was available at build time.
240 @item --reader-port @var{number_or_string}
241 @opindex reader-port
242 This option may be used to specify the port of the card terminal.  A
243 value of 0 refers to the first serial device; add 32768 to access USB
244 devices.  The default is 32768 (first USB device).  PC/SC or CCID
245 readers might need a string here; run the program in verbose mode to get
246 a list of available readers.  The default is then the first reader
247 found.
249 To get a list of available CCID readers you may use this command:
250 @smallexample
251 echo scd getinfo reader_list | gpg-connect-agent --decode | awk '/^D/ @{print $2@}'
252 @end smallexample
255 @item --card-timeout @var{n}
256 @opindex card-timeout
257 If @var{n} is not 0 and no client is actively using the card, the card
258 will be powered down after @var{n} seconds.  Powering down the card
259 avoids a potential risk of damaging a card when used with certain
260 cheap readers.  This also allows non Scdaemon aware applications to
261 access the card.  The disadvantage of using a card timeout is that
262 accessing the card takes longer and that the user needs to enter the
263 PIN again after the next power up.
265 Note that with the current version of Scdaemon the card is powered
266 down immediatley at the next timer tick for any value of @var{n} other
267 than 0.
270 @item --disable-keypad
271 @opindex disable-keypad
272 Even if a card reader features a keypad, do not try to use it.
275 @item --allow-admin
276 @itemx --deny-admin
277 @opindex allow-admin
278 @opindex deny-admin
279 This enables the use of Admin class commands for card applications
280 where this is supported.  Currently we support it for the OpenPGP
281 card.  Deny is the default.  This commands is useful to inhibit
282 accidental access to admin class command which could ultimately lock
283 the card through wrong PIN numbers.
285 @item --disable-application @var{name}
286 @opindex disable-application
287 This option disables the use of the card application named
288 @var{name}.  This is mainly useful for debugging or if a application
289 with lower priority should be used by default.
291 @end table
293 All the long options may also be given in the configuration file after
294 stripping off the two leading dashes.
297 @mansect card applications
298 @node Card applications
299 @section Description of card applications
301 @command{scdaemon} supports the card applications as described below.
303 @menu
304 * OpenPGP Card::          The OpenPGP card application
305 * NKS Card::              The Telesec NetKey card application
306 * DINSIG Card::           The DINSIG card application
307 * PKCS#15 Card::          The PKCS#15 card application
308 @end menu
310 @node OpenPGP Card
311 @subsection The OpenPGP card application ``openpgp''
313 This application is currently only used by @command{gpg} but may in
314 future also be useful with @command{gpgsm}. 
316 The specification for such a card is available at
317 @uref{http://g10code.com/docs/openpgp-card-1.0.pdf}.
319 @node NKS Card
320 @subsection The Telesec NetKey card ``nks''
322 This is the main application of the Telesec cards as available in
323 Germany.  It is a superset of the German DINSIG card.  The card is
324 used by @command{gpgsm}.
326 @node DINSIG Card
327 @subsection The DINSIG card application ``dinsig''
329 This is an application as described in the German draft standard
330 @emph{DIN V 66291-1}.  It is intended to be used by cards supporting
331 the German signature law and its bylaws (SigG and SigV).
333 @node PKCS#15 Card
334 @subsection The PKCS#15 card application ``p15''
336 This is common fraqmework for smart card applications.  It is used by
337 @command{gpgsm}.
340 @c *******************************************
341 @c ***************            ****************
342 @c ***************   FILES    ****************
343 @c ***************            ****************
344 @c *******************************************
345 @mansect files
346 @node Scdaemon Configuration
347 @section Configuration files
349 There are a few configuration files to control certain aspects of
350 @command{scdaemons}'s operation. Unless noted, they are expected in the
351 current home directory (@pxref{option --homedir}).
353 @table @file
355 @item scdaemon.conf
356 @cindex scdaemon.conf
357 This is the standard configuration file read by @command{scdaemon} on
358 startup.  It may contain any valid long option; the leading two dashes
359 may not be entered and the option may not be abbreviated.  This default
360 name may be changed on the command line (@pxref{option --options}).
362 @item scd-event
363 @cindex scd-event
364 If this file is present and executable, it will be called on veyer card
365 reader's status changed. An example of this script is provided with the
366 distribution
368 @item reader_@var{n}.status
369 This file is created by @command{sdaemon} to let other applications now
370 about reader status changes.  Its use is now deprecated in favor of
371 @file{scd-event}.
373 @end table
376 @c 
377 @c  Examples
379 @mansect examples
380 @node Scdaemon Examples
381 @section Examples
383 @c man begin EXAMPLES
385 @example
386 $ scdaemon --server -v
387 @end example
389 @c man end
391 @c 
392 @c  Assuan Protocol
394 @manpause
395 @node Scdaemon Protocol
396 @section Scdaemon's Assuan Protocol
398 The SC-Daemon should be started by the system to provide access to
399 external tokens.  Using Smartcards on a multi-user system does not
400 make much sense expcet for system services, but in this case no
401 regular user accounts are hosted on the machine.
403 A client connects to the SC-Daemon by connecting to the socket named
404 @file{/var/run/scdaemon/socket}, configuration information is read from
405 @var{/etc/scdaemon.conf}
407 Each connection acts as one session, SC-Daemon takes care of
408 syncronizing access to a token between sessions.
410 @menu
411 * Scdaemon SERIALNO::     Return the serial number.
412 * Scdaemon LEARN::        Read all useful information from the card.
413 * Scdaemon READCERT::     Return a certificate.
414 * Scdaemon READKEY::      Return a public key.
415 * Scdaemon PKSIGN::       Signing data with a Smartcard.
416 * Scdaemon PKDECRYPT::    Decrypting data with a Smartcard.
417 * Scdaemon GETATTR::      Read an attribute's value.
418 * Scdaemon SETATTR::      Update an attribute's value.
419 * Scdaemon WRITEKEY::     Write a key to a card.
420 * Scdaemon GENKEY::       Generate a new key on-card.
421 * Scdaemon RANDOM::       Return random bytes generate on-card.
422 * Scdaemon PASSWD::       Change PINs.
423 * Scdaemon CHECKPIN::     Perform a VERIFY operation.
424 * Scdaemon RESTART::      Restart connection
425 * Scdaemon APDU::         Send a verbatim APDU to the card
426 @end menu
428 @node Scdaemon SERIALNO 
429 @subsection Return the serial number
431 This command should be used to check for the presence of a card.  It is
432 special in that it can be used to reset the card.  Most other commands
433 will return an error when a card change has been detected and the use of
434 this function is therefore required.
436 Background: We want to keep the client clear of handling card changes
437 between operations; i.e. the client can assume that all operations are
438 done on the same card unless he call this function.
440 @example
441   SERIALNO
442 @end example
444 Return the serial number of the card using a status reponse like:
446 @example
447   S SERIALNO D27600000000000000000000 0
448 @end example
450 The trailing 0 should be ignored for now, it is reserved for a future
451 extension.  The serial number is the hex encoded value identified by 
452 the @code{0x5A} tag in the GDO file (FIX=0x2F02).
456 @node Scdaemon LEARN
457 @subsection Read all useful information from the card
459 @example
460   LEARN [--force]
461 @end example
463 Learn all useful information of the currently inserted card.  When
464 used without the force options, the command might do an INQUIRE
465 like this:
467 @example
468       INQUIRE KNOWNCARDP <hexstring_with_serialNumber> <timestamp>
469 @end example
471 The client should just send an @code{END} if the processing should go on
472 or a @code{CANCEL} to force the function to terminate with a cancel
473 error message.  The response of this command is a list of status lines
474 formatted as this:
476 @example
477      S KEYPAIRINFO @var{hexstring_with_keygrip} @var{hexstring_with_id}
478 @end example
480 If there is no certificate yet stored on the card a single "X" is
481 returned in @var{hexstring_with_keygrip}.
483 @node Scdaemon READCERT
484 @subsection Return a certificate
486 @example
487  READCERT @var{hexified_certid}|@var{keyid}
488 @end example
490 This function is used to read a certificate identified by
491 @var{hexified_certid} from the card.  With OpenPGP cards the keyid
492 @code{OpenPGP.3} may be used to rad the certticate of version 2 cards.
495 @node Scdaemon READKEY
496 @subsection Return a public key
498 @example
499 READKEY @var{hexified_certid}
500 @end example
502 Return the public key for the given cert or key ID as an standard
503 S-Expression. 
507 @node Scdaemon PKSIGN
508 @subsection Signing data with a Smartcard
510 To sign some data the caller should use the command
512 @example
513  SETDATA @var{hexstring}
514 @end example
516 to tell @command{scdaemon} about the data to be signed.  The data must be given in
517 hex notation.  The actual signing is done using the command
519 @example
520   PKSIGN @var{keyid}
521 @end example
523 where @var{keyid} is the hexified ID of the key to be used.  The key id
524 may have been retrieved using the command @code{LEARN}.  If another
525 hash algorithm than SHA-1 is used, that algorithm may be given like:
527 @example
528   PKSIGN --hash=@var{algoname} @var{keyid}
529 @end example
531 With @var{algoname} are one of @code{sha1}, @code{rmd160} or @code{md5}.
534 @node Scdaemon PKDECRYPT
535 @subsection Decrypting data with a Smartcard
537 To decrypt some data the caller should use the command
539 @example
540  SETDATA @var{hexstring}
541 @end example
543 to tell @command{scdaemon} about the data to be decrypted.  The data
544 must be given in hex notation.  The actual decryption is then done
545 using the command
547 @example
548   PKDECRYPT @var{keyid}
549 @end example
551 where @var{keyid} is the hexified ID of the key to be used.
554 @node Scdaemon GETATTR
555 @subsection Read an attribute's value.
557 TO BE WRITTEN.
559 @node Scdaemon SETATTR
560 @subsection Update an attribute's value.
562 TO BE WRITTEN.
564 @node Scdaemon WRITEKEY
565 @subsection Write a key to a card.
567 @example
568   WRITEKEY [--force] @var{keyid}
569 @end example
571 This command is used to store a secret key on a a smartcard.  The
572 allowed keyids depend on the currently selected smartcard
573 application. The actual keydata is requested using the inquiry
574 @code{KEYDATA} and need to be provided without any protection.  With
575 @option{--force} set an existing key under this @var{keyid} will get
576 overwritten.  The key data is expected to be the usual canonical encoded
577 S-expression.
579 A PIN will be requested in most saes.  This however depends on the
580 actual card application.
583 @node Scdaemon GENKEY
584 @subsection Generate a new key on-card.
586 TO BE WRITTEN.
588 @node Scdaemon RANDOM
589 @subsection Return random bytes generate on-card.
591 TO BE WRITTEN.
594 @node Scdaemon PASSWD
595 @subsection Change PINs.
597 @example
598    PASSWD [--reset] [--nullpin] @var{chvno}
599 @end example
600   
601 Change the PIN or reset the retry counter of the card holder
602 verification vector number @var{chvno}.  The option @option{--nullpin}
603 is used to initialize the PIN of TCOS cards (6 byte NullPIN only).
606 @node Scdaemon CHECKPIN
607 @subsection Perform a VERIFY operation.
609 @example
610   CHECKPIN @var{idstr}
611 @end example
613 Perform a VERIFY operation without doing anything else.  This may be
614 used to initialize a the PIN cache earlier to long lasting
615 operations.  Its use is highly application dependent:
617 @table @strong
618 @item OpenPGP
620 Perform a simple verify operation for CHV1 and CHV2, so that further
621 operations won't ask for CHV2 and it is possible to do a cheap check on
622 the PIN: If there is something wrong with the PIN entry system, only the
623 regular CHV will get blocked and not the dangerous CHV3.  @var{idstr} is
624 the usual card's serial number in hex notation; an optional fingerprint
625 part will get ignored.
627 There is however a special mode if @var{idstr} is suffixed with the
628 literal string @code{[CHV3]}: In this case the Admin PIN is checked if
629 and only if the retry counter is still at 3.
631 @end table
635 @node Scdaemon RESTART
636 @subsection Perform a RESTART operation.
638 @example
639   RESTART
640 @end example
642 Restart the current connection; this is a kind of warm reset.  It
643 deletes the context used by this connection but does not actually
644 reset the card. 
646 This is used by gpg-agent to reuse a primary pipe connection and
647 may be used by clients to backup from a conflict in the serial
648 command; i.e. to select another application. 
653 @node Scdaemon APDU
654 @subsection Send a verbatim APDU to the card.
656 @example
657   APDU [--atr] [--more] [@var{hexstring}]
658 @end example
661 Send an APDU to the current reader.  This command bypasses the high
662 level functions and sends the data directly to the card.
663 @var{hexstring} is expected to be a proper APDU.  If @var{hexstring} is
664 not given no commands are send to the card; However the command will
665 implicitly check whether the card is ready for use.
667 Using the option @code{--atr} returns the ATR of the card as a status
668 message before any data like this:
669 @example
670      S CARD-ATR 3BFA1300FF813180450031C173C00100009000B1
671 @end example
673 Using the option @code{--more} handles the card status word MORE_DATA
674 (61xx) and concatenate all reponses to one block.
678 @mansect see also
679 @ifset isman
680 @command{gpg-agent}(1),
681 @command{gpgsm}(1), 
682 @command{gpg2}(1)
683 @end ifset
684 @include see-also-note.texi