串行验证通过
This commit is contained in:
836
src/validation/tree_runner.rs
Normal file
836
src/validation/tree_runner.rs
Normal file
@@ -0,0 +1,836 @@
|
||||
use crate::fetch::rsync::RsyncFetcher;
|
||||
use crate::policy::Policy;
|
||||
use crate::report::{RfcRef, Warning};
|
||||
use crate::storage::RocksStore;
|
||||
use crate::sync::repo::sync_publication_point;
|
||||
use crate::sync::rrdp::Fetcher;
|
||||
use crate::audit::{
|
||||
AuditObjectKind, AuditObjectResult, AuditWarning, ObjectAuditEntry, PublicationPointAudit,
|
||||
sha256_hex, sha256_hex_from_32,
|
||||
};
|
||||
use crate::validation::ca_instance::ca_instance_uris_from_ca_certificate;
|
||||
use crate::validation::ca_path::{CaPathError, validate_subordinate_ca_cert};
|
||||
use crate::validation::manifest::{PublicationPointSource, process_manifest_publication_point};
|
||||
use crate::validation::objects::process_verified_publication_point_pack_for_issuer;
|
||||
use crate::validation::tree::{CaInstanceHandle, PublicationPointRunResult, PublicationPointRunner};
|
||||
|
||||
pub struct Rpkiv1PublicationPointRunner<'a> {
|
||||
pub store: &'a RocksStore,
|
||||
pub policy: &'a Policy,
|
||||
pub http_fetcher: &'a dyn Fetcher,
|
||||
pub rsync_fetcher: &'a dyn RsyncFetcher,
|
||||
pub validation_time: time::OffsetDateTime,
|
||||
}
|
||||
|
||||
impl<'a> PublicationPointRunner for Rpkiv1PublicationPointRunner<'a> {
|
||||
fn run_publication_point(
|
||||
&self,
|
||||
ca: &CaInstanceHandle,
|
||||
) -> Result<PublicationPointRunResult, String> {
|
||||
let mut warnings: Vec<Warning> = Vec::new();
|
||||
|
||||
if let Err(e) = sync_publication_point(
|
||||
self.store,
|
||||
self.policy,
|
||||
ca.rrdp_notification_uri.as_deref(),
|
||||
&ca.rsync_base_uri,
|
||||
self.http_fetcher,
|
||||
self.rsync_fetcher,
|
||||
) {
|
||||
warnings.push(
|
||||
Warning::new(format!("repo sync failed (continuing with cached/raw data): {e}"))
|
||||
.with_rfc_refs(&[RfcRef("RFC 8182 §3.4.5"), RfcRef("RFC 9286 §6.6")])
|
||||
.with_context(&ca.rsync_base_uri),
|
||||
);
|
||||
}
|
||||
|
||||
let pp = match process_manifest_publication_point(
|
||||
self.store,
|
||||
self.policy,
|
||||
&ca.manifest_rsync_uri,
|
||||
&ca.publication_point_rsync_uri,
|
||||
self.validation_time,
|
||||
) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return Err(format!("{e}")),
|
||||
};
|
||||
|
||||
warnings.extend(pp.warnings.clone());
|
||||
|
||||
let objects = process_verified_publication_point_pack_for_issuer(
|
||||
&pp.pack,
|
||||
self.policy,
|
||||
&ca.ca_certificate_der,
|
||||
ca.ca_certificate_rsync_uri.as_deref(),
|
||||
ca.effective_ip_resources.as_ref(),
|
||||
ca.effective_as_resources.as_ref(),
|
||||
self.validation_time,
|
||||
);
|
||||
|
||||
let (discovered_children, child_audits) = if pp.source == PublicationPointSource::Fresh {
|
||||
match discover_children_from_fresh_pack_with_audit(ca, &pp.pack, self.validation_time) {
|
||||
Ok(out) => (out.children, out.audits),
|
||||
Err(e) => {
|
||||
warnings.push(
|
||||
Warning::new(format!("child CA discovery failed: {e}"))
|
||||
.with_rfc_refs(&[RfcRef("RFC 6487 §7.2")])
|
||||
.with_context(&ca.manifest_rsync_uri),
|
||||
);
|
||||
(Vec::new(), Vec::new())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(Vec::new(), Vec::new())
|
||||
};
|
||||
|
||||
let audit = build_publication_point_audit(ca, &pp, &warnings, &objects, &child_audits);
|
||||
|
||||
Ok(PublicationPointRunResult {
|
||||
source: pp.source,
|
||||
pack: pp.pack,
|
||||
warnings,
|
||||
objects,
|
||||
audit,
|
||||
discovered_children,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ChildDiscoveryOutput {
|
||||
children: Vec<CaInstanceHandle>,
|
||||
audits: Vec<ObjectAuditEntry>,
|
||||
}
|
||||
|
||||
fn discover_children_from_fresh_pack_with_audit(
|
||||
issuer: &CaInstanceHandle,
|
||||
pack: &crate::storage::VerifiedPublicationPointPack,
|
||||
validation_time: time::OffsetDateTime,
|
||||
) -> Result<ChildDiscoveryOutput, String> {
|
||||
let issuer_ca_der = issuer.ca_certificate_der.as_slice();
|
||||
let (issuer_crl_uri, issuer_crl_der) = select_issuer_crl_from_pack(issuer, pack)?;
|
||||
|
||||
let mut out: Vec<CaInstanceHandle> = Vec::new();
|
||||
let mut audits: Vec<ObjectAuditEntry> = Vec::new();
|
||||
for f in &pack.files {
|
||||
if !f.rsync_uri.ends_with(".cer") {
|
||||
continue;
|
||||
}
|
||||
let child_der = f.bytes.as_slice();
|
||||
|
||||
let validated = match validate_subordinate_ca_cert(
|
||||
child_der,
|
||||
issuer_ca_der,
|
||||
issuer_crl_der,
|
||||
issuer.ca_certificate_rsync_uri.as_deref(),
|
||||
issuer_crl_uri,
|
||||
issuer.effective_ip_resources.as_ref(),
|
||||
issuer.effective_as_resources.as_ref(),
|
||||
validation_time,
|
||||
) {
|
||||
Ok(v) => v,
|
||||
Err(CaPathError::ChildNotCa) => {
|
||||
audits.push(ObjectAuditEntry {
|
||||
rsync_uri: f.rsync_uri.clone(),
|
||||
sha256_hex: sha256_hex_from_32(&f.sha256),
|
||||
kind: AuditObjectKind::Certificate,
|
||||
result: AuditObjectResult::Skipped,
|
||||
detail: Some("skipped: not a CA resource certificate".to_string()),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
audits.push(ObjectAuditEntry {
|
||||
rsync_uri: f.rsync_uri.clone(),
|
||||
sha256_hex: sha256_hex_from_32(&f.sha256),
|
||||
kind: AuditObjectKind::Certificate,
|
||||
result: AuditObjectResult::Error,
|
||||
detail: Some(e.to_string()),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let uris = match ca_instance_uris_from_ca_certificate(&validated.child_ca) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
audits.push(ObjectAuditEntry {
|
||||
rsync_uri: f.rsync_uri.clone(),
|
||||
sha256_hex: sha256_hex_from_32(&f.sha256),
|
||||
kind: AuditObjectKind::Certificate,
|
||||
result: AuditObjectResult::Error,
|
||||
detail: Some(format!("CA instance URI discovery failed: {e}")),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
out.push(CaInstanceHandle {
|
||||
depth: 0,
|
||||
ca_certificate_der: child_der.to_vec(),
|
||||
ca_certificate_rsync_uri: Some(f.rsync_uri.clone()),
|
||||
effective_ip_resources: validated.effective_ip_resources.clone(),
|
||||
effective_as_resources: validated.effective_as_resources.clone(),
|
||||
rsync_base_uri: uris.rsync_base_uri,
|
||||
manifest_rsync_uri: uris.manifest_rsync_uri,
|
||||
publication_point_rsync_uri: uris.publication_point_rsync_uri,
|
||||
rrdp_notification_uri: uris.rrdp_notification_uri,
|
||||
});
|
||||
|
||||
audits.push(ObjectAuditEntry {
|
||||
rsync_uri: f.rsync_uri.clone(),
|
||||
sha256_hex: sha256_hex_from_32(&f.sha256),
|
||||
kind: AuditObjectKind::Certificate,
|
||||
result: AuditObjectResult::Ok,
|
||||
detail: Some("validated subordinate CA certificate; enqueued CA instance".to_string()),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(ChildDiscoveryOutput { children: out, audits })
|
||||
}
|
||||
|
||||
fn select_issuer_crl_from_pack<'a>(
|
||||
issuer: &CaInstanceHandle,
|
||||
pack: &'a crate::storage::VerifiedPublicationPointPack,
|
||||
) -> Result<(&'a str, &'a [u8]), String> {
|
||||
let issuer_ca = crate::data_model::rc::ResourceCertificate::decode_der(&issuer.ca_certificate_der)
|
||||
.map_err(|e| e.to_string())?;
|
||||
let subject_dn = issuer_ca.tbs.subject_dn;
|
||||
|
||||
if let Some(uris) = issuer_ca.tbs.extensions.crl_distribution_points_uris.as_ref() {
|
||||
for u in uris {
|
||||
let s = u.as_str();
|
||||
if let Some(f) = pack.files.iter().find(|f| f.rsync_uri == s) {
|
||||
return Ok((f.rsync_uri.as_str(), f.bytes.as_slice()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for f in &pack.files {
|
||||
if !f.rsync_uri.ends_with(".crl") {
|
||||
continue;
|
||||
}
|
||||
let Ok(crl) = crate::data_model::crl::RpkixCrl::decode_der(&f.bytes) else {
|
||||
continue;
|
||||
};
|
||||
if crl.issuer_dn == subject_dn {
|
||||
return Ok((f.rsync_uri.as_str(), f.bytes.as_slice()));
|
||||
}
|
||||
}
|
||||
Err("issuer CRL not found in verified pack (RFC 9286 §7)".to_string())
|
||||
}
|
||||
|
||||
fn kind_from_rsync_uri(uri: &str) -> AuditObjectKind {
|
||||
if uri.ends_with(".crl") {
|
||||
AuditObjectKind::Crl
|
||||
} else if uri.ends_with(".cer") {
|
||||
AuditObjectKind::Certificate
|
||||
} else if uri.ends_with(".roa") {
|
||||
AuditObjectKind::Roa
|
||||
} else if uri.ends_with(".asa") {
|
||||
AuditObjectKind::Aspa
|
||||
} else {
|
||||
AuditObjectKind::Other
|
||||
}
|
||||
}
|
||||
|
||||
fn build_publication_point_audit(
|
||||
ca: &CaInstanceHandle,
|
||||
pp: &crate::validation::manifest::PublicationPointResult,
|
||||
runner_warnings: &[Warning],
|
||||
objects: &crate::validation::objects::ObjectsOutput,
|
||||
child_audits: &[ObjectAuditEntry],
|
||||
) -> PublicationPointAudit {
|
||||
use crate::data_model::crl::RpkixCrl;
|
||||
use crate::validation::manifest::PublicationPointSource;
|
||||
use std::collections::HashMap;
|
||||
|
||||
let mut audit_by_uri: HashMap<String, ObjectAuditEntry> = HashMap::new();
|
||||
for f in &pp.pack.files {
|
||||
audit_by_uri.insert(
|
||||
f.rsync_uri.clone(),
|
||||
ObjectAuditEntry {
|
||||
rsync_uri: f.rsync_uri.clone(),
|
||||
sha256_hex: sha256_hex_from_32(&f.sha256),
|
||||
kind: kind_from_rsync_uri(&f.rsync_uri),
|
||||
result: AuditObjectResult::Skipped,
|
||||
detail: Some("skipped: not processed in stage2".to_string()),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// CRL decode status (best-effort).
|
||||
for f in &pp.pack.files {
|
||||
if !f.rsync_uri.ends_with(".crl") {
|
||||
continue;
|
||||
}
|
||||
let ok = RpkixCrl::decode_der(&f.bytes).is_ok();
|
||||
audit_by_uri.insert(
|
||||
f.rsync_uri.clone(),
|
||||
ObjectAuditEntry {
|
||||
rsync_uri: f.rsync_uri.clone(),
|
||||
sha256_hex: sha256_hex_from_32(&f.sha256),
|
||||
kind: AuditObjectKind::Crl,
|
||||
result: if ok {
|
||||
AuditObjectResult::Ok
|
||||
} else {
|
||||
AuditObjectResult::Error
|
||||
},
|
||||
detail: if ok {
|
||||
None
|
||||
} else {
|
||||
Some("CRL decode failed".to_string())
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Child discovery audits (.cer).
|
||||
for e in child_audits {
|
||||
audit_by_uri.insert(e.rsync_uri.clone(), e.clone());
|
||||
}
|
||||
|
||||
// Signed object audits (.roa/.asa).
|
||||
for e in &objects.audit {
|
||||
audit_by_uri.insert(e.rsync_uri.clone(), e.clone());
|
||||
}
|
||||
|
||||
// Emit as a stable order: manifest first, then pack files as listed in the pack.
|
||||
let mut objects_out: Vec<ObjectAuditEntry> = Vec::with_capacity(pp.pack.files.len() + 1);
|
||||
objects_out.push(ObjectAuditEntry {
|
||||
rsync_uri: pp.pack.manifest_rsync_uri.clone(),
|
||||
sha256_hex: sha256_hex(&pp.pack.manifest_bytes),
|
||||
kind: AuditObjectKind::Manifest,
|
||||
result: AuditObjectResult::Ok,
|
||||
detail: None,
|
||||
});
|
||||
for f in &pp.pack.files {
|
||||
if let Some(e) = audit_by_uri.remove(&f.rsync_uri) {
|
||||
objects_out.push(e);
|
||||
} else {
|
||||
objects_out.push(ObjectAuditEntry {
|
||||
rsync_uri: f.rsync_uri.clone(),
|
||||
sha256_hex: sha256_hex_from_32(&f.sha256),
|
||||
kind: kind_from_rsync_uri(&f.rsync_uri),
|
||||
result: AuditObjectResult::Skipped,
|
||||
detail: Some("skipped: no audit entry".to_string()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let mut warnings = Vec::new();
|
||||
// `runner_warnings` already includes `pp.warnings` (mirrors the runtime propagation behavior).
|
||||
warnings.extend(runner_warnings.iter().map(AuditWarning::from));
|
||||
warnings.extend(objects.warnings.iter().map(AuditWarning::from));
|
||||
|
||||
PublicationPointAudit {
|
||||
rsync_base_uri: ca.rsync_base_uri.clone(),
|
||||
manifest_rsync_uri: ca.manifest_rsync_uri.clone(),
|
||||
publication_point_rsync_uri: ca.publication_point_rsync_uri.clone(),
|
||||
rrdp_notification_uri: ca.rrdp_notification_uri.clone(),
|
||||
source: match pp.source {
|
||||
PublicationPointSource::Fresh => "fresh".to_string(),
|
||||
PublicationPointSource::VerifiedCache => "verified_cache".to_string(),
|
||||
},
|
||||
this_update_rfc3339_utc: pp.pack.this_update.rfc3339_utc.clone(),
|
||||
next_update_rfc3339_utc: pp.pack.next_update.rfc3339_utc.clone(),
|
||||
verified_at_rfc3339_utc: pp.pack.verified_at.rfc3339_utc.clone(),
|
||||
warnings,
|
||||
objects: objects_out,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::data_model::rc::ResourceCertificate;
|
||||
use crate::fetch::rsync::LocalDirRsyncFetcher;
|
||||
use crate::storage::{PackFile, PackTime, VerifiedPublicationPointPack};
|
||||
use crate::sync::rrdp::Fetcher;
|
||||
use crate::validation::tree::PublicationPointRunner;
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
struct NeverHttpFetcher;
|
||||
impl Fetcher for NeverHttpFetcher {
|
||||
fn fetch(&self, _uri: &str) -> Result<Vec<u8>, String> {
|
||||
Err("http fetch disabled in test".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn openssl_available() -> bool {
|
||||
Command::new("openssl")
|
||||
.arg("version")
|
||||
.output()
|
||||
.map(|o| o.status.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
struct Generated {
|
||||
issuer_ca_der: Vec<u8>,
|
||||
child_ca_der: Vec<u8>,
|
||||
issuer_crl_der: Vec<u8>,
|
||||
}
|
||||
|
||||
fn run(cmd: &mut Command) {
|
||||
let out = cmd.output().expect("run command");
|
||||
if !out.status.success() {
|
||||
panic!(
|
||||
"command failed: {:?}\nstdout={}\nstderr={}",
|
||||
cmd,
|
||||
String::from_utf8_lossy(&out.stdout),
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_chain_and_crl() -> Generated {
|
||||
assert!(openssl_available(), "openssl is required for this test");
|
||||
|
||||
let td = tempfile::tempdir().expect("tempdir");
|
||||
let dir = td.path();
|
||||
|
||||
std::fs::create_dir_all(dir.join("newcerts")).expect("newcerts");
|
||||
std::fs::write(dir.join("index.txt"), b"").expect("index");
|
||||
std::fs::write(dir.join("serial"), b"1000\n").expect("serial");
|
||||
std::fs::write(dir.join("crlnumber"), b"1000\n").expect("crlnumber");
|
||||
|
||||
let cnf = format!(
|
||||
r#"
|
||||
[ ca ]
|
||||
default_ca = CA_default
|
||||
|
||||
[ CA_default ]
|
||||
dir = {dir}
|
||||
database = $dir/index.txt
|
||||
new_certs_dir = $dir/newcerts
|
||||
certificate = $dir/issuer.pem
|
||||
private_key = $dir/issuer.key
|
||||
serial = $dir/serial
|
||||
crlnumber = $dir/crlnumber
|
||||
default_md = sha256
|
||||
default_days = 365
|
||||
default_crl_days = 1
|
||||
policy = policy_any
|
||||
x509_extensions = v3_issuer_ca
|
||||
crl_extensions = crl_ext
|
||||
unique_subject = no
|
||||
copy_extensions = none
|
||||
|
||||
[ policy_any ]
|
||||
commonName = supplied
|
||||
|
||||
[ req ]
|
||||
prompt = no
|
||||
distinguished_name = dn
|
||||
|
||||
[ dn ]
|
||||
CN = Test Issuer CA
|
||||
|
||||
[ v3_issuer_ca ]
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = critical, keyCertSign, cRLSign
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always
|
||||
certificatePolicies = critical, 1.3.6.1.5.5.7.14.2
|
||||
subjectInfoAccess = caRepository;URI:rsync://example.test/repo/issuer/, rpkiManifest;URI:rsync://example.test/repo/issuer/issuer.mft, rpkiNotify;URI:https://example.test/notification.xml
|
||||
sbgp-ipAddrBlock = critical, IPv4:10.0.0.0/8
|
||||
sbgp-autonomousSysNum = critical, AS:64496-64511
|
||||
|
||||
[ v3_child_ca ]
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = critical, keyCertSign, cRLSign
|
||||
subjectKeyIdentifier = hash
|
||||
authorityKeyIdentifier = keyid:always
|
||||
crlDistributionPoints = URI:rsync://example.test/repo/issuer/issuer.crl
|
||||
authorityInfoAccess = caIssuers;URI:rsync://example.test/repo/issuer/issuer.cer
|
||||
certificatePolicies = critical, 1.3.6.1.5.5.7.14.2
|
||||
subjectInfoAccess = caRepository;URI:rsync://example.test/repo/child/, rpkiManifest;URI:rsync://example.test/repo/child/child.mft, rpkiNotify;URI:https://example.test/notification.xml
|
||||
sbgp-ipAddrBlock = critical, IPv4:10.0.0.0/16
|
||||
sbgp-autonomousSysNum = critical, AS:64496
|
||||
|
||||
[ crl_ext ]
|
||||
authorityKeyIdentifier = keyid:always
|
||||
"#,
|
||||
dir = dir.display()
|
||||
);
|
||||
std::fs::write(dir.join("openssl.cnf"), cnf.as_bytes()).expect("write cnf");
|
||||
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("genrsa")
|
||||
.arg("-out")
|
||||
.arg(dir.join("issuer.key"))
|
||||
.arg("2048"),
|
||||
);
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("req")
|
||||
.arg("-new")
|
||||
.arg("-x509")
|
||||
.arg("-sha256")
|
||||
.arg("-days")
|
||||
.arg("365")
|
||||
.arg("-key")
|
||||
.arg(dir.join("issuer.key"))
|
||||
.arg("-config")
|
||||
.arg(dir.join("openssl.cnf"))
|
||||
.arg("-extensions")
|
||||
.arg("v3_issuer_ca")
|
||||
.arg("-out")
|
||||
.arg(dir.join("issuer.pem")),
|
||||
);
|
||||
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("genrsa")
|
||||
.arg("-out")
|
||||
.arg(dir.join("child.key"))
|
||||
.arg("2048"),
|
||||
);
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("req")
|
||||
.arg("-new")
|
||||
.arg("-key")
|
||||
.arg(dir.join("child.key"))
|
||||
.arg("-subj")
|
||||
.arg("/CN=Test Child CA")
|
||||
.arg("-out")
|
||||
.arg(dir.join("child.csr")),
|
||||
);
|
||||
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("ca")
|
||||
.arg("-batch")
|
||||
.arg("-config")
|
||||
.arg(dir.join("openssl.cnf"))
|
||||
.arg("-in")
|
||||
.arg(dir.join("child.csr"))
|
||||
.arg("-extensions")
|
||||
.arg("v3_child_ca")
|
||||
.arg("-out")
|
||||
.arg(dir.join("child.pem")),
|
||||
);
|
||||
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("x509")
|
||||
.arg("-in")
|
||||
.arg(dir.join("issuer.pem"))
|
||||
.arg("-outform")
|
||||
.arg("DER")
|
||||
.arg("-out")
|
||||
.arg(dir.join("issuer.cer")),
|
||||
);
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("x509")
|
||||
.arg("-in")
|
||||
.arg(dir.join("child.pem"))
|
||||
.arg("-outform")
|
||||
.arg("DER")
|
||||
.arg("-out")
|
||||
.arg(dir.join("child.cer")),
|
||||
);
|
||||
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("ca")
|
||||
.arg("-gencrl")
|
||||
.arg("-config")
|
||||
.arg(dir.join("openssl.cnf"))
|
||||
.arg("-out")
|
||||
.arg(dir.join("issuer.crl.pem")),
|
||||
);
|
||||
run(
|
||||
Command::new("openssl")
|
||||
.arg("crl")
|
||||
.arg("-in")
|
||||
.arg(dir.join("issuer.crl.pem"))
|
||||
.arg("-outform")
|
||||
.arg("DER")
|
||||
.arg("-out")
|
||||
.arg(dir.join("issuer.crl")),
|
||||
);
|
||||
|
||||
Generated {
|
||||
issuer_ca_der: std::fs::read(dir.join("issuer.cer")).expect("read issuer der"),
|
||||
child_ca_der: std::fs::read(dir.join("child.cer")).expect("read child der"),
|
||||
issuer_crl_der: std::fs::read(dir.join("issuer.crl")).expect("read crl der"),
|
||||
}
|
||||
}
|
||||
|
||||
fn dummy_pack_with_files(files: Vec<PackFile>) -> VerifiedPublicationPointPack {
|
||||
let now = time::OffsetDateTime::now_utc();
|
||||
VerifiedPublicationPointPack {
|
||||
format_version: VerifiedPublicationPointPack::FORMAT_VERSION_V1,
|
||||
manifest_rsync_uri: "rsync://example.test/repo/issuer/issuer.mft".to_string(),
|
||||
publication_point_rsync_uri: "rsync://example.test/repo/issuer/".to_string(),
|
||||
this_update: PackTime::from_utc_offset_datetime(now),
|
||||
next_update: PackTime::from_utc_offset_datetime(now + time::Duration::hours(1)),
|
||||
verified_at: PackTime::from_utc_offset_datetime(now),
|
||||
manifest_bytes: vec![0x01],
|
||||
files,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn select_issuer_crl_from_pack_finds_matching_crl() {
|
||||
let g = generate_chain_and_crl();
|
||||
|
||||
let pack = dummy_pack_with_files(vec![PackFile::from_bytes_compute_sha256(
|
||||
"rsync://example.test/repo/issuer/issuer.crl",
|
||||
g.issuer_crl_der.clone(),
|
||||
)]);
|
||||
|
||||
let issuer_ca = ResourceCertificate::decode_der(&g.issuer_ca_der).expect("decode issuer");
|
||||
let issuer = CaInstanceHandle {
|
||||
depth: 0,
|
||||
ca_certificate_der: g.issuer_ca_der.clone(),
|
||||
ca_certificate_rsync_uri: None,
|
||||
effective_ip_resources: issuer_ca.tbs.extensions.ip_resources.clone(),
|
||||
effective_as_resources: issuer_ca.tbs.extensions.as_resources.clone(),
|
||||
rsync_base_uri: "rsync://example.test/repo/issuer/".to_string(),
|
||||
manifest_rsync_uri: "rsync://example.test/repo/issuer/issuer.mft".to_string(),
|
||||
publication_point_rsync_uri: "rsync://example.test/repo/issuer/".to_string(),
|
||||
rrdp_notification_uri: None,
|
||||
};
|
||||
|
||||
let (uri, found) = select_issuer_crl_from_pack(&issuer, &pack).expect("find crl");
|
||||
assert_eq!(uri, "rsync://example.test/repo/issuer/issuer.crl");
|
||||
assert_eq!(found, g.issuer_crl_der.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discover_children_from_fresh_pack_discovers_child_ca() {
|
||||
let g = generate_chain_and_crl();
|
||||
|
||||
let pack = dummy_pack_with_files(vec![
|
||||
PackFile::from_bytes_compute_sha256(
|
||||
"rsync://example.test/repo/issuer/issuer.crl",
|
||||
g.issuer_crl_der.clone(),
|
||||
),
|
||||
PackFile::from_bytes_compute_sha256(
|
||||
"rsync://example.test/repo/issuer/child.cer",
|
||||
g.child_ca_der.clone(),
|
||||
),
|
||||
]);
|
||||
|
||||
let issuer_ca = ResourceCertificate::decode_der(&g.issuer_ca_der).expect("decode issuer");
|
||||
let issuer = CaInstanceHandle {
|
||||
depth: 0,
|
||||
ca_certificate_der: g.issuer_ca_der.clone(),
|
||||
ca_certificate_rsync_uri: None,
|
||||
effective_ip_resources: issuer_ca.tbs.extensions.ip_resources.clone(),
|
||||
effective_as_resources: issuer_ca.tbs.extensions.as_resources.clone(),
|
||||
rsync_base_uri: "rsync://example.test/repo/issuer/".to_string(),
|
||||
manifest_rsync_uri: "rsync://example.test/repo/issuer/issuer.mft".to_string(),
|
||||
publication_point_rsync_uri: "rsync://example.test/repo/issuer/".to_string(),
|
||||
rrdp_notification_uri: None,
|
||||
};
|
||||
|
||||
let now = time::OffsetDateTime::now_utc();
|
||||
let children = discover_children_from_fresh_pack_with_audit(&issuer, &pack, now)
|
||||
.expect("discover children")
|
||||
.children;
|
||||
assert_eq!(children.len(), 1);
|
||||
assert_eq!(children[0].rsync_base_uri, "rsync://example.test/repo/child/".to_string());
|
||||
assert_eq!(
|
||||
children[0].manifest_rsync_uri,
|
||||
"rsync://example.test/repo/child/child.mft".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
children[0].publication_point_rsync_uri,
|
||||
"rsync://example.test/repo/child/".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
children[0].rrdp_notification_uri.as_deref(),
|
||||
Some("https://example.test/notification.xml")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runner_offline_rsync_fixture_produces_pack_and_warnings() {
|
||||
let fixture_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
|
||||
"tests/fixtures/repository/rpki.cernet.net/repo/cernet/0",
|
||||
);
|
||||
assert!(fixture_dir.is_dir(), "fixture directory must exist");
|
||||
|
||||
let rsync_base_uri = "rsync://rpki.cernet.net/repo/cernet/0/".to_string();
|
||||
let manifest_file = "05FC9C5B88506F7C0D3F862C8895BED67E9F8EBA.mft";
|
||||
let manifest_rsync_uri = format!("{rsync_base_uri}{manifest_file}");
|
||||
|
||||
// Pick a validation_time inside the fixture manifest's validity window to keep this
|
||||
// test stable across wall-clock time.
|
||||
let fixture_manifest_bytes =
|
||||
std::fs::read(fixture_dir.join(manifest_file)).expect("read manifest fixture");
|
||||
let fixture_manifest =
|
||||
crate::data_model::manifest::ManifestObject::decode_der(&fixture_manifest_bytes)
|
||||
.expect("decode manifest fixture");
|
||||
let validation_time = {
|
||||
let this_update = fixture_manifest.manifest.this_update;
|
||||
let next_update = fixture_manifest.manifest.next_update;
|
||||
let candidate = this_update + time::Duration::seconds(60);
|
||||
if candidate < next_update {
|
||||
candidate
|
||||
} else {
|
||||
this_update
|
||||
}
|
||||
};
|
||||
|
||||
let store_dir = tempfile::tempdir().expect("store dir");
|
||||
let store = RocksStore::open(store_dir.path()).expect("open rocksdb");
|
||||
let policy = Policy {
|
||||
sync_preference: crate::policy::SyncPreference::RsyncOnly,
|
||||
..Policy::default()
|
||||
};
|
||||
|
||||
let runner = Rpkiv1PublicationPointRunner {
|
||||
store: &store,
|
||||
policy: &policy,
|
||||
http_fetcher: &NeverHttpFetcher,
|
||||
rsync_fetcher: &LocalDirRsyncFetcher::new(&fixture_dir),
|
||||
validation_time,
|
||||
};
|
||||
|
||||
// For this fixture-driven smoke, we provide the correct issuer CA certificate (the CA for
|
||||
// this publication point) so ROA EE certificate paths can validate.
|
||||
let issuer_ca_der = std::fs::read(
|
||||
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
|
||||
"tests/fixtures/repository/rpki.apnic.net/repository/B527EF581D6611E2BB468F7C72FD1FF2/BfycW4hQb3wNP4YsiJW-1n6fjro.cer",
|
||||
),
|
||||
)
|
||||
.expect("read issuer ca fixture");
|
||||
let issuer_ca = ResourceCertificate::decode_der(&issuer_ca_der).expect("decode issuer ca");
|
||||
|
||||
let handle = CaInstanceHandle {
|
||||
depth: 0,
|
||||
ca_certificate_der: issuer_ca_der,
|
||||
ca_certificate_rsync_uri: Some("rsync://rpki.apnic.net/repository/B527EF581D6611E2BB468F7C72FD1FF2/BfycW4hQb3wNP4YsiJW-1n6fjro.cer".to_string()),
|
||||
effective_ip_resources: issuer_ca.tbs.extensions.ip_resources.clone(),
|
||||
effective_as_resources: issuer_ca.tbs.extensions.as_resources.clone(),
|
||||
rsync_base_uri: rsync_base_uri.clone(),
|
||||
manifest_rsync_uri: manifest_rsync_uri.clone(),
|
||||
publication_point_rsync_uri: rsync_base_uri.clone(),
|
||||
rrdp_notification_uri: None,
|
||||
};
|
||||
|
||||
let out = runner
|
||||
.run_publication_point(&handle)
|
||||
.expect("run publication point");
|
||||
assert_eq!(out.source, PublicationPointSource::Fresh);
|
||||
assert_eq!(out.pack.manifest_rsync_uri, manifest_rsync_uri);
|
||||
assert!(out.pack.files.len() > 1);
|
||||
assert!(
|
||||
out.objects.vrps.len() > 1,
|
||||
"expected to extract VRPs from ROAs"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_publication_point_audit_marks_invalid_crl_as_error_and_overlays_roa_audit() {
|
||||
let now = time::OffsetDateTime::now_utc();
|
||||
let pack = dummy_pack_with_files(vec![
|
||||
PackFile::from_bytes_compute_sha256(
|
||||
"rsync://example.test/repo/issuer/bad.crl",
|
||||
vec![0u8],
|
||||
),
|
||||
PackFile::from_bytes_compute_sha256(
|
||||
"rsync://example.test/repo/issuer/x.roa",
|
||||
vec![1u8],
|
||||
),
|
||||
]);
|
||||
|
||||
let pp = crate::validation::manifest::PublicationPointResult {
|
||||
source: crate::validation::manifest::PublicationPointSource::Fresh,
|
||||
pack: pack.clone(),
|
||||
warnings: Vec::new(),
|
||||
};
|
||||
|
||||
let issuer = CaInstanceHandle {
|
||||
depth: 0,
|
||||
ca_certificate_der: vec![1],
|
||||
ca_certificate_rsync_uri: None,
|
||||
effective_ip_resources: None,
|
||||
effective_as_resources: None,
|
||||
rsync_base_uri: "rsync://example.test/repo/issuer/".to_string(),
|
||||
manifest_rsync_uri: pack.manifest_rsync_uri.clone(),
|
||||
publication_point_rsync_uri: pack.publication_point_rsync_uri.clone(),
|
||||
rrdp_notification_uri: None,
|
||||
};
|
||||
|
||||
let objects = crate::validation::objects::ObjectsOutput {
|
||||
vrps: Vec::new(),
|
||||
aspas: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
stats: crate::validation::objects::ObjectsStats::default(),
|
||||
audit: vec![ObjectAuditEntry {
|
||||
rsync_uri: "rsync://example.test/repo/issuer/x.roa".to_string(),
|
||||
sha256_hex: sha256_hex_from_32(&pack.files[1].sha256),
|
||||
kind: AuditObjectKind::Roa,
|
||||
result: AuditObjectResult::Ok,
|
||||
detail: None,
|
||||
}],
|
||||
};
|
||||
|
||||
let audit = build_publication_point_audit(&issuer, &pp, &[], &objects, &[]);
|
||||
assert_eq!(audit.objects[0].kind, AuditObjectKind::Manifest);
|
||||
|
||||
let crl = audit
|
||||
.objects
|
||||
.iter()
|
||||
.find(|e| e.rsync_uri.ends_with("bad.crl"))
|
||||
.expect("crl entry");
|
||||
assert!(matches!(crl.result, AuditObjectResult::Error));
|
||||
|
||||
let roa = audit
|
||||
.objects
|
||||
.iter()
|
||||
.find(|e| e.rsync_uri.ends_with("x.roa"))
|
||||
.expect("roa entry");
|
||||
assert!(matches!(roa.result, AuditObjectResult::Ok));
|
||||
|
||||
// Smoke that time fields are populated from pack.
|
||||
assert!(audit.verified_at_rfc3339_utc.contains('T'));
|
||||
assert!(audit.this_update_rfc3339_utc.contains('T'));
|
||||
assert!(audit.next_update_rfc3339_utc.contains('T'));
|
||||
let _ = now;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discover_children_with_audit_records_decode_error_for_corrupt_cer() {
|
||||
let g = generate_chain_and_crl();
|
||||
|
||||
let pack = dummy_pack_with_files(vec![
|
||||
PackFile::from_bytes_compute_sha256(
|
||||
"rsync://example.test/repo/issuer/issuer.crl",
|
||||
g.issuer_crl_der.clone(),
|
||||
),
|
||||
PackFile::from_bytes_compute_sha256(
|
||||
"rsync://example.test/repo/issuer/corrupt.cer",
|
||||
vec![0u8],
|
||||
),
|
||||
]);
|
||||
|
||||
let issuer_ca = ResourceCertificate::decode_der(&g.issuer_ca_der).expect("decode issuer");
|
||||
let issuer = CaInstanceHandle {
|
||||
depth: 0,
|
||||
ca_certificate_der: g.issuer_ca_der.clone(),
|
||||
ca_certificate_rsync_uri: None,
|
||||
effective_ip_resources: issuer_ca.tbs.extensions.ip_resources.clone(),
|
||||
effective_as_resources: issuer_ca.tbs.extensions.as_resources.clone(),
|
||||
rsync_base_uri: "rsync://example.test/repo/issuer/".to_string(),
|
||||
manifest_rsync_uri: "rsync://example.test/repo/issuer/issuer.mft".to_string(),
|
||||
publication_point_rsync_uri: "rsync://example.test/repo/issuer/".to_string(),
|
||||
rrdp_notification_uri: None,
|
||||
};
|
||||
|
||||
let now = time::OffsetDateTime::now_utc();
|
||||
let out = discover_children_from_fresh_pack_with_audit(&issuer, &pack, now)
|
||||
.expect("discover children");
|
||||
assert!(out.children.is_empty());
|
||||
assert_eq!(out.audits.len(), 1);
|
||||
assert!(matches!(out.audits[0].result, AuditObjectResult::Error));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user