mirror of
https://github.com/block/buzz.git
synced 2026-11-25 02:31:36 +00:00
test(push): cover strict App Attest verification
Co-authored-by: Tom Brow <tomb@block.xyz> Signed-off-by: npub1tquskdu6yc4h8l7xxtceculxw600grekeq0xg2ukqfrwl7vrzg3quz3gmp <58390b379a262b73ffc632f19c73e6769ef40f36c81e642b960246eff9831222@buzz.block.builderlab.xyz> Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
parent
f563f833cd
commit
4a9b4d98c4
@@ -146,3 +146,330 @@ fn assertion_counter(cbor: &[u8]) -> Result<u32, AppAttestError> {
|
||||
.ok_or(AppAttestError::Invalid)?;
|
||||
Ok(BigEndian::read_u32(&auth[33..37]))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use appattest::error::AppAttestError as DependencyAppAttestError;
|
||||
use chrono::{Duration, NaiveDateTime, Utc};
|
||||
use serde::Deserialize;
|
||||
|
||||
const GOOD_FIXTURE_JSON: &str = include_str!("../tests/fixtures/app-attest-good.json");
|
||||
const WRONG_AAGUID_FIXTURE_JSON: &str =
|
||||
include_str!("../tests/fixtures/app-attest-wrong-aaguid.json");
|
||||
const WRONG_ROOT_FIXTURE_JSON: &str =
|
||||
include_str!("../tests/fixtures/app-attest-wrong-root.json");
|
||||
const APPLE_ROOT_CERT_PEM: &[u8] =
|
||||
include_bytes!("../tests/fixtures/apple-app-attestation-root.pem");
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Fixture {
|
||||
description: String,
|
||||
generator: String,
|
||||
generated_at: String,
|
||||
regeneration_command: String,
|
||||
app_id: String,
|
||||
challenge: String,
|
||||
aaguid: String,
|
||||
leaf_not_after: String,
|
||||
attestation_b64: String,
|
||||
key_id_b64: String,
|
||||
root_cert_pem: String,
|
||||
}
|
||||
|
||||
fn fixture(json: &str) -> Fixture {
|
||||
let fixture: Fixture = serde_json::from_str(json).expect("valid App Attest fixture JSON");
|
||||
assert!(!fixture.description.is_empty());
|
||||
assert_eq!(
|
||||
fixture.generator,
|
||||
"crates/buzz-push-gateway/tests/fixtures/app-attest-generator"
|
||||
);
|
||||
assert!(!fixture.generated_at.is_empty());
|
||||
fixture
|
||||
}
|
||||
|
||||
fn verifier(app_id: &str, root_cert_pem: &[u8]) -> AppAttestVerifier {
|
||||
AppAttestVerifier {
|
||||
app_id: app_id.to_owned(),
|
||||
apple_root_cert_pem: root_cert_pem.to_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_dependency(
|
||||
fixture: &Fixture,
|
||||
app_id: &str,
|
||||
challenge: &str,
|
||||
key_id_b64: &str,
|
||||
root_cert_pem: &[u8],
|
||||
) -> Result<(), DependencyAppAttestError> {
|
||||
let cbor = STANDARD
|
||||
.decode(&fixture.attestation_b64)
|
||||
.expect("fixture attestation is base64");
|
||||
let attestation = Attestation::from_cbor_bytes(&cbor)?;
|
||||
let result = attestation
|
||||
.verify(challenge, app_id, key_id_b64, root_cert_pem)
|
||||
.map(|_| ());
|
||||
result
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strict_verifier_accepts_good_fixture() {
|
||||
let fixture = fixture(GOOD_FIXTURE_JSON);
|
||||
assert_eq!(fixture.aaguid, "appattest");
|
||||
verify_dependency(
|
||||
&fixture,
|
||||
&fixture.app_id,
|
||||
&fixture.challenge,
|
||||
&fixture.key_id_b64,
|
||||
fixture.root_cert_pem.as_bytes(),
|
||||
)
|
||||
.expect("strict dependency verifier accepts the generated encoding");
|
||||
|
||||
let verified = verifier(&fixture.app_id, fixture.root_cert_pem.as_bytes())
|
||||
.verify_attestation(
|
||||
&fixture.attestation_b64,
|
||||
&fixture.key_id_b64,
|
||||
fixture.challenge.as_bytes(),
|
||||
)
|
||||
.expect("shipped gateway wrapper accepts the generated encoding");
|
||||
assert_eq!(verified.key_id.len(), 32);
|
||||
assert_eq!(verified.public_key.len(), 65);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_root_is_rejected() {
|
||||
let good = fixture(GOOD_FIXTURE_JSON);
|
||||
let wrong_root = fixture(WRONG_ROOT_FIXTURE_JSON);
|
||||
assert!(verify_dependency(
|
||||
&wrong_root,
|
||||
&wrong_root.app_id,
|
||||
&wrong_root.challenge,
|
||||
&wrong_root.key_id_b64,
|
||||
good.root_cert_pem.as_bytes(),
|
||||
)
|
||||
.is_err());
|
||||
assert!(verifier(&wrong_root.app_id, good.root_cert_pem.as_bytes())
|
||||
.verify_attestation(
|
||||
&wrong_root.attestation_b64,
|
||||
&wrong_root.key_id_b64,
|
||||
wrong_root.challenge.as_bytes(),
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_app_id_is_rejected() {
|
||||
let fixture = fixture(GOOD_FIXTURE_JSON);
|
||||
let wrong_app_id = "TEAMID.xyz.buzz.wrong";
|
||||
assert_eq!(
|
||||
verify_dependency(
|
||||
&fixture,
|
||||
wrong_app_id,
|
||||
&fixture.challenge,
|
||||
&fixture.key_id_b64,
|
||||
fixture.root_cert_pem.as_bytes(),
|
||||
),
|
||||
Err(DependencyAppAttestError::InvalidAppID)
|
||||
);
|
||||
assert!(verifier(wrong_app_id, fixture.root_cert_pem.as_bytes())
|
||||
.verify_attestation(
|
||||
&fixture.attestation_b64,
|
||||
&fixture.key_id_b64,
|
||||
fixture.challenge.as_bytes(),
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_challenge_is_rejected() {
|
||||
let fixture = fixture(GOOD_FIXTURE_JSON);
|
||||
let wrong_challenge = "wrong-challenge";
|
||||
assert_eq!(
|
||||
verify_dependency(
|
||||
&fixture,
|
||||
&fixture.app_id,
|
||||
wrong_challenge,
|
||||
&fixture.key_id_b64,
|
||||
fixture.root_cert_pem.as_bytes(),
|
||||
),
|
||||
Err(DependencyAppAttestError::InvalidNonce)
|
||||
);
|
||||
assert!(verifier(&fixture.app_id, fixture.root_cert_pem.as_bytes())
|
||||
.verify_attestation(
|
||||
&fixture.attestation_b64,
|
||||
&fixture.key_id_b64,
|
||||
wrong_challenge.as_bytes(),
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrong_aaguid_is_rejected_as_invalid_aaguid() {
|
||||
let fixture = fixture(WRONG_AAGUID_FIXTURE_JSON);
|
||||
assert_eq!(fixture.aaguid, "appattestdevelop");
|
||||
assert_eq!(
|
||||
verify_dependency(
|
||||
&fixture,
|
||||
&fixture.app_id,
|
||||
&fixture.challenge,
|
||||
&fixture.key_id_b64,
|
||||
fixture.root_cert_pem.as_bytes(),
|
||||
),
|
||||
Err(DependencyAppAttestError::InvalidAAGUID)
|
||||
);
|
||||
assert!(verifier(&fixture.app_id, fixture.root_cert_pem.as_bytes())
|
||||
.verify_attestation(
|
||||
&fixture.attestation_b64,
|
||||
&fixture.key_id_b64,
|
||||
fixture.challenge.as_bytes(),
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_and_oversize_key_ids_are_rejected() {
|
||||
let fixture = fixture(GOOD_FIXTURE_JSON);
|
||||
for key_id_b64 in [STANDARD.encode([0x11; 31]), STANDARD.encode([0x22; 33])] {
|
||||
assert!(verify_dependency(
|
||||
&fixture,
|
||||
&fixture.app_id,
|
||||
&fixture.challenge,
|
||||
&key_id_b64,
|
||||
fixture.root_cert_pem.as_bytes(),
|
||||
)
|
||||
.is_err());
|
||||
assert!(verifier(&fixture.app_id, fixture.root_cert_pem.as_bytes())
|
||||
.verify_attestation(
|
||||
&fixture.attestation_b64,
|
||||
&key_id_b64,
|
||||
fixture.challenge.as_bytes(),
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::assertions_on_constants, unexpected_cfgs)]
|
||||
fn gateway_test_build_does_not_define_testing_feature() {
|
||||
assert!(!cfg!(feature = "testing"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constructor_still_pins_the_apple_root() {
|
||||
let fixture = fixture(GOOD_FIXTURE_JSON);
|
||||
assert!(
|
||||
AppAttestVerifier::new(fixture.app_id.clone(), APPLE_ROOT_CERT_PEM.to_vec()).is_ok()
|
||||
);
|
||||
assert!(
|
||||
AppAttestVerifier::new(fixture.app_id, fixture.root_cert_pem.as_bytes().to_vec(),)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fixture_leaf_certificate_is_valid_for_at_least_thirty_days() {
|
||||
let fixture = fixture(GOOD_FIXTURE_JSON);
|
||||
let leaf_certificate = fixture_leaf_certificate(&fixture);
|
||||
let not_after = certificate_not_after(&leaf_certificate);
|
||||
assert_eq!(
|
||||
not_after.format("%b %e %H:%M:%S %Y GMT").to_string(),
|
||||
fixture.leaf_not_after
|
||||
);
|
||||
assert!(
|
||||
not_after > Utc::now() + Duration::days(30),
|
||||
"App Attest fixture expires within 30 days; regenerate with: {}",
|
||||
fixture.regeneration_command
|
||||
);
|
||||
}
|
||||
|
||||
fn fixture_leaf_certificate(fixture: &Fixture) -> Vec<u8> {
|
||||
let cbor = STANDARD
|
||||
.decode(&fixture.attestation_b64)
|
||||
.expect("fixture attestation is base64");
|
||||
let mut decoder = minicbor::Decoder::new(&cbor);
|
||||
let root_entries = decoder
|
||||
.map()
|
||||
.expect("attestation root is a map")
|
||||
.expect("attestation root map has a fixed length");
|
||||
for _ in 0..root_entries {
|
||||
let key = decoder.str().expect("attestation root key is text");
|
||||
if key != "attStmt" {
|
||||
decoder.skip().expect("skip non-attStmt value");
|
||||
continue;
|
||||
}
|
||||
let statement_entries = decoder
|
||||
.map()
|
||||
.expect("attStmt is a map")
|
||||
.expect("attStmt map has a fixed length");
|
||||
for _ in 0..statement_entries {
|
||||
let key = decoder.str().expect("attStmt key is text");
|
||||
if key != "x5c" {
|
||||
decoder.skip().expect("skip non-x5c value");
|
||||
continue;
|
||||
}
|
||||
assert!(
|
||||
decoder
|
||||
.array()
|
||||
.expect("x5c is an array")
|
||||
.expect("x5c has a fixed length")
|
||||
>= 2
|
||||
);
|
||||
return decoder
|
||||
.bytes()
|
||||
.expect("x5c leaf certificate is bytes")
|
||||
.to_vec();
|
||||
}
|
||||
}
|
||||
panic!("fixture attestation has no x5c leaf certificate");
|
||||
}
|
||||
|
||||
fn certificate_not_after(certificate: &[u8]) -> chrono::DateTime<Utc> {
|
||||
let (tag, certificate, _) = der_tlv(certificate);
|
||||
assert_eq!(tag, 0x30, "certificate must be a DER sequence");
|
||||
let (tag, tbs_certificate, _) = der_tlv(certificate);
|
||||
assert_eq!(tag, 0x30, "TBSCertificate must be a DER sequence");
|
||||
|
||||
let mut fields = tbs_certificate;
|
||||
if fields.first() == Some(&0xa0) {
|
||||
fields = der_tlv(fields).2;
|
||||
}
|
||||
for _ in 0..3 {
|
||||
fields = der_tlv(fields).2;
|
||||
}
|
||||
let (tag, validity, _) = der_tlv(fields);
|
||||
assert_eq!(tag, 0x30, "certificate validity must be a DER sequence");
|
||||
let (_, _, after_not_before) = der_tlv(validity);
|
||||
let (time_tag, not_after, _) = der_tlv(after_not_before);
|
||||
let not_after = std::str::from_utf8(not_after).expect("notAfter is ASCII");
|
||||
let format = match time_tag {
|
||||
0x17 => "%y%m%d%H%M%SZ",
|
||||
0x18 => "%Y%m%d%H%M%SZ",
|
||||
_ => panic!("unexpected DER time tag {time_tag:#x}"),
|
||||
};
|
||||
NaiveDateTime::parse_from_str(not_after, format)
|
||||
.expect("valid DER notAfter timestamp")
|
||||
.and_utc()
|
||||
}
|
||||
|
||||
fn der_tlv(input: &[u8]) -> (u8, &[u8], &[u8]) {
|
||||
let tag = *input.first().expect("DER TLV has a tag");
|
||||
let first_length = *input.get(1).expect("DER TLV has a length");
|
||||
let (length, length_bytes) = if first_length & 0x80 == 0 {
|
||||
(first_length as usize, 1)
|
||||
} else {
|
||||
let byte_count = (first_length & 0x7f) as usize;
|
||||
assert!(
|
||||
byte_count > 0 && byte_count <= std::mem::size_of::<usize>(),
|
||||
"supported DER long-form length"
|
||||
);
|
||||
let length = input[2..2 + byte_count]
|
||||
.iter()
|
||||
.fold(0_usize, |length, byte| (length << 8) | *byte as usize);
|
||||
(length, 1 + byte_count)
|
||||
};
|
||||
let value_start = 1 + length_bytes;
|
||||
let value_end = value_start + length;
|
||||
assert!(value_end <= input.len(), "DER TLV length is in bounds");
|
||||
(tag, &input[value_start..value_end], &input[value_end..])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,6 +344,24 @@ mod tests {
|
||||
assert_eq!(config.health_addr, "0.0.0.0:8081".parse().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn production_and_sandbox_profiles_parse_together_without_bypass() {
|
||||
let mut env = base();
|
||||
env.insert(
|
||||
"BUZZ_PUSH_ENABLED_PROFILES".into(),
|
||||
"buzz-ios-production,buzz-ios-sandbox".into(),
|
||||
);
|
||||
|
||||
let config = Config::from_map(&env).unwrap();
|
||||
assert_eq!(config.enabled_profiles.len(), 2);
|
||||
assert!(config
|
||||
.enabled_profiles
|
||||
.contains(&crate::model::AppProfile::BuzzIosProduction));
|
||||
assert!(config
|
||||
.enabled_profiles
|
||||
.contains(&crate::model::AppProfile::BuzzIosSandbox));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dev_app_attest_bypass_flag_is_strict_and_feature_gated() {
|
||||
let absent = Config::from_map(&base()).unwrap();
|
||||
|
||||
341
crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.lock
generated
vendored
Normal file
341
crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.lock
generated
vendored
Normal file
@@ -0,0 +1,341 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "buzz-app-attest-fixture-generator"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"byteorder",
|
||||
"ciborium",
|
||||
"openssl",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"ciborium-ll",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-io"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
|
||||
|
||||
[[package]]
|
||||
name = "ciborium-ll"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
|
||||
dependencies = [
|
||||
"ciborium-io",
|
||||
"half",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
dependencies = [
|
||||
"foreign-types-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crunchy",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.189"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.81"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
"openssl-macros",
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.117"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a105cd7b140f6eeec8acff2ea38135d3cab283ada58540f629fe51e46696eb"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fe976fb70c78cd64cccfe3a6fc142244e8a77b70959b30faf9d0ac37ee228eb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
14
crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.toml
vendored
Normal file
14
crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.toml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "buzz-app-attest-fixture-generator"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.22"
|
||||
byteorder = "1.5"
|
||||
ciborium = "0.2"
|
||||
openssl = "0.10"
|
||||
sha2 = "0.10"
|
||||
18
crates/buzz-push-gateway/tests/fixtures/app-attest-generator/README.md
vendored
Normal file
18
crates/buzz-push-gateway/tests/fixtures/app-attest-generator/README.md
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# App Attest verifier fixtures
|
||||
|
||||
This standalone crate generates synthetic App Attest fixtures for the gateway's strict verifier tests. It has its own `[workspace]`, does not belong to the repository workspace dependency graph, and must never depend on `appattest`. That separation prevents the dependency's `testing` feature from being unified into the gateway test build, where it would permit the development AAGUID.
|
||||
|
||||
The generator owns the full root, intermediate, and credential certificate chain. It writes Apple's nonce extension OID `1.2.840.113635.100.8.2` and App Attest EKU `1.2.840.113635.100.4.24` directly. Generator correctness is therefore load-bearing. The strict verifier's good-fixture acceptance test is the encoding oracle. Any generator change must pass the full App Attest test floor, and a fixture rejected by the shipped verifier must never be made green by loosening a test.
|
||||
|
||||
`apple-app-attestation-root.pem` is the production pin-control fixture downloaded from [Apple's certificate authority](https://www.apple.com/certificateauthority/Apple_App_Attestation_Root_CA.pem). Its exact PEM-file SHA-256 must remain `c778d09ac341f7fd9f8f3b19e2b815af6aed4ad4490e1e92c05cb355212a5013`.
|
||||
|
||||
Regenerate from the repository root:
|
||||
|
||||
```bash
|
||||
cargo run --manifest-path crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.toml -- \
|
||||
--output-dir crates/buzz-push-gateway/tests/fixtures \
|
||||
--good-aaguid appattest \
|
||||
--wrong-aaguid appattestdevelop
|
||||
```
|
||||
|
||||
The command rewrites `app-attest-good.json`, `app-attest-wrong-aaguid.json`, and `app-attest-wrong-root.json`. Review all fixture changes and run the complete gateway package test suite afterward.
|
||||
404
crates/buzz-push-gateway/tests/fixtures/app-attest-generator/src/main.rs
vendored
Normal file
404
crates/buzz-push-gateway/tests/fixtures/app-attest-generator/src/main.rs
vendored
Normal file
@@ -0,0 +1,404 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use base64::{engine::general_purpose::STANDARD, Engine as _};
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
use ciborium::{cbor, Value};
|
||||
use openssl::{
|
||||
asn1::{Asn1Integer, Asn1Object, Asn1OctetString, Asn1Time},
|
||||
bn::{BigNum, MsbOption},
|
||||
ec::{EcGroup, EcKey, PointConversionForm},
|
||||
hash::MessageDigest,
|
||||
nid::Nid,
|
||||
pkey::{PKey, Private},
|
||||
x509::{
|
||||
extension::{BasicConstraints, ExtendedKeyUsage, KeyUsage},
|
||||
X509Builder, X509Extension, X509Name, X509NameBuilder, X509,
|
||||
},
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
const APP_ID: &str = "TEAMID.xyz.buzz.mobile";
|
||||
const CHALLENGE: &str = "buzz-app-attest-strict-verifier-fixture";
|
||||
const CERT_VALIDITY_DAYS: u32 = 7_305;
|
||||
const REGENERATION_COMMAND: &str = "cargo run --manifest-path crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.toml -- --output-dir crates/buzz-push-gateway/tests/fixtures --good-aaguid appattest --wrong-aaguid appattestdevelop";
|
||||
|
||||
struct Args {
|
||||
output_dir: PathBuf,
|
||||
good_aaguid: String,
|
||||
wrong_aaguid: String,
|
||||
}
|
||||
|
||||
struct CertificateAuthority {
|
||||
root_cert: X509,
|
||||
intermediate_cert: X509,
|
||||
intermediate_key: PKey<Private>,
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
attestation_b64: String,
|
||||
key_id_b64: String,
|
||||
root_cert_pem: String,
|
||||
leaf_not_after: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = parse_args();
|
||||
validate_aaguid(&args.good_aaguid);
|
||||
validate_aaguid(&args.wrong_aaguid);
|
||||
fs::create_dir_all(&args.output_dir).expect("create fixture output directory");
|
||||
|
||||
let primary_ca = CertificateAuthority::generate("Buzz App Attest Fixture Root");
|
||||
let good = build_fixture(&primary_ca, &args.good_aaguid);
|
||||
let wrong_aaguid = build_fixture(&primary_ca, &args.wrong_aaguid);
|
||||
|
||||
let unrelated_ca = CertificateAuthority::generate("Unrelated App Attest Fixture Root");
|
||||
let wrong_root = build_fixture(&unrelated_ca, &args.good_aaguid);
|
||||
|
||||
write_fixture(
|
||||
&args.output_dir,
|
||||
"app-attest-good.json",
|
||||
"Valid synthetic Apple App Attest attestation for the gateway strict-verifier acceptance control.",
|
||||
&args.good_aaguid,
|
||||
&good,
|
||||
);
|
||||
write_fixture(
|
||||
&args.output_dir,
|
||||
"app-attest-wrong-aaguid.json",
|
||||
"Synthetic attestation with a development AAGUID and a correctly recomputed nonce; the strict verifier must report InvalidAAGUID.",
|
||||
&args.wrong_aaguid,
|
||||
&wrong_aaguid,
|
||||
);
|
||||
write_fixture(
|
||||
&args.output_dir,
|
||||
"app-attest-wrong-root.json",
|
||||
"Internally valid synthetic attestation signed by an unrelated root; the verifier configured with the good fixture root must reject it.",
|
||||
&args.good_aaguid,
|
||||
&wrong_root,
|
||||
);
|
||||
}
|
||||
|
||||
fn parse_args() -> Args {
|
||||
let mut output_dir = None;
|
||||
let mut good_aaguid = None;
|
||||
let mut wrong_aaguid = None;
|
||||
let mut args = env::args().skip(1);
|
||||
while let Some(arg) = args.next() {
|
||||
let value = args
|
||||
.next()
|
||||
.unwrap_or_else(|| panic!("missing value for {arg}"));
|
||||
match arg.as_str() {
|
||||
"--output-dir" => output_dir = Some(PathBuf::from(value)),
|
||||
"--good-aaguid" => good_aaguid = Some(value),
|
||||
"--wrong-aaguid" => wrong_aaguid = Some(value),
|
||||
_ => panic!("unknown argument {arg}"),
|
||||
}
|
||||
}
|
||||
Args {
|
||||
output_dir: output_dir.expect("--output-dir is required"),
|
||||
good_aaguid: good_aaguid.expect("--good-aaguid is required"),
|
||||
wrong_aaguid: wrong_aaguid.expect("--wrong-aaguid is required"),
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_aaguid(aaguid: &str) {
|
||||
assert!(
|
||||
!aaguid.is_empty() && aaguid.len() <= 16 && aaguid.is_ascii(),
|
||||
"AAGUID must be 1 to 16 ASCII bytes"
|
||||
);
|
||||
}
|
||||
|
||||
impl CertificateAuthority {
|
||||
fn generate(root_common_name: &str) -> Self {
|
||||
let root_key = p384_key();
|
||||
let root_name = name(root_common_name);
|
||||
let root_cert = certificate(
|
||||
&root_name,
|
||||
&root_name,
|
||||
&root_key,
|
||||
&root_key,
|
||||
MessageDigest::sha384(),
|
||||
true,
|
||||
None,
|
||||
);
|
||||
|
||||
let intermediate_key = p256_key();
|
||||
let intermediate_name = name("Buzz App Attest Fixture Intermediate");
|
||||
let intermediate_cert = certificate(
|
||||
&intermediate_name,
|
||||
root_cert.subject_name(),
|
||||
&intermediate_key,
|
||||
&root_key,
|
||||
MessageDigest::sha384(),
|
||||
true,
|
||||
None,
|
||||
);
|
||||
|
||||
Self {
|
||||
root_cert,
|
||||
intermediate_cert,
|
||||
intermediate_key,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn build_fixture(ca: &CertificateAuthority, aaguid_value: &str) -> Fixture {
|
||||
let device_key = p256_key();
|
||||
let group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).expect("P-256 group");
|
||||
let ec_key = device_key.ec_key().expect("device EC key");
|
||||
let mut context = openssl::bn::BigNumContext::new().expect("bignum context");
|
||||
let public_key = ec_key
|
||||
.public_key()
|
||||
.to_bytes(&group, PointConversionForm::UNCOMPRESSED, &mut context)
|
||||
.expect("serialize device public key");
|
||||
let key_id = Sha256::digest(&public_key);
|
||||
let key_id_b64 = STANDARD.encode(key_id);
|
||||
|
||||
let mut aaguid = [0_u8; 16];
|
||||
aaguid[..aaguid_value.len()].copy_from_slice(aaguid_value.as_bytes());
|
||||
let mut auth_data = Vec::with_capacity(87);
|
||||
auth_data.extend_from_slice(&Sha256::digest(APP_ID.as_bytes()));
|
||||
auth_data.push(0x41);
|
||||
auth_data.extend_from_slice(&[0_u8; 4]);
|
||||
auth_data.extend_from_slice(&aaguid);
|
||||
let mut credential_length = [0_u8; 2];
|
||||
BigEndian::write_u16(&mut credential_length, key_id.len() as u16);
|
||||
auth_data.extend_from_slice(&credential_length);
|
||||
auth_data.extend_from_slice(&key_id);
|
||||
|
||||
let mut nonce_input = auth_data.clone();
|
||||
nonce_input.extend_from_slice(&Sha256::digest(CHALLENGE.as_bytes()));
|
||||
let nonce = Sha256::digest(nonce_input);
|
||||
|
||||
let leaf_name = name("Buzz App Attest Fixture Credential");
|
||||
let leaf_cert = certificate(
|
||||
&leaf_name,
|
||||
ca.intermediate_cert.subject_name(),
|
||||
&device_key,
|
||||
&ca.intermediate_key,
|
||||
MessageDigest::sha256(),
|
||||
false,
|
||||
Some(&nonce),
|
||||
);
|
||||
let leaf_der = leaf_cert.to_der().expect("encode credential certificate");
|
||||
let intermediate_der = ca
|
||||
.intermediate_cert
|
||||
.to_der()
|
||||
.expect("encode intermediate certificate");
|
||||
let value = cbor!({
|
||||
"fmt" => "apple-appattest",
|
||||
"attStmt" => {
|
||||
"x5c" => [
|
||||
Value::Bytes(leaf_der),
|
||||
Value::Bytes(intermediate_der)
|
||||
],
|
||||
"receipt" => Value::Bytes(Vec::new())
|
||||
},
|
||||
"authData" => Value::Bytes(auth_data)
|
||||
})
|
||||
.expect("build attestation CBOR value");
|
||||
let mut cbor = Vec::new();
|
||||
ciborium::into_writer(&value, &mut cbor).expect("encode attestation CBOR");
|
||||
|
||||
Fixture {
|
||||
attestation_b64: STANDARD.encode(cbor),
|
||||
key_id_b64,
|
||||
root_cert_pem: String::from_utf8(
|
||||
ca.root_cert.to_pem().expect("encode root certificate PEM"),
|
||||
)
|
||||
.expect("root PEM is UTF-8"),
|
||||
leaf_not_after: leaf_cert.not_after().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn certificate(
|
||||
subject: &X509Name,
|
||||
issuer: &openssl::x509::X509NameRef,
|
||||
subject_key: &PKey<Private>,
|
||||
issuer_key: &PKey<Private>,
|
||||
signature_digest: MessageDigest,
|
||||
is_ca: bool,
|
||||
nonce: Option<&[u8]>,
|
||||
) -> X509 {
|
||||
let mut builder = X509Builder::new().expect("create certificate builder");
|
||||
builder.set_version(2).expect("set X.509 version");
|
||||
builder
|
||||
.set_serial_number(&serial_number())
|
||||
.expect("set certificate serial");
|
||||
builder
|
||||
.set_subject_name(subject)
|
||||
.expect("set certificate subject");
|
||||
builder
|
||||
.set_issuer_name(issuer)
|
||||
.expect("set certificate issuer");
|
||||
builder
|
||||
.set_pubkey(subject_key)
|
||||
.expect("set certificate public key");
|
||||
builder
|
||||
.set_not_before(&Asn1Time::days_from_now(0).expect("build notBefore"))
|
||||
.expect("set notBefore");
|
||||
builder
|
||||
.set_not_after(&Asn1Time::days_from_now(CERT_VALIDITY_DAYS).expect("build long notAfter"))
|
||||
.expect("set notAfter");
|
||||
|
||||
if is_ca {
|
||||
builder
|
||||
.append_extension(
|
||||
BasicConstraints::new()
|
||||
.critical()
|
||||
.ca()
|
||||
.build()
|
||||
.expect("build CA constraints"),
|
||||
)
|
||||
.expect("append CA constraints");
|
||||
builder
|
||||
.append_extension(
|
||||
KeyUsage::new()
|
||||
.critical()
|
||||
.key_cert_sign()
|
||||
.crl_sign()
|
||||
.build()
|
||||
.expect("build CA key usage"),
|
||||
)
|
||||
.expect("append CA key usage");
|
||||
} else {
|
||||
builder
|
||||
.append_extension(
|
||||
BasicConstraints::new()
|
||||
.critical()
|
||||
.build()
|
||||
.expect("build leaf constraints"),
|
||||
)
|
||||
.expect("append leaf constraints");
|
||||
builder
|
||||
.append_extension(
|
||||
ExtendedKeyUsage::new()
|
||||
.other("1.2.840.113635.100.4.24")
|
||||
.build()
|
||||
.expect("build App Attest EKU"),
|
||||
)
|
||||
.expect("append App Attest EKU");
|
||||
|
||||
let nonce = nonce.expect("credential certificate nonce");
|
||||
assert_eq!(nonce.len(), 32, "App Attest nonce must be 32 bytes");
|
||||
let mut extension_value = Vec::with_capacity(38);
|
||||
extension_value.extend_from_slice(&[0x30, 0x24, 0xa1, 0x22, 0x04, 0x20]);
|
||||
extension_value.extend_from_slice(nonce);
|
||||
let oid = Asn1Object::from_str("1.2.840.113635.100.8.2")
|
||||
.expect("parse App Attest nonce extension OID");
|
||||
let octets = Asn1OctetString::new_from_bytes(&extension_value)
|
||||
.expect("encode App Attest nonce extension");
|
||||
builder
|
||||
.append_extension(
|
||||
X509Extension::new_from_der(&oid, false, &octets)
|
||||
.expect("build App Attest nonce extension"),
|
||||
)
|
||||
.expect("append App Attest nonce extension");
|
||||
}
|
||||
|
||||
builder
|
||||
.sign(issuer_key, signature_digest)
|
||||
.expect("sign certificate");
|
||||
builder.build()
|
||||
}
|
||||
|
||||
fn p256_key() -> PKey<Private> {
|
||||
ec_key(Nid::X9_62_PRIME256V1)
|
||||
}
|
||||
|
||||
fn p384_key() -> PKey<Private> {
|
||||
ec_key(Nid::SECP384R1)
|
||||
}
|
||||
|
||||
fn ec_key(curve: Nid) -> PKey<Private> {
|
||||
let group = EcGroup::from_curve_name(curve).expect("EC group");
|
||||
PKey::from_ec_key(EcKey::generate(&group).expect("generate EC key")).expect("wrap EC key")
|
||||
}
|
||||
|
||||
fn name(common_name: &str) -> X509Name {
|
||||
let mut builder = X509NameBuilder::new().expect("create X.509 name builder");
|
||||
builder
|
||||
.append_entry_by_text("CN", common_name)
|
||||
.expect("set common name");
|
||||
builder
|
||||
.append_entry_by_text("O", "Buzz")
|
||||
.expect("set organization");
|
||||
builder.build()
|
||||
}
|
||||
|
||||
fn serial_number() -> Asn1Integer {
|
||||
let mut number = BigNum::new().expect("create certificate serial");
|
||||
number
|
||||
.rand(128, MsbOption::MAYBE_ZERO, false)
|
||||
.expect("generate certificate serial");
|
||||
Asn1Integer::from_bn(&number).expect("convert certificate serial")
|
||||
}
|
||||
|
||||
fn write_fixture(
|
||||
output_dir: &Path,
|
||||
file_name: &str,
|
||||
description: &str,
|
||||
aaguid: &str,
|
||||
fixture: &Fixture,
|
||||
) {
|
||||
let generated_at = generation_date();
|
||||
let json = format!(
|
||||
concat!(
|
||||
"{{\n",
|
||||
" \"description\": \"{}\",\n",
|
||||
" \"generator\": \"crates/buzz-push-gateway/tests/fixtures/app-attest-generator\",\n",
|
||||
" \"generated_at\": \"{}\",\n",
|
||||
" \"regeneration_command\": \"{}\",\n",
|
||||
" \"app_id\": \"{}\",\n",
|
||||
" \"challenge\": \"{}\",\n",
|
||||
" \"aaguid\": \"{}\",\n",
|
||||
" \"leaf_not_after\": \"{}\",\n",
|
||||
" \"attestation_b64\": \"{}\",\n",
|
||||
" \"key_id_b64\": \"{}\",\n",
|
||||
" \"root_cert_pem\": \"{}\"\n",
|
||||
"}}\n"
|
||||
),
|
||||
json_escape(description),
|
||||
generated_at,
|
||||
json_escape(REGENERATION_COMMAND),
|
||||
APP_ID,
|
||||
CHALLENGE,
|
||||
aaguid,
|
||||
json_escape(&fixture.leaf_not_after),
|
||||
fixture.attestation_b64,
|
||||
fixture.key_id_b64,
|
||||
json_escape(&fixture.root_cert_pem),
|
||||
);
|
||||
fs::write(output_dir.join(file_name), json).expect("write fixture JSON");
|
||||
}
|
||||
|
||||
fn generation_date() -> String {
|
||||
let output = std::process::Command::new("date")
|
||||
.args(["-u", "+%Y-%m-%d"])
|
||||
.output()
|
||||
.expect("run date for fixture metadata");
|
||||
assert!(output.status.success(), "date command failed");
|
||||
String::from_utf8(output.stdout)
|
||||
.expect("date output is UTF-8")
|
||||
.trim()
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
fn json_escape(value: &str) -> String {
|
||||
value
|
||||
.chars()
|
||||
.flat_map(|character| match character {
|
||||
'\\' => "\\\\".chars().collect::<Vec<_>>(),
|
||||
'"' => "\\\"".chars().collect(),
|
||||
'\n' => "\\n".chars().collect(),
|
||||
'\r' => "\\r".chars().collect(),
|
||||
'\t' => "\\t".chars().collect(),
|
||||
value if value.is_control() => {
|
||||
panic!("unsupported control character in fixture metadata")
|
||||
}
|
||||
value => vec![value],
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
13
crates/buzz-push-gateway/tests/fixtures/app-attest-good.json
vendored
Normal file
13
crates/buzz-push-gateway/tests/fixtures/app-attest-good.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"description": "Valid synthetic Apple App Attest attestation for the gateway strict-verifier acceptance control.",
|
||||
"generator": "crates/buzz-push-gateway/tests/fixtures/app-attest-generator",
|
||||
"generated_at": "2026-08-02",
|
||||
"regeneration_command": "cargo run --manifest-path crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.toml -- --output-dir crates/buzz-push-gateway/tests/fixtures --good-aaguid appattest --wrong-aaguid appattestdevelop",
|
||||
"app_id": "TEAMID.xyz.buzz.mobile",
|
||||
"challenge": "buzz-app-attest-strict-verifier-fixture",
|
||||
"aaguid": "appattest",
|
||||
"leaf_not_after": "Aug 2 05:27:02 2046 GMT",
|
||||
"attestation_b64": "o2NmbXRvYXBwbGUtYXBwYXR0ZXN0Z2F0dFN0bXSiY3g1Y4JZAdgwggHUMIIBeqADAgECAhEA1hkzMVx4LIlx2Z04+dq+DjAKBggqhkjOPQQDAjA+MS0wKwYDVQQDDCRCdXp6IEFwcCBBdHRlc3QgRml4dHVyZSBJbnRlcm1lZGlhdGUxDTALBgNVBAoMBEJ1enowHhcNMjYwODAyMDUyNzAyWhcNNDYwODAyMDUyNzAyWjA8MSswKQYDVQQDDCJCdXp6IEFwcCBBdHRlc3QgRml4dHVyZSBDcmVkZW50aWFsMQ0wCwYDVQQKDARCdXp6MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEPnUoIjO//gCI6cvjfmAw62OnnngGVoId2q7MQYG//94tXIX2tIZChUe1y/spRzJqxLo0JNm7d9QKdoVuLNBpfaNbMFkwDAYDVR0T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MIIByjCCAVCgAwIBAgIQMLQQs1cI8JQdL88vvx4tZjAKBggqhkjOPQQDAzA2MSUw\nIwYDVQQDDBxCdXp6IEFwcCBBdHRlc3QgRml4dHVyZSBSb290MQ0wCwYDVQQKDARC\ndXp6MB4XDTI2MDgwMjA1MjcwMloXDTQ2MDgwMjA1MjcwMlowNjElMCMGA1UEAwwc\nQnV6eiBBcHAgQXR0ZXN0IEZpeHR1cmUgUm9vdDENMAsGA1UECgwEQnV6ejB2MBAG\nByqGSM49AgEGBSuBBAAiA2IABHRmKNadAoMBUMGUELKgZJrT7Qg3h0HwHGSvvZnN\nWkDJdDCFODg7AZVQsCv7Wx0DYK0TAX+y/JxItkd0qvZKWRhtyN3VednVNJ+qRVFh\nt0r5R3Jn14A3es+y7w+mDdqXS6MjMCEwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8B\nAf8EBAMCAQYwCgYIKoZIzj0EAwMDaAAwZQIwSv2nREeLrLyau01dS8/fInt6Xc/r\ntB9sV92eezwl1asw+MoY9NOuMo6QO/KaWtgiAjEAlnP+9HKkQ3SsHcAHnoc0Sjue\nCjNMcsRxsusqjzy7+uSZzyIprpBvzTS4oGE+2/Ky\n-----END CERTIFICATE-----\n"
|
||||
}
|
||||
13
crates/buzz-push-gateway/tests/fixtures/app-attest-wrong-aaguid.json
vendored
Normal file
13
crates/buzz-push-gateway/tests/fixtures/app-attest-wrong-aaguid.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"description": "Synthetic attestation with a development AAGUID and a correctly recomputed nonce; the strict verifier must report InvalidAAGUID.",
|
||||
"generator": "crates/buzz-push-gateway/tests/fixtures/app-attest-generator",
|
||||
"generated_at": "2026-08-02",
|
||||
"regeneration_command": "cargo run --manifest-path crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.toml -- --output-dir crates/buzz-push-gateway/tests/fixtures --good-aaguid appattest --wrong-aaguid appattestdevelop",
|
||||
"app_id": "TEAMID.xyz.buzz.mobile",
|
||||
"challenge": "buzz-app-attest-strict-verifier-fixture",
|
||||
"aaguid": "appattestdevelop",
|
||||
"leaf_not_after": "Aug 2 05:27:02 2046 GMT",
|
||||
"attestation_b64": "o2NmbXRvYXBwbGUtYXBwYXR0ZXN0Z2F0dFN0bXSiY3g1Y4JZAdcwggHTMIIBeaADAgECAhAXdDyYByLYxE4WftXjOFC1MAoGCCqGSM49BAMCMD4xLTArBgNVBAMMJEJ1enogQXBwIEF0dGVzdCBGaXh0dXJlIEludGVybWVkaWF0ZTENMAsGA1UECgwEQnV6ejAeFw0yNjA4MDIwNTI3MDJaFw00NjA4MDIwNTI3MDJaMDwxKzApBgNVBAMMIkJ1enogQXBwIEF0dGVzdCBGaXh0dXJlIENyZWRlbnRpYWwxDTALBgNVBAoMBEJ1enowWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ8ZGvDc7xMJINZw6mLHRU6xr1kFY+vn+PRZYIMypdlYb99U/l8VCK9zWQt+xXSEAyNvzdcZiom5N/fKuAI5xh/o1swWTAMBgNVHRMBAf8EAjAAMBQGA1UdJQQNMAsGCSqGSIb3Y2QEGDAzBgkqhkiG92NkCAIEJjAkoSIEILEfYIC8xsY+hZnqOrQF1PpWR3VioqnjjQwo5/YmtAwRMAoGCCqGSM49BAMCA0gAMEUCIQCpOzhfo94xcJ0ojQki6wxpOdORPsNwXtZz+eByIhtwlwIgPr71d/DiOaQ3Jd9jDaiCFrzozcR5owB0kaKRzvFuBv1ZAbowggG2MIIBO6ADAgECAhAmPphyy55whfrMX9kVDrDMMAoGCCqGSM49BAMDMDYxJTAjBgNVBAMMHEJ1enogQXBwIEF0dGVzdCBGaXh0dXJlIFJvb3QxDTALBgNVBAoMBEJ1enowHhcNMjYwODAyMDUyNzAyWhcNNDYwODAyMDUyNzAyWjA+MS0wKwYDVQQDDCRCdXp6IEFwcCBBdHRlc3QgRml4dHVyZSBJbnRlcm1lZGlhdGUxDTALBgNVBAoMBEJ1enowWTATBgcqhkjOPQIBBgg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yau01dS8/fInt6Xc/r\ntB9sV92eezwl1asw+MoY9NOuMo6QO/KaWtgiAjEAlnP+9HKkQ3SsHcAHnoc0Sjue\nCjNMcsRxsusqjzy7+uSZzyIprpBvzTS4oGE+2/Ky\n-----END CERTIFICATE-----\n"
|
||||
}
|
||||
13
crates/buzz-push-gateway/tests/fixtures/app-attest-wrong-root.json
vendored
Normal file
13
crates/buzz-push-gateway/tests/fixtures/app-attest-wrong-root.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"description": "Internally valid synthetic attestation signed by an unrelated root; the verifier configured with the good fixture root must reject it.",
|
||||
"generator": "crates/buzz-push-gateway/tests/fixtures/app-attest-generator",
|
||||
"generated_at": "2026-08-02",
|
||||
"regeneration_command": "cargo run --manifest-path crates/buzz-push-gateway/tests/fixtures/app-attest-generator/Cargo.toml -- --output-dir crates/buzz-push-gateway/tests/fixtures --good-aaguid appattest --wrong-aaguid appattestdevelop",
|
||||
"app_id": "TEAMID.xyz.buzz.mobile",
|
||||
"challenge": "buzz-app-attest-strict-verifier-fixture",
|
||||
"aaguid": "appattest",
|
||||
"leaf_not_after": "Aug 2 05:27:02 2046 GMT",
|
||||
"attestation_b64": "o2NmbXRvYXBwbGUtYXBwYXR0ZXN0Z2F0dFN0bXSiY3g1Y4JZAdcwggHTMIIBeaADAgECAhBGe4kbr8X3vBBmRW24fEPWMAoGCCqGSM49BAMCMD4xLTArBgNVBAMMJEJ1enogQXBwIEF0dGVzdCBGaXh0dXJlIEludGVybWVkaWF0ZTENMAsGA1UECgwEQnV6ejAeFw0yNjA4MDIwNTI3MDJaFw00NjA4MDIwNTI3MDJaMDwxKzApBgNVBAMMIkJ1enogQXBwIEF0dGVzdCBGaXh0dXJlIENyZWRlbnRpYWwxDTALBgNVBAoMBEJ1enowWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ3NUd9f8Ma88b5fiKPmvgL0akkZfv3Q5v2jJMGVQ+pDY2ZFkZTQnzTfAPydFBFtVQ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"root_cert_pem": "-----BEGIN CERTIFICATE-----\nMIIB1DCCAVugAwIBAgIRALE3l3fzQ4wPjIL/IjBs02IwCgYIKoZIzj0EAwMwOzEq\nMCgGA1UEAwwhVW5yZWxhdGVkIEFwcCBBdHRlc3QgRml4dHVyZSBSb290MQ0wCwYD\nVQQKDARCdXp6MB4XDTI2MDgwMjA1MjcwMloXDTQ2MDgwMjA1MjcwMlowOzEqMCgG\nA1UEAwwhVW5yZWxhdGVkIEFwcCBBdHRlc3QgRml4dHVyZSBSb290MQ0wCwYDVQQK\nDARCdXp6MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEPa8SWuDIcjNVDwTXlTQnWbKj\n5Vt8TCiGGH0CiSJajPOlevvjHBEYuVHf7bFYa5N/7OzXQ3qkZomCyizJ6nc5tBEN\nGL3rkz7vZjb9J3QPfixkBwyUHFHmx1WJ84fgAYcDoyMwITAPBgNVHRMBAf8EBTAD\nAQH/MA4GA1UdDwEB/wQEAwIBBjAKBggqhkjOPQQDAwNnADBkAjAMO0cvuHHJSqWj\n4DxJorq8LH7VH9ILTGjcZmz91rLlO7w4oDqiewFQE+GVFl9boekCMBhaa0a/WiW2\nyf2j5d04SOkXREM1NkbHsd1yH1jqSOCuj6PU3Z6zDSSXy1z3HjQIBg==\n-----END CERTIFICATE-----\n"
|
||||
}
|
||||
14
crates/buzz-push-gateway/tests/fixtures/apple-app-attestation-root.pem
vendored
Normal file
14
crates/buzz-push-gateway/tests/fixtures/apple-app-attestation-root.pem
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICITCCAaegAwIBAgIQC/O+DvHN0uD7jG5yH2IXmDAKBggqhkjOPQQDAzBSMSYw
|
||||
JAYDVQQDDB1BcHBsZSBBcHAgQXR0ZXN0YXRpb24gUm9vdCBDQTETMBEGA1UECgwK
|
||||
QXBwbGUgSW5jLjETMBEGA1UECAwKQ2FsaWZvcm5pYTAeFw0yMDAzMTgxODMyNTNa
|
||||
Fw00NTAzMTUwMDAwMDBaMFIxJjAkBgNVBAMMHUFwcGxlIEFwcCBBdHRlc3RhdGlv
|
||||
biBSb290IENBMRMwEQYDVQQKDApBcHBsZSBJbmMuMRMwEQYDVQQIDApDYWxpZm9y
|
||||
bmlhMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAERTHhmLW07ATaFQIEVwTtT4dyctdh
|
||||
NbJhFs/Ii2FdCgAHGbpphY3+d8qjuDngIN3WVhQUBHAoMeQ/cLiP1sOUtgjqK9au
|
||||
Yen1mMEvRq9Sk3Jm5X8U62H+xTD3FE9TgS41o0IwQDAPBgNVHRMBAf8EBTADAQH/
|
||||
MB0GA1UdDgQWBBSskRBTM72+aEH/pwyp5frq5eWKoTAOBgNVHQ8BAf8EBAMCAQYw
|
||||
CgYIKoZIzj0EAwMDaAAwZQIwQgFGnByvsiVbpTKwSga0kP0e8EeDS4+sQmTvb7vn
|
||||
53O5+FRXgeLhpJ06ysC5PrOyAjEAp5U4xDgEgllF7En3VcE3iexZZtKeYnpqtijV
|
||||
oyFraWVIyd/dganmrduC1bmTBGwD
|
||||
-----END CERTIFICATE-----
|
||||
Reference in New Issue
Block a user