aboutsummaryrefslogtreecommitdiffstats
path: root/scd/apdu.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2024-07-09Use gpgrt_process_spawn API from libgpg-error.NIIBE Yutaka1-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]>
2024-05-31indent: Fix spellingDaniel Kahn Gillmor1-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
2024-05-28scd: Avoid buffer overrun with more than 16 PC/SC readers.Jakub Jelen1-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
2023-11-21scd: New option --debug-allow-pin-logging.Werner Koch1-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.
2023-11-16scd: Minor debug output tweakWerner Koch1-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.
2023-05-01scd: Fix cmd_apdu on error.NIIBE Yutaka1-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]>
2022-11-17scd: Redact --debug cardio output of a VERIFY APDU.Werner Koch1-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
2022-05-17scd: Fix use of SCardListReaders for PC/SC.NIIBE Yutaka1-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]>
2022-01-04scd,pcsc: Fix error handling for a reader with reader-port.NIIBE Yutaka1-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]>
2021-08-20scd: Don't release the context until list_finish for PC/SC.NIIBE Yutaka1-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]>
2021-06-18scd: Improve reading of binary records.Werner Koch1-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]>
2021-06-07scd: Fix READER-PORT option handling for PC/SC.NIIBE Yutaka1-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]>
2021-05-14scd: Remove wrong assertion and add protection to PCSC.COUNT.NIIBE Yutaka1-1/+2
* scd/apdu.c (apdu_dev_list_finish): Fix for calling release_pcsc_context. Signed-off-by: NIIBE Yutaka <[email protected]>
2021-05-11scd: Serialize READER_TABLE access for PC/SC.NIIBE Yutaka1-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]>
2021-05-10scd: Fix close_pcsc_reader.NIIBE Yutaka1-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]>
2021-05-10scd: Make sure releasing PC/SC context.NIIBE Yutaka1-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]>
2021-05-07scd: Increment PCSC.COUNT correctly.NIIBE Yutaka1-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]>
2021-05-07scd: Fix memory leak for RDRNAME and serialize access.NIIBE Yutaka1-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]>
2021-05-06scd: Fix declarations for PC/SC access.NIIBE Yutaka1-2/+2
* scd/apdu.c (pcsc_begin_transaction, pcsc_transmit): Use HANDLE. -- Signed-off-by: NIIBE Yutaka <[email protected]>
2021-05-06scd: Recover the partial match for PORTSTR for PC/SC.NIIBE Yutaka1-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]>
2021-05-06scd: When reader is specified, make sure only open once.NIIBE Yutaka1-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]>
2021-04-29scd: Fix PC/SC removed card problemWerner Koch1-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]>
2021-04-28scd: Fix problem with reader list becoming empty.Werner Koch1-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]>
2021-04-13scd: Fix memory leaks.Jakub Jelen1-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]>
2021-03-31scd: Replace all assert macros by the log_assert macro.Werner Koch1-9/+8
Signed-off-by: Werner Koch <[email protected]>
2021-03-26scd: Fix PC/SC error handling at apdu_dev_list_start.NIIBE Yutaka1-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]>
2021-03-12scd: New option --pcsc-shared.Werner Koch1-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.
2021-02-23scd:p15: Make it code work again for D-Trust cards.Werner Koch1-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.
2021-01-27scd: Define new status wordWerner Koch1-0/+1
* scd/apdu.h (SW_NO_CURRENT_EF): New. -- This merely to show better diagnostics. Used for example by CardOS 5.3.
2020-11-27scd: New getinfo sub-command apdu_strerror.Werner Koch1-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.
2020-11-11scd: Do not print reader status change with --debug cardio.Werner Koch1-1/+1
-- ... but use --debug reader for this. Signed-off-by: Werner Koch <[email protected]> (cherry picked from commit bd3b698d8ec427a02f2fa793777f2a88bc356f25)
2020-11-05scd: Use lock_slot for apdu_send_direct.NIIBE Yutaka1-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]>
2020-09-28scd: Internal CCID: Clear the handle after use.NIIBE Yutaka1-1/+5
* scd/apdu.c (close_ccid_reader): Clear the handle. (open_ccid_reader): Likewise. Signed-off-by: NIIBE Yutaka <[email protected]>
2020-09-25scd: For PC/SC, send the ESC command at init for SPR532 reader.NIIBE Yutaka1-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]>
2020-09-04scd: Increase the number of supported readers from 4 to 16.Werner Koch1-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]>
2020-08-12scd: Log info about CCIDs with permission problems.Werner Koch1-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]>
2020-08-12scd: Map some error codes from libusb to ccid-driver error codes.Werner Koch1-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]>
2020-07-17scd: Fix closing reader and reeleasing context in PC/SC.NIIBE Yutaka1-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]>
2020-07-17scd: PC/SC: Don't release the context when it's in use.NIIBE Yutaka1-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]>
2020-06-29scd: Shorten cardio debug output for all zeroes.Werner Koch1-4/+33
* scd/apdu.c (all_zero_p): New. (send_le): Use it. Signed-off-by: Werner Koch <[email protected]>
2019-09-17scd,pcsc: Use HANDLE for context and card.NIIBE Yutaka1-28/+34
* scd/apdu.c (HANDLE): New. Signed-off-by: NIIBE Yutaka <[email protected]>
2019-09-12scd: Remove old fallback logic from CCID to PC/SC.gniibe/T4620NIIBE Yutaka1-12/+5
* scd/apdu.c (apdu_dev_list_start): Return an error on failure. Signed-off-by: NIIBE Yutaka <[email protected]>
2019-09-12scd,pcsc: Support "reader-port" option for PC/SC reader.NIIBE Yutaka1-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]>
2019-09-11scd,pcsc: Remove the restriction of no-scanning in PC/SC.NIIBE Yutaka1-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]>
2019-09-11scd,pcsc: Fix examining the list of readers.NIIBE Yutaka1-5/+13
* scd/apdu.c (apdu_dev_list_start): Traverse the string+NUL carefully. Signed-off-by: NIIBE Yutaka <[email protected]>
2019-09-11scd,pcsc: Fix for initializing PC/SC.NIIBE Yutaka1-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]>
2019-09-11scd,pcsc: Support multiple card readers.NIIBE Yutaka1-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]>
2019-09-11scd,pcsc: Use a single context.NIIBE Yutaka1-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]>
2019-09-11scd: Clean up the structure for future fix of PC/SC.NIIBE Yutaka1-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]>
2019-08-06scd: Remove fallback mechanism to PC/SC.NIIBE Yutaka1-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]>