#![allow(clippy::unwrap_used, clippy::expect_used)]
use matter_commissioning::attestation::cd::{verify_certification_declaration, CdSigningRoots};
use matter_commissioning::attestation::{ProductId, VendorId};
const CHIP_CD_FFF2_8001: &[u8] = include_bytes!("vectors/Chip-Test-CD-FFF2-8001.der");
const CHIP_CD_SIGNING_CERT: &[u8] = include_bytes!("vectors/Chip-Test-CD-Signing-Cert.der");
const C6_CD_FFF1: &[u8] = include_bytes!("vectors/c6-cd-fff1.der");
const CSA_CD_SIGNING_KEY_001: &[u8] = include_bytes!("vectors/CSA-CD-Signing-Key-001.der");
#[test]
fn verifies_real_chip_cd_against_chip_test_signing_root() {
let trust = CdSigningRoots::from_cert_der(&[CHIP_CD_SIGNING_CERT])
.expect("chip test CD signing cert must parse");
assert_eq!(trust.len(), 1, "trust root must load");
verify_certification_declaration(
CHIP_CD_FFF2_8001,
VendorId::new(0xFFF2),
ProductId::new(0x8001),
&trust,
)
.expect("a real chip CD must verify against chip's own test CD signing root");
}
#[test]
fn verifies_esp_matter_c6_cd_against_csa_production_key_001() {
let trust = CdSigningRoots::from_cert_der(&[CSA_CD_SIGNING_KEY_001])
.expect("CSA CD signing key 001 cert must parse");
verify_certification_declaration(
C6_CD_FFF1,
VendorId::new(0xFFF1),
ProductId::new(0x8000),
&trust,
)
.expect("the C6's CD must verify against CSA production CD signing key 001");
}
#[test]
fn c6_cd_verifies_against_bundled_example_device_roots() {
let trust = CdSigningRoots::with_example_device_roots();
assert!(
trust.len() >= 3,
"bundled roots must include synthetic + chip-test + CSA-prod-001"
);
verify_certification_declaration(
C6_CD_FFF1,
VendorId::new(0xFFF1),
ProductId::new(0x8000),
&trust,
)
.expect("the C6's real CD must verify against the bundled example_device_roots set");
}
#[test]
fn c6_cd_is_rejected_by_test_authority_alone() {
let trust = CdSigningRoots::from_cert_der(&[CHIP_CD_SIGNING_CERT])
.expect("chip test CD signing cert must parse");
let err = verify_certification_declaration(
C6_CD_FFF1,
VendorId::new(0xFFF1),
ProductId::new(0x8000),
&trust,
)
.expect_err("the C6's CD is not signed by the test authority");
assert!(
matches!(
err,
matter_commissioning::attestation::AttestationError::
CertificationDeclarationSignatureInvalid
),
"expected a signature-invalid rejection, got {err:?}"
);
}