20260716 澄清CA验证上下文摘要命名
This commit is contained in:
@@ -180,7 +180,7 @@ pub struct RoaValidationCacheStats {
|
||||
pub struct RoaValidationCacheInput<'a> {
|
||||
enabled: bool,
|
||||
view: Option<&'a RoaValidationCacheView>,
|
||||
parent_context_digest: Option<[u8; 32]>,
|
||||
ca_validation_context_digest: Option<[u8; 32]>,
|
||||
policy_fingerprint: Option<[u8; 32]>,
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ impl<'a> RoaValidationCacheInput<'a> {
|
||||
Self {
|
||||
enabled: false,
|
||||
view: None,
|
||||
parent_context_digest: None,
|
||||
ca_validation_context_digest: None,
|
||||
policy_fingerprint: None,
|
||||
}
|
||||
}
|
||||
@@ -198,20 +198,20 @@ impl<'a> RoaValidationCacheInput<'a> {
|
||||
Self {
|
||||
enabled: true,
|
||||
view,
|
||||
parent_context_digest: None,
|
||||
ca_validation_context_digest: None,
|
||||
policy_fingerprint: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enabled_with_context(
|
||||
view: Option<&'a RoaValidationCacheView>,
|
||||
parent_context_digest: [u8; 32],
|
||||
ca_validation_context_digest: [u8; 32],
|
||||
policy_fingerprint: [u8; 32],
|
||||
) -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
view,
|
||||
parent_context_digest: Some(parent_context_digest),
|
||||
ca_validation_context_digest: Some(ca_validation_context_digest),
|
||||
policy_fingerprint: Some(policy_fingerprint),
|
||||
}
|
||||
}
|
||||
@@ -495,7 +495,7 @@ fn evaluate_roa_cache_crl_gate(
|
||||
pub struct RoaValidationCacheView {
|
||||
entries_by_uri: HashMap<String, CachedRoaValidationResult>,
|
||||
issuer_ca_sha256_hex: Option<String>,
|
||||
parent_context_digest: Option<[u8; 32]>,
|
||||
ca_validation_context_digest: Option<[u8; 32]>,
|
||||
policy_fingerprint: Option<[u8; 32]>,
|
||||
crl_sha256_by_uri: HashMap<String, String>,
|
||||
blocked: bool,
|
||||
@@ -519,7 +519,7 @@ impl RoaValidationCacheView {
|
||||
let mut entries_by_uri: HashMap<String, CachedRoaValidationResult> =
|
||||
HashMap::with_capacity(projection.entries.len());
|
||||
let issuer_ca_sha256_hex = projection.issuer_ca_sha256_hex.clone();
|
||||
let parent_context_digest = projection.parent_context_digest;
|
||||
let ca_validation_context_digest = projection.ca_validation_context_digest;
|
||||
let policy_fingerprint = projection.policy_fingerprint;
|
||||
let crl_sha256_by_uri = projection
|
||||
.crl_sha256_by_uri
|
||||
@@ -536,7 +536,7 @@ impl RoaValidationCacheView {
|
||||
return Self {
|
||||
entries_by_uri,
|
||||
issuer_ca_sha256_hex,
|
||||
parent_context_digest,
|
||||
ca_validation_context_digest,
|
||||
policy_fingerprint,
|
||||
crl_sha256_by_uri,
|
||||
blocked,
|
||||
@@ -580,7 +580,7 @@ impl RoaValidationCacheView {
|
||||
Self {
|
||||
entries_by_uri,
|
||||
issuer_ca_sha256_hex,
|
||||
parent_context_digest,
|
||||
ca_validation_context_digest,
|
||||
policy_fingerprint,
|
||||
crl_sha256_by_uri,
|
||||
blocked,
|
||||
@@ -590,7 +590,7 @@ impl RoaValidationCacheView {
|
||||
fn matches_current_context(
|
||||
&self,
|
||||
issuer_ca_der: &[u8],
|
||||
parent_context_digest: Option<[u8; 32]>,
|
||||
ca_validation_context_digest: Option<[u8; 32]>,
|
||||
policy_fingerprint: Option<[u8; 32]>,
|
||||
) -> bool {
|
||||
if self.blocked {
|
||||
@@ -604,8 +604,8 @@ impl RoaValidationCacheView {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(expected_parent_context) = self.parent_context_digest {
|
||||
if Some(expected_parent_context) != parent_context_digest {
|
||||
if let Some(expected_ca_validation_context) = self.ca_validation_context_digest {
|
||||
if Some(expected_ca_validation_context) != ca_validation_context_digest {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -797,7 +797,7 @@ fn active_roa_cache_view<'a>(
|
||||
let gate_started = Instant::now();
|
||||
if view.matches_current_context(
|
||||
issuer_ca_der,
|
||||
roa_cache.parent_context_digest,
|
||||
roa_cache.ca_validation_context_digest,
|
||||
roa_cache.policy_fingerprint,
|
||||
) {
|
||||
stats.context_gate_nanos = stats
|
||||
@@ -3914,7 +3914,7 @@ mod tests {
|
||||
OffsetDateTime::parse(value, &Rfc3339).expect("parse fixed test time")
|
||||
}
|
||||
|
||||
const TEST_PARENT_CONTEXT: [u8; 32] = [0x70; 32];
|
||||
const TEST_CA_VALIDATION_CONTEXT: [u8; 32] = [0x70; 32];
|
||||
const TEST_POLICY_FINGERPRINT: [u8; 32] = [0x71; 32];
|
||||
const TEST_CRL_URI: &str = "rsync://example.test/repo/current.crl";
|
||||
const TEST_ROA_URI: &str = "rsync://example.test/repo/a.roa";
|
||||
@@ -3933,7 +3933,7 @@ mod tests {
|
||||
RoaCacheProjection::from_vcir_with_context(
|
||||
vcir,
|
||||
Some(&RoaCacheProjectionContext {
|
||||
parent_context_digest: TEST_PARENT_CONTEXT,
|
||||
ca_validation_context_digest: TEST_CA_VALIDATION_CONTEXT,
|
||||
policy_fingerprint: TEST_POLICY_FINGERPRINT,
|
||||
object_meta: vec![RoaCacheObjectMeta {
|
||||
source_object_uri: TEST_ROA_URI.to_string(),
|
||||
@@ -4071,7 +4071,7 @@ mod tests {
|
||||
|
||||
assert!(view.matches_current_context(
|
||||
issuer_der,
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
let hit = view.lookup(&file, &mut crl_cache, issuer_der, validation_time);
|
||||
@@ -4202,7 +4202,10 @@ mod tests {
|
||||
fixed_time("2026-06-08T00:00:00Z"),
|
||||
);
|
||||
let projection = sample_roa_cache_projection(&vcir, roa_hash);
|
||||
assert_eq!(projection.parent_context_digest, Some(TEST_PARENT_CONTEXT));
|
||||
assert_eq!(
|
||||
projection.ca_validation_context_digest,
|
||||
Some(TEST_CA_VALIDATION_CONTEXT)
|
||||
);
|
||||
assert_eq!(projection.policy_fingerprint, Some(TEST_POLICY_FINGERPRINT));
|
||||
assert_eq!(
|
||||
projection.entries[0].outputs_effective_until_unix,
|
||||
@@ -4245,7 +4248,7 @@ mod tests {
|
||||
let issuer_changed = RoaValidationCacheView::from_projection(&projection, validation_time);
|
||||
assert!(!issuer_changed.matches_current_context(
|
||||
issuer_der,
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
|
||||
@@ -4258,7 +4261,7 @@ mod tests {
|
||||
));
|
||||
assert!(!parent_changed.matches_current_context(
|
||||
issuer_der,
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some([0x98; 32])
|
||||
));
|
||||
|
||||
@@ -4283,7 +4286,7 @@ mod tests {
|
||||
RoaValidationCacheView::from_projection(&expired_projection, validation_time);
|
||||
assert!(!expired_view.matches_current_context(
|
||||
issuer_der,
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
let mut crl_cache = sample_crl_cache(b"current-crl".to_vec());
|
||||
@@ -4563,7 +4566,7 @@ mod tests {
|
||||
|
||||
assert!(view.matches_current_context(
|
||||
issuer_der,
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
assert!(matches!(
|
||||
@@ -4595,43 +4598,43 @@ mod tests {
|
||||
let mut view = RoaValidationCacheView {
|
||||
entries_by_uri: HashMap::new(),
|
||||
issuer_ca_sha256_hex: None,
|
||||
parent_context_digest: Some(TEST_PARENT_CONTEXT),
|
||||
ca_validation_context_digest: Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
policy_fingerprint: Some(TEST_POLICY_FINGERPRINT),
|
||||
crl_sha256_by_uri: HashMap::new(),
|
||||
blocked: false,
|
||||
};
|
||||
assert!(!view.matches_current_context(
|
||||
b"issuer-ca",
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
|
||||
view.issuer_ca_sha256_hex = Some("00".repeat(32));
|
||||
assert!(!view.matches_current_context(
|
||||
b"issuer-ca",
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
|
||||
view.issuer_ca_sha256_hex = Some(sha256_hex(b"issuer-ca"));
|
||||
assert!(view.matches_current_context(
|
||||
b"issuer-ca",
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
assert!(!view.matches_current_context(b"issuer-ca", None, Some(TEST_POLICY_FINGERPRINT)));
|
||||
|
||||
view.parent_context_digest = None;
|
||||
view.ca_validation_context_digest = None;
|
||||
assert!(!view.matches_current_context(
|
||||
b"issuer-ca",
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
view.parent_context_digest = Some(TEST_PARENT_CONTEXT);
|
||||
view.ca_validation_context_digest = Some(TEST_CA_VALIDATION_CONTEXT);
|
||||
view.policy_fingerprint = None;
|
||||
assert!(!view.matches_current_context(
|
||||
b"issuer-ca",
|
||||
Some(TEST_PARENT_CONTEXT),
|
||||
Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
Some(TEST_POLICY_FINGERPRINT)
|
||||
));
|
||||
}
|
||||
@@ -4661,7 +4664,7 @@ mod tests {
|
||||
let mut view = RoaValidationCacheView {
|
||||
entries_by_uri: HashMap::new(),
|
||||
issuer_ca_sha256_hex: Some(sha256_hex(issuer_der)),
|
||||
parent_context_digest: Some(TEST_PARENT_CONTEXT),
|
||||
ca_validation_context_digest: Some(TEST_CA_VALIDATION_CONTEXT),
|
||||
policy_fingerprint: Some(TEST_POLICY_FINGERPRINT),
|
||||
crl_sha256_by_uri: HashMap::from([(TEST_CRL_URI.to_string(), crl_hash_hex.clone())]),
|
||||
blocked: false,
|
||||
@@ -4849,7 +4852,7 @@ mod tests {
|
||||
false,
|
||||
RoaValidationCacheInput::enabled_with_context(
|
||||
Some(&view),
|
||||
TEST_PARENT_CONTEXT,
|
||||
TEST_CA_VALIDATION_CONTEXT,
|
||||
TEST_POLICY_FINGERPRINT,
|
||||
),
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user