Commit Graph

7267 Commits

Author SHA1 Message Date
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
Frank Morgner e05574d942 use correct naming scheme for launch agents 2020-11-10 23:23:11 +01:00
Zhang Xiaohui c5508c5eae Add sc_disconnect_card() before exit() and initialize two variables 2020-11-09 10:21:14 +01:00
Zhang Xiaohui e8f27abd02 Add sc_release_context() before exit() 2020-11-09 10:21:14 +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
Carsten Blüggel 8098b7de61 pkcs11-tool: disable wrap/unwrap test until #1796 is resolved 2020-10-27 11:28:40 +01:00
Frank Morgner c621f39034 pkcs11-register: free up memory before exiting 2020-10-27 09:48:02 +01:00
Jakub Jelen 704afd0e2d cac: Use the specific pin change operation only on HID cards 2020-10-24 21:01:18 +02:00
Jakub Jelen 42254ae792 cac: Support changing PIN with CAC ALT tokens 2020-10-24 21:01:18 +02:00
Jakub Jelen 88f3d19479 opensc: Expose iso7816_build_pin_apdu function to support different pin APDUs 2020-10-24 21:01:18 +02:00
Doug Engert ce28ea8162 PIV global pin bug
Fixes #2141

NIST 800-73-3 based cards only had 2 bits set in first pin policy byte.
NIST 800-73-4 defines additions bits in first pin policy byte.
When one of these bit is set, and the policy prefers the Global pin,
it is not recognized and the local pin is used.

 On branch PIV-global-pin-bug
 Changes to be committed:
	modified:   src/libopensc/card-piv.c
2020-10-24 00:54:55 +02:00
w00475903 26a404d6a5 pkcs15-oberthur.c:remove redundant code
Signed-off-by: whzhe <wanghongzhe@huawei.com>
2020-10-16 14:02:56 +02:00
Zhang Xiaohui 0dc3dcbc00 There may be a memory leak in main in /src/tools/sceac-example.c
When failed to access reader, cxt needs to be released before
exiting the program. Like in the patch of CVE-2019-6502, a
sc_release_context(ctx) is needed before line 71, or a
memory leak may occur.
2020-10-16 14:00:23 +02:00
w00475903 7551e14c58 westcos-tool.c:fix memory leaks in dst->modulus.data and dst->exponent.data
Signed-off-by: whzhe <wanghongzhe@huawei.com>
2020-10-14 23:09:36 +02:00
Frank Morgner d0c44b9ddc oberthur: fixed missing error handling
fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25962
2020-10-05 23:18:27 +02:00
Frank Morgner fca2ba9474 oberthur: fixed length checking
fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26116
2020-10-05 08:49:27 +02:00
Jakub Jelen b3501ff669 idprime: Unbreak OS version 2 after key&cert renewal 2020-10-03 01:08:05 +02:00
Frank Morgner 0b40d3b999 idprime: check max. buffer length
fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25998
2020-10-02 13:23:11 +02:00
Frank Morgner 3ff059a74b fixed length checking in oberthur profile
fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25943
2020-10-02 13:23:11 +02:00
Jakub Jelen 732ed77ad6 idprime: Unbreak reading of compressed certificates 2020-09-30 23:13:14 +02:00
Anton Logachev 03396707f0 card-rtecp: Add Rutoken ECP SC NFC ATR 2020-09-30 01:18:50 +02:00
Frank Morgner 3ebfb01a3c itacns: fixed length checking
fixes https://oss-fuzz.com/testcase-detail/5116660103774208
2020-09-29 08:53:16 +02:00
Alexander 7296210224 Hide private objects only when not logged in 2020-09-28 13:01:15 +02:00
Alexander d85610b29b Fixed issue with C_FindObjectsInit, when CKU_SO does not see private objects, but CKU_USER see them 2020-09-28 13:01:15 +02:00
Conrado P. L. Gouvea 40da5cace2 pkcs11-tool: add --allow-sw flag that removes CKF_HW and allows using software tokens 2020-09-28 12:59:58 +02:00
rickyepoderi 57a391f16c Issue 2105: Add new DNIe CA structure for the secure channel 2020-09-26 01:36:55 +02:00
Jakub Jelen b577531720 coolkey: Remove dead code
Thanks coverity

** CID 362100:  Control flow issues  (DEADCODE)
/src/libopensc/card-coolkey.c: 1755 in coolkey_rsa_op()
2020-09-24 08:59:47 +02:00
Jakub Jelen 595926471b itacns: Really do not read behind the buffer bounds
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25885
2020-09-24 08:59:47 +02:00
Doug Engert 6545cd26f4 PIV-update-DOD-Yubikey
Update the ATR table for PIV/CAC matrix to 2019 -10-18 version:
https://www.cac.mil/Portals/53/Documents/DoD%20Token%20utilziation%20and%20variation%20matrix%20v2_06_17October2019.docx?ver=2019-10-18-102519-120

Also update table for several PivKey cards, and added ATR for IDEMIA PIV 2.4.1.
But did not update for use of SM or VCI.

Yubico changed the ATR historical data for Yubikey 5 NFC. Code was added to recognize
it, when used with USB or NFC.

Note: Yubikey 5 NFC  when used with NFC cant use touch policy. NFC reader may not provide
enough power to power the LED on button.

 On branch PIV-update-DOD-Yubikey
 Changes to be committed:
	modified:   card-piv.c
2020-09-24 08:55:01 +02:00
Taylor R Campbell 5a369a8f31 epass2003: Fix erase sequence.
The previous erase sequence did not always work.  For example:

   % pkcs15-init -C
   Using reader with a card: Feitian ePass2003 00 00
   New User PIN.
   Please enter User PIN: 1234
   Please type again to verify: 1234
   Unblock Code for New User PIN (Optional - press return for no PIN).
   Please enter User unblocking PIN (PUK):
   Failed to create PKCS #15 meta structure: Security status not satisfied

   % pkcs15-init -E
   Using reader with a card: Feitian ePass2003 00 00
   Failed to erase card: Security status not satisfied

This apparently bricked many people's ePass2003 devices:

https://github.com/OpenSC/OpenSC/issues/767
https://sourceforge.net/p/opensc/mailman/message/33621883/
https://github.com/OpenSC/OpenSC/wiki/Feitian-ePass2003

Feitian provided a proprietary binary blob called `FIX_TOOL' to recover
devices from this state, but declined to offer source code when asked:

https://download.ftsafe.com/files/ePass/Fix_Tool.tar.gz
https://download.ftsafe.com/files/reader/SDK/Fix_Tool_20200604.zip

With reverse-engineering help by Saleem Rashid (@saleemrashid on
Github), I was able to find the sequence of three APDUs that the tool
submits to the device to erase it.  The mechanism seems to be:

1. Install a magic PIN.  This is like install_secret_key, as used by
   internal_install_pin, but with a few different magic constants.

2. Verify the magic PIN.

3. Delete the MF file, without selecting anything first.

With this patch, `pkcs15-init -E' successfully erases my ePass2003, and
I am able to initialize it with `pkcs15-init -C -p pkcs15+onepin' if I
set both a user pin and a PUK.  (This patch does not prevent the
ePass2003 from getting into the state which could not be erased by the
old erase sequence.)
2020-09-23 08:37:09 +02:00
Jakub Jelen 56acf7b445 oberthur: Do not leak memory on repeated init
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=24518
2020-09-22 23:08:27 +02:00
Jakub Jelen 101e9c720d coolkey: For large data, do not even expect response data
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25708
2020-09-22 23:08:27 +02:00
Jakub Jelen 8dd136ac24 pkcs15-itacns: Do not access behind the allocated buffer boundary
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25473
2020-09-15 12:41:37 +02:00
Jakub Jelen 752c088e10 pkcs15-itacns: Free allocated memory
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25475
2020-09-15 12:41:37 +02:00
Jakub Jelen cf66cf1416 pkcs15-data: Do not fail on zero-lenght data blocks 2020-09-15 12:41:37 +02:00
Jakub Jelen a626c63d91 itacns: Do not leaek memory if file is empty
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25475
2020-09-15 12:41:37 +02:00
Jakub Jelen c07d9ec103 card-authentic: Avoid memory leak
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=24013
2020-09-15 12:41:37 +02:00
Jakub Jelen 460a862ee0 pkcs15-cert: Avoid memory leaks
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=24056
2020-09-15 12:41:37 +02:00
Jakub Jelen 777a9e0386 pkcs15-piv: Make sure we do not leak memory on errors
This replaces all returns from sc_pkcs15emu_piv_init() with goto err
and makes sure all allocated memory is freed on error.

Thanks oss-fuzz

https://oss-fuzz.com/testcase-detail/6243443299581952
2020-09-15 12:41:37 +02:00
Jakub Jelen 209d28a63f pkcs15-cert: Improve logging 2020-09-15 12:41:37 +02:00
Jakub Jelen 238b783a0e card-asepcos: Fix heap-buffer overflow
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=24940
2020-09-15 12:41:37 +02:00
Jakub Jelen 94d67bed81 npa: Free allocated apps in match function
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23977
2020-09-15 12:41:37 +02:00
Jakub Jelen d743a347d7 coolkey: Avoid memory leak when processing multiple combined objects
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=24023
2020-09-15 12:41:37 +02:00
Jakub Jelen dce4ad1aa2 coolkey: Avoid bogus check before free 2020-09-15 12:41:37 +02:00
Jakub Jelen 71876042bd oberthur: Do not leak memory on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=24518
2020-09-15 12:41:37 +02:00
Jakub Jelen a1d35518dd CID 357984: Avoid casting signed integer to unsigned before checking its value 2020-09-15 12:41:37 +02:00
Jakub Jelen 34a5a80870 CID 360515: Avoid dereferencing null pointer crypt_out_p.
Thanks coverity and oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23976
2020-09-15 12:41:37 +02:00
Zoltan Kelemen 7c8c77cf1f Corrected highly misleading, confusing and ambiguous use of PIN length_offset
field. Now only the PIN offset fields are used.

This change synchronizes the code with similar changes in reader-pcsc.c
(commit eb3e00a385).
2020-09-04 12:28:24 +02:00
Raul Metsma 57f37ffd8d Remove unused and broken RSA EstEID support
Signed-off-by: Raul Metsma <raul@metsma.ee>
2020-09-02 11:21:33 +02: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
Ludovic Rousseau 3168f48503 Fix spelling error in comments 2020-08-29 23:22:34 +02:00
Ludovic Rousseau e1353c0488 Fix spelling error
Thanks to Debian lintian:
I: opensc-pkcs11: spelling-error-in-binary
usr/lib/x86_64-linux-gnu/libopensc.so.6.0.0 certificat certificate
2020-08-29 23:19:37 +02:00
Ludovic Rousseau 7fc00a1178 Fix spelling error
Thanks to Debian lintian:
I: opensc: spelling-error-in-binary usr/bin/netkey-tool conatin contain
I: opensc: spelling-error-in-binary usr/bin/piv-tool conatin contain
2020-08-29 23:17:02 +02:00
Peter Marschall 4dbfc77eba opensc-explorer: extend do_asn1() to accept offsets
Have do_asn1() accept an optional parameter indicating an offset.
If this is given then start ASN.1-decoding the file/record at this offset.
2020-08-23 22:46:26 +02:00
Peter Marschall 45e7039940 opensc-explorer: extend do_asn1() to decode records
Have do_asn1() accept an optional parameter indicating a record number.
If this is given and the file is a record-oriented file, then ASN.1-decode
the record requested.
2020-08-23 22:46:26 +02:00
Peter Marschall d345c65a5d opensc-explorer: extend do_cat()
Have do_cat() accept an optional second parameter indicating a record number.
If this is given and the file is a record-oriented file, only print the record
requested.
2020-08-23 22:46:26 +02:00
Zoltan Kelemen f0b157b8e7 Improved comments for PIN cmd structures. 2020-08-19 10:01:58 +02:00
Zoltan Kelemen 11adcfca99 Removed 'acls' from the public interface in 'sc_pin_cmd_pin' since it is not
supported by most of the card drivers and can therefore not be regarded to be
part of the public interface.

Modified the only remaining card driver that used it (authentic) to store acls
in a private variable.
2020-08-19 10:01:58 +02:00
Zoltan Kelemen 6e3e81a9f4 Remove unused stored_length field. 2020-08-19 10:01:58 +02:00
Zoltan Kelemen 48d939b057 Removed length_offset since it is not used any more. 2020-08-19 10:01:58 +02:00
Zoltan Kelemen aca0d08e29 Removed the 'crts' field from 'sc_acl_entry' type since:
- its definition is specific to the IAS-ECC card type
- its presence can not be assumed since it is read from non-mandatory SE type of an SDO
- it is currently not used anywhere in the code
2020-08-19 10:01:58 +02:00
Peter Marschall 376cc2d910 iso7816: set record_length for any record-oriented EF 2020-08-19 09:58:12 +02:00
Jakub Jelen cdbcb5b7db coolkey: Fix AddressSanitizer: stack-use-after-scope
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23979
2020-08-04 13:11:55 +02:00
Peter Marschall 8963c35189 pkcs15-sc-hsm: use correct name for EF.CDF 2020-08-03 15:34:22 +02:00
Peter Marschall 07e98b5193 pkcs15-sc-hsm: fix commit c4d7bb1
Set the trigger for LOG_TEST_RET() to a negative value if obj.data == NULL.
2020-08-03 15:34:22 +02:00
Frank Morgner 978c912c70 fixed Heap-buffer-overflow READ
7cf8087351 seemed to be incomplete. Change
the length of the buffer right before it's accessed.

fixes https://oss-fuzz.com/testcase-detail/5734055866531840
2020-07-30 02:40:02 +02:00
Frank Morgner 6903aebfdd Heap-buffer-overflow WRITE
fixes https://oss-fuzz.com/testcase-detail/5088104168554496
2020-07-30 02:27:02 +02:00
Julian Strobl 9ffb9bae63 tcos: add missing encryption certificates 2020-07-30 02:00:15 +02:00
Zoltan Kelemen 2b78374e37 Print error message for the case that a PUK object is not available for a PIN
during an unblock operation (this is a sign of a card with invalid PKCS #15
info). Without this error message the program just terminates silently, which
is confusing to the user.
2020-07-22 22:58:57 +02:00
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 bad74e1ed6 Enabled code for using PUK reference for PIN unblock, when available. 2020-07-22 22:57:23 +02:00
Zoltan Kelemen 998284dd1c Removed unused define. 2020-07-22 22:57:23 +02:00
Zoltan Kelemen ba76bc0239 Improved syntactic readability without any change in functionality. 2020-07-22 22:57:23 +02:00
Zoltan Kelemen c903ddfce1 Fixed bounds checking and enabled the function again. 2020-07-22 22:57:23 +02:00
Zoltan Kelemen 163b69e6a7 Change ADF selection to return FCP for Oberthur cards. No need to simulate
since it is supported.
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 3331a7f134 Fix MF selection APDU to use 0x0c in P2 (no data). The previous value of 0x00
is invalid according to IAS-ECC and resulted in 6A 86 on the Oberthur
cards that we tested with.
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 471468260e Improved PIN unblock function:
- Uses PIN padding from merged policy
- Added PIN-pad support
- Use ISO 7816 layer to avoid code duplication
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 79e81eeef0 Improved PIN change function:
- Uses PIN padding from merged policy
- Improved PIN-pad logic and merged here from separate function
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 5ae488c1b9 Improved PIN verification function:
- Uses PIN padding from merged policy
- Moved PIN-pad logic into this function instead of keeping separate
2020-07-22 22:57:23 +02:00
Zoltan Kelemen d0b3e90431 Simlified low-level CHV verification function:
- Removed special PIN-pad case, moving logic into high-level function.
- Use ISO 7816 layer to avoid code duplication.
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 8c2d629f94 Functions used to control PIN padding and PIN pad use:
- Use PIN padding information when provided by upper layers
- Enable PIN padding at card level when min/max len set to same, nonzero value
- Allow PIN-pad use to be dynamically selected for each PIN
2020-07-22 22:57:23 +02:00
Zoltan Kelemen ca911e342c Improved PIN info retrieval, now returning verification status, and attempts
left even when previously not available (due to card not providing it in the
SDO).
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 19063932f0 Simplified PIN policy retrieval to only read the data that is actually needed,
excluding the CRT info from the SE-SDO, which is not guaranteed to be
available in all card types.

Use an explicit PIN policy structure type instead of keeping the info in the
sc_pin_cmd_data, since this type of info is only used privately in the card
driver.
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 741ee73ec9 Add generic function for PIN status retrieval, for subsequent use (among
others intended to replace iasecc_pin_is_verified).

Base it on functionality in the ISO 7816 layer to avoid code duplication.
2020-07-22 22:57:23 +02:00
Zoltan Kelemen 7ed876c816 Added ATR mask for Idemia (Oberthur) IAS-ECC card to recognize Cosmo V8 cards. 2020-07-22 22:57:23 +02:00
Zoltan Kelemen eb3e00a385 Corrected highly misleading, confusing and ambiguous use of PIN length_offset
field. Now only the PIN offset fields are used. Also added error checking for
invalid values.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen 80853bda31 Only enable static frame size for PIN padding when padding length is below
maximum limits. Otherwise resort to adaptive support.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen afffeccc29 Fixed problems with PIN min/max length handling:
- The wrong PIN was selected from the sc_pin_cmd_data structure.
- When the PIN max value was zero from the caller (meaning unknown max), the
  reader max value was not used.
2020-07-22 22:56:09 +02:00
Zoltan Kelemen 1dc359cb61 Fix for issue #1999:
- Reset context to undefined handle value on error since call may alter
  output parameter.
- Continue to assume -1 as undefined handle value in all PCSC
  implementations, to keep this fix as small and surgical as possible.
2020-07-22 22:55:30 +02:00
Jakub Jelen b16a5cbee0 pkcs15: Free app info when allocating new and in cleanup
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23746
2020-07-07 16:21:21 +02:00
Jakub Jelen c82aa92687 pkcs15: Clean memory on alocation failure 2020-07-07 16:21:21 +02:00
Jakub Jelen 2d6de2510c pkcs15: Drop bogus checks 2020-07-07 16:21:21 +02:00
Jakub Jelen 4c473fba29 authentic: Clean private data on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23786
2020-07-07 16:21:21 +02:00
Jakub Jelen 05dcde508b authentic: Use memmove as the memory can overlap (if path is > 2B)
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23787
2020-07-07 16:21:21 +02:00
Jakub Jelen 5098cfdb40 authentic: Do not leak memory on fail path
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23788
2020-07-07 16:21:21 +02:00
Jakub Jelen 7cf8087351 asepcos: Avoid heap-buffer-overflow
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23529
2020-07-07 16:21:21 +02:00
Jakub Jelen c4d7bb1a7b Do not crash on if private certificate is ignored (#2057) 2020-07-07 16:21:21 +02:00
Jakub Jelen 43379b3b22 coolkey: Rewrite coolkey_rsa_op() for better readability 2020-07-07 16:21:21 +02:00
Jakub Jelen 0cda376dba pkcs15-pubkey: Make sc_pkcs15_pubkey_from_spki_fields more robust against errors
Original patch from Douglas E Engert <deengert@gmail.com>
2020-07-07 16:21:21 +02:00
Jakub Jelen e759b17b66 pkcs15-pubkey: Avoid memory leaks when spki parsing fails
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22189
2020-07-07 16:21:21 +02:00
Jakub Jelen 56f4c6c34a piv: Free pubkey on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22297
2020-07-07 16:21:21 +02:00
Jakub Jelen 3696331d5c Remove more needless checks for NULL before free 2020-07-07 16:21:21 +02:00
Jakub Jelen fea08d749d coolkey: Avoid memory leak
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23251
2020-07-07 16:21:21 +02:00
Jakub Jelen 97ec23a2d9 pkcs11: Propagate ignore_user_consent
If user consent is ignored through configuration, do not present
ALWAYS_AUTHENTICATE=TRUE attribute in PKCS#11

Fixes #2039
2020-07-03 17:55:24 +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
Zoltan Kelemen bf30d64cf9 Fixes build error in opensc-notify (issue #2068). 2020-07-02 13:20:01 +02:00
René Liebscher 223a0949e8 Add sc_free()
For more details see https://github.com/OpenSC/OpenSC/issues/2054
2020-06-22 10:47:59 +02:00
René Liebscher 4d96fbfed4 Remove compiler warnings/errors
Recent compilers have activated some additional
checks which let the build fail. (at least with cygwin)
(Normally it would be warnings but opensc compiles
with -Werror)

GCC 9.3:
In file included from profile.c:27:
profile.c: In function '__expr_get':
profile.c:2273:18: error: array subscript has type 'char' [-Werror=char-subscripts]
 2273 |   while (isspace(*s))
      |                  ^~

clang 8.0.1:
compat_getopt_main.c:102:22: error: array subscript is of type 'char' [-Werror,-Wchar-subscripts]
                rc = toupper(rc);
                     ^~~~~~~~~~~
/usr/include/ctype.h:161:25: note: expanded from macro 'toupper'
      (void) __CTYPE_PTR[__x]; (toupper) (__x);})
                        ^~~~

Actually the code is correct as isspace and others
are used here with data type char, and are to be used
with data type int.

So either the compiler should have deactivated
this error, or the ctype.h macros have to be
written so the compiler no longer complains.

As there is also a simple workaround by casting
char to unsigned char, there is no need to wait for one
of the former options to be happen sometime.
2020-06-22 10:47:02 +02:00
Jakub Jelen 7ae74c524f piv: Avoid accessing memory after zero-length tags
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23215
2020-06-09 13:02:27 +02:00
Jakub Jelen 5e7d4fb8ba oberthur: Avoid memory leaks
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23126
2020-06-09 13:02:27 +02:00
Jakub Jelen 0a34d11cb7 oberthur: Avoid memory leaks on error paths 2020-06-09 13:02:27 +02:00
Jakub Jelen 62403eec34 tcos: Use memset instead of for cycle 2020-06-09 13:02:27 +02:00
Jakub Jelen 9dd3370673 oberthur: Fix operator precedence
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22665
2020-06-09 13:02:27 +02:00
Jakub Jelen a5f04188bc pteid: Do not overwrite already set information in tokeninfo
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22578
2020-06-09 13:02:27 +02:00
Jakub Jelen f49162af04 Avoid memory leaks when initializing tokeninfo in various drivers
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22578
2020-06-09 13:02:27 +02:00
Jakub Jelen 71d1f69a3a Reformat tcos_compute_signature() for better readability 2020-06-09 13:02:27 +02:00
Jakub Jelen e6848b6d88 tcos: Yet anoter buffer underflow as previous 2020-06-09 13:02:27 +02:00
Jakub Jelen fa719b301f tcos: Prevent buffer underflow
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22995
2020-06-09 13:02:27 +02:00
Jakub Jelen d141b35596 tcos: Rewrite assert to explicit check 2020-06-09 13:02:27 +02:00
Jakub Jelen 1819ca33d6 tcos_decipher: Reformat to improve readability 2020-06-09 13:02:27 +02:00
Jakub Jelen 53395f4075 tcos: Replace assert with explicit check
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22999
2020-06-09 13:02:27 +02:00
Jakub Jelen 8940ed5d85 tcos: Avoid memory leak on invalid inputs
(make sure the pointer is initialized)

Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22765#c2
2020-06-09 13:02:27 +02:00
Jakub Jelen b418601942 pkcs11-spy: Dump slot id for C_WaitForSlotEvent 2020-06-09 13:02:27 +02:00
Frank Morgner 36247d85b0 pkcs11: fixed notifying twice in case of an attached reader
before 14e396273 sc_wait_for_event() only notified in case of a new
reader, but didn't add it to the internal list of readers. That's why
PKCS#11 needed to bail out early in this case (and the application had
to call C_WaitForSlotEvent a second time to actually get the related
slot). Since sc_wait_for_event() can now handle insertion correctly, we
can now immediately check (and reset) the events on the slots.
2020-06-09 12:07:04 +02:00
Frank Morgner 1c7b311289 pcsc: immediately exit on hotplug events
fixes delayed notification for removed readers

closes https://github.com/OpenSC/OpenSC/issues/2021
2020-06-09 12:07:04 +02:00
Frank Morgner 8f6e5dc2b0 Unbreak wait for events
By Jabuk Jelen

Fixes https://github.com/OpenSC/OpenSC/issues/2021
2020-06-09 12:07:04 +02:00
Frank Morgner 1bb2547abc respect PKCS#11 allowed return values 2020-06-08 14:18:23 +02:00
Frank Morgner 6a6b3e4b62 prevent memory leak 2020-06-08 14:18:23 +02:00
Frank Morgner 58b03b68dd check for unbound cards
closes https://github.com/OpenSC/OpenSC/pull/2045
2020-06-08 14:18:23 +02:00
Luka Logar a10b661f99 IsoApplet: Fix uninitialized public key oid during key generation 2020-06-05 14:48:50 +02:00
Peter Marschall ca5f5c8844 explorer: set stdout to O_BINARY in Windows where needed 2020-06-05 14:48:08 +02:00
Peter Marschall 5714dbfa08 opensc-explorer: add function 'get_record' 2020-06-05 14:48:08 +02:00
Peter Marschall f55c4e5c93 opensc-explorer: extend path_to_filename()
Expect a record number as 3rd parameter:
if this record number is greater than 0, indicating a single record,
then append the record number to the file name being constructed.
2020-06-05 14:48:08 +02:00
Frank Morgner 180c57fd15 fixed compiler warning 2020-06-05 09:43:38 +02:00
Frank Morgner 0f0e0b2e30 prevent out of bounds read
fixes https://oss-fuzz.com/testcase-detail/5769298181357568
2020-06-05 08:31:19 +02:00
Frank Morgner 9d294de90d prevent out of bounds write
fixes https://oss-fuzz.com/testcase-detail/5226571123392512
2020-06-04 10:04:10 +02:00
Frank Morgner 55fd3db2b5 prevent integer underflow and subsequent heap overflow
fixes https://oss-fuzz.com/testcase-detail/5666689944649728
2020-06-04 09:47:22 +02:00
Frank Morgner 4bc03cb55d fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5113223765557248
2020-06-04 00:13:57 +02:00
Feitian Technologies f334f3eabe
Bug fixed (#1859)
* Bug fixed

1. It solves the problem that can be signed without input PIN, and new code will check the state that the PIN value
2. The algorithm fails to verify sha256, cause signature failure
3. The format of distinguishing ECC and RSA key pair is added - after the key pair is generated successfully, ECC and RSA need to be distinguished when reading the public key. The return format of ECC is different from the RSA
4. Fix ECC information display bug - The problem is using pkcs15-tool -D to print ECC key pair information no display correctly
5. Modify the module attribute of generating ECC key pair, and add 0x04 flag according to pkcs11 standard
2020-06-03 14:54:39 +02:00
Jakub Jelen 16456922e2 pkcs11: Return CKR_TOKEN_NOT_RECOGNIZED for not recognized cards
Fixes #2030
2020-05-30 16:00:04 +02:00
Jakub Jelen e8a2644435 Remove duplicate condition
Thanks coverity
2020-05-29 09:57:39 +02:00
Jakub Jelen 38474739b3 card-cardos: Fix NULL dereference
Thanks coverity
2020-05-29 09:57:39 +02:00
Frank Morgner 0a17188710 fixed out of bounds read
fixes https://oss-fuzz.com/testcase-detail/5769032858075136
2020-05-24 23:47:29 +02:00
Piotr Majkrzak d4a9405bf4
Initial support for Polish eID card (e-dowód, eDO) (#2023) 2020-05-19 14:05:13 +02:00
Frank Morgner ed55fcd299 fixed invalid read
fixes https://oss-fuzz.com/testcase-detail/5765246676631552
2020-05-18 17:25:32 +02:00
Frank Morgner 96a7eca99a fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5633315576217600
2020-05-18 17:13:48 +02:00
Frank Morgner 4cb9788b99 fixed invalid read
fixes https://oss-fuzz.com/testcase-detail/5726023753924608
2020-05-18 16:45:24 +02:00
Frank Morgner 7e1679b2db fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5675417580339200
2020-05-18 16:38:43 +02:00
Torin Carey 93bed892a8 tests: Fix card present check
Check SC_READER_CARD_PRESENT flag rather than == 1.
Having no card present on the first loop and then inserting a card will
return rc = CARD_PRESENT | CARD_CHANGED (= 3). SEGFAULT ensures when we mistake
the unset opt_reader as having a present card.
2020-05-18 16:30:15 +02:00
Jakub Jelen 27a819baa7 framework-pkcs15: Do not leak memory (CID 139147) 2020-05-13 21:54:16 +02:00
Jakub Jelen 19791f63d5 piv: Avoid cast ignoring errors (CID 357984)
Thanks coverity
2020-05-13 21:54:16 +02:00
Jakub Jelen 787c32d195 piv: Avoid cast to unsigned ints to properly check for errors (CID 357985)
Thanks coverity scan
2020-05-13 21:54:16 +02:00
Frank Morgner d8734baf83
Merge pull request #1924 from frankmorgner/recursion
avoid calling sc_*_binary recursively
2020-05-13 00:27:42 +02:00
Doug Engert 4ebb29ce4d card-piv.c error in using sc_asn1-put-tag
In piv_general_mutual_authenticate sc_asn1_put_tag is not used correctly.

 On branch piv-sc_asn1_put_tag-error
 Changes to be committed:
	modified:   card-piv.c
2020-05-13 00:26:18 +02:00
Frank Morgner 4e9cec1a64 fixed missing includes 2020-05-11 18:58:12 +02:00
Frank Morgner a7d563b657
Merge branch 'master' into recursion 2020-05-11 18:45:36 +02:00
Frank Morgner 0dcb910289 fixed "libtool: compile: unable to infer tagged configuration" 2020-05-11 18:41:16 +02:00
Frank Morgner 178c4a9eaa fixed checking for strlcat/strlcpy
newer clang uses a definition rather than a function
2020-05-11 18:41:16 +02:00
Frank Morgner c1eda42099 oberthur: fixed current file state handling
fixes https://oss-fuzz.com/testcase-detail/5644083327664128
2020-05-10 01:14:00 +02:00
Frank Morgner 7add7e9ded fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5738653415636992
2020-05-10 01:01:34 +02:00
Michael Weiser a49a64ec79 unittests: Fix out-of-source build
Commit 4fd34e28ea unintentionally replaced top_builddir with
top_srcdir when refactoring flags variables in Makefile.am. This causes
out-of-source builds to fail.

Restore top_builddir in LDADD.

Also, remove a superfluous -L flag also referencing top_srcdir from
AM_CFLAGS while at it.

Signed-off-by: Michael Weiser <michael.weiser@gmx.de>

Closes #2027.
2020-05-10 00:01:27 +02:00
Doug Engert db41cd9ab1 Various CardOS V5_* improvements
Treat CardOS V5_0 and V5_3 cards differently then older versions:

Use card->dvr_data as a pointer to cardos_data_t to store private driver
data to pass internally, especially between set security environment
and the crypto operations. Sc_get_encoding_flags sets sec_flags from
algo_info->flags in pkcs15-sec.c and it passed to decipher.

Some cards when doing a decipher may drop leading 00 byte when
returning data from RSA_RAW decipher. Add leading byte(s) as needed.

Get Cryptographic Mechanism Reference from Key Reference:

Key reference byte appears to be a 4 bit Cryptographic Mechanism Reference
and a 4 bit key reference.

This is only done if key reference & 0xF0 != 0  i.e. default Cryptographic
mechanism reference is 0. which appears to be the case for RSA RAW.
PKCS1 appears to be 0x10 and ECDSA 0x30

    See iso 7816-4 table 55 for DST:
      84 Reference of a private key
      95 Usage qualifier byte - Table 57 - 40 looks OK
      80 Cryptographic mechanism reference and referes to section 9.2

The 4 bit key reference limits card to 16 keys. In future this may not work,
but we can derive a Cryptographic Mechanism Reference from what OpenSC
thinks the card needs to do. Only know RSA RAW, PKCS1 and ECDSA.

ECDSA code has not been tested, but expected to work.

Allow setting CardOS type and flags from opensc.conf using card_atr stanza
This is a fallback if newer cards are added or older cards have problems
giving us time to make need changes in next release.

It will help in identifying what flags are needed for each card.
As user can report what combination of flags work for them. They do this by
adding to opensc.conf with something like this. (Change the ATR to your card's ATR):

        card_atr 3b:d2:18:00:81:31:fe:58:c9:03:16 {
                driver = "cardos";
                # type is decimal from cards.h:
                # SC_CARD_TYPE_CARDOS_V5_0 is 1009
                # SC_CARD_TYPE_CARDOS_V5_3 is 1010
                type = 1010;

                # flags is hex from opensc.h:
                #define SC_ALGORITHM_ONBOARD_KEY_GEN    0x80000000
                #define SC_ALGORITHM_NEED_USAGE         0x40000000

                #define SC_ALGORITHM_RSA_RAW            0x00000001 /* RSA_RAW is PAD_NONE */
                #define SC_ALGORITHM_RSA_PAD_NONE       0x00000001
                #define SC_ALGORITHM_RSA_PAD_PKCS1      0x00000002 /* PKCS#1 v1.5 padding */
                #define SC_ALGORITHM_RSA_PAD_ANSI       0x00000004
                #define SC_ALGORITHM_RSA_PAD_ISO9796    0x00000008
                #define SC_ALGORITHM_RSA_PAD_PSS        0x00000010 /* PKCS#1 v2.0 PSS */
                #define SC_ALGORITHM_RSA_PAD_OAEP       0x00000020 /* PKCS#1 v2.0 OAEP */
                #define SC_ALGORITHM_RSA_HASH_NONE      0x00000100 /* only applies to PKCS1 padding */
                # example: SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_HASH_NONE |  SC_ALGORITHM_RSA_RAW
                flags = 80000101;
                #example: SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_PAD_PKCS1
                flags = 80000002;
        }

For V5_0 and v5_3 cards, use sc_get_max_send_size and sc_get_max_recv_size
which takes care or reader sizes even on Windows where SCardControl can not get PART_10 sizes.

(commit eddea6f3c2 on Windows forces reader sizes to 255, 256
in reader-pcsc.c if not already set. It should not do this, but leave that up to card drivers.)

pkcs15-cardos.c added:

New file, pkcs15-cardos.c, added as emulation only for CardOS
V5_0 and V5_3 cards.

sc_pkcs15_bind_internal is called to get tokenInfo as CardOS
cards are substantially PKCS15 cards. But some V5_* cards have
errors in the tokenInfo, Which are corrected.

For older CardOS cards, card-cardos.c will create all the
card->algorithms.

Pkcs15-cardos.c will check for card->algorithms and if there
are none, it will do the following:

SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS is called twice. First to get
the flags as set by user via opensc.conf card_atr or default
flags set by the card driver.  Then after determining from the
tokenInfo what algorithms the card can support, the new flags
are passed to card_cardos.c to create card->algorithms.

https://atos.net/wp-content/uploads/2018/11/CT_181026_LPM_CardOS_V5-3_Multifunctionality_FS_en3_web.pdf
says card supports: "“Command chaining” in accordance with ISO/IEC 7816-4"

To take advantage of this with older readers, max_send_size and max_recv_size
is now based on minimum of reader limits and  "data_field_length" from card.
This should allow card to work in older readers not capable of extended APDU.
So far current cards we have seen do no appear to support “Command chaining”.

 Changes to be committed:
	modified:   src/libopensc/Makefile.am
	modified:   src/libopensc/Makefile.mak
	modified:   src/libopensc/card-cardos.c
	modified:   src/libopensc/cardctl.h
	modified:   src/libopensc/cards.h
	new file:   src/libopensc/pkcs15-cardos.c
	modified:   src/libopensc/pkcs15-syn.c
	modified:   src/libopensc/pkcs15-syn.h
2020-05-09 23:59:51 +02:00
Doug Engert 8a5a1435f1 pkcs15-tool.c - print Supported_algorithms from tokenInfo
Some cards can provide supported algorithms in tokenInfo
which contain ECDSA OID, and PKCS11 mechanism

Don't know how many Algo_refs were actually read,
and a ref of 0 may be valid. print at least one Algo_refs.

Print the mechanism from PKCS11, and print operations
Use the $(top_srcdir)/src/pkcs11/pkcs11-display.c  on Unix
Use the $(TOPDIR)\src\pkcs11\pkcs11-display.obj on Windows

pkcs15.tool.c treat ECDSA OID as inline

pkcs15-tool prints PKCS11 mechanisms using pkcs11-display.c
Automake now warns that the default will change, in the future
so "[subdir-objects]" is added to configure.ac

 Changes to be committed:
	modified:   configure.ac
	modified:   src/tools/Makefile.am
	modified:   src/tools/Makefile.mak
	modified:   src/tools/pkcs15-tool.c
2020-05-09 23:59:51 +02:00
Doug Engert c03efeee40 sc_supported_algo_info - Put ECDSA OID as inline
Mismatch of ASN1 parsing of tokeninfo.supported_algos[n].paramters
    in one place parameter was treated as a pointer to sc_object_id
    and in another as inline structure. This caused segfaults
    in pkcs15-tool when it tried to print the OID.

 Changes to be committed:
	modified:   src/libopensc/opensc.h
	modified:   src/libopensc/pkcs15.c
2020-05-09 23:59:51 +02:00
Doug Engert 3f21dc57b7 Increase SC_MAX_SUPPORTED_ALGORITHMS from 8 to 16
CardOS cards may have more then 8 supported_algo_info entries in tokenInfo.
We may bemissing some. We have seen 8 in some pkcs15-tool -i -v output.

Simple fix is to incrase the limit. More appropriate fix is to remove the limit,
much like is done with sc_algorithm_info. and use realloc of the array.

 On branch cardos-5.3
 Changes to be committed:
	modified:   src/libopensc/pkcs15-prkey.c
	modified:   src/libopensc/pkcs15-skey.c
	modified:   src/libopensc/pkcs15.c
	modified:   src/libopensc/types.h
2020-05-09 23:59:51 +02:00
Doug Engert f5fe292ae1 pkcs11-tool - use valid data for decription tests
In tests, make sute test data is either padded, or "zero" padded
so size if data <=  modlen - 11. The smallest pad in 11 bytes,
00 | NN | PS | 00. PS is at least 8 bytes.
"zero" padding has N = 00, PS >= 8 byte of 00.

 On branch cardos-5.3
 Changes to be committed:
	modified:   tools/pkcs11-tool.c
2020-05-09 23:59:51 +02:00
Doug Engert 52d5370c1e asn1.c don't use strict mode
see:
https://github.com/OpenSC/OpenSC/issues/1995#issuecomment-607490809

 On branch cardos-5.3
 Changes to be committed:
	modified:   asn1.c
2020-05-09 23:59:51 +02:00
Jakub Jelen 0a057a976d Fix typo arguement -> argument in documentation 2020-05-07 02:34:12 +02:00
Jakub Jelen ddc049e37b Remove bogus file from tools directory 2020-05-07 02:34:12 +02:00
Jakub Jelen d1457e9fa3 coolkey: Drop dead code (CID 351911)
default branch of the switch calls continue, preventing
going out of the loop without obj_info set.
2020-05-07 02:32:46 +02:00
Jakub Jelen 295f399304 reader-pcsc: Avoid use after free (CID 355473) 2020-05-07 02:32:46 +02:00
Jakub Jelen 71998501f2 piv: Replace internal implementation of put_tag with asn1
The asn1 implementation is simpler and has more throughout error and
buffer overflow checking.

Fixes #1394
2020-05-07 02:32:46 +02:00
Jakub Jelen 4c4237f8a3 tests: Cover asn1_put_tag() 2020-05-07 02:32:46 +02:00
Jakub Jelen 508f8a9fce iso7816: Do not recurse if no data was returned
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20399
2020-05-07 02:32:46 +02:00
Jakub Jelen 84ee2be122 framework-pkcs15: Copy pubkey to avoid double free 2020-05-07 02:32:46 +02:00
Jakub Jelen 75be610ea0 pkcs15: Clean memory if it was not transfered to framework-pkcs15 2020-05-07 02:32:46 +02:00
Jakub Jelen 127c8d911f pkcs15-pubkey: Avoid memory leaks when ec_params are already initialized from pkcs15-algo 2020-05-07 02:32:46 +02:00
Jakub Jelen b76e08504a piv: Fix indentation 2020-05-07 02:32:46 +02:00
Jakub Jelen ed06787b5e oberthur: Avoid memory leak when the auth_init is called multiple times
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21678
2020-05-07 02:32:46 +02:00
Frank Morgner 1202eceeef fixed wrong error 2020-04-29 15:16:31 +02:00
Frank Morgner 7936bdef15 resolve unused variable warning on newer gcc 2020-04-29 01:25:33 +02:00
Vladimir Panteleev bb47c1a5d0 pkcs11-tool: Fix mismatched --help text
The addition of --usage-wrap did not add a corresponding help string,
which caused all help text for the options below it to be shifted by one.
2020-04-23 14:54:46 +02:00
Frank Morgner 3124d9f6fb
Merge pull request #1821 from alex-nitrokey/ecc-fixes
openpgp: Fixes for importing ECC keys
2020-04-23 13:35:59 +02:00
Frank Morgner 843779fe6e opensc-notify: respect signal safety
Thanks, Marcin.
5e79a2a4ab (r38486829)
2020-04-23 08:45:24 +02:00
Frank Morgner 5e79a2a4ab fixed compiler warning 2020-04-09 16:29:44 +02:00
alex-nitrokey 27ea7cc6ac
Merge branch 'master' of https://github.com/OpenSC/OpenSC into ecc-fixes 2020-04-09 10:25:00 +02:00
Lars Silvén 8257e0186d The PKCS#11 specifies that the PIN parameter(s) in C_Login and C_SetPIN
always should be used, even if a PIN pad reader is used. PIN must only
be fetched from the PIN pad reader if the corresponding parameter is
null.
Before this commit PIN was always fetch from the reader if the PIN could
be fetched from the reader.
The 'pkcs11-tool has also been updated. Before parameters was never
taken from the command line if a PID pad reader was used. Now PINs from
the command line is always used but if not existing the PIN is fetched
from the reader if a reader with a PIN pad is used, otherwise the user
is prompted for PIN(s) from the CLI.
2020-04-08 09:54:07 +02:00
Lars Silvén a771450ab2 From the PKCS#11 specification chapter C_SetPIN:
C_SetPIN modifies the PIN of the user that is currently logged in, or
the CKU_USER PIN if the session is not logged in. ....

This was not true for "if the session is not logged in" before this fix.
2020-04-08 09:54:07 +02:00
Frank Morgner f9b31e50dd iso-sm: fixed too short response APDU data length
one byte off error in calculation of ASN.1 length
2020-04-08 02:13:24 +02:00
Frank Morgner 2c26b7392d opensc-notify: handle reader insertion/removal events
- If readers are attatched, the new reader is probed for a card to check
if a notification needs to be sent
- removal of readers are not notified to the user, we assume that PC/SC
sends the correct card removal event
- The list of readers to be monitored is adjusted once a reader (dis)appears
- On macOS, without PnP notification, we always check for new/removed
readers with SCardListReaders
- fixes interrupt handling in opensc-notify on Unix

fixes https://github.com/OpenSC/OpenSC/issues/1874
2020-04-06 18:08:34 +02:00
Jakub Jelen 7893d2860c idprime: Fix null-dereference
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21586
2020-04-06 17:56:28 +02:00
Jakub Jelen 1ddef2cd15 iasecc: Avoid memory leak on error
Thanks oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21297
2020-04-06 17:56:28 +02:00
Marcin Cieślak 768bd1dde7 Check if we HAVE_ENDIAN_H
BSDs will have <sys/endian.h>, Linux just <endian.h>
2020-04-03 09:52:08 +02:00
alex-nitrokey 7ba89620bf
refactoring: get rid of oid_binary in ec_tables 2020-03-24 12:09:06 +01:00
Frank Morgner 7840804762 fixed typo
fixes coverity's: "Argument cannot be negative (NEGATIVE_RETURNS)"
2020-03-21 16:47:43 +01:00
Frank Morgner d5ecafc334 fixed memory leak
fixes https://oss-fuzz.com/testcase-detail/5084702283399168
2020-03-20 17:12:18 +01:00
alex-nitrokey 0ba44cbec6
Add length checking 2020-03-19 13:31:31 +01:00
Alexander Paetzelt e45712bd29
Merge branch 'master' into ecc-fixes 2020-03-19 11:54:18 +01:00