@pithy-sh/auth 0.15.3 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/attestation/appAttest/assertion.d.ts +32 -0
- package/dist/attestation/appAttest/assertion.d.ts.map +1 -0
- package/dist/attestation/appAttest/assertion.js +59 -0
- package/dist/attestation/appAttest/attestation.d.ts +49 -0
- package/dist/attestation/appAttest/attestation.d.ts.map +1 -0
- package/dist/attestation/appAttest/attestation.js +111 -0
- package/dist/attestation/appAttest/authData.d.ts +24 -0
- package/dist/attestation/appAttest/authData.d.ts.map +1 -0
- package/dist/attestation/appAttest/authData.js +32 -0
- package/dist/attestation/appAttest/base64.d.ts +8 -0
- package/dist/attestation/appAttest/base64.d.ts.map +1 -0
- package/dist/attestation/appAttest/base64.js +27 -0
- package/dist/attestation/appAttest/bytes.d.ts +7 -0
- package/dist/attestation/appAttest/bytes.d.ts.map +1 -0
- package/dist/attestation/appAttest/bytes.js +19 -0
- package/dist/attestation/appAttest/cbor.d.ts +20 -0
- package/dist/attestation/appAttest/cbor.d.ts.map +1 -0
- package/dist/attestation/appAttest/cbor.js +96 -0
- package/dist/attestation/appAttest/der.d.ts +38 -0
- package/dist/attestation/appAttest/der.d.ts.map +1 -0
- package/dist/attestation/appAttest/der.js +106 -0
- package/dist/attestation/appAttest/keys.d.ts +15 -0
- package/dist/attestation/appAttest/keys.d.ts.map +1 -0
- package/dist/attestation/appAttest/keys.js +37 -0
- package/dist/attestation/appAttest/root.d.ts +9 -0
- package/dist/attestation/appAttest/root.d.ts.map +1 -0
- package/dist/attestation/appAttest/root.js +12 -0
- package/dist/attestation/appAttest/verifier.d.ts +39 -0
- package/dist/attestation/appAttest/verifier.d.ts.map +1 -0
- package/dist/attestation/appAttest/verifier.js +121 -0
- package/dist/attestation/appAttest/x509.d.ts +50 -0
- package/dist/attestation/appAttest/x509.d.ts.map +1 -0
- package/dist/attestation/appAttest/x509.js +163 -0
- package/dist/attestation/challenge.d.ts +26 -0
- package/dist/attestation/challenge.d.ts.map +1 -0
- package/dist/attestation/challenge.js +47 -0
- package/dist/attestation/config.d.ts +72 -0
- package/dist/attestation/config.d.ts.map +1 -0
- package/dist/attestation/config.js +52 -0
- package/dist/attestation/errors.d.ts +30 -0
- package/dist/attestation/errors.d.ts.map +1 -0
- package/dist/attestation/errors.js +45 -0
- package/dist/attestation/gate.d.ts +27 -0
- package/dist/attestation/gate.d.ts.map +1 -0
- package/dist/attestation/gate.js +78 -0
- package/dist/attestation/playIntegrity/google.d.ts +47 -0
- package/dist/attestation/playIntegrity/google.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/google.js +178 -0
- package/dist/attestation/playIntegrity/verdict.d.ts +40 -0
- package/dist/attestation/playIntegrity/verdict.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/verdict.js +93 -0
- package/dist/attestation/playIntegrity/verifier.d.ts +22 -0
- package/dist/attestation/playIntegrity/verifier.d.ts.map +1 -0
- package/dist/attestation/playIntegrity/verifier.js +64 -0
- package/dist/attestation/verifier.d.ts +60 -0
- package/dist/attestation/verifier.d.ts.map +1 -0
- package/dist/attestation/verifier.js +46 -0
- package/dist/attestation/wire.d.ts +42 -0
- package/dist/attestation/wire.d.ts.map +1 -0
- package/dist/attestation/wire.js +72 -0
- package/dist/capability.d.ts +49 -6
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +42 -7
- package/dist/client/api.d.ts +37 -24
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +52 -41
- package/dist/client/attestation.d.ts +148 -0
- package/dist/client/attestation.d.ts.map +1 -0
- package/dist/client/attestation.js +321 -0
- package/dist/client/projection.d.ts +29 -4
- package/dist/client/projection.d.ts.map +1 -1
- package/dist/data/appAttestKey.d.ts +30 -0
- package/dist/data/appAttestKey.d.ts.map +1 -0
- package/dist/data/appAttestKey.js +25 -0
- package/dist/data/attestationChallenge.d.ts +17 -0
- package/dist/data/attestationChallenge.d.ts.map +1 -0
- package/dist/data/attestationChallenge.js +19 -0
- package/dist/data/tables.d.ts +19 -1
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +6 -2
- package/dist/data/userLifecycle.d.ts +1 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +3 -2
- package/dist/hooks/runtime.d.ts +32 -0
- package/dist/hooks/runtime.d.ts.map +1 -0
- package/dist/hooks/runtime.js +25 -0
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +4 -2
- package/dist/http/devLoginRoute.js +3 -3
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +3 -2
- package/dist/http/responses.d.ts +15 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +13 -2
- package/dist/http/routes.d.ts +5 -1
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +92 -25
- package/dist/http/schemas.d.ts +7 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +7 -1
- package/dist/index.js +1 -1
- package/dist/instance/secrets.d.ts +86 -7
- package/dist/instance/secrets.d.ts.map +1 -1
- package/dist/instance/secrets.js +54 -8
- package/dist/lifecycle/erasure.d.ts.map +1 -1
- package/dist/lifecycle/erasure.js +2 -1
- package/dist/lifecycle/hooks.d.ts +18 -10
- package/dist/lifecycle/hooks.d.ts.map +1 -1
- package/dist/lifecycle/request.d.ts +2 -1
- package/dist/lifecycle/request.d.ts.map +1 -1
- package/dist/lifecycle/request.js +4 -1
- package/dist/lifecycle/transitions.d.ts +24 -16
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +27 -16
- package/dist/migrations/0009_attestation_challenges.d.ts +9 -0
- package/dist/migrations/0009_attestation_challenges.d.ts.map +1 -0
- package/dist/migrations/0009_attestation_challenges.js +21 -0
- package/dist/migrations/0010_app_attest_keys.d.ts +9 -0
- package/dist/migrations/0010_app_attest_keys.d.ts.map +1 -0
- package/dist/migrations/0010_app_attest_keys.js +17 -0
- package/dist/migrations/0011_retained_basis_key.d.ts +10 -0
- package/dist/migrations/0011_retained_basis_key.d.ts.map +1 -0
- package/dist/migrations/0011_retained_basis_key.js +18 -0
- package/dist/migrations/set.d.ts +4 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +8 -2
- package/dist/purge/run.d.ts +11 -11
- package/dist/purge/run.d.ts.map +1 -1
- package/dist/purge/run.js +9 -8
- package/dist/purge/workflow.d.ts +7 -1
- package/dist/purge/workflow.d.ts.map +1 -1
- package/dist/purge/workflow.js +6 -2
- package/dist/seeds/devSession.js +1 -1
- package/dist/test-utils/appAttestDevice.d.ts +92 -0
- package/dist/test-utils/appAttestDevice.d.ts.map +1 -0
- package/dist/test-utils/appAttestDevice.js +282 -0
- package/dist/test-utils/appAttestSample.d.ts +22 -0
- package/dist/test-utils/appAttestSample.d.ts.map +1 -0
- package/dist/test-utils/appAttestSample.js +24 -0
- package/dist/test-utils/googlePlay.d.ts +47 -0
- package/dist/test-utils/googlePlay.d.ts.map +1 -0
- package/dist/test-utils/googlePlay.js +117 -0
- package/dist/test-utils/liveApp.d.ts +76 -36
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +16 -5
- package/dist/test-utils/rollbackThrough.d.ts +11 -0
- package/dist/test-utils/rollbackThrough.d.ts.map +1 -0
- package/dist/test-utils/rollbackThrough.js +16 -0
- package/dist/test-utils/scopedBackend.d.ts +25 -0
- package/dist/test-utils/scopedBackend.d.ts.map +1 -1
- package/dist/test-utils/scopedBackend.js +1 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +46 -10
- package/docs/attestation.md +173 -0
- package/package.json +5 -5
- package/pithy.manifest.json +14 -0
- package/src/attestation/appAttest/assertion.ts +65 -0
- package/src/attestation/appAttest/attestation.ts +159 -0
- package/src/attestation/appAttest/authData.ts +45 -0
- package/src/attestation/appAttest/base64.ts +29 -0
- package/src/attestation/appAttest/bytes.ts +18 -0
- package/src/attestation/appAttest/cbor.ts +116 -0
- package/src/attestation/appAttest/der.ts +126 -0
- package/src/attestation/appAttest/keys.ts +57 -0
- package/src/attestation/appAttest/root.ts +13 -0
- package/src/attestation/appAttest/verifier.ts +113 -0
- package/src/attestation/appAttest/x509.ts +209 -0
- package/src/attestation/challenge.ts +56 -0
- package/src/attestation/config.ts +118 -0
- package/src/attestation/errors.ts +60 -0
- package/src/attestation/gate.ts +105 -0
- package/src/attestation/playIntegrity/google.ts +239 -0
- package/src/attestation/playIntegrity/verdict.ts +149 -0
- package/src/attestation/playIntegrity/verifier.ts +77 -0
- package/src/attestation/verifier.ts +87 -0
- package/src/attestation/wire.ts +79 -0
- package/src/capability.ts +85 -16
- package/src/client/api.ts +73 -40
- package/src/client/attestation.ts +404 -0
- package/src/client/projection.ts +29 -4
- package/src/data/appAttestKey.ts +45 -0
- package/src/data/attestationChallenge.ts +23 -0
- package/src/data/tables.ts +5 -1
- package/src/data/userLifecycle.ts +9 -2
- package/src/hooks/runtime.ts +41 -0
- package/src/http/adminRoutes.ts +14 -7
- package/src/http/resolve.ts +8 -4
- package/src/http/responses.ts +29 -1
- package/src/http/routes.ts +128 -38
- package/src/http/schemas.ts +24 -0
- package/src/instance/secrets.ts +88 -9
- package/src/lifecycle/erasure.ts +2 -1
- package/src/lifecycle/hooks.ts +22 -10
- package/src/lifecycle/request.ts +4 -1
- package/src/lifecycle/transitions.ts +47 -28
- package/src/migrations/0009_attestation_challenges.ts +28 -0
- package/src/migrations/0010_app_attest_keys.ts +27 -0
- package/src/migrations/0011_retained_basis_key.ts +19 -0
- package/src/migrations/set.ts +7 -1
- package/src/purge/run.ts +29 -17
- package/src/purge/workflow.ts +7 -3
- package/src/test-utils/appAttestDevice.ts +399 -0
- package/src/test-utils/appAttestSample.ts +20 -0
- package/src/test-utils/googlePlay.ts +144 -0
- package/src/test-utils/liveApp.ts +31 -5
- package/src/test-utils/rollbackThrough.ts +24 -0
- package/src/version.generated.ts +1 -1
package/src/purge/run.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isRetained,
|
|
6
|
+
type PurgeContext,
|
|
7
|
+
type PurgeStep,
|
|
8
|
+
type RetainingPurgeContribution,
|
|
9
|
+
} from "@pithy-sh/core/src/capability/purge";
|
|
5
10
|
import type { LegalHolds } from "@pithy-sh/core/src/retention/holds";
|
|
6
11
|
import {
|
|
7
12
|
classifiedSteps,
|
|
@@ -23,7 +28,7 @@ import { authWorkflowRetry } from "./retryPolicy";
|
|
|
23
28
|
import { AUTH_CAPABILITY, type AuthPurgeDueParams, type AuthPurgeParams } from "./specs";
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
|
-
* The purge, as steps
|
|
31
|
+
* The purge, as steps — the bodies `./workflow.ts` hands a Workflow's step runner to.
|
|
27
32
|
*
|
|
28
33
|
* ## One step per contribution, and the order they run in
|
|
29
34
|
*
|
|
@@ -31,7 +36,7 @@ import { AUTH_CAPABILITY, type AuthPurgeDueParams, type AuthPurgeParams } from "
|
|
|
31
36
|
* and one already erased all end the run here, having erased nothing. This is the one check a cron-started
|
|
32
37
|
* purge and a hard deletion's both pass through, so re-running a purge for the same subject exits cleanly.
|
|
33
38
|
* 2. **`erase <capability>`** — one step per composed contribution, in composition order, each recording that it
|
|
34
|
-
* ran in `pithy_auth_user_lifecycle`. A contribution that **retains** its rows
|
|
39
|
+
* ran in `pithy_auth_user_lifecycle`. A contribution that **retains** its rows is a `retain <capability>`
|
|
35
40
|
* step instead: it erases nothing, and records `purge_retained` with the basis it gave. Handed to the platform's retry unclassified: an `erase` is idempotent by
|
|
36
41
|
* contract and runs code the kit did not write, so any fault in it is worth another attempt (`./retryPolicy.ts`).
|
|
37
42
|
* A failing contribution retries alone, and the ones that finished are served from the journal.
|
|
@@ -41,7 +46,7 @@ import { AUTH_CAPABILITY, type AuthPurgeDueParams, type AuthPurgeParams } from "
|
|
|
41
46
|
* 4. **`erase auth`** — auth's own contribution, last for that reason.
|
|
42
47
|
* 5. **`complete`** — the `purged` record, the audit event, `onUserPurged`. Once.
|
|
43
48
|
*
|
|
44
|
-
* Every step from 2 on records an audit event as well as its row
|
|
49
|
+
* Every step from 2 on records an audit event as well as its row, which the erasure attestation cites.
|
|
45
50
|
*
|
|
46
51
|
* ## A legal hold stops it
|
|
47
52
|
*
|
|
@@ -52,7 +57,7 @@ import { AUTH_CAPABILITY, type AuthPurgeDueParams, type AuthPurgeParams } from "
|
|
|
52
57
|
* erase where the first one did and carry on from there. A hold that cannot be read fails its step, which retries:
|
|
53
58
|
* a purge never erases past a hold it could not see.
|
|
54
59
|
*
|
|
55
|
-
* ## A purge that gives up says where
|
|
60
|
+
* ## A purge that gives up says where
|
|
56
61
|
*
|
|
57
62
|
* A step that exhausts its retries fails the instance, and the daily pass starts a fresh one tomorrow. Until then the
|
|
58
63
|
* record would read as a purge still running. So the failure is caught once, recorded in its own `fail` step —
|
|
@@ -66,10 +71,10 @@ export interface PurgeOps {
|
|
|
66
71
|
due(userId: string): Promise<"due" | "not_due" | "gone">;
|
|
67
72
|
/** Record that one capability's step erased its rows. */
|
|
68
73
|
recordStep(userId: string, step: string, summary: string): Promise<void>;
|
|
69
|
-
/** Record that one capability's step kept its rows, and why
|
|
70
|
-
recordRetained(userId: string, step: string,
|
|
74
|
+
/** Record that one capability's step kept its rows, and why: its basis, and the catalog key that translates it. */
|
|
75
|
+
recordRetained(userId: string, step: string, retain: RetainingPurgeContribution["retain"]): Promise<void>;
|
|
71
76
|
/**
|
|
72
|
-
* The account's address, read now, or `null` once it is gone
|
|
77
|
+
* The account's address, read now, or `null` once it is gone. Handed to each step as
|
|
73
78
|
* `PurgeContext.address`, so a capability holding rows by address reads it inside its own step.
|
|
74
79
|
*/
|
|
75
80
|
address(userId: string): Promise<string | null>;
|
|
@@ -80,7 +85,7 @@ export interface PurgeOps {
|
|
|
80
85
|
mailComplete(userId: string, notify: boolean | undefined): Promise<boolean>;
|
|
81
86
|
/** Write the `purged` record, the audit event and the hook. Says whether this call wrote them. */
|
|
82
87
|
complete(userId: string): Promise<boolean>;
|
|
83
|
-
/** Record that the purge gave up at `step`, in the history and the trail
|
|
88
|
+
/** Record that the purge gave up at `step`, in the history and the trail. */
|
|
84
89
|
fail(userId: string, step: string): Promise<void>;
|
|
85
90
|
/** Whether a legal hold stands on the account. Throws when it cannot say. */
|
|
86
91
|
held(userId: string): Promise<boolean>;
|
|
@@ -91,13 +96,20 @@ export function purgeOps(deps: LifecycleDeps, holds: LegalHolds): PurgeOps {
|
|
|
91
96
|
return {
|
|
92
97
|
due: async (userId) => (await purgeSubject(deps, userId)).state,
|
|
93
98
|
recordStep: (userId, step, summary) => recordPurgeStep(deps, { userId, step, summary }),
|
|
94
|
-
recordRetained: (userId, step,
|
|
99
|
+
recordRetained: (userId, step, retain) =>
|
|
100
|
+
recordPurgeStep(deps, {
|
|
101
|
+
userId,
|
|
102
|
+
step,
|
|
103
|
+
summary: retain.basis,
|
|
104
|
+
retained: true,
|
|
105
|
+
...(retain.basisKey === undefined ? {} : { basisKey: retain.basisKey }),
|
|
106
|
+
}),
|
|
95
107
|
address: (userId) => purgeAddress(deps.db, userId),
|
|
96
108
|
mailComplete: async (userId, notify) => {
|
|
97
109
|
const subject = await purgeSubject(deps, userId);
|
|
98
110
|
if (subject.state !== "due") return false;
|
|
99
111
|
// Either can silence it: the parameter a hard deletion started this purge with, or the choice that deletion
|
|
100
|
-
// wrote on its history row — the one a purge the daily pass started still has
|
|
112
|
+
// wrote on its history row — the one a purge the daily pass started still has.
|
|
101
113
|
const silenced = notify === false || subject.notify === false;
|
|
102
114
|
return (await mailPurgeComplete(deps, { recipient: subject.recipient, ...(silenced ? { notify: false } : {}) }))
|
|
103
115
|
.mailed;
|
|
@@ -119,7 +131,7 @@ export interface PurgeOutcome {
|
|
|
119
131
|
readonly state: "purged" | "not_due" | "gone" | "held";
|
|
120
132
|
/** Every step that erased its rows, in the order it ran. Empty when nothing was erased. */
|
|
121
133
|
readonly erased: readonly string[];
|
|
122
|
-
/** Every step that kept its rows under a stated basis
|
|
134
|
+
/** Every step that kept its rows under a stated basis, in the order it ran. */
|
|
123
135
|
readonly retained: readonly string[];
|
|
124
136
|
/** Whether the deletion-complete mail was enqueued. */
|
|
125
137
|
readonly mailed: boolean;
|
|
@@ -165,7 +177,7 @@ export async function purgeUser(
|
|
|
165
177
|
const { contribution } = each;
|
|
166
178
|
current = each.step;
|
|
167
179
|
if (isRetained(contribution))
|
|
168
|
-
retained.push(await retainStep(step, run.ops, each.step, contribution.retain
|
|
180
|
+
retained.push(await retainStep(step, run.ops, each.step, contribution.retain, userId));
|
|
169
181
|
else erased.push(await eraseStep(step, run.ops, each, context));
|
|
170
182
|
};
|
|
171
183
|
try {
|
|
@@ -218,18 +230,18 @@ function eraseStep(step: WorkflowStepLike, ops: PurgeOps, each: PurgeStep, conte
|
|
|
218
230
|
}
|
|
219
231
|
|
|
220
232
|
/**
|
|
221
|
-
* One capability's retained step
|
|
233
|
+
* One capability's retained step: nothing is erased, and the record says the rows were kept and why. Its own
|
|
222
234
|
* step, so the trail names it in the order it would have run, and a replay serves it from the journal.
|
|
223
235
|
*/
|
|
224
236
|
function retainStep(
|
|
225
237
|
step: WorkflowStepLike,
|
|
226
238
|
ops: PurgeOps,
|
|
227
239
|
name: string,
|
|
228
|
-
|
|
240
|
+
retain: RetainingPurgeContribution["retain"],
|
|
229
241
|
userId: string,
|
|
230
242
|
): Promise<string> {
|
|
231
243
|
return step.do(`retain ${name}`, async () => {
|
|
232
|
-
await ops.recordRetained(userId, name,
|
|
244
|
+
await ops.recordRetained(userId, name, retain);
|
|
233
245
|
return name;
|
|
234
246
|
});
|
|
235
247
|
}
|
|
@@ -258,7 +270,7 @@ export interface PurgeDueRun {
|
|
|
258
270
|
}
|
|
259
271
|
|
|
260
272
|
/**
|
|
261
|
-
* The daily pass
|
|
273
|
+
* The daily pass: list every account past its window, and start a purge for each — in pages, one step
|
|
262
274
|
* each, so a pass that dies part-way resumes after the page it finished rather than starting every purge
|
|
263
275
|
* again. An account still inside its window is not listed, so it is not started.
|
|
264
276
|
*/
|
package/src/purge/workflow.ts
CHANGED
|
@@ -31,7 +31,7 @@ import { AUTH_PURGE_BINDING, AUTH_PURGE_KEY, AuthPurgeDueParams, AuthPurgeParams
|
|
|
31
31
|
import { startPurgeInstance } from "./start";
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* The purge's two Workflow bodies
|
|
34
|
+
* The purge's two Workflow bodies — run by classes **the adopter's own Worker** exports, beside the
|
|
35
35
|
* `createEntrypoint` it already exports, because a purge runs every composed capability's contribution and
|
|
36
36
|
* those exist nowhere else:
|
|
37
37
|
*
|
|
@@ -67,8 +67,11 @@ interface PurgeEvent {
|
|
|
67
67
|
readonly instanceId?: string;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/**
|
|
71
|
-
|
|
70
|
+
/**
|
|
71
|
+
* The lifecycle transitions' dependencies, for a run with no request: this env, and the composition's seams. The
|
|
72
|
+
* hooks run in this env with no `waitUntil`, since a Workflow has no `ExecutionContext`.
|
|
73
|
+
*/
|
|
74
|
+
export function lifecycleFor(auth: AuthCapability, env: Record<string, unknown>, log: Logger): LifecycleDeps {
|
|
72
75
|
const d1 = resolveDb(env, auth.authConfig.database);
|
|
73
76
|
return {
|
|
74
77
|
db: authDatabase(d1),
|
|
@@ -76,6 +79,7 @@ function lifecycleFor(auth: AuthCapability, env: Record<string, unknown>, log: L
|
|
|
76
79
|
emit: auth.auditFor(env),
|
|
77
80
|
config: auth.authConfig,
|
|
78
81
|
hooks: auth.lifecycleHooks,
|
|
82
|
+
runtime: { env },
|
|
79
83
|
enqueueEmail: (input) => enqueueFromEnv(env as unknown as EmailEnqueueEnv, input),
|
|
80
84
|
log,
|
|
81
85
|
};
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { base64UrlEncode } from "@pithy-sh/core/src/controlPlane/token/base64url";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A stand-in for Apple's App Attest service and a device's Secure Enclave, built on WebCrypto.
|
|
8
|
+
*
|
|
9
|
+
* It mints a root and an intermediate in the shape Apple's are (P-384, ECDSA with SHA-384), and per key a P-256
|
|
10
|
+
* leaf signed with SHA-256 that carries the nonce extension `1.2.840.113635.100.8.2`, then the attestation object
|
|
11
|
+
* and assertions exactly as `DCAppAttestService` returns them. A test trusts {@link AppAttestAuthority.root} in
|
|
12
|
+
* place of Apple's, which is the only difference from a real device: every byte goes through the same reader.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
type Bytes = Uint8Array;
|
|
16
|
+
|
|
17
|
+
function concat(...parts: Bytes[]): Bytes {
|
|
18
|
+
const out = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
19
|
+
let offset = 0;
|
|
20
|
+
for (const part of parts) {
|
|
21
|
+
out.set(part, offset);
|
|
22
|
+
offset += part.length;
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function standardBase64(bytes: Bytes): string {
|
|
28
|
+
let binary = "";
|
|
29
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
30
|
+
return btoa(binary);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function sha256(...parts: Bytes[]): Promise<Bytes> {
|
|
34
|
+
return new Uint8Array(await crypto.subtle.digest("SHA-256", concat(...parts)));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// DER writer.
|
|
38
|
+
|
|
39
|
+
function tlv(tag: number, content: Bytes): Bytes {
|
|
40
|
+
const length = content.length;
|
|
41
|
+
const header =
|
|
42
|
+
length < 0x80
|
|
43
|
+
? [length]
|
|
44
|
+
: length < 0x100
|
|
45
|
+
? [0x81, length]
|
|
46
|
+
: length < 0x10000
|
|
47
|
+
? [0x82, length >> 8, length & 0xff]
|
|
48
|
+
: [0x83, length >> 16, (length >> 8) & 0xff, length & 0xff];
|
|
49
|
+
return concat(new Uint8Array([tag, ...header]), content);
|
|
50
|
+
}
|
|
51
|
+
const seq = (...items: Bytes[]) => tlv(0x30, concat(...items));
|
|
52
|
+
const set = (...items: Bytes[]) => tlv(0x31, concat(...items));
|
|
53
|
+
const octets = (bytes: Bytes) => tlv(0x04, bytes);
|
|
54
|
+
const bits = (bytes: Bytes) => tlv(0x03, concat(new Uint8Array([0]), bytes));
|
|
55
|
+
const utf8 = (text: string) => tlv(0x0c, new TextEncoder().encode(text));
|
|
56
|
+
|
|
57
|
+
function integer(bytes: Bytes): Bytes {
|
|
58
|
+
let start = 0;
|
|
59
|
+
while (start < bytes.length - 1 && bytes[start] === 0) start++;
|
|
60
|
+
const digits = bytes.subarray(start);
|
|
61
|
+
return tlv(0x02, (digits[0] as number) & 0x80 ? concat(new Uint8Array([0]), digits) : digits);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function oid(dotted: string): Bytes {
|
|
65
|
+
const [first, second, ...rest] = dotted.split(".").map(Number) as number[];
|
|
66
|
+
const out = [(first as number) * 40 + (second as number)];
|
|
67
|
+
for (const arc of rest) {
|
|
68
|
+
const chunk = [arc & 0x7f];
|
|
69
|
+
for (let value = Math.floor(arc / 128); value > 0; value = Math.floor(value / 128))
|
|
70
|
+
chunk.unshift((value & 0x7f) | 0x80);
|
|
71
|
+
out.push(...chunk);
|
|
72
|
+
}
|
|
73
|
+
return tlv(0x06, new Uint8Array(out));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function time(date: Date): Bytes {
|
|
77
|
+
const iso = date.toISOString();
|
|
78
|
+
const text = `${iso.slice(2, 4)}${iso.slice(5, 7)}${iso.slice(8, 10)}${iso.slice(11, 13)}${iso.slice(14, 16)}${iso.slice(17, 19)}Z`;
|
|
79
|
+
return tlv(0x17, new TextEncoder().encode(text));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const name = (commonName: string) =>
|
|
83
|
+
seq(set(seq(oid("2.5.4.3"), utf8(commonName))), set(seq(oid("2.5.4.10"), utf8("Apple Inc."))));
|
|
84
|
+
|
|
85
|
+
const CURVE_OID = { "P-256": "1.2.840.10045.3.1.7", "P-384": "1.3.132.0.34" } as const;
|
|
86
|
+
const SIGNATURE_OID = { "SHA-256": "1.2.840.10045.4.3.2", "SHA-384": "1.2.840.10045.4.3.3" } as const;
|
|
87
|
+
const FIELD = { "P-256": 32, "P-384": 48 } as const;
|
|
88
|
+
|
|
89
|
+
type Curve = keyof typeof CURVE_OID;
|
|
90
|
+
type Hash = keyof typeof SIGNATURE_OID;
|
|
91
|
+
|
|
92
|
+
interface KeyPair {
|
|
93
|
+
curve: Curve;
|
|
94
|
+
privateKey: CryptoKey;
|
|
95
|
+
point: Bytes;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function keyPair(curve: Curve): Promise<KeyPair> {
|
|
99
|
+
const pair = (await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: curve }, true, [
|
|
100
|
+
"sign",
|
|
101
|
+
"verify",
|
|
102
|
+
])) as CryptoKeyPair;
|
|
103
|
+
const point = new Uint8Array((await crypto.subtle.exportKey("raw", pair.publicKey)) as ArrayBuffer);
|
|
104
|
+
return { curve, privateKey: pair.privateKey, point };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** An ECDSA signature, DER-encoded as X.509 and App Attest carry it. */
|
|
108
|
+
async function sign(key: KeyPair, hash: Hash, data: Bytes): Promise<Bytes> {
|
|
109
|
+
const raw = new Uint8Array(await crypto.subtle.sign({ name: "ECDSA", hash }, key.privateKey, data));
|
|
110
|
+
const size = FIELD[key.curve];
|
|
111
|
+
return seq(integer(raw.subarray(0, size)), integer(raw.subarray(size)));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface CertificateSpec {
|
|
115
|
+
serial: number;
|
|
116
|
+
issuer: string;
|
|
117
|
+
subject: string;
|
|
118
|
+
subjectKey: KeyPair;
|
|
119
|
+
signer: KeyPair;
|
|
120
|
+
hash: Hash;
|
|
121
|
+
notBefore: Date;
|
|
122
|
+
notAfter: Date;
|
|
123
|
+
ca: boolean;
|
|
124
|
+
extensions?: Bytes[];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function certificate(spec: CertificateSpec): Promise<Bytes> {
|
|
128
|
+
const algorithm = seq(oid(SIGNATURE_OID[spec.hash]));
|
|
129
|
+
const spki = seq(seq(oid("1.2.840.10045.2.1"), oid(CURVE_OID[spec.subjectKey.curve])), bits(spec.subjectKey.point));
|
|
130
|
+
const extensions = [
|
|
131
|
+
...(spec.ca
|
|
132
|
+
? [seq(oid("2.5.29.19"), tlv(0x01, new Uint8Array([0xff])), octets(seq(tlv(0x01, new Uint8Array([0xff])))))]
|
|
133
|
+
: []),
|
|
134
|
+
...(spec.extensions ?? []),
|
|
135
|
+
];
|
|
136
|
+
const tbs = seq(
|
|
137
|
+
tlv(0xa0, integer(new Uint8Array([2]))),
|
|
138
|
+
integer(new Uint8Array([spec.serial >> 8, spec.serial & 0xff])),
|
|
139
|
+
algorithm,
|
|
140
|
+
name(spec.issuer),
|
|
141
|
+
seq(time(spec.notBefore), time(spec.notAfter)),
|
|
142
|
+
name(spec.subject),
|
|
143
|
+
spki,
|
|
144
|
+
...(extensions.length > 0 ? [tlv(0xa3, seq(...extensions))] : []),
|
|
145
|
+
);
|
|
146
|
+
return seq(tbs, algorithm, bits(await sign(spec.signer, spec.hash, tbs)));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// CBOR writer.
|
|
150
|
+
|
|
151
|
+
type CborIn = number | string | Bytes | CborIn[] | Map<CborIn, CborIn>;
|
|
152
|
+
|
|
153
|
+
function cborHead(major: number, value: number): Bytes {
|
|
154
|
+
if (value < 24) return new Uint8Array([(major << 5) | value]);
|
|
155
|
+
if (value < 0x100) return new Uint8Array([(major << 5) | 24, value]);
|
|
156
|
+
if (value < 0x10000) return new Uint8Array([(major << 5) | 25, value >> 8, value & 0xff]);
|
|
157
|
+
return new Uint8Array([(major << 5) | 26, value >>> 24, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function cbor(value: CborIn): Bytes {
|
|
161
|
+
if (typeof value === "number") return value >= 0 ? cborHead(0, value) : cborHead(1, -1 - value);
|
|
162
|
+
if (typeof value === "string") {
|
|
163
|
+
const bytes = new TextEncoder().encode(value);
|
|
164
|
+
return concat(cborHead(3, bytes.length), bytes);
|
|
165
|
+
}
|
|
166
|
+
if (value instanceof Uint8Array) return concat(cborHead(2, value.length), value);
|
|
167
|
+
if (Array.isArray(value)) return concat(cborHead(4, value.length), ...value.map(cbor));
|
|
168
|
+
return concat(cborHead(5, value.size), ...[...value.entries()].flatMap(([k, v]) => [cbor(k), cbor(v)]));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function uint32(value: number): Bytes {
|
|
172
|
+
return new Uint8Array([value >>> 24, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const AAGUID = {
|
|
176
|
+
production: concat(new TextEncoder().encode("appattest"), new Uint8Array(7)),
|
|
177
|
+
development: new TextEncoder().encode("appattestdevelop"),
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** What to put in one attestation. Each override breaks the one field a refusal test is about. */
|
|
181
|
+
export interface AttestOptions {
|
|
182
|
+
/** `<TeamID>.<bundleId>`, hashed into the authenticator data's `rpIdHash`. */
|
|
183
|
+
appId: string;
|
|
184
|
+
/** What the app passed to `attestKey`. */
|
|
185
|
+
clientDataHash: Bytes;
|
|
186
|
+
environment?: "production" | "development";
|
|
187
|
+
/** The authenticator data's counter. Apple's is always 0. */
|
|
188
|
+
counter?: number;
|
|
189
|
+
/** A nonce to write into the leaf in place of the right one. */
|
|
190
|
+
nonce?: Bytes;
|
|
191
|
+
/** A credential id to write in place of the key id. */
|
|
192
|
+
credentialId?: Bytes;
|
|
193
|
+
/** Leaf validity, defaulting to an hour either side of the authority's `now`. */
|
|
194
|
+
notBefore?: Date;
|
|
195
|
+
notAfter?: Date;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** One attested key. */
|
|
199
|
+
export interface AttestedKey {
|
|
200
|
+
/** The key id as `generateKey` hands it over: standard base64 of SHA-256 over the public point. */
|
|
201
|
+
keyId: string;
|
|
202
|
+
/** The attestation object as `attestKey` hands it over: standard base64. */
|
|
203
|
+
attestation: string;
|
|
204
|
+
/** The raw public point. */
|
|
205
|
+
publicKey: Bytes;
|
|
206
|
+
/** An assertion over `clientDataHash`, as `generateAssertion` hands it over: standard base64. */
|
|
207
|
+
assert(options: { appId: string; clientDataHash: Bytes; counter: number }): Promise<string>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** A key generated in the fake Secure Enclave and not yet attested, as `generateKey` leaves it. */
|
|
211
|
+
export interface GeneratedKey {
|
|
212
|
+
/** The key id as `generateKey` hands it over: standard base64 of SHA-256 over the public point. */
|
|
213
|
+
keyId: string;
|
|
214
|
+
/** The raw public point. */
|
|
215
|
+
publicKey: Bytes;
|
|
216
|
+
/** Apple's attestation of this key, as `attestKey` hands it over: standard base64. */
|
|
217
|
+
attest(options: AttestOptions): Promise<string>;
|
|
218
|
+
/** An assertion over `clientDataHash`, as `generateAssertion` hands it over: standard base64. */
|
|
219
|
+
assert(options: { appId: string; clientDataHash: Bytes; counter: number }): Promise<string>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** A fake App Attest service. */
|
|
223
|
+
export interface AppAttestAuthority {
|
|
224
|
+
/** The root to trust in place of Apple's, DER. */
|
|
225
|
+
root: Bytes;
|
|
226
|
+
/** Generate a key and attest to it. */
|
|
227
|
+
attest(options: AttestOptions): Promise<AttestedKey>;
|
|
228
|
+
/** Generate a key, to attest later: the two steps a device takes, `generateKey` then `attestKey`. */
|
|
229
|
+
generate(): Promise<GeneratedKey>;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Stand up a fake App Attest service whose certificates are valid around `now`. */
|
|
233
|
+
export async function appAttestAuthority(options: { now?: Date } = {}): Promise<AppAttestAuthority> {
|
|
234
|
+
const now = options.now ?? new Date();
|
|
235
|
+
const hours = (n: number) => new Date(now.getTime() + n * 3_600_000);
|
|
236
|
+
const rootKey = await keyPair("P-384");
|
|
237
|
+
const intermediateKey = await keyPair("P-384");
|
|
238
|
+
const rootName = "Test App Attestation Root CA";
|
|
239
|
+
const intermediateName = "Test App Attestation CA 1";
|
|
240
|
+
const root = await certificate({
|
|
241
|
+
serial: 1,
|
|
242
|
+
issuer: rootName,
|
|
243
|
+
subject: rootName,
|
|
244
|
+
subjectKey: rootKey,
|
|
245
|
+
signer: rootKey,
|
|
246
|
+
hash: "SHA-384",
|
|
247
|
+
notBefore: hours(-24 * 365),
|
|
248
|
+
notAfter: hours(24 * 365 * 20),
|
|
249
|
+
ca: true,
|
|
250
|
+
});
|
|
251
|
+
const intermediate = await certificate({
|
|
252
|
+
serial: 2,
|
|
253
|
+
issuer: rootName,
|
|
254
|
+
subject: intermediateName,
|
|
255
|
+
subjectKey: intermediateKey,
|
|
256
|
+
signer: rootKey,
|
|
257
|
+
hash: "SHA-384",
|
|
258
|
+
notBefore: hours(-24 * 365),
|
|
259
|
+
notAfter: hours(24 * 365 * 10),
|
|
260
|
+
ca: true,
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
async function generate(): Promise<GeneratedKey> {
|
|
264
|
+
const key = await keyPair("P-256");
|
|
265
|
+
const keyId = await sha256(key.point);
|
|
266
|
+
return {
|
|
267
|
+
keyId: standardBase64(keyId),
|
|
268
|
+
publicKey: key.point,
|
|
269
|
+
async attest(spec) {
|
|
270
|
+
const authData = concat(
|
|
271
|
+
await sha256(new TextEncoder().encode(spec.appId)),
|
|
272
|
+
new Uint8Array([0x40]),
|
|
273
|
+
uint32(spec.counter ?? 0),
|
|
274
|
+
AAGUID[spec.environment ?? "production"],
|
|
275
|
+
new Uint8Array([0, (spec.credentialId ?? keyId).length]),
|
|
276
|
+
spec.credentialId ?? keyId,
|
|
277
|
+
cbor(
|
|
278
|
+
new Map<CborIn, CborIn>([
|
|
279
|
+
[1, 2],
|
|
280
|
+
[3, -7],
|
|
281
|
+
[-1, 1],
|
|
282
|
+
[-2, key.point.subarray(1, 33)],
|
|
283
|
+
[-3, key.point.subarray(33)],
|
|
284
|
+
]),
|
|
285
|
+
),
|
|
286
|
+
);
|
|
287
|
+
const nonce = spec.nonce ?? (await sha256(authData, spec.clientDataHash));
|
|
288
|
+
const leaf = await certificate({
|
|
289
|
+
serial: 3,
|
|
290
|
+
issuer: intermediateName,
|
|
291
|
+
subject: Array.from(keyId, (byte) => byte.toString(16).padStart(2, "0")).join(""),
|
|
292
|
+
subjectKey: key,
|
|
293
|
+
signer: intermediateKey,
|
|
294
|
+
hash: "SHA-256",
|
|
295
|
+
notBefore: spec.notBefore ?? hours(-1),
|
|
296
|
+
notAfter: spec.notAfter ?? hours(72),
|
|
297
|
+
ca: false,
|
|
298
|
+
extensions: [seq(oid("1.2.840.113635.100.8.2"), octets(seq(tlv(0xa1, octets(nonce)))))],
|
|
299
|
+
});
|
|
300
|
+
return standardBase64(
|
|
301
|
+
cbor(
|
|
302
|
+
new Map<CborIn, CborIn>([
|
|
303
|
+
["fmt", "apple-appattest"],
|
|
304
|
+
[
|
|
305
|
+
"attStmt",
|
|
306
|
+
new Map<CborIn, CborIn>([
|
|
307
|
+
["x5c", [leaf, intermediate]],
|
|
308
|
+
["receipt", new Uint8Array([1, 2, 3])],
|
|
309
|
+
]),
|
|
310
|
+
],
|
|
311
|
+
["authData", authData],
|
|
312
|
+
]),
|
|
313
|
+
),
|
|
314
|
+
);
|
|
315
|
+
},
|
|
316
|
+
async assert({ appId, clientDataHash, counter }) {
|
|
317
|
+
const authenticatorData = concat(
|
|
318
|
+
await sha256(new TextEncoder().encode(appId)),
|
|
319
|
+
new Uint8Array([0x40]),
|
|
320
|
+
uint32(counter),
|
|
321
|
+
);
|
|
322
|
+
const signature = await sign(key, "SHA-256", await sha256(authenticatorData, clientDataHash));
|
|
323
|
+
return standardBase64(
|
|
324
|
+
cbor(
|
|
325
|
+
new Map<CborIn, CborIn>([
|
|
326
|
+
["signature", signature],
|
|
327
|
+
["authenticatorData", authenticatorData],
|
|
328
|
+
]),
|
|
329
|
+
),
|
|
330
|
+
);
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
root,
|
|
337
|
+
generate,
|
|
338
|
+
async attest(spec) {
|
|
339
|
+
const key = await generate();
|
|
340
|
+
return { keyId: key.keyId, attestation: await key.attest(spec), publicKey: key.publicKey, assert: key.assert };
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** A key id as auth stores it: base64url of the 32 bytes. */
|
|
346
|
+
export function storedKeyId(keyId: string): string {
|
|
347
|
+
return base64UrlEncode(Uint8Array.from(atob(keyId), (char) => char.charCodeAt(0)));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** A fake device's `@expo/app-integrity`: the shape `appAttestAttester` takes, over `authority`'s keys. */
|
|
351
|
+
export interface AppAttestDeviceModule {
|
|
352
|
+
readonly isSupported: boolean;
|
|
353
|
+
generateKeyAsync(): Promise<string>;
|
|
354
|
+
attestKeyAsync(keyId: string, challenge: string): Promise<string>;
|
|
355
|
+
generateAssertionAsync(keyId: string, challenge: string): Promise<string>;
|
|
356
|
+
/** Forget every key, as a reinstall or a restore to a new phone does: asserting with one then throws. */
|
|
357
|
+
wipe(): void;
|
|
358
|
+
/** Each call in order, with the string it was handed. */
|
|
359
|
+
readonly calls: string[];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* `@expo/app-integrity`'s App Attest half on a fake device: the key lives in `authority`'s Secure Enclave stand-in,
|
|
364
|
+
* and each call hashes the string it is handed with SHA-256 over its UTF-8 into `clientDataHash`, as the native
|
|
365
|
+
* module does. Each key's counter rises by one per assertion, as the Secure Enclave's does.
|
|
366
|
+
*/
|
|
367
|
+
export function appAttestDeviceModule(authority: AppAttestAuthority, appId: string): AppAttestDeviceModule {
|
|
368
|
+
const keys = new Map<string, { key: GeneratedKey; counter: number }>();
|
|
369
|
+
const calls: string[] = [];
|
|
370
|
+
const hash = (text: string) => sha256(new TextEncoder().encode(text));
|
|
371
|
+
const find = (keyId: string) => {
|
|
372
|
+
const entry = keys.get(keyId);
|
|
373
|
+
if (entry === undefined) throw new Error("invalidKey");
|
|
374
|
+
return entry;
|
|
375
|
+
};
|
|
376
|
+
return {
|
|
377
|
+
isSupported: true,
|
|
378
|
+
calls,
|
|
379
|
+
async generateKeyAsync() {
|
|
380
|
+
const key = await authority.generate();
|
|
381
|
+
keys.set(key.keyId, { key, counter: 0 });
|
|
382
|
+
calls.push(`generateKeyAsync -> ${key.keyId}`);
|
|
383
|
+
return key.keyId;
|
|
384
|
+
},
|
|
385
|
+
async attestKeyAsync(keyId, challenge) {
|
|
386
|
+
calls.push(`attestKeyAsync ${keyId} ${challenge}`);
|
|
387
|
+
return find(keyId).key.attest({ appId, clientDataHash: await hash(challenge) });
|
|
388
|
+
},
|
|
389
|
+
async generateAssertionAsync(keyId, challenge) {
|
|
390
|
+
calls.push(`generateAssertionAsync ${keyId} ${challenge}`);
|
|
391
|
+
const entry = find(keyId);
|
|
392
|
+
entry.counter += 1;
|
|
393
|
+
return entry.key.assert({ appId, clientDataHash: await hash(challenge), counter: entry.counter });
|
|
394
|
+
},
|
|
395
|
+
wipe() {
|
|
396
|
+
keys.clear();
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The sample attestation Apple publishes in its Attestation Object Validation Guide
|
|
6
|
+
* (https://developer.apple.com/documentation/devicecheck/attestation-object-validation-guide): a real device's
|
|
7
|
+
* attestation, in Apple's production environment, chaining to Apple App Attestation Root CA.
|
|
8
|
+
*
|
|
9
|
+
* The app passed the challenge's own bytes to `attestKey` as its client data hash, which is why
|
|
10
|
+
* {@link APPLE_SAMPLE.clientDataHash} is the challenge text and not its digest. Its leaf certificate is valid from
|
|
11
|
+
* 2026-04-20T18:13:12Z to 2026-04-23T18:13:12Z, so it verifies only at a time inside that window.
|
|
12
|
+
*/
|
|
13
|
+
export const APPLE_SAMPLE = {
|
|
14
|
+
app: { teamId: "1234567890", bundleId: "com.example.myapp" },
|
|
15
|
+
keyId: "zgSY9YSD+7TaDXssY6WlOPVS1K3Lmk+pFhlcSWE+ZV0=",
|
|
16
|
+
clientDataHash: new TextEncoder().encode("example_server_challenge"),
|
|
17
|
+
at: new Date("2026-04-21T12:00:00.000Z"),
|
|
18
|
+
attestation:
|
|
19
|
+
"o2NmbXRvYXBwbGUtYXBwYXR0ZXN0Z2F0dFN0bXSiY3g1Y4JZBCEwggQdMIIDo6ADAgECAgYBnbE/C04wCgYIKoZIzj0EAwIwTzEjMCEGA1UEAwwaQXBwbGUgQXBwIEF0dGVzdGF0aW9uIENBIDExEzARBgNVBAoMCkFwcGxlIEluYy4xEzARBgNVBAgMCkNhbGlmb3JuaWEwHhcNMjYwNDIwMTgxMzEyWhcNMjYwNDIzMTgxMzEyWjCBkTFJMEcGA1UEAwxAY2UwNDk4ZjU4NDgzZmJiNGRhMGQ3YjJjNjNhNWE1MzhmNTUyZDRhZGNiOWE0ZmE5MTYxOTVjNDk2MTNlNjU1ZDEaMBgGA1UECwwRQUFBIENlcnRpZmljYXRpb24xEzARBg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