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

Make *ring* optional #134

Merged
merged 7 commits into from
Jul 28, 2023
Merged

Make *ring* optional #134

merged 7 commits into from
Jul 28, 2023

Conversation

ctz
Copy link
Member

@ctz ctz commented Jul 25, 2023

fixes #130

@codecov
Copy link

codecov bot commented Jul 25, 2023

Codecov Report

Merging #134 (6528d52) into main (56c55c8) will increase coverage by 0.93%.
The diff coverage is 99.77%.

@@            Coverage Diff             @@
##             main     #134      +/-   ##
==========================================
+ Coverage   95.35%   96.28%   +0.93%     
==========================================
  Files          15       16       +1     
  Lines        4002     4070      +68     
==========================================
+ Hits         3816     3919     +103     
+ Misses        186      151      -35     
Files Changed Coverage Δ
src/subject_name/verify.rs 96.56% <ø> (ø)
src/trust_anchor.rs 96.22% <ø> (+3.49%) ⬆️
src/signed_data.rs 99.18% <96.55%> (-0.82%) ⬇️
src/calendar.rs 97.26% <100.00%> (ø)
src/crl.rs 99.65% <100.00%> (ø)
src/der.rs 98.65% <100.00%> (+0.50%) ⬆️
src/end_entity.rs 100.00% <100.00%> (+31.73%) ⬆️
src/ring_algs.rs 100.00% <100.00%> (ø)
src/verify_cert.rs 95.23% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ctz ctz force-pushed the jbp-optional-ring branch 5 times, most recently from 7b8ed5e to 348be58 Compare July 25, 2023 16:07
@ctz ctz marked this pull request as ready for review July 25, 2023 16:10
@ctz ctz requested review from djc and cpu July 25, 2023 16:10
@cpu
Copy link
Member

cpu commented Jul 26, 2023

Haven't forgotten about this branch, I just want to review it carefully and have been tied up with other work. I will make time tomorrow :-)

@djc
Copy link
Member

djc commented Jul 26, 2023

Same here. My high-level thought so far: have you given thought to the ergonomics of implementing separate signature traits for both rustls and webpki? It would suck a little to have a bunch of boilerplate to do them twice.

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

Some smaller nits, overall this looks great!

src/der.rs Outdated
@@ -13,7 +13,9 @@
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use crate::{calendar, time, Error};
pub(crate) use ring::io::der::{CONSTRUCTED, CONTEXT_SPECIFIC};

pub(crate) const CONSTRUCTED: u8 = 0x20;
Copy link
Member

Choose a reason for hiding this comment

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

Style nit: top-down ordering would suggest moving these to the bottom of the module.

src/signed_data.rs Show resolved Hide resolved
src/signed_data.rs Show resolved Hide resolved
pub struct SignatureAlgorithm {
/// A detail-less error when a signature is not valid.
#[derive(Debug, Copy, Clone)]
pub struct InvalidSignature;
Copy link
Member

Choose a reason for hiding this comment

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

Style nits: I would move the InvalidSignature type definition below the trait definition, and move the RingSignatureAlgorithm definition and impl above the trait definition.

src/signed_data.rs Outdated Show resolved Hide resolved
src/signed_data_ring.rs Outdated Show resolved Hide resolved
@ctz
Copy link
Member Author

ctz commented Jul 27, 2023

Same here. My high-level thought so far: have you given thought to the ergonomics of implementing separate signature traits for both rustls and webpki? It would suck a little to have a bunch of boilerplate to do them twice.

I think there isn't any overlap. The closest we have is https://docs.rs/rustls/latest/rustls/client/trait.ServerCertVerifier.html#method.verify_tls13_signature but that is in terms of certificates rather than public keys, and doesn't deal with any of the pkix public key/signature algorithm matching business that needs to happen here.

There's also https://docs.rs/rustls/latest/rustls/sign/trait.Signer.html but that's for signing rather than verification.

@djc
Copy link
Member

djc commented Jul 27, 2023

There's also https://docs.rs/rustls/latest/rustls/sign/trait.Signer.html but that's for signing rather than verification.

But this is implemented for the same number of algorithms, right? And an implementation would presumably want to support both signing and verification using the same algorithms.

@ctz
Copy link
Member Author

ctz commented Jul 27, 2023

But this is implemented for the same number of algorithms, right? And an implementation would presumably want to support both signing and verification using the same algorithms.

Signer is implemented for an object that has (or can access) a private signing key and can use it for a specific algorithm. It wouldn't make sense for that object to implement a webpki::SignatureAlgorithm (which is a public operation, not needing any key material outside what is provided from the certificate). Now I'm wondering if SignatureAlgorithm should be VerifyAlgorithm or SignatureVerifyAlgorithm?

@djc
Copy link
Member

djc commented Jul 27, 2023

Signer is implemented for an object that has (or can access) a private signing key and can use it for a specific algorithm. It wouldn't make sense for that object to implement a webpki::SignatureAlgorithm (which is a public operation, not needing any key material outside what is provided from the certificate). Now I'm wondering if SignatureAlgorithm should be VerifyAlgorithm or SignatureVerifyAlgorithm?

Alright, that's fair.

Renaming to make this more obvious is a good idea. It looks like ring calls them VerificationAlgorithm. Maybe SignatureVerificationAlgorithm? I think the noun form is a little nicer than the verb form for this.

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.

Very cool to see this coming together! Nice work @ctz 🎉

I only had small comments :-)

src/crl.rs Outdated Show resolved Hide resolved
src/der.rs Outdated Show resolved Hide resolved
src/der.rs Show resolved Hide resolved
src/crl.rs Outdated Show resolved Hide resolved
src/signed_data.rs Outdated Show resolved Hide resolved
src/signed_data.rs Outdated Show resolved Hide resolved
src/signed_data.rs Outdated Show resolved Hide resolved
src/signed_data.rs Outdated Show resolved Hide resolved
src/signed_data.rs Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
@ctz ctz force-pushed the jbp-optional-ring branch 4 times, most recently from 5b0c4ff to 6b98fb7 Compare July 28, 2023 11:38
src/subject_name/verify.rs Outdated Show resolved Hide resolved
ctz added 6 commits July 28, 2023 13:10
`der::nonnegative_integer` and `der::small_nonnegative_integer` are
imported from ring.

This relaxes id-ce-cRLNumber decoding from being a positive integer
to a non-negative integer (ie, 0 is now allowed).  This is OK because
RFC5240 defines it as:

> CRLNumber ::= INTEGER (0..MAX)
- use oid! macro for OIDs
- add thousand separators for large integer literals
- remove allow(dead_code) that had no effect
- split out and document calculation of DAYS_BEFORE_UNIX_EPOCH_AD
The next commit makes a breaking change to callers of these APIs,
so it's a good time to drop them?

Inline the single-caller `verify_is_valid_cert` function.
Rename it to `SignatureVerificationAlgorithm`.

`RingAlgorithm` exists as the previous type, and implements
the trait.

This is a breaking change:

- top level functions now need to pass a &[&dyn SignatureVerificationAlgorithm]
- objects like `ECDSA_P256_SHA256` are now a `&dyn SignatureVerificationAlgorithm`
  so callers don't see the internal `RingAlgorithm` type.
It is a default feature.

Taking it away disables all the signature algorithms, and therefore most of the tests.
@ctz ctz added this pull request to the merge queue Jul 28, 2023
Merged via the queue into main with commit 205f5d7 Jul 28, 2023
42 checks passed
@ctz ctz deleted the jbp-optional-ring branch July 28, 2023 19:18
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.

Consider making *ring* dependency optional
3 participants