Commit Graph

6977 Commits

Author SHA1 Message Date
Frank Morgner e8e8153cda md: prevent endless loop for card without sn 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
Frank Morgner b05273b01e starcos: fixed key reference for "local" key id 2018-03-09 14:36:55 +01:00
Doug Engert 4222036a60 PIV completely separate piv_match_card from piv_init
In order to satisfy some concerns over the use of <card>_match_card
and <card>_init, this modification will do that at the cost of additional
overhead of repeating some card commands.

Hopefully this commit will not be needed.

 On branch piv-aid-discovery
 Changes to be committed:
	modified:   card-piv.c
2018-02-28 13:49:14 -06:00
Doug Engert aee62c7c67 Requested changed to not rely on success *_match_card being followed by *_init
As requested and as the alternative solution see:
https://github.com/OpenSC/OpenSC/pull/1256#issuecomment-365319444

In order to not pass a card lock and the card->drv_data from piv_match_card
piv_match_card is split in 2 parts.

the piv_match_card_continued is called from piv_init. piv_init may
now return with SC_ERROR_INVALID_CARD to single to sc_connect_card to look
for additional drivers.

Cosmetic change to indicate neo_version is really a Yubico version.
Change wording on the comments when setting card_issues.

 On branch piv-aid-discovery

 Changes to be committed:
	modified:   src/libopensc/card-piv.c
2018-02-22 09:48:43 -06:00
Doug Engert efe7eb598f Some CAC / PIV cards do not support Discovery Object
Some CAC card return '6A80` Incorrect parameters in APDU when trying to
read the Discovery object. If it fails other then not found, then we can
not use the Discovery object to test for the active AID.

The test is done in piv_match_card just after doing a SELECT AID for the PIV.
and set CI_DISCOVERY_USELESS if needed. piv_card_reader_lock_obtained will
then not use the Discovery object.

Some older PIV cards, prior to the introduction of the PIV
Discovery and History objects, may get errors trying to read them.
Ignore these errors too.

Remove comment and remove code to check verify Lc=0 as requested in:

https://github.com/OpenSC/OpenSC/pull/1256#pullrequestreview-96124443

They can easily be added back in.

 On branch piv-aid-discovery

 Changes to be committed:
	modified:   src/libopensc/card-piv.c
2018-02-22 09:40:42 -06:00
Doug Engert 27add2ee3c Inform pkcs15 and card drivers of PKCS#11 C_Login(CKU_CONTEXT_SPECIFIC)"
Framework-pkcs15.c will now set pin_info->auth_method to SC_AC_CONTEXT_SPECIFIC

iso7816.c iso7816_build_pin_apdu treats this the same as SC_AC_CHV

card-piv.c piv_pin_cmd sets priv->xcontext_specific=1 and calls sc_lock before
the verify command. If the verify fails sc_unlock is called.
Later after the next card command returns, if priv->context_specific==1 piv_check_sw
will call sc_unlock as the application may not have requested the crypto but
some other command.

Some additional calls to sc_lock and sc_unlock have been added to make sure
PIV internal command sequences including the crypto command ('87') and any get
responses are always protected by a lock.

This guarantees the card is locked for verify and the next command
which should be the crypto operation. The PIV card also inforces this restriction
on the card.

This is based on suggestions in:
://github.com/OpenSC/OpenSC/pull/1256#issuecomment-361975751

 On branch piv-aid-discovery

 Changes to be committed:
	modified:   src/libopensc/card-piv.c
	modified:   src/libopensc/iso7816.c
	modified:   src/libopensc/types.h
	modified:   src/pkcs11/framework-pkcs15.c
2018-02-22 09:37:46 -06:00
Doug Engert 3fea6b7927 PIV detection of AID using Discovery Object before doing select AID
Many OpenSC drivers try and detect during match if the card supports
their AID by doing a SELECT FILE for the AID.

But this can cause problems with cards such as Yubico that do not ignore
SELECT AID commands for applications they do not support. Other cards may
have the same problems. Selecting the wrong AID can also lose the security
state.

The card-piv.c will now uses the GET DATA to read the PIV Discovery Object '7E'
which is a ISO standard template that will contain the AID of the currently
active application. The driver will then double check that the template is
for the PIV application.

If the template contains the PIV AID, then no SELECT AID is done.
PIV standards say there can only be one PIV application on a card.
PIV standards also say PIV must be the the default application,
but Yubico does not follow this.

The command fails only then will a SELECT AID be done.

Thus this can avoid the Yubico problem.

This logic is used in both "match" and in the piv_card_reader_lock_obtained
routine.

Additional logic was in piv_card_reader_lock_obtained was added to handle
when the card reset was received by some other program. Multiple programs
may be trying to use the PIV application on the card, and thus multiple
programs will all receive that the card was reset. The first program to receive
the card was reset will do all of the above logic, and may leave the card in
a state will cause other programs to not  have to do much at all.

 The intent of all of this is to avoid sending extra commands to the card
 including SELECT AID that could change the card state when not needed.

 On branch piv-aid-discovery
 Changes to be committed:
	modified:   card-piv.c
2018-02-22 09:37:46 -06:00
Doug Engert 8cc0c3911a Yubico PIV application fixed CI_VERIFY_LC0_FAIL in version 4.3.2
Also add PIV card types to  sc_pkcs15_is_emulation_only

 On branch piv-aid-discovery

 Changes to be committed:
	modified:   src/libopensc/card-piv.c
	modified:   src/libopensc/pkcs15-syn.c
2018-02-22 09:33:30 -06:00
Frank Morgner 1d4f59ea51 compiler fix 2018-02-20 22:16:51 +01:00
Frank Morgner 86350d3f72 fixed compilation proble 2018-02-20 22:16:51 +01:00
Frank Morgner 905e95eb37 compiler fix 2018-02-20 22:16:51 +01:00
Frank Morgner f862060614 EAC: Clearify naming of functions and data
Use names that are specific to EAC, not the German ID card (nPA),
because Protocol and Commands are defined by BSI TR-03110 and ICAO.
Functions that are nPA specific are moved to card-npa.h.
2018-02-20 22:16:51 +01:00
Mardalemer 6843ab4190 pkcs15init: Fix rutokenS FCP parsing (#1259)
RutokenS returns data with little endian byte order, due to this
fact token wouldn't work with standard function. So function for
parsing fcp from little endian data was inplemented.
2018-02-13 13:24:28 +01:00
Frank Morgner 8ee2c61932 Return SC_SUCCESS in openpgp_card_reader_lock_obtained
prevents locking the card forever in case of a problem
2018-02-12 09:45:36 +01:00
Frank Morgner 50a35c1bae OpenPGP: Workaround for change in Extended Capabilities
The maximum length for sending and receiving data can now be found in DO
7F66. For now, we just use the default values for short/extended length
capabiliites.
2018-02-12 09:45:36 +01:00
Frank Morgner 36894c87cf
sc-hsm: fixed accessing version info (#1252)
fixes https://github.com/OpenSC/OpenSC/issues/1244
2018-02-07 12:00:09 +01:00
Frank Morgner 88175e35d3 PIV: use better long name 2018-02-07 11:57:48 +01:00
Frank Morgner 87cdfcb08c OpenPGP: Implemented "keep alive" command 2018-02-07 11:57:48 +01:00
Frank Morgner d719977d14 Reselect PKI-Applets after card reset
PKI-Applets may not be active if the card has been reset or unpowered.
The SELECT command used to activate the applet, is identical to the one
used during card matching or initialization.
2018-02-07 11:57:48 +01:00
Jakub Jelen e46193499b Use only 'filename' for file arguments replacements 2018-02-07 11:13:09 +01:00
Jakub Jelen 391ad1db01 Use filename replacement to allow completion 2018-02-07 11:13:09 +01:00
Jakub Jelen 5cb0484ea6 Correctly autocomplete --write-object option 2018-02-07 11:13:09 +01:00
Jakub Jelen 1d49e8e0db docs/tools: Improve bash-completion template and generation
This allows us to generate templates also for arguments expecting
files (input, output) or PKCS#11 modules. The general ideal was
already implemented, but never completed.
2018-02-07 11:13:09 +01:00
Jakub Jelen ccfd4b4c35 cac: Try to read the ACA file
Some "unfriendly" cards return SW 90 00 to any instruction including
the ACA file selection and therefore they are identified as CAC card.
To avoid this, we will try to read the assumed ACA file and we will
mark the card as matched only if we will read something from that file.
We do not parse the content yet.
2018-02-07 11:13:09 +01:00
Jakub Jelen e7deb3410d cac: Fail if the read instruction does not return anything
To avoid infinite loop on "unfriendly" cards, we assume that
read data instruction always returns some data. It it does not,
we can safely assume the file is not there or it is not the card
we are looking for.
2018-02-07 11:13:09 +01:00
Jakub Jelen ed0cfbd808 libopensc: Log what configuration file is used
This simplifies debugging
2018-02-07 11:13:09 +01:00
edgarholleis a7b066cc83 Fix memleak (#1255) 2018-01-29 10:30:03 +01:00
Frank Morgner e5699ef04b
DNIe: card also supports 1920 bits (#1247)
fixes https://github.com/OpenSC/OpenSC/issues/1246
2018-01-28 21:25:42 +01:00
Frank Morgner a0b562a7c8 documented usage of SM_MODE_ACL
fixes https://github.com/OpenSC/OpenSC/issues/971
2018-01-24 11:05:31 +01:00
Frank Morgner f24b55db4a IAS/ECC: fixed applet selection
fixes https://github.com/OpenSC/OpenSC/issues/1240
2018-01-24 10:45:16 +01:00
Frank Morgner 74553a5a8f PC/SC: don't reset the card on disconnection
Windows/macOS (minidriver/tokend) handle the authentication status and
perform an explicit logout on shutdown. PKCS#11 standard requires a
session for logging into the card; when closing the session we perform
an explicit logout. Hence, the authentication status should be reset
even if not performing a reset on disconnect.
2018-01-22 15:27:18 +01:00
Frank Morgner 490e825a65 OpenPGP: implemented GET CHALLENGE 2018-01-22 15:26:44 +01:00
Frank Morgner 449f6c2b94 OpenPGP: Added support for PIN logout and status 2018-01-22 15:26:44 +01:00
Frank Morgner 995845b002 openpgp: factory reset is possible if LCS is supported 2018-01-22 15:26:44 +01:00
Frank Morgner ddeb01ddc1 ISO7816: allow nested CP DOs 2018-01-22 15:26:44 +01:00
Frank Morgner fccc42295d OpenPGP: Added basic support for OpenPGP card V3
partially implements https://github.com/OpenSC/OpenSC/issues/1215

Refactored OpenPGP code so that future versions of the card will be
accessed using the logic for OpenPGP V2. We hope that backward
compatibility of the standard will keep the new versions functional.
2018-01-22 15:26:44 +01:00
Frank Morgner 16354f11af OpenPGP: fixed selecting Applet
fixes https://github.com/OpenSC/OpenSC/issues/1230
2018-01-22 15:26:44 +01:00
Frank Morgner 44447b7801 fixed warnings about uninitialized data 2018-01-17 00:28:42 +01:00
Jakub Jelen 9b2023c7ae SimpleTLV: Skip correctly two bytes after reading 2b size (#1231) 2018-01-17 00:28:05 +01:00
Frank Morgner 74e7200c31 macOS: fixed detection of OpenPACE package 2017-12-19 12:52:50 +01:00
Frank Morgner b2cca65237 sc-hsm: check integrity of SM channel
cope with multiple processes that may reset the SM channel when
accessing the card at the same time
2017-12-13 12:22:27 +01:00
Frank Morgner 47993116da macOS High Sierra: fixed dmg creation
fixes https://github.com/OpenSC/OpenSC/issues/1198
2017-12-05 08:27:55 +01:00
Frank Morgner bb4bdc8a2c CardOS: Try forcing max_send_size for PSO:DEC
Fixes https://github.com/OpenSC/OpenSC/issues/1208
Fixes https://github.com/OpenSC/OpenSC/issues/1118
Fixes https://github.com/OpenSC/OpenSC/issues/1005
Fixes https://github.com/OpenSC/OpenSC/issues/802
2017-12-04 21:09:46 +01:00
Frank Morgner 3e7f7e632c SC-HSM: Don't block generic contactless ATR 2017-12-04 21:09:26 +01:00
Frank Morgner 804ac2b7f2 fixed compiler warning 2017-12-04 21:09:26 +01:00
Frank Morgner 5ca99febe3 ISO 7816-4 doesn't force a maximum for GET CHALLENGE 2017-12-04 21:09:26 +01:00
Frank Morgner 6f37229303 opensc-explorer/opensc-tool: Allow extended APDUs 2017-12-04 21:09:26 +01:00