Skip to content

Commit 57f91a5

Browse files
Correct X.509 EC pubkey extraction logic
1 parent 9ab417c commit 57f91a5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkcs11/util/x509.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Certificate handling utilities for X.509 (SSL) certificates.
33
"""
44

5+
from asn1crypto.core import OctetString
56
from asn1crypto.x509 import Certificate
67

78
from pkcs11.constants import Attribute, CertificateType, ObjectClass
@@ -55,6 +56,10 @@ def decode_x509_public_key(der):
5556
elif key_type is KeyType.EC:
5657
params = key_info["algorithm"]["parameters"].dump()
5758

59+
# bytes(key_info['public_key']) returns the binary encoding
60+
# of the EC point itself (decoded from its BitString representation in X.509),
61+
# but PKCS#11 expects this as a DER OctetString.
62+
key = OctetString(key).dump()
5863
attrs.update(
5964
{
6065
Attribute.EC_PARAMS: params,

0 commit comments

Comments
 (0)