@idpartners/client-attestation-sdk 0.0.0-stage → 1.0.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 +202 -0
- package/README.md +142 -2
- package/dist/attester.d.ts +93 -0
- package/dist/attester.js +139 -0
- package/dist/builders.d.ts +92 -0
- package/dist/builders.js +284 -0
- package/dist/credential.d.ts +22 -0
- package/dist/credential.js +44 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +28 -0
- package/dist/evidence.d.ts +55 -0
- package/dist/evidence.js +168 -0
- package/dist/http.d.ts +1 -0
- package/dist/http.js +183 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +20 -0
- package/dist/issuance.d.ts +61 -0
- package/dist/issuance.js +117 -0
- package/dist/logging.d.ts +12 -0
- package/dist/logging.js +77 -0
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +64 -0
- package/dist/signer.d.ts +32 -0
- package/dist/signer.js +121 -0
- package/dist/signing-key-pair.d.ts +44 -0
- package/dist/signing-key-pair.js +130 -0
- package/dist/svid-source.d.ts +41 -0
- package/dist/svid-source.js +77 -0
- package/dist/token-source.d.ts +146 -0
- package/dist/token-source.js +510 -0
- package/dist/validator/config.d.ts +61 -0
- package/dist/validator/config.js +61 -0
- package/dist/validator/errors.d.ts +20 -0
- package/dist/validator/errors.js +18 -0
- package/dist/validator/index.d.ts +19 -0
- package/dist/validator/index.js +12 -0
- package/dist/validator/jwks.d.ts +2 -0
- package/dist/validator/jwks.js +150 -0
- package/dist/validator/resource.d.ts +37 -0
- package/dist/validator/resource.js +98 -0
- package/dist/validator/result.d.ts +17 -0
- package/dist/validator/result.js +28 -0
- package/dist/validator/strict.d.ts +1 -0
- package/dist/validator/strict.js +202 -0
- package/dist/validator/validator.d.ts +41 -0
- package/dist/validator/validator.js +240 -0
- package/package.json +56 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,143 @@
|
|
|
1
|
-
#
|
|
1
|
+
# client-attestation-sdk (TypeScript)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Client-side builder SDK for **OAuth Attestation-Based Client Authentication**
|
|
4
|
+
(`draft-ietf-oauth-attestation-based-client-auth`). Mints the three artifacts a client
|
|
5
|
+
presents at the token endpoint:
|
|
6
|
+
|
|
7
|
+
- **Client Attestation JWT** (`typ=oauth-client-attestation+jwt`) — issued by a Client Attester,
|
|
8
|
+
names the client (`sub` = `client_id`) and binds its instance key via `cnf.jwk`.
|
|
9
|
+
- **Client Attestation PoP JWT** (`typ=oauth-client-attestation-pop+jwt`) — proves possession of
|
|
10
|
+
the instance key (PoP method `attestation_pop_jwt`).
|
|
11
|
+
- **DPoP proof JWT** (`typ=dpop+jwt`) — combined mode (PoP method `dpop_combined`); its embedded
|
|
12
|
+
`jwk` header is the instance key bound in the attestation's `cnf`.
|
|
13
|
+
|
|
14
|
+
This is one port of a polyglot SDK; it emits byte-compatible artifacts with the Java and Python
|
|
15
|
+
ports and is judged by a shared Java verifier. Built on [panva `jose`](https://github.com/panva/jose).
|
|
16
|
+
`kid` values are RFC 7638 JWK thumbprints (SHA-256, base64url); `iat`/`exp` are integer epoch seconds.
|
|
17
|
+
|
|
18
|
+
## Install / build
|
|
19
|
+
|
|
20
|
+
Requires **Node 20+**, or an edge runtime with WebCrypto and `fetch` (Cloudflare Workers, Vercel Edge,
|
|
21
|
+
Deno Deploy) with no Node compatibility layer needed. Crypto, encoding and HTTP use web-standard APIs, and
|
|
22
|
+
nothing imports a Node built-in at load time, so the builders, the one-call `ClientAttestation` flow, the
|
|
23
|
+
issuance client and the token validator all work on the edge.
|
|
24
|
+
|
|
25
|
+
CI tests this in a real Workers runtime: `npm run test:edge` bundles the package as an edge bundler would
|
|
26
|
+
and runs it in [`workerd`](https://github.com/cloudflare/workerd), Cloudflare's open-source Workers runtime
|
|
27
|
+
(1.20261007.1, compatibility date 2026-10-01, Node compatibility switched off). It generates keys, builds an
|
|
28
|
+
attestation, a PoP and a DPoP proof, and runs the token validator against the shared validation vectors.
|
|
29
|
+
Vercel Edge and Deno Deploy are not tested directly.
|
|
30
|
+
|
|
31
|
+
Evidence gathering is the part that needs Node. Each of these loads the built-in it needs on first use; the
|
|
32
|
+
two sources throw a `ClientAttestationError` naming themselves from `fetch` on a runtime without it:
|
|
33
|
+
|
|
34
|
+
- `SpireWorkloadApiSvidSource` runs the `spire-agent` CLI (`node:child_process`);
|
|
35
|
+
- `FileTokenSvidSource` reads a projected token file (`node:fs`);
|
|
36
|
+
- `autoDetectEvidence` reads environment variables and probes for token files and the SPIRE socket. On
|
|
37
|
+
the edge those all read as absent, so it falls through to the GCP metadata server and then throws
|
|
38
|
+
`EvidenceNotFound`. Pass an explicit `SvidSource` to `ClientAttestation` there: `StaticSvidSource`,
|
|
39
|
+
your own, or `HttpSvidSource` in development.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install @idpartners/client-attestation-sdk
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
To build from a clone:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install
|
|
49
|
+
npm run build # tsc -> dist/
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
jose's crypto is async, so key factories and `build()` return promises.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import {
|
|
58
|
+
ClientAttestationBuilder,
|
|
59
|
+
ClientAttestationCredential,
|
|
60
|
+
SigningKeyPair,
|
|
61
|
+
} from "client-attestation-sdk";
|
|
62
|
+
|
|
63
|
+
// Attester side: issue the attestation.
|
|
64
|
+
const attester = await SigningKeyPair.generate("ES256"); // or SigningKeyPair.fromJwk(jwk, "ES256")
|
|
65
|
+
const instance = await SigningKeyPair.generate("ES256"); // the client's instance key
|
|
66
|
+
const attestation = await new ClientAttestationBuilder(attester, "https://attester.example.com")
|
|
67
|
+
.clientId("https://rp.example.com")
|
|
68
|
+
.confirmationKey(instance)
|
|
69
|
+
.expiresIn(300)
|
|
70
|
+
// optional: .authorizationDetails(...) / .workload(...) / .operator(sub, issuer?) —
|
|
71
|
+
// operator names who's accountable for running the client (RFC 8693 may_act-shaped; an
|
|
72
|
+
// assertion, not proof of authorisation), distinct from clientId and from the principal.
|
|
73
|
+
.build();
|
|
74
|
+
|
|
75
|
+
// Client side: produce token-request headers.
|
|
76
|
+
const cred = new ClientAttestationCredential(attestation, instance);
|
|
77
|
+
|
|
78
|
+
const popHeaders = await cred.popHeaders("https://rp.example.com", "https://as.example.com");
|
|
79
|
+
// { "OAuth-Client-Attestation": "...", "OAuth-Client-Attestation-PoP": "..." }
|
|
80
|
+
|
|
81
|
+
const dpopHeaders = await cred.dpopHeaders("POST", "https://as.example.com/as/token.oauth2");
|
|
82
|
+
// { "OAuth-Client-Attestation": "...", "DPoP": "..." }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The one-call `ClientAttestation` orchestration class (see the [root README](../README.md#get-a-token-in-one-call))
|
|
86
|
+
wraps this: `{ popMethod: "dpop_combined" }` in its options switches it to DPoP mode, and a fetched
|
|
87
|
+
challenge is carried through automatically as the PoP JWT's `challenge` claim or the DPoP proof's `nonce`
|
|
88
|
+
claim, whichever mode is active. `operator: {...}` asks the attester to state the client's operator: it
|
|
89
|
+
goes in the mint request and, repeated as compact sorted-key JSON, in the token request's `operator` form
|
|
90
|
+
parameter. `DRAFT_REVISION` names the draft revision implemented (`"10"`).
|
|
91
|
+
|
|
92
|
+
### Presenting the token at a resource
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const ca = new ClientAttestation("pf.example.com", { popMethod: "dpop_combined" });
|
|
96
|
+
await ca.fetch("https://api.example.com/things"); // headers + one nonce retry
|
|
97
|
+
const headers = await ca.requestHeaders("GET", "https://api.example.com/things");
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`requestHeaders(method, url)` returns what to send for one request. For a Bearer token that is just
|
|
101
|
+
`Authorization: Bearer <t>`. When the AS answers `token_type: DPoP` (normal in `dpop_combined` mode) the
|
|
102
|
+
token is bound to the instance key that minted the attestation, so the SDK keeps that key with the cached
|
|
103
|
+
token and returns `Authorization: DPoP <t>` plus a fresh `DPoP` proof (`htm`, `htu` without query or
|
|
104
|
+
fragment, `ath`, and the last `DPoP-Nonce` that origin sent). `authorizationHeader()` still works, but for
|
|
105
|
+
a DPoP-bound token it returns only the `DPoP` scheme - a resource will also want the proof.
|
|
106
|
+
|
|
107
|
+
`ca.fetch` resends once when a resource answers with a `use_dpop_nonce` challenge (401
|
|
108
|
+
`WWW-Authenticate: DPoP error="use_dpop_nonce"`, or a 400 JSON error) and a `DPoP-Nonce`. String,
|
|
109
|
+
`URLSearchParams`, `ArrayBuffer` and `Request` bodies are resent; a one-shot `ReadableStream` body is not,
|
|
110
|
+
and the challenge response is returned instead. The token request itself retries once on an AS's
|
|
111
|
+
`use_dpop_nonce` demand.
|
|
112
|
+
|
|
113
|
+
### Failing closed
|
|
114
|
+
|
|
115
|
+
- If the attester advertises a `challenge_endpoint` and the challenge cannot be fetched, `token()` throws
|
|
116
|
+
`ClientAttestationError`. Pass `requireChallenge: false` to mint without one instead.
|
|
117
|
+
- `CLIENT_ATTESTATION_TOKEN_FILE` or `SPIFFE_ENDPOINT_SOCKET` pointing at a missing path throws
|
|
118
|
+
`EvidenceNotFound` naming the variable - it never falls through to another identity source.
|
|
119
|
+
- `challengeAtToken: false` keeps the attester challenge in the mint's instance proof but leaves it out
|
|
120
|
+
of the token-endpoint PoP `challenge` claim / DPoP `nonce` - for attesters that consume a challenge at
|
|
121
|
+
mint and reject it when the token request presents it again.
|
|
122
|
+
- The attester URL and every endpoint the attester advertises must be `https`, except loopback
|
|
123
|
+
(`localhost`, `127.0.0.1`, `::1`). Pass `allowInsecure: true` for, say, an in-cluster plain-http PF.
|
|
124
|
+
|
|
125
|
+
### Other attesters
|
|
126
|
+
|
|
127
|
+
`ClientAttestation` speaks PingFederate's discovery and mint protocol by default. For another attester,
|
|
128
|
+
pass the `profile` option (your own `AttesterProfile`), or the `metadata` option to give its endpoints
|
|
129
|
+
directly and skip discovery: `new ClientAttestation({ metadata: { evidenceAudience, attestationEndpoint,
|
|
130
|
+
tokenEndpoint } })`. `AttestationIssuanceClient.create` takes `{ profile }` too. See
|
|
131
|
+
[`docs/attester-profiles.md`](../docs/attester-profiles.md).
|
|
132
|
+
|
|
133
|
+
The validator's `ProtectedResource` strips control characters from every quoted `WWW-Authenticate` value,
|
|
134
|
+
and validation failures never echo the token's own `alg`, `kid`, `iss` or `aud` back in
|
|
135
|
+
`error_description`.
|
|
136
|
+
|
|
137
|
+
## Test & interop
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npm test # vitest — self-verifies each artifact with jose
|
|
141
|
+
npm run test:edge # the same SDK in workerd, Cloudflare's Workers runtime, with no Node compatibility
|
|
142
|
+
npm run emit # writes ../vectors/out/typescript.json for the cross-language Java verifier
|
|
143
|
+
```
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type SigningKeyPair } from "./signing-key-pair.js";
|
|
2
|
+
/** Where the attester lives and what it expects. */
|
|
3
|
+
export interface AttesterMetadata {
|
|
4
|
+
/** The audience the workload's platform identity is requested for, and the instance proof's `aud`. */
|
|
5
|
+
evidenceAudience?: string;
|
|
6
|
+
/** Where the mint request goes. */
|
|
7
|
+
attestationEndpoint?: string;
|
|
8
|
+
/** The authorization server's token endpoint. A profile fills in its own fallback. */
|
|
9
|
+
tokenEndpoint?: string;
|
|
10
|
+
/** The draft's challenge endpoint, if the attester issues challenges. */
|
|
11
|
+
challengeEndpoint?: string;
|
|
12
|
+
/** The Client Attestation PoP `aud` (the AS issuer); falls back to the token endpoint URL. */
|
|
13
|
+
popAudience?: string;
|
|
14
|
+
/** The raw discovery document, when there was one; returned by `ClientAttestation.discovery()`. */
|
|
15
|
+
document?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/** What the attester returned: the attestation, and its lifetime in seconds if it said. */
|
|
18
|
+
export interface MintResult {
|
|
19
|
+
attestation: string;
|
|
20
|
+
expiresIn?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* How a profile talks to the attester. The client supplies it, so every call shares the client's timeout,
|
|
24
|
+
* redirect and size limits, https rule and logging (`http.failed`).
|
|
25
|
+
*/
|
|
26
|
+
export interface AttesterTransport {
|
|
27
|
+
/**
|
|
28
|
+
* Send `body` (as JSON, if given) and resolve to the JSON object response. `step` names the call in
|
|
29
|
+
* logs (`discover`, `mint`). Rejects on a non-2xx status or a body that is not a JSON object.
|
|
30
|
+
*/
|
|
31
|
+
requestJson(step: string, method: string, url: string, body?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The attester-specific part of the flow. Implement it and pass it as the `profile` option.
|
|
35
|
+
*
|
|
36
|
+
* @experimental See docs/api.md: new in 0.4.0 and fitted to one real attester so far; a method added to it would break custom profiles.
|
|
37
|
+
*/
|
|
38
|
+
export interface AttesterProfile {
|
|
39
|
+
/**
|
|
40
|
+
* Find the attester's endpoints. Called once per client and cached; not called when the caller passes
|
|
41
|
+
* static `metadata`.
|
|
42
|
+
*/
|
|
43
|
+
discover(transport: AttesterTransport, attesterUrl: string | undefined): Promise<AttesterMetadata>;
|
|
44
|
+
/** Exchange the evidence and a proof of the instance key for an attestation. */
|
|
45
|
+
mint(transport: AttesterTransport, metadata: AttesterMetadata, request: MintRequest): Promise<MintResult>;
|
|
46
|
+
}
|
|
47
|
+
/** Everything a profile needs to mint one attestation. */
|
|
48
|
+
export declare class MintRequest {
|
|
49
|
+
/** The fresh key the attestation will be bound to (its `cnf`). */
|
|
50
|
+
readonly instanceKey: SigningKeyPair;
|
|
51
|
+
/** The workload's platform identity token (a JWT-SVID or equivalent). */
|
|
52
|
+
readonly evidence: string;
|
|
53
|
+
/** The attester-issued challenge, if any. */
|
|
54
|
+
readonly challenge?: string;
|
|
55
|
+
/** Set by {@link AttestationIssuanceClient}; unset in the evidence-first one-call flow. */
|
|
56
|
+
readonly clientId?: string;
|
|
57
|
+
/** Optional RFC 9396 access request. */
|
|
58
|
+
readonly authorizationDetails?: Array<Record<string, unknown>>;
|
|
59
|
+
/** Optional operator object (who answers for this workload). */
|
|
60
|
+
readonly operator?: Record<string, unknown>;
|
|
61
|
+
constructor(init: {
|
|
62
|
+
instanceKey: SigningKeyPair;
|
|
63
|
+
evidence: string;
|
|
64
|
+
challenge?: string;
|
|
65
|
+
clientId?: string;
|
|
66
|
+
authorizationDetails?: Array<Record<string, unknown>>;
|
|
67
|
+
operator?: Record<string, unknown>;
|
|
68
|
+
});
|
|
69
|
+
/** Sign `claims` as a compact JWS with the instance key, under header `typ` (no `jwk`). */
|
|
70
|
+
sign(claims: Record<string, unknown>, typ: string): Promise<string>;
|
|
71
|
+
/** A proof of possession of the instance key: `{aud, jti, iat[, challenge]}` signed with it. */
|
|
72
|
+
instanceProof(typ: string, audience: string | undefined): Promise<string>;
|
|
73
|
+
}
|
|
74
|
+
/** The instance-key proof typ of the PingFederate profile (server InstanceKeyProofValidator.TYP). */
|
|
75
|
+
export declare const INSTANCE_PROOF_TYP = "oauth-attestation-instance-proof+jwt";
|
|
76
|
+
/**
|
|
77
|
+
* The attester this SDK was built against (PingFederate), and the default.
|
|
78
|
+
*
|
|
79
|
+
* - Discovery: `GET {attesterUrl}/.well-known/client-attester`, a JSON object with `evidence_audience`,
|
|
80
|
+
* `attestation_endpoint`, `challenge_endpoint`, `token_endpoint` and `pop_audience`. With no
|
|
81
|
+
* `token_endpoint`, `{attesterUrl}/as/token.oauth2`.
|
|
82
|
+
* - Mint: `POST attestation_endpoint` with JSON `{[client_id,] instance_key, svid, proof
|
|
83
|
+
* [, authorization_details][, operator]}`, where `proof` is `{aud: evidence_audience, jti, iat
|
|
84
|
+
* [, challenge]}` signed by the instance key with `typ` `oauth-attestation-instance-proof+jwt`. The
|
|
85
|
+
* response is `{"attestation": ..., "expires_in": ...}`.
|
|
86
|
+
*/
|
|
87
|
+
export declare class PingFederateProfile implements AttesterProfile {
|
|
88
|
+
static readonly WELL_KNOWN_PATH = "/.well-known/client-attester";
|
|
89
|
+
static readonly INSTANCE_PROOF_TYP = "oauth-attestation-instance-proof+jwt";
|
|
90
|
+
static readonly DEFAULT_TOKEN_PATH = "/as/token.oauth2";
|
|
91
|
+
discover(transport: AttesterTransport, attesterUrl: string | undefined): Promise<AttesterMetadata>;
|
|
92
|
+
mint(transport: AttesterTransport, metadata: AttesterMetadata, request: MintRequest): Promise<MintResult>;
|
|
93
|
+
}
|
package/dist/attester.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attester profiles: the part of the flow that differs from one attester to the next.
|
|
3
|
+
*
|
|
4
|
+
* The draft says what a Client Attestation, its PoP and the challenge endpoint look like, and how they
|
|
5
|
+
* are presented at the token endpoint. It does not say how a workload gets an attestation from its
|
|
6
|
+
* attester. That part - where the attester's endpoints are listed, what the mint request looks like, how
|
|
7
|
+
* the instance key is proven, and what comes back - is an {@link AttesterProfile}.
|
|
8
|
+
*
|
|
9
|
+
* {@link ClientAttestation} and {@link AttestationIssuanceClient} use {@link PingFederateProfile} unless
|
|
10
|
+
* told otherwise, which is exactly the behaviour of earlier releases. See docs/attester-profiles.md.
|
|
11
|
+
*/
|
|
12
|
+
import { ClientAttestationError } from "./errors.js";
|
|
13
|
+
import { signCompact } from "./signing-key-pair.js";
|
|
14
|
+
/** Everything a profile needs to mint one attestation. */
|
|
15
|
+
export class MintRequest {
|
|
16
|
+
/** The fresh key the attestation will be bound to (its `cnf`). */
|
|
17
|
+
instanceKey;
|
|
18
|
+
/** The workload's platform identity token (a JWT-SVID or equivalent). */
|
|
19
|
+
evidence;
|
|
20
|
+
/** The attester-issued challenge, if any. */
|
|
21
|
+
challenge;
|
|
22
|
+
/** Set by {@link AttestationIssuanceClient}; unset in the evidence-first one-call flow. */
|
|
23
|
+
clientId;
|
|
24
|
+
/** Optional RFC 9396 access request. */
|
|
25
|
+
authorizationDetails;
|
|
26
|
+
/** Optional operator object (who answers for this workload). */
|
|
27
|
+
operator;
|
|
28
|
+
constructor(init) {
|
|
29
|
+
this.instanceKey = init.instanceKey;
|
|
30
|
+
this.evidence = init.evidence;
|
|
31
|
+
this.challenge = init.challenge;
|
|
32
|
+
this.clientId = init.clientId;
|
|
33
|
+
this.authorizationDetails = init.authorizationDetails;
|
|
34
|
+
this.operator = init.operator;
|
|
35
|
+
}
|
|
36
|
+
/** Sign `claims` as a compact JWS with the instance key, under header `typ` (no `jwk`). */
|
|
37
|
+
sign(claims, typ) {
|
|
38
|
+
return signCompact(claims, this.instanceKey, typ, false);
|
|
39
|
+
}
|
|
40
|
+
/** A proof of possession of the instance key: `{aud, jti, iat[, challenge]}` signed with it. */
|
|
41
|
+
instanceProof(typ, audience) {
|
|
42
|
+
const claims = {
|
|
43
|
+
aud: audience,
|
|
44
|
+
jti: crypto.randomUUID(),
|
|
45
|
+
iat: Math.floor(Date.now() / 1000),
|
|
46
|
+
};
|
|
47
|
+
if (this.challenge)
|
|
48
|
+
claims.challenge = this.challenge;
|
|
49
|
+
return this.sign(claims, typ);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The PingFederate profile's discovery document path.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export const WELL_KNOWN_PATH = "/.well-known/client-attester";
|
|
58
|
+
/** The instance-key proof typ of the PingFederate profile (server InstanceKeyProofValidator.TYP). */
|
|
59
|
+
export const INSTANCE_PROOF_TYP = "oauth-attestation-instance-proof+jwt";
|
|
60
|
+
/**
|
|
61
|
+
* The attester this SDK was built against (PingFederate), and the default.
|
|
62
|
+
*
|
|
63
|
+
* - Discovery: `GET {attesterUrl}/.well-known/client-attester`, a JSON object with `evidence_audience`,
|
|
64
|
+
* `attestation_endpoint`, `challenge_endpoint`, `token_endpoint` and `pop_audience`. With no
|
|
65
|
+
* `token_endpoint`, `{attesterUrl}/as/token.oauth2`.
|
|
66
|
+
* - Mint: `POST attestation_endpoint` with JSON `{[client_id,] instance_key, svid, proof
|
|
67
|
+
* [, authorization_details][, operator]}`, where `proof` is `{aud: evidence_audience, jti, iat
|
|
68
|
+
* [, challenge]}` signed by the instance key with `typ` `oauth-attestation-instance-proof+jwt`. The
|
|
69
|
+
* response is `{"attestation": ..., "expires_in": ...}`.
|
|
70
|
+
*/
|
|
71
|
+
export class PingFederateProfile {
|
|
72
|
+
static WELL_KNOWN_PATH = WELL_KNOWN_PATH;
|
|
73
|
+
static INSTANCE_PROOF_TYP = INSTANCE_PROOF_TYP;
|
|
74
|
+
static DEFAULT_TOKEN_PATH = "/as/token.oauth2";
|
|
75
|
+
async discover(transport, attesterUrl) {
|
|
76
|
+
if (!attesterUrl)
|
|
77
|
+
throw new Error("attesterUrl is required for discovery");
|
|
78
|
+
const doc = await transport.requestJson("discover", "GET", attesterUrl + WELL_KNOWN_PATH);
|
|
79
|
+
const str = (key) => (typeof doc[key] === "string" && doc[key] ? doc[key] : undefined);
|
|
80
|
+
return {
|
|
81
|
+
evidenceAudience: str("evidence_audience"),
|
|
82
|
+
attestationEndpoint: str("attestation_endpoint"),
|
|
83
|
+
// token_endpoint is advertised by current attesters; fall back to the standard PF path so an older
|
|
84
|
+
// discovery document still works from the host alone.
|
|
85
|
+
tokenEndpoint: str("token_endpoint") ?? attesterUrl + PingFederateProfile.DEFAULT_TOKEN_PATH,
|
|
86
|
+
challengeEndpoint: str("challenge_endpoint"),
|
|
87
|
+
popAudience: str("pop_audience"),
|
|
88
|
+
document: doc,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async mint(transport, metadata, request) {
|
|
92
|
+
if (!metadata.attestationEndpoint) {
|
|
93
|
+
throw new ClientAttestationError("attester discovery document has no attestation_endpoint");
|
|
94
|
+
}
|
|
95
|
+
const proof = await request.instanceProof(INSTANCE_PROOF_TYP, metadata.evidenceAudience);
|
|
96
|
+
const body = {};
|
|
97
|
+
if (request.clientId)
|
|
98
|
+
body.client_id = request.clientId;
|
|
99
|
+
body.instance_key = request.instanceKey.publicJwk();
|
|
100
|
+
body.svid = request.evidence;
|
|
101
|
+
body.proof = proof;
|
|
102
|
+
if (request.authorizationDetails)
|
|
103
|
+
body.authorization_details = request.authorizationDetails;
|
|
104
|
+
// Asked for at mint time so the ATTESTER is what states the operator, rather than the client
|
|
105
|
+
// asserting it about itself at the token endpoint. An attester that does not know it ignores it.
|
|
106
|
+
if (request.operator)
|
|
107
|
+
body.operator = request.operator;
|
|
108
|
+
const response = await transport.requestJson("mint", "POST", metadata.attestationEndpoint, body);
|
|
109
|
+
const attestation = response.attestation;
|
|
110
|
+
if (typeof attestation !== "string" || !attestation) {
|
|
111
|
+
throw new ClientAttestationError("attester response contained no attestation", {
|
|
112
|
+
body: JSON.stringify(response),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const expiresIn = response.expires_in;
|
|
116
|
+
return { attestation, expiresIn: typeof expiresIn === "number" ? expiresIn : undefined };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The discovery-document view of metadata: the raw document, or the snake_case fields that are set.
|
|
121
|
+
*
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export function metadataDocument(metadata) {
|
|
125
|
+
if (metadata.document)
|
|
126
|
+
return metadata.document;
|
|
127
|
+
const doc = {};
|
|
128
|
+
const fields = [
|
|
129
|
+
["evidence_audience", metadata.evidenceAudience],
|
|
130
|
+
["attestation_endpoint", metadata.attestationEndpoint],
|
|
131
|
+
["challenge_endpoint", metadata.challengeEndpoint],
|
|
132
|
+
["token_endpoint", metadata.tokenEndpoint],
|
|
133
|
+
["pop_audience", metadata.popAudience],
|
|
134
|
+
];
|
|
135
|
+
for (const [key, value] of fields)
|
|
136
|
+
if (value)
|
|
137
|
+
doc[key] = value;
|
|
138
|
+
return doc;
|
|
139
|
+
}
|