Commit Graph

3128 Commits

Author SHA1 Message Date
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 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 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
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 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 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 5ca99febe3 ISO 7816-4 doesn't force a maximum for GET CHALLENGE 2017-12-04 21:09:26 +01:00
Frank Morgner 4444d24f59 win32: generate PDB files for releases
https://msdn.microsoft.com/fsk896zz.aspx

fixes https://github.com/OpenSC/OpenSC/issues/1191
2017-11-21 10:54:48 +01:00
Jakub Jelen 09af8714ad Avoid GCC 7 warnings with -Werror (#1196)
* Avoid GCC 7 warnings with -Werror

-Werror=implicit-fallthrough=
	libopensc/card-incrypto34.c
		not sure if this is a bug or intention
	libopensc/card-rutoken.c
		most probably intention
	libopensc/card-westcos.c
		remove bogus if so the compile is not confused
		I will fill a separate bug to gcc probably
	pkcs15init/pkcs15-iasecc.c
		Simplify the log and avoid compiler confusion
	sm/sm-common.c
		explicit fallthrough
	tools/pkcs11-tool.c
		use explicit fallthrough comment
	tools/pkcs15-init.c
		The fallthrough is obvious here

-Werror=format-truncation=
	libopensc/pkcs15-itacns.c
		use explicit string lengths
	pkcs11/framework-pkcs15.c
		calculate the truncation
	tests/pintest.c
		avoid sprintf
	tools/pkcs15-crypt.c
		avoid sprintf
	tools/pkcs15-init.c
		calculate the truncation
2017-11-17 10:47:53 +01:00
Raul Metsma 514f898671 Fix reading EstEID certificates with T=0 (#1193) 2017-11-17 10:46:34 +01:00
Frank Morgner c70ed34669 CTK: Added support for PIN pad 2017-11-17 10:04:46 +01:00
Frank Morgner ad6515ba55 CTX: detect card resets 2017-11-17 10:04:46 +01:00
Frank Morgner b4072af26e export sc_card_find_ec_alg 2017-11-17 10:04:46 +01:00
Frank Morgner 2494765cdc CTK: fixed initializing ATR and UID 2017-11-17 10:04:46 +01:00
Frank Morgner baa709ff74 print ASN.1 time and ASCII tranlation 2017-11-17 10:03:54 +01:00
Frank Morgner 8de544653c dump data with sc_debug_hex and sc_log_hex 2017-11-17 10:03:54 +01:00
Frank Morgner 9468ce7f89 beautify printed ASN.1 output
- fixed printing tags on multiple bytes
- align indenting with raw tags
- use OpenSSL's human readable OID database
- only print the canonical names for universal tags
2017-11-17 10:03:54 +01:00
Raul Metsma 2846295e1f EstEID ECDH token support (#1185) 2017-11-10 08:58:31 +01:00
Jakub Jelen 77f2640ea7 Avoid potential memory leak 2017-11-09 12:45:35 +01:00
Jakub Jelen 07267df313 Add the ACA path to the PIN structure if we have one 2017-11-09 12:45:35 +01:00
Jakub Jelen fd6882f686 Enable CAC ALT token card operations 2017-11-09 12:45:35 +01:00
Frank Morgner eacb53fc60 added boilerplate for disabling old card driver
currently disabled:
- miocos
- jcop
2017-11-09 12:43:06 +01:00
Frank Morgner 4d5b73d869 fixed accessing garbage value 2017-11-09 12:42:29 +01:00
Frank Morgner 1d03000222 fixed dead assignment 2017-11-09 12:42:29 +01:00
Frank Morgner 9c025280a6 avoid integer underflow 2017-11-09 12:42:29 +01:00
Frank Morgner 3ca6c4b04a fixed possible NULL dereference 2017-11-09 12:42:29 +01:00
Frank Morgner 10101984da fixed dereferencing type-punned pointer 2017-11-09 12:42:29 +01:00
Frank Morgner 3693a96911 win32: don't link static libs into static libs 2017-11-09 12:42:29 +01:00
Frank Morgner 854123c75e fixed binary comparison 2017-11-09 12:42:29 +01:00
Frank Morgner 4251a362b5 fixed potential memory leak 2017-11-09 12:42:29 +01:00
Frank Morgner 1b880b5675 fixed uninitialized buffer 2017-11-09 12:42:29 +01:00
Frank Morgner f4946df4e9 fixed dead assignments 2017-11-09 12:42:29 +01:00
Frank Morgner 251a5f9fef reader-pcsc: use sc_apdu2bytes for PIN APDU 2017-11-09 12:42:29 +01:00
Frank Morgner 04a7075290 fixed compiler warnings 2017-11-09 12:42:29 +01:00
Raul Metsma 189368e49f Fix crash when certificate read failed (#1189)
Fixes https://github.com/OpenSC/OpenSC/issues/1176
2017-11-08 13:24:18 +01:00
Raul Metsma be35d3d026 EstEID ECDSA token support (#1158) 2017-10-27 19:51:33 +02:00
Frank Morgner 594e125f06 Added PKCS#15 emulator for DIN 66291 profile 2017-10-27 19:48:22 +02:00
Frank Morgner bc075d6639 iso7816: don't show error for PIN status on 63C3 2017-10-27 19:48:22 +02:00
Frank Morgner b7b6680f38 starcos: 3.4 supports ISO based PIN status queries 2017-10-27 19:48:22 +02:00
Frank Morgner e54684b9db fixed documentation of GLP encoded PIN 2017-10-27 19:48:22 +02:00
Frank Morgner 4f189a5174 check for digits in case of BCD encoded PIN 2017-10-27 19:48:22 +02:00
Frank Morgner 0502a839c6 unified reading of EF.GDO 2017-10-27 19:48:22 +02:00
Frank Morgner 293d02ea4b removed unused test
test is performed by sc_asn1_read_tag
2017-10-27 19:48:22 +02:00
Frank Morgner 5918e005d7 starcos: added serial number for 3.4 2017-10-27 19:48:22 +02:00
Frank Morgner 498aedd165 Merge remote-tracking branch 'upstream/master' into winui 2017-10-16 15:16:34 +02:00
Feitian Technologies 8d7346406d Add ECC support and solve wrong Length status codes with SM card
Fix #1073
Fix #1115
2017-10-16 14:57:52 +02:00
Maciej S. Szmigiero 0cb654ca78 sc-hsm: fix unused variable warnings in sc_hsm_init()
When building without OpenPACE there are two unused variables in
sc_hsm_init() that cause compiler to emit warnings about them.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
2017-10-16 14:56:01 +02:00
Frank Morgner dfd1838934 fixed building without SM
fixes https://github.com/OpenSC/OpenSC/issues/1155
2017-09-24 22:14:19 +02:00
vletoux 8965ee38dd Gids verified mutual auth 2017-09-17 23:10:28 +02:00
Nathaniel Wesley Filardo 00535f0174 sc_pkcs15_get_bitstring_extension: int, not long long
Use the ASN.1 decoder's SC_ASN1_BIT_FIELD decoder to properly decode
into a machine word.  As _bitstring_extension is used only for the OID
2.5.29.15 by all callers, which is at most 9 bits wide, this is a
reasonable thing to do.
2017-09-12 23:05:27 +02:00
vletoux ab8a51a1ab Fix wrong padding for GIDS admin authentication 2017-09-11 00:25:08 +02:00
Nathaniel Wesley Filardo 5882df745a Use |, not ||, when decoding CAC key_reference
This quiets two compiler warnings and is almost surely what was actually
meant.  However, I do not have a CAC card to test.
2017-09-04 10:58:31 +02:00
Jakub Jelen eeeefecf12 Add newly reported ATR for CardOS 5.3 2017-09-02 00:19:35 +02:00
Jakub Jelen 60dbebf511 Parse the ECC parameters from TokenInfo (CHOICE in AlgorithmInfo)
Fixes #1134
2017-09-02 00:19:35 +02:00
Jakub Jelen eee4964d7f The cardos driver supports also CardOS 5
CardOS M4 is confusing since it refers to the old card versions
2017-09-02 00:19:35 +02:00
Jakub Jelen d018855b9f Get cardholder name from the first certificate 2017-09-02 00:17:15 +02:00
Jakub Jelen 56c8f59b25 Use shorter PIN name for default PIN to accomodate Card Holder name in future 2017-09-02 00:17:15 +02:00
Frank Morgner 555671b54d sc_read_binary may return less bytes than requested
Note, that there are a number of card drivers that still use
`sc_read_binary` in the wrong way. Unfortunately, I don't have the time
to go through all of them.

Fixes https://github.com/OpenSC/OpenSC/issues/1112
2017-08-27 21:21:00 +02:00
Arnaud Fontaine 2765b7b1a0 Support for new MinInt agent card (#1092)
* Support for new MinInt agent card

This card uses the same ATR as the existing card, but the applet installed
does not have the same AID. This card actually works exactly as the
IASECC_SAGEM.

Unify iasecc_init for AMOS/SAGEM and MI cards
2017-08-22 01:13:18 +02:00
Frank Morgner a1466f7395 sc-hsm: better error messages for optional files 2017-08-11 23:07:25 +02:00
Frank Morgner a007ab7820 sc-hsm: New PIN commands for GoID 1.0 2017-08-11 23:07:25 +02:00
Jakub Jelen 0dcf673296 CAC issues (#1120)
* cac: Make the retransmitted APDU valid by restoring the resplen

* cac: Check SWs for all the APDUs and report the errors to underlying layers

* cac: Fallback from CACv1 to CACv2 when CACv1 instruction is not recognized

for the lack of other pointers how to recongnize them

* avoid goto
2017-08-04 08:48:24 +02:00
Frank Morgner 496e2afc9e reader-pcsc: allow no attached reader for notification
Return an error only on OS X, where PnP notification is not supported.
2017-08-02 19:07:16 +02:00
Frank Morgner b2cde0f7fb Windows: Added support for notifications 2017-08-02 19:03:16 +02:00
Frank Morgner cd62c6cdf5 Linux: Added support for notifications 2017-08-02 19:02:21 +02:00
Frank Morgner bf828014e5 macOS: Added support for notifications
- adds framework for user defined message strings
- automatically determine the system's language
2017-08-02 19:02:05 +02:00
HAMANO Tsukasa e25565d851 add public keys 2017-08-02 10:27:06 +02:00
HAMANO Tsukasa da9484bd6b fix trivial leak 2017-08-02 10:27:06 +02:00
HAMANO Tsukasa 977728a5bf jpki: set user_consent flag 2017-08-02 10:27:06 +02:00
Frank Morgner 7a39d6d058 build against OpenSSL 1.1.0 on Windows, by default
- build with AppVeyor's OpenSSL 1.1.0
- updates AppVeyor version of OpenPACE

Fixes https://github.com/OpenSC/OpenSC/issues/1108
2017-07-24 21:39:01 +02:00
Frank Morgner def06389bf sc-hsm: fixed building with --disable-sm
Closes https://github.com/OpenSC/OpenSC/pull/1103
2017-07-19 09:27:24 +02:00