-
Notifications
You must be signed in to change notification settings - Fork 141
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
Build SignedData CMS (and PKCS #7) #1051
Conversation
See also #1045 where we are discussing the future of the |
pkcs7/src/builder.rs
Outdated
/// This method returns a `ContentInfo` of type `signedData`. After this call, the builder cannot | ||
/// be used any more. However, as the signature(s) are stored in the builder, the builder object | ||
/// must be kept until the message is dropped. | ||
pub fn build(&'s mut self) -> Result<ContentInfo<'s>> { |
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.
Just wondering, would it make sense to reuse the Builder
trait from x509-cert
, it's a dependency already.
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.
This would also hold for CertificateBuilder
, right?
As for the PKCS #7 builder: how would we handle multiple signers? My current solution is to add a SignerInfo
including the signature with each call of SignedDataBuilder::sign()
. Idea: I could possibly rename sign()
to add_signer()
and just add the SignerInfo
without the signature. The signatures would then be calculated when building the message with SignedDataBuilder::build()
.
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.
Yeah, I guess you would need an owned structure to be able to use it.
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.
@baloo I'm currently moving my implementations to the cms
crate, which uses owned types. It looks like I will be able to reuse your Builder
trait for the SignerInfo
objects. 🙂
Yes, I will definitely check the cms crate. But first I'd like to solve my lifetime problem. |
@bkstein the https://docs.rs/cms/0.2.1/cms/content_info/struct.ContentInfo.html |
I had a look into the |
@bkstein some past discussion here: #765 We ended up moving many of the crates to use all owned types. This makes things like builders easier (as you are experiencing), but also makes one-pass deserialization from PEM possible. The |
That sounds reasonable to me, too. The only difference between CMS and PKCS #7 I could find ist the coding of encapsulated content (RFC 5652, 5.2.1) and that should be manageable. |
Yes, I worked exactly on this during the last week. But I'm not ready, yet. |
I moved the code from crate pkcs7 (which is deprecated) to cms. I used |
Unless I'm missing something, all you're doing is calling it before That's unnecessary, as |
I added |
That still looks like a newtype of I still don't see why you need |
pkcs7/src/signer_info.rs
Outdated
@@ -15,12 +15,12 @@ use x509_cert::{ | |||
/// ```text | |||
/// SignedAttributes ::= SET SIZE (1..MAX) OF Attribute | |||
/// ``` | |||
type SignedAttributes<'a> = SetOfVec<Attribute>; | |||
pub type SignedAttributes<'a> = SetOfVec<Attribute>; |
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 believe changes in pkcs7 need to be dropped (deprecated).
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.
Right, I will check pkcs7 for remainders of my changes.
looks great! Thank you for doing that! |
@bkstein can you split out the |
Sure, I already expected this 🙂. |
We also merged #1071 this weekend which bring back the |
Co-authored-by: Arthur Gautier <superbaloo+registrations.github@superbaloo.net>
Co-authored-by: Arthur Gautier <superbaloo+registrations.github@superbaloo.net>
Co-authored-by: Arthur Gautier <superbaloo+registrations.github@superbaloo.net>
Just realized, that resolving does not automatically accept the suggested changes. 🙄 |
we'll still need you to send the Sorry for the extra work. |
I checked the |
(lastly, I think we'll want you to squash those commits if you could) |
@baloo we use squash-and-merge so we don't depend on developers to squash their own PRs |
Sorry I missed this request somehow last month (was very busy then and just missed it). I reviewed now in prep of reviewing the EnvelopedData changes and had a couple of comments. None of this is essential (though fixing the test case probably ought be done). SignerInfoBuilder.assemble
SignedDataBuilder.build
Test comments
Questions
Nits
|
@carl-wallace Thanks for reviewing this. I have some questions/remarks. SignedDataBuilder.build/assemble Could you give an example, how you would interrogate the info? Test comments
Questions
Nits
|
Re: interrogation, adding a trait bound to S is what I was thinking. At present it is Re: hash algorithm and signature algorithm, you're right they can move independently, but accumulating the full list in the SignedData later is required (as a SHOULD). The consistency check suggestion is likely too much, just ignore that. Here's a certs only test case:
|
Added - `SignedData` builder (RustCrypto#1051) Changed - Deprecate `pkcs7` in favor of `cms` (RustCrypto#1062) - der: add `SetOf(Vec)::insert(_ordered)`; deprecate `add` (RustCrypto#1067) - Re-enable all minimal-versions checks (RustCrypto#1071) Fixed - Don't insert signing time attribute by default (RustCrypto#1148) - Fixed encoding of `SubjectKeyIdentifier` (RustCrypto#1152)
Added - `SignedData` builder (#1051) Changed - Deprecate `pkcs7` in favor of `cms` (#1062) - der: add `SetOf(Vec)::insert(_ordered)`; deprecate `add` (#1067) - Re-enable all minimal-versions checks (#1071) Fixed - Don't insert signing time attribute by default (#1148) - Fixed encoding of `SubjectKeyIdentifier` (#1152)
This branch adds a builder for SignedData PKCS #7 messages.