Commit Graph

162 Commits

Author SHA1 Message Date
Luka Logar c80375eb4c Minidriver RSA-PSS signing not working
I am using a somewhat modified version of IsoApplet. Up till now it worked fine. However recently I stumbled upon a web site that
forces a client cert auth with RSA-PSS. And (at least on windows, using minidriver) it didn't work. It looks to me, that it's a bug
in the PSS support code in minidriver, as I cannot find any place where a MGF1 padding scheme is specified. And since none is specified
signing fails. This patch fixes this. It assumes, that the same hash is used for hashing and padding.
2021-02-25 18:35:57 +01:00
Arya Senna 4cc0d0c7c9 Update upper length for ATR and the comments. 2020-11-04 11:02:56 +01:00
Arya Senna 64de4a5001 Update minidriver.c
Fix check of ATR length for Ledger
2020-11-04 11:02:56 +01:00
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
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
Priit Laes 0b4b7fbaf0 openssl: Drop all compatibility checks for <=openssl-1.0.0 2020-01-06 15:47:07 +01:00
Frank Morgner 72f474f09f use consistent parameters
- in sc_pkcs15_wrap()
- and sc_pkcs15_derive()
2019-07-26 15:23:02 +02:00
Jakub Jelen 272e380898 Set correctly flags for ECDH derive operations 2019-06-17 12:49:11 +02:00
Frank Morgner 447335bc1f md: clean OpenSSL memory when DLL is unloaded 2018-11-13 15:50:17 +01:00
Frank Morgner 027ccad439 allow specifying the size of OpenSSL secure memory
... and set it for builds where we're linking OpenSSL statically (i.e.
Windows and macOS)

fixes https://github.com/OpenSC/OpenSC/issues/1515
2018-11-13 15:50:17 +01:00
Frank Morgner 263b945f62 md: added support for PSS 2018-11-06 12:38:57 +01:00
Frank Morgner 99a9029848 md: use constants for AlgId comparison 2018-11-06 12:38:47 +01:00
Frank Morgner 8c535c184f removed duplicate code for adding padding
Fixes padding handling of SC_ALGORITHM_RSA_PAD_NONE introduced with
e5707b545e
2018-10-15 15:21:52 +02:00
Luka Logar d517d8e18d Fix minidriver padding
Commit e5707b545e broke signing using minidriver on Windows.

More specifically changing #define SC_ALGORITHM_RSA_PAD_NONE from 0x00000000 to 0x00000001 caused a call to sc_pkcs1_encode() to fail as the padding algorithm was not specified anywhere in the CardSignData() implementation. It kind of worked as long as SC_ALGORITHM_RSA_PAD_NONE was 0x00000000, but the above mentioned commit broke this.

Now padding algorithm has to be explicitly specified, otherwise a call to sc_pkcs1_encode() will fail.
2018-10-11 12:47:48 +02:00
Frank Morgner 129946ca96 pkcs11: CKF_WRITE_PROTECTED based on card's read_only flag
uses `md_read_only` as `read_only` for both, PKCS#11 and Minidriver
2018-09-14 08:23:08 +02:00
Frank Morgner e36c1468e5 md: derive md_read_only from PKCS#15 profile 2018-09-14 08:23:08 +02:00
Frank Morgner cd557df54d md: change semantics of cancelling the PIN pad prompt
md_pinpad_dlg_allow_cancel now defines whether or not the user is asked
before verifying the PIN on the PIN pad. This can be denied without
interaction with the PIN pad. A checkbox in the dialog allows the user
to change this setting, which is saved in the registry by the path of
the process.

This change fixes the progress bar to match the actual configured
timout. The progressbar now fills instead of running empty, which seemed
less frightening for most users.

This change also fixes some copy/paste errors in the documentation of
opensc.conf(5).
2018-08-05 11:35:12 +02:00
Frank Morgner 410cdf0dcc refactored sc_get_challenge
Let sc_get_challenge() do sc_lock() and loop through the card driver's
get_challenge() until enough bytes were collected. The card driver's
get_challenge() now returns the number of bytes collected (less or equal
than requested) or an error code.

- Allow more code re-use.
- PIV driver now uses ASN.1 parser for reading the random bytes
2018-05-23 14:20:28 +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 e8e8153cda md: prevent endless loop for card without sn 2018-03-09 14:36:55 +01:00
Frank Morgner d0d9b974a7 md: protect MD entry points with CriticalSection
CardDeleteContext may be called at any time, interrupting any ongoing
operation with the same PCARD_DATA. This leads to a race condition when
CardDeleteContext deletes, for example, the sc_context_t which the
interrupted call still wants to access. We have seen and fixed this
problem in https://github.com/OpenSC/OpenSC/issues/973 specifically for
the PIN entry process, however, it also applies to all other calls to
the md.

The new implementation removes the need for global data in the md.
2017-11-30 11:30:31 +01:00
Frank Morgner 9583d3b650 md: fixed memory leak
may be related to https://github.com/OpenSC/OpenSC/issues/1106
2017-11-30 11:30:31 +01:00
Frank Morgner 3693a96911 win32: don't link static libs into static libs 2017-11-09 12:42:29 +01:00
Frank Morgner 04a7075290 fixed compiler warnings 2017-11-09 12:42:29 +01:00
Frank Morgner 6a4e120b44 md: added default text for role: user+sign 2017-10-17 09:38:19 +02:00
Frank Morgner 498aedd165 Merge remote-tracking branch 'upstream/master' into winui 2017-10-16 15:16:34 +02:00
Maciej S. Szmigiero 294c232ca9 Minidriver card reinitialization cleanup
In minidriver before performing a card operation we currently check whether
the supplied card handles have changed.
If they did the card in reader might have been changed so we reinitialize
it.

However, in few places in reinitialization call path an error returned by
some operation would leave the context in an inconsistent state.

So let's walk through this path to make sure that functions there will exit
cleanly if an error happens.

Also, make sure that all card operations that actually do something have
the necessary check call in the first place and also that they all
consistently check whether VENDOR_SPECIFIC pointer is not NULL before
dereferencing it.

This is a cleanup part of "Keep track of card resets by other contexts in
minidriver" (that is, it does not include the actual reset handling code
introduced by that commit), simplified.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-10-16 14:56:01 +02:00
Maciej S. Szmigiero bd9cdd243d Add multiple PINs support to minidriver
Many cards need multiple PINs to work correctly since different on-card
keys are secured by different PINs (this is true for for example OpenPGP
card).

Smart Card Minidriver API has supported such cards since version 6.02
(Vista+).

Use the same method as PKCS#11 driver does to discover user and sign PINs,
for consistency.
However, if there is a default container on card we'll make sure that its
PIN is an user PIN and if there is no default container we'll mark the one
with the user PIN as default.

All other PINs securing containers on card are added as next PINs, up to
MD_MAX_PINS.

Use this opportunity to also fix two cases where a pointer-to-DWORD
variable was passed as pointer-to-size_t parameter to
md_dialog_perform_pin_operation() - they are of different size on Win64.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-10-16 14:56:01 +02:00
Frank Morgner 172f320c9a win32: Dedicated md/pkcs11 installation folders
Don't install non-permanent files (md/pkcs11) to system folder anymore.
2017-08-22 23:41:29 +02:00
Frank Morgner 7bc070ac67 win32: Load notification icons from Windows DLLs
fixes showing wrong icons when loaded as PKCS#11 module
2017-08-03 00:19:26 +02:00
Frank Morgner b2cde0f7fb Windows: Added support for notifications 2017-08-02 19:03:16 +02:00
Frank Morgner 417a409406 md: allow user defined data for PIN pad dialog
- use UI framework
- timeout progressbar is running backwards
- cancelling is disabled by default
- removes card specific UI strings, use opensc.conf for that instead
- icon can be loaded by file
2017-08-02 19:02:13 +02:00
Frank Morgner 0b3d7f25c8 md: use c89 style to silence VC2010 2017-08-02 19:01:31 +02:00
Frank Morgner 03418173b0 md: Delegate user to the PIN pad's "Cancel" button
Pressing the cancel button in the PIN pad dialog should not close the
dialog. The application will still wait for the request to complete
even if the dialog is gone. Instead, we tell the user to press the
cancel butten on the PIN pad if the reader does not support SCardCancel.
2017-08-02 19:01:14 +02:00
Frank Morgner 378bc1f381 md: Use card specifiic pin pad strings
implemented for sc-hsm SoC
2017-08-02 19:00:28 +02:00
Frank Morgner bfa7aef042 md: fixed race condition when showin pin pad dialog
When the dialog is shown in a separate thread and the user removes the
card, both, the thread for the pin pad operation and the main thread
are trying to access the card and context handles. Even worse, the main
thread deletes the context handle, which may result in a segmentation
fault for the thread with the pin pad operation.
2017-08-02 19:00:19 +02:00
Frank Morgner c57c9c36bf md: added themable PIN-pad dialog
- themable in the sense of using OS native design
- user messages on PIN pad dialog are identical to Base CSP, which still displays the dialog for PIN entry if no PIN pad is available
- adds progress bar to dialog
- Uses Smartcard icon extracted from DDORes.dll
- requires windows vista/windows server 2008 or above
2017-08-02 19:00:07 +02:00
Frank Morgner d6e1d2ae8e md: Implemented German locale for PINPAD-dialog 2017-08-02 18:51:49 +02:00
Frank Morgner 61916be728 md: added cancel button to PINPAD GUI
... as required by minidriver spec

- Shows PIN purpose depending on the PIN type similar to Base CSP
2017-08-02 18:49:41 +02:00
Frank Morgner 7c3bb44cdf minidriver: added support for session pin 2017-05-22 16:25:08 +02:00
Frank Morgner 74ec7b04ff sc-hsm: Add support for SoC
- eac: allow CA without EF.CardSecurity
- sc-hsm: implemented CA based on document PKI
- sc-hsm: adds receive limit for SoC card
- introduces dedicated card type for SoC card
- md: integrate card's PIN pad capabilities
- installer: added SC-HSM SoC card to registry
- pkcs15-tool: Added support for PIN entry on card
- change/unblock PIN: add support for PIN entry on card
- added OpenPACE to macOS build
- travis-ci: install gengetopt/help2man via brew
- sc-hsm: Cache EF.C_DevAut
- sc-hsm: Prevent unnecessary applet selection and state resets
- sc-hsm: added support for session pin
- sc-hsm: avoid multiple AID selection
- sc-hsm: Use the information from match_card for all subsequent selections of the applet
- sc-hsm: cache optional files as empty files (Decoding the files will reveal that they were not existing prior caching. This avoids selecting the file though we have already tried to cache the file before.)
- use dedicated directory for CVC trust anchors
- appveyor: added OpenPACE to windows build
2017-05-22 16:25:08 +02:00
Frank Morgner 6bfb39454b Fix missing error handling of memory allocation (#1020)
* libopensc: handle allocation errors
* handle more faults during memory allocation

fixes several situations that cause segmentation fault
2017-04-20 21:08:49 +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 428b134776 Minidriver CardReadFile() parameters are optional
According to minidriver specs CardReadFile() method output parameters are
optional so don't return SCARD_E_INVALID_PARAMETER when they are NULL.

Also, use this opportunity to walk through this function helpers to make
sure they correctly return error status.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:09:38 +02:00
Maciej S. Szmigiero d203ad76a4 Minidriver CardGetChallenge() parameters are output only
According to minidriver specs CardGetChallenge() method parameters
are purely for output and do not have a meaning of requested challenge
length, so remove a misleading log line.

There is also no need to have a special case for pcbChallengeData being
NULL since in this case the function would have exited early anyway with
SCARD_E_INVALID_PARAMETER (also, it was just dereferenced in the previous
code line).

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 56f880613a Fix minidriver log messages format and parameter issues flagged by GCC
Since last commit GCC warns us about problems with format strings and their
arguments in minidriver, so let's fix these warnings just as we did in rest
of the OpenSC code.

Most of these warnings were about DWORDs being printed as ints, there were
also some format directives and size_t size specifiers missing and various
misc format / parameter disagreements.

Attempt was made to keep log strings as-is, only the most obvious typos
were fixed.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 1a073d5683 Add GCC format checking attributes to minidriver logging function
Commit "Add GCC format checking attributes to log functions" added format
and parameter checking to OpenSC log functions.
Minidriver, however, logs most of its output via a dedicated log function,
so this function needs such attributes, too.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero da6815d542 Use built-in formatted output functions on mingw
Mingw currently links to msvcrt.dll as C runtime.
This library is documented by Microsoft as off-limits to applications and
its feature set vary between Windows versions.

Due to this, presence of particular printf() format string directives
depends on which Windows version the code is run.

This is, naturally, bad, so mingw developers introduced ability to replace
formatted output functions with built-in equivalents with defined feature
set by setting "__USE_MINGW_ANSI_STDIO" macro to 1.
There are, however, no built-in equivalents for "_s" suffixed functions.
Fortunately, they are used only a few times in minidriver so let's simply
replace them with equivalent code using standard functions.

This also allows skipping "MINGW_HAS_SECURE_API" macro definition so any
future uses will be caught by compiler.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00
Maciej S. Szmigiero 1c40426421 Support PIN unblocking in minidriver via PUK as response to challenge
Minidriver currently has basic support for unblocking card PIN by providing
PUK as an administrator password to CardUnblockPin() function.

However, this doesn't work for example when trying to unblock PIN via
system smartcard PIN unblock screen accessible after pressing Ctrl+Alt+Del
as it wants to use challenge / response authentication.
MS Smart Card Minidriver specification (version 7.07) explicitly says that
challenge / response is the only authentication mode that Windows uses to
authenticate an administrator.
Unfortunately, this way of unblocking PIN seems to not be widely supported
by cards.

However, we can simply treat the provided response to challenge as PUK.
Because (at least) Ctrl+Alt+Del PIN unblock screen accepts only hex string,
every PUK digit X has to be input as '3X' (without quotes) there.
Also the response string is not hidden behind asterisks on this screen as
it should been.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-03-27 11:05:16 +02:00