Add pkcs11-module-default-slot-id cfg for default slot ID#536
Conversation
3dd2936 to
a564597
Compare
|
Looks reasonable but also requires changes to provider-pkcs11.7.md as well as at least one test I think (software tokens can expose many slots, shouldn't be too hard). |
Jakuje
left a comment
There was a problem hiding this comment.
Do you plan to get back to this PR any time soon to finalize it? I found one copy paste error, but otherwise I think it is going in the right direction!
a564597 to
631c354
Compare
I just fixed that typo and added docs but tests will take me a bit more time. I had a look and it seems like it has currently only single slot setup so might need some extending to allow adding setup for multiple slots with different pins and then somehow pass through the slot id so it can be used (e.g. SoftHSMv2 will re-assign the value so it needs to be fetched - possibly from the output message). Or maybe there is an easier way how to test it? |
Kryoptic can easily be configured to have as many slots as you want (each one with a different token), you just need to provide a config file that specifies them and initialize them. |
|
Here is a draft commit that adds multiple slots to the kryoptic setup (and initializes just one): Feel free to reuse it or adjust it to crate a test case. I do not exactly know how the problem you are solving would demonstrate so if you will need some help to put things together, please let me know. |
631c354 to
9e06cd7
Compare
9e06cd7 to
82e94bf
Compare
|
Just a quick update here that I put some initial setup for multiple sot with an initial C test for refreshing (after fork check), which is where I needed this setting of the default slot ID. This is still incomplete as the load key currently loads the key without calling verify (something that I need to figure out later). I just realised that I have got some other fixes to address this particular issue in a different way so this test could no longer test the actual functionality for default slot. So I plan to change the test as it might be done in an easier way through the import. Basically I could import new pub key and then just check that it's in the default slot. I will still need the current fork test for other changes so will just add it as part of other (future) PR. It means that it's still a draft and there will be some further clean up as well so don't bother with review yet as it will change. This note is also for me so I remember it when I'm back on this in the next few weeks. :) |
887ff0a to
4508607
Compare
|
I spent another chunk of time on this and getting this tested is actually a bit harder. First I tried the new approach with just importing the pubkey. This can be done in a couple of ways and the simplest seemed to be doing that during the match. It means using I thought about it and what I really need first is to somehow get EVP_DigestVerifyInit executed on public key that will have keymgmt pointing to pkcs11 provider. That imports the key (through The part that seems a bit harder is to get the public key keymgmt pointing to pkcs11 provider. At least it doesn't seem to work in test when using store load as used by testing |
|
Simply set propquery to "provider=pkcs11" in your tests and it should try to force operations to happen on the token. |
4508607 to
8bbefa6
Compare
|
Thanks. Using It actually doesn't store pub key after refresh so it's hitting slightly different flow - I will need to figure out the flow when the pub key gets stored though. I feel I'm quite close to it but don't have more time today so will look into it next month when I have got my next time slot on this. |
8bbefa6 to
493fe16
Compare
b31dd82 to
8c96dab
Compare
8c96dab to
08fbf3e
Compare
|
So I finally managed to get this to the working state. I decided to test just the actual setting of default slot. The default slot is used only in store_key which is called when storing pub key or private key. This actually does not happen very often and the most reliable / re-creatable case is using EVP_PKEY_fromdata which took me some time to realise. So the test needed extending the framework for multislot variant that needs to be separate because bunch of tests depend on the fact that there is just one slot. With this setup, the test just set the slot to the second one (be default provider picks the first one as default) and then imports pubkey using EVP_PKEY_fromdata which calls store_key and stores to the default slot. This is then verified using pkcs11-tool. I'm not sure why coverage test is failing. I tried locally with And that TLS test (other failure) might be a bit flaky and seems unrelated to this. |
The CI job will likely need to be updated to upload test artifacts on failure (which is not done now). The tls test in kryoptic sounds flaky. The faulure from the artifacts is: This is the test |
700b4bc to
cd56f76
Compare
Jakuje
left a comment
There was a problem hiding this comment.
just a nit for documentation, otherwise looks good.
Not sure whats up with the CI though
|
@bukka can you squash all commits that deal with tests? I see a lot of back and forth there and would rather collapse all dead-ends away |
cd56f76 to
3a7b6a0
Compare
|
@simo5 I squashed to a single commit which probably makes most sense as that multi slot setup should be introduced with some test that uses it. It's also rebased. |
| * and the following query excludes it */ | ||
| if ((sctx->default_slot == CK_UNAVAILABLE_INFORMATION) | ||
| && (prov_default_slotid == CK_UNAVAILABLE_INFORMATION | ||
| || prov_default_slotid == slot->id) |
There was a problem hiding this comment.
Why did you clamp this check down here?
This code is meant to avoid using softokn first slot whch is usually a read-only slot and it also usually not what you'd mark as default.
There was a problem hiding this comment.
This just adds an extra condition to make sure that the specified provider default slot is set only if it's a valid slot id (meaning if there is any slot with such ID). The softokn conditions still applies here as it's AND. What am I missing?
There was a problem hiding this comment.
I would think that if a slot is set in configuration as the default it should be used regardless of other considerations ?
|
|
||
| setup_script=find_program('setup.sh') | ||
| all_suites=['softokn', 'softhsm', 'kryoptic', 'kryoptic.nss'] | ||
| multi_suites=['kryoptic.multislot'] |
There was a problem hiding this comment.
Doesn't look like you really need to change around these definitions, given kryoptic.multislot is used only in one test you can simply use it here, and leave "all_suites" as it is. It will make more clear that kryoptic.multislot is special and not one of the generic suites to run.
This will cause less churn as well.
There was a problem hiding this comment.
Yeah sure I can change it if you prefer.
Just to be clear, all will not really mean all then. Also it might be useful to also add softhsm.multislot in the future so there could be more multislot ones.
But as I said I don't really mind to change it. This was just my thinking why I did it this way. Let me know if you still want me to change and I will do that.
There was a problem hiding this comment.
yes I prefer to keep the change minimal for now, and only add multislot to "all" if it really becomes more widely used.
There are use cases when one wants to select the default slot id (especially when the first slot ID is not convenient for this purpose) which is used for example for storing public keys. As part of this change, the test framework was extended to allow testing of multi slot scenarios. Signed-off-by: Jakub Zelenka <jakub.openssl@gmail.com>
3a7b6a0 to
fb3cd8a
Compare
bukka
left a comment
There was a problem hiding this comment.
Oh I replied 2 weeks ago but forgot to submit so here are my replies - sorry for the delay :)
| * and the following query excludes it */ | ||
| if ((sctx->default_slot == CK_UNAVAILABLE_INFORMATION) | ||
| && (prov_default_slotid == CK_UNAVAILABLE_INFORMATION | ||
| || prov_default_slotid == slot->id) |
There was a problem hiding this comment.
This just adds an extra condition to make sure that the specified provider default slot is set only if it's a valid slot id (meaning if there is any slot with such ID). The softokn conditions still applies here as it's AND. What am I missing?
|
|
||
| setup_script=find_program('setup.sh') | ||
| all_suites=['softokn', 'softhsm', 'kryoptic', 'kryoptic.nss'] | ||
| multi_suites=['kryoptic.multislot'] |
There was a problem hiding this comment.
Yeah sure I can change it if you prefer.
Just to be clear, all will not really mean all then. Also it might be useful to also add softhsm.multislot in the future so there could be more multislot ones.
But as I said I don't really mind to change it. This was just my thinking why I did it this way. Let me know if you still want me to change and I will do that.
| cases, it allows you to ensure that pkcs11-module-token-pin points to the | ||
| expected slot. | ||
|
|
||
| If no value is specified, the first listed slot is used. |
There was a problem hiding this comment.
nit: The logic for the selection of the slot is more complicated -- the slot needs to be initialized, it needs to require a login and it can not be locked:
&& (slot->token.flags & CKF_LOGIN_REQUIRED)
&& (slot->token.flags & CKF_TOKEN_INITIALIZED)
&& (!(slot->token.flags & CKF_USER_PIN_LOCKED))) {
I think it would be better to be a bit more specific here, for example:
| If no value is specified, the first listed slot is used. | |
| If no value is specified, the first slot listed by the token, that is initialized and does not have a PIN locked is used. |
(I do not insist of this wording -- but I would prefer to have the documentation more specific)
Description
There are use cases when one wants to select the default slot id (especially when the first slot ID is not convenient for this purpose) which is used for example for storing public keys.
Checklist
Reviewer's checklist: