将fetch pp cache改成使用vcir结构,跑通apnic全量同步
This commit is contained in:
@@ -10,6 +10,7 @@ use rpki::validation::from_tal::{
|
||||
discover_root_ca_instance_from_tal_and_ta_der, discover_root_ca_instance_from_tal_url,
|
||||
run_root_from_tal_url_once,
|
||||
};
|
||||
use rpki::validation::manifest::PublicationPointSource;
|
||||
use url::Url;
|
||||
|
||||
struct MapFetcher {
|
||||
@@ -42,6 +43,26 @@ impl RsyncFetcher for EmptyRsync {
|
||||
}
|
||||
}
|
||||
|
||||
fn openssl_available() -> bool {
|
||||
std::process::Command::new("openssl")
|
||||
.arg("version")
|
||||
.output()
|
||||
.map(|o| o.status.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn run(cmd: &mut std::process::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 apnic_tal_bytes() -> Vec<u8> {
|
||||
std::fs::read("tests/fixtures/tal/apnic-rfc7730-https.tal").expect("read apnic TAL fixture")
|
||||
}
|
||||
@@ -145,7 +166,7 @@ fn discover_root_from_tal_url_errors_when_tal_fetch_fails() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_root_from_tal_url_once_propagates_run_error_when_repo_is_empty() {
|
||||
fn run_root_from_tal_url_once_returns_failed_fetch_no_cache_when_repo_is_empty() {
|
||||
let tal_bytes = apnic_tal_bytes();
|
||||
let tal = Tal::decode_bytes(&tal_bytes).expect("decode TAL");
|
||||
let ta_uri = tal.ta_uris[0].as_str().to_string();
|
||||
@@ -161,7 +182,7 @@ fn run_root_from_tal_url_once_propagates_run_error_when_repo_is_empty() {
|
||||
let mut policy = Policy::default();
|
||||
policy.sync_preference = SyncPreference::RsyncOnly;
|
||||
|
||||
let err = run_root_from_tal_url_once(
|
||||
let out = run_root_from_tal_url_once(
|
||||
&store,
|
||||
&policy,
|
||||
"https://example.test/apnic.tal",
|
||||
@@ -169,7 +190,105 @@ fn run_root_from_tal_url_once_propagates_run_error_when_repo_is_empty() {
|
||||
&EmptyRsync,
|
||||
time::OffsetDateTime::now_utc(),
|
||||
)
|
||||
.unwrap_err();
|
||||
.expect("run should return failed-fetch-no-cache output");
|
||||
|
||||
assert!(matches!(err, FromTalError::Run(_)));
|
||||
assert_eq!(
|
||||
out.run.publication_point_source,
|
||||
PublicationPointSource::FailedFetchNoCache
|
||||
);
|
||||
assert!(out.run.objects.vrps.is_empty());
|
||||
assert!(out.run.objects.aspas.is_empty());
|
||||
assert!(
|
||||
out.run
|
||||
.publication_point_warnings
|
||||
.iter()
|
||||
.any(|warning| warning.message.contains("no latest validated result"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discover_root_records_ca_instance_discovery_failure_when_ta_lacks_sia() {
|
||||
use base64::Engine;
|
||||
|
||||
assert!(openssl_available(), "openssl is required for this test");
|
||||
|
||||
let temp = tempfile::tempdir().expect("tempdir");
|
||||
let dir = temp.path();
|
||||
std::fs::write(
|
||||
dir.join("openssl.cnf"),
|
||||
r#"
|
||||
[ req ]
|
||||
prompt = no
|
||||
distinguished_name = dn
|
||||
x509_extensions = v3_ta
|
||||
|
||||
[ dn ]
|
||||
CN = Test TA Without SIA
|
||||
|
||||
[ v3_ta ]
|
||||
basicConstraints = critical,CA:true
|
||||
keyUsage = critical, keyCertSign, cRLSign
|
||||
subjectKeyIdentifier = hash
|
||||
certificatePolicies = critical, 1.3.6.1.5.5.7.14.2
|
||||
sbgp-ipAddrBlock = critical, IPv4:10.0.0.0/8
|
||||
sbgp-autonomousSysNum = critical, AS:64496-64511
|
||||
"#,
|
||||
)
|
||||
.expect("write openssl cnf");
|
||||
|
||||
run(std::process::Command::new("openssl")
|
||||
.arg("genrsa")
|
||||
.arg("-out")
|
||||
.arg(dir.join("ta.key"))
|
||||
.arg("2048"));
|
||||
run(std::process::Command::new("openssl")
|
||||
.arg("req")
|
||||
.arg("-new")
|
||||
.arg("-x509")
|
||||
.arg("-sha256")
|
||||
.arg("-days")
|
||||
.arg("365")
|
||||
.arg("-key")
|
||||
.arg(dir.join("ta.key"))
|
||||
.arg("-config")
|
||||
.arg(dir.join("openssl.cnf"))
|
||||
.arg("-extensions")
|
||||
.arg("v3_ta")
|
||||
.arg("-out")
|
||||
.arg(dir.join("ta.pem")));
|
||||
run(std::process::Command::new("openssl")
|
||||
.arg("x509")
|
||||
.arg("-in")
|
||||
.arg(dir.join("ta.pem"))
|
||||
.arg("-outform")
|
||||
.arg("DER")
|
||||
.arg("-out")
|
||||
.arg(dir.join("ta.cer")));
|
||||
run(std::process::Command::new("sh").arg("-c").arg(format!(
|
||||
"openssl x509 -in {} -pubkey -noout | openssl pkey -pubin -outform DER > {}",
|
||||
dir.join("ta.pem").display(),
|
||||
dir.join("spki.der").display(),
|
||||
)));
|
||||
|
||||
let ta_uri = "https://example.test/no-sia-ta.cer";
|
||||
let tal_text = format!(
|
||||
"{ta_uri}\n\n{}\n",
|
||||
base64::engine::general_purpose::STANDARD
|
||||
.encode(std::fs::read(dir.join("spki.der")).expect("read spki der"))
|
||||
);
|
||||
let tal = Tal::decode_bytes(tal_text.as_bytes()).expect("decode generated tal");
|
||||
|
||||
let mut map = HashMap::new();
|
||||
map.insert(
|
||||
ta_uri.to_string(),
|
||||
std::fs::read(dir.join("ta.cer")).expect("read ta der"),
|
||||
);
|
||||
let fetcher = MapFetcher::new(map);
|
||||
|
||||
let err = discover_root_ca_instance_from_tal(&fetcher, tal, None).unwrap_err();
|
||||
assert!(matches!(err, FromTalError::TaFetch(_)), "{err}");
|
||||
assert!(
|
||||
err.to_string().contains("CA instance discovery failed"),
|
||||
"{err}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user