I’m trying to understand how are ordered the keys generated from the PIV command line.
I have generated every possible key on my Nitrokey 3 using this command (82-95 + 9a, 9c, 9d, 9e):
nitropy nk3 piv --experimental generate-key --key XX --algo rsa2048
Here is my code to list the key ids using python-pkcs11:
from pkcs11 import ObjectClass, Attribute, KeyType, lib
lib = lib("C:\Program Files\OpenSC Project\OpenSC\pkcs11\opensc-pkcs11.dll")
token = lib.get_token(token_serial=b"b3164da64aaa4d8e")
with token.open(user_pin="123456") as session:
pub_keys = session.get_objects(
{
Attribute.CLASS: ObjectClass.PUBLIC_KEY,
Attribute.KEY_TYPE: KeyType.RSA,
}
)
for pub_key in pub_keys:
print(pub_key[Attribute.LABEL])
print(pub_key[Attribute.ID])
Here is the output:
PIV AUTH pubkey
b’\x01’
SIGN pubkey
b’\x02’
KEY MAN pubkey
b’\x03’
Retired KEY MAN 1
b’\x05’
Retired KEY MAN 2
b’\x06’
Retired KEY MAN 3
b’\x07’
Retired KEY MAN 4
b’\x08’
Retired KEY MAN 5
b’\t’
Retired KEY MAN 6
b’\x10’
Retired KEY MAN 7
b’\x11’
Retired KEY MAN 8
b’\x12’
Retired KEY MAN 9
b’\x13’
Retired KEY MAN 10
b’\x14’
Retired KEY MAN 11
b’\x15’
Retired KEY MAN 12
b’\x16’
Retired KEY MAN 13
b’\x17’
Retired KEY MAN 14
b’\x18’
Retired KEY MAN 15
b’\x19’
Retired KEY MAN 16
b’ ’
Retired KEY MAN 17
b’!’
Retired KEY MAN 18
b’"’
Retired KEY MAN 19
b’#’
Retired KEY MAN 20
b’$’
CARD AUTH pubkey
b’\x04’
First, when I print their ids, they are different than the argument --key.
Then, why is id 9 = b’\t’ and not b’\x09’ when id 10 is b’\x10’ and not b’\n’
It seems to be hexadecimal until 9 and then turn to decimal written hexadecimal.
Is this an issue with the firmware or with python-pkcs11 ?
It may be another topic but I can decrypt messages with every of those key except b’\x04’. Is this id special ?