Start to build sync route
This commit is contained in:
@ -76,6 +76,17 @@ impl CertData {
|
||||
crl: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Check if a certificate is revoked
|
||||
pub fn is_revoked(&self, cert: &X509) -> anyhow::Result<bool> {
|
||||
let crl = X509Crl::from_pem(&std::fs::read(
|
||||
self.crl.as_ref().ok_or(PKIError::MissingCRL)?,
|
||||
)?)?;
|
||||
|
||||
let res = crl.get_by_cert(cert);
|
||||
|
||||
Ok(matches!(res, CrlStatus::Revoked(_)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate private key
|
||||
@ -480,21 +491,10 @@ pub fn gen_certificate_for_device(csr: &X509Req) -> anyhow::Result<String> {
|
||||
Ok(String::from_utf8(cert)?)
|
||||
}
|
||||
|
||||
/// Check if a certificate is revoked
|
||||
fn is_revoked(cert: &X509, ca: &CertData) -> anyhow::Result<bool> {
|
||||
let crl = X509Crl::from_pem(&std::fs::read(
|
||||
ca.crl.as_ref().ok_or(PKIError::MissingCRL)?,
|
||||
)?)?;
|
||||
|
||||
let res = crl.get_by_cert(cert);
|
||||
|
||||
Ok(matches!(res, CrlStatus::Revoked(_)))
|
||||
}
|
||||
|
||||
/// Revoke a certificate
|
||||
pub fn revoke(cert: &X509, ca: &CertData) -> anyhow::Result<()> {
|
||||
// Check if certificate is already revoked
|
||||
if is_revoked(cert, ca)? {
|
||||
if ca.is_revoked(cert)? {
|
||||
// No op
|
||||
return Ok(());
|
||||
}
|
||||
|
Reference in New Issue
Block a user