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 execpt for the fact that
62 only one 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.
98 This is mainly a debugging command, used to print the ATR
99 (Answer-To-Reset) of a card and exit immediately.
106 @node Scdaemon Options
107 @section Option Summary
111 @item --options @var{file}
113 Reads configuration from @var{file} instead of from the default
114 per-user configuration file. The default configuration file is named
115 @file{scdaemon.conf} and expected in the @file{.gnupg} directory directly
116 below the home directory of the user.
118 @include opt-homedir.texi
125 Outputs additional information while running.
126 You can increase the verbosity by giving several
127 verbose commands to @command{gpgsm}, such as @samp{-vv}.
129 @item --debug-level @var{level}
131 Select the debug level for investigating problems. @var{level} may be
138 some basic debug messages
140 more verbose debug messages
142 even more detailed messages
144 all of the debug messages you can get
147 How these messages are mapped to the actual debugging flags is not
148 specified and may change with newer releaes of this program. They are
149 however carefully selected to best aid in debugging.
152 All debugging options are subject to change and thus should not be used
153 by any application program. As the name says, they are only used as
154 helpers to debug problems.
158 @item --debug @var{flags}
160 This option is only useful for debugging and the behaviour may change at
161 any time without notice. FLAGS are bit encoded and may be given in
162 usual C-Syntax. The currently defined bits are:
168 values of big number integers
170 low level crypto operations
176 show memory statistics.
178 write hashed data to files named @code{dbgmd-000*}
180 trace Assuan protocol
182 trace APDU I/O to the card. This may reveal sensitive data.
187 Same as @code{--debug=0xffffffff}
189 @item --debug-wait @var{n}
191 When running in server mode, wait @var{n} seconds before entering the
192 actual processing loop and print the pid. This gives time to attach a
195 @item --debug-ccid-driver
197 Enable debug output from the included CCID driver for smartcards.
198 Using this option twice will also enable some tracing of the T=1
199 protocol. Note that this option may reveal sensitive data.
201 @item --debug-disable-ticker
202 @opindex debug-disable-ticker
203 This option disables all ticker functions like checking for card
206 @item --debug-allow-core-dump
207 @opindex debug-allow-core-dump
208 For security reasons we won't create a core dump when the process
209 aborts. For debugging purposes it is sometimes better to allow core
210 dump. This options enables it and also changes the working directory to
211 @file{/tmp} when running in @option{--server} mode.
216 Don't detach the process from the console. This is manly usefule for
219 @item --log-file @var{file}
221 Append all logging output to @var{file}. This is very helpful in
222 seeing what the agent actually does.
225 @item --pcsc-driver @var{library}
227 Use @var{library} to access the smartcard reader. The current default
228 is @file{libpcsclite.so}. Instead of using this option you might also
229 want to install a symbolic link to the default file name
230 (e.g. from @file{libpcsclite.so.1}).
232 @item --ctapi-driver @var{library}
233 @opindex ctapi-driver
234 Use @var{library} to access the smartcard reader. The current default
235 is @file{libtowitoko.so}. Note that the use of this interface is
236 deprecated; it may be removed in future releases.
239 @opindex disable-ccid
240 Disable the integrated support for CCID compliant readers. This
241 allows to fall back to one of the other drivers even if the internal
242 CCID driver can handle the reader. Note, that CCID support is only
243 available if libusb was available at build time.
245 @item --reader-port @var{number_or_string}
247 This option may be used to specify the port of the card terminal. A
248 value of 0 refers to the first serial device; add 32768 to access USB
249 devices. The default is 32768 (first USB device). PC/SC or CCID
250 readers might need a string here; run the program in verbose mode to get
251 a list of available readers. The default is then the first reader
254 @item --disable-keypad
255 @opindex disable-keypad
256 Even if a card reader features a keypad, do not try to use it.
263 This enables the use of Admin class commands for card applications
264 where this is supported. Currently we support it for the OpenPGP
265 card. Deny is the default. This commands is useful to inhibit
266 accidental access to admin class command which could ultimately lock
267 the card through worng PIN numbers.
269 @item --disable-application @var{name}
270 @opindex disable-application
271 This option disables the use of the card application named
272 @var{name}. This is mainly useful for debugging or if a application
273 with lower priority should be used by default.
277 All the long options may also be given in the configuration file after
278 stripping off the two leading dashes.
281 @mansect card applications
282 @node Card applications
283 @section Description of card applications
285 @command{scdaemon} supports the card applications as described below.
288 * OpenPGP Card:: The OpenPGP card application
289 * NKS Card:: The Telesec NetKey card application
290 * DINSIG Card:: The DINSIG card application
291 * PKCS#15 Card:: The PKCS#15 card application
295 @subsection The OpenPGP card application ``openpgp''
297 This application is currently only used by @command{gpg} but may in
298 future also be useful with @command{gpgsm}.
300 The specification for such a card is available at
301 @uref{http://g10code.com/docs/openpgp-card-1.0.pdf}.
304 @subsection The Telesec NetKey card ``nks''
306 This is the main application of the Telesec cards as available in
307 Germany. It is a superset of the German DINSIG card. The card is
308 used by @command{gpgsm}.
311 @subsection The DINSIG card application ``dinsig''
313 This is an application as described in the German draft standard
314 @emph{DIN V 66291-1}. It is intended to be used by cards supporteing
315 the German signature law and its bylaws (SigG and SigV).
318 @subsection The PKCS#15 card application ``p15''
320 This is common fraqmework for smart card applications. It is used by
324 @c *******************************************
325 @c *************** ****************
326 @c *************** FILES ****************
327 @c *************** ****************
328 @c *******************************************
330 @node Scdaemon Configuration
331 @section Configuration files
333 There are a few configuration files to control certain aspects of
334 @command{scdaemons}'s operation. Unless noted, they are expected in the
335 current home directory (@pxref{option --homedir}).
340 @cindex scdaemon.conf
341 This is the standard configuration file read by @command{scdaemon} on
342 startup. It may contain any valid long option; the leading two dashes
343 may not be entered and the option may not be abbreviated. This default
344 name may be changed on the command line (@pxref{option --options}).
348 If this file is present and executable, it will be called on veyer card
349 reader's status changed. An example of this script is provided with the
352 @item reader_@var{n}.status
353 This file is created by @command{sdaemon} to let other applications now
354 about reader status changes. Its use is now deprecated in favor of
364 @node Scdaemon Examples
367 @c man begin EXAMPLES
370 $ scdaemon --server -v
379 @node Scdaemon Protocol
380 @section Scdaemon's Assuan Protocol
382 The SC-Daemon should be started by the system to provide access to
383 external tokens. Using Smartcards on a multi-user system does not
384 make much sense expcet for system services, but in this case no
385 regular user accounts are hosted on the machine.
387 A client connects to the SC-Daemon by connecting to the socket named
388 @file{/var/run/scdaemon/socket}, configuration information is read from
389 @var{/etc/scdaemon.conf}
391 Each connection acts as one session, SC-Daemon takes care of
392 syncronizing access to a token between sessions.
395 * Scdaemon SERIALNO:: Return the serial number.
396 * Scdaemon LEARN:: Read all useful information from the card.
397 * Scdaemon READCERT:: Return a certificate.
398 * Scdaemon READKEY:: Return a public key.
399 * Scdaemon PKSIGN:: Signing data with a Smartcard.
400 * Scdaemon PKDECRYPT:: Decrypting data with a Smartcard.
401 * Scdaemon GETATTR:: Read an attribute's value.
402 * Scdaemon SETATTR:: Update an attribute's value.
403 * Scdaemon WRITEKEY:: Write a key to a card.
404 * Scdaemon GENKEY:: Generate a new key on-card.
405 * Scdaemon RANDOM:: Return random bytes generate on-card.
406 * Scdaemon PASSWD:: Change PINs.
407 * Scdaemon CHECKPIN:: Perform a VERIFY operation.
408 * Scdaemon RESTART:: Restart connection
409 * Scdaemon APDU:: Send a verbatim APDU to the card
412 @node Scdaemon SERIALNO
413 @subsection Return the serial number
415 This command should be used to check for the presence of a card. It is
416 special in that it can be used to reset the card. Most other commands
417 will return an error when a card change has been detected and the use of
418 this function is therefore required.
420 Background: We want to keep the client clear of handling card changes
421 between operations; i.e. the client can assume that all operations are
422 done on the same card unless he call this function.
428 Return the serial number of the card using a status reponse like:
431 S SERIALNO D27600000000000000000000 0
434 The trailing 0 should be ignored for now, it is reserved for a future
435 extension. The serial number is the hex encoded value identified by
436 the @code{0x5A} tag in the GDO file (FIX=0x2F02).
441 @subsection Read all useful information from the card
447 Learn all useful information of the currently inserted card. When
448 used without the force options, the command might do an INQUIRE
452 INQUIRE KNOWNCARDP <hexstring_with_serialNumber> <timestamp>
455 The client should just send an @code{END} if the processing should go on
456 or a @code{CANCEL} to force the function to terminate with a cancel
457 error message. The response of this command is a list of status lines
461 S KEYPAIRINFO @var{hexstring_with_keygrip} @var{hexstring_with_id}
464 If there is no certificate yet stored on the card a single "X" is
465 returned in @var{hexstring_with_keygrip}.
467 @node Scdaemon READCERT
468 @subsection Return a certificate
471 READCERT @var{hexified_certid}
474 This function is used to read a certificate identified by
475 @var{hexified_certid} from the card.
478 @node Scdaemon READKEY
479 @subsection Return a public key
482 READKEY @var{hexified_certid}
485 Return the public key for the given cert or key ID as an standard
490 @node Scdaemon PKSIGN
491 @subsection Signing data with a Smartcard
493 To sign some data the caller should use the command
496 SETDATA @var{hexstring}
499 to tell @command{scdaemon} about the data to be signed. The data must be given in
500 hex notation. The actual signing is done using the command
506 where @var{keyid} is the hexified ID of the key to be used. The key id
507 may have been retrieved using the command @code{LEARN}. If another
508 hash algorithm than SHA-1 is used, that algorithm may be given like:
511 PKSIGN --hash=@var{algoname} @var{keyid}
514 With @var{algoname} are one of @code{sha1}, @code{rmd160} or @code{md5}.
517 @node Scdaemon PKDECRYPT
518 @subsection Decrypting data with a Smartcard
520 To decrypt some data the caller should use the command
523 SETDATA @var{hexstring}
526 to tell @command{scdaemon} about the data to be decrypted. The data
527 must be given in hex notation. The actual decryption is then done
531 PKDECRYPT @var{keyid}
534 where @var{keyid} is the hexified ID of the key to be used.
537 @node Scdaemon GETATTR
538 @subsection Read an attribute's value.
542 @node Scdaemon SETATTR
543 @subsection Update an attribute's value.
547 @node Scdaemon WRITEKEY
548 @subsection Write a key to a card.
551 WRITEKEY [--force] @var{keyid}
554 This command is used to store a secret key on a a smartcard. The
555 allowed keyids depend on the currently selected smartcard
556 application. The actual keydata is requested using the inquiry
557 @code{KEYDATA} and need to be provided without any protection. With
558 @option{--force} set an existing key under this @var{keyid} will get
559 overwritten. The key data is expected to be the usual canonical encoded
562 A PIN will be requested in most saes. This however depends on the
563 actual card application.
566 @node Scdaemon GENKEY
567 @subsection Generate a new key on-card.
571 @node Scdaemon RANDOM
572 @subsection Return random bytes generate on-card.
577 @node Scdaemon PASSWD
578 @subsection Change PINs.
581 PASSWD [--reset] @var{chvno}
584 Change the PIN or reset the retry counter of the card holder
585 verification vector number @var{chvno}.
588 @node Scdaemon CHECKPIN
589 @subsection Perform a VERIFY operation.
595 Perform a VERIFY operation without doing anything else. This may be
596 used to initialize a the PIN cache earlier to long lasting
597 operations. Its use is highly application dependent:
602 Perform a simple verify operation for CHV1 and CHV2, so that further
603 operations won't ask for CHV2 and it is possible to do a cheap check on
604 the PIN: If there is something wrong with the PIN entry system, only the
605 regular CHV will get blocked and not the dangerous CHV3. @var{idstr} is
606 the usual card's serial number in hex notation; an optional fingerprint
607 part will get ignored.
609 There is however a special mode if @var{idstr} is suffixed with the
610 literal string @code{[CHV3]}: In this case the Admin PIN is checked if
611 and only if the retry counter is still at 3.
617 @node Scdaemon RESTART
618 @subsection Perform a RESTART operation.
624 Restart the current connection; this is a kind of warm reset. It
625 deletes the context used by this connection but does not actually
628 This is used by gpg-agent to reuse a primary pipe connection and
629 may be used by clients to backup from a conflict in the serial
630 command; i.e. to select another application.
636 @subsection Send a verbatim APDU to the card.
639 APDU [--atr] [--more] [@var{hexstring}]
643 Send an APDU to the current reader. This command bypasses the high
644 level functions and sends the data directly to the card.
645 @var{hexstring} is expected to be a proper APDU. If @var{hexstring} is
646 not given no commands are send to the card; However the command will
647 implictly check whether the card is ready for use.
649 Using the option @code{--atr} returns the ATR of the card as a status
650 message before any data like this:
652 S CARD-ATR 3BFA1300FF813180450031C173C00100009000B1
655 Using the option @code{--more} handles the card status word MORE_DATA
656 (61xx) and concatenate all reponses to one block.
662 @command{gpg-agent}(1),
666 @include see-also-note.texi