WIP: add test for mixed DER/BER encoding CMS#827
Closed
smndtrl wants to merge 2 commits intoRustCrypto:masterfrom
smndtrl:pkcs7-ber
Closed
WIP: add test for mixed DER/BER encoding CMS#827smndtrl wants to merge 2 commits intoRustCrypto:masterfrom smndtrl:pkcs7-ber
smndtrl wants to merge 2 commits intoRustCrypto:masterfrom
smndtrl:pkcs7-ber
Conversation
tarcieri
reviewed
Jan 1, 2023
Comment on lines
+146
to
+165
| let path = "./tests/examples/cms_der.bin"; | ||
| let bytes = fs::read(&path).expect(&format!("Failed to read from {}", &path)); | ||
|
|
||
| let content = ContentInfo::from_der(&bytes).expect("expected valid data"); | ||
|
|
||
| match content { | ||
| ContentInfo::SignedData(Some(data)) => { | ||
| assert_eq!( | ||
| data.encap_content_info | ||
| .e_content | ||
| .unwrap() | ||
| .decode_into::<OctetStringRef>() | ||
| .unwrap() | ||
| .as_bytes() | ||
| .len(), | ||
| 10034 | ||
| ) | ||
| } | ||
| _ => panic!("expected ContentInfo::SignedData(Some(_))"), | ||
| } |
Member
There was a problem hiding this comment.
Suggested change
| let path = "./tests/examples/cms_der.bin"; | |
| let bytes = fs::read(&path).expect(&format!("Failed to read from {}", &path)); | |
| let content = ContentInfo::from_der(&bytes).expect("expected valid data"); | |
| match content { | |
| ContentInfo::SignedData(Some(data)) => { | |
| assert_eq!( | |
| data.encap_content_info | |
| .e_content | |
| .unwrap() | |
| .decode_into::<OctetStringRef>() | |
| .unwrap() | |
| .as_bytes() | |
| .len(), | |
| 10034 | |
| ) | |
| } | |
| _ => panic!("expected ContentInfo::SignedData(Some(_))"), | |
| } | |
| let bytes = include_bytes!("examples/cms_der.bin"); | |
| let content = match ContentInfo::from_der(bytes) { | |
| Ok(ContentInfo::SignedData(Some(data))) => data, | |
| other => panic!("unexpected result: {:?}", other), | |
| }; | |
| assert_eq!( | |
| content | |
| .encap_content_info | |
| .e_content | |
| .unwrap() | |
| .decode_into::<OctetStringRef>() | |
| .unwrap() | |
| .as_bytes() | |
| .len(), | |
| 10034 | |
| ); |
Member
|
Looking at the BER example, it looks like it's using indefinite lengths fairly pervasively for several (nested) fields. Making this work will probably involve modifying custom derive to be able to generate |
tarcieri
added a commit
that referenced
this pull request
Jan 2, 2023
Per #823 and #827, making PKCS#7 work interoperably will involve supporting at limited number of BER productions, one of which is indefinite lengths. The current built-in `Length` type rejects them, as a proper DER parser is expected to. This commit adds a separate `IndefiniteLength` type as a newtype of `Option<Length>` with support for parsing indefinite lengths.
Member
|
Here's a stepping stone towards a solution: #830 |
tarcieri
added a commit
that referenced
this pull request
Jan 2, 2023
Per #823 and #827, making PKCS#7 work interoperably will involve supporting at limited number of BER productions, one of which is indefinite lengths. The current built-in `Length` type rejects them, as a proper DER parser is expected to. This commit adds a separate `IndefiniteLength` type as a newtype of `Option<Length>` with support for parsing indefinite lengths.
tarcieri
added a commit
that referenced
this pull request
Jan 2, 2023
Per #823 and #827, making PKCS#7 work interoperably will involve supporting at limited number of BER productions, one of which is indefinite lengths. The current built-in `Length` type rejects them, as a proper DER parser is expected to. This commit adds a separate `IndefiniteLength` type as a newtype of `Option<Length>` with support for parsing indefinite lengths.
Member
|
Merged in #840 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As requested in #813 a test for mixed encoding CMS.
@tarcieri I didn't find my original BER file from the Apple MDM Signature so I just checked the example at https://lapo.it/asn1js/# and it's very similar in that it starts with an indefinite length tag, uses multiple along the way and also uses constructed undefined length OctetStrings.
Both the DER/BER file have the same
e_content. Currently the DER encoded file is used in the test and works fine.