Skip to content

Commit

Permalink
Don't re-compute extensions in permits_basic (#10076)
Browse files Browse the repository at this point in the history
The callers already have it
  • Loading branch information
alex authored Dec 30, 2023
1 parent 201851a commit 223b52e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/rust/cryptography-x509-verification/src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,11 @@ impl<'a, B: CryptoOps> Policy<'a, B> {
}
}

fn permits_basic(&self, cert: &Certificate<'_>) -> Result<(), ValidationError> {
let extensions = cert.extensions()?;

fn permits_basic(
&self,
cert: &Certificate<'_>,
extensions: &Extensions<'_>,
) -> Result<(), ValidationError> {
// CA/B 7.1.1:
// Certificates MUST be of type X.509 v3.
if cert.tbs_cert.version != 2 {
Expand Down Expand Up @@ -405,7 +407,7 @@ impl<'a, B: CryptoOps> Policy<'a, B> {

// Extension policy checks.
for ext_policy in self.common_extension_policies.iter() {
ext_policy.permits(self, cert, &extensions)?;
ext_policy.permits(self, cert, extensions)?;
}

// Check that all critical extensions in this certificate are accounted for.
Expand Down Expand Up @@ -443,7 +445,7 @@ impl<'a, B: CryptoOps> Policy<'a, B> {
current_depth: u8,
extensions: &Extensions<'_>,
) -> Result<(), ValidationError> {
self.permits_basic(cert)?;
self.permits_basic(cert, extensions)?;

// 5280 4.1.2.6: Subject
// CA certificates MUST have a subject populated with a non-empty distinguished name.
Expand Down Expand Up @@ -484,7 +486,7 @@ impl<'a, B: CryptoOps> Policy<'a, B> {
cert: &Certificate<'_>,
extensions: &Extensions<'_>,
) -> Result<(), ValidationError> {
self.permits_basic(cert)?;
self.permits_basic(cert, extensions)?;

for ext_policy in self.ee_extension_policies.iter() {
ext_policy.permits(self, cert, extensions)?;
Expand Down

0 comments on commit 223b52e

Please sign in to comment.