Blame SOURCES/opensc-0.19.0-coolkey-matching.patch

5831fa
From 6691487cd7433b4ffc3a99124b5ecf92361b8a76 Mon Sep 17 00:00:00 2001
5831fa
From: Jakub Jelen <jjelen@redhat.com>
5831fa
Date: Tue, 9 Oct 2018 15:10:36 +0200
5831fa
Subject: [PATCH 1/3] cac: These functions do not have to be exposed
5831fa
5831fa
---
5831fa
 src/libopensc/card-cac.c | 4 ++--
5831fa
 1 file changed, 2 insertions(+), 2 deletions(-)
5831fa
5831fa
diff --git a/src/libopensc/card-cac.c b/src/libopensc/card-cac.c
5831fa
index eeab07e4f..bd4e03362 100644
5831fa
--- a/src/libopensc/card-cac.c
5831fa
+++ b/src/libopensc/card-cac.c
5831fa
@@ -211,7 +211,7 @@ typedef struct cac_private_data {
5831fa
 
5831fa
 #define CAC_DATA(card) ((cac_private_data_t*)card->drv_data)
5831fa
 
5831fa
-int cac_list_compare_path(const void *a, const void *b)
5831fa
+static int cac_list_compare_path(const void *a, const void *b)
5831fa
 {
5831fa
 	if (a == NULL || b == NULL)
5831fa
 		return 1;
5831fa
@@ -220,7 +220,7 @@ int cac_list_compare_path(const void *a, const void *b)
5831fa
 }
5831fa
 
5831fa
 /* For SimCList autocopy, we need to know the size of the data elements */
5831fa
-size_t cac_list_meter(const void *el) {
5831fa
+static size_t cac_list_meter(const void *el) {
5831fa
 	return sizeof(cac_object_t);
5831fa
 }
5831fa
 
5831fa
5831fa
From fab79b70ff45d02d99bc05863be57f8ca8f0acda Mon Sep 17 00:00:00 2001
5831fa
From: Jakub Jelen <jjelen@redhat.com>
5831fa
Date: Tue, 9 Oct 2018 15:58:12 +0200
5831fa
Subject: [PATCH 2/3] coolkey: Improve card matching to avoid mismatches in
5831fa
 muscle
5831fa
5831fa
---
5831fa
 src/libopensc/card-coolkey.c | 20 +++++++++++++++++++-
5831fa
 1 file changed, 19 insertions(+), 1 deletion(-)
5831fa
5831fa
diff --git a/src/libopensc/card-coolkey.c b/src/libopensc/card-coolkey.c
5831fa
index b97559cc3..2cf2362c8 100644
5831fa
--- a/src/libopensc/card-coolkey.c
5831fa
+++ b/src/libopensc/card-coolkey.c
5831fa
@@ -2224,14 +2224,32 @@ static int coolkey_initialize(sc_card_t *card)
5831fa
 /* NOTE: returns a bool, 1 card matches, 0 it does not */
5831fa
 static int coolkey_match_card(sc_card_t *card)
5831fa
 {
5831fa
+	sc_apdu_t apdu;
5831fa
 	int r;
5831fa
+
5831fa
 	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
5831fa
 	/* Since we send an APDU, the card's logout function may be called...
5831fa
 	 * however it may be in dirty memory */
5831fa
 	card->ops->logout = NULL;
5831fa
 
5831fa
 	r = coolkey_select_applet(card);
5831fa
-	return (r >= SC_SUCCESS);
5831fa
+	if (r == SC_SUCCESS) {
5831fa
+		/* The GET STATUS INS with P1 = 1 returns invalid instruction (0x6D00)
5831fa
+		 * on Coolkey applet (reserved for GetMemory function),
5831fa
+		 * while incorrect P1 (0x9C10) on Muscle applets
5831fa
+		 */
5831fa
+		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
5831fa
+		apdu.cla = COOLKEY_CLASS;
5831fa
+		apdu.le = 0x00;
5831fa
+		apdu.resplen = 0;
5831fa
+		apdu.resp = NULL;
5831fa
+		r = sc_transmit_apdu(card, &apdu);
5831fa
+		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
5831fa
+			return 1;
5831fa
+		}
5831fa
+		return 0;
5831fa
+	}
5831fa
+	return 0;
5831fa
 }
5831fa
 
5831fa
 
5831fa
5831fa
From 98a1716768d11afd6d0e1e73bf8154dddfe915e9 Mon Sep 17 00:00:00 2001
5831fa
From: Jakub Jelen <jjelen@redhat.com>
5831fa
Date: Tue, 9 Oct 2018 16:01:57 +0200
5831fa
Subject: [PATCH 3/3] ctx: Move coolkey driver up after improving the matching
5831fa
5831fa
Fixes #1483
5831fa
---
5831fa
 src/libopensc/ctx.c | 2 +-
5831fa
 1 file changed, 1 insertion(+), 1 deletion(-)
5831fa
5831fa
diff --git a/src/libopensc/ctx.c b/src/libopensc/ctx.c
5831fa
index f24a61ca0..98e6038a7 100644
5831fa
--- a/src/libopensc/ctx.c
5831fa
+++ b/src/libopensc/ctx.c
5831fa
@@ -128,6 +128,7 @@ static const struct _sc_driver_entry internal_card_drivers[] = {
5831fa
 
5831fa
 /* Here should be placed drivers that need some APDU transactions in the
5831fa
  * driver's `match_card()` function. */
5831fa
+	{ "coolkey",	(void *(*)(void)) sc_get_coolkey_driver },
5831fa
 	/* MUSCLE card applet returns 9000 on whatever AID is selected, see
5831fa
 	 * https://github.com/JavaCardOS/MuscleCard-Applet/blob/master/musclecard/src/com/musclecard/CardEdge/CardEdge.java#L326
5831fa
 	 * put the muscle driver first to cope with this bug. */
5831fa
@@ -144,7 +145,6 @@ static const struct _sc_driver_entry internal_card_drivers[] = {
5831fa
 #endif
5831fa
 	{ "openpgp",	(void *(*)(void)) sc_get_openpgp_driver },
5831fa
 	{ "jpki",	(void *(*)(void)) sc_get_jpki_driver },
5831fa
-	{ "coolkey",	(void *(*)(void)) sc_get_coolkey_driver },
5831fa
 	{ "npa",	(void *(*)(void)) sc_get_npa_driver },
5831fa
 	/* The default driver should be last, as it handles all the
5831fa
 	 * unrecognized cards. */
5831fa