[OpenSC/libp11] Unable to enumerate public keys
Alexandre Gonzalo via Opensc-devel <[email protected]> Thu, 27 Oct 2022 15:23:35 +0000
| Newsgroups | gmane.comp.encryption.opensc.devel |
|---|---|
| Message-ID | <CWXP123MB41366AADDCFDCF8E67B522F9F6339@CWXP123MB4136.GBRP123.PROD.OUTLOOK.COM> |
--===============5534232556055549288==
Content-Language: en-US
Content-Type: multipart/alternative;
boundary="_000_CWXP123MB41366AADDCFDCF8E67B522F9F6339CWXP123MB4136GBRP_"
--_000_CWXP123MB41366AADDCFDCF8E67B522F9F6339CWXP123MB4136GBRP_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello OpenSC team,
I have an issue with the latest version of the libp11-0.4.12.
It was working fine with the previous version.
In my test, I am creating EC, EC_EDWARDS and EC_MONTGOMERY keys with the pk=
cs11-tool.
I can list the objects as you can see below:
Private Key Object; EC
ID: 30
Usage: sign
Access: sensitive, always sensitive, extractable, local
Unique ID: 1bc0000866ac3ec4346a4a8a753fd396fec524fc2d4542b8d20a348ecdafd=
8e97febccebd40f55232456ab73fea4ede820d409d719153c1bef5f3ba76b0263e8
Private Key Object; EC_EDWARDS
ID: 31
Usage: sign
Access: sensitive, always sensitive, extractable, local
Unique ID: b80251e75b7c07aa5fd149ea4f408d6b9986de9ed4217f3ded957d9f5d6e4=
8c2cd79c09280f8073efe0289a17e83f18942c7c28fa3830638a0ade67f823cc315
Public Key Object; EC EC_POINT 256 bits
EC_POINT: 0441048a17deb5642b21ee7c6582cf0ccef7d3404fb2aa2174e9cab525bd9=
ebf57a576ba044683fe5331434ca19a9d6c7a1a1122fc482bc1b5e68a0383db1e91575538
EC_PARAMS: 06082a8648ce3d030107
ID: 30
Usage: verify
Access: local
Unique ID: b4bda529c0274024287613f2ea0c7968cff6a29b1eaefa32d0dbf3a22b094=
fbdd8a68a8b0213553cfa9e5877d66d9a131c20de1d0081b1628f9fc859bfa4d2b6
Public Key Object; EC_MONTGOMERY EC_POINT 32 bytes
EC_POINT: 04208feef18f8f5f6e8b3eb285244145fd5d200305399e31a3bfa6dd38fcf=
f7b6620
EC_PARAMS: 130a63757276653235353139 (x25519)
ID: 32
Usage: verify
Access: local
Unique ID: 8d207940a60058acd89251d4da407b48ed87cc7630266ab731a1e4567bed1=
ff164767da192918f4fcbf85a99ace88c4288e9d94aa8990b6e2f65e85d084e670d
Private Key Object; EC_MONTGOMERY
ID: 32
Usage: sign
Access: sensitive, always sensitive, extractable, local
Unique ID: 99c9f7f54d8952174c6e02b9989c0120f3e1e413cd2582320b8ca74369011=
b23ad776699924adb389c2c9591eae4d93b9a55ea26662b7391d61e41c90fc9e7d7
Public Key Object; EC_EDWARDS EC_POINT 32 bytes
EC_POINT: 042003a700641101974ecb5e4684984b2990e7fe5fea2c16708a465bc8f1d=
541e13f
EC_PARAMS: 130c656477617264733235353139 (ed25519)
ID: 31
Usage: verify
Access: local
Unique ID: 1755adc73f371b563a78ddf6189c7cf2078edd05cf18c23504e39c510ff56=
e804a8fbc1994b31c869b60c66bf71a12a55a737cd5587f0a8cf5848bd532fa1238
But when I am trying to verify a signature with OpenSSL, it is not able to =
find my public key.
engine "pkcs11" set.
Unable to enumerate public keys
Unable to enumerate public keys
The public key was not found at: pkcs11:id=3D0
PKCS11_load_public_key returned NULL
cannot load key file from engine
484453151992:error:80068065:pkcs11 engine:ctx_load_pubkey:object not found:=
/OpenSC_libp11/Out/Code/src/eng_back.c:871:
484453151992:error:26097081:engine routines:ENGINE_load_public_key:failed l=
oading public key:crypto/engine/eng_pkey.c:108:
unable to load key file
That's because in pkcs11_init_key() we now call pkcs11_object_from_handle()=
but this function does not support the EC_EDWARDS and EC_MONTGOMERY types.
So, the function returns an error, and the enumeration is stopped.
I suggest that in that case, we don't check the error returned by pkcs11_in=
it_key() as you can see the below patch.
diff --git a/src/p11_key.c b/src/p11_key.c
index ec7f279..c849808 100644
--- a/src/p11_key.c
+++ b/src/p11_key.c
@@ -605,8 +605,7 @@ static int pkcs11_next_key(PKCS11_CTX_private *ctx, PKC=
S11_SLOT_private *slot,
if (count =3D=3D 0)
return 1;
- if (pkcs11_init_key(slot, session, obj, type, NULL))
- return -1;
+ pkcs11_init_key(slot, session, obj, type, NULL);
return 0;
}
Please, let me know if I should create a pull request.
Regards,
Alexandre.
Trustonic SAS - 535 route de Lucioles, Les Aqueducs Batiment 2, Sophia Anti=
polis 06560 Valbonne, France - SAS au capital de 3 038 000EUR - RCS Grasse =
- SIRET 480 011 998 00055 - TVA intracommunautaire : FR02 480 011 998
--_000_CWXP123MB41366AADDCFDCF8E67B522F9F6339CWXP123MB4136GBRP_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof">
Hello OpenSC team,</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0">
I have an issue with the latest version of the libp11-0.4.12.</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0">
It was working fine with the previous version.</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0">
<br>
</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted2 ContentPasted3">
In my test, I am creating EC, EC_EDWARDS and EC_MONTGOMERY keys w=
ith the pkcs11-tool.</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0">
I can list the objects as you can see below:</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0">
<br>
</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1">
<i>Private Key Object; EC</i>
<div class=3D"ContentPasted1"><i> ID: 30<=
/i></div>
<div class=3D"ContentPasted1"><i> Usage: sign</i>=
</div>
<div class=3D"ContentPasted1"><i> Access: sensitive, al=
ways sensitive, extractable, local</i></div>
<div class=3D"ContentPasted1"><i> Unique ID: 1bc0000866ac3ec434=
6a4a8a753fd396fec524fc2d4542b8d20a348ecdafd8e97febccebd40f55232456ab73fea4e=
de820d409d719153c1bef5f3ba76b0263e8</i></div>
<div class=3D"ContentPasted1"><i>Private Key Object; EC_EDWARDS</i></div>
<div class=3D"ContentPasted1"><i> ID: 31<=
/i></div>
<div class=3D"ContentPasted1"><i> Usage: sign</i>=
</div>
<div class=3D"ContentPasted1"><i> Access: sensitive, al=
ways sensitive, extractable, local</i></div>
<i> Unique ID: b80251e75b7c07aa5fd149ea4f408d6b9986de9ed4217f3d=
ed957d9f5d6e48c2cd79c09280f8073efe0289a17e83f18942c7c28fa3830638a0ade67f823=
cc315<br>
</i></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4">
<i>Public Key Object; EC EC_POINT 256 bits</i>
<div class=3D"ContentPasted4"><i> EC_POINT: 0441048a17deb5642b=
21ee7c6582cf0ccef7d3404fb2aa2174e9cab525bd9ebf57a576ba044683fe5331434ca19a9=
d6c7a1a1122fc482bc1b5e68a0383db1e91575538</i></div>
<div class=3D"ContentPasted4"><i> EC_PARAMS: 06082a8648ce3d0301=
07</i></div>
<div class=3D"ContentPasted4"><i> ID: 30<=
/i></div>
<div class=3D"ContentPasted4"><i> Usage: verify</=
i></div>
<div class=3D"ContentPasted4"><i> Access: local</i></di=
v>
<div class=3D"ContentPasted4"><i> Unique ID: b4bda529c027402428=
7613f2ea0c7968cff6a29b1eaefa32d0dbf3a22b094fbdd8a68a8b0213553cfa9e5877d66d9=
a131c20de1d0081b1628f9fc859bfa4d2b6</i></div>
<div class=3D"ContentPasted4"><i>Public Key Object; EC_MONTGOMERY EC_=
POINT 32 bytes</i></div>
<div class=3D"ContentPasted4"><i> EC_POINT: 04208feef18f8f5f6e=
8b3eb285244145fd5d200305399e31a3bfa6dd38fcff7b6620</i></div>
<div class=3D"ContentPasted4"><i> EC_PARAMS: 130a63757276653235=
353139 (x25519)</i></div>
<div class=3D"ContentPasted4"><i> ID: 32<=
/i></div>
<div class=3D"ContentPasted4"><i> Usage: verify</=
i></div>
<div class=3D"ContentPasted4"><i> Access: local</i></di=
v>
<i> Unique ID: 8d207940a60058acd89251d4da407b48ed87cc7630266ab7=
31a1e4567bed1ff164767da192918f4fcbf85a99ace88c4288e9d94aa8990b6e2f65e85d084=
e670d<br>
</i></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5">
<i>Private Key Object; EC_MONTGOMERY</i></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5">
<div class=3D"ContentPasted5"><i> ID: 32<=
/i></div>
<div class=3D"ContentPasted5"><i> Usage: sign</i>=
</div>
<div class=3D"ContentPasted5"><i> Access: sensitive, al=
ways sensitive, extractable, local</i></div>
<i> Unique ID: 99c9f7f54d8952174c6e02b9989c0120f3e1e413cd258232=
0b8ca74369011b23ad776699924adb389c2c9591eae4d93b9a55ea26662b7391d61e41c90fc=
9e7d7<br>
</i></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<i>Public Key Object; EC_EDWARDS EC_POINT 32 bytes</i>
<div class=3D"ContentPasted6"><i> EC_POINT: 042003a70064110197=
4ecb5e4684984b2990e7fe5fea2c16708a465bc8f1d541e13f</i></div>
<div class=3D"ContentPasted6"><i> EC_PARAMS: 130c65647761726473=
3235353139 (ed25519)</i></div>
<div class=3D"ContentPasted6"><i> ID: 31<=
/i></div>
<div class=3D"ContentPasted6"><i> Usage: verify</=
i></div>
<div class=3D"ContentPasted6"><i> Access: local</i></di=
v>
</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<i> Unique ID: 1755adc73f371b563a78ddf6189c7cf2078edd05cf18c235=
04e39c510ff56e804a8fbc1994b31c869b60c66bf71a12a55a737cd5587f0a8cf5848bd532f=
a1238</i><br>
</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<i><br>
</i></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
But when I am trying to verify a signature with OpenSSL, it is not able to =
find my public key.</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<i><br>
</i></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<i class=3D"ContentPasted7">engine "pkcs11" set.
<div class=3D"ContentPasted7">Unable to enumerate public keys</div>
<div class=3D"ContentPasted7">Unable to enumerate public keys</div>
<div class=3D"ContentPasted7">The public key was not found at: pkcs11:id=3D=
0</div>
<div class=3D"ContentPasted7">PKCS11_load_public_key returned NULL</div>
<div class=3D"ContentPasted7">cannot load key file from engine</div>
<div class=3D"ContentPasted7">484453151992:error:80068065:pkcs11 engine:ctx=
_load_pubkey:object not found:/OpenSC_libp11/Out/Code/src/eng_back.c:871:</=
div>
<div class=3D"ContentPasted7">484453151992:error:26097081:engine routines:E=
NGINE_load_public_key:failed loading public key:crypto/engine/eng_pkey.c:10=
8:</div>
unable to load key file<br>
</i></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<span class=3D"ContentPasted7"><br>
</span></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<span class=3D"ContentPasted7 ContentPasted8 ContentPasted9">That's because=
in pkcs11_init_key() we now call pkcs11_object_from_handle() but=
this function does not support the <span style=3D"background-color:rg=
b(255, 255, 255)" class=3D"ContentPasted10">EC_EDWARDS
and <span class=3D"ContentPasted11" style=3D"">EC_MONTGOMERY types.</=
span></span></span></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<span class=3D"ContentPasted7 ContentPasted8 ContentPasted9"><span style=3D=
"background-color:rgb(255, 255, 255)" class=3D"ContentPasted10"><span class=
=3D"ContentPasted11" style=3D"">So, the function returns an error, and the =
enumeration is stopped.</span></span></span></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<span class=3D"ContentPasted7 ContentPasted8 ContentPasted9"><span style=3D=
"background-color:rgb(255, 255, 255)" class=3D"ContentPasted10"><span class=
=3D"ContentPasted11" style=3D"">I suggest that in that case, we don't check=
the error returned by <span style=3D"background-color:rgb(255, 255, 2=
55);display:inline !important" class=3D"ContentPasted13">pkcs11_init_key()
as you can see the below patch.</span></span></span></span></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<br>
</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<span class=3D"ContentPasted7 ContentPasted8 ContentPasted9"><span style=3D=
"background-color:rgb(255, 255, 255)" class=3D"ContentPasted10"><span class=
=3D"ContentPasted11 ContentPasted12" style=3D"">diff --git a/src/p11_key.c =
b/src/p11_key.c
<div class=3D"ContentPasted12">index ec7f279..c849808 100644</div>
<div class=3D"ContentPasted12">--- a/src/p11_key.c</div>
<div class=3D"ContentPasted12">+++ b/src/p11_key.c</div>
<div class=3D"ContentPasted12">@@ -605,8 +605,7 @@ static int pkcs11_next_k=
ey(PKCS11_CTX_private *ctx, PKCS11_SLOT_private *slot,</div>
<div class=3D"ContentPasted12"> if (count =3D=3D=
0)</div>
<div class=3D"ContentPasted12"> &n=
bsp; return 1;</div>
<div class=3D"ContentPasted12"> </div>
<div class=3D"ContentPasted12">- if (pkcs11_init_key(s=
lot, session, obj, type, NULL))</div>
<div class=3D"ContentPasted12">- =
return -1;</div>
<div class=3D"ContentPasted12">+ pkcs11_init_key(slot,=
session, obj, type, NULL);</div>
<div class=3D"ContentPasted12"> </div>
<div class=3D"ContentPasted12"> return 0;</div>
<div class=3D"ContentPasted12"> }</div>
<div class=3D"ContentPasted12"><br>
</div>
<div class=3D"ContentPasted12">Please, let me know if I should create a pul=
l request.</div>
<br>
</span></span></span></div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
Regards,</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
Alexandre.</div>
<div style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class=
=3D"elementToProof ContentPasted0 ContentPasted1 ContentPasted4 ContentPast=
ed5 ContentPasted6">
<i><br>
</i></div>
<br>
<div style=3D"font-size:9pt; font-family: 'Calibri',sans-serif;">
<p style=3D"font-size:7pt; line-height:9pt; color:#bebebe; font-family: 'Ca=
libri', Arial, Verdana, serif;">
Trustonic SAS - 535 route de Lucioles, Les Aqueducs Batiment 2, Sophia Anti=
polis 06560 Valbonne, France – SAS au capital de 3 038 000€ - R=
CS Grasse – SIRET 480 011 998 00055 - TVA intracommunautaire : FR02 4=
80 011 998</p>
</div>
</body>
</html>
--_000_CWXP123MB41366AADDCFDCF8E67B522F9F6339CWXP123MB4136GBRP_--
--===============5534232556055549288==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============5534232556055549288==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Opensc-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensc-devel
--===============5534232556055549288==--