Skip to content

Commit 360a8e7

Browse files
committed
feat(push): support explicit personal development App Attest builds
Signed-off-by: Tom Brow <[email protected]>
1 parent 8953cbf commit 360a8e7

8 files changed

Lines changed: 477 additions & 21 deletions

File tree

‎Cargo.lock‎

Lines changed: 215 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Dockerfile.push-gateway‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ COPY . .
1111
RUN cargo chef prepare --recipe-path recipe.json
1212

1313
FROM chef AS builder
14+
ARG BUZZ_PUSH_CARGO_FEATURES=""
1415
RUN apt-get update \
1516
&& apt-get install -y --no-install-recommends build-essential pkg-config libssl-dev ca-certificates \
1617
&& rm -rf /var/lib/apt/lists/*
1718
COPY --from=planner /build/recipe.json recipe.json
18-
RUN cargo chef cook --release --recipe-path recipe.json
19+
RUN cargo chef cook --release --recipe-path recipe.json --features "$BUZZ_PUSH_CARGO_FEATURES"
1920
COPY . .
20-
RUN cargo build --release --locked -p buzz-push-gateway --bin buzz-push-gateway \
21+
RUN cargo build --release --locked -p buzz-push-gateway --bin buzz-push-gateway --features "$BUZZ_PUSH_CARGO_FEATURES" \
2122
&& strip target/release/buzz-push-gateway
2223

2324
FROM debian:${DEBIAN_VERSION}-slim AS runtime

‎crates/buzz-push-gateway/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ path = "src/lib.rs"
1515
name = "buzz-push-gateway"
1616
path = "src/main.rs"
1717

18+
[features]
19+
# Personal device development only. Production builds remain production-only.
20+
personal-dev-app-attest = ["appattest/testing"]
21+
1822
[dependencies]
1923
aes-gcm = "0.10"
2024
appattest = { version = "0.1.1", default-features = false }

‎crates/buzz-push-gateway/src/app_attest.rs‎

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Narrow App Attest verification boundary. Production enrollment accepts only
2-
//! Apple production AAGUID material; unsupported devices have no bypass path.
2+
//! Apple production AAGUID material by default; personal development requires
3+
//! an explicit build feature and environment. No cryptographic checks are skipped.
4+
use crate::config::AppAttestEnvironment;
35
use appattest::{assertion::Assertion, attestation::Attestation};
46
use base64::{engine::general_purpose::STANDARD, Engine as _};
57
use byteorder::{BigEndian, ByteOrder};
@@ -31,9 +33,24 @@ pub enum AppAttestError {
3133
pub struct AppAttestVerifier {
3234
app_id: String,
3335
apple_root_cert_pem: Vec<u8>,
36+
environment: AppAttestEnvironment,
3437
}
3538
impl AppAttestVerifier {
39+
/// Construct a production-only verifier.
3640
pub fn new(app_id: String, apple_root_cert_pem: Vec<u8>) -> Result<Self, AppAttestError> {
41+
Self::with_environment(
42+
app_id,
43+
apple_root_cert_pem,
44+
AppAttestEnvironment::Production,
45+
)
46+
}
47+
48+
/// Construct a verifier for exactly one server-selected attestation environment.
49+
pub fn with_environment(
50+
app_id: String,
51+
apple_root_cert_pem: Vec<u8>,
52+
environment: AppAttestEnvironment,
53+
) -> Result<Self, AppAttestError> {
3754
if app_id.is_empty()
3855
|| Sha256::digest(&apple_root_cert_pem).as_slice() != APPLE_APP_ATTEST_ROOT_PEM_SHA256
3956
{
@@ -42,6 +59,7 @@ impl AppAttestVerifier {
4259
Ok(Self {
4360
app_id,
4461
apple_root_cert_pem,
62+
environment,
4563
})
4664
}
4765
/// `client_data` is the exact canonical enrollment transcript represented by
@@ -59,6 +77,7 @@ impl AppAttestVerifier {
5977
if cbor.is_empty() || cbor.len() > crate::model::MAX_APP_ATTESTATION_BYTES {
6078
return Err(AppAttestError::Invalid);
6179
}
80+
verify_attestation_environment(&cbor, self.environment)?;
6281
let challenge = std::str::from_utf8(client_data).map_err(|_| AppAttestError::Invalid)?;
6382
let att = Attestation::from_cbor_bytes(&cbor).map_err(|_| AppAttestError::Invalid)?;
6483
let (public_key, _) = att
@@ -112,6 +131,44 @@ impl AppAttestVerifier {
112131
}
113132
}
114133

134+
// The dependency's development feature accepts both Apple environments. Fence
135+
// the exact signed authData here, then let its full verifier validate those same
136+
// bytes (chain, nonce, app ID, counter, public key and credential ID).
137+
fn verify_attestation_environment(
138+
cbor: &[u8],
139+
environment: AppAttestEnvironment,
140+
) -> Result<(), AppAttestError> {
141+
let mut decoder = minicbor::Decoder::new(cbor);
142+
let count = decoder
143+
.map()
144+
.map_err(|_| AppAttestError::Invalid)?
145+
.ok_or(AppAttestError::Invalid)?;
146+
let mut auth_data = None;
147+
for _ in 0..count {
148+
let key = decoder.str().map_err(|_| AppAttestError::Invalid)?;
149+
if key == "authData" {
150+
if auth_data.is_some() {
151+
return Err(AppAttestError::Invalid);
152+
}
153+
auth_data = Some(decoder.bytes().map_err(|_| AppAttestError::Invalid)?);
154+
} else {
155+
decoder.skip().map_err(|_| AppAttestError::Invalid)?;
156+
}
157+
}
158+
if decoder.position() != cbor.len() {
159+
return Err(AppAttestError::Invalid);
160+
}
161+
let expected: &[u8] = match environment {
162+
AppAttestEnvironment::Production => b"appattest\0\0\0\0\0\0\0",
163+
#[cfg(feature = "personal-dev-app-attest")]
164+
AppAttestEnvironment::Development => b"appattestdevelop",
165+
};
166+
if auth_data.and_then(|data| data.get(37..53)) != Some(expected) {
167+
return Err(AppAttestError::Invalid);
168+
}
169+
Ok(())
170+
}
171+
115172
/// App Attest assertion CBOR is a closed two-field map. Extracting signCount
116173
/// from authenticatorData is safe only after the library verifies the same
117174
/// bytes' RP ID, signature, and monotonic relation.
@@ -173,6 +230,7 @@ mod tests {
173230
AppAttestVerifier {
174231
app_id: app_id.to_owned(),
175232
apple_root_cert_pem: root_cert_pem.to_vec(),
233+
environment: AppAttestEnvironment::Production,
176234
}
177235
}
178236

@@ -288,6 +346,7 @@ mod tests {
288346
fn wrong_aaguid_is_rejected_as_invalid_aaguid() {
289347
let fixture = fixture(WRONG_AAGUID_FIXTURE_JSON);
290348
assert_eq!(fixture.aaguid, "appattestdevelop");
349+
#[cfg(not(feature = "personal-dev-app-attest"))]
291350
assert_eq!(
292351
verify_dependency(
293352
&fixture,
@@ -307,6 +366,99 @@ mod tests {
307366
.is_err());
308367
}
309368

369+
#[cfg(feature = "personal-dev-app-attest")]
370+
#[test]
371+
fn development_mode_preserves_verification_and_rejects_production() {
372+
let dev = fixture(WRONG_AAGUID_FIXTURE_JSON);
373+
let mut v = verifier(&dev.app_id, dev.root_cert_pem.as_bytes());
374+
v.environment = AppAttestEnvironment::Development;
375+
let cbor = STANDARD.decode(&dev.attestation_b64).unwrap();
376+
assert!(
377+
verify_attestation_environment(&cbor, v.environment).is_ok(),
378+
"environment parser"
379+
);
380+
verify_dependency(
381+
&dev,
382+
&dev.app_id,
383+
&dev.challenge,
384+
&dev.key_id_b64,
385+
dev.root_cert_pem.as_bytes(),
386+
)
387+
.expect("development dependency");
388+
assert!(v
389+
.verify_attestation(
390+
&dev.attestation_b64,
391+
&dev.key_id_b64,
392+
dev.challenge.as_bytes()
393+
)
394+
.is_ok());
395+
let prod = fixture(GOOD_FIXTURE_JSON);
396+
assert!(v
397+
.verify_attestation(
398+
&prod.attestation_b64,
399+
&prod.key_id_b64,
400+
prod.challenge.as_bytes()
401+
)
402+
.is_err());
403+
assert!(v
404+
.verify_attestation(&dev.attestation_b64, &dev.key_id_b64, b"wrong challenge")
405+
.is_err());
406+
assert!(v
407+
.verify_attestation(
408+
&dev.attestation_b64,
409+
&STANDARD.encode([0; 32]),
410+
dev.challenge.as_bytes()
411+
)
412+
.is_err());
413+
v.app_id = "OTHER.wrong.app".into();
414+
assert!(v
415+
.verify_attestation(
416+
&dev.attestation_b64,
417+
&dev.key_id_b64,
418+
dev.challenge.as_bytes()
419+
)
420+
.is_err());
421+
v.app_id = dev.app_id;
422+
v.apple_root_cert_pem = fixture(WRONG_ROOT_FIXTURE_JSON).root_cert_pem.into_bytes();
423+
assert!(v
424+
.verify_attestation(
425+
&dev.attestation_b64,
426+
&dev.key_id_b64,
427+
dev.challenge.as_bytes()
428+
)
429+
.is_err());
430+
}
431+
432+
#[test]
433+
fn environment_parser_rejects_ambiguous_or_truncated_auth_data() {
434+
for data in [vec![], vec![0xa0], vec![0xa1, 0x68], vec![0xbf, 0xff]] {
435+
assert!(
436+
verify_attestation_environment(&data, AppAttestEnvironment::Production).is_err()
437+
);
438+
}
439+
let mut data = [0u8; 256];
440+
let mut encoder =
441+
minicbor::Encoder::new(minicbor::encode::write::Cursor::new(data.as_mut_slice()));
442+
let mut auth = [0u8; 53];
443+
auth[37..53].copy_from_slice(b"appattest\0\0\0\0\0\0\0");
444+
encoder
445+
.map(2)
446+
.unwrap()
447+
.str("authData")
448+
.unwrap()
449+
.bytes(&auth)
450+
.unwrap()
451+
.str("authData")
452+
.unwrap()
453+
.bytes(&auth)
454+
.unwrap();
455+
let length = encoder.writer().position();
456+
assert!(
457+
verify_attestation_environment(&data[..length], AppAttestEnvironment::Production)
458+
.is_err()
459+
);
460+
}
461+
310462
#[test]
311463
fn short_and_oversize_key_ids_are_rejected() {
312464
let fixture = fixture(GOOD_FIXTURE_JSON);

‎crates/buzz-push-gateway/src/config.rs‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@ pub enum ApnsEnvironment {
1111
#[derive(Debug, Clone)]
1212
pub struct AppProfileConfig {
1313
pub app_attest_app_id: String,
14+
/// Exact Apple attestation environment accepted for enrollment.
15+
pub app_attest_environment: AppAttestEnvironment,
1416
pub apns_cert_path: PathBuf,
1517
pub apns_topic: String,
1618
pub apns_environment: ApnsEnvironment,
1719
}
1820

21+
/// Apple App Attest environment, independent of the APNs transport environment.
22+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23+
pub enum AppAttestEnvironment {
24+
/// Distributed applications, also the default for personal development builds.
25+
Production,
26+
/// Development-signed applications in an explicitly opted-in gateway build.
27+
#[cfg(feature = "personal-dev-app-attest")]
28+
Development,
29+
}
30+
1931
#[derive(Debug, Clone, PartialEq, Eq)]
2032
pub struct KeyConfig {
2133
pub id: String,
@@ -143,6 +155,15 @@ fn parse_profile(e: &HashMap<String, String>) -> Result<AppProfileConfig, Config
143155
.ok_or(ConfigError::Missing(key))
144156
};
145157
let app_attest_app_id = required(app_id_key)?.to_owned();
158+
let app_attest_environment = match e
159+
.get("BUZZ_PUSH_APP_ATTEST_ENVIRONMENT")
160+
.map(String::as_str)
161+
{
162+
None | Some("production") => AppAttestEnvironment::Production,
163+
#[cfg(feature = "personal-dev-app-attest")]
164+
Some("development") => AppAttestEnvironment::Development,
165+
Some(_) => return Err(ConfigError::Invalid("BUZZ_PUSH_APP_ATTEST_ENVIRONMENT")),
166+
};
146167
let apns_topic = required(topic_key)?.to_owned();
147168
let apns_cert_path = PathBuf::from(required(cert_key)?);
148169
let apns_environment = match e.get(environment_key).map(String::as_str) {
@@ -152,6 +173,7 @@ fn parse_profile(e: &HashMap<String, String>) -> Result<AppProfileConfig, Config
152173
};
153174
Ok(AppProfileConfig {
154175
app_attest_app_id,
176+
app_attest_environment,
155177
apns_cert_path,
156178
apns_topic,
157179
apns_environment,
@@ -258,6 +280,47 @@ impl Config {
258280
#[cfg(test)]
259281
mod tests {
260282
use super::*;
283+
#[test]
284+
fn attestation_environment_is_explicit_and_build_gated() {
285+
let mut env = base();
286+
assert_eq!(
287+
Config::from_map(&env)
288+
.unwrap()
289+
.profile
290+
.app_attest_environment,
291+
AppAttestEnvironment::Production
292+
);
293+
for value in ["", "sandbox", "Production", "unknown"] {
294+
env.insert("BUZZ_PUSH_APP_ATTEST_ENVIRONMENT".into(), value.into());
295+
assert!(Config::from_map(&env).is_err());
296+
}
297+
env.insert(
298+
"BUZZ_PUSH_APP_ATTEST_ENVIRONMENT".into(),
299+
"production".into(),
300+
);
301+
assert_eq!(
302+
Config::from_map(&env)
303+
.unwrap()
304+
.profile
305+
.app_attest_environment,
306+
AppAttestEnvironment::Production
307+
);
308+
env.insert(
309+
"BUZZ_PUSH_APP_ATTEST_ENVIRONMENT".into(),
310+
"development".into(),
311+
);
312+
#[cfg(feature = "personal-dev-app-attest")]
313+
assert_eq!(
314+
Config::from_map(&env)
315+
.unwrap()
316+
.profile
317+
.app_attest_environment,
318+
AppAttestEnvironment::Development
319+
);
320+
#[cfg(not(feature = "personal-dev-app-attest"))]
321+
assert!(Config::from_map(&env).is_err());
322+
}
323+
261324
fn base() -> HashMap<String, String> {
262325
HashMap::from([
263326
(

‎crates/buzz-push-gateway/src/main.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4343
configured.apns_topic.clone(),
4444
configured.apns_environment,
4545
)?);
46-
let apple = AppAttestVerifier::new(
46+
let apple = AppAttestVerifier::with_environment(
4747
configured.app_attest_app_id.clone(),
4848
app_attest_root.clone(),
49+
configured.app_attest_environment,
4950
)?;
5051
buzz_push_gateway::http::ProfileRuntime {
5152
app_attest: Arc::new(apple),

‎docs/push-gateway-deployment.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,32 @@ select among multiple application profiles.
4545

4646
Optional endpoint quota policy variables are `BUZZ_PUSH_ENDPOINT_QUOTA_WINDOW_SECONDS` (default `10`, max `86400`) and `BUZZ_PUSH_ENDPOINT_QUOTA_MAX_DELIVERIES` (default `10`, max `10000`). These are Buzz policy hypotheses, not Apple-published limits; tune under load while retaining a hard ceiling.
4747

48+
## Personal device development
49+
50+
A development-signed iOS app uses Apple's development App Attest environment.
51+
The ordinary gateway binary rejects those attestations. For an isolated personal
52+
stack, build with Cargo feature `personal-dev-app-attest` (Docker build argument
53+
`BUZZ_PUSH_CARGO_FEATURES=personal-dev-app-attest`) and set
54+
`BUZZ_PUSH_APP_ATTEST_ENVIRONMENT=development`. The default remains `production`,
55+
including in that special build; ordinary builds reject the development setting.
56+
The gateway accepts exactly the selected AAGUID and still verifies the pinned
57+
Apple root, certificate chain, nonce, application identity, public key,
58+
credential ID, and counter. This is not a simulator or attestation bypass.
59+
60+
Set `BUZZ_PUSH_DOGFOOD_APP_ATTEST_APP_ID` to the personal `TEAMID.bundle-id`,
61+
`BUZZ_PUSH_DOGFOOD_APNS_TOPIC` to that same bundle ID,
62+
`BUZZ_PUSH_DOGFOOD_APNS_ENVIRONMENT=sandbox`, and supply its APNs certificate.
63+
This isolated stack reuses the single `buzz-ios-dogfood` wire profile for its
64+
server-owned personal identity; it does not add a production application profile.
65+
Do not point distributed dogfood clients at this personal gateway.
66+
67+
Build the mobile client with the personal team and parent bundle ID, its matching
68+
`.NotificationService` extension, development APNs/App Attest entitlements, and
69+
an explicit `BUZZ_PUSH_GATEWAY_URL`. See `mobile/README.md` for gitignored signing
70+
overrides. Both targets need matching provisioning profiles; the parent profile
71+
must include the capabilities in `Runner.entitlements`. Validate enrollment and
72+
notification presentation on a physical device, not a simulator.
73+
4874
## Secret and key rotation rules
4975

5076
Mount the App Attest root read-only and startup will reject any byte mismatch. The sole accepted artifact is Apple’s **Apple App Attestation Root CA** from `https://www.apple.com/certificateauthority/Apple_App_Attestation_Root_CA.pem`: certificate SHA-256 fingerprint `1C:B9:82:3B:A2:8B:A6:AD:2D:33:A0:06:94:1D:E2:AE:4F:51:3E:F1:D4:E8:31:B9:F7:E0:FA:7B:62:42:C9:32`; exact PEM-file SHA-256 `c778d09ac341f7fd9f8f3b19e2b815af6aed4ad4490e1e92c05cb355212a5013`. Treat an Apple root rotation as a reviewed code/config rollout, not an unpinned mount replacement. Mount the APNs certificate identity and both AEAD keyrings from a secret manager; never place values in an image, manifest, log, or metrics label. Keep the current AEAD key first and retain decrypt-only predecessors until every capability/token encrypted under them has expired or been re-encrypted. Grant and token key ids and bytes must be distinct. Rotation is an operator rollout: add the new current key while retaining predecessors, deploy, wait through the retention window, then remove the old key.

0 commit comments

Comments
 (0)