fix(fermata): a certificate file is judged by all of its text, not by its armor labels
API_TOKEN=x, a lowercase private block or a raw key beside a certificate block no longer pass the read gate. Bag Attributes, subject= and issuer=, a CA bundle's comments and the head of x509 -text stay allowed, so real PEMs keep passing.
This commit is contained in:
@@ -245,6 +245,42 @@ fn a_certificate_only_pem_passes_and_adds_no_entry() {
|
||||
row(&files, VALUE, Read::Passes, Elsewhere::NotMasked);
|
||||
}
|
||||
|
||||
/// Certificates with the text real files carry around them are certificate-only. Text that
|
||||
/// is none of that makes the file a secret again.
|
||||
#[test]
|
||||
fn a_certificate_file_is_judged_by_all_of_its_text() {
|
||||
const CERT: &str = "-----BEGIN CERTIFICATE-----\nFAKEFAKEfakeFAKEfake\n-----END CERTIFICATE-----\n";
|
||||
let denied = |out: Value| out["hookSpecificOutput"]["permissionDecision"] == "deny";
|
||||
for content in [
|
||||
CERT.to_string(),
|
||||
CERT.replace('\n', "\r\n"),
|
||||
format!("\n{CERT}\n{CERT}"),
|
||||
format!("Bag Attributes\n friendlyName: fake-name\n localKeyID: 01 02 03\nsubject=/CN=fake\nissuer=/CN=fake\n{CERT}"),
|
||||
format!("# Issuer: CN=Fake Root O=Fake\n# Label: \"Fake\"\n# SHA256 Fingerprint: 01:02\n{CERT}"),
|
||||
format!("Certificate:\n Data:\n Version: 3 (0x2)\n{CERT}"),
|
||||
] {
|
||||
let p = project("", "server.pem", content.as_bytes());
|
||||
assert!(!denied(p.pre_read("server.pem")), "{content:?}");
|
||||
assert!(!denied(p.pre_cat("server.pem")), "{content:?}");
|
||||
}
|
||||
for content in [
|
||||
format!("{CERT}API_TOKEN=fake-beside-a-cert\n"),
|
||||
format!("API_TOKEN=fake-beside-a-cert\n{CERT}"),
|
||||
format!("# API_TOKEN=fake-beside-a-cert\n{CERT}"),
|
||||
format!("{CERT}fake-beside-a-cert\n"),
|
||||
format!("{CERT}-----begin private key-----\nfake-beside-a-cert\n"),
|
||||
format!("{CERT}-----BEGIN PRIVATE KEY-----\nfake-beside-a-cert\n-----END PRIVATE KEY-----\n"),
|
||||
"# -----BEGIN CERTIFICATE-----\nfake-beside-a-cert\n".to_string(),
|
||||
// A block that holds another, or never ends, is no certificate.
|
||||
"-----BEGIN CERTIFICATE-----\n-----BEGIN PRIVATE KEY-----\nfake\n-----END PRIVATE KEY-----\n".to_string(),
|
||||
"-----BEGIN CERTIFICATE-----\nfake\n".to_string(),
|
||||
] {
|
||||
let p = project("", "server.pem", content.as_bytes());
|
||||
assert!(denied(p.pre_read("server.pem")), "{content:?}");
|
||||
assert!(denied(p.pre_cat("server.pem")), "{content:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Binary, whatever the name: stopped on Read, and under `deny` no refusal of everything else.
|
||||
#[test]
|
||||
fn a_binary_key_file_is_stopped_and_refuses_nothing() {
|
||||
|
||||
Reference in New Issue
Block a user