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

Add logic to verify and get signing key from chain #70

Closed
wants to merge 1 commit into from

Conversation

nick-mobilecoin
Copy link
Collaborator

Motivation

@github-actions github-actions bot added the size/L Large PRs label Apr 27, 2023
@meowblecoinbot meowblecoinbot requested a review from a team April 27, 2023 22:34
@github-actions
Copy link

❌ Unreviewed dependencies found

Crate Version Reviews (N/2) LoC Left-Pad Index Geiger Flags

// In order to verify the signature, we need to access the original DER
// bytes
der_bytes: &'a [u8],
certificate: X509Certificate,
der_bytes: Vec<u8>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got rid of the lifetimes here, it prevented the PEM decoding in the code, since pem generates a vector, and since this logic inherently needs alloc behind the scenes it doesn't seem like we gain much trying to minimize vector usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

Comment on lines +30 to +37
/// Returning the signing key from the leaf certificate
///
/// The chain will be verified against the `trust_root` and the `unix_time`.
pub fn signing_key(
&self,
trust_root: VerifiedCertificate,
unix_time: Duration,
) -> Result<VerifyingKey> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might be doing too much, but TBH I'm still on the fence on the "unverified***"->"verified***" logic I have for certs and CRLs.

Comment on lines +47 to +48
#[cfg(test)]
mod test {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is going to need some more robust testing, thinking of grabbing some of the test vectors from https://csrc.nist.gov/projects/pki-testing

@codecov
Copy link

codecov bot commented Apr 27, 2023

Codecov Report

Merging #70 (224104a) into main (9f0feeb) will increase coverage by 0.27%.
The diff coverage is 99.43%.

❗ Current head 224104a differs from pull request most recent head 687cf04. Consider uploading reports for the commit 687cf04 to get more accurate results

@@            Coverage Diff             @@
##             main      #70      +/-   ##
==========================================
+ Coverage   97.35%   97.63%   +0.27%     
==========================================
  Files           6        7       +1     
  Lines        1476     1648     +172     
==========================================
+ Hits         1437     1609     +172     
  Misses         39       39              
Impacted Files Coverage Δ
verifier/src/x509/crl.rs 98.88% <98.88%> (+0.09%) ⬆️
verifier/src/x509/certs.rs 99.41% <100.00%> (+0.10%) ⬆️
verifier/src/x509/chain.rs 100.00% <100.00%> (ø)
verifier/src/x509/error.rs 100.00% <100.00%> (ø)

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

/// Returning the signing key from the leaf certificate
///
/// The chain will be verified against the `trust_root` and the `unix_time`.
pub fn signing_key(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will need to be passed a collection of CRLs added a bullet item to #50 to keep track of this

// In order to verify the signature, we need to access the original DER
// bytes
der_bytes: &'a [u8],
certificate: X509Certificate,
der_bytes: Vec<u8>,
Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

Comment on lines +150 to +154
#[parameterized(
root = { ROOT_CA },
processor = { PROCESSOR_CA },
leaf = { LEAF_CERT },
)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why parametrize these values if there's only one value for each param? Consider removing this usage if there isn't a good reason...

Copy link
Collaborator Author

@nick-mobilecoin nick-mobilecoin May 2, 2023

Choose a reason for hiding this comment

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

I'm not sure I follow. Parameterized tests allow one to re-use the same testing behavior with different inputs(parameters). The number of parameters per test seems orthogonal to that use.

For this specific case I'll admit it doesn't gain much, other than if one wants to add another certificate to try it's one line vs 4 and doesn't require as much thought on the naming.
For example the explicit creation of dedicated tests would be something like:

    fn try_from_root_ca() {
        assert!(UnverifiedCertificate::try_from(ROOT_CA).is_ok());
    }
    
    fn try_from_processor_ca() {
        assert!(UnverifiedCertificate::try_from(PROCESSOR_CA).is_ok());
    }

    fn try_from_leaf_cert() {
        assert!(UnverifiedCertificate::try_from(LEAF_CERT).is_ok());
    }

@nick-mobilecoin
Copy link
Collaborator Author

punting on implementing x509 chain parsing logic.

@nick-mobilecoin nick-mobilecoin deleted the nick/chain branch October 3, 2023 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Large PRs
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants