@solidnative-dev/cli 0.0.0-stage → 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +841 -2
- package/dist/android-apk-signing.d.ts +36 -0
- package/dist/android-apk-signing.d.ts.map +1 -0
- package/dist/android-apk-signing.js +292 -0
- package/dist/android-apk-signing.js.map +1 -0
- package/dist/android-bundle-signing.d.ts +34 -0
- package/dist/android-bundle-signing.d.ts.map +1 -0
- package/dist/android-bundle-signing.js +167 -0
- package/dist/android-bundle-signing.js.map +1 -0
- package/dist/android-causal-debug.d.ts +38 -0
- package/dist/android-causal-debug.d.ts.map +1 -0
- package/dist/android-causal-debug.js +239 -0
- package/dist/android-causal-debug.js.map +1 -0
- package/dist/android-device-proof.d.ts +58 -0
- package/dist/android-device-proof.d.ts.map +1 -0
- package/dist/android-device-proof.js +554 -0
- package/dist/android-device-proof.js.map +1 -0
- package/dist/android-logs.d.ts +50 -0
- package/dist/android-logs.d.ts.map +1 -0
- package/dist/android-logs.js +253 -0
- package/dist/android-logs.js.map +1 -0
- package/dist/android-release-signing.d.ts +12 -0
- package/dist/android-release-signing.d.ts.map +1 -0
- package/dist/android-release-signing.js +165 -0
- package/dist/android-release-signing.js.map +1 -0
- package/dist/android-run-lease.d.ts +15 -0
- package/dist/android-run-lease.d.ts.map +1 -0
- package/dist/android-run-lease.js +333 -0
- package/dist/android-run-lease.js.map +1 -0
- package/dist/android-run-preflight.d.ts +45 -0
- package/dist/android-run-preflight.d.ts.map +1 -0
- package/dist/android-run-preflight.js +183 -0
- package/dist/android-run-preflight.js.map +1 -0
- package/dist/android-signing-shared.d.ts +38 -0
- package/dist/android-signing-shared.d.ts.map +1 -0
- package/dist/android-signing-shared.js +210 -0
- package/dist/android-signing-shared.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +4530 -0
- package/dist/bin.js.map +1 -0
- package/dist/bundle-artifacts.d.ts +48 -0
- package/dist/bundle-artifacts.d.ts.map +1 -0
- package/dist/bundle-artifacts.js +427 -0
- package/dist/bundle-artifacts.js.map +1 -0
- package/dist/causal-debug-compare.d.ts +81 -0
- package/dist/causal-debug-compare.d.ts.map +1 -0
- package/dist/causal-debug-compare.js +238 -0
- package/dist/causal-debug-compare.js.map +1 -0
- package/dist/causal-debug-report.d.ts +33 -0
- package/dist/causal-debug-report.d.ts.map +1 -0
- package/dist/causal-debug-report.js +979 -0
- package/dist/causal-debug-report.js.map +1 -0
- package/dist/causal-debug-watch.d.ts +33 -0
- package/dist/causal-debug-watch.d.ts.map +1 -0
- package/dist/causal-debug-watch.js +92 -0
- package/dist/causal-debug-watch.js.map +1 -0
- package/dist/causal-debug.d.ts +131 -0
- package/dist/causal-debug.d.ts.map +1 -0
- package/dist/causal-debug.js +503 -0
- package/dist/causal-debug.js.map +1 -0
- package/dist/compatibility-catalog.d.ts +88 -0
- package/dist/compatibility-catalog.d.ts.map +1 -0
- package/dist/compatibility-catalog.js +344 -0
- package/dist/compatibility-catalog.js.map +1 -0
- package/dist/deep-link.d.ts +90 -0
- package/dist/deep-link.d.ts.map +1 -0
- package/dist/deep-link.js +346 -0
- package/dist/deep-link.js.map +1 -0
- package/dist/device-proof-signatures.d.ts +307 -0
- package/dist/device-proof-signatures.d.ts.map +1 -0
- package/dist/device-proof-signatures.js +1024 -0
- package/dist/device-proof-signatures.js.map +1 -0
- package/dist/fingerprint.d.ts +35 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +454 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/index.d.ts +388 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2996 -0
- package/dist/index.js.map +1 -0
- package/dist/ios-causal-debug.d.ts +39 -0
- package/dist/ios-causal-debug.d.ts.map +1 -0
- package/dist/ios-causal-debug.js +318 -0
- package/dist/ios-causal-debug.js.map +1 -0
- package/dist/ios-logs.d.ts +58 -0
- package/dist/ios-logs.d.ts.map +1 -0
- package/dist/ios-logs.js +269 -0
- package/dist/ios-logs.js.map +1 -0
- package/dist/ios-process.d.ts +69 -0
- package/dist/ios-process.d.ts.map +1 -0
- package/dist/ios-process.js +389 -0
- package/dist/ios-process.js.map +1 -0
- package/dist/ios-run-preflight.d.ts +35 -0
- package/dist/ios-run-preflight.d.ts.map +1 -0
- package/dist/ios-run-preflight.js +172 -0
- package/dist/ios-run-preflight.js.map +1 -0
- package/dist/live-causal-debug-report.d.ts +49 -0
- package/dist/live-causal-debug-report.d.ts.map +1 -0
- package/dist/live-causal-debug-report.js +123 -0
- package/dist/live-causal-debug-report.js.map +1 -0
- package/dist/local-symbolication.d.ts +35 -0
- package/dist/local-symbolication.d.ts.map +1 -0
- package/dist/local-symbolication.js +89 -0
- package/dist/local-symbolication.js.map +1 -0
- package/dist/native-archive.d.ts +15 -0
- package/dist/native-archive.d.ts.map +1 -0
- package/dist/native-archive.js +441 -0
- package/dist/native-archive.js.map +1 -0
- package/dist/native-test.d.ts +43 -0
- package/dist/native-test.d.ts.map +1 -0
- package/dist/native-test.js +209 -0
- package/dist/native-test.js.map +1 -0
- package/dist/package-add.d.ts +56 -0
- package/dist/package-add.d.ts.map +1 -0
- package/dist/package-add.js +764 -0
- package/dist/package-add.js.map +1 -0
- package/dist/react-native-upgrade.d.ts +96 -0
- package/dist/react-native-upgrade.d.ts.map +1 -0
- package/dist/react-native-upgrade.js +882 -0
- package/dist/react-native-upgrade.js.map +1 -0
- package/dist/release-device-correlation.d.ts +40 -0
- package/dist/release-device-correlation.d.ts.map +1 -0
- package/dist/release-device-correlation.js +113 -0
- package/dist/release-device-correlation.js.map +1 -0
- package/dist/release-signatures.d.ts +168 -0
- package/dist/release-signatures.d.ts.map +1 -0
- package/dist/release-signatures.js +677 -0
- package/dist/release-signatures.js.map +1 -0
- package/dist/release.d.ts +88 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +771 -0
- package/dist/release.js.map +1 -0
- package/dist/signature-utilities.d.ts +16 -0
- package/dist/signature-utilities.d.ts.map +1 -0
- package/dist/signature-utilities.js +114 -0
- package/dist/signature-utilities.js.map +1 -0
- package/dist/solid-diagnostics-correlation.d.ts +11 -0
- package/dist/solid-diagnostics-correlation.d.ts.map +1 -0
- package/dist/solid-diagnostics-correlation.js +78 -0
- package/dist/solid-diagnostics-correlation.js.map +1 -0
- package/dist/solid-diagnostics-debug.d.ts +15 -0
- package/dist/solid-diagnostics-debug.d.ts.map +1 -0
- package/dist/solid-diagnostics-debug.js +93 -0
- package/dist/solid-diagnostics-debug.js.map +1 -0
- package/dist/solid-diagnostics-inspection.d.ts +41 -0
- package/dist/solid-diagnostics-inspection.d.ts.map +1 -0
- package/dist/solid-diagnostics-inspection.js +196 -0
- package/dist/solid-diagnostics-inspection.js.map +1 -0
- package/dist/source-map.d.ts +36 -0
- package/dist/source-map.d.ts.map +1 -0
- package/dist/source-map.js +488 -0
- package/dist/source-map.js.map +1 -0
- package/dist/stack-symbolication.d.ts +56 -0
- package/dist/stack-symbolication.d.ts.map +1 -0
- package/dist/stack-symbolication.js +310 -0
- package/dist/stack-symbolication.js.map +1 -0
- package/dist/symbolication.d.ts +27 -0
- package/dist/symbolication.d.ts.map +1 -0
- package/dist/symbolication.js +75 -0
- package/dist/symbolication.js.map +1 -0
- package/dist/tree-debug.d.ts +53 -0
- package/dist/tree-debug.d.ts.map +1 -0
- package/dist/tree-debug.js +283 -0
- package/dist/tree-debug.js.map +1 -0
- package/dist/versions.d.ts +13 -0
- package/dist/versions.d.ts.map +1 -0
- package/dist/versions.js +14 -0
- package/dist/versions.js.map +1 -0
- package/package.json +46 -3
- package/templates/react-native-0.88/README.md +328 -0
- package/templates/react-native-0.88/android/CMakeLists.txt +27 -0
- package/templates/react-native-0.88/android/MainActivity.kt +123 -0
- package/templates/react-native-0.88/android/MainApplication.kt +43 -0
- package/templates/react-native-0.88/android/OnLoad.cpp +60 -0
- package/templates/react-native-0.88/index.js +1 -0
- package/templates/react-native-0.88/ios/AppDelegate.swift +190 -0
- package/templates/react-native-0.88/metro.config.js +16 -0
- package/templates/react-native-0.88/specs/NativeSolidNativeDebug.ts +16 -0
- package/templates/react-native-0.88/specs/NativeSolidNativePlatformAndroid.ts +14 -0
- package/templates/react-native-0.88/src/App.tsx +161 -0
- package/templates/react-native-0.88/src/main.tsx +88 -0
- package/templates/react-native-0.88/test/App.test.tsx +152 -0
|
@@ -0,0 +1,1024 @@
|
|
|
1
|
+
import { createHash, randomUUID, sign, verify, } from "node:crypto";
|
|
2
|
+
import { rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readDetachedEd25519Signature, readEd25519PrivateKey, readEd25519PublicKey, readStableRegularFile, publicEd25519KeyFromSpki, } from "./signature-utilities.js";
|
|
5
|
+
const MAX_PROOF_BYTES = 1024 * 1024;
|
|
6
|
+
const MAX_SIGNATURE_BYTES = 64 * 1024;
|
|
7
|
+
const MAX_SIGNING_REQUEST_BYTES = 64 * 1024;
|
|
8
|
+
const MAX_TRUST_POLICY_BYTES = 64 * 1024;
|
|
9
|
+
const MAX_TRUST_POLICY_KEYS = 32;
|
|
10
|
+
const MAX_SOURCE_POLICY_CHECKS = 64;
|
|
11
|
+
const MAX_APK_BYTES = 1024 * 1024 * 1024;
|
|
12
|
+
const MAX_BUNDLE_BYTES = 512 * 1024 * 1024;
|
|
13
|
+
const MAX_SOURCE_MAP_BYTES = 512 * 1024 * 1024;
|
|
14
|
+
const MAX_BINDING_BYTES = 16 * 1024 * 1024;
|
|
15
|
+
const MAX_INSTRUMENTATION_BYTES = 1024 * 1024;
|
|
16
|
+
const MAX_INSTRUMENTATION_SECONDS = 20 * 60;
|
|
17
|
+
const KEY_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/@-]{0,127}$/u;
|
|
18
|
+
const REVISION_PATTERN = /^[a-f0-9]{7,64}$/u;
|
|
19
|
+
const SHA256_PATTERN = /^[a-f0-9]{64}$/u;
|
|
20
|
+
const FINGERPRINT_PATTERN = /^sha256:[a-f0-9]{64}$/u;
|
|
21
|
+
const BASE64URL_SIGNATURE_PATTERN = /^[A-Za-z0-9_-]{86}$/u;
|
|
22
|
+
const INSTRUMENTATION_CLASS_PATTERN = /^(?:[A-Za-z_$][A-Za-z0-9_$]*\.)+[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
23
|
+
const INSTRUMENTATION_TEST_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]{0,127}$/u;
|
|
24
|
+
const SIGNATURE_CONTEXT = "solid-native.device-proof-signature.v0\0";
|
|
25
|
+
const ANDROID_SOURCE_POLICY = Object.freeze([
|
|
26
|
+
Object.freeze({
|
|
27
|
+
kind: "required-source",
|
|
28
|
+
matches: 1,
|
|
29
|
+
pattern: "app:///apps/native-e2e/adapters/NotifeeApiModule.ts",
|
|
30
|
+
}),
|
|
31
|
+
Object.freeze({
|
|
32
|
+
kind: "required-source",
|
|
33
|
+
matches: 1,
|
|
34
|
+
pattern: "app:///apps/native-e2e/generated/SolidNativeBindings.ts",
|
|
35
|
+
}),
|
|
36
|
+
Object.freeze({
|
|
37
|
+
kind: "required-source",
|
|
38
|
+
matches: 1,
|
|
39
|
+
pattern: "app:///packages/notifications/dist/notify-kit-10.js",
|
|
40
|
+
}),
|
|
41
|
+
Object.freeze({
|
|
42
|
+
kind: "forbidden-fragment",
|
|
43
|
+
matches: 0,
|
|
44
|
+
pattern: "/node_modules/react-native-notify-kit/",
|
|
45
|
+
}),
|
|
46
|
+
]);
|
|
47
|
+
function record(value, location) {
|
|
48
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
49
|
+
throw new TypeError(`${location} must be an object.`);
|
|
50
|
+
}
|
|
51
|
+
const prototype = Object.getPrototypeOf(value);
|
|
52
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
53
|
+
throw new TypeError(`${location} must be a plain object.`);
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
function exactKeys(value, expected, location) {
|
|
58
|
+
const actual = Object.keys(value).sort();
|
|
59
|
+
const sortedExpected = [...expected].sort();
|
|
60
|
+
if (actual.length !== sortedExpected.length ||
|
|
61
|
+
actual.some((key, index) => key !== sortedExpected[index])) {
|
|
62
|
+
throw new TypeError(`${location} has unexpected or missing fields.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function boundedString(value, location, maximumLength = 1024) {
|
|
66
|
+
if (typeof value !== "string" ||
|
|
67
|
+
value.length === 0 ||
|
|
68
|
+
value.length > maximumLength ||
|
|
69
|
+
/[\r\n\0]/u.test(value)) {
|
|
70
|
+
throw new TypeError(`${location} is invalid.`);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
function integer(value, location, minimum, maximum) {
|
|
75
|
+
if (typeof value !== "number" ||
|
|
76
|
+
!Number.isSafeInteger(value) ||
|
|
77
|
+
value < minimum ||
|
|
78
|
+
value > maximum) {
|
|
79
|
+
throw new TypeError(`${location} is invalid.`);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
function finiteNumber(value, location, minimum, maximum) {
|
|
84
|
+
if (typeof value !== "number" ||
|
|
85
|
+
!Number.isFinite(value) ||
|
|
86
|
+
value < minimum ||
|
|
87
|
+
value > maximum) {
|
|
88
|
+
throw new TypeError(`${location} is invalid.`);
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
function sha256(value, location) {
|
|
93
|
+
if (typeof value !== "string" || !SHA256_PATTERN.test(value)) {
|
|
94
|
+
throw new TypeError(`${location} is not a lowercase SHA-256 digest.`);
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
function sourceRevision(value, location) {
|
|
99
|
+
if (typeof value !== "string" || !REVISION_PATTERN.test(value)) {
|
|
100
|
+
throw new TypeError(`${location} is not a lowercase source revision.`);
|
|
101
|
+
}
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
function fingerprint(value, location) {
|
|
105
|
+
if (typeof value !== "string" || !FINGERPRINT_PATTERN.test(value)) {
|
|
106
|
+
throw new TypeError(`${location} is not a SHA-256 fingerprint.`);
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
function canonicalTimestamp(value, location) {
|
|
111
|
+
if (typeof value !== "string") {
|
|
112
|
+
throw new TypeError(`${location} is invalid.`);
|
|
113
|
+
}
|
|
114
|
+
let canonical;
|
|
115
|
+
try {
|
|
116
|
+
canonical = new Date(value).toISOString();
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
throw new TypeError(`${location} is invalid.`);
|
|
120
|
+
}
|
|
121
|
+
if (canonical !== value) {
|
|
122
|
+
throw new TypeError(`${location} must be canonical UTC.`);
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
function fileFact(value, location, maximumBytes) {
|
|
127
|
+
const source = record(value, location);
|
|
128
|
+
exactKeys(source, ["bytes", "sha256"], location);
|
|
129
|
+
return Object.freeze({
|
|
130
|
+
bytes: integer(source.bytes, `${location}.bytes`, 1, maximumBytes),
|
|
131
|
+
sha256: sha256(source.sha256, `${location}.sha256`),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function projectName(value, location) {
|
|
135
|
+
return boundedString(value, location, 214);
|
|
136
|
+
}
|
|
137
|
+
function keyId(value, location) {
|
|
138
|
+
if (typeof value !== "string" || !KEY_ID_PATTERN.test(value)) {
|
|
139
|
+
throw new TypeError(`${location} must be a static key identifier.`);
|
|
140
|
+
}
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
function parseNativeDeviceProofTrustPolicy(value) {
|
|
144
|
+
const policy = record(value, "Device proof trust policy");
|
|
145
|
+
const schemaVersion = policy.schemaVersion;
|
|
146
|
+
exactKeys(policy, schemaVersion === 1
|
|
147
|
+
? [
|
|
148
|
+
"keys",
|
|
149
|
+
"policySequence",
|
|
150
|
+
"profileFingerprint",
|
|
151
|
+
"projectName",
|
|
152
|
+
"proof",
|
|
153
|
+
"schemaVersion",
|
|
154
|
+
]
|
|
155
|
+
: ["keys", "policySequence", "projectName", "proof", "schemaVersion"], "Device proof trust policy");
|
|
156
|
+
if ((schemaVersion !== 0 && schemaVersion !== 1) ||
|
|
157
|
+
policy.proof !== "solid-native-android-release-device" ||
|
|
158
|
+
!Array.isArray(policy.keys) ||
|
|
159
|
+
policy.keys.length === 0 ||
|
|
160
|
+
policy.keys.length > MAX_TRUST_POLICY_KEYS) {
|
|
161
|
+
throw new TypeError("Device proof trust policy has an invalid schema.");
|
|
162
|
+
}
|
|
163
|
+
const parsedProjectName = projectName(policy.projectName, "Device proof trust policy project name");
|
|
164
|
+
const policySequence = integer(policy.policySequence, "Device proof trust policy sequence", 1, Number.MAX_SAFE_INTEGER);
|
|
165
|
+
const keyIds = new Set();
|
|
166
|
+
const publicKeys = new Set();
|
|
167
|
+
const keys = policy.keys
|
|
168
|
+
.map((value, index) => {
|
|
169
|
+
const entry = record(value, `Device proof trust policy key ${index}`);
|
|
170
|
+
exactKeys(entry, ["algorithm", "keyId", "publicKeySpki", "status"], `Device proof trust policy key ${index}`);
|
|
171
|
+
if (entry.algorithm !== "ed25519" ||
|
|
172
|
+
typeof entry.publicKeySpki !== "string" ||
|
|
173
|
+
(entry.status !== "active" && entry.status !== "revoked")) {
|
|
174
|
+
throw new TypeError(`Device proof trust policy key ${index} has an invalid schema.`);
|
|
175
|
+
}
|
|
176
|
+
const parsedKeyId = keyId(entry.keyId, `Device proof trust policy key ${index} ID`);
|
|
177
|
+
if (keyIds.has(parsedKeyId)) {
|
|
178
|
+
throw new TypeError(`Device proof trust policy key ID ${parsedKeyId} is duplicated.`);
|
|
179
|
+
}
|
|
180
|
+
keyIds.add(parsedKeyId);
|
|
181
|
+
publicEd25519KeyFromSpki(entry.publicKeySpki, `Device proof trust policy key ${parsedKeyId}`);
|
|
182
|
+
if (publicKeys.has(entry.publicKeySpki)) {
|
|
183
|
+
throw new TypeError(`Device proof trust policy key ${parsedKeyId} duplicates another public key.`);
|
|
184
|
+
}
|
|
185
|
+
publicKeys.add(entry.publicKeySpki);
|
|
186
|
+
return Object.freeze({
|
|
187
|
+
keyId: parsedKeyId,
|
|
188
|
+
algorithm: "ed25519",
|
|
189
|
+
publicKeySpki: entry.publicKeySpki,
|
|
190
|
+
status: entry.status,
|
|
191
|
+
});
|
|
192
|
+
})
|
|
193
|
+
.sort((left, right) => left.keyId < right.keyId ? -1 : left.keyId > right.keyId ? 1 : 0);
|
|
194
|
+
const common = {
|
|
195
|
+
policySequence,
|
|
196
|
+
projectName: parsedProjectName,
|
|
197
|
+
proof: "solid-native-android-release-device",
|
|
198
|
+
keys: Object.freeze(keys),
|
|
199
|
+
};
|
|
200
|
+
return schemaVersion === 0
|
|
201
|
+
? Object.freeze({ schemaVersion: 0, ...common })
|
|
202
|
+
: Object.freeze({
|
|
203
|
+
schemaVersion: 1,
|
|
204
|
+
...common,
|
|
205
|
+
profileFingerprint: fingerprint(policy.profileFingerprint, "Device proof trust policy profile fingerprint"),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function fingerprintParsedDeviceProofTrustPolicy(policy) {
|
|
209
|
+
return `sha256:${createHash("sha256")
|
|
210
|
+
.update(JSON.stringify(policy), "utf8")
|
|
211
|
+
.digest("hex")}`;
|
|
212
|
+
}
|
|
213
|
+
export function nativeDeviceProofTrustPolicyFingerprint(policy) {
|
|
214
|
+
return fingerprintParsedDeviceProofTrustPolicy(parseNativeDeviceProofTrustPolicy(policy));
|
|
215
|
+
}
|
|
216
|
+
export async function readNativeDeviceProofTrustPolicy(policyPath) {
|
|
217
|
+
if (typeof policyPath !== "string" || policyPath.length === 0) {
|
|
218
|
+
throw new TypeError("The device proof trust policy path must be a string.");
|
|
219
|
+
}
|
|
220
|
+
const file = await readStableRegularFile(path.resolve(policyPath), "Device proof trust policy", MAX_TRUST_POLICY_BYTES);
|
|
221
|
+
return parseNativeDeviceProofTrustPolicy(parseJson(file.bytes, "Device proof trust policy"));
|
|
222
|
+
}
|
|
223
|
+
export function parseNativeDeviceProofReceipt(value) {
|
|
224
|
+
const receipt = record(value, "Device proof receipt");
|
|
225
|
+
exactKeys(receipt, receipt.schemaVersion === 1
|
|
226
|
+
? [
|
|
227
|
+
"artifacts",
|
|
228
|
+
"bundle",
|
|
229
|
+
"device",
|
|
230
|
+
"generatedBindings",
|
|
231
|
+
"instrumentation",
|
|
232
|
+
"measuredAt",
|
|
233
|
+
"nativeCompatibility",
|
|
234
|
+
"proof",
|
|
235
|
+
"schemaVersion",
|
|
236
|
+
"source",
|
|
237
|
+
"sourceMap",
|
|
238
|
+
"status",
|
|
239
|
+
]
|
|
240
|
+
: [
|
|
241
|
+
"artifacts",
|
|
242
|
+
"bundle",
|
|
243
|
+
"device",
|
|
244
|
+
"generatedBindings",
|
|
245
|
+
"instrumentation",
|
|
246
|
+
"measuredAt",
|
|
247
|
+
"nativeCompatibility",
|
|
248
|
+
"proof",
|
|
249
|
+
"schemaVersion",
|
|
250
|
+
"source",
|
|
251
|
+
"status",
|
|
252
|
+
], "Device proof receipt");
|
|
253
|
+
if ((receipt.schemaVersion !== 0 && receipt.schemaVersion !== 1) ||
|
|
254
|
+
receipt.proof !== "solid-native-android-release-device" ||
|
|
255
|
+
receipt.status !== "passed") {
|
|
256
|
+
throw new TypeError("Device proof receipt identity is invalid.");
|
|
257
|
+
}
|
|
258
|
+
const measuredAt = canonicalTimestamp(receipt.measuredAt, "Device proof receipt measuredAt");
|
|
259
|
+
const source = record(receipt.source, "Device proof receipt source");
|
|
260
|
+
exactKeys(source, ["dirty", "revision"], "Device proof receipt source");
|
|
261
|
+
if (typeof source.revision !== "string" ||
|
|
262
|
+
!REVISION_PATTERN.test(source.revision) ||
|
|
263
|
+
typeof source.dirty !== "boolean") {
|
|
264
|
+
throw new TypeError("Device proof receipt source identity is invalid.");
|
|
265
|
+
}
|
|
266
|
+
const device = record(receipt.device, "Device proof receipt device");
|
|
267
|
+
exactKeys(device, [
|
|
268
|
+
"abi",
|
|
269
|
+
"batteryLevel",
|
|
270
|
+
"batteryTemperatureCelsius",
|
|
271
|
+
"buildFingerprintSha256",
|
|
272
|
+
"kind",
|
|
273
|
+
"lowPowerMode",
|
|
274
|
+
"manufacturer",
|
|
275
|
+
"model",
|
|
276
|
+
"osVersion",
|
|
277
|
+
"product",
|
|
278
|
+
"sdkLevel",
|
|
279
|
+
"serialSha256",
|
|
280
|
+
], "Device proof receipt device");
|
|
281
|
+
if (device.kind !== "physical" || typeof device.lowPowerMode !== "boolean") {
|
|
282
|
+
throw new TypeError("Device proof receipt did not identify physical hardware.");
|
|
283
|
+
}
|
|
284
|
+
const parsedDevice = Object.freeze({
|
|
285
|
+
kind: "physical",
|
|
286
|
+
serialSha256: fingerprint(device.serialSha256, "Device proof receipt serial identity"),
|
|
287
|
+
manufacturer: boundedString(device.manufacturer, "Device proof receipt manufacturer"),
|
|
288
|
+
model: boundedString(device.model, "Device proof receipt model"),
|
|
289
|
+
product: boundedString(device.product, "Device proof receipt product"),
|
|
290
|
+
abi: boundedString(device.abi, "Device proof receipt ABI"),
|
|
291
|
+
osVersion: boundedString(device.osVersion, "Device proof receipt OS version"),
|
|
292
|
+
sdkLevel: integer(device.sdkLevel, "Device proof receipt SDK level", 1, 999),
|
|
293
|
+
buildFingerprintSha256: fingerprint(device.buildFingerprintSha256, "Device proof receipt build identity"),
|
|
294
|
+
batteryLevel: integer(device.batteryLevel, "Device proof receipt battery level", 0, 100),
|
|
295
|
+
batteryTemperatureCelsius: finiteNumber(device.batteryTemperatureCelsius, "Device proof receipt battery temperature", -50, 150),
|
|
296
|
+
lowPowerMode: device.lowPowerMode,
|
|
297
|
+
});
|
|
298
|
+
const compatibility = record(receipt.nativeCompatibility, "Device proof receipt native compatibility");
|
|
299
|
+
exactKeys(compatibility, ["fingerprint", "inputCount"], "Device proof receipt native compatibility");
|
|
300
|
+
const parsedCompatibility = Object.freeze({
|
|
301
|
+
fingerprint: fingerprint(compatibility.fingerprint, "Device proof receipt native compatibility fingerprint"),
|
|
302
|
+
inputCount: integer(compatibility.inputCount, "Device proof receipt native compatibility input count", 1, 10_000),
|
|
303
|
+
});
|
|
304
|
+
const bindings = record(receipt.generatedBindings, "Device proof receipt generated bindings");
|
|
305
|
+
exactKeys(bindings, ["bytes", "fileSha256", "manifestSha256"], "Device proof receipt generated bindings");
|
|
306
|
+
const parsedBindings = Object.freeze({
|
|
307
|
+
bytes: integer(bindings.bytes, "Device proof receipt generated binding bytes", 1, MAX_BINDING_BYTES),
|
|
308
|
+
fileSha256: sha256(bindings.fileSha256, "Device proof receipt generated binding file digest"),
|
|
309
|
+
manifestSha256: sha256(bindings.manifestSha256, "Device proof receipt generated binding manifest digest"),
|
|
310
|
+
});
|
|
311
|
+
const sourceMap = record(receipt.schemaVersion === 0 ? receipt.bundle : receipt.sourceMap, "Device proof receipt source map");
|
|
312
|
+
exactKeys(sourceMap, ["bytes", "checks", "sha256", "sourceCount"], "Device proof receipt source map");
|
|
313
|
+
if (!Array.isArray(sourceMap.checks) ||
|
|
314
|
+
(receipt.schemaVersion === 0
|
|
315
|
+
? sourceMap.checks.length !== ANDROID_SOURCE_POLICY.length
|
|
316
|
+
: sourceMap.checks.length === 0 ||
|
|
317
|
+
sourceMap.checks.length > MAX_SOURCE_POLICY_CHECKS)) {
|
|
318
|
+
throw new TypeError("Device proof receipt source policy is invalid.");
|
|
319
|
+
}
|
|
320
|
+
const sourceCheckIdentities = new Set();
|
|
321
|
+
const checks = sourceMap.checks.map((value, index) => {
|
|
322
|
+
const check = record(value, `Device proof receipt source check ${index}`);
|
|
323
|
+
exactKeys(check, ["kind", "matches", "pattern"], `Device proof receipt source check ${index}`);
|
|
324
|
+
if (receipt.schemaVersion === 0) {
|
|
325
|
+
const expected = ANDROID_SOURCE_POLICY[index];
|
|
326
|
+
if (check.kind !== expected.kind ||
|
|
327
|
+
check.matches !== expected.matches ||
|
|
328
|
+
check.pattern !== expected.pattern) {
|
|
329
|
+
throw new TypeError("Device proof receipt source policy drifted.");
|
|
330
|
+
}
|
|
331
|
+
return expected;
|
|
332
|
+
}
|
|
333
|
+
if (check.kind !== "required-source" &&
|
|
334
|
+
check.kind !== "forbidden-fragment") {
|
|
335
|
+
throw new TypeError(`Device proof receipt source check ${index} has an invalid kind.`);
|
|
336
|
+
}
|
|
337
|
+
const pattern = boundedString(check.pattern, `Device proof receipt source check ${index} pattern`, 4_096);
|
|
338
|
+
if (/\p{Cc}/u.test(pattern)) {
|
|
339
|
+
throw new TypeError(`Device proof receipt source check ${index} pattern contains control characters.`);
|
|
340
|
+
}
|
|
341
|
+
const matches = integer(check.matches, `Device proof receipt source check ${index} matches`, 0, 1);
|
|
342
|
+
if ((check.kind === "required-source" &&
|
|
343
|
+
(matches !== 1 ||
|
|
344
|
+
!pattern.startsWith("app:///") ||
|
|
345
|
+
pattern.includes("\\") ||
|
|
346
|
+
pattern.split("/").includes(".."))) ||
|
|
347
|
+
(check.kind === "forbidden-fragment" && matches !== 0)) {
|
|
348
|
+
throw new TypeError(`Device proof receipt source check ${index} did not prove its policy.`);
|
|
349
|
+
}
|
|
350
|
+
const identity = `${check.kind}\0${pattern}`;
|
|
351
|
+
if (sourceCheckIdentities.has(identity)) {
|
|
352
|
+
throw new TypeError("Device proof receipt source policy is duplicated.");
|
|
353
|
+
}
|
|
354
|
+
sourceCheckIdentities.add(identity);
|
|
355
|
+
return Object.freeze({ kind: check.kind, matches, pattern });
|
|
356
|
+
});
|
|
357
|
+
if (receipt.schemaVersion === 1 &&
|
|
358
|
+
!checks.some((check) => check.kind === "required-source")) {
|
|
359
|
+
throw new TypeError("Portable device proof source policy must require at least one exact source.");
|
|
360
|
+
}
|
|
361
|
+
const parsedSourceMap = Object.freeze({
|
|
362
|
+
bytes: integer(sourceMap.bytes, "Device proof receipt source map bytes", 1, MAX_SOURCE_MAP_BYTES),
|
|
363
|
+
sha256: sha256(sourceMap.sha256, "Device proof receipt source map digest"),
|
|
364
|
+
sourceCount: integer(sourceMap.sourceCount, "Device proof receipt source count", 1, 100_000),
|
|
365
|
+
checks: Object.freeze(checks),
|
|
366
|
+
});
|
|
367
|
+
const parsedBundle = receipt.schemaVersion === 1
|
|
368
|
+
? fileFact(receipt.bundle, "Device proof receipt JavaScript bundle", MAX_BUNDLE_BYTES)
|
|
369
|
+
: undefined;
|
|
370
|
+
const artifacts = record(receipt.artifacts, "Device proof receipt artifacts");
|
|
371
|
+
exactKeys(artifacts, ["applicationApk", "instrumentationApk"], "Device proof receipt artifacts");
|
|
372
|
+
const parsedArtifacts = Object.freeze({
|
|
373
|
+
applicationApk: fileFact(artifacts.applicationApk, "Device proof receipt application APK", MAX_APK_BYTES),
|
|
374
|
+
instrumentationApk: fileFact(artifacts.instrumentationApk, "Device proof receipt instrumentation APK", MAX_APK_BYTES),
|
|
375
|
+
});
|
|
376
|
+
const instrumentation = record(receipt.instrumentation, "Device proof receipt instrumentation");
|
|
377
|
+
exactKeys(instrumentation, [
|
|
378
|
+
"className",
|
|
379
|
+
"durationSeconds",
|
|
380
|
+
"exitCodeSha256",
|
|
381
|
+
"reportedAt",
|
|
382
|
+
"resultBytes",
|
|
383
|
+
"resultSha256",
|
|
384
|
+
"testName",
|
|
385
|
+
], "Device proof receipt instrumentation");
|
|
386
|
+
if (receipt.schemaVersion === 0 &&
|
|
387
|
+
(instrumentation.className !==
|
|
388
|
+
"dev.solidnative.e2e.SolidNativePhysicalTest" ||
|
|
389
|
+
instrumentation.testName !== "testPhysicalRendererUpdate")) {
|
|
390
|
+
throw new TypeError("Device proof receipt test identity is invalid.");
|
|
391
|
+
}
|
|
392
|
+
const className = receipt.schemaVersion === 0
|
|
393
|
+
? "dev.solidnative.e2e.SolidNativePhysicalTest"
|
|
394
|
+
: boundedString(instrumentation.className, "Device proof receipt instrumentation class name", 255);
|
|
395
|
+
const testName = receipt.schemaVersion === 0
|
|
396
|
+
? "testPhysicalRendererUpdate"
|
|
397
|
+
: boundedString(instrumentation.testName, "Device proof receipt instrumentation test name", 128);
|
|
398
|
+
if (!INSTRUMENTATION_CLASS_PATTERN.test(className) ||
|
|
399
|
+
!INSTRUMENTATION_TEST_PATTERN.test(testName)) {
|
|
400
|
+
throw new TypeError("Device proof receipt test identity is invalid.");
|
|
401
|
+
}
|
|
402
|
+
const reportedAt = canonicalTimestamp(instrumentation.reportedAt, "Device proof receipt instrumentation reportedAt");
|
|
403
|
+
const parsedInstrumentation = Object.freeze({
|
|
404
|
+
className,
|
|
405
|
+
durationSeconds: finiteNumber(instrumentation.durationSeconds, "Device proof receipt instrumentation duration", Number.MIN_VALUE, MAX_INSTRUMENTATION_SECONDS),
|
|
406
|
+
reportedAt,
|
|
407
|
+
testName,
|
|
408
|
+
resultBytes: integer(instrumentation.resultBytes, "Device proof receipt instrumentation result bytes", 1, MAX_INSTRUMENTATION_BYTES),
|
|
409
|
+
resultSha256: sha256(instrumentation.resultSha256, "Device proof receipt instrumentation result digest"),
|
|
410
|
+
exitCodeSha256: sha256(instrumentation.exitCodeSha256, "Device proof receipt instrumentation exit-code digest"),
|
|
411
|
+
});
|
|
412
|
+
if (Date.parse(measuredAt) < Date.parse(reportedAt) ||
|
|
413
|
+
Date.parse(measuredAt) - Date.parse(reportedAt) > 60 * 60 * 1000) {
|
|
414
|
+
throw new TypeError("Device proof receipt timestamps are inconsistent.");
|
|
415
|
+
}
|
|
416
|
+
const common = {
|
|
417
|
+
proof: "solid-native-android-release-device",
|
|
418
|
+
status: "passed",
|
|
419
|
+
measuredAt,
|
|
420
|
+
source: Object.freeze({
|
|
421
|
+
revision: source.revision,
|
|
422
|
+
dirty: source.dirty,
|
|
423
|
+
}),
|
|
424
|
+
device: parsedDevice,
|
|
425
|
+
nativeCompatibility: parsedCompatibility,
|
|
426
|
+
generatedBindings: parsedBindings,
|
|
427
|
+
artifacts: parsedArtifacts,
|
|
428
|
+
instrumentation: parsedInstrumentation,
|
|
429
|
+
};
|
|
430
|
+
return receipt.schemaVersion === 0
|
|
431
|
+
? Object.freeze({
|
|
432
|
+
schemaVersion: 0,
|
|
433
|
+
...common,
|
|
434
|
+
bundle: parsedSourceMap,
|
|
435
|
+
})
|
|
436
|
+
: Object.freeze({
|
|
437
|
+
schemaVersion: 1,
|
|
438
|
+
...common,
|
|
439
|
+
bundle: parsedBundle,
|
|
440
|
+
sourceMap: parsedSourceMap,
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
function inspectParsedDeviceProofProfile(receipt) {
|
|
444
|
+
const sourceMap = receipt.schemaVersion === 0 ? receipt.bundle : receipt.sourceMap;
|
|
445
|
+
const sourcePolicy = Object.freeze([...sourceMap.checks].sort((left, right) => {
|
|
446
|
+
const leftIdentity = `${left.kind}\0${left.pattern}`;
|
|
447
|
+
const rightIdentity = `${right.kind}\0${right.pattern}`;
|
|
448
|
+
return leftIdentity < rightIdentity
|
|
449
|
+
? -1
|
|
450
|
+
: leftIdentity > rightIdentity
|
|
451
|
+
? 1
|
|
452
|
+
: 0;
|
|
453
|
+
}));
|
|
454
|
+
const instrumentation = Object.freeze({
|
|
455
|
+
className: receipt.instrumentation.className,
|
|
456
|
+
testName: receipt.instrumentation.testName,
|
|
457
|
+
});
|
|
458
|
+
const identity = {
|
|
459
|
+
schemaVersion: 0,
|
|
460
|
+
kind: "solid-native.android-device-proof-profile",
|
|
461
|
+
proof: receipt.proof,
|
|
462
|
+
instrumentation,
|
|
463
|
+
sourcePolicy,
|
|
464
|
+
};
|
|
465
|
+
return Object.freeze({
|
|
466
|
+
...identity,
|
|
467
|
+
receiptSchemaVersion: receipt.schemaVersion,
|
|
468
|
+
profileFingerprint: `sha256:${createHash("sha256")
|
|
469
|
+
.update(JSON.stringify(identity), "utf8")
|
|
470
|
+
.digest("hex")}`,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
function fingerprintParsedDeviceProofProfile(receipt) {
|
|
474
|
+
return inspectParsedDeviceProofProfile(receipt).profileFingerprint;
|
|
475
|
+
}
|
|
476
|
+
export function inspectNativeDeviceProofProfile(receipt) {
|
|
477
|
+
return inspectParsedDeviceProofProfile(parseNativeDeviceProofReceipt(receipt));
|
|
478
|
+
}
|
|
479
|
+
export function nativeDeviceProofProfileFingerprint(receipt) {
|
|
480
|
+
return inspectNativeDeviceProofProfile(receipt).profileFingerprint;
|
|
481
|
+
}
|
|
482
|
+
function parseJson(bytes, label) {
|
|
483
|
+
try {
|
|
484
|
+
return JSON.parse(bytes.toString("utf8"));
|
|
485
|
+
}
|
|
486
|
+
catch (error) {
|
|
487
|
+
throw new TypeError(`${label} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
async function readProofFile(proofPath) {
|
|
491
|
+
const file = await readStableRegularFile(proofPath, "Device proof receipt", MAX_PROOF_BYTES);
|
|
492
|
+
return Object.freeze({
|
|
493
|
+
bytes: file.bytes,
|
|
494
|
+
proofSha256: `sha256:${createHash("sha256").update(file.bytes).digest("hex")}`,
|
|
495
|
+
receipt: parseNativeDeviceProofReceipt(parseJson(file.bytes, "Device proof receipt")),
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
export async function readNativeDeviceProofReceipt(proofPath) {
|
|
499
|
+
if (typeof proofPath !== "string" || proofPath.length === 0) {
|
|
500
|
+
throw new TypeError("The device proof path must be a string.");
|
|
501
|
+
}
|
|
502
|
+
return (await readProofFile(path.resolve(proofPath))).receipt;
|
|
503
|
+
}
|
|
504
|
+
function signingStatement(signingKeyId, signingProjectName, proofSha256) {
|
|
505
|
+
return Object.freeze({
|
|
506
|
+
schemaVersion: 0,
|
|
507
|
+
algorithm: "ed25519",
|
|
508
|
+
keyId: keyId(signingKeyId, "The device-proof signing key ID"),
|
|
509
|
+
projectName: projectName(signingProjectName, "The device-proof project name"),
|
|
510
|
+
proofSha256,
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function signaturePayload(statement) {
|
|
514
|
+
return Buffer.from(`${SIGNATURE_CONTEXT}${JSON.stringify(statement)}`, "utf8");
|
|
515
|
+
}
|
|
516
|
+
function signingRequestForStatement(statement) {
|
|
517
|
+
const payload = signaturePayload(statement);
|
|
518
|
+
return Object.freeze({
|
|
519
|
+
...statement,
|
|
520
|
+
payloadBase64url: payload.toString("base64url"),
|
|
521
|
+
payloadSha256: createHash("sha256").update(payload).digest("hex"),
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
function parseNativeDeviceProofSigningRequest(value) {
|
|
525
|
+
const request = record(value, "Device proof signing request");
|
|
526
|
+
exactKeys(request, [
|
|
527
|
+
"algorithm",
|
|
528
|
+
"keyId",
|
|
529
|
+
"payloadBase64url",
|
|
530
|
+
"payloadSha256",
|
|
531
|
+
"projectName",
|
|
532
|
+
"proofSha256",
|
|
533
|
+
"schemaVersion",
|
|
534
|
+
], "Device proof signing request");
|
|
535
|
+
if (request.schemaVersion !== 0 ||
|
|
536
|
+
request.algorithm !== "ed25519" ||
|
|
537
|
+
typeof request.proofSha256 !== "string" ||
|
|
538
|
+
!FINGERPRINT_PATTERN.test(request.proofSha256) ||
|
|
539
|
+
typeof request.payloadBase64url !== "string" ||
|
|
540
|
+
typeof request.payloadSha256 !== "string" ||
|
|
541
|
+
!SHA256_PATTERN.test(request.payloadSha256)) {
|
|
542
|
+
throw new TypeError("Device proof signing request has an invalid schema.");
|
|
543
|
+
}
|
|
544
|
+
const expected = signingRequestForStatement(signingStatement(request.keyId, request.projectName, request.proofSha256));
|
|
545
|
+
if (request.payloadBase64url !== expected.payloadBase64url ||
|
|
546
|
+
request.payloadSha256 !== expected.payloadSha256) {
|
|
547
|
+
throw new TypeError("Device proof signing request payload does not match its statement.");
|
|
548
|
+
}
|
|
549
|
+
return expected;
|
|
550
|
+
}
|
|
551
|
+
export async function readNativeDeviceProofSigningRequest(requestPath) {
|
|
552
|
+
if (typeof requestPath !== "string" || requestPath.length === 0) {
|
|
553
|
+
throw new TypeError("The device proof signing request path must be a string.");
|
|
554
|
+
}
|
|
555
|
+
const file = await readStableRegularFile(path.resolve(requestPath), "Device proof signing request", MAX_SIGNING_REQUEST_BYTES);
|
|
556
|
+
return parseNativeDeviceProofSigningRequest(parseJson(file.bytes, "Device proof signing request"));
|
|
557
|
+
}
|
|
558
|
+
function parseNativeDeviceProofSignature(value) {
|
|
559
|
+
const signature = record(value, "Device proof signature");
|
|
560
|
+
exactKeys(signature, [
|
|
561
|
+
"algorithm",
|
|
562
|
+
"keyId",
|
|
563
|
+
"projectName",
|
|
564
|
+
"proofSha256",
|
|
565
|
+
"schemaVersion",
|
|
566
|
+
"signature",
|
|
567
|
+
], "Device proof signature");
|
|
568
|
+
if (signature.schemaVersion !== 0 ||
|
|
569
|
+
signature.algorithm !== "ed25519" ||
|
|
570
|
+
typeof signature.proofSha256 !== "string" ||
|
|
571
|
+
!FINGERPRINT_PATTERN.test(signature.proofSha256) ||
|
|
572
|
+
typeof signature.signature !== "string" ||
|
|
573
|
+
!BASE64URL_SIGNATURE_PATTERN.test(signature.signature)) {
|
|
574
|
+
throw new TypeError("Device proof signature has an invalid schema.");
|
|
575
|
+
}
|
|
576
|
+
const bytes = Buffer.from(signature.signature, "base64url");
|
|
577
|
+
if (bytes.length !== 64 ||
|
|
578
|
+
bytes.toString("base64url") !== signature.signature) {
|
|
579
|
+
throw new TypeError("Device proof signature is not canonical base64url.");
|
|
580
|
+
}
|
|
581
|
+
return Object.freeze({
|
|
582
|
+
...signingStatement(signature.keyId, signature.projectName, signature.proofSha256),
|
|
583
|
+
signature: signature.signature,
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
export async function readNativeDeviceProofSignature(signaturePath) {
|
|
587
|
+
if (typeof signaturePath !== "string" || signaturePath.length === 0) {
|
|
588
|
+
throw new TypeError("The device proof signature path must be a string.");
|
|
589
|
+
}
|
|
590
|
+
const file = await readStableRegularFile(path.resolve(signaturePath), "Device proof signature", MAX_SIGNATURE_BYTES);
|
|
591
|
+
return parseNativeDeviceProofSignature(parseJson(file.bytes, "Device proof signature"));
|
|
592
|
+
}
|
|
593
|
+
async function writeAtomicJson(outputPath, value, label) {
|
|
594
|
+
const parent = await stat(path.dirname(outputPath)).catch(() => undefined);
|
|
595
|
+
if (parent?.isDirectory() !== true) {
|
|
596
|
+
throw new TypeError(`${label} output directory does not exist.`);
|
|
597
|
+
}
|
|
598
|
+
const temporary = `${outputPath}.solid-native-${randomUUID()}.tmp`;
|
|
599
|
+
try {
|
|
600
|
+
await writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, {
|
|
601
|
+
flag: "wx",
|
|
602
|
+
mode: 0o644,
|
|
603
|
+
});
|
|
604
|
+
await rename(temporary, outputPath);
|
|
605
|
+
}
|
|
606
|
+
finally {
|
|
607
|
+
await rm(temporary, { force: true });
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
export async function createNativeDeviceProofSigningRequest(options) {
|
|
611
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
612
|
+
const proofPath = path.resolve(cwd, options.proofPath);
|
|
613
|
+
const requestPath = path.resolve(cwd, options.outputPath ?? `${proofPath}.signing-request.json`);
|
|
614
|
+
if (requestPath === proofPath) {
|
|
615
|
+
throw new TypeError("The device proof signing request must not overwrite the receipt.");
|
|
616
|
+
}
|
|
617
|
+
const proof = await readProofFile(proofPath);
|
|
618
|
+
if (proof.receipt.source.dirty) {
|
|
619
|
+
throw new TypeError("Refusing to prepare a signing request for a dirty-checkout device proof.");
|
|
620
|
+
}
|
|
621
|
+
const request = signingRequestForStatement(signingStatement(options.keyId, options.projectName, proof.proofSha256));
|
|
622
|
+
const finalProof = await readProofFile(proofPath);
|
|
623
|
+
if (finalProof.proofSha256 !== proof.proofSha256 ||
|
|
624
|
+
!finalProof.bytes.equals(proof.bytes)) {
|
|
625
|
+
throw new TypeError("The device proof changed while preparing its signing request.");
|
|
626
|
+
}
|
|
627
|
+
await writeAtomicJson(requestPath, request, "Device proof signing request");
|
|
628
|
+
return Object.freeze({
|
|
629
|
+
proofPath,
|
|
630
|
+
requestPath,
|
|
631
|
+
request,
|
|
632
|
+
receipt: proof.receipt,
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
export async function createNativeDeviceProofSignature(options) {
|
|
636
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
637
|
+
const proofPath = path.resolve(cwd, options.proofPath);
|
|
638
|
+
const privateKeyPath = path.resolve(cwd, options.privateKeyPath);
|
|
639
|
+
const signaturePath = path.resolve(cwd, options.outputPath ?? `${proofPath}.sig.json`);
|
|
640
|
+
if (signaturePath === proofPath || signaturePath === privateKeyPath) {
|
|
641
|
+
throw new TypeError("The device proof signature must not overwrite a signing input.");
|
|
642
|
+
}
|
|
643
|
+
const proof = await readProofFile(proofPath);
|
|
644
|
+
if (proof.receipt.source.dirty) {
|
|
645
|
+
throw new TypeError("Refusing to sign a dirty-checkout device proof.");
|
|
646
|
+
}
|
|
647
|
+
const statement = signingStatement(options.keyId, options.projectName, proof.proofSha256);
|
|
648
|
+
const privateKey = await readEd25519PrivateKey(privateKeyPath);
|
|
649
|
+
const signature = Object.freeze({
|
|
650
|
+
...statement,
|
|
651
|
+
signature: sign(null, signaturePayload(statement), privateKey).toString("base64url"),
|
|
652
|
+
});
|
|
653
|
+
const finalProof = await readProofFile(proofPath);
|
|
654
|
+
if (finalProof.proofSha256 !== proof.proofSha256 ||
|
|
655
|
+
!finalProof.bytes.equals(proof.bytes)) {
|
|
656
|
+
throw new TypeError("The device proof changed while being signed.");
|
|
657
|
+
}
|
|
658
|
+
await writeAtomicJson(signaturePath, signature, "Device proof signature");
|
|
659
|
+
return Object.freeze({
|
|
660
|
+
proofPath,
|
|
661
|
+
signaturePath,
|
|
662
|
+
signature,
|
|
663
|
+
receipt: proof.receipt,
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
export async function assembleNativeDeviceProofSignature(options) {
|
|
667
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
668
|
+
const requestPath = path.resolve(cwd, options.requestPath);
|
|
669
|
+
const detachedSignaturePath = path.resolve(cwd, options.detachedSignaturePath);
|
|
670
|
+
const publicKeyPath = path.resolve(cwd, options.publicKeyPath);
|
|
671
|
+
const signaturePath = path.resolve(cwd, options.outputPath ?? `${requestPath}.sig.json`);
|
|
672
|
+
if (signaturePath === requestPath ||
|
|
673
|
+
signaturePath === detachedSignaturePath ||
|
|
674
|
+
signaturePath === publicKeyPath) {
|
|
675
|
+
throw new TypeError("The assembled device proof signature must not overwrite an assembly input.");
|
|
676
|
+
}
|
|
677
|
+
const [request, detachedSignature, publicKey] = await Promise.all([
|
|
678
|
+
readNativeDeviceProofSigningRequest(requestPath),
|
|
679
|
+
readDetachedEd25519Signature(detachedSignaturePath),
|
|
680
|
+
readEd25519PublicKey(publicKeyPath),
|
|
681
|
+
]);
|
|
682
|
+
const statement = signingStatement(request.keyId, request.projectName, request.proofSha256);
|
|
683
|
+
if (!verify(null, signaturePayload(statement), publicKey, detachedSignature.bytes)) {
|
|
684
|
+
throw new TypeError("The detached Ed25519 signature does not authenticate the device proof signing request with the supplied public key.");
|
|
685
|
+
}
|
|
686
|
+
const signature = parseNativeDeviceProofSignature({
|
|
687
|
+
...statement,
|
|
688
|
+
signature: detachedSignature.base64url,
|
|
689
|
+
});
|
|
690
|
+
const finalRequest = await readNativeDeviceProofSigningRequest(requestPath);
|
|
691
|
+
if (JSON.stringify(finalRequest) !== JSON.stringify(request)) {
|
|
692
|
+
throw new TypeError("The device proof signing request changed while assembling its signature.");
|
|
693
|
+
}
|
|
694
|
+
await writeAtomicJson(signaturePath, signature, "Assembled device proof signature");
|
|
695
|
+
return Object.freeze({ requestPath, signaturePath, signature });
|
|
696
|
+
}
|
|
697
|
+
function check(id, pass, success, failure) {
|
|
698
|
+
return Object.freeze({
|
|
699
|
+
id,
|
|
700
|
+
status: pass ? "pass" : "fail",
|
|
701
|
+
message: pass ? success : failure,
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
export async function verifyNativeDeviceProofSignature(options) {
|
|
705
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
706
|
+
const proofPath = path.resolve(cwd, options.proofPath);
|
|
707
|
+
const signaturePath = path.resolve(cwd, options.signaturePath);
|
|
708
|
+
const unchecked = options;
|
|
709
|
+
if (unchecked.minimumTrustPolicySequence !== undefined &&
|
|
710
|
+
(typeof unchecked.minimumTrustPolicySequence !== "number" ||
|
|
711
|
+
!Number.isSafeInteger(unchecked.minimumTrustPolicySequence) ||
|
|
712
|
+
unchecked.minimumTrustPolicySequence <= 0)) {
|
|
713
|
+
throw new TypeError("The minimum device-proof trust policy sequence must be a positive safe integer.");
|
|
714
|
+
}
|
|
715
|
+
if (unchecked.trustPolicyPath !== undefined &&
|
|
716
|
+
typeof unchecked.trustPolicyPath !== "string") {
|
|
717
|
+
throw new TypeError("The device proof trust policy path must be a string.");
|
|
718
|
+
}
|
|
719
|
+
const pinnedTrustSupplied = unchecked.expectedKeyId !== undefined ||
|
|
720
|
+
unchecked.projectName !== undefined ||
|
|
721
|
+
unchecked.publicKeyPath !== undefined;
|
|
722
|
+
if (unchecked.trustPolicyPath !== undefined && pinnedTrustSupplied) {
|
|
723
|
+
throw new TypeError("Device proof verification cannot combine a trust policy with pinned-key options.");
|
|
724
|
+
}
|
|
725
|
+
if (unchecked.trustPolicyPath === undefined &&
|
|
726
|
+
unchecked.minimumTrustPolicySequence !== undefined) {
|
|
727
|
+
throw new TypeError("A minimum device-proof trust policy sequence requires a trust policy file.");
|
|
728
|
+
}
|
|
729
|
+
if (unchecked.trustPolicyPath === undefined &&
|
|
730
|
+
(unchecked.expectedKeyId === undefined ||
|
|
731
|
+
unchecked.projectName === undefined ||
|
|
732
|
+
typeof unchecked.publicKeyPath !== "string")) {
|
|
733
|
+
throw new TypeError("Device proof verification requires a trust policy or complete pinned-key options.");
|
|
734
|
+
}
|
|
735
|
+
const expectedProofSha256 = options.expectedProofSha256 === undefined
|
|
736
|
+
? undefined
|
|
737
|
+
: fingerprint(options.expectedProofSha256, "The expected device-proof receipt fingerprint");
|
|
738
|
+
const expectedSourceRevision = options.expectedSourceRevision === undefined
|
|
739
|
+
? undefined
|
|
740
|
+
: sourceRevision(options.expectedSourceRevision, "The expected device-proof source revision");
|
|
741
|
+
const expectedNativeCompatibilityFingerprint = options.expectedNativeCompatibilityFingerprint === undefined
|
|
742
|
+
? undefined
|
|
743
|
+
: fingerprint(options.expectedNativeCompatibilityFingerprint, "The expected device-proof native compatibility fingerprint");
|
|
744
|
+
const expectedApplicationArtifactSha256 = options.expectedApplicationArtifactSha256 === undefined
|
|
745
|
+
? undefined
|
|
746
|
+
: sha256(options.expectedApplicationArtifactSha256, "The expected device-proof application artifact digest");
|
|
747
|
+
let expectedProfileFingerprint = options.expectedProfileFingerprint === undefined
|
|
748
|
+
? undefined
|
|
749
|
+
: fingerprint(options.expectedProfileFingerprint, "The expected device-proof verification profile fingerprint");
|
|
750
|
+
const minimumMeasuredAt = options.minimumMeasuredAt === undefined
|
|
751
|
+
? undefined
|
|
752
|
+
: canonicalTimestamp(options.minimumMeasuredAt, "The minimum device-proof measurement time");
|
|
753
|
+
const maximumMeasuredAt = options.maximumMeasuredAt === undefined
|
|
754
|
+
? undefined
|
|
755
|
+
: canonicalTimestamp(options.maximumMeasuredAt, "The maximum device-proof measurement time");
|
|
756
|
+
if (minimumMeasuredAt !== undefined &&
|
|
757
|
+
maximumMeasuredAt !== undefined &&
|
|
758
|
+
Date.parse(minimumMeasuredAt) > Date.parse(maximumMeasuredAt)) {
|
|
759
|
+
throw new TypeError("The minimum device-proof measurement time must not be after the maximum.");
|
|
760
|
+
}
|
|
761
|
+
const [proof, signature] = await Promise.all([
|
|
762
|
+
readProofFile(proofPath),
|
|
763
|
+
readNativeDeviceProofSignature(signaturePath),
|
|
764
|
+
]);
|
|
765
|
+
let expectedProjectName;
|
|
766
|
+
let publicKey;
|
|
767
|
+
let keyAuthorized;
|
|
768
|
+
let keySuccess;
|
|
769
|
+
let keyFailure;
|
|
770
|
+
let trustPolicyAccepted = true;
|
|
771
|
+
let trustPolicyPath;
|
|
772
|
+
let trustPolicyFingerprint;
|
|
773
|
+
let trustPolicySequence;
|
|
774
|
+
if (unchecked.trustPolicyPath !== undefined) {
|
|
775
|
+
trustPolicyPath = path.resolve(cwd, unchecked.trustPolicyPath);
|
|
776
|
+
const trustPolicy = await readNativeDeviceProofTrustPolicy(trustPolicyPath);
|
|
777
|
+
expectedProjectName = trustPolicy.projectName;
|
|
778
|
+
trustPolicySequence = trustPolicy.policySequence;
|
|
779
|
+
trustPolicyFingerprint =
|
|
780
|
+
fingerprintParsedDeviceProofTrustPolicy(trustPolicy);
|
|
781
|
+
if (trustPolicy.schemaVersion === 1) {
|
|
782
|
+
if (expectedProfileFingerprint !== undefined &&
|
|
783
|
+
expectedProfileFingerprint !== trustPolicy.profileFingerprint) {
|
|
784
|
+
throw new TypeError("The explicit device-proof profile conflicts with the trust policy.");
|
|
785
|
+
}
|
|
786
|
+
expectedProfileFingerprint = trustPolicy.profileFingerprint;
|
|
787
|
+
}
|
|
788
|
+
trustPolicyAccepted =
|
|
789
|
+
unchecked.minimumTrustPolicySequence === undefined ||
|
|
790
|
+
trustPolicy.policySequence >= unchecked.minimumTrustPolicySequence;
|
|
791
|
+
const trustedKey = trustPolicy.keys.find((entry) => entry.keyId === signature.keyId);
|
|
792
|
+
publicKey =
|
|
793
|
+
trustedKey === undefined
|
|
794
|
+
? undefined
|
|
795
|
+
: publicEd25519KeyFromSpki(trustedKey.publicKeySpki, `Device proof trust policy key ${trustedKey.keyId}`);
|
|
796
|
+
keyAuthorized = trustedKey?.status === "active";
|
|
797
|
+
keySuccess =
|
|
798
|
+
"The authenticated key is active in the device proof trust policy.";
|
|
799
|
+
keyFailure =
|
|
800
|
+
trustedKey?.status === "revoked"
|
|
801
|
+
? "The authenticated key is revoked by the device proof trust policy."
|
|
802
|
+
: "The authenticated key is absent from the device proof trust policy.";
|
|
803
|
+
}
|
|
804
|
+
else {
|
|
805
|
+
const expectedKeyId = keyId(unchecked.expectedKeyId, "The expected device-proof key ID");
|
|
806
|
+
expectedProjectName = projectName(unchecked.projectName, "The expected device-proof project name");
|
|
807
|
+
publicKey = await readEd25519PublicKey(path.resolve(cwd, unchecked.publicKeyPath));
|
|
808
|
+
keyAuthorized = signature.keyId === expectedKeyId;
|
|
809
|
+
keySuccess = "The authenticated key ID matches the pinned identity.";
|
|
810
|
+
keyFailure = "The authenticated key ID does not match the pinned identity.";
|
|
811
|
+
}
|
|
812
|
+
const statement = signingStatement(signature.keyId, signature.projectName, signature.proofSha256);
|
|
813
|
+
const clean = !proof.receipt.source.dirty;
|
|
814
|
+
const profileFingerprint = fingerprintParsedDeviceProofProfile(proof.receipt);
|
|
815
|
+
const profileMatches = expectedProfileFingerprint === undefined
|
|
816
|
+
? proof.receipt.schemaVersion === 0
|
|
817
|
+
: profileFingerprint === expectedProfileFingerprint;
|
|
818
|
+
const projectMatches = signature.projectName === expectedProjectName;
|
|
819
|
+
const digestMatches = signature.proofSha256 === proof.proofSha256;
|
|
820
|
+
const lineageMismatch = expectedProofSha256 !== undefined &&
|
|
821
|
+
proof.proofSha256 !== expectedProofSha256
|
|
822
|
+
? "The authenticated receipt digest does not match the required fingerprint."
|
|
823
|
+
: expectedSourceRevision !== undefined &&
|
|
824
|
+
proof.receipt.source.revision !== expectedSourceRevision
|
|
825
|
+
? "The authenticated source revision does not match the required revision."
|
|
826
|
+
: expectedNativeCompatibilityFingerprint !== undefined &&
|
|
827
|
+
proof.receipt.nativeCompatibility.fingerprint !==
|
|
828
|
+
expectedNativeCompatibilityFingerprint
|
|
829
|
+
? "The authenticated native compatibility identity does not match the required fingerprint."
|
|
830
|
+
: expectedApplicationArtifactSha256 !== undefined &&
|
|
831
|
+
proof.receipt.artifacts.applicationApk.sha256 !==
|
|
832
|
+
expectedApplicationArtifactSha256
|
|
833
|
+
? "The authenticated application APK does not match the required digest."
|
|
834
|
+
: undefined;
|
|
835
|
+
const lineageConstrained = expectedProofSha256 !== undefined ||
|
|
836
|
+
expectedSourceRevision !== undefined ||
|
|
837
|
+
expectedNativeCompatibilityFingerprint !== undefined ||
|
|
838
|
+
expectedApplicationArtifactSha256 !== undefined;
|
|
839
|
+
const measuredAtMilliseconds = Date.parse(proof.receipt.measuredAt);
|
|
840
|
+
const timeConstrained = minimumMeasuredAt !== undefined || maximumMeasuredAt !== undefined;
|
|
841
|
+
const timePolicyMatches = (minimumMeasuredAt === undefined ||
|
|
842
|
+
measuredAtMilliseconds >= Date.parse(minimumMeasuredAt)) &&
|
|
843
|
+
(maximumMeasuredAt === undefined ||
|
|
844
|
+
measuredAtMilliseconds <= Date.parse(maximumMeasuredAt));
|
|
845
|
+
const authentic = publicKey !== undefined &&
|
|
846
|
+
verify(null, signaturePayload(statement), publicKey, Buffer.from(signature.signature, "base64url"));
|
|
847
|
+
const checks = Object.freeze([
|
|
848
|
+
check("proof", clean, "The strict device proof records a clean physical run.", "The device proof was produced from a dirty checkout."),
|
|
849
|
+
check("trust-policy", trustPolicyAccepted, trustPolicySequence === undefined
|
|
850
|
+
? "Device proof verification uses explicit pinned-key trust."
|
|
851
|
+
: "The device proof trust policy sequence satisfies the minimum.", "The device proof trust policy sequence is older than the required minimum."),
|
|
852
|
+
check("key", keyAuthorized, keySuccess, keyFailure),
|
|
853
|
+
check("signature", digestMatches && authentic, "The Ed25519 signature authenticates the exact device-proof bytes.", digestMatches
|
|
854
|
+
? "The Ed25519 signature is invalid for the supplied public key."
|
|
855
|
+
: "The signed device-proof digest does not match the supplied receipt."),
|
|
856
|
+
check("policy", projectMatches, "The signed project identity matches the trusted policy input.", "The signed project identity does not match the trusted policy input."),
|
|
857
|
+
check("profile", profileMatches, expectedProfileFingerprint === undefined
|
|
858
|
+
? "The receipt uses the fixed legacy device-proof verification profile."
|
|
859
|
+
: "The receipt instrumentation and source policy match the trusted verification profile.", expectedProfileFingerprint === undefined
|
|
860
|
+
? "Portable device-proof receipts require an explicitly trusted verification profile."
|
|
861
|
+
: "The receipt instrumentation or source policy does not match the trusted verification profile."),
|
|
862
|
+
check("lineage", lineageMismatch === undefined, lineageConstrained
|
|
863
|
+
? "The authenticated device proof matches every supplied lineage constraint."
|
|
864
|
+
: "No exact device-proof lineage constraints were supplied.", lineageMismatch ?? "The authenticated device proof lineage is invalid."),
|
|
865
|
+
check("time-policy", timePolicyMatches, timeConstrained
|
|
866
|
+
? "The signed device measurement satisfies the supplied time window."
|
|
867
|
+
: "No device-proof measurement time window was supplied.", "The signed device measurement is outside the required time window."),
|
|
868
|
+
]);
|
|
869
|
+
const ok = checks.every((entry) => entry.status === "pass");
|
|
870
|
+
const policy = Object.freeze({
|
|
871
|
+
projectName: expectedProjectName,
|
|
872
|
+
...(expectedProofSha256 === undefined ? {} : { expectedProofSha256 }),
|
|
873
|
+
...(expectedSourceRevision === undefined ? {} : { expectedSourceRevision }),
|
|
874
|
+
...(expectedNativeCompatibilityFingerprint === undefined
|
|
875
|
+
? {}
|
|
876
|
+
: { expectedNativeCompatibilityFingerprint }),
|
|
877
|
+
...(expectedApplicationArtifactSha256 === undefined
|
|
878
|
+
? {}
|
|
879
|
+
: { expectedApplicationArtifactSha256 }),
|
|
880
|
+
...(expectedProfileFingerprint === undefined
|
|
881
|
+
? {}
|
|
882
|
+
: { expectedProfileFingerprint }),
|
|
883
|
+
...(minimumMeasuredAt === undefined ? {} : { minimumMeasuredAt }),
|
|
884
|
+
...(maximumMeasuredAt === undefined ? {} : { maximumMeasuredAt }),
|
|
885
|
+
});
|
|
886
|
+
const report = {
|
|
887
|
+
schemaVersion: 0,
|
|
888
|
+
proofPath,
|
|
889
|
+
signaturePath,
|
|
890
|
+
proofSha256: proof.proofSha256,
|
|
891
|
+
keyId: signature.keyId,
|
|
892
|
+
projectName: expectedProjectName,
|
|
893
|
+
policy,
|
|
894
|
+
...(trustPolicyPath === undefined ? {} : { trustPolicyPath }),
|
|
895
|
+
...(trustPolicyFingerprint === undefined ? {} : { trustPolicyFingerprint }),
|
|
896
|
+
...(trustPolicySequence === undefined ? {} : { trustPolicySequence }),
|
|
897
|
+
checks,
|
|
898
|
+
};
|
|
899
|
+
if (!ok)
|
|
900
|
+
return Object.freeze({ ...report, ok: false });
|
|
901
|
+
return Object.freeze({
|
|
902
|
+
...report,
|
|
903
|
+
ok: true,
|
|
904
|
+
authenticatedProof: Object.freeze({
|
|
905
|
+
schemaVersion: 0,
|
|
906
|
+
projectName: expectedProjectName,
|
|
907
|
+
proof: proof.receipt.proof,
|
|
908
|
+
proofSha256: proof.proofSha256,
|
|
909
|
+
receiptSchemaVersion: proof.receipt.schemaVersion,
|
|
910
|
+
profileFingerprint,
|
|
911
|
+
sourceRevision: proof.receipt.source.revision,
|
|
912
|
+
measuredAt: proof.receipt.measuredAt,
|
|
913
|
+
nativeCompatibilityFingerprint: proof.receipt.nativeCompatibility.fingerprint,
|
|
914
|
+
applicationArtifactSha256: proof.receipt.artifacts.applicationApk.sha256,
|
|
915
|
+
deviceModel: proof.receipt.device.model,
|
|
916
|
+
authenticatedKeyId: signature.keyId,
|
|
917
|
+
...(trustPolicyFingerprint === undefined
|
|
918
|
+
? {}
|
|
919
|
+
: { trustPolicyFingerprint }),
|
|
920
|
+
...(trustPolicySequence === undefined ? {} : { trustPolicySequence }),
|
|
921
|
+
}),
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Repeats device-proof authentication and returns a path-free, uploader-neutral
|
|
926
|
+
* descriptor derived only from the exact receipt snapshot that stayed present
|
|
927
|
+
* after verification. The result is execution evidence, never release
|
|
928
|
+
* authorization.
|
|
929
|
+
*/
|
|
930
|
+
export async function createNativeDeviceProofIngestion(options) {
|
|
931
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
932
|
+
const proofPath = path.resolve(cwd, options.proofPath);
|
|
933
|
+
const verification = await verifyNativeDeviceProofSignature({
|
|
934
|
+
...options,
|
|
935
|
+
cwd,
|
|
936
|
+
proofPath,
|
|
937
|
+
});
|
|
938
|
+
if (!verification.ok) {
|
|
939
|
+
throw new TypeError(`Refusing to prepare ingestion from an unauthenticated device proof.\n${formatNativeDeviceProofSignatureVerification(verification)}`);
|
|
940
|
+
}
|
|
941
|
+
// Repeat the bounded receipt read at the handoff boundary. This prevents a
|
|
942
|
+
// mutable proof path from silently describing different bytes after trust
|
|
943
|
+
// verification completed.
|
|
944
|
+
const proof = await readProofFile(proofPath);
|
|
945
|
+
if (proof.proofSha256 !== verification.authenticatedProof.proofSha256) {
|
|
946
|
+
throw new TypeError("Refusing to prepare ingestion because the authenticated device proof changed.");
|
|
947
|
+
}
|
|
948
|
+
const receipt = proof.receipt;
|
|
949
|
+
const sourceMap = receipt.schemaVersion === 0 ? receipt.bundle : receipt.sourceMap;
|
|
950
|
+
return Object.freeze({
|
|
951
|
+
schemaVersion: 0,
|
|
952
|
+
kind: "solid-native.device-proof-ingestion",
|
|
953
|
+
authenticatedProof: verification.authenticatedProof,
|
|
954
|
+
verificationPolicy: verification.policy,
|
|
955
|
+
environment: Object.freeze({
|
|
956
|
+
platform: "android",
|
|
957
|
+
device: Object.freeze({
|
|
958
|
+
kind: receipt.device.kind,
|
|
959
|
+
manufacturer: receipt.device.manufacturer,
|
|
960
|
+
model: receipt.device.model,
|
|
961
|
+
product: receipt.device.product,
|
|
962
|
+
abi: receipt.device.abi,
|
|
963
|
+
osVersion: receipt.device.osVersion,
|
|
964
|
+
sdkLevel: receipt.device.sdkLevel,
|
|
965
|
+
buildFingerprintSha256: receipt.device.buildFingerprintSha256,
|
|
966
|
+
batteryLevel: receipt.device.batteryLevel,
|
|
967
|
+
batteryTemperatureCelsius: receipt.device.batteryTemperatureCelsius,
|
|
968
|
+
lowPowerMode: receipt.device.lowPowerMode,
|
|
969
|
+
}),
|
|
970
|
+
}),
|
|
971
|
+
inputs: Object.freeze({
|
|
972
|
+
nativeCompatibility: receipt.nativeCompatibility,
|
|
973
|
+
generatedBindings: receipt.generatedBindings,
|
|
974
|
+
...(receipt.schemaVersion === 1 ? { bundle: receipt.bundle } : {}),
|
|
975
|
+
sourceMap: Object.freeze({
|
|
976
|
+
bytes: sourceMap.bytes,
|
|
977
|
+
sha256: sourceMap.sha256,
|
|
978
|
+
sourceCount: sourceMap.sourceCount,
|
|
979
|
+
}),
|
|
980
|
+
artifacts: receipt.artifacts,
|
|
981
|
+
}),
|
|
982
|
+
execution: receipt.instrumentation,
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
export function formatNativeDeviceProofIngestion(ingestion) {
|
|
986
|
+
const proof = ingestion.authenticatedProof;
|
|
987
|
+
return [
|
|
988
|
+
`PASS device proof ingestion ${proof.proofSha256}`,
|
|
989
|
+
`Project: ${proof.projectName}`,
|
|
990
|
+
`Device: ${ingestion.environment.device.manufacturer} ${ingestion.environment.device.model} (${ingestion.environment.device.osVersion}, SDK ${String(ingestion.environment.device.sdkLevel)})`,
|
|
991
|
+
`Native compatibility: ${proof.nativeCompatibilityFingerprint}`,
|
|
992
|
+
`Application artifact: ${proof.applicationArtifactSha256}`,
|
|
993
|
+
`Verification profile: ${proof.profileFingerprint} (receipt schema ${String(proof.receiptSchemaVersion)})`,
|
|
994
|
+
`Execution: ${ingestion.execution.durationSeconds.toFixed(3)} seconds at ${proof.measuredAt}`,
|
|
995
|
+
`Authenticated key: ${proof.authenticatedKeyId}`,
|
|
996
|
+
...(proof.trustPolicyFingerprint === undefined
|
|
997
|
+
? []
|
|
998
|
+
: [
|
|
999
|
+
`Trust policy: ${proof.trustPolicyFingerprint} (sequence ${String(proof.trustPolicySequence)})`,
|
|
1000
|
+
]),
|
|
1001
|
+
"",
|
|
1002
|
+
"Transport and retention are intentionally delegated to the selected observability or device-lab backend.",
|
|
1003
|
+
].join("\n");
|
|
1004
|
+
}
|
|
1005
|
+
export function formatNativeDeviceProofSignatureVerification(report) {
|
|
1006
|
+
return [
|
|
1007
|
+
`${report.ok ? "PASS" : "FAIL"} device proof ${report.proofSha256}`,
|
|
1008
|
+
`Project: ${report.projectName}`,
|
|
1009
|
+
`Key: ${report.keyId}`,
|
|
1010
|
+
...(report.ok
|
|
1011
|
+
? [
|
|
1012
|
+
`Verification profile: ${report.authenticatedProof.profileFingerprint} (receipt schema ${String(report.authenticatedProof.receiptSchemaVersion)})`,
|
|
1013
|
+
]
|
|
1014
|
+
: []),
|
|
1015
|
+
...(report.trustPolicyFingerprint === undefined
|
|
1016
|
+
? []
|
|
1017
|
+
: [
|
|
1018
|
+
`Trust policy: ${report.trustPolicyFingerprint}`,
|
|
1019
|
+
`Trust policy sequence: ${String(report.trustPolicySequence)}`,
|
|
1020
|
+
]),
|
|
1021
|
+
...report.checks.map((entry) => `${entry.status.toUpperCase()} ${entry.id}: ${entry.message}`),
|
|
1022
|
+
].join("\n");
|
|
1023
|
+
}
|
|
1024
|
+
//# sourceMappingURL=device-proof-signatures.js.map
|