将fetch pp cache改成使用vcir结构,跑通apnic全量同步
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
use std::path::Path;
|
||||
|
||||
use sha2::Digest;
|
||||
|
||||
use rpki::data_model::manifest::ManifestObject;
|
||||
use rpki::policy::{CaFailedFetchPolicy, Policy};
|
||||
use rpki::storage::{FetchCachePpKey, FetchCachePpPack, RocksStore};
|
||||
use rpki::storage::{
|
||||
PackTime, RawByHashEntry, RocksStore, ValidatedCaInstanceResult, ValidatedManifestMeta,
|
||||
VcirArtifactKind, VcirArtifactRole, VcirArtifactValidationStatus, VcirAuditSummary,
|
||||
VcirInstanceGate, VcirRelatedArtifact, VcirSummary,
|
||||
};
|
||||
use rpki::validation::manifest::{PublicationPointSource, process_manifest_publication_point};
|
||||
|
||||
fn issuer_ca_fixture() -> Vec<u8> {
|
||||
@@ -38,8 +44,78 @@ fn fixture_dir_to_rsync_uri(dir: &Path) -> String {
|
||||
s
|
||||
}
|
||||
|
||||
fn store_validated_manifest_baseline(
|
||||
store: &RocksStore,
|
||||
manifest_rsync_uri: &str,
|
||||
manifest_bytes: &[u8],
|
||||
manifest_number_be: Vec<u8>,
|
||||
this_update: time::OffsetDateTime,
|
||||
next_update: time::OffsetDateTime,
|
||||
) {
|
||||
let manifest_sha256 = hex::encode(sha2::Sha256::digest(manifest_bytes));
|
||||
let mut manifest_raw =
|
||||
RawByHashEntry::from_bytes(manifest_sha256.clone(), manifest_bytes.to_vec());
|
||||
manifest_raw
|
||||
.origin_uris
|
||||
.push(manifest_rsync_uri.to_string());
|
||||
manifest_raw.object_type = Some("mft".to_string());
|
||||
manifest_raw.encoding = Some("der".to_string());
|
||||
store
|
||||
.put_raw_by_hash_entry(&manifest_raw)
|
||||
.expect("store VCIR manifest raw_by_hash");
|
||||
|
||||
let vcir = ValidatedCaInstanceResult {
|
||||
manifest_rsync_uri: manifest_rsync_uri.to_string(),
|
||||
parent_manifest_rsync_uri: None,
|
||||
tal_id: "test-tal".to_string(),
|
||||
ca_subject_name: "CN=test".to_string(),
|
||||
ca_ski: "aa".to_string(),
|
||||
issuer_ski: "aa".to_string(),
|
||||
last_successful_validation_time: PackTime::from_utc_offset_datetime(this_update),
|
||||
current_manifest_rsync_uri: manifest_rsync_uri.to_string(),
|
||||
current_crl_rsync_uri: format!("{manifest_rsync_uri}.crl"),
|
||||
validated_manifest_meta: ValidatedManifestMeta {
|
||||
validated_manifest_number: manifest_number_be,
|
||||
validated_manifest_this_update: PackTime::from_utc_offset_datetime(this_update),
|
||||
validated_manifest_next_update: PackTime::from_utc_offset_datetime(next_update),
|
||||
},
|
||||
instance_gate: VcirInstanceGate {
|
||||
manifest_next_update: PackTime::from_utc_offset_datetime(next_update),
|
||||
current_crl_next_update: PackTime::from_utc_offset_datetime(next_update),
|
||||
self_ca_not_after: PackTime::from_utc_offset_datetime(next_update),
|
||||
instance_effective_until: PackTime::from_utc_offset_datetime(next_update),
|
||||
},
|
||||
child_entries: Vec::new(),
|
||||
local_outputs: Vec::new(),
|
||||
related_artifacts: vec![VcirRelatedArtifact {
|
||||
artifact_role: VcirArtifactRole::Manifest,
|
||||
artifact_kind: VcirArtifactKind::Mft,
|
||||
uri: Some(manifest_rsync_uri.to_string()),
|
||||
sha256: manifest_sha256,
|
||||
object_type: Some("mft".to_string()),
|
||||
validation_status: VcirArtifactValidationStatus::Accepted,
|
||||
}],
|
||||
summary: VcirSummary {
|
||||
local_vrp_count: 0,
|
||||
local_aspa_count: 0,
|
||||
child_count: 0,
|
||||
accepted_object_count: 1,
|
||||
rejected_object_count: 0,
|
||||
},
|
||||
audit_summary: VcirAuditSummary {
|
||||
failed_fetch_eligible: true,
|
||||
last_failed_fetch_reason: None,
|
||||
warning_count: 0,
|
||||
audit_flags: Vec::new(),
|
||||
},
|
||||
};
|
||||
store
|
||||
.put_vcir(&vcir)
|
||||
.expect("store validated manifest baseline");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manifest_success_writes_fetch_cache_pp_pack() {
|
||||
fn manifest_success_returns_validated_publication_point_data() {
|
||||
let manifest_path = Path::new(
|
||||
"tests/fixtures/repository/rpki.cernet.net/repo/cernet/0/05FC9C5B88506F7C0D3F862C8895BED67E9F8EBA.mft",
|
||||
);
|
||||
@@ -87,21 +163,15 @@ fn manifest_success_writes_fetch_cache_pp_pack() {
|
||||
assert_eq!(out.source, PublicationPointSource::Fresh);
|
||||
assert!(out.warnings.is_empty());
|
||||
|
||||
let key = FetchCachePpKey::from_manifest_rsync_uri(&manifest_rsync_uri);
|
||||
let stored = store
|
||||
.get_fetch_cache_pp(&key)
|
||||
.expect("get fetch_cache_pp")
|
||||
.expect("fetch_cache_pp pack exists");
|
||||
let decoded = FetchCachePpPack::decode(&stored).expect("decode stored pack");
|
||||
assert_eq!(decoded.manifest_rsync_uri, manifest_rsync_uri);
|
||||
assert_eq!(out.snapshot.manifest_rsync_uri, manifest_rsync_uri);
|
||||
assert_eq!(
|
||||
decoded.publication_point_rsync_uri,
|
||||
out.snapshot.publication_point_rsync_uri,
|
||||
publication_point_rsync_uri
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manifest_hash_mismatch_falls_back_to_fetch_cache_pp_when_enabled() {
|
||||
fn manifest_hash_mismatch_reuses_current_instance_vcir_when_enabled() {
|
||||
let manifest_path = Path::new(
|
||||
"tests/fixtures/repository/rpki.cernet.net/repo/cernet/0/05FC9C5B88506F7C0D3F862C8895BED67E9F8EBA.mft",
|
||||
);
|
||||
@@ -144,15 +214,17 @@ fn manifest_hash_mismatch_falls_back_to_fetch_cache_pp_when_enabled() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
validation_time,
|
||||
)
|
||||
.expect("first run stores fetch_cache_pp pack");
|
||||
.expect("first run returns validated publication point");
|
||||
assert_eq!(first.source, PublicationPointSource::Fresh);
|
||||
|
||||
let key = FetchCachePpKey::from_manifest_rsync_uri(&manifest_rsync_uri);
|
||||
let cached_bytes = store
|
||||
.get_fetch_cache_pp(&key)
|
||||
.expect("get fetch_cache_pp")
|
||||
.expect("fetch_cache_pp pack exists");
|
||||
let cached_pack = FetchCachePpPack::decode(&cached_bytes).expect("decode cached");
|
||||
store_validated_manifest_baseline(
|
||||
&store,
|
||||
&manifest_rsync_uri,
|
||||
&manifest_bytes,
|
||||
manifest.manifest.manifest_number.bytes_be.clone(),
|
||||
manifest.manifest.this_update,
|
||||
manifest.manifest.next_update,
|
||||
);
|
||||
|
||||
let entries = manifest
|
||||
.manifest
|
||||
@@ -176,10 +248,14 @@ fn manifest_hash_mismatch_falls_back_to_fetch_cache_pp_when_enabled() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
validation_time,
|
||||
)
|
||||
.expect("second run falls back to fetch_cache_pp");
|
||||
assert_eq!(second.source, PublicationPointSource::FetchCachePp);
|
||||
assert!(!second.warnings.is_empty());
|
||||
assert_eq!(second.pack, cached_pack);
|
||||
.expect("second run reuses current-instance VCIR");
|
||||
assert_eq!(second.source, PublicationPointSource::VcirCurrentInstance);
|
||||
assert!(
|
||||
second.warnings.iter().any(|w| w
|
||||
.message
|
||||
.contains("using latest validated result for current CA instance")),
|
||||
"expected current-instance VCIR reuse warning"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -216,7 +292,7 @@ fn manifest_failed_fetch_stop_all_output() {
|
||||
}
|
||||
|
||||
let mut policy = Policy::default();
|
||||
policy.ca_failed_fetch_policy = CaFailedFetchPolicy::UseFetchCachePp;
|
||||
policy.ca_failed_fetch_policy = CaFailedFetchPolicy::ReuseCurrentInstanceVcir;
|
||||
let issuer_ca_der = issuer_ca_fixture();
|
||||
let _ = process_manifest_publication_point(
|
||||
&store,
|
||||
@@ -227,7 +303,7 @@ fn manifest_failed_fetch_stop_all_output() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
validation_time,
|
||||
)
|
||||
.expect("first run stores fetch_cache_pp pack");
|
||||
.expect("first run returns validated publication point");
|
||||
|
||||
let entries = manifest
|
||||
.manifest
|
||||
@@ -252,13 +328,13 @@ fn manifest_failed_fetch_stop_all_output() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
validation_time,
|
||||
)
|
||||
.expect_err("stop_all_output should not use fetch_cache_pp");
|
||||
.expect_err("stop_all_output should not reuse current-instance VCIR");
|
||||
let msg = err.to_string();
|
||||
assert!(msg.contains("cache use is disabled"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manifest_fallback_pack_is_revalidated_and_rejected_if_stale() {
|
||||
fn manifest_failed_fetch_rejects_stale_current_instance_vcir() {
|
||||
let manifest_path = Path::new(
|
||||
"tests/fixtures/repository/rpki.cernet.net/repo/cernet/0/05FC9C5B88506F7C0D3F862C8895BED67E9F8EBA.mft",
|
||||
);
|
||||
@@ -302,7 +378,16 @@ fn manifest_fallback_pack_is_revalidated_and_rejected_if_stale() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
ok_time,
|
||||
)
|
||||
.expect("first run stores fetch_cache_pp pack");
|
||||
.expect("first run returns validated publication point");
|
||||
|
||||
store_validated_manifest_baseline(
|
||||
&store,
|
||||
&manifest_rsync_uri,
|
||||
&manifest_bytes,
|
||||
manifest.manifest.manifest_number.bytes_be.clone(),
|
||||
manifest.manifest.this_update,
|
||||
manifest.manifest.next_update,
|
||||
);
|
||||
|
||||
store
|
||||
.delete_raw(&manifest_rsync_uri)
|
||||
@@ -317,9 +402,9 @@ fn manifest_fallback_pack_is_revalidated_and_rejected_if_stale() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
stale_time,
|
||||
)
|
||||
.expect_err("stale validation_time must reject fetch_cache_pp pack");
|
||||
.expect_err("stale validation_time must reject current-instance VCIR reuse");
|
||||
let msg = err.to_string();
|
||||
assert!(msg.contains("not valid at validation_time"));
|
||||
assert!(msg.contains("instance_gate expired"), "{msg}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -369,9 +454,18 @@ fn manifest_revalidation_with_unchanged_manifest_is_fresh() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
t1,
|
||||
)
|
||||
.expect("first run builds and stores fetch_cache_pp pack");
|
||||
.expect("first run returns validated publication point");
|
||||
assert_eq!(first.source, PublicationPointSource::Fresh);
|
||||
|
||||
store_validated_manifest_baseline(
|
||||
&store,
|
||||
&manifest_rsync_uri,
|
||||
&manifest_bytes,
|
||||
first.snapshot.manifest_number_be.clone(),
|
||||
manifest.manifest.this_update,
|
||||
manifest.manifest.next_update,
|
||||
);
|
||||
|
||||
let second = process_manifest_publication_point(
|
||||
&store,
|
||||
&policy,
|
||||
@@ -384,16 +478,19 @@ fn manifest_revalidation_with_unchanged_manifest_is_fresh() {
|
||||
.expect("second run should accept revalidation of the same manifest");
|
||||
assert_eq!(second.source, PublicationPointSource::Fresh);
|
||||
assert!(second.warnings.is_empty());
|
||||
assert_eq!(second.pack.manifest_bytes, first.pack.manifest_bytes);
|
||||
assert_eq!(
|
||||
second.pack.manifest_number_be,
|
||||
first.pack.manifest_number_be
|
||||
second.snapshot.manifest_bytes,
|
||||
first.snapshot.manifest_bytes
|
||||
);
|
||||
assert_eq!(second.pack.files, first.pack.files);
|
||||
assert_eq!(
|
||||
second.snapshot.manifest_number_be,
|
||||
first.snapshot.manifest_number_be
|
||||
);
|
||||
assert_eq!(second.snapshot.files, first.snapshot.files);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manifest_rollback_is_treated_as_failed_fetch_and_uses_fetch_cache_pp() {
|
||||
fn manifest_rollback_is_treated_as_failed_fetch_and_reuses_current_instance_vcir() {
|
||||
let manifest_path = Path::new(
|
||||
"tests/fixtures/repository/rpki.cernet.net/repo/cernet/0/05FC9C5B88506F7C0D3F862C8895BED67E9F8EBA.mft",
|
||||
);
|
||||
@@ -439,16 +536,11 @@ fn manifest_rollback_is_treated_as_failed_fetch_and_uses_fetch_cache_pp() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
t1,
|
||||
)
|
||||
.expect("first run builds and stores fetch_cache_pp pack");
|
||||
.expect("first run returns validated publication point");
|
||||
assert_eq!(first.source, PublicationPointSource::Fresh);
|
||||
|
||||
// Simulate a previously validated manifest with a higher manifestNumber (rollback detection).
|
||||
let key = FetchCachePpKey::from_manifest_rsync_uri(&manifest_rsync_uri);
|
||||
let stored = store
|
||||
.get_fetch_cache_pp(&key)
|
||||
.expect("get fetch_cache_pp")
|
||||
.expect("fetch_cache_pp pack exists");
|
||||
let mut bumped = FetchCachePpPack::decode(&stored).expect("decode stored pack");
|
||||
let mut bumped = first.snapshot.clone();
|
||||
// Deterministically bump the cached manifestNumber to be strictly greater than the current one.
|
||||
for i in (0..bumped.manifest_number_be.len()).rev() {
|
||||
let (v, carry) = bumped.manifest_number_be[i].overflowing_add(1);
|
||||
@@ -461,10 +553,14 @@ fn manifest_rollback_is_treated_as_failed_fetch_and_uses_fetch_cache_pp() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let bumped_bytes = bumped.encode().expect("encode bumped pack");
|
||||
store
|
||||
.put_fetch_cache_pp(&key, &bumped_bytes)
|
||||
.expect("store bumped pack");
|
||||
store_validated_manifest_baseline(
|
||||
&store,
|
||||
&manifest_rsync_uri,
|
||||
&manifest_bytes,
|
||||
bumped.manifest_number_be.clone(),
|
||||
manifest.manifest.this_update,
|
||||
manifest.manifest.next_update,
|
||||
);
|
||||
|
||||
let second = process_manifest_publication_point(
|
||||
&store,
|
||||
@@ -475,9 +571,8 @@ fn manifest_rollback_is_treated_as_failed_fetch_and_uses_fetch_cache_pp() {
|
||||
Some(issuer_ca_rsync_uri()),
|
||||
t2,
|
||||
)
|
||||
.expect("second run should treat rollback as failed fetch and use cache");
|
||||
assert_eq!(second.source, PublicationPointSource::FetchCachePp);
|
||||
assert_eq!(second.pack, bumped);
|
||||
.expect("second run should treat rollback as failed fetch and reuse current-instance VCIR");
|
||||
assert_eq!(second.source, PublicationPointSource::VcirCurrentInstance);
|
||||
assert!(
|
||||
second
|
||||
.warnings
|
||||
|
||||
Reference in New Issue
Block a user