Commit Graph

7267 Commits

Author SHA1 Message Date
Vincent JARDIN 7cd713d15d IASECC/CPX: enable RSA algorithms
Without this fix, we get:
./pkcs11-tool --module ../lib/onepin-opensc-pkcs11.so -M
Using slot 0 with a present token (0x0)
Supported mechanisms:
  SHA-1, digest
  SHA224, digest
  SHA256, digest
  SHA384, digest
  SHA512, digest
  MD5, digest
  RIPEMD160, digest
  GOSTR3411, digest

Once we include it, we get:
./pkcs11-tool --module ../lib/onepin-opensc-pkcs11.so -M
Using slot 0 with a present token (0x0)
Supported mechanisms:
  SHA-1, digest
  SHA224, digest
  SHA256, digest
  SHA384, digest
  SHA512, digest
  MD5, digest
  RIPEMD160, digest
  GOSTR3411, digest
  RSA-9796, keySize={1024,2048}, hw, decrypt, sign, verify
  RSA-PKCS, keySize={1024,2048}, hw, decrypt, sign, verify
  SHA1-RSA-PKCS, keySize={1024,2048}, sign, verify
  SHA256-RSA-PKCS, keySize={1024,2048}, sign, verify
  RSA-PKCS-KEY-PAIR-GEN, keySize={1024,2048}, generate_key_pair
2021-03-17 10:58:20 +01:00
Vincent JARDIN fd97f49a84 IASECC: CPX have 2 applications
There are 2 applications: default one (contact mode) and the contactless
mode.
2021-03-17 10:58:20 +01:00
Vincent JARDIN 560692221b IASECC/CPX: file selection and app enumeration
Thanks to this commit, we get the full support of:
  - ./opensc-explore
    cd 0001
    asn1 2F00
  - ./pkcs11-tool -O
  - etc.
2021-03-17 10:58:20 +01:00
Vincent JARDIN acb8822444 IASECC: Add support for CPx cards
The French CPx Healthcare cards are designed to support the IASECC
standard.
2021-03-17 10:58:20 +01:00
Jakub Jelen 40c50a3a42 oberthur: Handle more memory issues during initialization
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31540
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31448
2021-03-16 12:02:05 +01:00
Peter Popovec f46b617397 Skip authentication if card access control mechanism is not active.
Depending on the "lifecycle" of the file, we may omit the authentication
operation.  Typically if the card is in initialization or creation state,
the access control mechanism is inactive.  If authentification can be
skiped, the card driver is responsible for setting the "acl_inactive"
variable in sc_file structure.
2021-03-16 10:57:05 +01:00
Jakub Jelen 1ef79e99f7 reader-pcsc: Avoid strict aliasing issues 2021-03-09 23:59:58 +01:00
Jakub Jelen 60632100a0 pkcs11: Avoid redefinition of ck_interface (#2243) 2021-03-09 23:59:58 +01:00
Jakub Jelen 63031b2193 pkcs11-tool: Avoid strict-aliasing issues on 32b architectures 2021-03-09 23:59:58 +01:00
Jakub Jelen 2fa6700599 Remove more issues with strict aliasing
These would demonstrate with gcc11 and can be detected with gcc
flag -Wstrict-aliasing=2 (also with older gcc)
2021-03-09 23:59:58 +01:00
Jakub Jelen 45e262f537 westcos: Avoid strict aliasing violations 2021-03-09 23:59:58 +01:00
Jakub Jelen b5f26051bb Fix build on gcc11
This made most of the applications crashing in Fedora 34 when
smart card was plugged in.

The suggested patch makes the code path more obvious for gcc to
handle.

https://bugzilla.redhat.com/show_bug.cgi?id=1930652
2021-03-09 23:59:58 +01:00
Jakub Jelen b8266a4c86 Revert "fixed atrmask for gnuk"
This reverts commit 98beb86a38.
2021-03-01 15:43:28 +01:00
Jakub Jelen 0ce245a411 p11test: Fix one-off comparison 2021-03-01 15:43:28 +01:00
Jakub Jelen 56af7de137 Change (X)EDDSA EC_PARAMS encoding to OID
This is the current interpretation of the specs after talking with
several members of PKCS #11 TC.
2021-03-01 15:43:28 +01:00
Jakub Jelen c39e31b274 pkcs11: Rewrite ec params to use sc_asn1_put_tag() 2021-03-01 15:43:28 +01:00
Jakub Jelen ae771a135f openpgp: Rewrite decipher/derive to use asn1 functions 2021-03-01 15:43:28 +01:00
Jakub Jelen cb8c7647ca asn1: Do not crash on invalid arguments 2021-03-01 15:43:28 +01:00
Jakub Jelen a020b85d94 unittests: Briefly test asn1_encode 2021-03-01 15:43:28 +01:00
Jakub Jelen 73e283b4b1 openpgp: Correctly handle curve25519 keys 2021-03-01 15:43:28 +01:00
Jakub Jelen 64b61a7556 openpgp: Do not fail hard if unknown algorithm is encountered and fix typo 2021-03-01 15:43:28 +01:00
Jakub Jelen 9bd139d1e4 openpgp: Check return code of OID decoding from ASN1 2021-03-01 15:43:28 +01:00
Jakub Jelen 8c4d325576 framework-pkcs15: Fix typo in comment 2021-03-01 15:43:28 +01:00
Doug Engert 0380142482 Fix obtaining key_length i.e. field_length pkcs15-openpgp
card-opennpgp.c and pkcs15-openpgp.c have a strang way of
using sc_object_id_t to store what they call a binary_oid
or oid_binary.  It is used to convert the EC curve asn1
returned in the cxdata.

This code uses asn1_decode_object_id to use sc_object_id_t
as used in the rest of the code.

The code and ec_curve tabes in card-openpgp.c where not changed.

pkcs15-openpgp.c was channge si to can use:
algorithm_info = sc_card_find_ec_alg(card, 0, &oid);
to retried the key_length to add to the pubkey and prkey entries.
The EC and EDDSA needs (i.e. field_length)  to run.

 On branch eddsa
 Your branch is up to date with 'Jakuje/eddsa'.

 Changes to be committed:
	modified:   card.c
	modified:   pkcs15-openpgp.c
2021-03-01 15:43:28 +01:00
Jakub Jelen 091b7670eb p11test: Reformat the script and allow running against softhsm ed25519 keys (with few tweaks)
The Ed25519 implementation in SoftHSM is now broken /non-interoperable. After fixing that,
the interoperability tests should work with this script:

 * SoftHSMv2#528: Avoid creating duplicate mechanisms
 * SoftHSMv2#522: Fix advertised min and max mechanism sizes according to final PKCS#11 3.0 specification
 * SoftHSMv2#526: Adjust EDDSA code to return valid EC_PARAMS according to the final PKCS #11 3.0 specification
2021-03-01 15:43:28 +01:00
Jakub Jelen 35cfc291ce pkcs11-tool: Add support for (X)EDDSA key generation 2021-03-01 15:43:24 +01:00
Jakub Jelen 485b6cff44 p11test: Add support for EdDSA keys 2021-03-01 15:42:29 +01:00
Jakub Jelen 32ec1f92b9 openpgp: Set reasonable usage for (X)EdDSA keys 2021-03-01 15:42:29 +01:00
Jakub Jelen e7d390f9dd openpgp: Unbreak EC algorithms for GNUK
Since 09a594d bringing ECC support to openPGP card, it did not count
with GNUK. This adds exception for GNUK to unbreak ECC signatures
as GNUK presents BCD version < 3.
2021-03-01 15:42:29 +01:00
Jakub Jelen a965829f52 openpgp: Use only Derive mechanism for curve25519 keys 2021-03-01 15:42:29 +01:00
Jakub Jelen 5d5c391793 opensc-tool: Support for new (X)EdDSA keys 2021-03-01 15:42:29 +01:00
Jakub Jelen 5178e74e1b pkcs11-tool: Support for new (X)EdDSA keys 2021-03-01 15:42:29 +01:00
Jakub Jelen 2fb688683e pkcs15-tool: Support for new (X)EdDSA keys 2021-03-01 15:42:29 +01:00
Jakub Jelen b351bf5ea4 openpgp: Initial support for (X)EdDSA keys 2021-03-01 15:42:29 +01:00
Jakub Jelen caae75758c Add internal support for (X)EdDSA keys 2021-03-01 15:42:26 +01:00
Jakub Jelen 80f80317d1 pkcs11: Add new SHA3 identifiers 2021-03-01 14:35:51 +01:00
Jakub Jelen 095c28e372 pkcs11: Add new (X)EDDSA identifiers 2021-03-01 14:35:51 +01:00
Jakub Jelen 0455a5665e winscard: Add missing constant define 2021-03-01 14:35:51 +01:00
Jakub Jelen c78fa164c9 openpgp-tool: Fix typos OpenGPG -> OpenPGP 2021-03-01 14:35:51 +01:00
Jakub Jelen a30bf95eed openpgp: Fix typo in the card name 2021-03-01 14:35:51 +01:00
Jakub Jelen a5a6757d10 pkcs11-tool: Add CKA_KEY_TYPE attribute for keygen as recommeneded in specification 2021-03-01 14:35:50 +01:00
Jakub Jelen e82f875047 pkcs11-spy: Systematize output of C_GetMechanismInfo 2021-03-01 14:35:50 +01:00
Jakub Jelen 86e01d7c47 pkcs11: Prefer CKA_EC_PARAMS over deprecated CKA_ECDSA_PARAMS by listing it first in the list 2021-03-01 14:35:50 +01:00
Jakub Jelen f726d4f201 Improve logging mostly in opengpg 2021-03-01 14:35:50 +01:00
Frank Morgner 5b42a62ec0 use macos' ${Caches} by default 2021-03-01 11:49:14 +01:00
Frank Morgner fe6864c5f3 fixed 354852 Invalid type in argument to printf format specifier 2021-02-25 23:34:57 +01:00
Frank Morgner c2670b0787 fixed 13755 Resource leak
... as reported by coverity scan.

p11cards are freed by emptying the virtual slots. virtual slots are
creatd with the framework's create_tokens. Hence, we need to free
p11card if no tokens were created.
2021-02-25 23:34:57 +01:00
Frank Morgner 881dca94ef avoid memory leak when creating pkcs#15 files 2021-02-25 23:34:57 +01:00
Frank Morgner d353a46d04 tcos: fixed memcpy with 0 or less bytes 2021-02-25 23:34:57 +01:00
Peter Popovec 6738d456ac ECDSA verify
Added support for raw ECDSA verify.
2021-02-25 18:37:18 +01:00
Frank Morgner 999874fb1c fixed potential memory issue
closes https://github.com/OpenSC/OpenSC/pull/2230
2021-02-25 18:36:39 +01:00
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
Jakub Jelen 5f7c91e54f pkcs15-isoApplet: Avoid uninitialized reads
Thanks coverity

CID 365817
2021-02-25 09:08:52 +01:00
Jakub Jelen 46cfe89b3c pkcs15-iasecc: Avoid memory leak
Thanks coverity

CID 365818
2021-02-25 09:08:52 +01:00
Jakub Jelen a567ab9dca p11test: Fix possible resource leak
Thanks coverity

CID 365819
2021-02-25 09:08:52 +01:00
Jakub Jelen cee431a3ce pkcs15-iasecc: Check return value as in other cases
Thanks coverity

CID 365820
2021-02-25 09:08:52 +01:00
Jakub Jelen ffed34663d sm-global-platform: Fix possible memory leak
Thanks coverity

CID 365821
2021-02-25 09:08:52 +01:00
Jakub Jelen 3b556ef618 sm-cwa14890: Fix resource leak
CID 365822

Thanks oss-fuzz
2021-02-25 09:08:52 +01:00
Jakub Jelen 1dbe4b5a5b isoApplet: Prevent reading uninitialized values
CID 365823

Thanks coverity
2021-02-25 09:08:52 +01:00
Jakub Jelen 2f232f217b pkcs11-tool: Avoid double free and check allocation
366349 Double free

Thanks coverity
2021-02-25 09:08:52 +01:00
Jakub Jelen ae1cf0be90 iasecc: Prevent stack buffer overflow when empty ACL is returned
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=30800
2021-02-25 09:08:52 +01:00
Jakub Jelen 1252aca9f1 cardos: Correctly calculate the left bytes to avoid buffer overrun
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29912
2021-02-25 09:08:52 +01:00
Jakub Jelen 17d8980cde oberthur: Avoid two buffer overflows
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=30112
2021-02-25 09:08:52 +01:00
Jakub Jelen 9c91a4327e oberthur: Free another read data on failure paths 2021-02-25 09:08:52 +01:00
Jakub Jelen 7ba89daae6 apdu: Do not insert delay while fuzzing
This was timeout after 60 seconds. After skipping this call, we
get down to 1 s for the same input

Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27423
2021-02-25 09:08:52 +01:00
Jakub Jelen 251c4f6b76 oberthur: Avoid memory leaks
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29998
2021-02-25 09:08:52 +01:00
alt3r 3go 3044557299 openpgp: fix DO deletion
This fixes a problem reported in Nitrokey forum at

https://support.nitrokey.com/t/veracrypt-encryption-with-nitrokey-error/2872

as inability to save the VeraCrypt's keyfile onto the token
after deleting an existing one, unless the PKCS11 is reinitialized.

Reason: commit cbc53b9 "OpenPGP: Support write certificate for Gnuk"
introduced a condition on getting the blob handle, which is surplus
(the pgp_find_blob() function actually does that) and prevents
the blob refresh upon deletion, breaking the logic introduced
earlier in commit 9e04ae4 and causing the higher-level effect reported.

While at it, corrected comments to actually reflect the flow logic.

Tested on Fedora 33 using the repro steps from the forum and Nitrokey Pro.

Signed-off-by: alt3r 3go <alt3r.3go@protonmail.com>
2021-02-16 13:07:19 +01:00
ihsinme 6372adeb20 Update card-oberthur.c 2021-02-11 12:32:19 +01:00
ihsinme 0a3d7a28a7 Update card-epass2003.c 2021-02-11 12:32:19 +01:00
Zhang Xiaohui 49788678fe Small memory leak fix 2021-02-10 09:26:37 +01:00
Zhang Xiaohui 1c4a01d766 Small memory leak fix 2021-02-10 09:26:11 +01:00
Vincent JARDIN 66e5600b27 IASECC: log AID selection
Record the selection of the AID for better debugging
2021-02-05 12:09:20 +01:00
Jakub Jelen 8a6026abf5 Avoid memory leak from profile objects 2021-02-05 00:22:43 +01:00
Jakub Jelen da247384e7 pkcs11: Do not advertize VERIFY flag on the EC derive mechanisms
Amends 285db1ef
2021-02-05 00:22:43 +01:00
Jakub Jelen 176b20f339 pkcs11-tool: Display additional EC mechanism flags 2021-02-05 00:22:43 +01:00
Jakub Jelen cb074c5fa0 pkcs11: Add new mechanism flags from EC curves from current PKCS #11 3.0 2021-02-05 00:22:43 +01:00
Jakub Jelen 5633129bd8 p11test: Add CKM_ECDSA_SHA224 2021-02-05 00:22:43 +01:00
Jakub Jelen 0d693f63cb pkcs11-spy: Fix behavior of PKCS#11 3.0 applications when proxying PKCS#11 2.x module
Fixes #2204
2021-01-26 13:52:23 +01:00
Doug Engert f704e4f23e Pkcs11-tool changes to test a modules ability to use threads
Option --use-locking has C_Initialize pass in parameters with the
CKF_OS_LOCKING_OK to tell module to use threads. The default is it passes NULL
which says threads are not needed.

The following is not designed to be used by the general user. There are for debugging
and test scripts and only compiled if the system has threads.

    Option --test-threads <arg> can be passed multiple times. Each one starts a thread.
    <arg> is a list of 2 byte commands seperated by ":". The thread will execute these.
    Current commands are:
       IN - C_Initialize(NULL)
       IL - C_Initialize with CKF_OS_LOCKING_OK
       Pn - Pause for n seconds
       GI - C_GetInfo
       SL - C_GetSlotList
       Tn - C_GetTokenInfo  from slot_index n

These are just enough calls to see if threads are working in the module.
Output is written to stderr.

 Changes to be committed:
	modified:   doc/tools/pkcs11-tool.1.xml
	modified:   src/tools/Makefile.am
	modified:   src/tools/pkcs11-tool.c
2021-01-26 12:50:39 +01:00
Doug Engert 1b4e9f1d4a C_Initialize may be called by multiple threads
While trying to setup an OpenSC context, the global_locking
and detect cards, it is possible that multiple threads may
call C_Initialize. The current code tries to prevent this using
"if (context == NULL)"  but this is not a mutex, and
multiple threads may endup overwrite contexts and global locking and
cause additional problems, with pcsc and segfault.

FireFox appears to do this see #2032

The PR adds a mutex or Critical section to make sure only one
thread creates the context sets the global_locking  and does
the initial detect cards, etc.

This allows the global_lock (if requested) to be setup
which is then used for other calls.

All but the first call to C_Initialize will return with CKR_OK,
others will return CKR_CRYPTOKI_ALREADY_INITIALIZED.

 Date:      Mon Jan 11 12:47:12 2021 -0600
 Changes to be committed:
	modified:   src/pkcs11/pkcs11-global.c
2021-01-26 12:50:39 +01:00
Doug Engert d369965a7f pkcs11-tool support key-gen for GENERIC secret key
Fixes #2139

Added code to support  mechanism GENERIC-SECRET-KEY-GEN.

Improved --help  and doc/tools/pkcs11-tool.1.xml because key gen
of symmetric keys pass CKA_VALUE_LEN which is length of key in bytes.

Tested with:

./pkcs11-tool --module /usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so \
 --login --label generic-64 --keygen --key-type GENERIC:64 \
 --mechanism GENERIC-SECRET-KEY-GEN

./pkcs11-tool --module /usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so --login -O
2021-01-26 12:34:15 +01:00
Jakub Jelen e1c8361ff3 idprime: Create algorithme reference based on the MGF1 flags as the HASH flags are no longer present for RSA-PSS mechanism 2021-01-26 10:53:30 +01:00
Jakub Jelen 44d429c3ad padding: Pass the MGF1 information to the card driver for RSA-PSS mechanism 2021-01-26 10:53:30 +01:00
Jakub Jelen edaf921eb6 idprime: Support V3 key references 2021-01-26 10:53:30 +01:00
Jakub Jelen ac81764308 idprime: Try to use different key_reference for V3 2021-01-26 10:53:30 +01:00
Jakub Jelen a6ed34bbb5 Add support for Gemalto IDPrime OS version 3 (padded pin to 16 bytes with zeroes)
Fixes #2202
2021-01-26 10:53:30 +01:00
Peter Popovec a3ca7613cd MyEID: opensc.conf - option to disable PKCS1 padding in card.
config option for MyEID:  "disable_hw_pkcs1_padding"

If user set this option to non zero, OpenSC is forced to calculate padding
in software. This will allow users to use RSA 1024 with SHA512.
2021-01-26 00:27:47 +01:00
Doug Engert 0b0deae4be unused code removed
On branch ECDSA-flags
 Changes to be committed:
	modified:   framework-pkcs15.c
2021-01-24 23:48:00 +01:00
Doug Engert 521d420c42 pkcs11 ECDSA verify need rs converted to sequence
The --signature-format openssl in pkcs11-tool does the correct
operation to convert the OpenSSL formated signature to rs for PKCS11

This commit modifies pkcs11/openssl.c to convert back to sequence
for EVP_VerifyFinal

Without this mod the signature file was passed unmodified to
PKCS11, then to EVP_VerifyFinal but this violates PKCS11 standard.

 On branch ECDSA-flags
 Changes to be committed:
	modified:   openssl.c
2021-01-24 23:48:00 +01:00
Doug Engert 285db1ef29 ECDSA Signatures with hashes
This PR is based on discussion with @popovec in
https://github.com/OpenSC/OpenSC/issues/2181
and https://github.com/OpenSC/OpenSC/pull/2187
which was cherry-picked as 5e5300816c8

This has been tested with PIV, MyEID and Smartcard-HSM.
with ECDSA keys.

The main fixes include :
 - Setting "flags" in card drivers
 - added code to sc_pkcs15-compute-signature for handle ECDSA with hashes
 - code in framework-pkcs15.c

Signatures made by pkcs11-tool -sigm verify with openssl
but pkcs11-tool --verify  does not work with ECDSA but does with RSA
I suspect it has to do with:
and some  then creating the wrong PKCS11 mechanisms

It should work with the epass2003 which does hashes in the driver.
2021-01-24 23:48:00 +01:00
Peter Popovec 6049cb926c ECDSA-SHA1: Apply SHA1 to input data before PSO compute signature.
CKM_ECDSA and CKM_ECDSA_SHA1 cannot be registered in the same way.
We need to use sc_pkcs11_register_sign_and_hash_mechanism ()
for CKM_ECDSA_SHA1.

This fix  also enables more ECDSA-SHAxxx mechanisms in framework-pkcs15.c

Tested: MyEID 4.0.1 (secp256r1 with SHA1, SHA224, SHA256, SHA384, SHA512)

CI tests (Travis + OsEID) for ECDSA-SHAxxx mechanisms are also enabled.
2021-01-24 23:48:00 +01:00
Jakub Jelen 5f16ffae84 p11test: Explicitly return in case of SKIP macro is used
Thanks coverity

Fixes CID 365263
2021-01-22 19:07:05 +01:00
Jakub Jelen 03cbf91be5 iasecc: Avoid another memory leak
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29456
2021-01-22 19:07:05 +01:00
Jakub Jelen b820bdf5b3 tcos: Reformat tcos_decipher 2021-01-22 19:07:05 +01:00
Jakub Jelen 1db88374bb oberthur: Correctly check for return values
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28843
2021-01-22 19:07:05 +01:00
Peter Popovec ba85ae75e3 opensc-explorer, command "info" - added information about LCS
Information about "Life cycle status byte" is now available in listing.
Also src/libopensc/types.h update - added more LCSB definitions.
iso7816_process_fci () update: improved tag 0x8A parsing.

Fixes in card-flex.c and card-miocos.c - SC_FILE_STATUS_xxx is not
bitfield.
2021-01-22 19:04:22 +01:00
Peter Popovec ce7fa42958 Use fresh data from FCI instead of FCP for sc_pkcs15init_authenticate()
Function sc_pkcs15init_update_file(): we will try to select the file, if
file can not be selected, the file is created, and select operation is
repeated. In both cases, the "selected_file" variable contains the current
FCI of the selected file.

Then the sc_pkcs15init_authenticate () function is called, but not with
"selected_file" variable, but "file" variable where the FCP data is present
(from the file creation operation).

Difference between FCP and FCI  (pkcs15-init -C  / MyEID card).
62 17 80 02 00 FF 82 01 01 83 02 50 31 86 03 01 3F FF 85 02 00 00 8A 01 00
6F 17 80 02 00 FF 82 01 01 83 02 50 31 86 03 01 3F FF 85 02 00 00 8A 01 01

Here it is clear that the data from FCP are outdated.  The card changed the
TAG 0x8a from 0 to 1 ("no information given", "creation state".) We need to
respect the authority of the card, FCI is to be used in next code, not FCP.

	modified:   src/pkcs15init/pkcs15-lib.c
2021-01-22 18:59:22 +01:00
Frank Morgner 7a090b994e essentially revert 1bb2547
fixes #2199

returns not allowed PKCS#11 codes to applications, however
2021-01-22 13:19:33 +01:00
Jakub Jelen 219c6cc494 framework-pkcs15: Avoid leaking memory when create object fails 2021-01-11 14:49:22 +01:00
Jakub Jelen 96ae693d5a framework-pkcs15: Return success from __pkcs15_create_object 2021-01-11 14:49:22 +01:00
Jakub Jelen db18a72c64 pkcs11: Implement PKCS #11 3.0 Profile object and its handling in tools 2021-01-11 14:49:22 +01:00
Jakub Jelen 7f9e8ba85c pkcs11-tool: Add option to list PKCS #11 3.0 interfaces 2021-01-11 14:49:22 +01:00
Jakub Jelen d224b2612d pkcs11-spy: Implement new functions and interfaces to intercept PKCS #11 3.0 calls 2021-01-11 14:49:22 +01:00
Jakub Jelen 03079a9413 pkcs11: Add missing flag for new PKCS #11 3.0 functions 2021-01-11 14:49:22 +01:00
Jakub Jelen 6e25924eb0 common, pkcs11-tool: Use new PKCS #11 API with fallback to old one 2021-01-11 14:49:22 +01:00
Jakub Jelen 224e265266 Implement C_SessionCancel from PKCS #11 3.0 2021-01-11 14:49:22 +01:00
Jakub Jelen 7f0166ab12 p11test: Basic test for C_GetInterface API from PKCS#11 3.0 2021-01-11 14:49:22 +01:00
Jakub Jelen 95122abe2e pkcs11: Implement PKCS#11 3.0 stubs for required functions 2021-01-11 14:49:22 +01:00
Jakub Jelen 47151e9335 pkcs11: Implement getInterface() for accessing PKCS #11 3.0 functions 2021-01-11 14:49:22 +01:00
Jakub Jelen e58e7e1428 Standardize PKCS #11 version to 2.20 systematically 2021-01-11 14:49:22 +01:00
Jakub Jelen 910020aeec Ignore non-useful check in clang-tidy as we have ton of memset/memcpy 2021-01-06 14:15:06 +01:00
Jakub Jelen 9cda87e200 authentic: Initialize structure to avoid comparison against garbage
Thanks clang:

/src/libopensc/card-authentic.c:1564:47: warning: The left operand of '==' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
        if (acls[AUTHENTIC_ACL_NUM_PIN_RESET].method == SC_AC_CHV)   {
                                                     ^
2021-01-06 14:15:06 +01:00
Jakub Jelen d25009cde6 belpic: Remove unused variable
Thanks clang

/src/libopensc/card-belpic.c:230:7: warning: Although the value stored to 'r' is used in the enclosing expression, the value is never actually read from 'r' [clang-analyzer-deadcode.DeadStores]
                if((r = get_carddata(card, carddata, sizeof(carddata))) < 0) {
                    ^
/src/libopensc/card-belpic.c:230:7: note: Although the value stored to 'r' is used in the enclosing expression, the value is never actually read from 'r'
2021-01-06 14:15:06 +01:00
Jakub Jelen 3135fccdca itacns: Correctly free allocated memory
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28510
2021-01-06 14:15:06 +01:00
Jakub Jelen 049b2a8754 pkcs15: Do not override tokeninfo in bind_internal
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28550
2021-01-06 14:15:06 +01:00
Jakub Jelen 66f274dcaf authentic: Fix copy&paste error in log message 2021-01-06 14:15:06 +01:00
Jakub Jelen 88543529a2 pkcs11.exports: Remove duplicate symbols 2021-01-06 14:15:06 +01:00
Jakub Jelen f7b0ce3dac Remove duplicate symbols from libopensc.exports 2021-01-06 14:15:06 +01:00
Doug Engert f443c391b0 PIV whitespace cleanup and addtion of // clang-format off|on
Cleanup trailing whitespaces and protect hand formated structures
in card-piv.c and pkcs15-piv.c

 On branch PIV-whitespace
 Changes to be committed:
	modified:   card-piv.c
	modified:   pkcs15-piv.c
2020-12-15 11:14:15 +01:00
Carsten Blüggel f8af905574 Fixes #2175, C_GetAttributeValue for CKA_EXTRACTABLE, CKA_MODIFIABLE 2020-12-10 13:04:11 +01:00
Jakub Jelen 1ae8b60425 mcrd: Do not leak memory
Similar as in 62049ea18c

Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28405
2020-12-09 15:50:54 +01:00
Jakub Jelen 5df913b7f5 tcos: Check bounds in insert_pin()
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28383
2020-12-09 15:50:54 +01:00
Jakub Jelen 69544553c3 tcos: Reformat insert_pin() for readability 2020-12-09 15:50:54 +01:00
Jakub Jelen 196bf9e574 gpk: Replace assert with error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28306
2020-12-09 15:50:54 +01:00
Peter Popovec a089353e1f MyEID: enable more PKCS11 mechanisms
This patch enables using of: SHA224-RSA-PKCS, SHA256-RSA-PKCS,
SHA384-RSA-PKCS, SHA512-RSA-PKCS and PSS variants of these mechanism for
MyEID users. (This patch is related to issue #2173.)

CI tests for these mechanisms are also enabled (using OsEID emulation).
2020-12-09 04:29:46 +01:00
Jakub Jelen f015746d22 idprime: Use temporary variable instead of messing up the passed one
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28185
2020-12-04 09:30:10 +01:00
Jakub Jelen 78cdab949f tcos: prevent out of bounds read
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27719
2020-12-04 09:30:10 +01:00
Jakub Jelen 3ffe24cfb6 pkcs15: Clean tokeninfo on parse errors to avoid memory leaks
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27779
2020-12-04 09:30:10 +01:00
Jakub Jelen fb83cd0439 asn1: Improve logging 2020-12-04 09:30:10 +01:00
Jakub Jelen 61eb4e487e card: Correctly free pointers durint cache invalidation
As the whole structure is memset(0) on the following line,
we need to clean the pointers before doing so.

Thanks oss-fuzz

Related to:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27797
2020-12-04 09:30:10 +01:00
Jakub Jelen 85e08ae675 pkcs11-tool: Avoid calloc with 0 argument 2020-11-25 14:38:23 +01:00
rickyepoderi 3ce249f365 Issue 2153: organizationIdentifier is not translated by openssl 1.1.0/1.0.x 2020-11-25 09:33:20 +01:00
Frank Morgner 98beb86a38 fixed atrmask for gnuk
fixes https://github.com/OpenSC/OpenSC/issues/2155
2020-11-25 09:28:00 +01:00
Frank Morgner 480da424a5
fix possible infinite recursion (#2151)
fixes https://github.com/OpenSC/OpenSC/issues/2149
2020-11-25 09:27:28 +01:00
Jakub Jelen 0365c3ce6c westcos: Avoid assigning local variable to function arguments 2020-11-25 09:26:42 +01:00
Jakub Jelen 3d257410b2 sc-hsm: Avoid assigning local variable to function arguments 2020-11-25 09:26:42 +01:00
Jakub Jelen 63bb85b050 gpk: Avoid assigning local variable to function arguments 2020-11-25 09:26:42 +01:00
Jakub Jelen 871e4f2ac6 flex: Avoid assigning local variable to function arguments 2020-11-25 09:26:42 +01:00
Jakub Jelen 55a5556949 dnie: Remove unused assignment leaking local variable through parameters 2020-11-25 09:26:42 +01:00
Jakub Jelen af2fb6938c cac: Avoid assigning local variable to function arguments
Reported by cppcheck. The argument is not used after
returning from this function, but better make it explicit.
2020-11-25 09:26:42 +01:00
Jakub Jelen d0e5d62bf5 Verify the cache dir is correctly set with different combination of variables 2020-11-25 09:26:18 +01:00
Jakub Jelen 3eae6a031c ctx: Use more standard cache directory
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
2020-11-25 09:26:18 +01:00
Doug Engert 483e153182 ASN1 cleanup part 1
ASN1 tags are represented in two many ways within OpenSC.
This is a trivial change to simplify one aspect of this.
It also makes the code more readable.

SC_ASN1_CLASS_MASK, SC_ASN1_APP, SC_ASN1_CTX, SC_ASN1_PRV,
SC_ASN1_CONS are changed, and SC_ASN1_CLASS_MASK is added.

These then align with the bits defined by SC_ASN1_TAG_CLASS,
SC_ASN1_TAG_APPLICATION, SC_ASN1_TAG_CONTEXT, SC_ASN1_TAG_PRIVATE,
and SC_ASN1_TAG_CONSTRUCTED.

(SC_ASN1_UNI and SC_ASN1_TAG_UNIVERSAL are both 0x00 thus no change
is needed).

(No sign of a right shift of SC_ASN1_CTX or SC_ASN1_PRV causeing
problems has been seen in the code.) If found, can be solved.)

Close examination of the OpenSC code base shows all uses of tags
used by routines and sc_asn1_entry use the defines.

This could allows 26 lines of code in sc_asn1_skip_tag used to test
the 3 CLASS and CONSTRUCTED bits to be replaced by:

	if (((cla << 24) | tag) != tag_in)
		return NULL;

The 26 lines still work as will any other code in OpenSC
that tests the bits using the defines. It also allows new code
to be simplified.

Problem identified while looking at better way to check response
on GET_DATA (0xCB) that returns TLV as used in card-piv.c

Changes tested using pkcs11-tool --test --login with PIV, SC_HSM
and OpenPGP cards.
2020-11-25 08:50:13 +01:00
Jakub Jelen 412372b024 tcos: Make sure we have at least two bytes to dive into the cycle 2020-11-18 23:02:34 +01:00
Jakub Jelen 65461e4eb5 authentic: Avoid accessing behind buffers
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26900
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26860
2020-11-18 23:02:34 +01:00
Jakub Jelen 445c651549 authentic: Improve debugging logs 2020-11-18 23:02:34 +01:00
Jakub Jelen c8b2e82713 oberthur: Once again, fix the error check
The shared codition was executed but the condition in LOG_TEST_RET
was not met in case of the acl was null.

Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25962
2020-11-18 23:02:34 +01:00
Jakub Jelen 5eccebb4ee pkcs15-cert: Free memory on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26145
2020-11-18 23:02:34 +01:00
Jakub Jelen b5b1afe401 tcos: Avoid reading behind the end of allocated buffer
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27480
2020-11-18 23:02:34 +01:00
Jakub Jelen d3451faa21 tcos: Reformat insert_key 2020-11-18 23:02:34 +01:00