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.
208 @item --debug-log-tid
209 @opindex debug-log-tid
210 This option appends a thread ID to the PID in the log output.
215 Don't detach the process from the console. This is mainly useful for
218 @item --log-file @var{file}
220 Append all logging output to @var{file}. This is very helpful in
221 seeing what the agent actually does.
224 @item --pcsc-driver @var{library}
226 Use @var{library} to access the smartcard reader. The current default
227 is @file{libpcsclite.so}. Instead of using this option you might also
228 want to install a symbolic link to the default file name
229 (e.g. from @file{libpcsclite.so.1}).
231 @item --ctapi-driver @var{library}
232 @opindex ctapi-driver
233 Use @var{library} to access the smartcard reader. The current default
234 is @file{libtowitoko.so}. Note that the use of this interface is
235 deprecated; it may be removed in future releases.
238 @opindex disable-ccid
239 Disable the integrated support for CCID compliant readers. This
240 allows to fall back to one of the other drivers even if the internal
241 CCID driver can handle the reader. Note, that CCID support is only
242 available if libusb was available at build time.
244 @item --reader-port @var{number_or_string}
246 This option may be used to specify the port of the card terminal. A
247 value of 0 refers to the first serial device; add 32768 to access USB
248 devices. The default is 32768 (first USB device). PC/SC or CCID
249 readers might need a string here; run the program in verbose mode to get
250 a list of available readers. The default is then the first reader
253 To get a list of available CCID readers you may use this command:
255 echo scd getinfo reader_list | gpg-connect-agent --decode | awk '/^D/ @{print $2@}'
259 @item --card-timeout @var{n}
260 @opindex card-timeout
261 If @var{n} is not 0 and no client is actively using the card, the card
262 will be powered down after @var{n} seconds. Powering down the card
263 avoids a potential risk of damaging a card when used with certain
264 cheap readers. This also allows non Scdaemon aware applications to
265 access the card. The disadvantage of using a card timeout is that
266 accessing the card takes longer and that the user needs to enter the
267 PIN again after the next power up.
269 Note that with the current version of Scdaemon the card is powered
270 down immediatley at the next timer tick for any value of @var{n} other
274 @item --disable-keypad
275 @opindex disable-keypad
276 Even if a card reader features a keypad, do not try to use it.
282 This option disables the use of admin class commands for card
283 applications where this is supported. Currently we support it for the
284 OpenPGP card. This commands is useful to inhibit accidental access to
285 admin class command which could ultimately lock the card through wrong
286 PIN numbers. Note that GnuPG versions older than 2.0.11 featured an
287 @option{--allow-admin} command which was required to use such admin
288 commands. This option has no more effect today because the default is
289 now to allow admin commands.
291 @item --disable-application @var{name}
292 @opindex disable-application
293 This option disables the use of the card application named
294 @var{name}. This is mainly useful for debugging or if a application
295 with lower priority should be used by default.
299 All the long options may also be given in the configuration file after
300 stripping off the two leading dashes.
303 @mansect card applications
304 @node Card applications
305 @section Description of card applications
307 @command{scdaemon} supports the card applications as described below.
310 * OpenPGP Card:: The OpenPGP card application
311 * NKS Card:: The Telesec NetKey card application
312 * DINSIG Card:: The DINSIG card application
313 * PKCS#15 Card:: The PKCS#15 card application
314 * Geldkarte Card:: The Geldkarte application
318 @subsection The OpenPGP card application ``openpgp''
320 This application is currently only used by @command{gpg} but may in
321 future also be useful with @command{gpgsm}. Version 1 and version 2 of
322 the card is supported.
324 The specifications for these cards are available at
325 @uref{http://g10code.com/docs/openpgp-card-1.0.pdf} and
326 @uref{http://g10code.com/docs/openpgp-card-2.0.pdf}.
329 @subsection The Telesec NetKey card ``nks''
331 This is the main application of the Telesec cards as available in
332 Germany. It is a superset of the German DINSIG card. The card is
333 used by @command{gpgsm}.
336 @subsection The DINSIG card application ``dinsig''
338 This is an application as described in the German draft standard
339 @emph{DIN V 66291-1}. It is intended to be used by cards supporting
340 the German signature law and its bylaws (SigG and SigV).
343 @subsection The PKCS#15 card application ``p15''
345 This is common fraqmework for smart card applications. It is used by
349 @subsection The Geldkarte card application ``geldkarte''
351 This is a simple application to display information of a German
352 Geldkarte. The Geldkarte is a small amount debit card application which
353 comes with almost all German banking cards.
356 @c *******************************************
357 @c *************** ****************
358 @c *************** FILES ****************
359 @c *************** ****************
360 @c *******************************************
362 @node Scdaemon Configuration
363 @section Configuration files
365 There are a few configuration files to control certain aspects of
366 @command{scdaemons}'s operation. Unless noted, they are expected in the
367 current home directory (@pxref{option --homedir}).
372 @cindex scdaemon.conf
373 This is the standard configuration file read by @command{scdaemon} on
374 startup. It may contain any valid long option; the leading two dashes
375 may not be entered and the option may not be abbreviated. This default
376 name may be changed on the command line (@pxref{option --options}).
380 If this file is present and executable, it will be called on veyer card
381 reader's status changed. An example of this script is provided with the
384 @item reader_@var{n}.status
385 This file is created by @command{sdaemon} to let other applications now
386 about reader status changes. Its use is now deprecated in favor of
396 @node Scdaemon Examples
399 @c man begin EXAMPLES
402 $ scdaemon --server -v
411 @node Scdaemon Protocol
412 @section Scdaemon's Assuan Protocol
414 The SC-Daemon should be started by the system to provide access to
415 external tokens. Using Smartcards on a multi-user system does not
416 make much sense expcet for system services, but in this case no
417 regular user accounts are hosted on the machine.
419 A client connects to the SC-Daemon by connecting to the socket named
420 @file{/var/run/scdaemon/socket}, configuration information is read from
421 @var{/etc/scdaemon.conf}
423 Each connection acts as one session, SC-Daemon takes care of
424 syncronizing access to a token between sessions.
427 * Scdaemon SERIALNO:: Return the serial number.
428 * Scdaemon LEARN:: Read all useful information from the card.
429 * Scdaemon READCERT:: Return a certificate.
430 * Scdaemon READKEY:: Return a public key.
431 * Scdaemon PKSIGN:: Signing data with a Smartcard.
432 * Scdaemon PKDECRYPT:: Decrypting data with a Smartcard.
433 * Scdaemon GETATTR:: Read an attribute's value.
434 * Scdaemon SETATTR:: Update an attribute's value.
435 * Scdaemon WRITEKEY:: Write a key to a card.
436 * Scdaemon GENKEY:: Generate a new key on-card.
437 * Scdaemon RANDOM:: Return random bytes generate on-card.
438 * Scdaemon PASSWD:: Change PINs.
439 * Scdaemon CHECKPIN:: Perform a VERIFY operation.
440 * Scdaemon RESTART:: Restart connection
441 * Scdaemon APDU:: Send a verbatim APDU to the card
444 @node Scdaemon SERIALNO
445 @subsection Return the serial number
447 This command should be used to check for the presence of a card. It is
448 special in that it can be used to reset the card. Most other commands
449 will return an error when a card change has been detected and the use of
450 this function is therefore required.
452 Background: We want to keep the client clear of handling card changes
453 between operations; i.e. the client can assume that all operations are
454 done on the same card unless he call this function.
460 Return the serial number of the card using a status reponse like:
463 S SERIALNO D27600000000000000000000 0
466 The trailing 0 should be ignored for now, it is reserved for a future
467 extension. The serial number is the hex encoded value identified by
468 the @code{0x5A} tag in the GDO file (FIX=0x2F02).
473 @subsection Read all useful information from the card
479 Learn all useful information of the currently inserted card. When
480 used without the force options, the command might do an INQUIRE
484 INQUIRE KNOWNCARDP <hexstring_with_serialNumber> <timestamp>
487 The client should just send an @code{END} if the processing should go on
488 or a @code{CANCEL} to force the function to terminate with a cancel
489 error message. The response of this command is a list of status lines
493 S KEYPAIRINFO @var{hexstring_with_keygrip} @var{hexstring_with_id}
496 If there is no certificate yet stored on the card a single "X" is
497 returned in @var{hexstring_with_keygrip}.
499 @node Scdaemon READCERT
500 @subsection Return a certificate
503 READCERT @var{hexified_certid}|@var{keyid}
506 This function is used to read a certificate identified by
507 @var{hexified_certid} from the card. With OpenPGP cards the keyid
508 @code{OpenPGP.3} may be used to rad the certticate of version 2 cards.
511 @node Scdaemon READKEY
512 @subsection Return a public key
515 READKEY @var{hexified_certid}
518 Return the public key for the given cert or key ID as an standard
523 @node Scdaemon PKSIGN
524 @subsection Signing data with a Smartcard
526 To sign some data the caller should use the command
529 SETDATA @var{hexstring}
532 to tell @command{scdaemon} about the data to be signed. The data must be given in
533 hex notation. The actual signing is done using the command
539 where @var{keyid} is the hexified ID of the key to be used. The key id
540 may have been retrieved using the command @code{LEARN}. If another
541 hash algorithm than SHA-1 is used, that algorithm may be given like:
544 PKSIGN --hash=@var{algoname} @var{keyid}
547 With @var{algoname} are one of @code{sha1}, @code{rmd160} or @code{md5}.
550 @node Scdaemon PKDECRYPT
551 @subsection Decrypting data with a Smartcard
553 To decrypt some data the caller should use the command
556 SETDATA @var{hexstring}
559 to tell @command{scdaemon} about the data to be decrypted. The data
560 must be given in hex notation. The actual decryption is then done
564 PKDECRYPT @var{keyid}
567 where @var{keyid} is the hexified ID of the key to be used.
570 @node Scdaemon GETATTR
571 @subsection Read an attribute's value.
575 @node Scdaemon SETATTR
576 @subsection Update an attribute's value.
580 @node Scdaemon WRITEKEY
581 @subsection Write a key to a card.
584 WRITEKEY [--force] @var{keyid}
587 This command is used to store a secret key on a a smartcard. The
588 allowed keyids depend on the currently selected smartcard
589 application. The actual keydata is requested using the inquiry
590 @code{KEYDATA} and need to be provided without any protection. With
591 @option{--force} set an existing key under this @var{keyid} will get
592 overwritten. The key data is expected to be the usual canonical encoded
595 A PIN will be requested in most saes. This however depends on the
596 actual card application.
599 @node Scdaemon GENKEY
600 @subsection Generate a new key on-card.
604 @node Scdaemon RANDOM
605 @subsection Return random bytes generate on-card.
610 @node Scdaemon PASSWD
611 @subsection Change PINs.
614 PASSWD [--reset] [--nullpin] @var{chvno}
617 Change the PIN or reset the retry counter of the card holder
618 verification vector number @var{chvno}. The option @option{--nullpin}
619 is used to initialize the PIN of TCOS cards (6 byte NullPIN only).
622 @node Scdaemon CHECKPIN
623 @subsection Perform a VERIFY operation.
629 Perform a VERIFY operation without doing anything else. This may be
630 used to initialize a the PIN cache earlier to long lasting
631 operations. Its use is highly application dependent:
636 Perform a simple verify operation for CHV1 and CHV2, so that further
637 operations won't ask for CHV2 and it is possible to do a cheap check on
638 the PIN: If there is something wrong with the PIN entry system, only the
639 regular CHV will get blocked and not the dangerous CHV3. @var{idstr} is
640 the usual card's serial number in hex notation; an optional fingerprint
641 part will get ignored.
643 There is however a special mode if @var{idstr} is suffixed with the
644 literal string @code{[CHV3]}: In this case the Admin PIN is checked if
645 and only if the retry counter is still at 3.
651 @node Scdaemon RESTART
652 @subsection Perform a RESTART operation.
658 Restart the current connection; this is a kind of warm reset. It
659 deletes the context used by this connection but does not actually
662 This is used by gpg-agent to reuse a primary pipe connection and
663 may be used by clients to backup from a conflict in the serial
664 command; i.e. to select another application.
670 @subsection Send a verbatim APDU to the card.
673 APDU [--atr] [--more] [--exlen[=@var{n}]] [@var{hexstring}]
677 Send an APDU to the current reader. This command bypasses the high
678 level functions and sends the data directly to the card.
679 @var{hexstring} is expected to be a proper APDU. If @var{hexstring} is
680 not given no commands are send to the card; However the command will
681 implicitly check whether the card is ready for use.
683 Using the option @code{--atr} returns the ATR of the card as a status
684 message before any data like this:
686 S CARD-ATR 3BFA1300FF813180450031C173C00100009000B1
689 Using the option @code{--more} handles the card status word MORE_DATA
690 (61xx) and concatenate all reponses to one block.
692 Using the option @code{--exlen} the returned APDU may use extended
693 length up to N bytes. If N is not given a default value is used
700 @command{gpg-agent}(1),
704 @include see-also-note.texi