From cb9c722473ad1faf64536528d719180af49d7940 Mon Sep 17 00:00:00 2001
From: DJO <790521+Alenar@users.noreply.github.com>
Date: Wed, 18 Dec 2024 18:44:30 +0100
Subject: [PATCH] feat(client-lib): enhanced security check when verifying with
cache enabled
By not using the cache until we cross an epoch boundary to make sure
that the avk in certificate to check was included in a certificate from
the previous epoch.
---
.../src/certificate_client/verify.rs | 131 +++++++++++++-----
1 file changed, 95 insertions(+), 36 deletions(-)
diff --git a/mithril-client/src/certificate_client/verify.rs b/mithril-client/src/certificate_client/verify.rs
index 04fbeb3de8..a1b95d3e4b 100644
--- a/mithril-client/src/certificate_client/verify.rs
+++ b/mithril-client/src/certificate_client/verify.rs
@@ -104,7 +104,7 @@ impl MithrilCertificateVerifier {
Ok(None)
}
- async fn verify_one(
+ async fn verify_with_cache(
&self,
certificate_chain_validation_id: &str,
certificate: CertificateToVerify,
@@ -123,23 +123,25 @@ impl MithrilCertificateVerifier {
hash: previous_hash,
}))
} else {
- self.verify_not_cached_certificate(certificate_chain_validation_id, certificate)
- .await
+ let certificate = match certificate {
+ CertificateToVerify::Downloaded { certificate } => certificate,
+ CertificateToVerify::ToDownload { hash } => {
+ self.retriever.get_certificate_details(&hash).await?
+ }
+ };
+
+ let previous_certificate = self
+ .verify_without_cache(certificate_chain_validation_id, certificate)
+ .await?;
+ Ok(previous_certificate.map(Into::into))
}
}
- async fn verify_not_cached_certificate(
+ async fn verify_without_cache(
&self,
certificate_chain_validation_id: &str,
- certificate: CertificateToVerify,
- ) -> MithrilResult