Commit Graph

6347 Commits

Author SHA1 Message Date
Frank Morgner c858d4b3d1 fixed argument checking 2019-02-14 09:22:23 +01:00
Frank Morgner 6fdb29a470 fixed use of uninitialized values 2019-02-14 09:22:23 +01:00
Frank Morgner 01d515a026 fixed use of garbage value 2019-02-14 09:22:23 +01:00
Frank Morgner 8ea77a83e0 fixed misuse of realloc 2019-02-14 09:22:23 +01:00
Frank Morgner 32e1995300 fixed dead assignment 2019-02-14 09:22:23 +01:00
Frank Morgner e4a01643a6 fixed possible NULL pointer dereference 2019-02-14 09:22:23 +01:00
Frank Morgner 53954e9ff1 fixed OpenSSL handling in PKCS#11 mapping
prevents NULL pointer dereference
2019-02-14 09:22:23 +01:00
Frank Morgner b708cab0a3 fixed assignment of garbage value 2019-02-14 09:22:23 +01:00
Frank Morgner 85485eb9b0 fixed unused assignments 2019-02-14 09:22:23 +01:00
Frank Morgner fdb0e6d581 Fixed Potential leak of memory 2019-02-14 09:22:23 +01:00
Raul Metsma c2cc83754e select_esteid_df is only used in card-mcrd.c
Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-02-12 08:56:20 +01:00
Raul Metsma f37a8a5c52 is_esteid_card is only used card-mcrd.c
Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-02-12 08:56:20 +01:00
Peter Marschall 4757466f27 OpenPGP: space police
remove trailing spaces & tabs
2019-02-12 08:55:59 +01:00
Alex Karabanov 04ef9dbf3b Fix build on cygwin in strict mode (#1605) 2019-02-11 20:50:12 +01:00
Frank Morgner be33e82b75 goid-tool: fixed possible memory leak
internally created context needs to be freed if TA/CA is done without
an existing SM context from PACE
2019-02-11 15:41:32 +01:00
Frank Morgner 72cdc9d82e goid-tool: fixed confusion about always/never acl 2019-02-08 15:08:03 +01:00
Frank Morgner aca9d79f6d fixed parsing SoCManager info 2019-02-07 16:56:33 +01:00
Frank Morgner 928fbf2f03 goid-tool: implented PIN/FP verification for PAccess 2019-02-04 16:01:56 +01:00
Raul Metsma 36c5461c99 Make function more readable
Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-01-30 22:02:14 +01:00
Hannu Honkanen ec176443e2 Fixes an issue that appeared in 6bf9685 (PR #1540). In case use_pinpad==0 && pinsize == 0, uninitialized pinbuf was passed to sc_pkcs15_verify_pin causing problems. 2019-01-30 22:01:52 +01:00
opensignature 84f0a88edb Remove postecert and infocamere support because no longer issued (#1584)
* Remove postecert and infocamere support because no longer issued

* Remove wrong changes

* reset NEWS

* EC_POINT_set_affine_coordinates_GFp and EC_POINT_get_affine_coordinates_GFp are
deprecated, use EC_POINT_set_affine_coordinates and EC_POINT_get_affine_coordinates

* If OPENSSL API version is < 3 use old functions EC_POINT_[sg]et_affine_coordinates_GFp

* Move the OpenSSL compatibility stuff to src/libopensc/sc-ossl-compat.h
2019-01-30 22:01:24 +01:00
Alexander Paetzelt 09a594d0f0 OpenPGP Card v3 ECC support (#1506)
* pgp: initialize ecc keys for OPC3

* Add supported ECC algorithms by card version

* Add tasks identified so far

* pgp: Recognize ECC set on card

* pgp: get_pubkey_pem read ECC pubkey from card

* pgp: minor code changes for ECC compatibility

* pgp: expand sc_cardctl_openpgp_keygen_info to hold ec info

* Fix segfault problem in pkcs15-pubkey.c

* pgp: enable key generation with pkcs15-init and ECC

* pgp: adapt calculate_and_store_fingerprint to accept ECC

* pgp: adapt rest of pgp_gen_key and subfunctions to accept ECC

* pgp: add kdf parameters for ECDH fingerprint calculation

* pgp: enable key import with pkcs15-init and ECC

* pkcs15-pubkey: fix_ec_parameters onlz accpets explicit data or named_curve

* Fix some mistakes during merge

* More clean up for PR

* Fix some ugly alignments

* Improve code readability

* Prevent unitialized variable by using FUNC_RETURN

* OpenPGP: add length check

* pgp: save exponent length in bits for sc_cardctl_openpgp_keystore_info_t

* pgp: length checks and reallocations

* pgp: oid init added

* OpenPGP: slightly re-factor pgp_update_new_algo_attr()

* replace loop copy with memcpy()
* use ushort2bebytes() to set RSA modulus & exponent
* use symbolic name SC_OPENPGP_KEYFORMAT_RSA_STD for the key import format

* OpenPGP: slighly re-factor pgp_parse_and_set_pubkey_output()

* check for RSA modulus & exponent lengths not being a multiple of 8
* make sure RSA modulus & exponent lengths are always set
* remove a left-over RSA setting from the EC code

* pgp: adding BYTES4BITS

* pgp: initialization of values in pgp_build_extended_header_list based on key type

* pgp: add BYTES4BITS and remove unnecessary tests

* Fix broken pgp_update_new_algo_attr

* pgp: fix the ecpoint_len variable
2019-01-30 22:00:36 +01:00
Frank Morgner 7a7ff50422 fixed memory leaks during card initialization 2019-01-30 21:57:59 +01:00
Frank Morgner f486486413 removed unused defines 2019-01-30 21:57:59 +01:00
Frank Morgner 97a58cb441 fixed https://github.com/OpenSC/OpenSC/issues/1581 2019-01-30 21:57:59 +01:00
Frank Morgner aed95b2f2b pkcs11: check inputs
prevents NULL pointer dereference
2019-01-30 21:57:59 +01:00
Frank Morgner 993f6f5cc6 Use opensc-pkcs11.so for static build of pkcs11-tool
Statically link opensc-pkcs11 into pkcs11-tool with --disable-shared
2019-01-30 21:57:59 +01:00
Frank Morgner 7f7bcbff52 fixed misuse of realloc
calling it with size 0 leads to a free, which eventually may lead to a
double free corruption.
2019-01-30 21:57:59 +01:00
Frank Morgner 2ad7453718 use const qualifier for sc_simpletlv_read/put_tag 2019-01-30 21:57:59 +01:00
Frank Morgner 893be0d9c0 fixed memory leaks 2019-01-30 21:57:59 +01:00
Frank Morgner 83c4ebe9d6 goid-tool: reset authentication status 2019-01-30 13:00:14 +01:00
Frank Morgner fc08d89247 goid-tool: differ PAccess and SoCManager usage 2019-01-30 09:35:16 +01:00
Frank Morgner a8c84d490a handle multiple verifications when changing secret 2019-01-30 09:35:11 +01:00
Raul Metsma 70d690ace7 r value is already checked on line 113 (#1582) 2019-01-24 13:15:13 +01:00
Frank Morgner 4916d07ff2 fixed unused check 2019-01-20 23:02:21 +01:00
Frank Morgner 79d019fc5f fixed typo
closes https://github.com/OpenSC/OpenSC/issues/1576
2019-01-20 23:02:21 +01:00
Frank Morgner 745b8cf420 added include guards to compatibility headers 2019-01-20 23:02:21 +01:00
Frank Morgner 6bf7c0d219 don't hide global variables 2019-01-20 23:02:21 +01:00
Frank Morgner 1991dcea0d removed unused comparison 2019-01-20 23:02:21 +01:00
Frank Morgner 3fe198f21e treat records with size_t 2019-01-20 23:02:21 +01:00
Frank Morgner 1106508656 removed tautologic comparison 2019-01-20 23:02:21 +01:00
Frank Morgner 4b30858092 pkcs11-tool: fixed argument type
reported by lgtm
2019-01-20 23:02:21 +01:00
Frank Morgner d806ee3245 fixed unsafe usage of gmtime
reported by lgtm
2019-01-20 23:02:21 +01:00
Frank Morgner b8b4f7c36f goid-tool: added error checking for verify/change 2019-01-18 23:02:36 +01:00
Martin Paljak c3a9837b10 Add mechanisms used by SoftHSM2
/Library/OpenSC/bin/pkcs11-tool --module /usr/local/lib/softhsm/libsofthsm2.so -M

will not show any more numeric mechanisms.

Source: https://www.cryptsoft.com/pkcs11doc/STANDARD/include/v240e01/pkcs11t.h
2019-01-15 13:07:58 +02:00
Raul Metsma 3c1d425eb9 Remove unused include
Signed-off-by: Raul Metsma <raul@metsma.ee>
2019-01-15 12:48:26 +02:00
Mat e19fe680c4 Add object type "secrkey" to help of --type switch in pkcs11-tool (#1575)
* Add object type "secrkey" to help of --type switch in pkcs11-tool

Reading an object with pkcs11-tool requires the `--type` switch. The help for that switch is currently incomplete as it is missing the (not very friendly named" *secrkey* option used to read out a secret key object.

I have added this information to the help description.

* Update man page

Describe secrkey option of pkcs11-tool's --type switch in man page
2019-01-15 07:32:41 +01:00
Hannu Honkanen 87d7eb2214 Select MyEID applet with AID in myeid_init() to ensure that it is selected before sending other commands. 2019-01-15 07:32:03 +01:00
Doug Engert 08a02ed5d2 Fix PKCS#11 Object Restrictions
Framework-pkcs15.c silently ignores adding objects if MAX_OBJECTS
is exceeded while creating the fw_data objects. This simple fix
is to change the MAX_OBJECTS from 64 to 128. A better fix would
be to realloc the objects arrays as needed.

__pkcs15_create_data_object and __pkcs15_create_secret_key_object
now return rv like the other  __pkcs15_create_*_object routines.

pkcs15_dobj_get_value now calls sc_pkcs15_read_data_object just like
the other pkcs15_*_get_value routines. The problem was introduced
in 0c3412bb 2018-04-09 which added:
 `return sc_to_cryptoki_error(SC_SUCCESS, "C_GetAttributeValue");`
before trying to read the data object.

The MAX_OBJECT problem was discovered while trying to use a new PIV
card with 24 standard cert objects and 10 other objects for a total
of 106 objects. Each cert object corresponds to a cert, pubkey,
private key, and the cert object itself for a possible 112 data objects.

The pkcs15_dobj_get_value was found while running:
running pkcs11-tool -r -y data --application-id 2.16.840.1.101.3.7.2.1.1
using git bisect to locate the bad commit.  The pkcs11 data objects are
created last from the pkcs15 objects which are a linked list with no limits.

 On branch fix-object-restrictions
	modified:   src/pkcs11/framework-pkcs15.c
2019-01-15 07:31:39 +01:00
Frank Morgner 53dfde94a9 iso-sm: fixed allocating enough data
regression from aa940e8619
2019-01-15 07:31:20 +01:00
Frank Morgner 7d36bab701 don't force the max buffer size with Le=0
This happens, when we know the size will be smaller, but we still use
Le=0 in case of SM.
2019-01-15 07:31:20 +01:00
Frank Morgner 609e2d89cf added GoID Tool 2019-01-15 07:31:20 +01:00
Frank Morgner 141ec6ab23 added shortcut to update binary via sfid 2019-01-15 07:31:20 +01:00
Frank Morgner 1eda4c1795 sc-hsm-tool: add support for initializing biometry 2019-01-15 07:31:20 +01:00
Frank Morgner 3611b5c9f2 tools: fixed colors if -v is specified 2019-01-15 07:30:46 +01:00
Frank Morgner fbb4d1f843 tools: use consistent behavior of -v
-v switches to debug output to stderr in OpenSC tools regardless of the opensc.conf setting
2019-01-15 07:30:46 +01:00
Frank Morgner 0af46c88b7 added tests for Microsoft CryptoAPI
imported from https://github.com/CardContact/sc-hsm-embedded
2019-01-15 07:30:13 +01:00
Peter Marschall bb6b78937f OpenPGP: harmonize error messages around 'key_id'
* consistently use term "Invalid key ID; must be 1, 2, or 3" in error messages
  about invalid key IDs instead of various alternatives.
* use error type SC_ERROR_INVALID_ARGUMENTS instead of SC_ERROR_INVALID_DATA
  when the key_id was passed to the respective function
* harmonize the checks to consistently use 'key_id < ... || key_id > ...'

In addition, initialize a variable to keep clang & compilers on OSX happy.
2019-01-06 22:34:52 +01:00
Peter Marschall 57e66fd42e OpenPGP: harmonize error messages
Combine sequences
	sc_log(..., "...");
	LOG_FUNC_RETURN(...);
where c_log() prints a constant string
by
	LOG_TEST_RET(..., "...");

This change results in shorter, more concise code as well as
better harmonized error messages.
2019-01-06 22:34:52 +01:00
Peter Marschall 5544418339 OpenPGP: harmonize error messages used in LOG_TEST...() calls
Don't terminate the messages with a period, because they are going to end up
as the first argument to a format string of the form "%s: ...".
I.e. they will be part of a longer string and terminated by a colon anyway.
2019-01-06 22:34:52 +01:00
Peter Marschall b95d936e6c OpenPGP: allow reading large DOs in v3 cards
Set the read buffer size in pgp_read_blob() large enough to contain DOs
with the maximum size defineable in the extended capabilities DO 00C0.
2019-01-06 22:28:14 +01:00
Frank Morgner 5c50dc58da fixed 320270 Dereference after null check 2019-01-04 00:44:45 +01:00
Frank Morgner aa940e8619 iso-sm: avoid allocation of big chunk of data
Use unencrypted APDU's resplen to estimate the size of the required SM
response buffer
2019-01-04 00:43:48 +01:00
Frank Morgner 6f0f42c506 fixed use of uninitialized data
When card->sm_ctx.ops.free_sm_apdu gets called in sc_sm_single_transmit
with a prior transmission error, then `sm_encrypt` still tries to
decrypt the response and hence, accesses the previously uninitialized
`resp`.
2019-01-04 00:43:48 +01:00
Peter Marschall a6ee84f13d opensc-explorer: fix 'pin_info' command
Correctly treat 'data.pin1.logged_in' as tristate instead of boolean.
While at it, fix visual glitch to not wrap around a stand-alone period.
2019-01-02 09:08:00 +01:00
Peter Marschall d577802ea7 OpenPGP: emulate SC_PIN_CMD_GET_INFO command for cards not supporting it 2019-01-02 09:06:54 +01:00
Peter Marschall 7092d32830 OpenPGP: get rid of "magic" constants in pgp_gen_key()
Use defined symbolic names for well-known DOs to copy data to a correctly
defined buffer 'apdu_data' using ulong2bebytes() instead of relying on
"magic" constants and C's string semantic.
Also use 'sizeof(apdu_data)' instead of additional magic constants.
2019-01-02 09:05:51 +01:00
Peter Marschall 4c51a53bed OpenPGP: get rid of "magic" constants in gnuk_delete_key()
Use defined symbolic names for well-known DOs to copy data to a correctly
defined buffer 'data' using ulong2bebytes() instead of relying on
"magic" constants and C's string semantic.
Also use 'sizeof(data)' instead of strange strlen() calculations.
2019-01-02 09:05:51 +01:00
Peter Marschall 0a903522b8 OpenPGP: get rid of "magic" constants in pgp_build_extended_header_list()
Use defined symbolic names for well-known DOs to copy data to a correctly
defined buffer 'data' using ulong2bebytes() instead of relying on
"magic" constants.
2019-01-02 09:05:51 +01:00
Jakub Jelen aa7118192a p11test: Use function compatible with OpenSSL 1.0.2 2018-12-31 21:56:45 +01:00
Peter Marschall 391131bb5e OpenPGP: use "hist_bytes" DO 5F52 as args to pgp_parse_hist_bytes()
Fix glitch that crept in during re-factoring.
This should unbreak Yubikeys.
2018-12-31 21:56:18 +01:00
Peter Marschall 1a60cd761f OpenPGP: fix value for EXT_CAP_MSE
enum _ext_caps is a set of bit flags
2018-12-31 21:56:18 +01:00
Peter Marschall bc17e23bd6 OpenPGP: fix spec interpretation error in hist_byte parsing
Command chaining is available with OpenPGP card spec 1.1+, not only with 3.0+
2018-12-31 21:56:18 +01:00
Peter Marschall 54dd9f4878 OpenPGP: revert 4d8b2c12ed
It broke OpenPGP on Yubikey NEOs and maybe other older versions too.

Reverting it restores functionality for those Yubikeys.
2018-12-31 21:56:18 +01:00
Doug Engert 075cac482b PIV - Some VA cards have LCS = 0F Terminated
Changes to be committed:
	modified:   card-piv.c
2018-12-27 14:25:45 +01:00
Doug Engert 7fbcd6e920 PIV - test i7e
On branch piv-improved-matching
 Changes to be committed:
	modified:   card-piv.c
2018-12-27 14:25:45 +01:00
Doug Engert a78becb76e PIV - Fix blanks and use returned value
On branch piv-improved-matching
 Changes to be committed:
	modified:   card-piv.c
2018-12-27 14:25:45 +01:00
Doug Engert 1fe1d40e38 PIV - Improved error handling of get_challenge
Random data from PIV card is obtained using GENERAL AUTHENTICATE command
for a request of a Challenge from the card. "00 87 00 9B 04 7C 02 81 00"
Usually 8 bytes are returned.

NIST 800-73-3_PART2, "A.1 Authentication of the PIV Card Application Administrator"
"Table 11. Authentication of PIV Card Application Administrator" shows an example of
how to do this.

Some cards (one I have: 3b:7d:96:00:00:80:31:80:65:b0:83:11:17:d6:83:00:90:00)
will not allow 2 of these commands in a row. (Maybe assuming command is only
used as in Table 11 and is expecting the second command.)

Code was added to card-piv.c so if "6A 80" is returned, try the command one more time.
For any other GENERAL AUTHENTICATE failure, SC_ERROR_NOT_SUPPORTED is returned.
piv_get_challenge may be called within a loop from sc_get_challenge if more random
data is needed thus causing the the 2 commands to sent in a row.

On branch piv-improved-matching
 Changes to be committed:
	modified:   card-piv.c
2018-12-27 14:25:45 +01:00
Doug Engert e13c0b83ef PIV - Improved Card Matching for Dual CAC/PIV and PIVKEY cards.
Not all PIV applets are the same. Different versions of NIST 800-73 and improperly implemented
or not implemented required features of NIST 800-73 cases problems. Have a look at the card_issues
listed in card-piv.c. The PIV driver has tried to detect the differences based on clues found in
the ATR historical bytes and vendor version numbers for some cards.

At the same time it has tried to support the possibility there are multiple applets
on a card that the user may want to use at the same time from different applications.
This has lead to some detection problems with Dual CAC/PIV cards. The same cards
sold by the vendor may have only a PIV applet that may not be the same PIV applet that
is on the Dual PIV/CAC cards.

http://www.cac.mil/Portals/53/Documents/CAC-utilziation-and-variation-matrix-v2.03-20May2016.doc
defines a number of official CAC cards in active service. A table of the ATRs for these is now used
to detect these cards. The PIV version of the CCC is also read to see if any CAC PKI objects
are defined in the CCC, indicating it is a Dual CAC/PIV, even if the ATR is not listed.

A more conservative approach to try and handle multiple applets on a card is used. Based
on issues with the implementation of the PIV applet this may not be possible to do.
So for many cards no additional detection will be done at the start of every transaction,
and the login state can not be detected correctly.

ATRs for PIVKEY are also in the match table, as these cards have a log of issues.

Other PIV cards in the future or not yet tested may not be covered properly by this patch.
Extra debugging was added with "PIV_MATCH" to help with these other cards.
With "debug = 7;", `grep PIV_MATCH opensc-debug.log` can be used to see how a card
type and card_issues are derived.

On branch piv-improved-matching
 Changes to be committed:
	modified:   card-piv.c
	modified:   cards.h
2018-12-27 14:25:45 +01:00
Peter Marschall dc505be808 openpgp-tool: use binary OR for calculating 32-bit integers from byte
Also avoid potential unintended sign extension (SIGN_EXTENSION).
2018-12-27 14:13:41 +01:00
Frank Morgner b11cc3871e tools: harmonize card initialization 2018-12-18 14:50:45 +01:00
Jakub Jelen 4d8b2c12ed card-openpgp: Workaround parsing historical bytes on Yubikey to set correct capabilities 2018-12-18 14:50:08 +01:00
Jakub Jelen 26aed9441a padding: Do not set wrong flags if the raw capability is not available
Thanks Doug Engert for pointing the issue out
2018-12-18 14:50:08 +01:00
Jakub Jelen 070190d72e padding: Resotre the PAD_NONE if nothing else is specified
Patch from Doug Engert
2018-12-18 14:50:08 +01:00
Jakub Jelen f0b47a51d3 p11test: Report key sizes for missing certificates 2018-12-18 14:50:08 +01:00
Jakub Jelen ed6267512c p11test: Do not report usage on incomplete keys 2018-12-18 14:50:08 +01:00
Jakub Jelen 28deeb2a00 p11test: Do not report and try pairs without private key 2018-12-18 14:50:08 +01:00
Jakub Jelen 969e29e663 p11test: Do not talk about multipart encryption 2018-12-18 14:50:08 +01:00
Khem Raj 35cb70b5d6 Remove redundant logging
Same information is printed a few line below in same function, the only
difference is that there it takes care of case when label is NULL pointer
unlike this line

secondly, every function call to cosm_write_tokeninfo() in this file
passes label=NULL, and then it tries to print a null pointer

Fixes errors like
src/libopensc/log.h:48:47: error: '%s' directive argument is null
[-Werror=format-overflow=]

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2018-12-18 13:50:08 +01:00
Peter Marschall b1539545d0 OpenPGP: free() unconditionally in error handling of pgp_store_key() 2018-12-17 09:49:57 +01:00
Peter Marschall c7fc7cc134 OpenPGP: refactor error handling in pgp_calculate_and_store_fingerprint()
* initialize pointers to NULL
* explicitly compare pointers to NULL
* use LOG_TEST_*() macros instead of explicit coding
2018-12-17 09:49:57 +01:00
Peter Marschall bf2a9bc53b OpenPGP: refactor error handling in pgp_build_extended_header_list()
* use LOG_TEST_*() macros instead of explicit coding
2018-12-17 09:49:57 +01:00
Peter Marschall 7916d45857 OpenPGP: refactor error handling in pgp_store_key()
* use LOG_TEST_*() macros instead of explicit coding
* harmonize use of card->ctx: saves one variable
* explictly compare pointers to != NULL
2018-12-17 09:49:57 +01:00
Peter Marschall 08b9f362c0 OpenPGP: refactor error handling in pgp_gen_key()
* use LOG_TEST_*() macros instead of explicit coding
2018-12-17 09:49:57 +01:00
Peter Marschall d3e730b621 OpenPGP: refactor error handling in pgp_put_data_plain()
* use LOG_TEST_*() macros instead of explicit coding
2018-12-17 09:49:57 +01:00
Peter Marschall 738c933609 OpenPGP: a few cleanups for Gnuk
* make sure to remain within buffer size in pgp_read_blob()
* make logic more readable in pgp_get_data()
2018-12-17 09:49:57 +01:00
Peter Marschall 01287e393e framework-pkcs15: fix warning
* fix -Werror=format-truncation= warning in pkcs15_init_slot()
* do not only remove blanks from the end, but all spaces
2018-12-09 23:44:00 +01:00
Frank Morgner f2145eca79 don't debug pointers 2018-12-06 09:26:42 +01:00
Frank Morgner 5474370b17 always log APDUs with SC_LOG_DEBUG_NORMAL 2018-12-06 09:26:42 +01:00
Frank Morgner a899a46b09 replaced SC_TEST_RET with LOG_TEST_RET 2018-12-06 09:26:42 +01:00