Commit Graph

3128 Commits

Author SHA1 Message Date
Jakub Jelen 9b4e00b24b gp.c: Properly check the SWs of the APDU when selecting AID 2018-05-18 23:52:01 +02:00
Jakub Jelen b6e08e008e Move the Global Platform related commands to separate file and port existing code to that 2018-05-18 23:52:01 +02:00
Jakub Jelen 8d4fbc34c3 coolkey: Make uninitialized cards working as expected with ESC
Original patch from John Magne <jmagne@redhat.com>
2018-05-18 23:52:01 +02:00
Jakub Jelen 58aeb62573 OPENSC_DRIVER: restrict driver list instead of forcing one (#1277)
Using the forced-driver prevents parsing of additional constructions
in configuration files (for example flags based on ATRs). This
implementation replaces transparently the existing list defined in
card_drivers.

Resolves: #1266
2018-05-18 23:50:26 +02:00
Frank Morgner c463985fed
Removed code for obsolete cards from D-Trust (#1261) 2018-05-18 23:49:59 +02:00
Frank Morgner 439a95f2d2
If card initialization fails, return SC_ERROR_INVALID_CARD (#1251)
fixes https://github.com/OpenSC/OpenSC/issues/946
2018-05-18 23:49:29 +02:00
Frank Morgner ae31408f81 fixed checking SW in iso7816_read_binary_sfid
fixes https://github.com/OpenSC/OpenSC/issues/1360
2018-05-18 23:39:16 +02:00
Alon Bar-Lev 62de900b1a build: fix --disable-sm 2018-05-18 23:20:21 +02:00
Florian Bezdeka af72682072 Fixed gcc 8 compilation errors (#1353)
The following errors occured during a compilation using gcc 8:

In function »gids_create_file.constprop«,
    inserted by »gids_save_certificate.isra.8« beicard-gids.c:1548:7:
card-gids.c:465:2: Error: »strncpy« output may be truncated copying 8 bytes from a string of length 8 [-Werror=stringop-truncation]
  strncpy(record->filename, filename, 8);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pkcs15-oberthur.c: In function »sc_pkcs15emu_oberthur_add_prvkey«:
pkcs15-oberthur.c:741:5: Error: »strncpy« output may be truncated copying 254 bytes from a string of length 254 [-Werror=stringop-truncation]
     strncpy(kobj.label, objs[ii]->label, sizeof(kobj.label) - 1);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2018-05-18 18:54:56 +02:00
David Ward 14afdf38e3 Do not temporarily set SC_READER_REMOVED on all readers (#1335)
* reader-pcsc: Do not temporarily set SC_READER_REMOVED on all readers

Fixes #1324.

* reader-cryptotokenkit: Do not temporarily set SC_READER_REMOVED on all readers

See #1324.
2018-05-18 13:11:49 +02:00
Frank Morgner 36b88c3ad7 reader-pcsc: allow fixing the length of a PIN
fixes https://github.com/OpenSC/OpenSC/issues/1221
closes https://github.com/OpenSC/OpenSC/pull/1288
2018-05-18 12:57:46 +02:00
Frank Morgner d11e05fe1f Generalized configuration option `ignored_readers` 2018-05-18 12:46:51 +02:00
Frank Morgner 4fca7d08c1 removed configuration option `force_card_driver`
Use `card_drivers` or `OPENSC_DRIVER` instead
2018-05-18 12:46:51 +02:00
Frank Morgner 6ab6d7bad9 removed configuration option `reopen_debug_file`
Simply re-open the debug file every time on Windows and don't do it
everywhere else.
2018-05-18 12:46:51 +02:00
Frank Morgner 5d7ed37246 Removed configuration option `paranoid-memory`
Don't pretend that we're capable of performing memory locking. The
implementation of that, `sc_mem_alloc_secure()` (also removed), was
almost unused anyway.
2018-05-18 12:46:51 +02:00
Frank Morgner 58b6cc05aa Reordered card driver detection
Workaround to not detect the MUSCLE applet as whatever other card driver
selects an AID first. MUSCLE applet will always return 9000, which will
confuse other card drivers. Since this bug is not going to go away any
time soon, we simply detect the MUSCLE applet first and hope that other
applets don't have a similar bug.
2018-05-18 12:36:28 +02:00
Frank Morgner f04a2654d9 card-muscle: be more relaxed in card initialization
closes https://github.com/OpenSC/OpenSC/pull/1248
2018-05-18 12:36:28 +02:00
Jakub Jelen 9858d05589 PKCS#11 testsuite (#1224)
* Initial version of pkcs11 testsuite

* Refactor test cases to several files, clean up awful and unused stuff

* Static mechanism list based on the actual token offer

* Get rid of magic numbers

* Documentation

* License update based on the original project

* Verbose readme

* Cleanup unused code, long lines and method order

* Typo; More verbose errors

* Use fallback mechanisms

* Refactor object allocation and certificate search

* PKCS11SPY mentioned, more TODO

* add SHA mechanisms

* Do not try to Finalize already finalized cryptoki

* Add more flags and mechanisms

* Do not list table for no results

* Logical order of the tests (regression last)

* read ALWAYS_AUTHENTICATE from correct place

* ALWAYS_AUTHENTICATE for decryption

* Test EC key length signature based on the actual key length

* Shorten CKM_ list output, add keygen types detection

* Skip decrypting on non-supported mechanisms

* Fail hard if the C_Login fails

* Reorganize local FLAGS_ constants

* Test RSA Digest mechanisms

* Correct mechanisms naming, typos

* Do not attempt to do signature using empty keys

* CKM_ECDSA_SHA1 support

* Correct type cast when getting attributes

* Report failures from all mechanisms

* Standardize return values, eliminate complete fails, documentation interface

* Wait for slot event test

* Add switch to allow interaction with a card (WaitForSlotEvent)

* At least try to verify using C_Verify, if it fails, fall back to openssl

* Get rid of function_pointers

* Get rid of additional newline

* Share always_authenticate() function between the test cases

* Refactor Encrypt&decrypt test to functions

* Do not overwrite bits if they are not provided by CKA, indentation

* Cleanup and Break to more functions Sign&Verify test

* CKM_RSA_X_509 sign and verify with openssl padding

* More TODO's

* Proper abstracted padding with RSA_X_509 mechanism

* Add ongoing tasks from different TODO list

* Update instructions. Another todo

* Variables naming

* Increase mechanism list size, use different static buffers for flags and mechanism names

* nonstandard mechanism CKM_SHA224_RSA_PKCS supported by some softotkens

* Get rid of loop initial declarations

* Loop initial declaration, typos, strict warnings

* Move the p11test to the new folder to avoid problems with dynamically linked opensc.so

* Update path in README

* Possibility to validate the testsuite agains software tokens

* Add possibility to select slot ID on command-line (when there are more cards present)

* Clean up readme to reflect current options and TODOs

* Do not attempt to use keys without advertised sign&verify bits to avoid false positives

* Get and present more object attributes in readonly test; refactor table

* New test checking if the set of attributes (usage flags) is reasonable

* Test multipart signatures. There is not reasonable mechanism supporting multipart encryption

* Use PKCS#11 encryption if possible (with openssl fallback)

* Identify few more mechanisms (PSS) in the lest

* Resize table to fit new mechanisms

* Remove initial loop declaration from multipart test

* Use pkcs11-tool instead of p11tool form most of the operations (master have most of the features)

* Preparation for machine readable results

* Refactor log variables out of the main context, try to export generic data

* Do not write to non-existing FD if not logging

* Export missing data into the log file in JSON

* Store database in json

* Sanity check

* Avoid uninitialized structure fields using in state structure

* Dump always_authenticate attribute too

* Manual selection of slots with possibility to use slots without tokens

* Do not free before finalizing

* Proper cleanup of message in all cases

* Proper allocation and deallocation of messages

* Sanitize missing cases (memory leaks)

* Suppressions for testing under valgrind

* Better handling message_lengt during sign&verify (avoid invalid access)

* Suppress another PCSC error

* Do not use default PIN. Fail if none specified

* Sanitize initialization. Skip incomplete key pairs

* Add missing newline in errors

* Fix condition for certificate search

* Avoid several calls for attributes of zero length

* Handle if the private key is not present on the card

* Improve memory handling, silent GCC warning of 'unused' variable

* Fail early with missing private key, cleanup the messages

* Use correct padding for encryption

* Cache if the card supports Verify/Encrypt and avoid trying over and over again

* Loosen the condition for the Usage flags

* OpenSSL 1.1.0 compatibility

* Add missing mechanisms

* Do not require certificates on the card and pass valid data for RSA_PKCS mechanisms

* Add missing PIN argument in runtest.sh

* Add OpenSSL < 1.1 comatible bits

* Add SHA2 ECDSA mechanisms handling

* Use public key from PKCS#11 if the certificate is missing (or compare it with certificate)

* Avoid long definitions in OpenSSL compat layer

* In older OpenSSL, the header file is ecdsa.h

* Add missing config.h to apply compat OpenSSL layer

* ASN1_STRING_get0_data() is also new in 1.1.0

* Return back RSA_X_509 mechanism

* Drop bogus CKM_* in the definitions

* Drop CKM_SHA224_RSA_PKCS as it is already in pkcs11.h

* Update documentation

* Use NDEBUG as intended

* typos, cleanup

* Typos, cleanup, update copyright

* Additional check for OpenCryptoki, generate more key types on soft tokens

* Prepare for RSA-PSS and RSA-OAEP

* Use usage&result flags for the tests, gracefully ignore PSS&OAEP

* pkcs11.h: Add missing definitions for PSS

* PSS and OAEP tests

readonly: Typos, reformat

* Working version, memory leak

* Tweak message lengths for OAEP and PSS

* Skip tests that are not aplicable for tokens

* configure.ac: New switch --enable-tests

Do not attempt to build tests if cmocka is not available or
--enable-tests is provided. It makes also more lightweight release
builds out of the box (or with --disable-tests).

* travis: Install cmocka if not available

* Do not build tests on Windows and make dist pass

* Try to install cmocka from apt and from brew

* Do not require sudo (cmocka from apt and brew works)
2018-05-18 12:31:55 +02:00
Frank Morgner 1798bbe692 manuals: added missing "Authors" section 2018-05-16 13:43:25 +02:00
Frank Morgner 90a5b262d0 nPA: fixed matching for newer cards
they have other ATRs... match if EF.CardAccess is found
2018-04-26 21:55:54 +02:00
Frank Morgner 4e83e2e1b3 reader-pcsc: fixed default for disconnect_action
Initialize it to "leave", even if no pcsc configuration block was given.
2018-04-26 14:48:54 +02:00
Frank Morgner 58a824527b sc-hsm: fixed default labels for GoID 2018-04-25 23:27:55 +02:00
David Ward fff4ca901d Provide more space for card holder name in CAC token label
The PKCS#15 emulation layer for the CAC uses a single PIN. Set its
label to "PIN" (rather than the card type "CAC I" or "CAC II"), so
that the PIN label will be omitted from the token label, providing
more space for the card holder name instead.

This is intended to match the behavior used for PIV cards, which
was changed with commit 56c8f59b25.
2018-04-24 14:35:11 +02:00
Peter Marschall 504d267e76 openpgp: don't treat OpenPGP v3 cards special in src/libopensc/pkcs15-syn.c
As OpenPGP v3 cards are backward compatible with earlier versions,
fix an inconsitency in src/libopensc/pkcs15-syn.c
2018-04-22 21:32:17 +02:00
David Ward 2c167a9982 Address compiler warnings when using --disable-optimization (#1325)
* Handle errors as intended in sc_pkcs15emu_openpgp_add_data()

If a data object can be read, but it cannot be added to the PKCS#15
framework, return from this function with an error; do not continue
reading other data objects. Otherwise, do not return an error from
this function when a data object cannot be read or is empty.

Improve existing comments for clarity.

* Address other compiler warnings when using --disable-optimization

Certain variables that are not initialized when they are declared
prevent the build from completing, when --disable-optimization is
passed to ./configure.
2018-04-15 09:37:43 +02:00
Peter Marschall 5abe99d228 fix typos
Mass-typo fixing, almost exclusively in comments and text strings.

While at it also fixed a few (very few) grammar errors.
2018-04-15 09:34:45 +02:00
Feitian Technologies 7b249084d8 Improve code and fix sign bugs (#1306)
1. In epass2003_set_security_env, remove unused code, add condition
check of ec and rsa
2. Line 1709 - add return check of hash_data
3. In epass2003_decipher API, the old sign using apdu.le = 256, now add
condition check of rsa
4. Line 2731-2734 - After login successful, need get session status,
adjust code, improve condition check of data->cmd.
2018-04-11 13:48:41 +02:00
Frank Morgner 148bc25238 fixed coverity issues
- CID 145623 (#1 of 1): Resource leak (RESOURCE_LEAK)
- CID 269069 (#1 of 1): Resource leak (RESOURCE_LEAK)
- CID undefined (#1 of 1): Dereference before null check (REVERSE_INULL)
2018-04-07 12:27:12 +02:00
Laurent Bigonville 491e5a47fc Clean up the belpic driver
Remove all the code related to the old GUI and PIN PAD.

This code was initially developed by Zetes and had the ability to
display a dialog to request the PIN to the user. It was also able to
manage some specific proprietary pin pads.

As the Belgian government/fedict has now its own implementation, all
these old crufts can be removed.

https://github.com/OpenSC/OpenSC/issues/1296
2018-04-06 12:42:12 +02:00
Frank Morgner fc64c87c5c with keep_alive, use cache only within the transaction
fixes https://github.com/OpenSC/OpenSC/issues/1159
2018-04-06 12:20:32 +02:00
Doug Engert 0911982bef Various PIV changes
Some ActivIdentity CAC/PIV cards lose the login state when selecting
the PIV AID SC_CARD_TYPE_PIV_II_CAC and CI_PIV_AID_LOSE_STATE were added
so piv_card_reader_lock_obtained will  try and do a SELECT PIV AID.

card->type is reset to its original value if piv_match_card_continued
fails to match a card as PIV.

pkcs15-piv.c now uses sc_card_ctl which checks card->ops->card_ctl for NULL.

closes https://github.com/OpenSC/OpenSC/pull/1307
fixes https://github.com/OpenSC/OpenSC/issues/1297
2018-04-05 15:23:16 +02:00
Jakub Jelen 58cd9aaeb6 card-authentic.c: Initialize variables and make it build
Ammends: #1205
2018-04-04 21:43:01 +02:00
Jakub Jelen e193b31e1a Log the used config file after processing it 2018-04-04 21:43:01 +02:00
Mouse b7dc5a0890 Retrieve OpenPGP applet version from OpenPGP applet on YubiKey token (#1262) 2018-04-04 21:41:39 +02:00
Frank Morgner 3e22daf7b5 OpenPGP: fixed memory leak 2018-04-04 10:02:30 +02:00
sergioag 098eed146f [AuthentIC v3] Correctly handle APDUs with more than 256 bytes (#1205) 2018-03-31 21:51:11 +02:00
Frank Morgner 45ad44e311 fixed handling SC_ASN1_TAG_EOC from sc_asn1_read_tag
We can't check for `tag == SC_ASN1_TAG_EOC` directly, because this
would also be true for a tag of 0x80 (with `class ==
SC_ASN1_CLASS_CONSTRUCTED`). So what we do is we check for the output
buffer to be NULL!

fixes https://github.com/OpenSC/OpenSC/issues/1273
2018-03-30 08:28:51 +02:00
Frank Morgner a84bf918af fixed memory leak 2018-03-22 14:54:50 +01:00
Frank Morgner b643bbbe40 fixed memory in case of a certificate parsing problem 2018-03-22 14:34:02 +01:00
Vadim Penzin e1d6f0869b Add missing initialisation of variables to pacify Clang.
1. src/libopensc/card-openpgp.c:pgp_store_key().
2. src/libopensc/cwa14890.c:cwa_verify_icc_certificates().
3. src/libopensc/cwa14890.c:cwa_prepare_external_auth().
4. src/libopensc/pkcs15-itacns.c:itacns_check_and_add_keyset().

(Discovered by Clang 4.0.0 on OpenBSD 6.2.)
2018-03-19 09:48:21 +01:00
Vadim Penzin 1ac08f96e7 epass2003: Fix buffer underrun in epass2003_decipher(), etc.
1. Buffer underrun in epass2003_decipher().
2. The parameter `data' in update_secret_key() must be constant.

(Discovered by Clang 4.0.0 on OpenBSD 6.2.)
2018-03-19 09:48:21 +01:00
Frank Morgner 7ca16a7531
Merge pull request #1256 from dengert/piv-aid-discovery
PIV detection of AID using Discovery Object before doing select AID - Partial 
 #1243
2018-03-16 22:06:16 +01:00
Igor Castañeda Ferreira 5d5caecfab Fix DNIe UI integration (#1280) 2018-03-09 14:37:38 +01:00
Frank Morgner a97fc86cc9 starcos: reverted deactivation of pin cmd for 2.X
It simply uses the implementation of iso7816. Fixes regression from
19bbfc76f5
2018-03-09 14:36:55 +01:00
Frank Morgner 01810fcb66 STARCOS: Added support for 3.5
ATR and differences between 3.4/3.5 are based on
https://github.com/CardContact/sc-hsm-embedded
Actually, 3.5 is untested, but 3.4 is almost identical, so we hope that
for 3.5 everything is fine.
2018-03-09 14:36:55 +01:00
Frank Morgner 196c838957 fixed use after free
ICCSN and CHN pointed into EF.GDO's content, which was freed
preemptively. Regression of 0502a839c6
2018-03-09 14:36:55 +01:00
Frank Morgner b403934718 PKCS#15: prevent use of empty serial number in TokenInfo
... and initialize the serial number with the card's serial number if
nothing useful is in EF.TokenInfo
2018-03-09 14:36:55 +01:00
Frank Morgner d29bdf9da0 md: register starcos cards 2018-03-09 14:36:55 +01:00
Frank Morgner c3ffdecd0b rename SC_SEC_ENV_KEY_REF_ASYMMETRIC to SC_SEC_ENV_KEY_REF_SYMMETRIC
This reflects the actual use of the identifier by the card drivers.
2018-03-09 14:36:55 +01:00
Frank Morgner e2ba2f8192 Starcos 3.4: implemented PSO:DEC 2018-03-09 14:36:55 +01:00