Skip to content

pem-rfc7468: accept a lone CR before the pre-encapsulation boundary - #2488

Open
choksi2212 wants to merge 1 commit into
RustCrypto:masterfrom
choksi2212:fix/pem-lone-cr-preamble-2486
Open

choksi2212 wants to merge 1 commit into
RustCrypto:masterfrom
choksi2212:fix/pem-lone-cr-preamble-2486

Conversation

@choksi2212

Copy link
Copy Markdown

Fixes #2486.

Section 3 ends every line with eol = CRLF / CR / LF, and the crate's own strip_leading_eol/strip_trailing_eol take all three, but strip_preamble only looked for the boundary after an LF. A preamble line ended by a lone CR was refused as Error::Preamble even with -----BEGIN right behind it. The case that bites is a chain: Certificate::load_pem_chain splits after each -----END CERTIFICATE-----, so the second message of a chain begins with the first one's trailing eol. With LF or CRLF that decodes; with a lone CR the whole chain is refused.

This adds the matching CR arm next to the LF arm. CRLF is untouched: the CR there is followed by the LF, not the boundary, so the walk still lands on the LF case.

The new tests cover the lone-CR preamble line, the chain hand-off with the whole message CR-wrapped, and a bare CR before the boundary, plus pins for the CRLF path and the NUL refusal. On the pre-change crate the four CR tests fail with exactly Err(Preamble) and they pass here; cargo test -p pem-rfc7468 is green with and without default features, clippy is clean under -D warnings, and cargo check --workspace --all-features still passes.

Section 3's grammar ends every line with eol = CRLF / CR / LF, and the
eol helpers already accept a lone CR, but strip_preamble only looked
for the boundary after an LF. A preamble ended by a lone CR (or the
previous message's trailing eol in a multi-certificate chain) was
refused as Error::Preamble even though the boundary follows it.

Accept a CR followed by the boundary the same way the LF case is
accepted. A CRLF is unaffected: the CR is then followed by the LF, not
the boundary, so the walk still lands on the LF arm.

Fixes RustCrypto#2486

Signed-off-by: choksi2212 <choksi2212@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant