Closed Bug 1059924 Opened 12 years ago Closed 12 years ago

Centralize tag and length decoding in mozilla::pkix's DER decoder

Categories

(Core :: Security: PSM, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED
mozilla35

People

(Reporter: briansmith, Assigned: briansmith)

References

Details

Attachments

(2 files, 1 obsolete file)

Attached patch fundamental-DER-decoder.patch (obsolete) — Splinter Review
This patch adds the function ReadTagAndGetLength, which will be needed by the new name processing code (bug 970542 and others). The patch also centralizes all of the tag and length parsing into ReadTagAndGetLength so that there is only place place where it is done. This should make it easier to verify (formally and semi-formally) that the DER decoder is safe and correct.
Attachment #8480733 - Flags: review?(dkeeler)
Comment on attachment 8480733 [details] [diff] [review] fundamental-DER-decoder.patch Review of attachment 8480733 [details] [diff] [review]: ----------------------------------------------------------------- Looks good with comments addressed. ::: security/pkix/lib/pkixder.cpp @@ +39,5 @@ > if (rv != Success) { > return rv; > } > + if ((tag & 0x1F) == 0x1F) { > + // TODO: test for this? Yes, a test would be nice. Should be pretty simple, right? @@ +81,5 @@ > // We don't support lengths larger than 2^16 - 1. > return Result::ERROR_BAD_DER; > } > > // Ensure the input is long enough for the length it says it has. This comment is a little out of date, now. ::: security/pkix/lib/pkixder.h @@ +124,5 @@ > ExpectTagAndGetTLV(Reader& input, uint8_t tag, /*out*/ Input& tlv) > { > Reader::Mark mark(input.GetMark()); > + Input unusedValue; > + Result rv = ExpectTagAndGetValue(input, tag, unusedValue); ExpectTagAndSkipValue?
Attachment #8480733 - Flags: review?(dkeeler) → review+
The tests weren't as trivial as I initially expected.
Attachment #8483293 - Flags: review?(dkeeler)
I pushed part 1 without part 2, which I probably shouldn't have, but I did: https://hg.mozilla.org/integration/mozilla-inbound/rev/88c41feb981d
Keywords: leave-open
Target Milestone: --- → mozilla35
Comment on attachment 8483293 [details] [diff] [review] Part 2: Add the tests Review of attachment 8483293 [details] [diff] [review]: ----------------------------------------------------------------- Looks good - I just have a question about some of the comments. ::: security/pkix/test/gtest/pkixder_input_tests.cpp @@ +551,5 @@ > +{ > + // High tag number form is not allowed (legal 1 byte tag). > + // > + // Even if we comment out ReadTagAndGetValue's check to prohibit the high tag > + // number form, this test will pass, because 31 will be interpreted as a Was this intended to be "If we comment out..." or "... this test will not pass..." or something else? As it is, I'm not understanding what you're saying. @@ +573,5 @@ > +{ > + // High tag number form is not allowed (2 byte legal tag) > + // > + // Even if we comment out ReadTagAndGetValue's check to prohibit the high tag > + // number form, this test will pass, because 31 will be interpreted as a Same here
Attachment #8483293 - Flags: review?(dkeeler) → review+
Comment on attachment 8483293 [details] [diff] [review] Part 2: Add the tests Review of attachment 8483293 [details] [diff] [review]: ----------------------------------------------------------------- ::: security/pkix/test/gtest/pkixder_input_tests.cpp @@ +551,5 @@ > +{ > + // High tag number form is not allowed (legal 1 byte tag). > + // > + // Even if we comment out ReadTagAndGetValue's check to prohibit the high tag > + // number form, this test will pass, because 31 will be interpreted as a When I originally wrote this test, the test passed right away, as expected. Then, in order to make sure the test was testing the code in question, I commented out (i.e. removed) the check that prohibits the high tag number form in pkixder.cpp. I was surprised that the test still passed, because the second byte of the tag was being interpreted as a length that happened to be correct given the input. Consequently, this test is really about "make sure we don't write code in the future to accept the high tag number form," not "make sure we don't mis-interpret the "high tag number form." I will clarify this before checkin.
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: