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
14 \- Smartcard daemon for the GnuPG system
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.
43 @xref{Option Index}, for an index to @command{scdaemon}'s commands and
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.
58 @node Scdaemon Commands
61 Commands are not distinguished from options except for the fact that
62 only one command is allowed.
67 Print the program version and licensing information. Not that you can
68 abbreviate this command.
72 Print a usage message summarizing the most usefule command-line options.
73 Not that you can abbreviate this command.
77 Print a list of all available options and commands. Not that you can
78 abbreviate this command.
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.
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.
93 Run the program in the background. This option is required to prevent
94 it from being accidently running in the background.
101 @node Scdaemon Options
102 @section Option Summary
106 @item --options @var{file}
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
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}
126 Select the debug level for investigating problems. @var{level} may be
133 some basic debug messages
135 more verbose debug messages
137 even more detailed messages
139 all of the debug messages you can get
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.
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.
153 @item --debug @var{flags}
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:
163 values of big number integers
165 low level crypto operations
171 show memory statistics.
173 write hashed data to files named @code{dbgmd-000*}
175 trace Assuan protocol
177 trace APDU I/O to the card. This may reveal sensitive data.
182 Same as @code{--debug=0xffffffff}
184 @item --debug-wait @var{n}
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
190 @item --debug-ccid-driver
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
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.
211 Don't detach the process from the console. This is mainly useful for
214 @item --log-file @var{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}
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.
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}
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
249 To get a list of available CCID readers you may use this command:
251 echo scd getinfo reader_list | gpg-connect-agent --decode | awk '/^D/ @{print $2@}'
256 @item --disable-keypad
257 @opindex disable-keypad
258 Even if a card reader features a keypad, do not try to use it.
265 This enables the use of Admin class commands for card applications
266 where this is supported. Currently we support it for the OpenPGP
267 card. Deny is the default. This commands is useful to inhibit
268 accidental access to admin class command which could ultimately lock
269 the card through worng PIN numbers.
271 @item --disable-application @var{name}
272 @opindex disable-application
273 This option disables the use of the card application named
274 @var{name}. This is mainly useful for debugging or if a application
275 with lower priority should be used by default.
279 All the long options may also be given in the configuration file after
280 stripping off the two leading dashes.
283 @mansect card applications
284 @node Card applications
285 @section Description of card applications
287 @command{scdaemon} supports the card applications as described below.
290 * OpenPGP Card:: The OpenPGP card application
291 * NKS Card:: The Telesec NetKey card application
292 * DINSIG Card:: The DINSIG card application
293 * PKCS#15 Card:: The PKCS#15 card application
297 @subsection The OpenPGP card application ``openpgp''
299 This application is currently only used by @command{gpg} but may in
300 future also be useful with @command{gpgsm}.
302 The specification for such a card is available at
303 @uref{http://g10code.com/docs/openpgp-card-1.0.pdf}.
306 @subsection The Telesec NetKey card ``nks''
308 This is the main application of the Telesec cards as available in
309 Germany. It is a superset of the German DINSIG card. The card is
310 used by @command{gpgsm}.
313 @subsection The DINSIG card application ``dinsig''
315 This is an application as described in the German draft standard
316 @emph{DIN V 66291-1}. It is intended to be used by cards supporting
317 the German signature law and its bylaws (SigG and SigV).
320 @subsection The PKCS#15 card application ``p15''
322 This is common fraqmework for smart card applications. It is used by
326 @c *******************************************
327 @c *************** ****************
328 @c *************** FILES ****************
329 @c *************** ****************
330 @c *******************************************
332 @node Scdaemon Configuration
333 @section Configuration files
335 There are a few configuration files to control certain aspects of
336 @command{scdaemons}'s operation. Unless noted, they are expected in the
337 current home directory (@pxref{option --homedir}).
342 @cindex scdaemon.conf
343 This is the standard configuration file read by @command{scdaemon} on
344 startup. It may contain any valid long option; the leading two dashes
345 may not be entered and the option may not be abbreviated. This default
346 name may be changed on the command line (@pxref{option --options}).
350 If this file is present and executable, it will be called on veyer card
351 reader's status changed. An example of this script is provided with the
354 @item reader_@var{n}.status
355 This file is created by @command{sdaemon} to let other applications now
356 about reader status changes. Its use is now deprecated in favor of
366 @node Scdaemon Examples
369 @c man begin EXAMPLES
372 $ scdaemon --server -v
381 @node Scdaemon Protocol
382 @section Scdaemon's Assuan Protocol
384 The SC-Daemon should be started by the system to provide access to
385 external tokens. Using Smartcards on a multi-user system does not
386 make much sense expcet for system services, but in this case no
387 regular user accounts are hosted on the machine.
389 A client connects to the SC-Daemon by connecting to the socket named
390 @file{/var/run/scdaemon/socket}, configuration information is read from
391 @var{/etc/scdaemon.conf}
393 Each connection acts as one session, SC-Daemon takes care of
394 syncronizing access to a token between sessions.
397 * Scdaemon SERIALNO:: Return the serial number.
398 * Scdaemon LEARN:: Read all useful information from the card.
399 * Scdaemon READCERT:: Return a certificate.
400 * Scdaemon READKEY:: Return a public key.
401 * Scdaemon PKSIGN:: Signing data with a Smartcard.
402 * Scdaemon PKDECRYPT:: Decrypting data with a Smartcard.
403 * Scdaemon GETATTR:: Read an attribute's value.
404 * Scdaemon SETATTR:: Update an attribute's value.
405 * Scdaemon WRITEKEY:: Write a key to a card.
406 * Scdaemon GENKEY:: Generate a new key on-card.
407 * Scdaemon RANDOM:: Return random bytes generate on-card.
408 * Scdaemon PASSWD:: Change PINs.
409 * Scdaemon CHECKPIN:: Perform a VERIFY operation.
410 * Scdaemon RESTART:: Restart connection
411 * Scdaemon APDU:: Send a verbatim APDU to the card
414 @node Scdaemon SERIALNO
415 @subsection Return the serial number
417 This command should be used to check for the presence of a card. It is
418 special in that it can be used to reset the card. Most other commands
419 will return an error when a card change has been detected and the use of
420 this function is therefore required.
422 Background: We want to keep the client clear of handling card changes
423 between operations; i.e. the client can assume that all operations are
424 done on the same card unless he call this function.
430 Return the serial number of the card using a status reponse like:
433 S SERIALNO D27600000000000000000000 0
436 The trailing 0 should be ignored for now, it is reserved for a future
437 extension. The serial number is the hex encoded value identified by
438 the @code{0x5A} tag in the GDO file (FIX=0x2F02).
443 @subsection Read all useful information from the card
449 Learn all useful information of the currently inserted card. When
450 used without the force options, the command might do an INQUIRE
454 INQUIRE KNOWNCARDP <hexstring_with_serialNumber> <timestamp>
457 The client should just send an @code{END} if the processing should go on
458 or a @code{CANCEL} to force the function to terminate with a cancel
459 error message. The response of this command is a list of status lines
463 S KEYPAIRINFO @var{hexstring_with_keygrip} @var{hexstring_with_id}
466 If there is no certificate yet stored on the card a single "X" is
467 returned in @var{hexstring_with_keygrip}.
469 @node Scdaemon READCERT
470 @subsection Return a certificate
473 READCERT @var{hexified_certid}
476 This function is used to read a certificate identified by
477 @var{hexified_certid} from the card.
480 @node Scdaemon READKEY
481 @subsection Return a public key
484 READKEY @var{hexified_certid}
487 Return the public key for the given cert or key ID as an standard
492 @node Scdaemon PKSIGN
493 @subsection Signing data with a Smartcard
495 To sign some data the caller should use the command
498 SETDATA @var{hexstring}
501 to tell @command{scdaemon} about the data to be signed. The data must be given in
502 hex notation. The actual signing is done using the command
508 where @var{keyid} is the hexified ID of the key to be used. The key id
509 may have been retrieved using the command @code{LEARN}. If another
510 hash algorithm than SHA-1 is used, that algorithm may be given like:
513 PKSIGN --hash=@var{algoname} @var{keyid}
516 With @var{algoname} are one of @code{sha1}, @code{rmd160} or @code{md5}.
519 @node Scdaemon PKDECRYPT
520 @subsection Decrypting data with a Smartcard
522 To decrypt some data the caller should use the command
525 SETDATA @var{hexstring}
528 to tell @command{scdaemon} about the data to be decrypted. The data
529 must be given in hex notation. The actual decryption is then done
533 PKDECRYPT @var{keyid}
536 where @var{keyid} is the hexified ID of the key to be used.
539 @node Scdaemon GETATTR
540 @subsection Read an attribute's value.
544 @node Scdaemon SETATTR
545 @subsection Update an attribute's value.
549 @node Scdaemon WRITEKEY
550 @subsection Write a key to a card.
553 WRITEKEY [--force] @var{keyid}
556 This command is used to store a secret key on a a smartcard. The
557 allowed keyids depend on the currently selected smartcard
558 application. The actual keydata is requested using the inquiry
559 @code{KEYDATA} and need to be provided without any protection. With
560 @option{--force} set an existing key under this @var{keyid} will get
561 overwritten. The key data is expected to be the usual canonical encoded
564 A PIN will be requested in most saes. This however depends on the
565 actual card application.
568 @node Scdaemon GENKEY
569 @subsection Generate a new key on-card.
573 @node Scdaemon RANDOM
574 @subsection Return random bytes generate on-card.
579 @node Scdaemon PASSWD
580 @subsection Change PINs.
583 PASSWD [--reset] @var{chvno}
586 Change the PIN or reset the retry counter of the card holder
587 verification vector number @var{chvno}.
590 @node Scdaemon CHECKPIN
591 @subsection Perform a VERIFY operation.
597 Perform a VERIFY operation without doing anything else. This may be
598 used to initialize a the PIN cache earlier to long lasting
599 operations. Its use is highly application dependent:
604 Perform a simple verify operation for CHV1 and CHV2, so that further
605 operations won't ask for CHV2 and it is possible to do a cheap check on
606 the PIN: If there is something wrong with the PIN entry system, only the
607 regular CHV will get blocked and not the dangerous CHV3. @var{idstr} is
608 the usual card's serial number in hex notation; an optional fingerprint
609 part will get ignored.
611 There is however a special mode if @var{idstr} is suffixed with the
612 literal string @code{[CHV3]}: In this case the Admin PIN is checked if
613 and only if the retry counter is still at 3.
619 @node Scdaemon RESTART
620 @subsection Perform a RESTART operation.
626 Restart the current connection; this is a kind of warm reset. It
627 deletes the context used by this connection but does not actually
630 This is used by gpg-agent to reuse a primary pipe connection and
631 may be used by clients to backup from a conflict in the serial
632 command; i.e. to select another application.
638 @subsection Send a verbatim APDU to the card.
641 APDU [--atr] [--more] [@var{hexstring}]
645 Send an APDU to the current reader. This command bypasses the high
646 level functions and sends the data directly to the card.
647 @var{hexstring} is expected to be a proper APDU. If @var{hexstring} is
648 not given no commands are send to the card; However the command will
649 implicitly check whether the card is ready for use.
651 Using the option @code{--atr} returns the ATR of the card as a status
652 message before any data like this:
654 S CARD-ATR 3BFA1300FF813180450031C173C00100009000B1
657 Using the option @code{--more} handles the card status word MORE_DATA
658 (61xx) and concatenate all reponses to one block.
664 @command{gpg-agent}(1),
668 @include see-also-note.texi