-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CKR_GENERAL_ERROR (0x5) on object read #69
Comments
How is the key generated? Edit: seems an outdated version of OpenSC. Try to use version 0.26 |
It was imported following the method described in this comment Here is key itself, if needed
didn't help. |
I am using this script and it works:
Also
|
@polhenarejos interesting. |
No, it wasn't. Can you try the snippet? To isolate the problem. Perhaps it's the securelock. |
I updated the script with SecureLock2 and still works. Can you try it? It is the same as the other comment. from picohsm import PicoHSM
from cryptography.hazmat.primitives.asymmetric import ec
from binascii import unhexlify
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
import platform
import sys
class SecureLock2:
def __init__(self, picohsm, secretkey):
self.picohsm = picohsm
self.secretkey = secretkey
def mse(self):
sk = ec.generate_private_key(ec.SECP256R1())
pn = sk.public_key().public_numbers()
self.__pb = sk.public_key().public_bytes(Encoding.X962, PublicFormat.UncompressedPoint)
ret = self.picohsm.send(cla=0x80, command=0x64, p1=0x3A, p2=0x01, data=list(self.__pb))
pk = ec.EllipticCurvePublicKey.from_encoded_point(ec.SECP256R1(), bytes(ret))
shared_key = sk.exchange(ec.ECDH(), pk)
xkdf = HKDF(
algorithm=hashes.SHA256(),
length=12+32,
salt=None,
info=self.__pb
)
kdf_out = xkdf.derive(shared_key)
self.__key_enc = kdf_out[12:]
self.__iv = kdf_out[:12]
def encrypt_chacha(self, data):
chacha = ChaCha20Poly1305(self.__key_enc)
ct = chacha.encrypt(self.__iv, data, self.__pb)
return ct
def unlock_device(self):
ct = self.get_skey()
self.picohsm.send(cla=0x80, command=0x64, p1=0x3A, p2=0x03, data=list(ct))
def _get_key_device(self):
return self.secretkey
def get_skey(self):
self.mse()
ct = self.encrypt_chacha(self._get_key_device())
return ct
def enable_device_aut(self):
ct = self.get_skey()
self.picohsm.send(cla=0x80, command=0x64, p1=0x3A, p2=0x02, data=list(ct))
def disable_device_aut(self):
ct = self.get_skey()
self.picohsm.send(cla=0x80, command=0x64, p1=0x3A, p2=0x04, p3=list(ct))
curve=ec.SECP256K1
secret_key=unhexlify('7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6')
pkey = ec.derive_private_key(
int.from_bytes(secret_key, byteorder='big'),
curve(), # Curve used in Ethereum
)
DEFAULT_DKEK = bytes([0x1] * 32)
print(pkey)
device = PicoHSM()
device.initialize(dkek_shares=1)
device.import_dkek(DEFAULT_DKEK)
key_id = device.import_key(pkey, dkek=DEFAULT_DKEK)
print(key_id)
pubkey = device.public_key(key_id, param=curve().name)
print(pubkey)
slck = SecureLock2(device,secret_key)
slck.enable_device_aut()
slck.unlock_device()
pubkey = device.public_key(key_id, param=curve().name)
print(pubkey) BTW, note that the log you posted is doing an ECDSA signature (4 attempts), nothing related with getting the pubkey. So what is failing in the log is the signature command.
If you want the log generated by
|
Hi!
btw, what version of pkcs11-tool do you use? |
Hi!
what version of pkcs11-tool do you use? Btw, when I do RAW ECDSA
At the end of your code, I get this
what am I doing wrong? |
I use OpenSC v0.26 EC_RAW requires data previously hashed. The used hash is derived from the length of data. Is the data 32 bytes length? |
@polhenarejos Just updated to OpenSC v0.26, with no luck. Btw, does your script interact with Pico from OS (which one do you use?) directly or from docker? |
After inspecting the log, I see the problem but not the cause. Your PCSC is disconnecting the session once it recovers all keys and then try log in. But since it has been disconnected, log in fails and raises the error.
and with login first
I guess it won't be any difference, but let's try. About signature, I confirm it fails. I'll check why later. |
Signed-off-by: Pol Henarejos <[email protected]>
Can you try latest nightly development build? It should be fixed. You would need to nuke it first. |
Patched fixed this issue.
works fine
same error. (key was initialized with pin 123456, so here is valid pin) btw, during signing signing, when pin is important, I get the same error. |
There's always a default PIN (648219). Edit: why the second command fails? I do not see any error or failing, it just exits with error code 1 but nothing strange is there, all the commands terminate correctly. |
Version: current state of development branch
Board: Pico
Pico-hsm with enabled SecureLock and unlocked.
Output on
/usr/local/bin/pkcs11-tool -O
when I try to read public key with
I get this (log with APDU commands)
The text was updated successfully, but these errors were encountered: