aboutsummaryrefslogtreecommitdiffstats
path: root/scd/apdu.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Use gpgrt_process_spawn API from libgpg-error.NIIBE Yutaka2024-07-091-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * agent/genkey.c (do_check_passphrase_pattern): Use the gpgrt API. * common/asshelp.c (start_new_service): Ditto. * common/exechelp.h: Remove gnupg_process_spawn API. * common/exechelp-posix.c: Remove gnupg_process_spawn implementation. * common/exechelp-w32.c: Likewise. * common/exectool.c (gnupg_exec_tool_stream): Use the gpgrt API. * common/t-exechelp.c (test_pipe_stream): Remove. * dirmngr/ldap-wrapper.c (destroy_wrapper, ldap_reaper_thread): Use the gpgrt API. (ldap_wrapper_connection_cleanup, ldap_wrapper): Ditto. * dirmngr/ldap.c, g10/call-keyboxd.c: No need to include exechelp.h. * g10/photoid.c (run_with_pipe, show_photo): Use the gpgrt API. * g13/be-encfs.c (run_umount_helper, run_encfs_tool): Ditto. * g13/g13.c, g13/mount.c, g13/runner.c: No need to include exechelp.h. * scd/apdu.c: No need to include exechelp.h. * scd/app.c (report_change): Use the gpgrt API. * sm/export.c, sm/import.c: No need to include exechelp.h. * tests/gpgscm/ffi.c (proc_object_finalize, proc_wrap) (do_process_spawn_io, do_process_spawn_fd, do_process_wait): Use the gpgrt API. * tools/gpg-auth.c: No need to include exechelp.h. * tools/gpg-card.c (cmd_gpg): Use the gpgrt API. * tools/gpg-connect-agent.c: No need to include exechelp.h. * tools/gpg-mail-tube.c (mail_tube_encrypt, prepare_for_appimage) (start_gpg_encrypt): Use the gpgrt API. * tools/gpgconf-comp.c (gpg_agent_runtime_change) (scdaemon_runtime_change, tpm2daemon_runtime_change) (dirmngr_runtime_change, keyboxd_runtime_change) (gc_component_launch, gc_component_check_options) (retrieve_options_from_program): Ditto. * tools/gpgconf.c (show_versions_via_dirmngr): Ditto. * tools/gpgtar-create.c (gpgtar_create): Ditto. * tools/gpgtar-extract.c (gpgtar_extract): Ditto. * tools/gpgtar-list.c (gpgtar_list): Ditto. -- GnuPG-bug-id: 7192 Signed-off-by: NIIBE Yutaka <[email protected]>
* indent: Fix spellingDaniel Kahn Gillmor2024-05-311-1/+1
| | | | | | | | | | | | | -- These are non-substantive corrections for minor spelling mistakes within the GnuPG codebase. With something like this applied to the codebase, and a judiciously tuned spellchecker integrated as part of a standard test suite, it should be possible to keep a uniform orthography within the project. GnuPG-bug-id: 7116
* scd: Avoid buffer overrun with more than 16 PC/SC readers.Jakub Jelen2024-05-281-1/+1
| | | | | | | | | | | | * scd/apdu.c (apdu_dev_list_start): Fix end condition. -- Signed-off-by: Jakub Jelen <[email protected]> This is part of GnuPG-bug-id: 7129 Fixes-commit: e8534f899915a039610973a84042cbe25a5e7ce2
* scd: New option --debug-allow-pin-logging.Werner Koch2023-11-211-4/+4
| | | | | | | | | | | | | * scd/scdaemon.c (oDebugAllowPINLogging): New. (opts): Add option. (main): Set option. * scd/scdaemon.h (opt): Add debug_allow_pin_logging. * scd/apdu.c (pcsc_send_apdu): Do not hide the PIN dat in the debug output if the option is set. (send_apdu_ccid): Ditto. -- This option is only required during development.
* scd: Minor debug output tweakWerner Koch2023-11-161-1/+3
| | | | | * scd/apdu.c (send_le): Do not dump "[all zero]" if tehre is no data. * scd/iso7816.c (iso7816_select_mf): Cosmetic fix.
* scd: Fix cmd_apdu on error.NIIBE Yutaka2023-05-011-1/+1
| | | | | | | | | | * scd/command.c (cmd_apdu): Fix the code path on error. -- GnuPG-bug-id: 6476 Reported-by: Robin Krahl Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Redact --debug cardio output of a VERIFY APDU.Werner Koch2022-11-171-2/+16
| | | | | | | | | | * scd/apdu.c (pcsc_send_apdu) [DBG_CARD_IO]: Detect and redact a VERIFY. (send_apdu_ccid): Ditto. -- This should handle the most common case. GnuPG-bug-id: 5085
* scd: Fix use of SCardListReaders for PC/SC.NIIBE Yutaka2022-05-171-1/+1
| | | | | | | | | | * scd/apdu.c (apdu_dev_list_start): Initialize NREADER. -- Reported-by: Ludovic Rousseau GnuPG-bug-id: 5979 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd,pcsc: Fix error handling for a reader with reader-port.NIIBE Yutaka2022-01-041-5/+1
| | | | | | | | | | | * scd/apdu.c (apdu_open_reader): Make sure dl->idx is always incremented to handle error from open_pcsc_reader correctly. -- Reported-by: Anže Jenšterle GnuPG-bug-id: 5758 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Don't release the context until list_finish for PC/SC.NIIBE Yutaka2021-08-201-1/+8
| | | | | | | | | | | * scd/apdu.c (apdu_dev_list_start): Increment PCSC.COUNT here. (apdu_dev_list_finish): Decrement PCSC.COUNT. -- GnuPG-bug-id: 5416 Fixes-commit: 32baa9acfb153004bdb2509f9516482b78f256a4 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Improve reading of binary records.Werner Koch2021-06-181-8/+3
| | | | | | | | | | | | | * scd/iso7816.c (iso7816_read_binary_ext): Handle the 0x6a86 SW the same as 6b00. * scd/apdu.c (apdu_get_atr): Modify debug messages. * scd/app-p15.c (app_select_p15): Print FCI on error. (read_p15_info): Clean up diag in presence of debug options. -- Some cards return 6a86 instead of 6b00. Signed-off-by: Werner Koch <[email protected]>
* scd: Fix READER-PORT option handling for PC/SC.NIIBE Yutaka2021-06-071-17/+27
| | | | | | | | | * scd/apdu.c (apdu_open_reader): READERNO should be -1 when READER-PORT is specified for PC/SC. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Remove wrong assertion and add protection to PCSC.COUNT.NIIBE Yutaka2021-05-141-1/+2
| | | | | | | * scd/apdu.c (apdu_dev_list_finish): Fix for calling release_pcsc_context. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Serialize READER_TABLE access for PC/SC.NIIBE Yutaka2021-05-111-15/+19
| | | | | | | | | | | | | * scd/apdu.c (apdu_dev_list_start): Remove locking READER_TABLE_LOCK. Don't increment PCSC.COUNT here. (apdu_dev_list_finish): Don't decrement PCSC.COUNT here. (apdu_open_reader): Protect access with READER_TABLE_LOCK. -- GnuPG-bug-id: 5416 Fixes-commit: 8d81fd7c01e8dfacc719ff190f8e364014e32fdf Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Fix close_pcsc_reader.NIIBE Yutaka2021-05-101-9/+9
| | | | | | | | | | | * scd/apdu.c (close_pcsc_reader): Don't touch .RDRNAME field. (apdu_dev_list_finish): Clear .RDRNAME field and replace call of close_pcsc_reader by release_pcsc_context. Add assertion. -- GnuPG-bug-id: 5416 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Make sure releasing PC/SC context.NIIBE Yutaka2021-05-101-6/+16
| | | | | | | | | | | | * scd/apdu.c (release_pcsc_context): New. (close_pcsc_reader): Use release_pcsc_context. Add assertion. (apdu_dev_list_start): Replace call of close_pcsc_reader into release_pcsc_context, add condition. -- GnuPG-bug-id: 5416 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Increment PCSC.COUNT correctly.NIIBE Yutaka2021-05-071-2/+2
| | | | | | | | | * scd/apdu.c (open_pcsc_reader): PCSC.COUNT should be incremented before possible call of close_pcsc_reader. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Fix memory leak for RDRNAME and serialize access.NIIBE Yutaka2021-05-071-2/+6
| | | | | | | | | | * scd/apdu.c (close_pcsc_reader): Move locking to... (apdu_close_reader): ... here, as it's also needed for CCID driver. Free RDRNAME when closed. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Fix declarations for PC/SC access.NIIBE Yutaka2021-05-061-2/+2
| | | | | | | | * scd/apdu.c (pcsc_begin_transaction, pcsc_transmit): Use HANDLE. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Recover the partial match for PORTSTR for PC/SC.NIIBE Yutaka2021-05-061-1/+2
| | | | | | | | | * scd/apdu.c (apdu_open_reader): Allow partial match of PORTSTR again just like 2.2 does. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: When reader is specified, make sure only open once.NIIBE Yutaka2021-05-061-0/+5
| | | | | | | | | * scd/apdu.c (apdu_open_reader): Make sure not to try multiple times, when PORTSTR is specified. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Fix PC/SC removed card problemWerner Koch2021-04-291-0/+11
| | | | | | | | | | | * scd/apdu.c (pcsc_cancel): New. (pcsc_init): Load new function. (connect_pcsc_card): Use it after a removed card error. -- Well, that was easier than I expected yesterday. Signed-off-by: Werner Koch <[email protected]>
* scd: Fix problem with reader list becoming empty.Werner Koch2021-04-281-21/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | * scd/apdu.c (close_pcsc_reader): Do not decrement refcount if already zero. Always release context if or becomes zero. (apdu_dev_list_start): Unlock prior to close_pcsc_reader. For PC/SC increment the count. Always release the lock. (apdu_dev_list_finish): No more unlocking. Use close_pcsc_reader instead of code duplication. * scd/apdu.c (pcsc_error_string): Add an error code. * scd/scdaemon.c (scd_kick_the_loop): Fix a diagnostic. -- There was an obvious bug in that the pcsc.count could go below zero and thus there was no chance to get the context release. Releasing and recreating the context is at least under Windows important to get rit of the PCSC_E_SERVICE_STOPPED. Also removes a potential problem in holding the reader_table_lock between calls to apdu_dev_list_start apdu_dev_list_finish. There is no need for this. Instead we bump the pcsc.count. The reader_table_lock strategy should be reviewed; we may be able to remove it. Signed-off-by: Werner Koch <[email protected]>
* scd: Fix memory leaks.Jakub Jelen2021-04-131-0/+4
| | | | | | | | | | * scd/apdu.c (apdu_dev_list_start): Free DL. * scd/app-nks.c (pubkey_from_pk_file): Fix typo in condition. -- GnuPG-bug-id: 5393 Signed-off-by: Jakub Jelen <[email protected]>
* scd: Replace all assert macros by the log_assert macro.Werner Koch2021-03-311-9/+8
| | | | Signed-off-by: Werner Koch <[email protected]>
* scd: Fix PC/SC error handling at apdu_dev_list_start.NIIBE Yutaka2021-03-261-1/+3
| | | | | | | | | | | * scd/apdu.c (PCSC_E_NO_READERS_AVAILABLE): Add. (pcsc_error_to_sw): Handle PCSC_E_NO_READERS_AVAILABLE. (apdu_dev_list_start): Return error correctly. -- GnuPG-bug-id: 4864 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: New option --pcsc-shared.Werner Koch2021-03-121-2/+3
| | | | | | | | | | | | | | | | | * scd/scdaemon.h (opt): Add field opcsc_shared. * scd/scdaemon.c (opcscShared): New. (opts): Add "--pcsc-shared". (main): Set flag. * scd/apdu.c (connect_pcsc_card): Use it. (pcsc_get_status): Take flag in account. * scd/app-openpgp.c (cache_pin): Bypass in shared mode. (verify_chv2: Do not auto verify chv1 in shared mode. * scd/app-piv.c (cache_pin): By pass caceh in shared mode. -- This option should in general not be used. The patch tries to limit bad effects but using shared mode is somewhat dangerous depending on the other PC/SC users.
* scd:p15: Make it code work again for D-Trust cards.Werner Koch2021-02-231-0/+1
| | | | | | | | | | | | | | | | | | | * scd/app-p15.c (select_and_read_binary): Allow to skip the select. (select_and_read_record): Return the statusword. Silence error message for SW_FILE_STRUCT. (select_ef_by_path): Fix selection with a home_DF. (read_first_record): Fallback to read_binary for CardOS and return info about this. (read_ef_prkdf): Use info from read_first_record to decide whether to use record or binary mode. (read_ef_pukdf): Ditto. (read_ef_aodf): Ditto. (read_ef_cdf): Ditto. New arg cdftype for diagnostics. (read_p15_info): Pass cdftype. * scd/apdu.h (SW_FILE_STRUCT): New. * scd/apdu.c (apdu_strerror): Map that one to a string. * scd/iso7816.c (map_sw): and to a gpg-error.
* scd: Define new status wordWerner Koch2021-01-271-0/+1
| | | | | | | | * scd/apdu.h (SW_NO_CURRENT_EF): New. -- This merely to show better diagnostics. Used for example by CardOS 5.3.
* scd: New getinfo sub-command apdu_strerror.Werner Koch2020-11-271-2/+7
| | | | | | | | | * scd/apdu.c (apdu_strerror): Add missing status codes. * scd/command.c (cmd_getinfo): New sub-command apdu_strerror. -- This is quite handy for gpg-card's APDU command and avoids that we need to duplicate the mapping table or put it into a shared file.
* scd: Do not print reader status change with --debug cardio.Werner Koch2020-11-111-1/+1
| | | | | | | | | -- ... but use --debug reader for this. Signed-off-by: Werner Koch <[email protected]> (cherry picked from commit bd3b698d8ec427a02f2fa793777f2a88bc356f25)
* scd: Use lock_slot for apdu_send_direct.NIIBE Yutaka2020-11-051-1/+1
| | | | | | | | | | | | | * scd/apdu.c (apdu_send_direct): Use lock_slot. -- With trylock_slot, it may return SW_HOST_BUSY. This may occur when apdu_get_status is called by scd_update_reader_status_file. Simply using lock_slot is much easier for user of apdu_send_direct. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Internal CCID: Clear the handle after use.NIIBE Yutaka2020-09-281-1/+5
| | | | | | | * scd/apdu.c (close_ccid_reader): Clear the handle. (open_ccid_reader): Likewise. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: For PC/SC, send the ESC command at init for SPR532 reader.NIIBE Yutaka2020-09-251-25/+32
| | | | | | | | | | | | | | | | | | | | | * scd/apdu.c (struct reader_table_s): Remove is_spr532. (pcsc_vendor_specific_init): Send the ESC command for SPR532. (pcsc_pinpad_verify, pcsc_pinpad_modify): Remove no_lc hack. -- The "no_lc" hack lets PC/SC-lite send the ESC command for SPR532 internally, for pcsc_pinpad_verify. However, PC/SC-lite doesn't do that for pcsc_pinpad_modify, unfortunately. Besides, I'm not sure this hack works on Windows, which has different implementation of PC/SC service. It's better to send the ESC command by the driver explicitly, at the initialization. Sending the ESC command results PCSC_E_NOT_TRANSACTED error when a card is not active (that is the case, usually). We ignore this error. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Increase the number of supported readers from 4 to 16.Werner Koch2020-09-041-1/+2
| | | | | | | | | | -- The limit on 4 readers I introduced in 2003 is too low for some of our use cases. 16 looks better. TODO: Return a useful error message in gpg-card if the limit has been reached. Signed-off-by: Werner Koch <[email protected]>
* scd: Log info about CCIDs with permission problems.Werner Koch2020-08-121-3/+13
| | | | | | | * scd/apdu.c (open_ccid_reader): Add arg r_cciderr. (apdu_open_reader): Print a note on EPERM of the USB device. Signed-off-by: Werner Koch <[email protected]>
* scd: Map some error codes from libusb to ccid-driver error codes.Werner Koch2020-08-121-0/+7
| | | | | | | | | | | | | | | * scd/ccid-driver.h (CCID_DRIVER_ERR_USB_*): New error codes. * scd/apdu.h: New SW_HOST error codes. * scd/apdu.c (host_sw_string): Print them * scd/ccid-driver.c (map_libusb_error): New. (ccid_open_usb_reader, bulk_in, abort_cmd): Map libusb error codes. * scd/iso7816.c (map_sw): Map new codes to gpg-error. -- This change will help to get low level error conditions from hipher application code. Signed-off-by: Werner Koch <[email protected]>
* scd: Fix closing reader and reeleasing context in PC/SC.NIIBE Yutaka2020-07-171-0/+7
| | | | | | | | | | * scd/apdu.c (close_pcsc_reader): Unlock the reader_table_lock. (apdu_dev_list_finish): Release the context when no readers. -- Fixes-commit: 46d185f60397f68830bfdfb99627b29aea5016f1 Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: PC/SC: Don't release the context when it's in use.NIIBE Yutaka2020-07-171-1/+1
| | | | | | | | | | * scd/apdu.c (close_pcsc_reader): Check if it's not in the loop. -- GnuPG-bug-id: 4998 Reported-by: Kevin Locke Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Shorten cardio debug output for all zeroes.Werner Koch2020-06-291-4/+33
| | | | | | | * scd/apdu.c (all_zero_p): New. (send_le): Use it. Signed-off-by: Werner Koch <[email protected]>
* scd,pcsc: Use HANDLE for context and card.NIIBE Yutaka2019-09-171-28/+34
| | | | | | * scd/apdu.c (HANDLE): New. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Remove old fallback logic from CCID to PC/SC.gniibe/T4620NIIBE Yutaka2019-09-121-12/+5
| | | | | | * scd/apdu.c (apdu_dev_list_start): Return an error on failure. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd,pcsc: Support "reader-port" option for PC/SC reader.NIIBE Yutaka2019-09-121-29/+34
| | | | | | | * scd/apdu.c (apdu_open_reader): Skip use of a reader if it's not the one specified when it is specified. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd,pcsc: Remove the restriction of no-scanning in PC/SC.NIIBE Yutaka2019-09-111-10/+1
| | | | | | | | * scd/apdu.h (app_open_reader): Remove the last argument. * scd/apdu.c (app_open_reader): Ditto. * scd/app.c (select_application): Don't supply APP_EMPTY. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd,pcsc: Fix examining the list of readers.NIIBE Yutaka2019-09-111-5/+13
| | | | | | * scd/apdu.c (apdu_dev_list_start): Traverse the string+NUL carefully. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd,pcsc: Fix for initializing PC/SC.NIIBE Yutaka2019-09-111-9/+13
| | | | | | | * scd/apdu.c (pcsc_init): Load it at first. (apdu_open_reader): Check for the CCID internal driver. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd,pcsc: Support multiple card readers.NIIBE Yutaka2019-09-111-180/+217
| | | | | | | | | | | * scd/apdu.c (close_pcsc_reader, apdu_init): Clear pcsc.rdrname. (pcsc_init): Load of PC/SC module moved from ... (open_pcsc_reader): ... here. (apdu_dev_list_start): Add support for PC/SC. (apdu_dev_list_finish): Likewise. (apdu_open_reader): Likewise. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd,pcsc: Use a single context.NIIBE Yutaka2019-09-111-26/+46
| | | | | | | | | | | | | | * scd/apdu.c (pcsc): New variable. (struct reader_table_s): Remove pcsc.context from member. (pcsc_get_status, connect_pcsc_card): Use pcsc.context. (close_pcsc_reader): Release pcsc.context here with reference count. (pcsc_init): New. (open_pcsc_reader): Don't call pcsc_establish_context here. Call close_pcsc_reader instead of pcsc_release_context. (apdu_open_reader): Call pcsc_init if needed. (apdu_init): Initialize pcsc.count and pcsc.context. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Clean up the structure for future fix of PC/SC.NIIBE Yutaka2019-09-111-9/+9
| | | | | | | | | | | | * scd/apdu.c (struct dev_list): Rename from ccid_table, with void*. (open_ccid_reader): Follow the change. (apdu_dev_list_start, apdu_dev_list_finish): Likewise. (apdu_open_reader): Likewise. * scd/ccid-driver.c (ccid_dev_scan): Use void *. (ccid_dev_scan_finish, ccid_get_BAI, ccid_open_usb_reader): Likewise. * scd/ccid-driver.h: Change the APIs. Signed-off-by: NIIBE Yutaka <[email protected]>
* scd: Remove fallback mechanism to PC/SC.NIIBE Yutaka2019-08-061-8/+2
| | | | | | | * scd/apdu.c [HAVE_LIBUSB] (apdu_open_reader): Simply let it fail. GnuPG-bug-id: 4673 Signed-off-by: NIIBE Yutaka <[email protected]>