Skip to content
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

Allow negative serials in all certificates, not just trust anchors. #10

Closed
wants to merge 2 commits into from

Conversation

dequbed
Copy link
Contributor

@dequbed dequbed commented Nov 2, 2022

Based on discussion in Discord: https://discord.com/channels/976380008299917365/1015156984007381033/1037367413357948928

This follows the crypt implementation of Go, as per the following commit: golang/go@a0ea93d

@dequbed dequbed force-pushed the feature/serial_neg_ee branch 2 times, most recently from 987b26e to b9ea527 Compare November 2, 2022 15:35
This follows the crypt implementation of Go, as per the following commit: golang/go@a0ea93d

Signed-off-by: Nadja Reitzenstein <me@dequbed.space>
Signed-off-by: Nadja Reitzenstein <me@dequbed.space>
@dequbed dequbed force-pushed the feature/serial_neg_ee branch from b9ea527 to 65c1a4d Compare November 2, 2022 16:58
@djc djc requested a review from ctz March 10, 2023 09:51
@djc
Copy link
Member

djc commented Mar 10, 2023

cc @cpu

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I think if it could be rebased on main we'd be good to go.

let anchors = vec![webpki::TrustAnchor::try_from_cert_der(ca).unwrap()];
let anchors = webpki::TLSServerTrustAnchors(&anchors);

//#[allow(clippy::unreadable_literal)] // TODO: Make this clear.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note to other reviewers: this TODO is not unique to this work, but another instance of a pattern established by 2 other tests in this file. It would be nice to fix these up but I don't think it needs to be done in this branch.

Comment on lines +99 to +102
assert_eq!(
Ok(()),
cert.verify_is_valid_tls_server_cert(ALL_SIGALGS, &anchors, &[], time)
);
Copy link
Member

@cpu cpu Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very tiny nit: I think this might be expressed more idiomatically as :

Suggested change
assert_eq!(
Ok(()),
cert.verify_is_valid_tls_server_cert(ALL_SIGALGS, &anchors, &[], time)
);
assert!(
cert.verify_is_valid_tls_server_cert(ALL_SIGALGS, &anchors, &[], time)
.is_ok());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think assert_eq!() probably has better ergonomics in case of failure (that is, the failure output is easier to diagnose). But I would find it more idiomatic to have actual, then expected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Fair point.

Comment on lines +95 to +96
//#[allow(clippy::unreadable_literal)] // TODO: Make this clear.
let time = webpki::Time::from_seconds_since_unix_epoch(1667401500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the TODO and add a comment with the RFC 3339 value of the timestamp. I'll do the same for the other instances in a follow-up.

Suggested change
//#[allow(clippy::unreadable_literal)] // TODO: Make this clear.
let time = webpki::Time::from_seconds_since_unix_epoch(1667401500);
//#[allow(clippy::unreadable_literal)]
let time = webpki::Time::from_seconds_since_unix_epoch(1667401500); // 2022-11-02T15:05:00Z

@djc djc mentioned this pull request Mar 11, 2023
Comment on lines -156 to -158
if value.big_endian_without_leading_zero().len() > 20 {
return Err(Error::BadDER);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is removing this length check intentional? The rest of the PR motivation is about allowing negative serials.

With that said, this constraint is clearly on issuers and not verifiers.

Comment on lines +145 to +146
// However, we don't enforce these constraints, as there are widely-deployed trust anchors
// and many X.509 implementations in common use that violate these constraints.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can further quote RFC5280 here:


   Note: Non-conforming CAs may issue certificates with serial numbers
   that are negative or zero.  Certificate users SHOULD be prepared to
   gracefully handle such certificates.

@cpu
Copy link
Member

cpu commented Mar 13, 2023

Since @ctz is aiming to cut a release tag Soon ™️ I took a crack at addressing the conflicts and outstanding review feedback in a follow-up PR: #36 If it looks good we can close this one and proceed there.

@djc
Copy link
Member

djc commented Mar 13, 2023

This was merged through #36. Thanks for working on this!

@djc djc closed this Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants