Commit Graph

6637 Commits

Author SHA1 Message Date
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 77f6e94e6f fixed import of multiple symbols
regression of 45a7ea9737075b5901fe7a5d65ed898733140315:
due to the change in the linkage, the symbols should be found in
opensc.dll instead of the static support libraries.
2017-05-22 16:25:08 +02:00
Doug Engert 0ec89941b2 gids-tool loops when using OpenSSL-1.1
Add code to support OpenSSL initialization as needed for OpenSSL-1.1
2017-05-22 13:38:34 +02:00
Doug Engert c7ed71c76f piv-tool loops when using OpenSSL-1.1
Add code to support OpenSSL initialization correctly when using OpenSSL-1.1

Tested with OpenSSL-1.1.0c and OpenSSL-1.1.0e.

 Changes to be committed:
	modified:   src/tools/piv-tool.c
2017-05-22 13:38:34 +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 e23960f793 Fixed ssh's pkcs11 usage on macOS
copy (instead of link) our pkcs11 libraries to the default location, which is whitelisted for ssh usage

fixes https://github.com/OpenSC/OpenSC/issues/1008
2017-05-13 23:41:12 +02:00
rickyepoderi d9d247e6cd Disable the secure channel at logout (#1048)
Fixes https://github.com/OpenSC/OpenSC/issues/1036
2017-05-13 16:15:08 +02:00
Jakub Jelen 427c175c08 Do not use the hardcoded magic numbers in PIV 2017-05-02 22:27:43 +02:00
Jakub Jelen 20e3836c9e Restore the functionality of CAC usage flags deriving from X509 certificates 2017-05-02 22:27:43 +02:00
Doug Engert 35bae65f11 Make sure it is an SPKI
On branch verify-pubkey-as-spki-2
 Changes to be committed:
	modified:   framework-pkcs15.c
2017-04-26 13:08:49 +02:00
Doug Engert 4049283675 Add new attribute CKA_SPKI for CKO_PUBLIC_KEY
CKA_SPKI is a vendor defined attribute to be used internally
as input to to OpenSSL d2i_PUBKEY

 On branch verify-pubkey-as-spki-2
 Changes to be committed:
	modified:   framework-pkcs15.c
	modified:   mechanism.c
	modified:   openssl.c
	modified:   pkcs11-opensc.h
2017-04-26 13:08:49 +02:00
Doug Engert d48f438581 PKCS#11 does not define a CKA_VALUE for public keys and is missused
OpenSC opennssl.c in sc_pkcs11_verify_data assumes that it can
retieve the CKA_VALUE for a public key object, and expect it to
be usable as RSA.

But internally sc_pkcs15_pubkey can have a "raw" or "spki"
version of the public key as defined by PKCS#15.  Card drivers
or pkcs15-<card> routines may store either the "raw" or "spki"
versions. A get attribute request for CKA_VALUE for a public key
will return either the raw, spki or will derived rsa verison of the
pubkey.

This commit will test if the CKA_VALUE is a spki and use d2i_PUBKEY
which takes a spki version and returns an EVP_KEY. If it not an spki
the current method, d21_PublicKey(EVP_PKEY_RSA,...) is used which
only works for RSA.

The problem was found while testing pkcs11-tool -t -l  where
the  verify tests would fail with a CKR_GENERAL_ERROR because
the card driver stored the public key as a spki.

On branch verify-pubkey-as-spki-2
 Changes to be committed:
	modified:   src/pkcs11/openssl.c

Date:      Fri Apr 07 07:50:00 2017 -0600
2017-04-26 13:08:49 +02:00
Timo Teräs f5aa3f5cc6 build fix for libressl 2.5.3
X509_up_ref is implemented in libressl 2.5.3
2017-04-26 10:59:47 +02:00
Timo Teräs 2114dea687 pkcs15: fix commit 76d59158 auth object regressions
Few conversions of SC_PKCS15_TYPE_AUTH_PIN to SC_PKCS15_TYPE_AUTH
were missed.
2017-04-24 13:14:46 +02:00
Mouse 0cb91fd68c Fix bug in pkcs11-tool.c that prevented it from displaying CKA_DERIVE key usage for EC public keys 2017-04-22 17:12:26 +02:00
Mouse 13f61eee7b Fix CAC-introduced bug that broke access to certificates (@dengert found it) (#1032)
Regression from 777e2a3751
2017-04-22 17:05: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
rickyepoderi 741add2588 Use sc_hex_dump instead of cwa_hexdump. 2017-04-20 11:04:02 +02:00
rickyepoderi ac091b7466 Add dnie_free_apdu_buffers into dnie_sm_free_wrapped_apdu. 2017-04-20 11:04:02 +02:00
Frank Morgner 74f11a32a5 removed obsolete comment 2017-04-20 10:58:54 +02:00
Frank Morgner 9d15326de1 fixed more coverity issues 2017-04-20 10:58:54 +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
Hannu Honkanen 8cf68bce1a Improved creation of key files so that the correct security attributes are set and keys can be created under specific PINs. Previously keys were always created under PIN 1. Changed description of myeid_create_key function. 2017-04-19 10:57:54 +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
Jakub Jelen c496af17d4 pkcs11-tool: Set CKA_PRIVATE=false for new public keys
Keygen should write public keys with explicit CKA_PRIVATE=false by default (possibility to modify by --private switch)

Related to 4df35b92 discussing writing separate objects years ago.
2017-04-17 01:24:03 +02:00
Jakub Jelen 1ca09b8f10 pkcs11-tool: Do not use unitialized data when C_GetTokenInfo() failed 2017-04-13 15:18:54 +02:00
Jakub Jelen 7214516547 Make sure the lock is released when returning 2017-04-13 15:18:54 +02:00
Timo Teräs 76d59158fe pkcs15: fix and simplify object type class comparisons 2017-04-13 12:49:13 +02:00
Timo Teräs 4eaaa797e6 pkcs15init: use flag symbolic names 2017-04-13 12:49:13 +02:00
Jakuje 8f33305421 Make CardOS 5.3 working with OpenSC (#1003)
* Set security context for CardOS 5.3 with p1=0x41 (as Coolkey does)

* Do not emulate signatures in CardOS 5.3

Remove the bogus SC_ALGORITHM_NEED_USAGE which prevents using the
actual implementation in cardos_compute_signature().

It might be bogus also in previous version, but I don't have a way
to verify against these cards.

* Do not advertise RSA-X-509 mechanism for CardOS 5.3 (card strips padding)
2017-04-05 09:44:34 +02:00
Frank Morgner e7915ec198 replace assert with error handling 2017-04-04 09:11:35 +02:00
Frank Morgner c2fa66f1fb pkcs11-tool: fixed RSA-X-509 corner case test
For testing RSA-X-509, we are generating random bytes for signing. It
may happen that the modulus is smaller than the random number
generated, which triggers an error in the card. With this change, we
are setting the most significant byte to 0x00 to assure the random
number is smaller than the modulus.
2017-04-03 21:55:59 +02:00
Frank Morgner d757db2ca8 Avoid dnie_transmit_apdu in the dnie driver (#970) (#1013)
closes #975 
closes #972
2017-04-03 18:00:41 +02:00
Frank Morgner c5e40127d0 Coverity fixes (#1012)
card-cac.c
 * CLANG_WARNING: The left operand of '<' is a garbage value
card-coolkey.c
 * CLANG_WARNING: overwriting variable
 * CPPCHECK_WARNING: memory leak / overwrite variable
 * CLANG_WARNING: null pointer dereference
 * UNUSED_VALUE: unused return value
card-gids.c
 * CLANG_WARNING: Branch condition evaluates to a garbage value
 * SIZEOF_MISMATCH: suspicious_sizeof
card-myeid.c
 * RESOURCE_LEAK: Variable "buf" going out of scope leaks the storage it points to.
 * CLANG_WARNING: overwriting variable
 * (rewrite not to confuse coverity)
pkcs15-cac.c
 * RESOURCE_LEAK: Variable "cert_out" going out of scope leaks the storage it points to.
pkcs15-coolkey.c
 * UNUSED_VALUE: unused return value
pkcs15-piv.c
 * RESOURCE_LEAK: Variable "cert_out" going out of scope leaks the storage it points to.
pkcs15-sc-hsm.c
 * DEADCODE
pkcs11/framework-pkcs15.c
 * RESOURCE_LEAK: Variable "p15_cert" going out of scope leaks the storage it points to.
pkcs15init/pkcs15-lib.c
 * CLANG_WARNING: Assigned value is garbage or undefined
pkcs15init/pkcs15-myeid.c
 * UNREACHABLE: Probably wrong placement of code block
tests/p15dump.c
 * IDENTICAL_BRANCHES
pkcs15-init.c
 * CLANG_WARNING: Potential leak of memory pointed to by 'args.der_encoded.value'
pkcs15-tool.c
 * RESOURCE_LEAK: Variable "cert" going out of scope leaks the storage it points to.
 * MISSING_BREAK: The above case falls through to this one.
sc-hsm-tool.c
 * CLANG_WARNING: Potential leak of memory pointed to by 'sp'
westcos-tool.c
 * FORWARD_NULL: Passing null pointer "pin" to "unlock_pin", which dereferences it.
 * (rewrite not to confuse coverity)
card-cac.c
* Avoid malloc with 0 argument
gids-tool.c
* FORWARD_NULL -- copy&paste error
scconf.c
* CLANG_WARNING: Call to 'malloc' has an allocation size of 0 bytes

closes #982
2017-04-03 13:43:30 +02:00
Frank Morgner 013bdcb264 macOS: added support for access via CryptoTokenKit
Binaries still need to be signed with the com.apple.security.smartcard
entitlement. The command should look something like this:

codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" target/Library/OpenSC/bin/*
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" target/Library/OpenSC/lib/*.dylib
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" --deep target/Library/OpenSC/lib/opensc-pkcs11.bundle
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" --deep target/Library/Security/tokend/OpenSC.tokend
2017-04-03 12:30:03 +02:00
Frank Morgner 70313512ad recognize T=0 limitation of sending 255 bytes
fixes https://github.com/OpenSC/OpenSC/issues/1009
2017-04-03 09:08:40 +02:00
Frank Morgner f21fe1de8d win32 installer: skip license agreement
in accordance to
https://www.gnu.org/licenses/old-licenses/gpl-2.0-faq.html#ClickThrough
2017-03-28 14:24:30 +02:00
Frank Morgner 8da29d4a1e pkcs15-tool: documentated `--clear-cache` 2017-03-28 14:24:13 +02:00
Frank Morgner 752e5afd49 log exit of sc_single_transmit in case of SM 2017-03-28 14:24:13 +02:00
Frank Morgner 0a254dc2bb fixed compiler warnings 2017-03-28 12:51:24 +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 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 2e75198181 Add GCC format checking attributes to log functions
GCC can check format and parameter correctness in printf()-like functions
for us so let's add necessary attributes to our log functions to emit a
warning where their way of being called is likely in need to be inspected
for correctness.

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
Maciej S. Szmigiero f91fc3d338 Remove logprintf() mingw hack in minidriver
Minidriver contained a hack since commit 7ef766b785 in 2010 to print to
debug file directly under mingw (instead of using normal OpenSC logging
system), as there was problem with "%S" format specifier then.

However, on recent mingw versions "%S" format works fine so let's remove
this hack.

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