aboutsummaryrefslogtreecommitdiffstats
path: root/scd/app-common.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* scd: New getinfo subcommand "manufacturer"Werner Koch2024-08-051-0/+1
| | | | | | | | | | | | | * scd/command.c (cmd_getinfo): Add subcommand "manufacturer". * scd/app-openpgp.c (get_manufacturer): Rename to ... (app_openpgp_manufacturer): this and make global. -- Example: $ gpg-connect-agent 'scd getinfo manufacturer 42' /bye D Magrathea OK
* scd: Add support for SCE 7.0Werner Koch2024-01-041-2/+2
| | | | | | | | | | | | | | | | | * scd/app-common.h (CARDTYPE_SCE7): New. * scd/app.c (strcardtype): Support it. (atr_to_cardtype): New. (app_new_register): Try to get the cardtype from atr_to_cardtype. * scd/app-piv.c (app_select_piv): Tweak for SCE7. Add general method to construct a S/N from the Card UUID. -- The test cards I have are rsa2048 with X.509 certificates. I don't have the entire chain but loading the certificates work. For testing I created an OpenPGP key from the keys and tested signing and decryption. GnuPG-bug-id: 6919
* scd: On a Yubikey re-select the last app after the use of APDU.Werner Koch2023-04-181-0/+1
| | | | | | | | | | | | | * scd/app-common.h (struct card_ctx_s): Add maybe_check_aid flag. * scd/command.c (cmd_apdu): Set it. * scd/app.c (check_external_interference): Consult this flag. (maybe_switch_app): Do a re-select if this flag is set. -- After the gpg-card tool has issued a Yubikey specific command the current application is not anymore correctly selected. This then results in all kind of errors. We detect this now and try to re-select the last app.
* scd: Fix access to list of cards (3/3).NIIBE Yutaka2021-07-211-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/app-common.h (card_reset): Simplify more. (select_additional_application): Supply CARD. (card_ref, card_unref): Remove. (card_get, card_put): New. * scd/app.c (card_reset): No locking/unlocking inside. (app_switch_current_card): Fix comment. (select_additional_application): No locking/unlocking inside. (do_with_keygrip): New, unlocked version. (card_get): New, with support of KEYGRIP. (card_unref): Remove. (card_put): New. (app_write_learn_status, app_readcert: No locking/unlocking inside. (app_readkey, app_getattr, app_setattr, app_sign, app_auth): Likewise. (app_decipher, app_writecert, app_writekey): Likewise. (app_genkey, app_get_challenge, app_change_pin): Likewise. (app_check_pin, app_switch_active_app): Likewise. * scd/command.c (do_reset): Use card_get/card_put. (open_card_with_request): Use card_get/card_put, return CARD locked. (cmd_serialno): Follow the change of open_card_with_request. (cmd_switchapp): Use card_get/card_put. (cmd_learn, cmd_readcert, cmd_readkey, cmd_pksign): Likewise. (cmd_pkauth, cmd_pkdecrypt, cmd_getattr): Likewise. (cmd_setattr, cmd_writecert, cmd_writekey): Likewise. (cmd_genkey, cmd_random, cmd_passwd): Likewise. (cmd_checkpin, cmd_getinfo, cmd_restart): Likewise. (cmd_disconnect, cmd_apdu, cmd_devinfo): Likewise. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Fix access to list of cards (2/3).NIIBE Yutaka2021-07-211-2/+2
| | | | | | | | | | | * scd/app-common.h (card_reset, select_application): Simplify. * scd/app.c (card_reset, select_application): Simplify. * scd/command.c (do_reset): Follow the change. (open_card, open_card_with_request): Follow the change. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Detect external interference when PCSC_SHARED.NIIBE Yutaka2021-07-061-0/+2
| | | | | | | | | | | | | | * scd/app-common.h (check_aid): New method. * scd/app-openpgp.c (do_check_aid): New. * scd/app-piv.c (do_check_aid): New. * scd/app.c (check_external_interference): New. (maybe_switch_app): Check interference to determine switching is needed. -- GnuPG-bug-id: 5484 Signed-off-by: NIIBE Yutaka <[email protected]>
* A few minor code cleanups and typo fixes.Werner Koch2021-05-111-1/+1
| | | | | | | | | | * agent/command-ssh.c (ssh_handler_request_identities): Remove double check of ERR. * g10/getkey.c (get_pubkey_byname): Remove double use of break. * g10/pkglue.c (pk_encrypt): Handle possible NULL-ptr access due to failed malloc. Signed-off-by: Werner Koch <[email protected]>
* scd: New flag --reread for LEARNWerner Koch2021-04-011-0/+1
| | | | | | | | | | | * scd/command.c (cmd_learn): Add flag --reread. * scd/app-common.h (struct app_ctx_s): New field need_reset. * scd/app.c (write_learn_status_core): Set need_reset if we notice an error after returning from a reread. Change all callers of card functions to return GPG_ERR_CARD_RESET so that that app is not anymore used. Signed-off-by: Werner Koch <[email protected]>
* scd:p15: New flag APP_LEARN_FLAG_REREAD.Werner Koch2021-04-011-0/+1
| | | | | | | | | | | | | | | | * scd/app-p15.c (do_deinit): Factor code out to ... (release_lists, release_tokeninfo): new. (read_ef_tokeninfo): Reset all data before reading. (read_p15_info): Ditto. (do_learn_status): Implement reread flag. -- Objects of a card may be protected by a PIN and thus only readble after a verify command. This new flag makes it possible to gather the entire PKCS#15 card info again without a need for a reset (and thus loss of the verify status). Signed-off-by: Werner Koch <[email protected]>
* scd: Minor tweak for easier backportingWerner Koch2021-02-191-0/+6
| | | | | | | | * scd/app-common.h (APP_CARD): New. Use it in app-*.c to access app->card. -- This should help to make backporting to 2.2 easier.
* scd: Rework the handling of the displayed serial number.Werner Koch2020-11-251-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/app.c (app_new_register): Call app_munge_serialno for Yubikeys. (app_munge_serialno): Handle Yubikey serial numbers. (card_get_serialno): Remove special Yubikey treatment. Drop arg is_canonical. (app_get_serialno): Clear ERRNO on error. (card_get_dispserialno): New. Also change formatting of Yubikey and OpenPGP numbers to match those printed on the card. (app_get_dispserialno): New. * scd/app-openpgp.c (do_getattr): Use app_get_dispserialno. (yubikey_get_serialno): Remove. * scd/app-piv.c (get_dispserialno): Remove. (do_getattr): Use app_get_dispserialno. -- This patch gets us back to a unique serial number for cards and provides a stable serial number as printed for Yubikeys. Because we use a slightly different serial number now for Yubikeys and cards only supporting OpenPGP card we need to come up with another change so that the version number of OpenPGP serial numbers are ignored when comparing card serial numbers. This is so that existing stub keys of gpg-agent will continue to work. GnuPG-bug-id: 5100 Signed-off-by: Werner Koch <[email protected]>
* scd: Handle canonical serialno and app specific serialno differently.NIIBE Yutaka2020-10-271-1/+1
| | | | | | | | | | | | | | | * scd/app-common.h (card_get_serialno): Add IS_CANONICAL arg. * scd/app.c (app_send_devinfo): Use app specific serialno. (card_get_serialno): Support two different cases. (app_get_serialno): Return app specific serialno. (send_serialno_and_app_status): Return canonical serialno. * scd/command.c (cmd_serialno): Return app specific serialno. (cmd_learn): Return canonical serialno. -- GnuPG-bug-id: 5100 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Handle Yubikey's multiple apps and serialno.NIIBE Yutaka2020-10-231-0/+1
| | | | | | | | | | | | | | * scd/app-common.h (yubikey_get_serialno): New. * scd/app-openpgp.c (yubikey_get_serialno): New. * scd/app.c (card_get_serialno): Use OpenPGP app's serialno, when it's enabled for Yubikey. (send_serialno_and_app_status): Use card_get_serialno, not directly accessing ->serialno. -- GnuPG-bug-id: 5100 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Extend KEYPAIRINFO with an algorithm string.Werner Koch2020-09-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | * scd/app-openpgp.c (send_keypair_info): Emit the algo string as part of a KEYPAIRINFO. * scd/command.c (do_readkey): Ditto. * scd/app-piv.c (do_readkey): Ditto. * scd/app-nks.c (do_learn_status_core): Ditto. (struct fid_cache_s): Add field algostr. (flush_fid_cache): Release it. (keygripstr_from_pk_file): Fill it and add it to the cache. Use a single exit label. * scd/app-help.c (app_help_get_keygrip_string_pk): Add new arg r_algostr. Change all callers. -- This is helpful so that callers do not need to parse the key for this basic information. Use "scd readkey --info-only" to return the info status line instead of the key material; using just --info returns the info in addition to the key material. Signed-off-by: Werner Koch <[email protected]>
* scd: Add heuristics to identify cardtype.NIIBE Yutaka2020-08-271-1/+3
| | | | | | | | | | | * scd/app-common.h (cardtype_t): Add CARDTYPE_GNUK and CARDTYPE_ZEITCONTROL. * scd/app.c (strcardtype): Handle CARDTYPE_GNUK and CARDTYPE_ZEITCONTROL. (app_new_register): Detect Gnuk and Zeit Control implementation by examining its ATR string. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Extend an internal function to also return the algo.Werner Koch2020-05-051-2/+3
| | | | | | | | * scd/app-help.c (app_help_get_keygrip_string_pk): Add optional arg r_algo. Change all callers. (app_help_get_keygrip_string): Ditto. Signed-off-by: Werner Koch <[email protected]>
* scd:p15: Support signing with CardOS 5 cards.Werner Koch2020-03-311-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/app-help.c (app_help_get_keygrip_string_pk): Add optional arg r_pkey and change all callers. (app_help_get_keygrip_string): Ditto. * scd/app-p15.c (struct cdf_object_s): Use bit flags (struct aodf_object_s): Ditto. Add field 'fid'. (struct prkdf_object_s): Ditto. Add fields keygrip, keyalgo, and keynbits. (parse_certid): Allow a keygrip instead of a certid aka keyref. (read_ef_aodf): Store the FID. (keygripstr_from_prkdf): Rename to ... (keygrip_from_prkdf): this. Remove arg r_gripstr and implement cache. Change callers to directly use the values from the object. Also store the algo and length of the key ion the object. (keyref_from_keyinfo): New. Factored out code. (do_sign): Support SHA-256 and >2048 bit RSA keys. (do_with_keygrip): New. (app_select_p15): Register new function. -- This has been tested with a D-Trust card featuring 3072 bit keys. Note that non-repudiation key for a qualified signature does not yet work because we do not yet support rsaPSS padding. Thus a gpgsm --learn shows a couple of Bad Signature errors for this key. Signed-off-by: Werner Koch <[email protected]>
* Spelling cleanup.Daniel Kahn Gillmor2020-02-181-1/+1
| | | | | | | | | | | | | | | | No functional changes, just fixing minor spelling issues. --- Most of these were identified from the command line by running: codespell \ --ignore-words-list fpr,stati,keyserver,keyservers,asign,cas,iff,ifset \ --skip '*.po,ChangeLog*,help.*.txt,*.jpg,*.eps,*.pdf,*.png,*.gpg,*.asc' \ doc g13 g10 kbx agent artwork scd tests tools am common dirmngr sm \ NEWS README README.maint TODO Signed-off-by: Daniel Kahn Gillmor <[email protected]>
* scd: New commands SWITCHCARD and SWITCHAPP.Werner Koch2020-01-161-0/+8
| | | | | | | | | | | | | | | | | | | | * scd/app.c: Include membuf.h. (app_switch_current_card): New. (send_card_and_app_list): Factor code out to ... (send_serialno_and_app_status): new. (app_send_card_list): New. (app_send_active_apps): New. (app_switch_active_app): New. * scd/command.c (cmd_switchcard): New. (cmd_switchapp): New. (register_commands): Register new commands. (cmd_getinfo): New sub-commands "active_apps" and "all_active_apps". -- These new commands allow to switch between known cards and are in particular useful for the gpg-card tool. Signed-off-by: Werner Koch <[email protected]>
* scd: First changes to implement a PIN cache.Werner Koch2020-01-071-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/command.c (pincache_put): New. Uses a dummy key for now. (pincache_get): New. * scd/app.c (select_application): Flush the PIN cache. (scd_update_reader_status_file): Ditto. (maybe_switch_app): Call the new prep_reselect function. (app_write_learn_status): Ditto. * scd/app-openpgp.c (cache_pin): New helper to cache a PIN. (verify_chv2): Call it. (verify_chv3): Call it. (clear_chv_status): Call it. (do_change_pin): Call it. * scd/app-common.h (struct app_ctx_s): Add function 'prep_select'. * scd/app-openpgp.c (do_prep_reselect): New stub function. (app_select_openpgp): Set new stub function. * scd/app-piv.c (do_prep_reselect): New stub function. (app_select_piv): Set new stub function. * scd/app-common.h (struct app_ctx_s): Add parameter ctrl to setattr, sign, auth, decipher, and check_pin. Change all implementations and callers to pass such a parameter. -- This is work in progress. Signed-off-by: Werner Koch <[email protected]>
* scd: Enhance KEYINFO command to limit listing with capability.NIIBE Yutaka2019-12-191-2/+3
| | | | | | | | | | | | | | | | | | * scd/app-common.h: Add CAPABILITY argument to the WITH_KEYGRIP. (app_do_with_keygrip): Likewise. * scd/app-openpgp.c (send_keyinfo_if_available): New. (do_with_keygrip): Support listing with CAPABILITY. * scd/app-piv.c (do_with_keygrip): Likewise. * scd/app.c (maybe_switch_app): Supply the argument. (app_do_with_keygrip): Add CAPABILITY argument. * scd/command.c (cmd_pksign, cmd_pkauth): Supply the argument. (cmd_pkdecrypt): Likewise. (cmd_keyinfo): Support listing with CAPABILITY. -- GnuPG-bug-id: 4784 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Add option --multi to the LEARN command.Werner Koch2019-09-041-0/+2
| | | | | | | | | | | | | | | | * scd/app-common.h (APP_LEARN_FLAG_MULTI): New. * scd/command.c (cmd_learn): Add option --multi. * scd/app.c (app_write_learn_status): Factor some code out to ... (write_learn_status_core): new. (app_write_learn_status): Implement flag --multi. -- This new option is intended to return information about all active applications of the current card. Thus if a "SERIALNO openpgp" and a "SERIALNO piv" has been done in a session the command "LEARN --force --multi" returns information about both applications. Signed-off-by: Werner Koch <[email protected]>
* scd: Use a macro for the flag parameter of learn_status.Werner Koch2019-09-041-1/+3
| | | | | | | | | | | | * scd/app-common.h (APP_LEARN_FLAG_KEYPAIRINFO): New flag macro.. * scd/command.c (cmd_learn): Pass that flag instead of a plain number. * scd/app-nks.c (do_learn_status_core): Use new flag. * scd/app-p15.c (do_learn_status): Ditto. * scd/app-piv.c (do_learn_status): Ditto. * scd/app-sc-hsm.c (do_learn_status): Ditto. * scd/app.c (app_write_learn_status): Ditto. Signed-off-by: Werner Koch <[email protected]>
* scd: Do not conflict if a card with another serialno is demanded.Werner Koch2019-06-251-1/+3
| | | | | | | | | * scd/app.c (check_application_conflict): Add args to pass a serialno. * scd/command.c (open_card_with_request): Pass the serialno to check_application_conflict. -- Signed-off-by: Werner Koch <[email protected]>
* scd: Return a stable list with "getinfo card_list".Werner Koch2019-06-251-1/+1
| | | | | | | | | | | * scd/app.c (compare_card_list_items): New. (app_send_card_list): Sort the card objects by slot. -- This is required so that in gpg-card a "list N" command always returns the expected card. Sorting by slot should be sufficient. Signed-off-by: Werner Koch <[email protected]>
* scd: Add an re-select mechanism to switch apps.Werner Koch2019-06-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/app-common.h (struct app_ctx_s): Add func ptr 'reselect'. * scd/app-piv.c (do_reselect): New. (app_select_piv): Move AID constant to file scope. * scd/app-openpgp.c (do_reselect): New. (app_select_openpgp): Move AID constant to file scope. * scd/app.c (apptype_from_name): New. (check_application_conflict): Check against all apps of the card. Always set current_apptype. (select_additional_application): New. (maybe_switch_app): New. (app_write_learn_status, app_readcert, app_readkey, app_getattr) (app_setattr, app_sign, app_auth, app_decipher, app_writecert) (app_writekey, app_genkey, app_change_pin, app_check_pin): Use it here. (app_do_with_keygrip): Force reselect on success. (app_new_register): Move setting of CURRENT_APPTYPE to ... (select_application): here so that it will be set to the requested card. * scd/command.c (open_card_with_request): Select additional application if possible. -- Noet that we will likely need to rework this even more so to get well defined semantics for card access. Signed-off-by: Werner Koch <[email protected]>
* scd: Add code to check whether app switching is possible.Werner Koch2019-06-211-1/+1
| | | | | | | | | | | * scd/app.c (check_conflict): Fold into ... (check_application_conflict): this and adjust callers. Return a different error code if it is possible to switch apps. -- Right now this change does nothing visible. Signed-off-by: Werner Koch <[email protected]>
* scd: Simplify inclusion of app-common.h.Werner Koch2019-06-211-3/+8
| | | | | | | | | | | | | | * scd/scdaemon.h: Include app-common.h. Remove inclusion of that header from all other files. (card_t, app_t): Move typedef to ... * scd/app-common.h: here. Use them in the defs. -- In another patch we will need apptype_t in the ctrl object and thus we need to reorganize things a bit now. Given that most files need app-common anyway it makes sense to always include it. Signed-off-by: Werner Koch <[email protected]>
* scd: Use enums for cardtype and apptype.Werner Koch2019-06-211-3/+33
| | | | | | | | | | | | | | | | * scd/app-common.h (cardtype_t): New. (apptype_t): New. (struct card_ctx_s): Change type of cardtype. (struct app_ctx_s): Change type of apptype. Adjust all users. * scd/app.c (struct app_priority_list_s): Add field apptype. (strcardtype): New. Use as needed. (strapptype): New. Use as needed. -- Using strcmp is lame and we can't use a switch to let the compiler complain about missed cases. Signed-off-by: Werner Koch <[email protected]>
* scd: Split data structures into app and card related objects.Werner Koch2019-06-191-41/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/app-common.h (struct card_ctx_s): New. (struct app_ctx_s): Factor card specific fields out to card_ctx_s. (app_get_slot): New. * scd/scdaemon.h (card_t): New. (struct server_control_s): Rename field app_ctx to card_ctx and change all users. * scd/app-dinsig.c: Use app_get_slot and adjust for chang in card related fields. * scd/app-geldkarte.c: Ditto. * scd/app-nks.c: Ditto. * scd/app-openpgp.c: Ditto. * scd/app-p15.c: Ditto. * scd/app-sc-hsm.c: Ditto. * scd/app.c: Lost of changes to adjust for the changed data structures. Change all callers. (app_list_lock): Rename to card_list_lock. (app_top): Remove. (card_top): New. (lock_app): Rename to lock_card and change arg type. (unlock_app): Rename to unlock_card. (app_dump_state): Print card and app info. (app_reset): Rename to card_reset. (app_new_register): Change for the new data structure. (deallocate_card): Dealloc card and all apps. (app_ref): Rename to card_ref. (app_unref): Rename to card_unref. (app_unref_locked): Rename to card_unref_locked. (card_get_serialno): New. * scd/command.c (cmd_pkdecrypt): Actually use the looked up card and former app object and not the standard one from the context. -- Although quite large, this is a straightforward change to separate card/token related data from card application related data. Before this change there was a one-to-one relation between card and application and no way to represent several applications on a card. The new data structure will allow for such a representation. Signed-off-by: Werner Koch <[email protected]>
* scd: Add explict functions for 'app' reference counting.Werner Koch2019-06-171-1/+5
| | | | | | | | | | | | | | | | | | | | | * scd/app.c (app_ref): New. (app_unref): New. (release_application): Renamed to ... (app_unref_locked): this and remove arg locked_already. Change callers to use this or app_ref. * scd/command.c (open_card_with_request): (cmd_pksign, cmd_pkauth, cmd_pkdecrypt): Use app_ref and app_unref instead of accessing the counter directly. -- This is better in case we need to debug stuff. There is a real change however: We now lock and unlock the app before changing the reference count. The whole app locking business should be reviewed because we pass pointers along without immediately bumping the refcount. Signed-off-by: Werner Koch <[email protected]>
* scd: Slight change to app->fnc.do_with_keygrip.Werner Koch2019-06-171-2/+5
| | | | | | | | | | | | | * scd/app-openpgp.c (do_with_keygrip): Return a real error code to avoid misinterpretation of the result. Also fix the case for a too small buffer. -- The only real chnage is the case for a too small buffer. That should in general never happen but if so we now return an error instead of success. Signed-off-by: Werner Koch <[email protected]>
* scd: Add new command: KEYINFO.NIIBE Yutaka2019-04-251-0/+10
| | | | | | | | | | | | | | | * scd/app-common.h (struct app_ctx_s): Add with_keygrip function. * scd/app-openpgp.c (do_with_keygrip): New. * scd/app.c (app_do_with_keygrip): New. * scd/command.c (cmd_keyinfo): New. (send_keyinfo): New. -- KEYGRIP_ACTION_LOOKUP is not yet used. It will be used for directly asking PK* action to determine an APP. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: New options --info and --info-only for READKEY.Werner Koch2019-04-031-3/+11
| | | | | | | | | | | | | | | | | | | | | | * scd/command.c (cmd_readkey): New options --info and --info-only. * scd/app.c (app_readkey): New arg 'flags'. * scd/app-common.h (APP_READKEY_FLAG_INFO): New. (struct app_ctx_s): New args 'ctrl' and 'flags' for member readkey. Change all implementers. * scd/app-nks.c (do_readkey): Stub implementation of APP_READKEY_FLAG_INFO. * scd/app-openpgp.c (do_readkey): Implement APP_READKEY_FLAG_INFO. * scd/app-piv.c (do_readkey): Ditto. -- This feature allows to quickly get the keygrip and in most cases also the usage flags for one specific keyref. Example: <- readkey --info-only PIV.9D -> S KEYPAIRINFO FC6061FB457224370B85C6F34DD56CD29E669620 PIV.9D e -> OK Signed-off-by: Werner Koch <[email protected]>
* scd: New option --application-priority.Werner Koch2019-03-281-0/+1
| | | | | | | | | | | | * scd/scdaemon.c (oApplicationPriority): New. (opts): Add "application_priority". (main): Process option. * scd/app.c (app_update_priority_list): New. (get_supported_applications): Take apps from global list. * tools/gpgconf-comp.c (gc_options_scdaemon): Add option. Signed-off-by: Werner Koch <[email protected]>
* scd: Rename a shared info field name.Werner Koch2019-03-051-1/+2
| | | | | | | | * scd/app-piv.c (app_select_piv): * scd/app-common.h (struct app_ctx_s): Rename 'card_version' to 'cardversion'. Rename all users. Add 'appversion'. Signed-off-by: Werner Koch <[email protected]>
* scd:piv: Implement import of private keys for Yubikeys.Werner Koch2019-03-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/app-piv.c (concat_tlv_list): Add arg 'secure' and adjust callers. (writekey_rsa, writekey_ecc): New. (do_writekey): New. (do_writecert): Provide a better error message for an empty cert. (app_select_piv): Register do_writekey. * scd/iso7816.c (iso7816_send_apdu): New. * scd/app-common.h (APP_WRITEKEY_FLAG_FORCE): New. * agent/command.c (cmd_keytocard): Make the timestamp optional. * tools/card-call-scd.c (inq_writekey_parms): Remove. (scd_writekey): Rewrite. * tools/gpg-card.c (cmd_writekey): New. (enum cmdids): Add cmdWRITEKEY. (dispatch_command, interactive_loop): Call cmd_writekey. -- This has been tested with gpgsm and RSA keys. For ECC keys only partly tested using the sample OpenPGP nistp256 and nistp384 keys because gpgsm does not yet support ECC certificates and thus we can't write the certificates to the cert object after a writekey. Note that they nevertheless show up in "gpgcard list" because gpg-card searches for them in gpg and gpgsm. However, this does not work completely. Signed-off-by: Werner Koch <[email protected]>
* scd: Simplify the app_readkey parameters.Werner Koch2019-02-261-2/+4
| | | | | | | | | | | | | | * scd/app-help.c (app_help_pubkey_from_cert): New. * scd/command.c (cmd_readkey): Refactor to use that new function and handle the --advanced flag only here. * scd/app.c (app_readkey): Remove parm advanced. * scd/app-common.h (struct app_ctx_s): Remove parm advanced from the readkey member. * scd/app-nks.c (do_readkey): Adjust for removed parm. * scd/app-piv.c (do_readkey): Ditto. * scd/app-openpgp.c (do_readkey): Ditto. Signed-off-by: Werner Koch <[email protected]>
* scd: Make app_genkey and supporting ISO function more flexible.Werner Koch2019-02-061-4/+4
| | | | | | | | | | | | | | | | | | | * scd/app.c (app_genkey): Add arg keytype. * scd/app-common.h (struct app_ctx_s): Fitto for the genkey member. * scd/command.c (cmd_genkey): Adjust for change. * scd/iso7816.c (do_generate_keypair): Replace arg read_only by new args p1 and p2. (iso7816_read_public_key): Adjust for this. (iso7816_generate_keypair): Add new args p1 and p2. * scd/app-openpgp.c (do_genkey): Adjust for changes. -- The OpenPGP card creates keys according to parameters read from a data object. Other cards we are about to implement require a direct specification of the requested keytype. This patch implements the required changes. Signed-off-by: Werner Koch <[email protected]>
* scd: Fix parameter name of app_change_key.Werner Koch2019-02-061-4/+7
| | | | | | | | | | | * scd/app-common.h (APP_GENKEY_FLAG_FORCE): New. * scd/app.c (app_change_pin): Rename arg reset_mode to flags and change from int to unsigned int. -- This is basically a documentation fix. Signed-off-by: Werner Koch <[email protected]>
* card: Support factory reset for Yubikey PIV application.Werner Koch2019-01-291-0/+1
| | | | | | | | | | | | | | | | | * scd/app-common.h (struct app_ctx_s): Add field cardtype. * scd/app.c (app_new_register): Set cardtype for yubikey. (app_getattr): Add CARDTYPE. (app_write_learn_status): Emit new attribute. * scd/app-piv.c (do_getattr): Add CHV-USAGE. (do_learn_status): Emit it. * tools/card-tool.h (struct card_info_s): Add field cardtype. * tools/card-call-scd.c (learn_status_cb): Parse "CARDTYPE". * tools/gpg-card-tool.c (list_piv): Print PIN usage policy. (list_card): Print card type. (cmd_factoryreset): Implement for Yubikey with PIV. Signed-off-by: Werner Koch <[email protected]>
* scd: Add option --clear to PASSWD.Werner Koch2019-01-211-2/+3
| | | | | | | | | | | | | | | * scd/command.c (cmd_passwd): Add option --clear. (send_status_printf): New. * scd/app-common.h (APP_CHANGE_FLAG_CLEAR): New. * scd/app-nks.c (do_change_pin): Return an error if that option is used. * scd/app-openpgp.c (do_change_pin): Ditto. -- Card application may support this option to clear the PIN verification status of a specific PIN. Signed-off-by: Werner Koch <[email protected]>
* scd: Add very basic support for PIV cards.Werner Koch2019-01-201-0/+3
| | | | | | | | | | | | | | * scd/app-piv.c: New. * scd/Makefile.am (card_apps): Add app-piv.c * scd/app.c (app_new_register): Try to get a Yubikey serial number. Detect the PIV application. (get_supported_applications): Add "piv". -- Right now this allows the use of the authentication key (9A) for SSH authentication. More support will follow soon. Tested with Yubikey-5.
* scd: Fix RESET command handling (more).NIIBE Yutaka2017-02-171-1/+2
| | | | | | | | | | | | | | | * scd/app-common.h (struct app_ctx_s): Add reset_requested. * scd/app.c (app_reset): Locking APP, set reset_requested. (deallocate_app): Release the lock. (release_application): Add LOCKED_ALREADY argument. (scd_update_reader_status_file): Hold the lock when accessing APP. When reset_requested is set, close the reader and deallocate APP. * scd/command.c (open_card_with_request, cmd_restart): Follow the change of release_application. (send_client_notifications): Here it calls release_application holding the lock. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: More changes on watching removal of card/reader.NIIBE Yutaka2017-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/app-common.h (struct app_ctx_s): Rename field to periodical_check_needed. * scd/scdaemon.c (update_usb): Rename from update_fdset_for_usb. Don't use libusb_get_pollfds any more. (scd_kick_the_loop): New. (need_tick): Follow the rename. (handle_connections): No libusb event handling here. * scd/app.c (app_new_register): Follow the change of rename. (select_application, scd_update_reader_status_file): Likewise. * scd/ccid-driver.c (ccid_usb_thread_is_alive): New. (intr_cb): Call scd_kick_the_loop. (ccid_usb_thread): New. Thread to invoke INTERRUPT callback. (ccid_open_usb_reader): Add thread invocation. (ccid_require_get_status): Remove LIBUSB_WORKS_EXPECTED_FOR_INTERRUPT_ENDP. (do_close_reader): Carefully handle handle->transfer. (get_escaped_usb_string): Insert npth_unprotect/npth_protect. (do_close_reader, bulk_out, bulk_in, abort_cmd, ccid_slot_status) (ccid_transceive, ccid_transceive_secure): Likewise. -- It found that libusb_get_pollfds is not supported on Windows. Besides, it's a bit difficult to use for the select loop. Thus, we use the thread named ccid_usb_thread, instead. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Improve watching USB device removal.NIIBE Yutaka2017-01-271-2/+0
| | | | | | | | | | | | | | | | | | | | | | | * scd/apdu.c(struct reader_table_s): Add require_get_status. (apdu_connect): Change return value meaning. Call apdu_reset here. * scd/app.c (app_new_register): Add require_get_status. (select_application): Use the return value of apdu_connect. (scd_update_reader_status_file): Call update_fdset_for_usb with checking all_have_intr_endp. (app_list_start, app_list_finish): Remove. * scd/ccid-driver.c (struct ccid_driver_s): Add transfer. (intr_cb): Don't call libusb_transfer in this callback. (ccid_require_get_status): New. (do_close_reader): Call libusb_transfer here. * scd/scdaemon.c (update_fdset_for_usb): Remove the first argument. -- With Gnuk Token, it works fine as expected. With Gemalto reader, intr_cb is not called when card is removed. So, the macro LIBUSB_WORKS_EXPECTED_FOR_INTERRUPT_ENDP is not defined yet. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Cleanup SERIALNO protocol.NIIBE Yutaka2017-01-181-1/+1
| | | | | | | | | | | | | | | | | | | | * scd/app.c (app_get_serial_and_stamp): Remove. (app_get_serialno): New. (app_write_learn_status): Use send_status_direct. (app_getattr): Use app_get_serialno for SERIALNO and send with send_status_direct. * scd/app-openpgp.c (do_getattr): Likewise. * scd/command.c (cmd_serialno): Don't send TIMESTAMP of 0. (cmd_learn): Likewise. Don't inquire with TIMESTAMP of 0. -- In the SERIALNO protocol, timestamp used to be considered, but had never used at all. In the new implementation, removed card/token is always detected and connection becomes invalid, no timestamp is required any more. Examined scute and poldi as well for this protocol change. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Add "card_list" sub command for GETINFO.NIIBE Yutaka2017-01-181-0/+1
| | | | | | | | * scd/app.c (app_send_card_list): New. * scd/command.c (cmd_getinfo): Fix "status" sub command. Add "card_list" sub command. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Add --demand option for SERIALNO.NIIBE Yutaka2017-01-161-1/+2
| | | | | | | | | | | | | | | * scd/app.c (select_application): Add SERIALNO_BIN and SERIALNO_BIN_LEN arguments. Return matched APP with a serial number when specified. * scd/command.c (open_card): Modify for the implicit open only. (open_card_with_request): New for explicit open and support match with a serial number. (cmd_serialno): Support --demand option. (cmd_learn, cmd_readcert, cmd_readkey, cmd_pksign, cmd_pkauth) (cmd_pkdecrypt, cmd_getattr, cmd_setattr, cmd_writecert, cmd_writekey) (cmd_genkey, cmd_random, cmd_passwd, cmd_checkpin, cmd_apdu): Follow the change of open_card. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Support multiple readers by CCID driver.NIIBE Yutaka2017-01-061-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/apdu.c (new_reader_slot): Lock is now in apdu_dev_list_start. (close_pcsc_reader_direct, close_ccid_reader): RDRNAME is handled... (apdu_close_reader): ... by this function now. (apdu_prepare_exit): Likewise. (open_ccid_reader): Open with dev_list. (apdu_dev_list_start, apdu_dev_list_finish): New. (apdu_open_one_reader): New. (apdu_open_reader): Support multiple readers. * scd/app.c (select_application): With SCAN, opening all readers available, and register as new APP. (app_write_learn_status): app->ref_count == 0 is valid for APP which is not yet used. (app_list_start, app_list_finish): New. * scd/ccid-driver.c (struct ccid_driver_s): Remove RID and BCD_DEVICE. Add BAI. (parse_ccid_descriptor): BCD_DEVICE is now on the arguments. (ccid_dev_scan, ccid_dev_scan_finish): New. (ccid_get_BAI, ccid_compare_BAI, ccid_open_usb_reader): New. (ccid_open_reader): Support multiple readers. (ccid_set_progress_cb, ccid_close_reader): No RID any more. -- With this change, multiple readers/tokens are supported by the internal CCID driver of GnuPG. Until the changes of upper layers (scdaemon, gpg-agent, and gpg front end), only a single reader is used, though. Signed-off-by: NIIBE Yutaka <[email protected]>