Commit Graph

274 Commits

Author SHA1 Message Date
Peter Marschall 16c889cf7d spelling fixes
Fix various spelling errors, mostly in comments but also in texts displayed.

Errors found & interactively fixed using 'codespell', with additional manual
checks after the fixes.
2020-08-30 10:35:14 +02:00
Zoltan Kelemen eb3e00a385 Corrected highly misleading, confusing and ambiguous use of PIN length_offset
field. Now only the PIN offset fields are used. Also added error checking for
invalid values.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen 80853bda31 Only enable static frame size for PIN padding when padding length is below
maximum limits. Otherwise resort to adaptive support.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen afffeccc29 Fixed problems with PIN min/max length handling:
- The wrong PIN was selected from the sc_pin_cmd_data structure.
- When the PIN max value was zero from the caller (meaning unknown max), the
  reader max value was not used.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen 1dc359cb61 Fix for issue #1999:
- Reset context to undefined handle value on error since call may alter
  output parameter.
- Continue to assume -1 as undefined handle value in all PCSC
  implementations, to keep this fix as small and surgical as possible.
2020-07-22 22:55:30 +02:00
Frank Morgner 1c7b311289 pcsc: immediately exit on hotplug events
fixes delayed notification for removed readers

closes https://github.com/OpenSC/OpenSC/issues/2021
2020-06-09 12:07:04 +02:00
Frank Morgner 8f6e5dc2b0 Unbreak wait for events
By Jabuk Jelen

Fixes https://github.com/OpenSC/OpenSC/issues/2021
2020-06-09 12:07:04 +02:00
Jakub Jelen 295f399304 reader-pcsc: Avoid use after free (CID 355473) 2020-05-07 02:32:46 +02:00
Frank Morgner 2c26b7392d opensc-notify: handle reader insertion/removal events
- If readers are attatched, the new reader is probed for a card to check
if a notification needs to be sent
- removal of readers are not notified to the user, we assume that PC/SC
sends the correct card removal event
- The list of readers to be monitored is adjusted once a reader (dis)appears
- On macOS, without PnP notification, we always check for new/removed
readers with SCardListReaders
- fixes interrupt handling in opensc-notify on Unix

fixes https://github.com/OpenSC/OpenSC/issues/1874
2020-04-06 18:08:34 +02:00
Frank Morgner 14e396273c reader-pcsc: fixed handling of detatching events
- allows re-attatching a reader to an existing reader object by
resetting the SC_READER_REMOVED flag
- readers that are flagged with SC_READER_REMOVED are not used for
SCardGetStatusChange to avoid SCARD_E_UNKNOWN_READER

fixes https://github.com/OpenSC/OpenSC/issues/1903
2020-03-03 22:55:27 +01:00
Doug Engert 0fd77d642c Minidriver additionl fixes
Use __FUNCTION__ as defind in log.h so will compile with any compiler.
logprint additional handles as size_t

Add check in reader-pcsc.c pcsc_user_reader for minidriver only.

 On branch minidriver-5
 Changes to be committed:
	modified:   src/libopensc/reader-pcsc.c
	modified:   src/minidriver/minidriver.c
2020-02-01 22:42:02 +01:00
Doug Engert 111246f1d2 Better error debug messages for Minidriver
Add MD_FUNC_CALLED(pCardData, level) and  MD_FUNC_RETURN(pCardData, level, ...)
macros.

Handles are type __int3264 in VS2015 are casted as size_t when printing so
all bytes are printed. size_t on Windows are also treated as 32 or 64 bits.
SC_FORMAT_LEN_SIZE is used in the format.
 (Works with VS2105 needs to be tested on other platforms.)

 On branch minidriver-4

 Changes to be committed:
	modified:   minidriver.c

Minidriver.c and reader-pcsc.c - reuse OpenSC reader structure

Windows CNG is managing the insertion and removal of the reader and the card
and will call CardAcquireContext and CardDeleteContext as needed if
the card or reader change. But different processes or threads may establish
different PCSC connects to the same reader and card but with different handles.

Reuse the OpenSC reader when windows uses the same reader but with different
handles. Tests show the certutil -v -scinfo works the same.
Associate_card is only need when called from
CardAcquireContext and disassociate_card is only need when called from
CardDeleteContext.
No need to call reinit_card_for(pCardData, name) just because the handles changed.

This may be the fix for #1763 because calls like CardCreateContainerEx remain
in card state rather then being lost when the handles changed.

 Changes to be committed:
	modified:   src/libopensc/reader-pcsc.c
	modified:   src/minidriver/minidriver.c
2020-02-01 22:42:02 +01:00
Jakub Jelen 23fcccecf4 reader-pcsc: Add a way to create corpus files for fuzzing 2020-01-07 17:18:05 +01:00
Jakub Jelen 326955a147 reader-pcsc: Preserve the CARD_PRESENT flag to make sure the card is detected after reader reinsertion 2019-11-28 11:18:25 +01:00
Jakub Jelen fb15a7dd86 reader-pcsc: Handle yubikey reinsertion
When the application (NSS) does not use WaitForSlotEvent and just
opportunistically tries to detect card and reader removals with
C_GetSlotInfo() and C_GetSessionInfo(), we might get errors in
various plcaes, in the sc_lock() function, when we try to transfer
other messages or when we ask for the reader status.

This is generally too late to call any disconnect functions because no
PC/SC handles are valid anymore. The reader state from PCSC
is searched by name so we can be pretty sure it is very similar
reader (with same name as the old one) and I hope we can reuse the
reader structure and just call the pcsc_connect() on that as we do
with invalid handles.

Otherwise we detect this issue in the refresh_attributes() (called
from C_GetSlotInfo()), where we can report the slot change in the
expected manner.

Fixes #1822
2019-11-01 15:50:34 +01:00
Frank Morgner 7d8009e429 PC/SC: handle resets in SCardTransmit
fixes https://github.com/OpenSC/OpenSC/issues/1725
2019-08-20 13:25:06 +02:00
Pierre Ossman bc4eeda573 Remove readers when smart card service stops
The code already removes all active cards when the service goes
away, but it doesn't remove the reader. This can be a bit confusing
since they will still be polled and listed.
2019-03-07 21:51:02 +02:00
Pierre Ossman 9ed5f63c17 Fix smart card removal handling for older PC/SC
Older PC/SC doesn't have the code SCARD_E_NO_READERS_AVAILABLE, so fix
the code to handle such systems as well.
2019-03-07 21:51:02 +02:00
Pierre Ossman 9e9bdac2f1 Handle reader going missing
It might just be this specific reader going missing, and not all
of them.
2019-03-07 21:51:02 +02:00
Frank Morgner 155b197932 sc-hsm: require T=1 connection 2019-03-05 13:47:45 +01:00
Alex Karabanov 04ef9dbf3b Fix build on cygwin in strict mode (#1605) 2019-02-11 20:50:12 +01:00
Frank Morgner 5474370b17 always log APDUs with SC_LOG_DEBUG_NORMAL 2018-12-06 09:26:42 +01:00
Frank Morgner 907c9479e2 replace sc_debug_hex with sc_log_hex 2018-12-06 09:26:42 +01:00
Frank Morgner 24b50a4277 replace sc_debug with sc_log 2018-12-06 09:26:42 +01:00
Shahin Hajikhorasani 0fca7df33a Update reader-pcsc.c (#1537)
Error handling extended in case of changing the card reader
2018-11-25 22:05:35 +01:00
Andreas Kemnade eddea6f3c2 fix logic of send/recv sizes in config files
- they are not set if
  SCardControl(card_handle, CM_IOCTL_GET_FEATURE_REQUEST, ...
  fails
- regarding max_send_size the logic is inverted
2018-11-09 08:56:53 +01:00
Raul Metsma dfe932d00d OMNIKEY 3x21 and 6121 Smart Card Reader are not pinpad readers
macOS 10.13 ships with ccid driver 1.4.27 (fixed in 1.4.29) and this version identifies these readers wrongly as pinpad readers.

Signed-off-by: Raul Metsma <raul@metsma.ee>
2018-07-28 13:42:20 +02:00
David Ward 14afdf38e3 Do not temporarily set SC_READER_REMOVED on all readers (#1335)
* reader-pcsc: Do not temporarily set SC_READER_REMOVED on all readers

Fixes #1324.

* reader-cryptotokenkit: Do not temporarily set SC_READER_REMOVED on all readers

See #1324.
2018-05-18 13:11:49 +02:00
Frank Morgner 36b88c3ad7 reader-pcsc: allow fixing the length of a PIN
fixes https://github.com/OpenSC/OpenSC/issues/1221
closes https://github.com/OpenSC/OpenSC/pull/1288
2018-05-18 12:57:46 +02:00
Frank Morgner d11e05fe1f Generalized configuration option `ignored_readers` 2018-05-18 12:46:51 +02:00
Frank Morgner 4e83e2e1b3 reader-pcsc: fixed default for disconnect_action
Initialize it to "leave", even if no pcsc configuration block was given.
2018-04-26 14:48:54 +02:00
Peter Marschall 5abe99d228 fix typos
Mass-typo fixing, almost exclusively in comments and text strings.

While at it also fixed a few (very few) grammar errors.
2018-04-15 09:34:45 +02:00
Frank Morgner 74553a5a8f PC/SC: don't reset the card on disconnection
Windows/macOS (minidriver/tokend) handle the authentication status and
perform an explicit logout on shutdown. PKCS#11 standard requires a
session for logging into the card; when closing the session we perform
an explicit logout. Hence, the authentication status should be reset
even if not performing a reset on disconnect.
2018-01-22 15:27:18 +01:00
Frank Morgner 10101984da fixed dereferencing type-punned pointer 2017-11-09 12:42:29 +01:00
Frank Morgner 251a5f9fef reader-pcsc: use sc_apdu2bytes for PIN APDU 2017-11-09 12:42:29 +01:00
Frank Morgner 496e2afc9e reader-pcsc: allow no attached reader for notification
Return an error only on OS X, where PnP notification is not supported.
2017-08-02 19:07:16 +02:00
Frank Morgner 7cff9c2810 Force T=1 for contactless cards
Communication defined by ISO/IEC 14443 is identical to T=1, so make
sure we connect in the right mode to the card so that the constructed
APDUs can be handled by the card.
2017-05-19 14:57:56 +02:00
Frank Morgner fcc8ea5939 reader-pcsc: removed cardmod driver
- pcsc driver takes over all the functionality
- no dedicated reader driver config values for cardmod, use application
  specific blocks to define a different behavior for the pcsc reader if
  needed
- removes legacy code; requiring at least libpcsclite 1.6.5

Fixes https://github.com/OpenSC/OpenSC/issues/892
2017-04-20 10:29:30 +02:00
Maciej S. Szmigiero 58c4de26a7 Fix cases of log function format strings not being a string literal
Looks like Travis CI build server found a few cases of log function format
string not being a string literal (now that log functions have necessary
attributes to check for such things).
Some instances clearly aren't a real problem, but to be future-proof and to
avoid compiler warnings let's fix all of them (that I was able to find in
code).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 62cbda6cd9 Fix log messages format and parameter issues flagged by GCC
Since "Add GCC format checking attributes to log functions" commit GCC
warns us about problems with format strings and their arguments provided
to OpenSC message logging functions.

This commit fixes all cases where GCC warned about incorrect format on
64-bit Linux, 32-bit and 64-bit mingw builds (with SM and OpenSSL enabled).
Well, almost all since on mingw GCC does not recognize "ll" size specifier
(present at least since Visual Studio 2005, also in mingw own CRT) so these
(few) warnings about it remain.

In most cases format size specifier for size_t type was missing (usually
size was left at default int level, with is different on 64-bit x86).
Some formats had too few / too many arguments.
In some cases pointers were printed as integers.
Some long variables were missing "l" prefix (especially with regard to %x
format).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 7f778ccff8 Fix most of warnings shown when building on Linux and mingw
This commit fixes most of warnings shown by GCC on 64-bit Linux, 32-bit and
64-bit mingw builds (with SM and OpenSSL enabled).

These warnings were mostly caused by missing casts.

In minidriver there was also a bit of unused variables and dead code.

Remaining warnings on mingw are mostly caused by GCC not recognizing on
this platform "ll" size specifier (present at least since
Visual Studio 2005, also in mingw own CRT) and "z" size specifier (this one
will be fixed in next commits).

There is also a warning about pointer truncation on Win64 when making
PKCS#11 object handle from pointer to this object.
This is a legitimate warning, since it could result in the same handles
being generated from different pointers and so from different objects.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 10:58:26 +02:00
Frank Morgner 40acedcc21 Added support for PIN commands via escape commands
As defined in BSI TR-03119 to issue SCardTransmit (with Uses
Pseudo-APDU) instead of SCardControl (with FEATURE_VERIFY_PIN_DIRECT).
It allows using a very basic PC/SC reader driver without special support
for PIN verification or modification (such as the default CCID driver on
Windows).

Also gets IFD vendor information via escape commands.

PC/SC's Get Uid command is now only triggered if enable_escape = true;
was set by the user to allow disabling wrapped commands on broken
readers (see https://github.com/OpenSC/OpenSC/issues/810)
2017-03-20 21:28:48 +01:00
Frank Morgner 60f2d06308 libopensc: fetch card's UID
Fetch card's UID.
For file caching, use UID if SN is not available.
2016-07-24 17:16:29 +02:00
Doug Engert 0d6fc02e23 reader-pcsc: improved logging and handling of reset
A sleep(1) is added after SCARD_W_CARD_RESET as done in other parts of reader-pcsc.c

Extra debugging messages are output.

SCard routines return "LONG" which may be different then "long" on some systems
were "LONG" is 32 bits and "long" is 64 bits.
Make sure printf format of 0x%08lx has a matching "long" input variable.

This closes #816
2016-07-19 15:20:49 +02:00
Frank Morgner 46efb02fec fixed memory leak of reader's vendor name 2016-05-26 14:39:41 +02:00
Frank Morgner fcf9b9e706 fixed missing initialisation and bad memory access 2016-05-26 13:46:57 +02:00
Viktor Tarasov 163fc42ee6 readers: coding style for log messages 2016-04-26 18:26:46 +02:00
Viktor Tarasov e95b515163 reader: by default only short APDU supported
default values of reader's max send/receive sizes correspond to only short APDU supported;
these values can be overwritten by reader itself with the proper value of dwMaxAPDUDataSize from TLV properties,
or with the corresponding options in OpenSC configuration.

resolves issue #735
2016-04-26 18:26:43 +02:00
Frank Morgner 5403899444 use SCardGetAttrib to initialize reader's metadata 2016-03-07 10:39:42 +01:00
Frank Morgner ef40021417 use sc_debug_hex for hexdump 2016-03-07 10:39:42 +01:00