Blame SOURCES/opensc-0.19.0-coolkey-2k.patch

687b17
From 6c1b9094a6060d9d838bac9ea4f7c4c9e755c4ae Mon Sep 17 00:00:00 2001
687b17
From: Steve Ross <sross@forcepoint.com>
687b17
Date: Wed, 14 Nov 2018 11:59:43 -0600
687b17
Subject: [PATCH] Enable CoolKey driver to handle 2048-bit keys.
687b17
687b17
For a problem description, see <https://github.com/OpenSC/OpenSC/issues/1524>.
687b17
In a nutshell, for a card with the CoolKey applet and 2048-bit keys,
687b17
the command
687b17
	pkcs11-tool --test --login
687b17
fails to complete all of its tests.
687b17
687b17
This commit consists of a patch from @dengert.
687b17
687b17
To avoid triggering an error when the data exceeds 255 bytes, this commit
687b17
limits the amount of the payload sent to the CoolKey applet on the card based
687b17
on the maximum amount of data that the card can receive, and overhead bytes
687b17
(namely, a header and nonce) that accompany the payload.
687b17
687b17
With this change, the command
687b17
	pkcs11-tool --test --login
687b17
succeeds.
687b17
---
687b17
 src/libopensc/card-coolkey.c | 6 +++++-
687b17
 1 file changed, 5 insertions(+), 1 deletion(-)
687b17
687b17
diff --git a/src/libopensc/card-coolkey.c b/src/libopensc/card-coolkey.c
687b17
index e320290dfe..11c4e92643 100644
687b17
--- a/src/libopensc/card-coolkey.c
687b17
+++ b/src/libopensc/card-coolkey.c
687b17
@@ -1168,12 +1168,16 @@ static int coolkey_write_object(sc_card_t *card, unsigned long object_id,
687b17
 	size_t operation_len;
687b17
 	size_t left = buf_len;
687b17
 	int r;
687b17
+	size_t max_operation_len;
687b17
+
687b17
+	/* set limit for the card's maximum send size and short write */
687b17
+	max_operation_len = MIN(COOLKEY_MAX_CHUNK_SIZE, (card->max_send_size - sizeof(coolkey_read_object_param_t) - nonce_size));
687b17
 
687b17
 	ulong2bebytes(&params.head.object_id[0], object_id);
687b17
 
687b17
 	do {
687b17
 		ulong2bebytes(&params.head.offset[0], offset);
687b17
-		operation_len = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
687b17
+		operation_len = MIN(left, max_operation_len);
687b17
 		params.head.length = operation_len;
687b17
 		memcpy(params.buf, buf, operation_len);
687b17
 		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
687b17