Skip to contentSkip to conversation

opensc: fix private key import

PATCH New Jan Luebbe 1 participant 1 message Feb 2, 2023

lore
Share & tools
lore

Jan Luebbe

author
#0 lore raw

PATCH 1/1 opensc: fix private key import

Importing private keys into a PKCS#11 token is broken with OpenSC 0.23.0 and OpenSSL 3. Fix it by backporting the corresponding upstream fixes.

---
 ...1-pkcs11-tool-Fix-private-key-import.patch | 33 ++++++++++++
 ...g-more-information-on-OpenSSL-errors.patch | 54 +++++++++++++++++++
 .../recipes-support/opensc/opensc_0.23.0.bb   |  2 +
 3 files changed, 89 insertions(+)
 create mode 100644 meta-oe/recipes-support/opensc/files/0001-pkcs11-tool-Fix-private-key-import.patch
 create mode 100644 meta-oe/recipes-support/opensc/files/0002-pkcs11-tool-Log-more-information-on-OpenSSL-errors.patch
meta-oe/recipes-support/opensc/files/0001-pkcs11-tool-Fix-private-key-import.patch new file +33 -0
new file mode 100644
index 000000000000..e270a8e2e6c6
@@ -0,0 +1,33 @@
+From 6f868bbcd9e65447f459f74381c09d1e315a32f6 Mon Sep 17 00:00:00 2001
+From: Jakub Jelen <[email protected]>
+Date: Thu, 1 Dec 2022 20:08:53 +0100
+Subject: [PATCH 1/2] pkcs11-tool: Fix private key import
+
+Upstream-Status: Backport
+---
+ src/tools/pkcs11-tool.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c
+index aae205fe2cd6..cfee8526d5b0 100644
+--- a/src/tools/pkcs11-tool.c
++++ b/src/tools/pkcs11-tool.c
+@@ -3669,13 +3669,13 @@ parse_rsa_pkey(EVP_PKEY *pkey, int private, struct rsakey_info *rsa)
+ 		RSA_get0_factors(r, &r_p, &r_q);
+ 		RSA_get0_crt_params(r, &r_dmp1, &r_dmq1, &r_iqmp);
+ #else
+-		if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_FACTOR1, &r_d) != 1 ||
++		if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_D, &r_d) != 1 ||
+ 			EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_FACTOR1, &r_p) != 1 ||
+ 			EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_FACTOR2, &r_q) != 1 ||
+ 			EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT1, &r_dmp1) != 1 ||
+ 			EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT2, &r_dmq1) != 1 ||
+-			EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT3, &r_iqmp) != 1) {
+ 			util_fatal("OpenSSL error during RSA private key parsing");
++			EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_COEFFICIENT1, &r_iqmp) != 1) {
+ 		}
+ #endif
+ 		RSA_GET_BN(rsa, private_exponent, r_d);
+-- 
+2.30.2
+
meta-oe/recipes-support/opensc/files/0002-pkcs11-tool-Log-more-information-on-OpenSSL-errors.patch new file +54 -0

54 lines not on this page · raw message

meta-oe/recipes-support/opensc/opensc_0.23.0.bb +2 -0
index b0f147c798d0..f68107df87ab 100644
@@ -14,6 +14,8 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=cb8aedd3bced19bd8026d96a8b6876d7"
 #v0.21.0
 SRCREV = "5497519ea6b4af596628f8f8f2f904bacaa3148f"
 SRC_URI = "git://github.com/OpenSC/OpenSC;branch=master;protocol=https \
+           file://0001-pkcs11-tool-Fix-private-key-import.patch \
+           file://0002-pkcs11-tool-Log-more-information-on-OpenSSL-errors.patch \
           "
 DEPENDS = "virtual/libiconv openssl"
 
Signature · 1 line
2.30.2