-
Notifications
You must be signed in to change notification settings - Fork 140
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
pkcs7+der: mixed BER/DER encoding with undefined length #779
Comments
We've talked about introducing a lax mode to the |
I gave it a shot with my limited experience with Rust and also this codebase. It is meant as a starting point. I used it successfully with changes to |
@smndtrl rather than trying to change how the existing parsing works in the |
@tarcieri Wouldn't that require me changing how For making indefinite length work a solution for I'm fine with carrying this patch on my own as it works well for my use case. I might revisit the suggested approach later on. |
@smndtrl you'll need to write all the impls by hand if you go that route, and you will have to avoid impl'ing one of If you can't figure it out I can take a look at some point based on your |
We've found a real-world use case:
|
BER was an issue working on PKCS #12 as well. Exports from Firefox are BER. In a cert collection I use for testing, there are several several AIAs hosting P7s that are BER encoded. |
We're aware this is a real issue. It's something I've been meaning to address. |
I think we can probably use an approach like #810 but we need some way to control the granularity so enabling it doesn't cause |
FYI, I have implemented a simple parser/converter ( ...
let der = Berder::ber_to_der(ber.as_slice())?; // Indefinite -> definite lengths
let ci = ContentInfo::from_der(der.as_slice())?;
let pki_message = SignedData::from_der(ci.content.to_der()?; This could be implemented as |
I think we can probably implement |
@tarcieri I have started doing that based on #810. I think I got pretty far with this implementation, but there are one or two issues left (correct handling of the end-of-content markers). The main idea was, to modify the
This implementation is not complete, but I think it is already more complete, than the current #810. |
@bkstein I'd like to avoid making changes to the existing APIs like that. The idea would be to use However, I'd definitely like to also preserve the way the existing implementation works so indefinite lengths are rejected when parsing DER. |
Yes, the |
I was thinking an enum like |
Adds an enum with `Ber` and `Der` (default) variants which can be used to selectively allow a limited number of BER productions when decoding certain BER-based security-oriented formats, e.g. CMS, PKCS#8. Currently this doesn't actually do anything, however the goal is to address #779, where we can't decode CMS generated by Apple tooling. PR #810 is an example of how the rules could be relaxed to support `IndefiniteLength`s.
I've bumped I opened #1321 which adds an |
Adds an enum with `Ber` and `Der` (default) variants which can be used to selectively allow a limited number of BER productions when decoding certain BER-based security-oriented formats, e.g. CMS, PKCS#8. Currently this doesn't actually do anything, however the goal is to address #779, where we can't decode CMS generated by Apple tooling. PR #810 is an example of how the rules could be relaxed to support `IndefiniteLength`s.
@tarcieri For reference, we were interested in the BER capability as we want to unify our LDAP and Kerberos parsers on one trusted encoding/decoding stack. Currently we have a "ber only" parser, but we would like to move to this crate. I'll do some testing soon to see what we need for extending this to support BER in our cases. |
Issue RustCrypto#779 has had some process (PR RustCrypto#1321). However, this helper function is intended to provide an escape hatch for limited support of some cases of BER, while not waiting for general support or needing API changes. Specifically, the transcoding of occurrences of the constructed, indefinite-length method into the constructed, definite-length method. This is likely sufficient to address the examples in the wild, reported in Issue RustCrypto#779 and elsewhere. The goal is not to support all possible violations of DER that are still following valid BER. Examples are non-canonical encodings of lengths (which would require an alternative `Length`), or constructed string types (which could be handled by further work on this function, but usage may not be well motivated).
I hit this issue. I did see And I read through prior attempts of @smndtrl and @bkstein I spent some time searching for additive-only changes, and even with, PR #1321, I could not see a path. My impression from the codebase was that there would need to be breaking changes, and one possible path might look like,
so that the existing API and usage doesn’t change dramatically, but so that nested readers can handle the constructed, indefinite-length method. As I need a solution in the short term, I had to go with the ‘transcoding’ approach that was discussed above. The following PR is me contributing that code back, in case the maintainers are open to accepting this into the crate in the near term (at least until more general solutions are developed). Or failing that, maybe it will be of use to others that find this issue while it remains open. |
Issue RustCrypto#779 has had some process (PR RustCrypto#1321). However, this helper function is intended to provide an escape hatch for limited support of some cases of BER, while not waiting for general support or needing API changes. Specifically, the transcoding of occurrences of the constructed, indefinite-length method into the constructed, definite-length method. This is likely sufficient to address the examples in the wild, reported in Issue RustCrypto#779 and elsewhere. The goal is not to support all possible violations of DER that are still following valid BER. Examples are non-canonical encodings of lengths (which would require an alternative `Length`), or constructed string types (which could be handled by further work on this function, but usage may not be well motivated).
Issue RustCrypto#779 has had some progress (PR RustCrypto#1321). However, this helper function is intended to provide an escape hatch for limited support of some cases of BER, while not waiting for general support or needing API changes. Specifically, the transcoding of occurrences of the constructed, indefinite-length method into the constructed, definite-length method. This is likely sufficient to address the examples in the wild, reported in Issue RustCrypto#779 and elsewhere. The goal is not to support all possible violations of DER that are still following valid BER. Examples are non-canonical encodings of lengths (which would require an alternative `Length`), or constructed string types (which could be handled by further work on this function, but usage may not be well motivated).
Issue RustCrypto#779 has had some progress (PR RustCrypto#1321). However, this helper function is intended to provide an escape hatch for limited support of some cases of BER, while not waiting for general support or needing API changes. Specifically, the transcoding of occurrences of the constructed, indefinite-length method into the constructed, definite-length method. This is likely sufficient to address the examples in the wild, reported in Issue RustCrypto#779 and elsewhere. The goal is not to support all possible violations of DER that are still following valid BER. Examples are non-canonical encodings of lengths (which would require an alternative `Length`), or constructed string types (which could be handled by further work on this function, but usage may not be well motivated).
… write my own parser
Hi,
while looking into the
pkcs7
crate for a CMS usecase around the Apple world I discovered that their detached signatures use the BER indefinite length encoding for some of theSEQUENCE
which of course is not supported by theder
crate.Has there been any thoughts/discussions around if that's something the formats repo should address or if that is out of scope (for now) and left to other crates.
I started with adding the signed-data content to
pkcs7
validating against a DER encoded signature and discovered the problem afterwards with the ones Apple generates :( Link to exampleSimon
The text was updated successfully, but these errors were encountered: