Skip to content

Commit

Permalink
csr: support reading crl dps from CSR
Browse files Browse the repository at this point in the history
  • Loading branch information
cpu committed Oct 10, 2023
1 parent 8258f2e commit 9d2c80b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/csr.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#[cfg(feature = "x509-parser")]
use crate::{
BasicConstraints, CustomExtension, DistinguishedName, ExtendedKeyUsagePurpose, GeneralSubtree,
IsCa, KeyUsagePurpose, NameConstraints, SanType,
BasicConstraints, CrlDistributionPoint, CustomExtension, DistinguishedName,
ExtendedKeyUsagePurpose, GeneralSubtree, IsCa, KeyUsagePurpose, NameConstraints, SanType,
};
#[cfg(feature = "pem")]
use pem::Pem;
use std::hash::Hash;
#[cfg(feature = "x509-parser")]
use x509_parser::extensions::{DistributionPointName, GeneralName};

use crate::{Certificate, CertificateParams, Error, PublicKeyData, SignatureAlgorithm};

Expand Down Expand Up @@ -201,6 +203,38 @@ impl CertificateSigningRequest {
}
true

Check warning on line 204 in src/csr.rs

View check run for this annotation

Codecov / codecov/patch

src/csr.rs#L183-L204

Added lines #L183 - L204 were not covered by tests
},
x509_parser::extensions::ParsedExtension::CRLDistributionPoints(crl_dps) => {
let dps = crl_dps
.points
.iter()
.map(|dp| {
// Rcgen does not support CRL DPs with specific reasons, or an indirect issuer.
if dp.reasons.is_some() || dp.crl_issuer.is_some() {
return Err(Error::UnsupportedCrlDistributionPoint);
}
let general_names = match &dp.distribution_point {
Some(DistributionPointName::FullName(general_names)) => {
Ok(general_names)

Check warning on line 217 in src/csr.rs

View check run for this annotation

Codecov / codecov/patch

src/csr.rs#L206-L217

Added lines #L206 - L217 were not covered by tests
},
// Rcgen does not support CRL DPs missing a distribution point,
// or that specific a distribution point with a name relative
// to an issuer.
_ => Err(Error::UnsupportedCrlDistributionPoint),
}?;
let uris = general_names
.iter()
.map(|general_name| match general_name {
GeneralName::URI(uri) => Ok(uri.to_string()),

Check warning on line 227 in src/csr.rs

View check run for this annotation

Codecov / codecov/patch

src/csr.rs#L222-L227

Added lines #L222 - L227 were not covered by tests
// Rcgen does not support CRL DP general names other than URI.
_ => Err(Error::UnsupportedGeneralName),
})
.collect::<Result<Vec<_>, _>>()?;
Ok(CrlDistributionPoint { uris })
})
.collect::<Result<Vec<_>, _>>()?;
params.crl_distribution_points = dps;
true

Check warning on line 236 in src/csr.rs

View check run for this annotation

Codecov / codecov/patch

src/csr.rs#L229-L236

Added lines #L229 - L236 were not covered by tests
},
_ => false,
};
if !supported {
Expand Down
5 changes: 5 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum Error {
/// Unsupported basic constraints extension path length in CSR
#[cfg(feature = "x509-parser")]
UnsupportedBasicConstraintsPathLen,
/// Unsupported CRL distribution point extension in CSR
#[cfg(feature = "x509-parser")]
UnsupportedCrlDistributionPoint,
/// Unsupported extension requested in CSR
#[cfg(feature = "x509-parser")]
UnsupportedExtension,
Expand Down Expand Up @@ -109,6 +112,8 @@ impl fmt::Display for Error {
)?,

Check warning on line 112 in src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/error.rs#L109-L112

Added lines #L109 - L112 were not covered by tests
#[cfg(feature = "x509-parser")]
UnsupportedGeneralName => write!(f, "Unsupported general name in CSR",)?,

Check warning on line 114 in src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/error.rs#L114

Added line #L114 was not covered by tests
#[cfg(feature = "x509-parser")]
UnsupportedCrlDistributionPoint => write!(f, "Unsupported CRL distribution point in CSR",)?,

Check warning on line 116 in src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/error.rs#L116

Added line #L116 was not covered by tests
};
Ok(())
}
Expand Down

0 comments on commit 9d2c80b

Please sign in to comment.