-
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
Key Usage Limit missing #30
Comments
Also when switching module to opensc ( I guess I'm using correct one from this repository (
|
There is currently no mechanism to query CKA_SC_HSM_KEY_USE_COUNTER. CKA_SC_HSM_KEY_USE_COUNTER can only be used to set the key use counter in C_GenerateKey() or C_GenerateKeyPair(). Unfortunately that code had a bug when used on non-32 bit systems. I've posted a fix a couple of minutes ago. |
@CardContact Nice! Thanks for that! I have compiled If you don't mind I have another question. Can you edit this value by using
|
No, you can't change the key use counter. It's initial value is set during key creation and decremented with each crypto operation performed with that key. If the use counter is expired, the key can no longer be used. You could probably use C_SetAttributeValue() and read back with C_GetAttributeValue(), but that has only an effect on the attribute stored in the PKCS#11 module, not on the device. The key use counter is a mechanism inside the device. You can also not export a key with a key use counter, as otherwise you could reset the counter by importing the key with the initial value. The key use counter serves two purposes: You can limit the number of times the key can be used or you can use the key use counter as auditing measure. |
@CardContact Thank you very much! That is a perfect explanation! One last question :) ... I want to sign and verify data using |
I guess it's coming from here: sc-hsm-embedded/src/pkcs11/p11mechanisms.c Line 1124 in e830573
But not sure why ... |
I have found that my compiled version didn't have support for libcrypto. I've fixed it and recompiled with libcrypto support but still getting |
Forgot to |
@stoprocent could you maybe share some example C code for creating a keypair with a key use counter? My use case is the same as yours, giving someone else a HSM with a keypair that only allows a limited amount of signings. |
@CardContact could you point me to documentation on how to set this up for RSA or EC encryption/signing? |
Currently the only way to generate a key with a key use counter is by using a Smart Card Shell script:
|
Is there a documented way how this setKeyUseCounter() is represented in an APDU? |
Yes, you can find that information in chapter 5.5.2 of the SmartCard-HSM User Manual. It is basically DO '90' in C-Data of the GENERATE ASYMMETRIC KEY PAIR / GENERATE SYMMETRIC KEY command. All manuals can be found in the CDN (Registration required). |
Hi
I bought just recently Nitrokey HSM2 and I wanted to validate a few things on it. I wanted to create a keypair with Key usage limit over pcks11 but that didnt work. I have looked up attributes to use from here: https://github.com/CardContact/sc-hsm-embedded/blob/master/src/sc-hsm/sc-hsm-pkcs11.h. I was able to create a key but couldn't set the key use limit. I then tried using
scsh3
and modifiedkeymanager.js
to input key limit and it worked.I was able to see it in
scsh3
and also after performing more signing operations than specified limit I was getting errors.I then wrote a script to dump every attribute from objects using
pkcs11js
library and this is what im getting:According to your spec Key Use Limit should be at
0x80000108
. But I cannot see this at any object. Am I doing something wrong?Edit:
Also
CKA_SC_HSM_ALGORITHM_LIST
which I have specified and is visible inscsh3
is missing from pcks11 attributes.The text was updated successfully, but these errors were encountered: