Commit Graph

125 Commits

Author SHA1 Message Date
Zoltan Kelemen 6f1df6454a Reject the case that the PIN and PUK padding flags are different, since this
case can not be handled by the card driver interface. Better to detect and
fail early instead of sending invalid data to the card.
2020-07-22 22:58:57 +02:00
Zoltan Kelemen 555cb73615 Fix for using the correct info for PIN/PUK (before they were switched). 2020-07-22 22:58:57 +02:00
Zoltan Kelemen e80906d973 Add path selection to sc_pkcs15_get_pin_info to make it work correctly with
local PINs. This makes the code behave the same way as PIN verification,
change and unblock, before calling the PIN command handler in the card driver.
2020-07-22 22:58:57 +02:00
Zoltan Kelemen 929717b505 Make PUK reference available to card driver from PKCS #15 layer for PIN
unblock operations. This helps some of the card drivers which otherwise
would have a hard time locating the PUK for a PIN.
2020-07-02 13:24:57 +02:00
Frank Morgner 3a5a90450e fixed 333715 Dereference after null check 2019-11-05 21:49:30 +01:00
Jakub Jelen d3f60a657f pkcs15*: Fail if there is no fallback file_app 2019-11-01 15:53:40 +01:00
Jakub Jelen 6c7b4bed37 pkcs15*: Avoid null dereference from fuzzers
Thanks oss-fuzz.

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18591
2019-10-31 02:17:44 +01:00
Frank Morgner a899a46b09 replaced SC_TEST_RET with LOG_TEST_RET 2018-12-06 09:26:42 +01:00
Frank Morgner 00a150f74c replaced SC_FUNC_RETURN with LOG_FUNC_RETURN 2018-12-06 09:26:42 +01:00
Frank Morgner cf55cdc637 replace SC_FUNC_CALLED with LOG_FUNC_CALLED 2018-12-06 09:26:42 +01:00
Doug Engert 91812cf40f Context Specific Login Using Pin Pad Reader Fix
sc_pkcs15_verify_pin say:

/* if pin cache is disabled, we can get here with no PIN data.
 * in this case, to avoid error or unnecessary pin prompting on pinpad,
 * check if the PIN has been already verified and the access condition
 * is still open on card.
 */

It then call sc_pkcs15_get_pin_info

A context specific login is used in PKCS#11 to force the user
to enter the PIN again and a verify command be sent to the card.
(Actually it could be a different value for the PINi depending on the card)
sc_pkcs15_get_pin_info will then call the card driver, but does not
say why it is testing the login status.sc_pkcs15_get_pin_info may return
SC_PIN_STATE_LOGGED_IN=1 and sc_pkcs15_verify_pin will then skip sending
the actual verify command to the card via _sc_pkcs15_verify_pin

To avoid this, sc_pkcs15_get_pin_info will set data.pin_type = pin_info->auth_method;
In the case of a context specific login, this is SC_AC_CONTEXT_SPECIFIC
and the card driver can take action and can return SC_PIN_STATE_LOGGED_IN=0
so the verify will be done.

The PIV driver card-piv.c does this. Other drivers could do something similar.

 Date:      MOn May 21 20:40:00 2018 -0500

 On branch History-fixes
 Changes to be committed:
	modified:   card-piv.c
	modified:   pkcs15-pin.c
2018-05-23 14:19:05 +02:00
Frank Morgner 3ca6c4b04a fixed possible NULL dereference 2017-11-09 12:42:29 +01:00
Frank Morgner bf828014e5 macOS: Added support for notifications
- adds framework for user defined message strings
- automatically determine the system's language
2017-08-02 19:02:05 +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
Hannu Honkanen e6f7373ef0 Added a check to sc_pkcs15_verify_pin to find out if the access condition is already open on card. This check is performed only if this function is called with empty data. This change fixes a problem with pinpad readers, when PIN cache is disabled and prevents unnecessary PIN queries. 2017-04-19 10:57:54 +02:00
Frank Morgner e7915ec198 replace assert with error handling 2017-04-04 09:11:35 +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
Nuno Goncalves ccc7e2f109 Improve pinpad use detection
Pinpad is used it it is present and if no pin string is provided (pinlen==0).

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-04 22:44:26 +01:00
Nuno Goncalves c6a9201b62 Validate PIN before verification
_validate_pin was not being called at all during a PIN verification.

After this tools report correctly when the PIN length is invalid, even on pkcs11 layer.

Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
2017-02-04 22:44:26 +01:00
Jakuje 12f4026160 Fix Coverity remarks (#876) 2016-10-10 22:21:46 +02:00
Frank Morgner cda3a2b5ad Initialize PIN logged_in field for default PKCS#15 data 2016-09-01 02:17:29 +02:00
Viktor Tarasov ce82e56411 pkcs15init: fix using PINPAD to verify PIN
on the way to fix problem observed in #856
2016-08-28 13:44:12 +02:00
Viktor Tarasov 98568fe13e libopensc: no cache for the zero length PIN
fixes problem with the revalidation of PIN with PINPAD
observed in #856
2016-08-27 15:30:30 +02:00
Viktor Tarasov 49a4eaaef3 pkcs15: no PIN cache update in pincache-revalidate
PIN cache is not updated when PIN is verified using the PIN value from cache.
That's the case of validating PIN in 'revalidate' context.

Few source format fixes included

closes #805
2016-07-24 18:49:51 +02:00
Frank Morgner 2f10de4f5c use sc_pkcs15_get_pin_info in C_GetTokenInfo
introduced paramter to signal back the login state
- used for the pin command SC_PIN_CMD_GET_INFO
- implemented in accordance to ISO 7816-4; all other implementations
  are currently set to an unknown login state

implemented and exporeted sc_pkcs15_get_pin_info

use sc_pkcs15_get_pin_info in C_GetTokenInfo

C_GetSessionInfo: Check whether a logout was done

Closes https://github.com/OpenSC/OpenSC/pull/624

rebased by @viktorTarasov
2016-07-17 14:07:43 +02:00
Andreas Schwier 83a28a1bc3 pkcs15: Observe path.aid for PIN operation 2015-09-25 11:56:32 +02:00
Andreas Schwier c41153aa13 pkcs15: Select application defined by path.aid for PIN verification 2015-09-23 15:36:56 +02:00
vletoux f154cdcaa4 pkcs15-pin: sc_pkcs15_unblock_pin: avoid to ask the PUK twice 2015-05-08 22:37:04 +02:00
Frank Morgner bcb5fc15e5 honour HAVE_CONFIG_H 2015-04-22 23:55:33 +02:00
Viktor Tarasov 46c86fcb66 coding style: use short form of debug macros 2014-01-19 19:19:17 +01:00
Viktor Tarasov 3f023d3342 pkcs15: PIN value not validated in pkcs15-verify
In pkcs15-verify the value of PIN is not more validated for conformity with PIN policy,
value is only checked for maximal allowed length.

So that, no more need of 'ignore-pin-length' configuration option - now it's default behavior of common framework.
2014-01-19 19:19:17 +01:00
Doug Engert a3b516a1e1 Add pin_cache_ignore_user_consent parameter to opensc.conf
When OpenSC is used with a card that enforces user_consent
and the calling PKCS#11 application does not understand how
to handle the CKA_ALWAYS_AUTHENTICATE, signature operations
will fail.

OpenSC will not cache a PIN that protects a user_consent
object as one would expect.

This mods allows PINs to be cached even if protecting a
user_consent object by adding
 pin_cache_ignore_user_consent = true;
option in opensc.conf.

Thunderbird is the prime example of this situation.
Mozilla has accepted mods (357025 and 613507) to support
CKA_ALWAYS_AUTHENTICATE that will appear in NSS-3.14 but
this may be some time before this version is in vendor
distribution.
2012-08-12 00:11:03 +02:00
Viktor Tarasov 1d2661c7ce pkcs15-pin: 'PIN' as particular choice of 'AuthenticationType'
Encode/decode 'PIN' pkcs15 object as particular choice of 'AuthenticationType' data.
Rudimental encoding/decoding of 'authKey' object.
2012-05-31 10:37:38 +02:00
Stef Walter 6ed52a06b8 libopensc: Don't fail to allocate memory when mlock fails
* Print out warning when mlock fails, and continue.
 * The warning required a ctx to be passed in, so that means
   changing a few function signatures.

https://www.opensc-project.org/opensc/ticket/389
2012-02-17 10:02:55 +01:00
vtarasov d888b3fd55 pkcs15: use general 'AuthenticationObject' instead of 'PinObject'
now the attributes of the previous 'pin-info' data type are included
as the sub-type attributes of the general 'auth-info' data .
It will allow to include support of the 'biometricTemplate' and 'authKey' authentication types.

http://www.opensc-project.org/pipermail/opensc-devel/2011-May/016655.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5550 c6295689-39f2-0310-b995-f0e70906c6a9
2011-06-05 15:46:25 +00:00
andre 3442649b42 pkcs15-pin: Fixing the method of obtaining objects protected by a particular PIN. Now it's in accordance with PKCS15. See [http://www.opensc-project.org/pipermail/opensc-devel/2011-January/015818.html discussion].
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5222 c6295689-39f2-0310-b995-f0e70906c6a9
2011-03-07 16:15:41 +00:00
vtarasov 33f44f8dc1 pkcs15: pin references are always positive integers ...
In the OpenSC versions previous to 0.11.5 the references greater then
127 were erroneously encoded by one byte (negative value ecording to the
ASN.1 rules).
Actually some other proprietary PKCS#15 cards have also this infirmity.

Actual commit makes general the application of the hack used for 'starcos' card.

http://www.opensc-project.org/pipermail/opensc-devel/2011-February/016062.html


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5220 c6295689-39f2-0310-b995-f0e70906c6a9
2011-03-06 12:35:35 +00:00
martin 03be594243 core: Fix PIN caching for PIN codes protecting user consent keys, broken in r4048
Such PIN codes were erroneously cached in memory, even though not used with revalidation..
User consent relates to private keys, not PIN codes.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5124 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-27 14:25:35 +00:00
vtarasov 47f997983e pkcs15: simplify PIN's path assignement
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5110 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-18 16:17:15 +00:00
andre 752af86f2b pkcs15-pin.c: fixes segmentation fault in the case where p15card->app == NULL
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5104 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-17 21:09:48 +00:00
vtarasov 2c6d3ee9fa pkcs15: comments and debug messages
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5094 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-17 13:11:21 +00:00
vtarasov e98dee0092 pkcs15: asn1: local PIN should have a path defined ...
if there is no 'path' in the 'PinAttributes', use DDO.AID or application path as a PIN's path.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5081 c6295689-39f2-0310-b995-f0e70906c6a9
2011-01-11 10:12:42 +00:00
andre 5b69b39c33 sc_pkcs15_pincache_revalidate: Avoid compiler warning 'discards qualifiers from pointer target type'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4927 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-06 18:59:49 +00:00
andre ea4ddf8f17 pkcs15-pin: If the usage counter of a cached PIN is expired, then free that cached PIN instead of freeing the objects content that is protected by the PIN.
If re-validation of a cached PIN fails, then free that cached PIN to ensure that it isn't used again for re-validation.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4924 c6295689-39f2-0310-b995-f0e70906c6a9
2010-12-06 18:33:17 +00:00
viktor.tarasov 58c1c88efa libopensc: homogenise line ending in the debug messages
continuating r4759


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4774 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-25 20:35:59 +00:00
martin befff1b0d4 libopensc: PIN usage counter is decreased every time it is sent to the card, no matter what the card replies (should probably reply with success)
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4665 c6295689-39f2-0310-b995-f0e70906c6a9
2010-09-01 06:23:43 +00:00
viktor.tarasov d9b0d643de libopensc: in sc_pkcs15_verify_pin() if no PIN provided try to use pin pad
It's a complement to the r4361.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4362 c6295689-39f2-0310-b995-f0e70906c6a9
2010-05-19 08:37:29 +00:00
aj 6545b42c02 cleanup of the debug code:
* reduce to a few, supported functions.
* change all functions to take the debug level as parameter.
* use symbolic names for the debug levels.
* fix tools to pass "verbose"/"opt_debug" as ctx->debug.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4118 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-15 12:17:13 +00:00
viktor.tarasov 052881c38f libopensc: in pkcs15 PIN commands 'pin_info' parameter replaced by 'pin_object'
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4103 c6295689-39f2-0310-b995-f0e70906c6a9
2010-03-10 09:23:01 +00:00