use std::collections::BTreeSet;
use chromium_roots::{
TLS_SERVER_ROOT_CERTS, TLS_TRUST_ANCHORS, TrustAnchorKind, encoded_trust_anchor_ids,
trust_anchor_id_for_certificate, trust_anchor_ids,
};
static TRUST_ANCHOR_IDS: [&[u8]; trust_anchor_ids().len()] = trust_anchor_ids();
static ENCODED_TRUST_ANCHOR_IDS: [u8; encoded_trust_anchor_ids().len()] =
encoded_trust_anchor_ids();
fn lowercase_hex(bytes: &[u8]) -> String {
const DIGITS: &[u8; 16] = b"0123456789abcdef";
let mut encoded = String::with_capacity(bytes.len().saturating_mul(2));
for byte in bytes {
encoded.push(char::from(DIGITS[usize::from(byte >> 4)]));
encoded.push(char::from(DIGITS[usize::from(byte & 0x0f)]));
}
encoded
}
fn main() {
println!("TLS trust-anchor certificates: {}", TLS_TRUST_ANCHORS.len());
println!(
"CertificateDer entries: {}; metadata entries: {}",
TLS_SERVER_ROOT_CERTS.len(),
TLS_TRUST_ANCHORS.len()
);
let root_entries = TLS_TRUST_ANCHORS
.iter()
.filter(|anchor| anchor.kind == TrustAnchorKind::Root)
.count();
let additional_entries = TLS_TRUST_ANCHORS
.iter()
.filter(|anchor| anchor.kind == TrustAnchorKind::Additional)
.count();
let expiring_anchors = TLS_TRUST_ANCHORS
.iter()
.filter(|anchor| anchor.enforce_anchor_expiry)
.count();
let constrained_anchors = TLS_TRUST_ANCHORS
.iter()
.filter(|anchor| anchor.enforce_anchor_constraints)
.count();
let anchors_with_chromium_rules = TLS_TRUST_ANCHORS
.iter()
.filter(|anchor| !anchor.constraints.is_empty())
.count();
println!(
"metadata: {root_entries} roots, {additional_entries} additional anchors, \
{expiring_anchors} expiry-enforced, {constrained_anchors} X.509-constrained, \
{anchors_with_chromium_rules} with Chromium-specific rules"
);
let ids_found_by_certificate = TRUST_ANCHOR_IDS.iter().copied().collect::<BTreeSet<_>>();
println!(
"unique Trust Anchor IDs found across all snapshot certificates: {}",
ids_found_by_certificate.len()
);
if let Some(anchor) = TLS_TRUST_ANCHORS
.iter()
.find(|anchor| anchor.trust_anchor_id.is_some())
{
match trust_anchor_id_for_certificate(anchor.der) {
Some(id) => println!(
"exact DER lookup: SHA-256 {} -> Trust Anchor ID bytes {}",
lowercase_hex(&anchor.sha256),
lowercase_hex(id)
),
None => println!("exact DER lookup unexpectedly found no ID"),
}
}
println!("metadata ID entries: {}", TRUST_ANCHOR_IDS.len());
for id in TRUST_ANCHOR_IDS {
println!(" {}", lowercase_hex(id));
}
println!(
"BoringSSL length-prefixed Trust Anchor ID bytes: {}",
ENCODED_TRUST_ANCHOR_IDS.len()
);
}