-
Notifications
You must be signed in to change notification settings - Fork 61
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
Compatiblity layer with RustCrypto #192
base: main
Are you sure you want to change the base?
Conversation
7f68cb7
to
3e33f45
Compare
a68557d
to
230120d
Compare
Amazing amount of work 🤯 thank you for the patch, I'll do a deep-dive when I get a bit of time. One thing I'm wondering is if it makes more sense to have the extra functionality as a new crate, or as a module in the existing crate. We have something similar in EDIT: if we keep it as a separate crate maybe we can frame it as a generic abstractions crate as well - if we want to implement other nice-to-have functionality in the future, we can just chuck it in the same one, as a separate mod. |
I don't really have an opinion whether to make it a module (behind a feature flag) or an additional crate. What I know is that this is going to end up pulling a chunky part of rust-crypto and that dependency management is going to be tedious. I do intend to bring a similar abstraction over to For the background story of this effort, nixos folks (this includes @RaitoBezarius who chimed in earlier) are doing secureboot work, and intend to use rust to sign build artifacts (with both HSM and TPM, depending on the use-case). I do intend to continue supporting this in the foreseeable future. |
b7a3961
to
b00e7c5
Compare
066d6fa
to
2972f78
Compare
Happy new year! Anything we can do on our side to make this PR gets in a nice state for merge? :) |
f6998fc
to
bdec32f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the patch! I've read throug the non-test code and it seems like a great step forward to me. Left a few comments below, but overall I'd be happy to merge.
Regarding the massive delay - if either of you would be willing to join us on the Slack channel, please ping me directly there and I'll make time to look at changes/issues/etc. Unfortunately it's all too easy for things to slip between cracks 😞
cryptoki-rustcrypto/tests/15b05c4865410c6b3ff76a4e8f3d87276756bd0c.der
Outdated
Show resolved
Hide resolved
/// [`Rng`] is a PKCS#11-backed CSPRNG. | ||
pub struct Rng<S: SessionLike>(S); | ||
|
||
// TODO(baloo): check for CKF_RNG bit flag (CK_TOKEN_INFO struct -> flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this resolved, or will it result in a new issue once this is merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'll need to make an API change to session to get back the Pkcs11
object and get_token_info on it.
fn fill_bytes(&mut self, dest: &mut [u8]) { | ||
self.try_fill_bytes(dest) | ||
.expect("Cryptoki provider failed to generate random"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it there's no way to not implement this and have the user always deal with the potential error. That's quite unfortunate. Maybe a comment on this method would be good to warn of a potential panic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I think the "panic warninig" is part of the documentation of the interface:
This method should guarantee that dest is entirely filled with new data, and may panic if this is impossible (e.g. reading past the end of a file that is being used as the source of randomness).
Source: https://docs.rs/rand_core/latest/rand_core/trait.RngCore.html#tymethod.fill_bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a documentation for that panic on our Rng object.
pub enum Error { | ||
#[error("Cryptoki error: {0}")] | ||
Cryptoki(#[from] cryptoki::error::Error), | ||
|
||
#[error("Private key missing attribute: {0}")] | ||
MissingAttribute(AttributeType), | ||
|
||
#[error("RSA error: {0}")] | ||
Rsa(#[from] rsa::Error), | ||
|
||
#[error("Key not found")] | ||
MissingKey, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious - why have a different error struct per module? Seems like it could add some headaches if someone wants to use multiple crypto primitives in the same file, they'd have to import and rename them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. One Error type should be sufficient. ( ™️ )
(But seriously, it's not such a big crate to need so many Errors).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I go back and forth between "errors should be the most precise" and "dyn Error is enough for everyone". Looks like that day was the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a great idea and thanks for working on it... I expect to be in need of this kind of crate in the future so... thanks for your time and work! 🙏
fn fill_bytes(&mut self, dest: &mut [u8]) { | ||
self.try_fill_bytes(dest) | ||
.expect("Cryptoki provider failed to generate random"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I think the "panic warninig" is part of the documentation of the interface:
This method should guarantee that dest is entirely filled with new data, and may panic if this is impossible (e.g. reading past the end of a file that is being used as the source of randomness).
Source: https://docs.rs/rand_core/latest/rand_core/trait.RngCore.html#tymethod.fill_bytes
pub enum Error { | ||
#[error("Cryptoki error: {0}")] | ||
Cryptoki(#[from] cryptoki::error::Error), | ||
|
||
#[error("Private key missing attribute: {0}")] | ||
MissingAttribute(AttributeType), | ||
|
||
#[error("RSA error: {0}")] | ||
Rsa(#[from] rsa::Error), | ||
|
||
#[error("Key not found")] | ||
MissingKey, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. One Error type should be sufficient. ( ™️ )
(But seriously, it's not such a big crate to need so many Errors).
24d9148
to
7512207
Compare
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
45a1d80
to
af53442
Compare
This is another take on #158
The purpose is to bring a compatibility layer with rustcrypto and use the tools developed there (x509 signing, pkcs7/CMS, ocsp, ...) with a pkcs#11-backed HSM