chiark / gitweb /
dirmngr: New option --no-use-tor and internal changes.
[gnupg2.git] / doc / scdaemon.texi
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.
4
5 @include defs.inc
6
7 @node Invoking SCDAEMON
8 @chapter Invoking the SCDAEMON
9 @cindex SCDAEMON command options
10 @cindex command options
11 @cindex options, SCDAEMON command
12
13 @manpage scdaemon.1
14 @ifset manverb
15 .B scdaemon
16 \- Smartcard daemon for the GnuPG system
17 @end ifset
18
19 @mansect synopsis
20 @ifset manverb
21 .B  scdaemon
22 .RB [ \-\-homedir
23 .IR dir ]
24 .RB [ \-\-options
25 .IR file ]
26 .RI [ options ]
27 .B  \-\-server
28 .br
29 .B  scdaemon
30 .RB [ \-\-homedir
31 .IR dir ]
32 .RB [ \-\-options
33 .IR file ]
34 .RI [ options ]
35 .B  \-\-daemon
36 .RI [ command_line ]
37 @end ifset
38
39
40 @mansect description
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.
43
44 @manpause
45 @xref{Option Index}, for an index to @command{scdaemon}'s commands and
46 options.
47 @mancont
48
49 @menu
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.
56 @end menu
57
58 @mansect commands
59
60 @node Scdaemon Commands
61 @section Commands
62
63 Commands are not distinguished from options except for the fact that
64 only one command is allowed.
65
66 @table @gnupgtabopt
67 @item --version
68 @opindex version
69 Print the program version and licensing information.  Note that you cannot
70 abbreviate this command.
71
72 @item --help, -h
73 @opindex help
74 Print a usage message summarizing the most useful command-line options.
75 Note that you cannot abbreviate this command.
76
77 @item --dump-options
78 @opindex dump-options
79 Print a list of all available options and commands.  Note that you cannot
80 abbreviate this command.
81
82 @item --server
83 @opindex server
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.
86
87 @item --multi-server
88 @opindex multi-server
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.
92
93 @item --daemon
94 @opindex daemon
95 Run the program in the background.  This option is required to prevent
96 it from being accidentally running in the background.
97
98 @end table
99
100
101 @mansect options
102
103 @node Scdaemon Options
104 @section Option Summary
105
106 @table @gnupgtabopt
107
108 @item --options @var{file}
109 @opindex options
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.
114
115 @include opt-homedir.texi
116
117
118 @item -v
119 @item --verbose
120 @opindex v
121 @opindex verbose
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}.
125
126 @item --debug-level @var{level}
127 @opindex debug-level
128 Select the debug level for investigating problems.  @var{level} may be
129 a numeric value or a keyword:
130
131 @table @code
132 @item none
133 No debugging at all.  A value of less than 1 may be used instead of
134 the keyword.
135 @item basic
136 Some basic debug messages.  A value between 1 and 2 may be used
137 instead of the keyword.
138 @item advanced
139 More verbose debug messages.  A value between 3 and 5 may be used
140 instead of the keyword.
141 @item expert
142 Even more detailed messages.  A value between 6 and 8 may be used
143 instead of the keyword.
144 @item guru
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.
148 @end table
149
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.
153
154 @quotation Note
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.
158 @end quotation
159
160
161 @item --debug @var{flags}
162 @opindex debug
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:
166
167 @table @code
168 @item 0  (1)
169 command I/O
170 @item 1  (2)
171 values of big number integers
172 @item 2  (4)
173 low level crypto operations
174 @item 5  (32)
175 memory allocation
176 @item 6  (64)
177 caching
178 @item 7  (128)
179 show memory statistics
180 @item 9  (512)
181 write hashed data to files named @code{dbgmd-000*}
182 @item 10 (1024)
183 trace Assuan protocol.
184 See also option @option{--debug-assuan-log-cats}.
185 @item 11 (2048)
186 trace APDU I/O to the card.  This may reveal sensitive data.
187 @item 12 (4096)
188 trace some card reader related function calls.
189 @end table
190
191 @item --debug-all
192 @opindex debug-all
193 Same as @code{--debug=0xffffffff}
194
195 @item --debug-wait @var{n}
196 @opindex debug-wait
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
199 debugger.
200
201 @item --debug-ccid-driver
202 @opindex debug-wait
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.
206
207 @item --debug-disable-ticker
208 @opindex debug-disable-ticker
209 This option disables all ticker functions like checking for card
210 insertions.
211
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.
218
219 @item --debug-log-tid
220 @opindex debug-log-tid
221 This option appends a thread ID to the PID in the log output.
222
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.
233
234 @item --no-detach
235 @opindex no-detach
236 Don't detach the process from the console.  This is mainly useful for
237 debugging.
238
239 @item --log-file @var{file}
240 @opindex log-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
243 socket.
244
245
246 @item --pcsc-driver @var{library}
247 @opindex pcsc-driver
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}).
252
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.
258
259 @item --disable-ccid
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.
265
266 @item --reader-port @var{number_or_string}
267 @opindex reader-port
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
273 found.
274
275 To get a list of available CCID readers you may use this command:
276 @cartouche
277 @smallexample
278   echo scd getinfo reader_list \
279     | gpg-connect-agent --decode | awk '/^D/ @{print $2@}'
280 @end smallexample
281 @end cartouche
282
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.
292
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
295 than 0.
296
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.
304
305
306 @item --disable-pinpad
307 @opindex disable-pinpad
308 Even if a card reader features a pinpad, do not try to use it.
309
310
311 @item --deny-admin
312 @opindex deny-admin
313 @opindex allow-admin
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.
322
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.
328
329 @end table
330
331 All the long options may also be given in the configuration file after
332 stripping off the two leading dashes.
333
334
335 @mansect card applications
336 @node Card applications
337 @section Description of card applications
338
339 @command{scdaemon} supports the card applications as described below.
340
341 @menu
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
349 @end menu
350
351 @node OpenPGP Card
352 @subsection The OpenPGP card application ``openpgp''
353
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.
357
358 @noindent
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}.
362
363 @node NKS Card
364 @subsection The Telesec NetKey card ``nks''
365
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}.
369
370 @node DINSIG Card
371 @subsection The DINSIG card application ``dinsig''
372
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).
376
377 @node PKCS#15 Card
378 @subsection The PKCS#15 card application ``p15''
379
380 This is common framework for smart card applications.  It is used by
381 @command{gpgsm}.
382
383 @node Geldkarte Card
384 @subsection The Geldkarte card application ``geldkarte''
385
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.
389
390 @node SmartCard-HSM
391 @subsection The SmartCard-HSM card application ``sc-hsm''
392
393 This application adds read-only support for keys and certificates
394 stored on a @uref{http://www.smartcard-hsm.com, SmartCard-HSM}.
395
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}.
399
400 The SmartCard-HSM cards requires a card reader that supports Extended
401 Length APDUs.
402
403 @node Undefined Card
404 @subsection The Undefined card application ``undefined''
405
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
409 SERIALNO command.
410
411
412 @c *******************************************
413 @c ***************            ****************
414 @c ***************   FILES    ****************
415 @c ***************            ****************
416 @c *******************************************
417 @mansect files
418 @node Scdaemon Configuration
419 @section Configuration files
420
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}).
424
425 @table @file
426
427 @item scdaemon.conf
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}).
433
434 @item scd-event
435 @cindex scd-event
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
438 distribution
439
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
443 @file{scd-event}.
444
445 @end table
446
447
448 @c
449 @c  Examples
450 @c
451 @mansect examples
452 @node Scdaemon Examples
453 @section Examples
454
455 @c man begin EXAMPLES
456
457 @example
458 $ scdaemon --server -v
459 @end example
460
461 @c man end
462
463 @c
464 @c  Assuan Protocol
465 @c
466 @manpause
467 @node Scdaemon Protocol
468 @section Scdaemon's Assuan Protocol
469
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.
474
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}
478
479 Each connection acts as one session, SC-Daemon takes care of
480 synchronizing access to a token between sessions.
481
482 @menu
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
498 @end menu
499
500 @node Scdaemon SERIALNO
501 @subsection Return the serial number
502
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.
507
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.
511
512 @example
513   SERIALNO
514 @end example
515
516 Return the serial number of the card using a status response like:
517
518 @example
519   S SERIALNO D27600000000000000000000
520 @end example
521
522 The serial number is the hex encoded value identified by
523 the @code{0x5A} tag in the GDO file (FIX=0x2F02).
524
525
526
527 @node Scdaemon LEARN
528 @subsection Read all useful information from the card
529
530 @example
531   LEARN [--force]
532 @end example
533
534 Learn all useful information of the currently inserted card.  When
535 used without the @option{--force} option, the command might do an INQUIRE
536 like this:
537
538 @example
539       INQUIRE KNOWNCARDP <hexstring_with_serialNumber>
540 @end example
541
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
545 formatted as this:
546
547 @example
548      S KEYPAIRINFO @var{hexstring_with_keygrip} @var{hexstring_with_id}
549 @end example
550
551 If there is no certificate yet stored on the card a single "X" is
552 returned in @var{hexstring_with_keygrip}.
553
554 @node Scdaemon READCERT
555 @subsection Return a certificate
556
557 @example
558  READCERT @var{hexified_certid}|@var{keyid}
559 @end example
560
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.
564
565
566 @node Scdaemon READKEY
567 @subsection Return a public key
568
569 @example
570 READKEY @var{hexified_certid}
571 @end example
572
573 Return the public key for the given cert or key ID as an standard
574 S-Expression.
575
576
577
578 @node Scdaemon PKSIGN
579 @subsection Signing data with a Smartcard
580
581 To sign some data the caller should use the command
582
583 @example
584  SETDATA @var{hexstring}
585 @end example
586
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
589
590 @example
591   PKSIGN @var{keyid}
592 @end example
593
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:
597
598 @example
599   PKSIGN --hash=@var{algoname} @var{keyid}
600 @end example
601
602 With @var{algoname} are one of @code{sha1}, @code{rmd160} or @code{md5}.
603
604
605 @node Scdaemon PKDECRYPT
606 @subsection Decrypting data with a Smartcard
607
608 To decrypt some data the caller should use the command
609
610 @example
611  SETDATA @var{hexstring}
612 @end example
613
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
616 using the command
617
618 @example
619   PKDECRYPT @var{keyid}
620 @end example
621
622 where @var{keyid} is the hexified ID of the key to be used.
623
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.
628
629 @node Scdaemon GETATTR
630 @subsection Read an attribute's value
631
632 TO BE WRITTEN.
633
634 @node Scdaemon SETATTR
635 @subsection Update an attribute's value
636
637 TO BE WRITTEN.
638
639 @node Scdaemon WRITEKEY
640 @subsection Write a key to a card
641
642 @example
643   WRITEKEY [--force] @var{keyid}
644 @end example
645
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
652 S-expression.
653
654 A PIN will be requested in most cases.  This however depends on the
655 actual card application.
656
657
658 @node Scdaemon GENKEY
659 @subsection Generate a new key on-card
660
661 TO BE WRITTEN.
662
663 @node Scdaemon RANDOM
664 @subsection Return random bytes generated on-card
665
666 TO BE WRITTEN.
667
668
669 @node Scdaemon PASSWD
670 @subsection Change PINs
671
672 @example
673    PASSWD [--reset] [--nullpin] @var{chvno}
674 @end example
675
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).
679
680
681 @node Scdaemon CHECKPIN
682 @subsection Perform a VERIFY operation
683
684 @example
685   CHECKPIN @var{idstr}
686 @end example
687
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:
691
692 @table @strong
693 @item OpenPGP
694
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.
701
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.
705
706 @end table
707
708
709
710 @node Scdaemon RESTART
711 @subsection Perform a RESTART operation
712
713 @example
714   RESTART
715 @end example
716
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
719 reset the card.
720
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.
724
725
726
727
728 @node Scdaemon APDU
729 @subsection Send a verbatim APDU to the card
730
731 @example
732   APDU [--atr] [--more] [--exlen[=@var{n}]] [@var{hexstring}]
733 @end example
734
735
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.
741
742 Using the option @code{--atr} returns the ATR of the card as a status
743 message before any data like this:
744 @example
745      S CARD-ATR 3BFA1300FF813180450031C173C00100009000B1
746 @end example
747
748 Using the option @code{--more} handles the card status word MORE_DATA
749 (61xx) and concatenate all responses to one block.
750
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
753 (currently 4096).
754
755
756
757 @mansect see also
758 @ifset isman
759 @command{gpg-agent}(1),
760 @command{gpgsm}(1),
761 @command{gpg2}(1)
762 @end ifset
763 @include see-also-note.texi
764