[pki] CA: the Domi CA from Ianitor core behind a Signer, agent certificates, webpki chain checks (34 tests)
This commit is contained in:
+68
-14
@@ -25,8 +25,14 @@ fn root_is_a_ten_year_ca_with_path_length_one() {
|
||||
assert_eq!(info.subject_cn, pki::ROOT_CN);
|
||||
assert_eq!(info.issuer_cn, pki::ROOT_CN);
|
||||
let days = (info.not_after - NOW) / DAY;
|
||||
assert!((ROOT_DAYS as i64 - 1..=ROOT_DAYS as i64).contains(&days), "{days}");
|
||||
assert!(pki::issued_by(&c.root_pem, &c.root_pem).unwrap(), "self-signed");
|
||||
assert!(
|
||||
(ROOT_DAYS as i64 - 1..=ROOT_DAYS as i64).contains(&days),
|
||||
"{days}"
|
||||
);
|
||||
assert!(
|
||||
pki::issued_by(&c.root_pem, &c.root_pem).unwrap(),
|
||||
"self-signed"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -41,16 +47,31 @@ fn both_intermediates_are_one_year_path_length_zero_under_the_root() {
|
||||
assert!(!pki::issued_by(&c.root_pem, int.cert_pem()).unwrap());
|
||||
}
|
||||
assert_eq!(
|
||||
pki::intermediate_problem(c.agents.cert_pem(), &c.root_pem, pki::AGENTS_INTERMEDIATE_CN, NOW),
|
||||
pki::intermediate_problem(
|
||||
c.agents.cert_pem(),
|
||||
&c.root_pem,
|
||||
pki::AGENTS_INTERMEDIATE_CN,
|
||||
NOW
|
||||
),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
pki::intermediate_problem(c.ianitor.cert_pem(), &c.root_pem, pki::IANITOR_INTERMEDIATE_CN, NOW),
|
||||
pki::intermediate_problem(
|
||||
c.ianitor.cert_pem(),
|
||||
&c.root_pem,
|
||||
pki::IANITOR_INTERMEDIATE_CN,
|
||||
NOW
|
||||
),
|
||||
None
|
||||
);
|
||||
// Each is only the intermediate it is named for.
|
||||
assert_eq!(
|
||||
pki::intermediate_problem(c.ianitor.cert_pem(), &c.root_pem, pki::AGENTS_INTERMEDIATE_CN, NOW),
|
||||
pki::intermediate_problem(
|
||||
c.ianitor.cert_pem(),
|
||||
&c.root_pem,
|
||||
pki::AGENTS_INTERMEDIATE_CN,
|
||||
NOW
|
||||
),
|
||||
Some("not_ca")
|
||||
);
|
||||
}
|
||||
@@ -73,7 +94,10 @@ fn server_chain_validates_for_its_name_only() {
|
||||
let info = pki::inspect(&leaf.cert_pem).unwrap();
|
||||
assert_eq!((info.not_after - NOW) / DAY, SERVER_DAYS as i64);
|
||||
let k = pki::KeyPair::from_pem(&leaf.key_pem).unwrap();
|
||||
assert_eq!(pki::public_key_der(&leaf.cert_pem).unwrap(), k.public_key_der());
|
||||
assert_eq!(
|
||||
pki::public_key_der(&leaf.cert_pem).unwrap(),
|
||||
k.public_key_der()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -104,7 +128,10 @@ fn a_leaf_cannot_sign() {
|
||||
let forged = pki::testing::sign_as(&leaf.cert_pem, leaf_key, "evil.home.test", NOW).unwrap();
|
||||
let chain = ders(&format!("{forged}{}", leaf.chain_pem));
|
||||
let e = pki::verify_chain(&chain, &c.root_der(), NOW + DAY, Usage::Server).unwrap_err();
|
||||
assert!(matches!(e, VerifyError::NotCa | VerifyError::UnknownIssuer), "{e:?}");
|
||||
assert!(
|
||||
matches!(e, VerifyError::NotCa | VerifyError::UnknownIssuer),
|
||||
"{e:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -143,7 +170,10 @@ fn an_expired_intermediate_fails_the_chain_and_issues_nothing() {
|
||||
let late = NOW + (INTERMEDIATE_DAYS as i64 - 10) * DAY;
|
||||
let dev = pki::issue_device(&c.ianitor, "tablet", late).unwrap();
|
||||
let info = pki::inspect(&dev.cert_pem).unwrap();
|
||||
assert!(info.not_after <= c.ianitor.not_after(), "no leaf outlives its issuer");
|
||||
assert!(
|
||||
info.not_after <= c.ianitor.not_after(),
|
||||
"no leaf outlives its issuer"
|
||||
);
|
||||
let gone = NOW + (INTERMEDIATE_DAYS as i64 + 1) * DAY;
|
||||
assert!(matches!(
|
||||
pki::issue_server(&c.agents, "fabrica.home.test", gone),
|
||||
@@ -151,7 +181,12 @@ fn an_expired_intermediate_fails_the_chain_and_issues_nothing() {
|
||||
));
|
||||
// A chain whose intermediate expired is refused even inside the leaf's own validity.
|
||||
assert_eq!(
|
||||
pki::verify_chain(&ders(&dev.chain_pem), &c.root_der(), c.ianitor.not_after() + 1, Usage::Client),
|
||||
pki::verify_chain(
|
||||
&ders(&dev.chain_pem),
|
||||
&c.root_der(),
|
||||
c.ianitor.not_after() + 1,
|
||||
Usage::Client
|
||||
),
|
||||
Err(VerifyError::Expired)
|
||||
);
|
||||
// The root refuses to sign once it has expired.
|
||||
@@ -159,7 +194,13 @@ fn an_expired_intermediate_fails_the_chain_and_issues_nothing() {
|
||||
let csr = pki::intermediate_csr(&key, pki::AGENTS_INTERMEDIATE_CN).unwrap();
|
||||
let past_root = NOW + (ROOT_DAYS as i64 + 1) * DAY;
|
||||
assert!(matches!(
|
||||
pki::sign_intermediate(&c.root_pem, &c.root, &csr, pki::AGENTS_INTERMEDIATE_CN, past_root),
|
||||
pki::sign_intermediate(
|
||||
&c.root_pem,
|
||||
&c.root,
|
||||
&csr,
|
||||
pki::AGENTS_INTERMEDIATE_CN,
|
||||
past_root
|
||||
),
|
||||
Err(PkiError::IssuerExpired)
|
||||
));
|
||||
}
|
||||
@@ -171,13 +212,26 @@ fn another_root_with_the_same_names_is_refused() {
|
||||
let c = ca();
|
||||
let other = ca();
|
||||
let leaf = pki::issue_server(&other.agents, "fabrica.home.test", NOW).unwrap();
|
||||
let e = pki::verify_chain(&ders(&leaf.chain_pem), &c.root_der(), NOW + DAY, Usage::Server)
|
||||
.unwrap_err();
|
||||
assert!(matches!(e, VerifyError::UnknownIssuer | VerifyError::BadSignature), "{e:?}");
|
||||
let e = pki::verify_chain(
|
||||
&ders(&leaf.chain_pem),
|
||||
&c.root_der(),
|
||||
NOW + DAY,
|
||||
Usage::Server,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
matches!(e, VerifyError::UnknownIssuer | VerifyError::BadSignature),
|
||||
"{e:?}"
|
||||
);
|
||||
assert!(!pki::issued_by(&leaf.cert_pem, other.ianitor.cert_pem()).unwrap());
|
||||
assert!(!pki::issued_by(other.agents.cert_pem(), &c.root_pem).unwrap());
|
||||
assert_eq!(
|
||||
pki::intermediate_problem(other.agents.cert_pem(), &c.root_pem, pki::AGENTS_INTERMEDIATE_CN, NOW),
|
||||
pki::intermediate_problem(
|
||||
other.agents.cert_pem(),
|
||||
&c.root_pem,
|
||||
pki::AGENTS_INTERMEDIATE_CN,
|
||||
NOW
|
||||
),
|
||||
Some("not_root")
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user