@motebit/crypto-android-keystore 1.1.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 +206 -0
- package/NOTICE +19 -0
- package/README.md +60 -0
- package/dist/asn1.d.ts +82 -0
- package/dist/asn1.d.ts.map +1 -0
- package/dist/asn1.js +257 -0
- package/dist/asn1.js.map +1 -0
- package/dist/google-roots.d.ts +89 -0
- package/dist/google-roots.d.ts.map +1 -0
- package/dist/google-roots.js +136 -0
- package/dist/google-roots.js.map +1 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/verify.d.ts +179 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +423 -0
- package/dist/verify.js.map +1 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Motebit, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
203
|
+
"Motebit" is a trademark of Motebit, Inc. The Apache License grants rights to
|
|
204
|
+
this software, not to any Motebit trademarks, logos, or branding. You may not
|
|
205
|
+
use Motebit branding in a way that suggests endorsement or affiliation without
|
|
206
|
+
written permission.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Motebit
|
|
2
|
+
Copyright 2026 Motebit, Inc.
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Motebit, Inc. (https://motebit.com).
|
|
5
|
+
|
|
6
|
+
The permissive-floor packages (the protocol, SDK, cryptographic primitives,
|
|
7
|
+
platform-attestation verifier leaves, scaffolding CLI, and GitHub Action) are
|
|
8
|
+
licensed under the Apache License, Version 2.0. See LICENSE files in each
|
|
9
|
+
`packages/*/` subdirectory and in `spec/` for the full license text.
|
|
10
|
+
|
|
11
|
+
The remaining packages, apps, and services are licensed under the Business
|
|
12
|
+
Source License 1.1 and convert to the Apache License, Version 2.0 four years
|
|
13
|
+
after each version's first public release. See `LICENSE` at the repository
|
|
14
|
+
root and `LICENSING.md` for the full license boundary.
|
|
15
|
+
|
|
16
|
+
"Motebit" is a trademark of Motebit, Inc. The licenses granted here cover
|
|
17
|
+
this software only, not Motebit trademarks, logos, or branding. Use of
|
|
18
|
+
Motebit branding in a way that suggests endorsement or affiliation requires
|
|
19
|
+
written permission.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @motebit/crypto-android-keystore
|
|
2
|
+
|
|
3
|
+
Offline Apache-2.0 verifier for Android Hardware-Backed Keystore Attestation hardware-attestation credentials.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i @motebit/crypto-android-keystore
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Plugs into [`@motebit/crypto`](https://www.npmjs.com/package/@motebit/crypto)'s `HardwareAttestationVerifiers` dispatcher as the `androidKeystore` verifier — called when a credential declares `platform: "android_keystore"` (Android devices with KeyMaster 3+ / KeyMint 1+ — every modern Android device since Android 7).
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { verify } from "@motebit/crypto";
|
|
15
|
+
import { androidKeystoreVerifier } from "@motebit/crypto-android-keystore";
|
|
16
|
+
|
|
17
|
+
const result = await verify(credential, {
|
|
18
|
+
hardwareAttestation: {
|
|
19
|
+
androidKeystore: androidKeystoreVerifier({
|
|
20
|
+
// Bytes of the registered Android package's `attestationApplicationId`,
|
|
21
|
+
// captured at registration time. Must byte-equal what the leaf
|
|
22
|
+
// attestation extension reports.
|
|
23
|
+
expectedAttestationApplicationId,
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## What it verifies
|
|
30
|
+
|
|
31
|
+
1. **Cert chain to a pinned Google Hardware Attestation root.** Two roots ship pinned: the legacy RSA-4096 root (for factory-provisioned devices) and the modern ECDSA P-384 root (for RKP-provisioned devices). Verifiers MUST pin both — Google rotated from RSA to ECDSA between Feb–Apr 2026, so a verifier pinning only one drops half its install base.
|
|
32
|
+
2. **The Android Key Attestation extension** (OID `1.3.6.1.4.1.11129.2.1.17`) on the leaf — `attestationVersion ≥ 3` (Keymaster 3 / Android 7+), `attestationSecurityLevel ≥ TRUSTED_ENVIRONMENT` (rejects software-only fallback), `hardwareEnforced.rootOfTrust.verifiedBootState` in caller's allowlist (default `[VERIFIED]`), `hardwareEnforced.attestationApplicationId` byte-equals the registered package binding.
|
|
33
|
+
3. **Optional revocation snapshot.** Caller-supplied snapshot keyed by lowercase-hex serial number, mirroring Google's published shape at `https://android.googleapis.com/attestation/status`. Defaults to empty (no revocation enforcement). The verifier never fetches at runtime — `@motebit/verify` ships an embedded snapshot at release time.
|
|
34
|
+
4. **Identity binding.** The leaf's `attestationChallenge` must byte-equal `SHA-256(canonicalJson({ attested_at, device_id, identity_public_key, motebit_id, platform: "android_keystore", version: "1" }))` — the same body the Kotlin `expo-android-keystore` mint path composes. A malicious client that substitutes any other body fails here.
|
|
35
|
+
|
|
36
|
+
## Why pinned
|
|
37
|
+
|
|
38
|
+
A verifier that dynamically fetched Google's attestation roots has no sovereign story. The pinned roots are the self-attesting contract — third parties audit `DEFAULT_ANDROID_KEYSTORE_TRUST_ANCHORS` and know which trust anchors this library accepts. Source of truth: `roots.json` in [`android/keyattestation`](https://github.com/android/keyattestation), Google's canonical Kotlin reference verifier.
|
|
39
|
+
|
|
40
|
+
## Why a hand-rolled DER walker
|
|
41
|
+
|
|
42
|
+
The `KeyDescription` ASN.1 structure has ~50 optional context-tagged fields in `AuthorizationList`, two of which carry policy-relevant material (`[704] rootOfTrust` and `[709] attestationApplicationId`). A schema-driven parser would have to declare all 50 fields just to skip past the ones we ignore. Walking the DER directly costs ~150 lines and stays scoped to exactly what verification needs — same trade-off [`@motebit/crypto-tpm`](https://www.npmjs.com/package/@motebit/crypto-tpm) made for `TPMS_ATTEST` parsing.
|
|
43
|
+
|
|
44
|
+
## Privacy posture
|
|
45
|
+
|
|
46
|
+
Closer to FIDO Yubico-batch than to TPM EK. The leaf X.509 subject is the fixed string `CN=Android Keystore Key` — not device-identifying. The optional ID-attestation family (`attestationIdSerial`, `attestationIdImei`, etc.) only fires when the caller invokes `setDevicePropertiesAttestationIncluded(true)`; motebit does not. Default `setAttestationChallenge()` produces batch-shareable chains with the device-identifying material confined to (a) the caller-controlled challenge and (b) `verifiedBootKey` (boot-image identity, not user identity).
|
|
47
|
+
|
|
48
|
+
## Related
|
|
49
|
+
|
|
50
|
+
- [`@motebit/crypto`](https://www.npmjs.com/package/@motebit/crypto) — dispatcher (pure permissive-floor; zero deps)
|
|
51
|
+
- [`@motebit/crypto-appattest`](https://www.npmjs.com/package/@motebit/crypto-appattest) — iOS sibling
|
|
52
|
+
- [`@motebit/crypto-tpm`](https://www.npmjs.com/package/@motebit/crypto-tpm) — Windows / Linux TPM sibling
|
|
53
|
+
- [`@motebit/crypto-webauthn`](https://www.npmjs.com/package/@motebit/crypto-webauthn) — browser sibling
|
|
54
|
+
- [`@motebit/verify`](https://www.npmjs.com/package/@motebit/verify) — canonical CLI bundling all four leaves with motebit defaults
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
Apache-2.0 — see [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
|
|
59
|
+
|
|
60
|
+
"Motebit" is a trademark. The Apache License grants rights to this software, not to any Motebit trademarks, logos, or branding. You may not use Motebit branding in a way that suggests endorsement or affiliation without written permission.
|
package/dist/asn1.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal DER reader for the Android Key Attestation extension.
|
|
3
|
+
*
|
|
4
|
+
* Why hand-rolled: the `KeyDescription` ASN.1 schema (Android Open
|
|
5
|
+
* Source Project, `attestation_record.cpp` / `keymint_attest.asn1`)
|
|
6
|
+
* has ~50 optional context-tagged fields in `AuthorizationList`. Two
|
|
7
|
+
* of them carry the policy-relevant material — `[704] rootOfTrust`
|
|
8
|
+
* and `[709] attestationApplicationId` — and the rest are
|
|
9
|
+
* key-shape parameters we do not gate on. A schema-driven parser
|
|
10
|
+
* (e.g. `@peculiar/asn1-schema`) would have to declare all 50 fields
|
|
11
|
+
* just to skip past the ones we ignore, or use Any-typed slots and
|
|
12
|
+
* lose type safety. Walking the DER directly costs ~150 lines and
|
|
13
|
+
* stays scoped to exactly what verification needs — same trade-off
|
|
14
|
+
* `@motebit/crypto-tpm` made for `TPMS_ATTEST` parsing.
|
|
15
|
+
*
|
|
16
|
+
* Specs referenced:
|
|
17
|
+
* - Android Open Source Project, `attestation_record.cpp`:
|
|
18
|
+
* https://source.android.com/docs/security/features/keystore/attestation
|
|
19
|
+
* - X.690 (DER encoding rules) — high-tag-number form for tags ≥ 31,
|
|
20
|
+
* long-form length encoding for content > 127 bytes.
|
|
21
|
+
*
|
|
22
|
+
* The parser is fail-closed: any structural anomaly throws a typed
|
|
23
|
+
* error rather than silently skipping. Callers wrap the parse call in
|
|
24
|
+
* try/catch and convert the throw into a structured `errors[]` entry.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Android `attestationSecurityLevel` / `keymintSecurityLevel` ENUMERATED.
|
|
28
|
+
* Values are stable across KeyMaster and KeyMint versions.
|
|
29
|
+
*/
|
|
30
|
+
export declare const SECURITY_LEVEL_SOFTWARE = 0;
|
|
31
|
+
export declare const SECURITY_LEVEL_TRUSTED_ENVIRONMENT = 1;
|
|
32
|
+
export declare const SECURITY_LEVEL_STRONG_BOX = 2;
|
|
33
|
+
/**
|
|
34
|
+
* Android `verifiedBootState` ENUMERATED — published in
|
|
35
|
+
* https://source.android.com/docs/security/features/verifiedboot.
|
|
36
|
+
* - VERIFIED (0): full chain of trust to a Google-signed bootloader
|
|
37
|
+
* - SELF_SIGNED (1): user-installed root of trust (GrapheneOS,
|
|
38
|
+
* CalyxOS, etc.)
|
|
39
|
+
* - UNVERIFIED (2): unlocked bootloader; no boot-image guarantee
|
|
40
|
+
* - FAILED (3): verification attempted and failed
|
|
41
|
+
*/
|
|
42
|
+
export declare const VERIFIED_BOOT_STATE_VERIFIED = 0;
|
|
43
|
+
export declare const VERIFIED_BOOT_STATE_SELF_SIGNED = 1;
|
|
44
|
+
export declare const VERIFIED_BOOT_STATE_UNVERIFIED = 2;
|
|
45
|
+
export declare const VERIFIED_BOOT_STATE_FAILED = 3;
|
|
46
|
+
export interface RootOfTrust {
|
|
47
|
+
/** SHA-256 of the boot-image verification public key. */
|
|
48
|
+
readonly verifiedBootKey: Uint8Array;
|
|
49
|
+
readonly deviceLocked: boolean;
|
|
50
|
+
readonly verifiedBootState: number;
|
|
51
|
+
/** Optional — present on KeyMint 2+ devices. */
|
|
52
|
+
readonly verifiedBootHash: Uint8Array | null;
|
|
53
|
+
}
|
|
54
|
+
export interface AuthorizationList {
|
|
55
|
+
readonly rootOfTrust: RootOfTrust | null;
|
|
56
|
+
/** Raw bytes of `[709] attestationApplicationId` — caller decides
|
|
57
|
+
* whether to JSON-decode further (it's a wrapped sequence of the
|
|
58
|
+
* package name + signing-cert SHA-256 set). */
|
|
59
|
+
readonly attestationApplicationId: Uint8Array | null;
|
|
60
|
+
}
|
|
61
|
+
export interface KeyDescription {
|
|
62
|
+
readonly attestationVersion: number;
|
|
63
|
+
readonly attestationSecurityLevel: number;
|
|
64
|
+
readonly keyMintVersion: number;
|
|
65
|
+
readonly keyMintSecurityLevel: number;
|
|
66
|
+
/** The challenge the caller passed to `setAttestationChallenge` —
|
|
67
|
+
* for motebit this is `SHA256(canonical body naming the
|
|
68
|
+
* identity)`. */
|
|
69
|
+
readonly attestationChallenge: Uint8Array;
|
|
70
|
+
readonly uniqueId: Uint8Array;
|
|
71
|
+
readonly softwareEnforced: AuthorizationList;
|
|
72
|
+
readonly hardwareEnforced: AuthorizationList;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Parse the Android Key Attestation extension value into a typed
|
|
76
|
+
* `KeyDescription`. `extValue` is the `extnValue` OCTET STRING's
|
|
77
|
+
* inner content — the bytes inside the OCTET STRING wrapper that
|
|
78
|
+
* `@peculiar/x509`'s `cert.getExtension(OID).value` returns as a
|
|
79
|
+
* Uint8Array.
|
|
80
|
+
*/
|
|
81
|
+
export declare function parseKeyDescription(extValue: Uint8Array): KeyDescription;
|
|
82
|
+
//# sourceMappingURL=asn1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn1.d.ts","sourceRoot":"","sources":["../src/asn1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AA+BH;;;GAGG;AACH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,kCAAkC,IAAI,CAAC;AACpD,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C,eAAO,MAAM,+BAA+B,IAAI,CAAC;AACjD,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAChD,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,MAAM,WAAW,WAAW;IAC1B,yDAAyD;IACzD,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,gDAAgD;IAChD,QAAQ,CAAC,gBAAgB,EAAE,UAAU,GAAG,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IACzC;;oDAEgD;IAChD,QAAQ,CAAC,wBAAwB,EAAE,UAAU,GAAG,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC1C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC;;sBAEkB;IAClB,QAAQ,CAAC,oBAAoB,EAAE,UAAU,CAAC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;IAC7C,QAAQ,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;CAC9C;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,UAAU,GAAG,cAAc,CAsBxE"}
|
package/dist/asn1.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal DER reader for the Android Key Attestation extension.
|
|
3
|
+
*
|
|
4
|
+
* Why hand-rolled: the `KeyDescription` ASN.1 schema (Android Open
|
|
5
|
+
* Source Project, `attestation_record.cpp` / `keymint_attest.asn1`)
|
|
6
|
+
* has ~50 optional context-tagged fields in `AuthorizationList`. Two
|
|
7
|
+
* of them carry the policy-relevant material — `[704] rootOfTrust`
|
|
8
|
+
* and `[709] attestationApplicationId` — and the rest are
|
|
9
|
+
* key-shape parameters we do not gate on. A schema-driven parser
|
|
10
|
+
* (e.g. `@peculiar/asn1-schema`) would have to declare all 50 fields
|
|
11
|
+
* just to skip past the ones we ignore, or use Any-typed slots and
|
|
12
|
+
* lose type safety. Walking the DER directly costs ~150 lines and
|
|
13
|
+
* stays scoped to exactly what verification needs — same trade-off
|
|
14
|
+
* `@motebit/crypto-tpm` made for `TPMS_ATTEST` parsing.
|
|
15
|
+
*
|
|
16
|
+
* Specs referenced:
|
|
17
|
+
* - Android Open Source Project, `attestation_record.cpp`:
|
|
18
|
+
* https://source.android.com/docs/security/features/keystore/attestation
|
|
19
|
+
* - X.690 (DER encoding rules) — high-tag-number form for tags ≥ 31,
|
|
20
|
+
* long-form length encoding for content > 127 bytes.
|
|
21
|
+
*
|
|
22
|
+
* The parser is fail-closed: any structural anomaly throws a typed
|
|
23
|
+
* error rather than silently skipping. Callers wrap the parse call in
|
|
24
|
+
* try/catch and convert the throw into a structured `errors[]` entry.
|
|
25
|
+
*/
|
|
26
|
+
/** Raw DER tag-class identifiers (top 2 bits of the tag byte). */
|
|
27
|
+
const TAG_CLASS_UNIVERSAL = 0;
|
|
28
|
+
const TAG_CLASS_CONTEXT = 2;
|
|
29
|
+
/** Universal-class ASN.1 tag numbers we read. */
|
|
30
|
+
const UTAG_BOOLEAN = 1;
|
|
31
|
+
const UTAG_INTEGER = 2;
|
|
32
|
+
const UTAG_OCTET_STRING = 4;
|
|
33
|
+
const UTAG_ENUMERATED = 10;
|
|
34
|
+
const UTAG_SEQUENCE = 16;
|
|
35
|
+
/**
|
|
36
|
+
* AuthorizationList context-tag numbers we care about. All other tags
|
|
37
|
+
* in the AuthorizationList SEQUENCE are skipped. These are the only
|
|
38
|
+
* two whose values gate canonical motebit verification — additional
|
|
39
|
+
* tags (`purpose`, `algorithm`, `keySize`, `ec_curve`, etc.) describe
|
|
40
|
+
* key-shape parameters and are out of scope for v1.
|
|
41
|
+
*/
|
|
42
|
+
const AUTH_LIST_TAG_ROOT_OF_TRUST = 704;
|
|
43
|
+
const AUTH_LIST_TAG_ATTESTATION_APPLICATION_ID = 709;
|
|
44
|
+
/**
|
|
45
|
+
* Android `attestationSecurityLevel` / `keymintSecurityLevel` ENUMERATED.
|
|
46
|
+
* Values are stable across KeyMaster and KeyMint versions.
|
|
47
|
+
*/
|
|
48
|
+
export const SECURITY_LEVEL_SOFTWARE = 0;
|
|
49
|
+
export const SECURITY_LEVEL_TRUSTED_ENVIRONMENT = 1;
|
|
50
|
+
export const SECURITY_LEVEL_STRONG_BOX = 2;
|
|
51
|
+
/**
|
|
52
|
+
* Android `verifiedBootState` ENUMERATED — published in
|
|
53
|
+
* https://source.android.com/docs/security/features/verifiedboot.
|
|
54
|
+
* - VERIFIED (0): full chain of trust to a Google-signed bootloader
|
|
55
|
+
* - SELF_SIGNED (1): user-installed root of trust (GrapheneOS,
|
|
56
|
+
* CalyxOS, etc.)
|
|
57
|
+
* - UNVERIFIED (2): unlocked bootloader; no boot-image guarantee
|
|
58
|
+
* - FAILED (3): verification attempted and failed
|
|
59
|
+
*/
|
|
60
|
+
export const VERIFIED_BOOT_STATE_VERIFIED = 0;
|
|
61
|
+
export const VERIFIED_BOOT_STATE_SELF_SIGNED = 1;
|
|
62
|
+
export const VERIFIED_BOOT_STATE_UNVERIFIED = 2;
|
|
63
|
+
export const VERIFIED_BOOT_STATE_FAILED = 3;
|
|
64
|
+
/**
|
|
65
|
+
* Parse the Android Key Attestation extension value into a typed
|
|
66
|
+
* `KeyDescription`. `extValue` is the `extnValue` OCTET STRING's
|
|
67
|
+
* inner content — the bytes inside the OCTET STRING wrapper that
|
|
68
|
+
* `@peculiar/x509`'s `cert.getExtension(OID).value` returns as a
|
|
69
|
+
* Uint8Array.
|
|
70
|
+
*/
|
|
71
|
+
export function parseKeyDescription(extValue) {
|
|
72
|
+
const seq = readDerNode(extValue, 0);
|
|
73
|
+
if (seq.node.tagClass !== TAG_CLASS_UNIVERSAL || seq.node.tagNumber !== UTAG_SEQUENCE) {
|
|
74
|
+
throw new Error(`KeyDescription: outer tag is not SEQUENCE (got class=${seq.node.tagClass} tagNumber=${seq.node.tagNumber})`);
|
|
75
|
+
}
|
|
76
|
+
const children = readSequenceChildren(seq.node.contentBytes);
|
|
77
|
+
if (children.length < 8) {
|
|
78
|
+
throw new Error(`KeyDescription: SEQUENCE has ${children.length} fields, expected ≥ 8`);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
attestationVersion: readUniversalInteger(children[0], "attestationVersion"),
|
|
82
|
+
attestationSecurityLevel: readUniversalEnumerated(children[1], "attestationSecurityLevel"),
|
|
83
|
+
keyMintVersion: readUniversalInteger(children[2], "keyMintVersion"),
|
|
84
|
+
keyMintSecurityLevel: readUniversalEnumerated(children[3], "keyMintSecurityLevel"),
|
|
85
|
+
attestationChallenge: readUniversalOctetString(children[4], "attestationChallenge"),
|
|
86
|
+
uniqueId: readUniversalOctetString(children[5], "uniqueId"),
|
|
87
|
+
softwareEnforced: parseAuthorizationList(children[6], "softwareEnforced"),
|
|
88
|
+
hardwareEnforced: parseAuthorizationList(children[7], "hardwareEnforced"),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse an `AuthorizationList` SEQUENCE into the two fields we care
|
|
93
|
+
* about. All other context-tagged fields are intentionally skipped —
|
|
94
|
+
* the AOSP spec defines ~50 optional context tags carrying key-shape
|
|
95
|
+
* parameters; motebit verification gates only on `rootOfTrust` and
|
|
96
|
+
* `attestationApplicationId`.
|
|
97
|
+
*/
|
|
98
|
+
function parseAuthorizationList(node, fieldName) {
|
|
99
|
+
if (node.tagClass !== TAG_CLASS_UNIVERSAL || node.tagNumber !== UTAG_SEQUENCE) {
|
|
100
|
+
throw new Error(`${fieldName}: not a SEQUENCE`);
|
|
101
|
+
}
|
|
102
|
+
let rootOfTrust = null;
|
|
103
|
+
let attestationApplicationId = null;
|
|
104
|
+
for (const child of readSequenceChildren(node.contentBytes)) {
|
|
105
|
+
if (child.tagClass !== TAG_CLASS_CONTEXT)
|
|
106
|
+
continue;
|
|
107
|
+
if (child.tagNumber === AUTH_LIST_TAG_ROOT_OF_TRUST) {
|
|
108
|
+
// [704] EXPLICIT RootOfTrust — the outer context-tag wraps the
|
|
109
|
+
// inner SEQUENCE. Read the SEQUENCE and parse its fields.
|
|
110
|
+
const inner = readDerNode(child.contentBytes, 0).node;
|
|
111
|
+
rootOfTrust = parseRootOfTrust(inner);
|
|
112
|
+
}
|
|
113
|
+
else if (child.tagNumber === AUTH_LIST_TAG_ATTESTATION_APPLICATION_ID) {
|
|
114
|
+
// [709] EXPLICIT OCTET STRING.
|
|
115
|
+
const inner = readDerNode(child.contentBytes, 0).node;
|
|
116
|
+
if (inner.tagClass !== TAG_CLASS_UNIVERSAL || inner.tagNumber !== UTAG_OCTET_STRING) {
|
|
117
|
+
throw new Error(`${fieldName}.attestationApplicationId: inner tag is not OCTET STRING (got class=${inner.tagClass} tagNumber=${inner.tagNumber})`);
|
|
118
|
+
}
|
|
119
|
+
attestationApplicationId = inner.contentBytes.slice();
|
|
120
|
+
}
|
|
121
|
+
// All other context tags are key-shape parameters — skip silently.
|
|
122
|
+
}
|
|
123
|
+
return { rootOfTrust, attestationApplicationId };
|
|
124
|
+
}
|
|
125
|
+
function parseRootOfTrust(node) {
|
|
126
|
+
if (node.tagClass !== TAG_CLASS_UNIVERSAL || node.tagNumber !== UTAG_SEQUENCE) {
|
|
127
|
+
throw new Error("rootOfTrust: not a SEQUENCE");
|
|
128
|
+
}
|
|
129
|
+
const children = readSequenceChildren(node.contentBytes);
|
|
130
|
+
if (children.length < 3) {
|
|
131
|
+
throw new Error(`rootOfTrust: SEQUENCE has ${children.length} fields, expected ≥ 3`);
|
|
132
|
+
}
|
|
133
|
+
const verifiedBootKey = readUniversalOctetString(children[0], "rootOfTrust.verifiedBootKey");
|
|
134
|
+
const deviceLocked = readUniversalBoolean(children[1], "rootOfTrust.deviceLocked");
|
|
135
|
+
const verifiedBootState = readUniversalEnumerated(children[2], "rootOfTrust.verifiedBootState");
|
|
136
|
+
const verifiedBootHash = children.length >= 4
|
|
137
|
+
? readUniversalOctetString(children[3], "rootOfTrust.verifiedBootHash")
|
|
138
|
+
: null;
|
|
139
|
+
return { verifiedBootKey, deviceLocked, verifiedBootState, verifiedBootHash };
|
|
140
|
+
}
|
|
141
|
+
// ── Universal-tag readers ─────────────────────────────────────────────
|
|
142
|
+
function readUniversalInteger(node, fieldName) {
|
|
143
|
+
if (node.tagClass !== TAG_CLASS_UNIVERSAL || node.tagNumber !== UTAG_INTEGER) {
|
|
144
|
+
throw new Error(`${fieldName}: not an INTEGER`);
|
|
145
|
+
}
|
|
146
|
+
// Attestation versions are small (current is 400 = KeyMint 4.0).
|
|
147
|
+
// We do not need a bigint reader for v1.
|
|
148
|
+
let n = 0;
|
|
149
|
+
for (const b of node.contentBytes) {
|
|
150
|
+
n = (n << 8) | b;
|
|
151
|
+
if (n > Number.MAX_SAFE_INTEGER) {
|
|
152
|
+
throw new Error(`${fieldName}: INTEGER exceeds Number.MAX_SAFE_INTEGER`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return n;
|
|
156
|
+
}
|
|
157
|
+
function readUniversalEnumerated(node, fieldName) {
|
|
158
|
+
if (node.tagClass !== TAG_CLASS_UNIVERSAL || node.tagNumber !== UTAG_ENUMERATED) {
|
|
159
|
+
throw new Error(`${fieldName}: not an ENUMERATED`);
|
|
160
|
+
}
|
|
161
|
+
// ENUMERATED encodes the same as INTEGER.
|
|
162
|
+
let n = 0;
|
|
163
|
+
for (const b of node.contentBytes) {
|
|
164
|
+
n = (n << 8) | b;
|
|
165
|
+
}
|
|
166
|
+
return n;
|
|
167
|
+
}
|
|
168
|
+
function readUniversalOctetString(node, fieldName) {
|
|
169
|
+
if (node.tagClass !== TAG_CLASS_UNIVERSAL || node.tagNumber !== UTAG_OCTET_STRING) {
|
|
170
|
+
throw new Error(`${fieldName}: not an OCTET STRING`);
|
|
171
|
+
}
|
|
172
|
+
return node.contentBytes.slice();
|
|
173
|
+
}
|
|
174
|
+
function readUniversalBoolean(node, fieldName) {
|
|
175
|
+
if (node.tagClass !== TAG_CLASS_UNIVERSAL || node.tagNumber !== UTAG_BOOLEAN) {
|
|
176
|
+
throw new Error(`${fieldName}: not a BOOLEAN`);
|
|
177
|
+
}
|
|
178
|
+
if (node.contentBytes.length !== 1) {
|
|
179
|
+
throw new Error(`${fieldName}: BOOLEAN content length ${node.contentBytes.length} ≠ 1`);
|
|
180
|
+
}
|
|
181
|
+
return node.contentBytes[0] !== 0;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Read one DER tag-length-value triple from `bytes` starting at
|
|
185
|
+
* `offset`. Handles X.690 high-tag-number form (multi-byte tag) and
|
|
186
|
+
* long-form length encoding.
|
|
187
|
+
*/
|
|
188
|
+
function readDerNode(bytes, offset) {
|
|
189
|
+
if (offset >= bytes.length) {
|
|
190
|
+
throw new Error(`DER: read past end (offset=${offset}, length=${bytes.length})`);
|
|
191
|
+
}
|
|
192
|
+
let i = offset;
|
|
193
|
+
const tagByte = bytes[i++];
|
|
194
|
+
const tagClass = (tagByte >> 6) & 0x03;
|
|
195
|
+
const constructed = (tagByte & 0x20) !== 0;
|
|
196
|
+
let tagNumber = tagByte & 0x1f;
|
|
197
|
+
if (tagNumber === 0x1f) {
|
|
198
|
+
// High-tag-number form: subsequent bytes encode tag in base-128,
|
|
199
|
+
// with high bit set on every byte except the last.
|
|
200
|
+
tagNumber = 0;
|
|
201
|
+
let b;
|
|
202
|
+
let safety = 0;
|
|
203
|
+
do {
|
|
204
|
+
if (i >= bytes.length)
|
|
205
|
+
throw new Error("DER: truncated high-tag-number form");
|
|
206
|
+
if (++safety > 4) {
|
|
207
|
+
// 4 bytes covers tag numbers up to 2^28 — far beyond anything
|
|
208
|
+
// AOSP defines; refuse to decode arbitrarily large tags.
|
|
209
|
+
throw new Error("DER: high-tag-number form exceeds 4 bytes");
|
|
210
|
+
}
|
|
211
|
+
b = bytes[i++];
|
|
212
|
+
tagNumber = (tagNumber << 7) | (b & 0x7f);
|
|
213
|
+
} while ((b & 0x80) !== 0);
|
|
214
|
+
}
|
|
215
|
+
if (i >= bytes.length)
|
|
216
|
+
throw new Error("DER: truncated length");
|
|
217
|
+
const lenByte = bytes[i++];
|
|
218
|
+
let length;
|
|
219
|
+
if ((lenByte & 0x80) === 0) {
|
|
220
|
+
length = lenByte;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
const lenBytes = lenByte & 0x7f;
|
|
224
|
+
if (lenBytes === 0) {
|
|
225
|
+
throw new Error("DER: indefinite-length encoding not allowed in DER");
|
|
226
|
+
}
|
|
227
|
+
if (lenBytes > 4) {
|
|
228
|
+
// A 4-byte length is 4 GiB — far beyond anything we'd see in a
|
|
229
|
+
// cert extension; refuse rather than overflow.
|
|
230
|
+
throw new Error(`DER: long-form length exceeds 4 bytes (got ${lenBytes})`);
|
|
231
|
+
}
|
|
232
|
+
length = 0;
|
|
233
|
+
for (let j = 0; j < lenBytes; j++) {
|
|
234
|
+
if (i >= bytes.length)
|
|
235
|
+
throw new Error("DER: truncated long-form length");
|
|
236
|
+
length = (length << 8) | bytes[i++];
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (i + length > bytes.length) {
|
|
240
|
+
throw new Error(`DER: content runs past buffer (start=${i}, length=${length}, buffer=${bytes.length})`);
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
node: { tagClass, constructed, tagNumber, contentBytes: bytes.subarray(i, i + length) },
|
|
244
|
+
nextOffset: i + length,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function readSequenceChildren(seqContent) {
|
|
248
|
+
const out = [];
|
|
249
|
+
let offset = 0;
|
|
250
|
+
while (offset < seqContent.length) {
|
|
251
|
+
const r = readDerNode(seqContent, offset);
|
|
252
|
+
out.push(r.node);
|
|
253
|
+
offset = r.nextOffset;
|
|
254
|
+
}
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=asn1.js.map
|
package/dist/asn1.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn1.js","sourceRoot":"","sources":["../src/asn1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,kEAAkE;AAClE,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,iBAAiB,GAAG,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