I’m trying to import an EC key into my new Nitrokey Start using a C# application with the pkcs#11Interop library and OpenSC but I get a CKR_GENERAL_ERROR as a result. What am I missing or doing wrong?
The pkcs11-spy.log looks like this: (I replaced the key value in CKA_VALUE from the log entry for obvious reasons )
12: C_OpenSession
P:20088; T:26324 2024-11-14 13:25:13.477
[in] slotID = 0x4
[in] flags = 0x6
[in] pApplication = 0000000000000000
[in] Notify = 0000000000000000
[out] *phSession = 0x5fb130
Returned: 0 CKR_OK
13: C_Login
P:20088; T:26324 2024-11-14 13:25:13.478
[in] hSession = 0x5fb130
[in] userType = CKU_SO
[in] pPin[ulPinLen] 00000268365e6358 / 8
00000000 31 32 33 34 35 36 37 38 12345678
Returned: 0 CKR_OK
14: C_CreateObject
P:20088; T:26324 2024-11-14 13:25:13.497
[in] hSession = 0x5fb130
[in] pTemplate[9]:
CKA_CLASS CKO_PRIVATE_KEY
CKA_KEY_TYPE CKK_EC
CKA_LABEL 00000268005dbc90 / 0
CKA_ID 00000268005dbca0 / 2
00000000 01 02
CKA_TOKEN True
CKA_SENSITIVE True
CKA_DERIVE True
CKA_EC_PARAMS 00000268025b2290 / 10
00000000 06 08 2A 86 48 CE 3D 03 01 07
CKA_VALUE 00000268025700d0 / 32
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Returned: 5 CKR_GENERAL_ERROR
The key has been generated with BouncyCastle. It is a SecP256R1Curve key:
Key algorithm: EC
Curve name: Org.BouncyCastle.Math.EC.Custom.Sec.SecP256R1Curve
Key type identifier: 1.2.840.10045.3.1.7
I tried with user login as well as with admin (SO) login.
I can generate and import an EC key using GPG as described in the Nitrokey manual. So the Nitrokey Start is working fine.
Do I miss anything in my pkcs#11 key object?
Do I need a special preparation/initialisation of my Nitrokey Start?
The error message CKR_GENERAL_ERROR is not really helpful.