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.
7 @node Invoking SCDAEMON
8 @chapter Invoking the SCDAEMON
9 @cindex SCDAEMON command options
10 @cindex command options
11 @cindex options, SCDAEMON command
16 \- Smartcard daemon for the GnuPG system
41 The @command{scdaemon} is a daemon to manage smartcards. It is usually
42 invoked by @command{gpg-agent} and in general not used directly.
45 @xref{Option Index}, for an index to @command{scdaemon}'s commands and
50 * Scdaemon Commands:: List of all commands.
51 * Scdaemon Options:: List of all options.
52 * Card applications:: Description of card applications.
53 * Scdaemon Configuration:: Configuration files.
54 * Scdaemon Examples:: Some usage examples.
55 * Scdaemon Protocol:: The protocol the daemon uses.
60 @node Scdaemon Commands
63 Commands are not distinguished from options except for the fact that
64 only one command is allowed.
69 Print the program version and licensing information. Note that you cannot
70 abbreviate this command.
74 Print a usage message summarizing the most useful command-line options.
75 Note that you cannot abbreviate this command.
79 Print a list of all available options and commands. Note that you cannot
80 abbreviate this command.
84 Run in server mode and wait for commands on the @code{stdin}. The
85 default mode is to create a socket and listen for commands there.
89 Run in server mode and wait for commands on the @code{stdin} as well as
90 on an additional Unix Domain socket. The server command @code{GETINFO}
91 may be used to get the name of that extra socket.
95 Run the program in the background. This option is required to prevent
96 it from being accidentally running in the background.
103 @node Scdaemon Options
104 @section Option Summary
108 @item --options @var{file}
110 Reads configuration from @var{file} instead of from the default
111 per-user configuration file. The default configuration file is named
112 @file{scdaemon.conf} and expected in the @file{.gnupg} directory directly
113 below the home directory of the user.
115 @include opt-homedir.texi
122 Outputs additional information while running.
123 You can increase the verbosity by giving several
124 verbose commands to @command{gpgsm}, such as @samp{-vv}.
126 @item --debug-level @var{level}
128 Select the debug level for investigating problems. @var{level} may be
129 a numeric value or a keyword:
133 No debugging at all. A value of less than 1 may be used instead of
136 Some basic debug messages. A value between 1 and 2 may be used
137 instead of the keyword.
139 More verbose debug messages. A value between 3 and 5 may be used
140 instead of the keyword.
142 Even more detailed messages. A value between 6 and 8 may be used
143 instead of the keyword.
145 All of the debug messages you can get. A value greater than 8 may be
146 used instead of the keyword. The creation of hash tracing files is
147 only enabled if the keyword is used.
150 How these messages are mapped to the actual debugging flags is not
151 specified and may change with newer releases of this program. They are
152 however carefully selected to best aid in debugging.
155 All debugging options are subject to change and thus should not be used
156 by any application program. As the name says, they are only used as
157 helpers to debug problems.
161 @item --debug @var{flags}
163 This option is only useful for debugging and the behavior may change at
164 any time without notice. FLAGS are bit encoded and may be given in
165 usual C-Syntax. The currently defined bits are:
171 values of big number integers
173 low level crypto operations
179 show memory statistics
181 write hashed data to files named @code{dbgmd-000*}
183 trace Assuan protocol.
184 See also option @option{--debug-assuan-log-cats}.
186 trace APDU I/O to the card. This may reveal sensitive data.
188 trace some card reader related function calls.
193 Same as @code{--debug=0xffffffff}
195 @item --debug-wait @var{n}
197 When running in server mode, wait @var{n} seconds before entering the
198 actual processing loop and print the pid. This gives time to attach a
201 @item --debug-ccid-driver
203 Enable debug output from the included CCID driver for smartcards.
204 Using this option twice will also enable some tracing of the T=1
205 protocol. Note that this option may reveal sensitive data.
207 @item --debug-disable-ticker
208 @opindex debug-disable-ticker
209 This option disables all ticker functions like checking for card
212 @item --debug-allow-core-dump
213 @opindex debug-allow-core-dump
214 For security reasons we won't create a core dump when the process
215 aborts. For debugging purposes it is sometimes better to allow core
216 dump. This option enables it and also changes the working directory to
217 @file{/tmp} when running in @option{--server} mode.
219 @item --debug-log-tid
220 @opindex debug-log-tid
221 This option appends a thread ID to the PID in the log output.
223 @item --debug-assuan-log-cats @var{cats}
224 @opindex debug-assuan-log-cats
225 @efindex ASSUAN_DEBUG
226 Changes the active Libassuan logging categories to @var{cats}. The
227 value for @var{cats} is an unsigned integer given in usual C-Syntax.
228 A value of 0 switches to a default category. If this option is not
229 used the categories are taken from the environment variable
230 @code{ASSUAN_DEBUG}. Note that this option has only an effect if the
231 Assuan debug flag has also been with the option @option{--debug}. For
232 a list of categories see the Libassuan manual.
236 Don't detach the process from the console. This is mainly useful for
239 @item --listen-backlog @var{n}
240 @opindex listen-backlog
241 Set the size of the queue for pending connections. The default is 64.
242 This option has an effect only if @option{--multi-server} is also
245 @item --log-file @var{file}
247 Append all logging output to @var{file}. This is very helpful in
248 seeing what the agent actually does. Use @file{socket://} to log to
252 @item --pcsc-driver @var{library}
254 Use @var{library} to access the smartcard reader. The current default
255 is @file{libpcsclite.so}. Instead of using this option you might also
256 want to install a symbolic link to the default file name
257 (e.g. from @file{libpcsclite.so.1}).
259 @item --ctapi-driver @var{library}
260 @opindex ctapi-driver
261 Use @var{library} to access the smartcard reader. The current default
262 is @file{libtowitoko.so}. Note that the use of this interface is
263 deprecated; it may be removed in future releases.
266 @opindex disable-ccid
267 Disable the integrated support for CCID compliant readers. This
268 allows falling back to one of the other drivers even if the internal
269 CCID driver can handle the reader. Note, that CCID support is only
270 available if libusb was available at build time.
272 @item --reader-port @var{number_or_string}
274 This option may be used to specify the port of the card terminal. A
275 value of 0 refers to the first serial device; add 32768 to access USB
276 devices. The default is 32768 (first USB device). PC/SC or CCID
277 readers might need a string here; run the program in verbose mode to get
278 a list of available readers. The default is then the first reader
281 To get a list of available CCID readers you may use this command:
284 echo scd getinfo reader_list \
285 | gpg-connect-agent --decode | awk '/^D/ @{print $2@}'
289 @item --card-timeout @var{n}
290 @opindex card-timeout
291 If @var{n} is not 0 and no client is actively using the card, the card
292 will be powered down after @var{n} seconds. Powering down the card
293 avoids a potential risk of damaging a card when used with certain
294 cheap readers. This also allows applications that are not aware of
295 Scdaemon to access the card. The disadvantage of using a card timeout
296 is that accessing the card takes longer and that the user needs to
297 enter the PIN again after the next power up.
299 Note that with the current version of Scdaemon the card is powered
300 down immediately at the next timer tick for any value of @var{n} other
303 @item --enable-pinpad-varlen
304 @opindex enable-pinpad-varlen
305 Please specify this option when the card reader supports variable
306 length input for pinpad (default is no). For known readers (listed in
307 ccid-driver.c and apdu.c), this option is not needed. Note that if
308 your card reader doesn't supports variable length input but you want
309 to use it, you need to specify your pinpad request on your card.
312 @item --disable-pinpad
313 @opindex disable-pinpad
314 Even if a card reader features a pinpad, do not try to use it.
320 This option disables the use of admin class commands for card
321 applications where this is supported. Currently we support it for the
322 OpenPGP card. This option is useful to inhibit accidental access to
323 admin class command which could ultimately lock the card through wrong
324 PIN numbers. Note that GnuPG versions older than 2.0.11 featured an
325 @option{--allow-admin} option which was required to use such admin
326 commands. This option has no more effect today because the default is
327 now to allow admin commands.
329 @item --disable-application @var{name}
330 @opindex disable-application
331 This option disables the use of the card application named
332 @var{name}. This is mainly useful for debugging or if a application
333 with lower priority should be used by default.
337 All the long options may also be given in the configuration file after
338 stripping off the two leading dashes.
341 @mansect card applications
342 @node Card applications
343 @section Description of card applications
345 @command{scdaemon} supports the card applications as described below.
348 * OpenPGP Card:: The OpenPGP card application
349 * NKS Card:: The Telesec NetKey card application
350 * DINSIG Card:: The DINSIG card application
351 * PKCS#15 Card:: The PKCS#15 card application
352 * Geldkarte Card:: The Geldkarte application
353 * SmartCard-HSM:: The SmartCard-HSM application
354 * Undefined Card:: The Undefined stub application
358 @subsection The OpenPGP card application ``openpgp''
360 This application is currently only used by @command{gpg} but may in
361 future also be useful with @command{gpgsm}. Version 1 and version 2 of
362 the card is supported.
365 The specifications for these cards are available at@*
366 @uref{http://g10code.com/docs/openpgp-card-1.0.pdf} and@*
367 @uref{http://g10code.com/docs/openpgp-card-2.0.pdf}.
370 @subsection The Telesec NetKey card ``nks''
372 This is the main application of the Telesec cards as available in
373 Germany. It is a superset of the German DINSIG card. The card is
374 used by @command{gpgsm}.
377 @subsection The DINSIG card application ``dinsig''
379 This is an application as described in the German draft standard
380 @emph{DIN V 66291-1}. It is intended to be used by cards supporting
381 the German signature law and its bylaws (SigG and SigV).
384 @subsection The PKCS#15 card application ``p15''
386 This is common framework for smart card applications. It is used by
390 @subsection The Geldkarte card application ``geldkarte''
392 This is a simple application to display information of a German
393 Geldkarte. The Geldkarte is a small amount debit card application which
394 comes with almost all German banking cards.
397 @subsection The SmartCard-HSM card application ``sc-hsm''
399 This application adds read-only support for keys and certificates
400 stored on a @uref{http://www.smartcard-hsm.com, SmartCard-HSM}.
402 To generate keys and store certifiates you may use
403 @uref{https://github.com/OpenSC/OpenSC/wiki/SmartCardHSM, OpenSC} or
404 the tools from @uref{http://www.openscdp.org, OpenSCDP}.
406 The SmartCard-HSM cards requires a card reader that supports Extended
410 @subsection The Undefined card application ``undefined''
412 This is a stub application to allow the use of the APDU command even
413 if no supported application is found on the card. This application is
414 not used automatically but must be explicitly requested using the
418 @c *******************************************
419 @c *************** ****************
420 @c *************** FILES ****************
421 @c *************** ****************
422 @c *******************************************
424 @node Scdaemon Configuration
425 @section Configuration files
427 There are a few configuration files to control certain aspects of
428 @command{scdaemons}'s operation. Unless noted, they are expected in the
429 current home directory (@pxref{option --homedir}).
434 @cindex scdaemon.conf
435 This is the standard configuration file read by @command{scdaemon} on
436 startup. It may contain any valid long option; the leading two dashes
437 may not be entered and the option may not be abbreviated. This default
438 name may be changed on the command line (@pxref{option --options}).
442 If this file is present and executable, it will be called on every card
443 reader's status change. An example of this script is provided with the
446 @item reader_@var{n}.status
447 This file is created by @command{scdaemon} to let other applications now
448 about reader status changes. Its use is now deprecated in favor of
458 @node Scdaemon Examples
461 @c man begin EXAMPLES
464 $ scdaemon --server -v
473 @node Scdaemon Protocol
474 @section Scdaemon's Assuan Protocol
476 The SC-Daemon should be started by the system to provide access to
477 external tokens. Using Smartcards on a multi-user system does not
478 make much sense except for system services, but in this case no
479 regular user accounts are hosted on the machine.
481 A client connects to the SC-Daemon by connecting to the socket named
482 @file{@value{LOCALRUNDIR}/scdaemon/socket}, configuration information
483 is read from @var{@value{SYSCONFDIR}/scdaemon.conf}
485 Each connection acts as one session, SC-Daemon takes care of
486 synchronizing access to a token between sessions.
489 * Scdaemon SERIALNO:: Return the serial number.
490 * Scdaemon LEARN:: Read all useful information from the card.
491 * Scdaemon READCERT:: Return a certificate.
492 * Scdaemon READKEY:: Return a public key.
493 * Scdaemon PKSIGN:: Signing data with a Smartcard.
494 * Scdaemon PKDECRYPT:: Decrypting data with a Smartcard.
495 * Scdaemon GETATTR:: Read an attribute's value.
496 * Scdaemon SETATTR:: Update an attribute's value.
497 * Scdaemon WRITEKEY:: Write a key to a card.
498 * Scdaemon GENKEY:: Generate a new key on-card.
499 * Scdaemon RANDOM:: Return random bytes generated on-card.
500 * Scdaemon PASSWD:: Change PINs.
501 * Scdaemon CHECKPIN:: Perform a VERIFY operation.
502 * Scdaemon RESTART:: Restart connection
503 * Scdaemon APDU:: Send a verbatim APDU to the card
506 @node Scdaemon SERIALNO
507 @subsection Return the serial number
509 This command should be used to check for the presence of a card. It is
510 special in that it can be used to reset the card. Most other commands
511 will return an error when a card change has been detected and the use of
512 this function is therefore required.
514 Background: We want to keep the client clear of handling card changes
515 between operations; i.e. the client can assume that all operations are
516 done on the same card unless he call this function.
522 Return the serial number of the card using a status response like:
525 S SERIALNO D27600000000000000000000
528 The serial number is the hex encoded value identified by
529 the @code{0x5A} tag in the GDO file (FIX=0x2F02).
534 @subsection Read all useful information from the card
540 Learn all useful information of the currently inserted card. When
541 used without the @option{--force} option, the command might do an INQUIRE
545 INQUIRE KNOWNCARDP <hexstring_with_serialNumber>
548 The client should just send an @code{END} if the processing should go on
549 or a @code{CANCEL} to force the function to terminate with a cancel
550 error message. The response of this command is a list of status lines
554 S KEYPAIRINFO @var{hexstring_with_keygrip} @var{hexstring_with_id}
557 If there is no certificate yet stored on the card a single "X" is
558 returned in @var{hexstring_with_keygrip}.
560 @node Scdaemon READCERT
561 @subsection Return a certificate
564 READCERT @var{hexified_certid}|@var{keyid}
567 This function is used to read a certificate identified by
568 @var{hexified_certid} from the card. With OpenPGP cards the keyid
569 @code{OpenPGP.3} may be used to read the certificate of version 2 cards.
572 @node Scdaemon READKEY
573 @subsection Return a public key
576 READKEY @var{hexified_certid}
579 Return the public key for the given cert or key ID as an standard
584 @node Scdaemon PKSIGN
585 @subsection Signing data with a Smartcard
587 To sign some data the caller should use the command
590 SETDATA @var{hexstring}
593 to tell @command{scdaemon} about the data to be signed. The data must be given in
594 hex notation. The actual signing is done using the command
600 where @var{keyid} is the hexified ID of the key to be used. The key id
601 may have been retrieved using the command @code{LEARN}. If another
602 hash algorithm than SHA-1 is used, that algorithm may be given like:
605 PKSIGN --hash=@var{algoname} @var{keyid}
608 With @var{algoname} are one of @code{sha1}, @code{rmd160} or @code{md5}.
611 @node Scdaemon PKDECRYPT
612 @subsection Decrypting data with a Smartcard
614 To decrypt some data the caller should use the command
617 SETDATA @var{hexstring}
620 to tell @command{scdaemon} about the data to be decrypted. The data
621 must be given in hex notation. The actual decryption is then done
625 PKDECRYPT @var{keyid}
628 where @var{keyid} is the hexified ID of the key to be used.
630 If the card is aware of the apdding format a status line with padding
631 information is send before the plaintext data. The key for this
632 status line is @code{PADDING} with the only defined value being 0 and
633 meaning padding has been removed.
635 @node Scdaemon GETATTR
636 @subsection Read an attribute's value
640 @node Scdaemon SETATTR
641 @subsection Update an attribute's value
645 @node Scdaemon WRITEKEY
646 @subsection Write a key to a card
649 WRITEKEY [--force] @var{keyid}
652 This command is used to store a secret key on a smartcard. The
653 allowed keyids depend on the currently selected smartcard
654 application. The actual keydata is requested using the inquiry
655 @code{KEYDATA} and need to be provided without any protection. With
656 @option{--force} set an existing key under this @var{keyid} will get
657 overwritten. The key data is expected to be the usual canonical encoded
660 A PIN will be requested in most cases. This however depends on the
661 actual card application.
664 @node Scdaemon GENKEY
665 @subsection Generate a new key on-card
669 @node Scdaemon RANDOM
670 @subsection Return random bytes generated on-card
675 @node Scdaemon PASSWD
676 @subsection Change PINs
679 PASSWD [--reset] [--nullpin] @var{chvno}
682 Change the PIN or reset the retry counter of the card holder
683 verification vector number @var{chvno}. The option @option{--nullpin}
684 is used to initialize the PIN of TCOS cards (6 byte NullPIN only).
687 @node Scdaemon CHECKPIN
688 @subsection Perform a VERIFY operation
694 Perform a VERIFY operation without doing anything else. This may be
695 used to initialize a the PIN cache earlier to long lasting
696 operations. Its use is highly application dependent:
701 Perform a simple verify operation for CHV1 and CHV2, so that further
702 operations won't ask for CHV2 and it is possible to do a cheap check on
703 the PIN: If there is something wrong with the PIN entry system, only the
704 regular CHV will get blocked and not the dangerous CHV3. @var{idstr} is
705 the usual card's serial number in hex notation; an optional fingerprint
706 part will get ignored.
708 There is however a special mode if @var{idstr} is suffixed with the
709 literal string @code{[CHV3]}: In this case the Admin PIN is checked if
710 and only if the retry counter is still at 3.
716 @node Scdaemon RESTART
717 @subsection Perform a RESTART operation
723 Restart the current connection; this is a kind of warm reset. It
724 deletes the context used by this connection but does not actually
727 This is used by gpg-agent to reuse a primary pipe connection and
728 may be used by clients to backup from a conflict in the serial
729 command; i.e. to select another application.
735 @subsection Send a verbatim APDU to the card
738 APDU [--atr] [--more] [--exlen[=@var{n}]] [@var{hexstring}]
742 Send an APDU to the current reader. This command bypasses the high
743 level functions and sends the data directly to the card.
744 @var{hexstring} is expected to be a proper APDU. If @var{hexstring} is
745 not given no commands are send to the card; However the command will
746 implicitly check whether the card is ready for use.
748 Using the option @code{--atr} returns the ATR of the card as a status
749 message before any data like this:
751 S CARD-ATR 3BFA1300FF813180450031C173C00100009000B1
754 Using the option @code{--more} handles the card status word MORE_DATA
755 (61xx) and concatenate all responses to one block.
757 Using the option @code{--exlen} the returned APDU may use extended
758 length up to N bytes. If N is not given a default value is used
765 @command{gpg-agent}(1),
769 @include see-also-note.texi