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 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 --log-file @var{file}
241 Append all logging output to @var{file}. This is very helpful in
242 seeing what the agent actually does. Use @file{socket://} to log to
246 @item --pcsc-driver @var{library}
248 Use @var{library} to access the smartcard reader. The current default
249 is @file{libpcsclite.so}. Instead of using this option you might also
250 want to install a symbolic link to the default file name
251 (e.g. from @file{libpcsclite.so.1}).
253 @item --ctapi-driver @var{library}
254 @opindex ctapi-driver
255 Use @var{library} to access the smartcard reader. The current default
256 is @file{libtowitoko.so}. Note that the use of this interface is
257 deprecated; it may be removed in future releases.
260 @opindex disable-ccid
261 Disable the integrated support for CCID compliant readers. This
262 allows falling back to one of the other drivers even if the internal
263 CCID driver can handle the reader. Note, that CCID support is only
264 available if libusb was available at build time.
266 @item --reader-port @var{number_or_string}
268 This option may be used to specify the port of the card terminal. A
269 value of 0 refers to the first serial device; add 32768 to access USB
270 devices. The default is 32768 (first USB device). PC/SC or CCID
271 readers might need a string here; run the program in verbose mode to get
272 a list of available readers. The default is then the first reader
275 To get a list of available CCID readers you may use this command:
278 echo scd getinfo reader_list \
279 | gpg-connect-agent --decode | awk '/^D/ @{print $2@}'
283 @item --card-timeout @var{n}
284 @opindex card-timeout
285 If @var{n} is not 0 and no client is actively using the card, the card
286 will be powered down after @var{n} seconds. Powering down the card
287 avoids a potential risk of damaging a card when used with certain
288 cheap readers. This also allows applications that are not aware of
289 Scdaemon to access the card. The disadvantage of using a card timeout
290 is that accessing the card takes longer and that the user needs to
291 enter the PIN again after the next power up.
293 Note that with the current version of Scdaemon the card is powered
294 down immediately at the next timer tick for any value of @var{n} other
297 @item --enable-pinpad-varlen
298 @opindex enable-pinpad-varlen
299 Please specify this option when the card reader supports variable
300 length input for pinpad (default is no). For known readers (listed in
301 ccid-driver.c and apdu.c), this option is not needed. Note that if
302 your card reader doesn't supports variable length input but you want
303 to use it, you need to specify your pinpad request on your card.
306 @item --disable-pinpad
307 @opindex disable-pinpad
308 Even if a card reader features a pinpad, do not try to use it.
314 This option disables the use of admin class commands for card
315 applications where this is supported. Currently we support it for the
316 OpenPGP card. This option is useful to inhibit accidental access to
317 admin class command which could ultimately lock the card through wrong
318 PIN numbers. Note that GnuPG versions older than 2.0.11 featured an
319 @option{--allow-admin} option which was required to use such admin
320 commands. This option has no more effect today because the default is
321 now to allow admin commands.
323 @item --disable-application @var{name}
324 @opindex disable-application
325 This option disables the use of the card application named
326 @var{name}. This is mainly useful for debugging or if a application
327 with lower priority should be used by default.
331 All the long options may also be given in the configuration file after
332 stripping off the two leading dashes.
335 @mansect card applications
336 @node Card applications
337 @section Description of card applications
339 @command{scdaemon} supports the card applications as described below.
342 * OpenPGP Card:: The OpenPGP card application
343 * NKS Card:: The Telesec NetKey card application
344 * DINSIG Card:: The DINSIG card application
345 * PKCS#15 Card:: The PKCS#15 card application
346 * Geldkarte Card:: The Geldkarte application
347 * SmartCard-HSM:: The SmartCard-HSM application
348 * Undefined Card:: The Undefined stub application
352 @subsection The OpenPGP card application ``openpgp''
354 This application is currently only used by @command{gpg} but may in
355 future also be useful with @command{gpgsm}. Version 1 and version 2 of
356 the card is supported.
359 The specifications for these cards are available at@*
360 @uref{http://g10code.com/docs/openpgp-card-1.0.pdf} and@*
361 @uref{http://g10code.com/docs/openpgp-card-2.0.pdf}.
364 @subsection The Telesec NetKey card ``nks''
366 This is the main application of the Telesec cards as available in
367 Germany. It is a superset of the German DINSIG card. The card is
368 used by @command{gpgsm}.
371 @subsection The DINSIG card application ``dinsig''
373 This is an application as described in the German draft standard
374 @emph{DIN V 66291-1}. It is intended to be used by cards supporting
375 the German signature law and its bylaws (SigG and SigV).
378 @subsection The PKCS#15 card application ``p15''
380 This is common framework for smart card applications. It is used by
384 @subsection The Geldkarte card application ``geldkarte''
386 This is a simple application to display information of a German
387 Geldkarte. The Geldkarte is a small amount debit card application which
388 comes with almost all German banking cards.
391 @subsection The SmartCard-HSM card application ``sc-hsm''
393 This application adds read-only support for keys and certificates
394 stored on a @uref{http://www.smartcard-hsm.com, SmartCard-HSM}.
396 To generate keys and store certifiates you may use
397 @uref{https://github.com/OpenSC/OpenSC/wiki/SmartCardHSM, OpenSC} or
398 the tools from @uref{http://www.openscdp.org, OpenSCDP}.
400 The SmartCard-HSM cards requires a card reader that supports Extended
404 @subsection The Undefined card application ``undefined''
406 This is a stub application to allow the use of the APDU command even
407 if no supported application is found on the card. This application is
408 not used automatically but must be explicitly requested using the
412 @c *******************************************
413 @c *************** ****************
414 @c *************** FILES ****************
415 @c *************** ****************
416 @c *******************************************
418 @node Scdaemon Configuration
419 @section Configuration files
421 There are a few configuration files to control certain aspects of
422 @command{scdaemons}'s operation. Unless noted, they are expected in the
423 current home directory (@pxref{option --homedir}).
428 @cindex scdaemon.conf
429 This is the standard configuration file read by @command{scdaemon} on
430 startup. It may contain any valid long option; the leading two dashes
431 may not be entered and the option may not be abbreviated. This default
432 name may be changed on the command line (@pxref{option --options}).
436 If this file is present and executable, it will be called on every card
437 reader's status change. An example of this script is provided with the
440 @item reader_@var{n}.status
441 This file is created by @command{scdaemon} to let other applications now
442 about reader status changes. Its use is now deprecated in favor of
452 @node Scdaemon Examples
455 @c man begin EXAMPLES
458 $ scdaemon --server -v
467 @node Scdaemon Protocol
468 @section Scdaemon's Assuan Protocol
470 The SC-Daemon should be started by the system to provide access to
471 external tokens. Using Smartcards on a multi-user system does not
472 make much sense except for system services, but in this case no
473 regular user accounts are hosted on the machine.
475 A client connects to the SC-Daemon by connecting to the socket named
476 @file{@value{LOCALRUNDIR}/scdaemon/socket}, configuration information
477 is read from @var{@value{SYSCONFDIR}/scdaemon.conf}
479 Each connection acts as one session, SC-Daemon takes care of
480 synchronizing access to a token between sessions.
483 * Scdaemon SERIALNO:: Return the serial number.
484 * Scdaemon LEARN:: Read all useful information from the card.
485 * Scdaemon READCERT:: Return a certificate.
486 * Scdaemon READKEY:: Return a public key.
487 * Scdaemon PKSIGN:: Signing data with a Smartcard.
488 * Scdaemon PKDECRYPT:: Decrypting data with a Smartcard.
489 * Scdaemon GETATTR:: Read an attribute's value.
490 * Scdaemon SETATTR:: Update an attribute's value.
491 * Scdaemon WRITEKEY:: Write a key to a card.
492 * Scdaemon GENKEY:: Generate a new key on-card.
493 * Scdaemon RANDOM:: Return random bytes generated on-card.
494 * Scdaemon PASSWD:: Change PINs.
495 * Scdaemon CHECKPIN:: Perform a VERIFY operation.
496 * Scdaemon RESTART:: Restart connection
497 * Scdaemon APDU:: Send a verbatim APDU to the card
500 @node Scdaemon SERIALNO
501 @subsection Return the serial number
503 This command should be used to check for the presence of a card. It is
504 special in that it can be used to reset the card. Most other commands
505 will return an error when a card change has been detected and the use of
506 this function is therefore required.
508 Background: We want to keep the client clear of handling card changes
509 between operations; i.e. the client can assume that all operations are
510 done on the same card unless he call this function.
516 Return the serial number of the card using a status response like:
519 S SERIALNO D27600000000000000000000
522 The serial number is the hex encoded value identified by
523 the @code{0x5A} tag in the GDO file (FIX=0x2F02).
528 @subsection Read all useful information from the card
534 Learn all useful information of the currently inserted card. When
535 used without the @option{--force} option, the command might do an INQUIRE
539 INQUIRE KNOWNCARDP <hexstring_with_serialNumber>
542 The client should just send an @code{END} if the processing should go on
543 or a @code{CANCEL} to force the function to terminate with a cancel
544 error message. The response of this command is a list of status lines
548 S KEYPAIRINFO @var{hexstring_with_keygrip} @var{hexstring_with_id}
551 If there is no certificate yet stored on the card a single "X" is
552 returned in @var{hexstring_with_keygrip}.
554 @node Scdaemon READCERT
555 @subsection Return a certificate
558 READCERT @var{hexified_certid}|@var{keyid}
561 This function is used to read a certificate identified by
562 @var{hexified_certid} from the card. With OpenPGP cards the keyid
563 @code{OpenPGP.3} may be used to read the certificate of version 2 cards.
566 @node Scdaemon READKEY
567 @subsection Return a public key
570 READKEY @var{hexified_certid}
573 Return the public key for the given cert or key ID as an standard
578 @node Scdaemon PKSIGN
579 @subsection Signing data with a Smartcard
581 To sign some data the caller should use the command
584 SETDATA @var{hexstring}
587 to tell @command{scdaemon} about the data to be signed. The data must be given in
588 hex notation. The actual signing is done using the command
594 where @var{keyid} is the hexified ID of the key to be used. The key id
595 may have been retrieved using the command @code{LEARN}. If another
596 hash algorithm than SHA-1 is used, that algorithm may be given like:
599 PKSIGN --hash=@var{algoname} @var{keyid}
602 With @var{algoname} are one of @code{sha1}, @code{rmd160} or @code{md5}.
605 @node Scdaemon PKDECRYPT
606 @subsection Decrypting data with a Smartcard
608 To decrypt some data the caller should use the command
611 SETDATA @var{hexstring}
614 to tell @command{scdaemon} about the data to be decrypted. The data
615 must be given in hex notation. The actual decryption is then done
619 PKDECRYPT @var{keyid}
622 where @var{keyid} is the hexified ID of the key to be used.
624 If the card is aware of the apdding format a status line with padding
625 information is send before the plaintext data. The key for this
626 status line is @code{PADDING} with the only defined value being 0 and
627 meaning padding has been removed.
629 @node Scdaemon GETATTR
630 @subsection Read an attribute's value
634 @node Scdaemon SETATTR
635 @subsection Update an attribute's value
639 @node Scdaemon WRITEKEY
640 @subsection Write a key to a card
643 WRITEKEY [--force] @var{keyid}
646 This command is used to store a secret key on a smartcard. The
647 allowed keyids depend on the currently selected smartcard
648 application. The actual keydata is requested using the inquiry
649 @code{KEYDATA} and need to be provided without any protection. With
650 @option{--force} set an existing key under this @var{keyid} will get
651 overwritten. The key data is expected to be the usual canonical encoded
654 A PIN will be requested in most cases. This however depends on the
655 actual card application.
658 @node Scdaemon GENKEY
659 @subsection Generate a new key on-card
663 @node Scdaemon RANDOM
664 @subsection Return random bytes generated on-card
669 @node Scdaemon PASSWD
670 @subsection Change PINs
673 PASSWD [--reset] [--nullpin] @var{chvno}
676 Change the PIN or reset the retry counter of the card holder
677 verification vector number @var{chvno}. The option @option{--nullpin}
678 is used to initialize the PIN of TCOS cards (6 byte NullPIN only).
681 @node Scdaemon CHECKPIN
682 @subsection Perform a VERIFY operation
688 Perform a VERIFY operation without doing anything else. This may be
689 used to initialize a the PIN cache earlier to long lasting
690 operations. Its use is highly application dependent:
695 Perform a simple verify operation for CHV1 and CHV2, so that further
696 operations won't ask for CHV2 and it is possible to do a cheap check on
697 the PIN: If there is something wrong with the PIN entry system, only the
698 regular CHV will get blocked and not the dangerous CHV3. @var{idstr} is
699 the usual card's serial number in hex notation; an optional fingerprint
700 part will get ignored.
702 There is however a special mode if @var{idstr} is suffixed with the
703 literal string @code{[CHV3]}: In this case the Admin PIN is checked if
704 and only if the retry counter is still at 3.
710 @node Scdaemon RESTART
711 @subsection Perform a RESTART operation
717 Restart the current connection; this is a kind of warm reset. It
718 deletes the context used by this connection but does not actually
721 This is used by gpg-agent to reuse a primary pipe connection and
722 may be used by clients to backup from a conflict in the serial
723 command; i.e. to select another application.
729 @subsection Send a verbatim APDU to the card
732 APDU [--atr] [--more] [--exlen[=@var{n}]] [@var{hexstring}]
736 Send an APDU to the current reader. This command bypasses the high
737 level functions and sends the data directly to the card.
738 @var{hexstring} is expected to be a proper APDU. If @var{hexstring} is
739 not given no commands are send to the card; However the command will
740 implicitly check whether the card is ready for use.
742 Using the option @code{--atr} returns the ATR of the card as a status
743 message before any data like this:
745 S CARD-ATR 3BFA1300FF813180450031C173C00100009000B1
748 Using the option @code{--more} handles the card status word MORE_DATA
749 (61xx) and concatenate all responses to one block.
751 Using the option @code{--exlen} the returned APDU may use extended
752 length up to N bytes. If N is not given a default value is used
759 @command{gpg-agent}(1),
763 @include see-also-note.texi