chiark / gitweb /
dirmngr: Drop useless housekeeping.
[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 0
520 @end example
521
522 The trailing 0 should be ignored for now, it is reserved for a future
523 extension.  The serial number is the hex encoded value identified by
524 the @code{0x5A} tag in the GDO file (FIX=0x2F02).
525
526
527
528 @node Scdaemon LEARN
529 @subsection Read all useful information from the card
530
531 @example
532   LEARN [--force]
533 @end example
534
535 Learn all useful information of the currently inserted card.  When
536 used without the @option{--force} option, the command might do an INQUIRE
537 like this:
538
539 @example
540       INQUIRE KNOWNCARDP <hexstring_with_serialNumber> <timestamp>
541 @end example
542
543 The client should just send an @code{END} if the processing should go on
544 or a @code{CANCEL} to force the function to terminate with a cancel
545 error message.  The response of this command is a list of status lines
546 formatted as this:
547
548 @example
549      S KEYPAIRINFO @var{hexstring_with_keygrip} @var{hexstring_with_id}
550 @end example
551
552 If there is no certificate yet stored on the card a single "X" is
553 returned in @var{hexstring_with_keygrip}.
554
555 @node Scdaemon READCERT
556 @subsection Return a certificate
557
558 @example
559  READCERT @var{hexified_certid}|@var{keyid}
560 @end example
561
562 This function is used to read a certificate identified by
563 @var{hexified_certid} from the card.  With OpenPGP cards the keyid
564 @code{OpenPGP.3} may be used to read the certificate of version 2 cards.
565
566
567 @node Scdaemon READKEY
568 @subsection Return a public key
569
570 @example
571 READKEY @var{hexified_certid}
572 @end example
573
574 Return the public key for the given cert or key ID as an standard
575 S-Expression.
576
577
578
579 @node Scdaemon PKSIGN
580 @subsection Signing data with a Smartcard
581
582 To sign some data the caller should use the command
583
584 @example
585  SETDATA @var{hexstring}
586 @end example
587
588 to tell @command{scdaemon} about the data to be signed.  The data must be given in
589 hex notation.  The actual signing is done using the command
590
591 @example
592   PKSIGN @var{keyid}
593 @end example
594
595 where @var{keyid} is the hexified ID of the key to be used.  The key id
596 may have been retrieved using the command @code{LEARN}.  If another
597 hash algorithm than SHA-1 is used, that algorithm may be given like:
598
599 @example
600   PKSIGN --hash=@var{algoname} @var{keyid}
601 @end example
602
603 With @var{algoname} are one of @code{sha1}, @code{rmd160} or @code{md5}.
604
605
606 @node Scdaemon PKDECRYPT
607 @subsection Decrypting data with a Smartcard
608
609 To decrypt some data the caller should use the command
610
611 @example
612  SETDATA @var{hexstring}
613 @end example
614
615 to tell @command{scdaemon} about the data to be decrypted.  The data
616 must be given in hex notation.  The actual decryption is then done
617 using the command
618
619 @example
620   PKDECRYPT @var{keyid}
621 @end example
622
623 where @var{keyid} is the hexified ID of the key to be used.
624
625 If the card is aware of the apdding format a status line with padding
626 information is send before the plaintext data.  The key for this
627 status line is @code{PADDING} with the only defined value being 0 and
628 meaning padding has been removed.
629
630 @node Scdaemon GETATTR
631 @subsection Read an attribute's value
632
633 TO BE WRITTEN.
634
635 @node Scdaemon SETATTR
636 @subsection Update an attribute's value
637
638 TO BE WRITTEN.
639
640 @node Scdaemon WRITEKEY
641 @subsection Write a key to a card
642
643 @example
644   WRITEKEY [--force] @var{keyid}
645 @end example
646
647 This command is used to store a secret key on a smartcard.  The
648 allowed keyids depend on the currently selected smartcard
649 application. The actual keydata is requested using the inquiry
650 @code{KEYDATA} and need to be provided without any protection.  With
651 @option{--force} set an existing key under this @var{keyid} will get
652 overwritten.  The key data is expected to be the usual canonical encoded
653 S-expression.
654
655 A PIN will be requested in most cases.  This however depends on the
656 actual card application.
657
658
659 @node Scdaemon GENKEY
660 @subsection Generate a new key on-card
661
662 TO BE WRITTEN.
663
664 @node Scdaemon RANDOM
665 @subsection Return random bytes generated on-card
666
667 TO BE WRITTEN.
668
669
670 @node Scdaemon PASSWD
671 @subsection Change PINs
672
673 @example
674    PASSWD [--reset] [--nullpin] @var{chvno}
675 @end example
676
677 Change the PIN or reset the retry counter of the card holder
678 verification vector number @var{chvno}.  The option @option{--nullpin}
679 is used to initialize the PIN of TCOS cards (6 byte NullPIN only).
680
681
682 @node Scdaemon CHECKPIN
683 @subsection Perform a VERIFY operation
684
685 @example
686   CHECKPIN @var{idstr}
687 @end example
688
689 Perform a VERIFY operation without doing anything else.  This may be
690 used to initialize a the PIN cache earlier to long lasting
691 operations.  Its use is highly application dependent:
692
693 @table @strong
694 @item OpenPGP
695
696 Perform a simple verify operation for CHV1 and CHV2, so that further
697 operations won't ask for CHV2 and it is possible to do a cheap check on
698 the PIN: If there is something wrong with the PIN entry system, only the
699 regular CHV will get blocked and not the dangerous CHV3.  @var{idstr} is
700 the usual card's serial number in hex notation; an optional fingerprint
701 part will get ignored.
702
703 There is however a special mode if @var{idstr} is suffixed with the
704 literal string @code{[CHV3]}: In this case the Admin PIN is checked if
705 and only if the retry counter is still at 3.
706
707 @end table
708
709
710
711 @node Scdaemon RESTART
712 @subsection Perform a RESTART operation
713
714 @example
715   RESTART
716 @end example
717
718 Restart the current connection; this is a kind of warm reset.  It
719 deletes the context used by this connection but does not actually
720 reset the card.
721
722 This is used by gpg-agent to reuse a primary pipe connection and
723 may be used by clients to backup from a conflict in the serial
724 command; i.e. to select another application.
725
726
727
728
729 @node Scdaemon APDU
730 @subsection Send a verbatim APDU to the card
731
732 @example
733   APDU [--atr] [--more] [--exlen[=@var{n}]] [@var{hexstring}]
734 @end example
735
736
737 Send an APDU to the current reader.  This command bypasses the high
738 level functions and sends the data directly to the card.
739 @var{hexstring} is expected to be a proper APDU.  If @var{hexstring} is
740 not given no commands are send to the card; However the command will
741 implicitly check whether the card is ready for use.
742
743 Using the option @code{--atr} returns the ATR of the card as a status
744 message before any data like this:
745 @example
746      S CARD-ATR 3BFA1300FF813180450031C173C00100009000B1
747 @end example
748
749 Using the option @code{--more} handles the card status word MORE_DATA
750 (61xx) and concatenate all responses to one block.
751
752 Using the option @code{--exlen} the returned APDU may use extended
753 length up to N bytes.  If N is not given a default value is used
754 (currently 4096).
755
756
757
758 @mansect see also
759 @ifset isman
760 @command{gpg-agent}(1),
761 @command{gpgsm}(1),
762 @command{gpg2}(1)
763 @end ifset
764 @include see-also-note.texi
765