@atol-sh/js 0.4.3 → 0.5.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/CHANGELOG.md +13 -0
- package/README.md +83 -10
- package/RESPONSE_VAULT_PROTOCOL.md +9 -2
- package/dist/index.cjs +553 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -18
- package/dist/index.d.ts +36 -18
- package/dist/index.js +554 -360
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -39,138 +39,6 @@ function base64ToBytes(b64) {
|
|
|
39
39
|
}
|
|
40
40
|
return bytes;
|
|
41
41
|
}
|
|
42
|
-
var managerKeys = /* @__PURE__ */ new WeakMap();
|
|
43
|
-
var P256_COORDINATE = /^[A-Za-z0-9_-]{43}$/;
|
|
44
|
-
function canonicalPublicJWK(exported) {
|
|
45
|
-
if (exported.kty !== "EC" || exported.crv !== "P-256" || typeof exported.x !== "string" || !P256_COORDINATE.test(exported.x) || typeof exported.y !== "string" || !P256_COORDINATE.test(exported.y) || typeof exported.d === "string") {
|
|
46
|
-
throw new Error("DPoP: exported public key is invalid");
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
crv: "P-256",
|
|
50
|
-
kty: "EC",
|
|
51
|
-
x: exported.x,
|
|
52
|
-
y: exported.y
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function validP256KeyPair(keyPair) {
|
|
56
|
-
const privateAlgorithm = keyPair.privateKey.algorithm;
|
|
57
|
-
const publicAlgorithm = keyPair.publicKey.algorithm;
|
|
58
|
-
return keyPair.privateKey.type === "private" && keyPair.privateKey.extractable === false && keyPair.privateKey.usages.length === 1 && keyPair.privateKey.usages[0] === "sign" && privateAlgorithm.name === "ECDSA" && privateAlgorithm.namedCurve === "P-256" && keyPair.publicKey.type === "public" && publicAlgorithm.name === "ECDSA" && publicAlgorithm.namedCurve === "P-256";
|
|
59
|
-
}
|
|
60
|
-
function restoreDPoPKeyManager(keyPair) {
|
|
61
|
-
if (!validP256KeyPair(keyPair)) {
|
|
62
|
-
throw new Error("DPoP: stored authorization key is invalid");
|
|
63
|
-
}
|
|
64
|
-
let cachedJWK = null;
|
|
65
|
-
let cachedThumbprint = null;
|
|
66
|
-
async function pubJWK() {
|
|
67
|
-
if (!cachedJWK) {
|
|
68
|
-
cachedJWK = canonicalPublicJWK(
|
|
69
|
-
await crypto.subtle.exportKey(
|
|
70
|
-
"jwk",
|
|
71
|
-
keyPair.publicKey
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
return { ...cachedJWK };
|
|
76
|
-
}
|
|
77
|
-
const manager = {
|
|
78
|
-
async publicJWK() {
|
|
79
|
-
return pubJWK();
|
|
80
|
-
},
|
|
81
|
-
async thumbprint() {
|
|
82
|
-
if (!cachedThumbprint) {
|
|
83
|
-
cachedThumbprint = await jose.calculateJwkThumbprint(
|
|
84
|
-
await pubJWK(),
|
|
85
|
-
"sha256"
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return cachedThumbprint;
|
|
89
|
-
},
|
|
90
|
-
async signProof(method, url, options) {
|
|
91
|
-
const jwk = await pubJWK();
|
|
92
|
-
const header = {
|
|
93
|
-
typ: "dpop+jwt",
|
|
94
|
-
alg: "ES256",
|
|
95
|
-
jwk
|
|
96
|
-
};
|
|
97
|
-
const payload = {
|
|
98
|
-
jti: newJTI(),
|
|
99
|
-
htm: method.toUpperCase(),
|
|
100
|
-
htu: canonicalizeURL(url),
|
|
101
|
-
iat: Math.floor(Date.now() / 1e3)
|
|
102
|
-
};
|
|
103
|
-
if (options?.accessToken) {
|
|
104
|
-
payload.ath = await accessTokenHash(options.accessToken);
|
|
105
|
-
}
|
|
106
|
-
if (options?.nonce) {
|
|
107
|
-
payload.nonce = options.nonce;
|
|
108
|
-
}
|
|
109
|
-
const headerB64 = stringToBase64Url(JSON.stringify(header));
|
|
110
|
-
const payloadB64 = stringToBase64Url(JSON.stringify(payload));
|
|
111
|
-
const signingInput = `${headerB64}.${payloadB64}`;
|
|
112
|
-
const sigRaw = await crypto.subtle.sign(
|
|
113
|
-
{ name: "ECDSA", hash: "SHA-256" },
|
|
114
|
-
keyPair.privateKey,
|
|
115
|
-
new TextEncoder().encode(signingInput)
|
|
116
|
-
);
|
|
117
|
-
const sigB64 = bytesToBase64Url(new Uint8Array(sigRaw));
|
|
118
|
-
return `${signingInput}.${sigB64}`;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
managerKeys.set(manager, keyPair);
|
|
122
|
-
return manager;
|
|
123
|
-
}
|
|
124
|
-
function dpopKeyPair(manager) {
|
|
125
|
-
const keyPair = managerKeys.get(manager);
|
|
126
|
-
if (!keyPair) {
|
|
127
|
-
throw new Error("DPoP: key manager was not created by this SDK");
|
|
128
|
-
}
|
|
129
|
-
return keyPair;
|
|
130
|
-
}
|
|
131
|
-
async function createDPoPKeyManager() {
|
|
132
|
-
if (typeof crypto === "undefined" || typeof crypto.subtle === "undefined") {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
let keyPair;
|
|
136
|
-
try {
|
|
137
|
-
keyPair = await crypto.subtle.generateKey(
|
|
138
|
-
{ name: "ECDSA", namedCurve: "P-256" },
|
|
139
|
-
false,
|
|
140
|
-
// non-exportable
|
|
141
|
-
["sign"]
|
|
142
|
-
);
|
|
143
|
-
} catch {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
return restoreDPoPKeyManager(keyPair);
|
|
147
|
-
}
|
|
148
|
-
function canonicalizeURL(raw) {
|
|
149
|
-
let u;
|
|
150
|
-
try {
|
|
151
|
-
u = new URL(raw);
|
|
152
|
-
} catch {
|
|
153
|
-
throw new Error(`DPoP: cannot canonicalize htu, invalid URL: ${raw}`);
|
|
154
|
-
}
|
|
155
|
-
u.search = "";
|
|
156
|
-
u.hash = "";
|
|
157
|
-
return u.toString();
|
|
158
|
-
}
|
|
159
|
-
async function accessTokenHash(accessToken) {
|
|
160
|
-
const digest = await crypto.subtle.digest(
|
|
161
|
-
"SHA-256",
|
|
162
|
-
new TextEncoder().encode(accessToken)
|
|
163
|
-
);
|
|
164
|
-
return bytesToBase64Url(new Uint8Array(digest));
|
|
165
|
-
}
|
|
166
|
-
function newJTI() {
|
|
167
|
-
if (typeof crypto.randomUUID === "function") {
|
|
168
|
-
return crypto.randomUUID();
|
|
169
|
-
}
|
|
170
|
-
const bytes = new Uint8Array(16);
|
|
171
|
-
crypto.getRandomValues(bytes);
|
|
172
|
-
return bytesToBase64Url(bytes);
|
|
173
|
-
}
|
|
174
42
|
|
|
175
43
|
// src/oidc/credential-generation.ts
|
|
176
44
|
var STORAGE_VERSION = 1;
|
|
@@ -423,8 +291,8 @@ var RESPONSE_VAULT_DEFAULT_EXECUTION_LEASE_MS = 30 * 1e3;
|
|
|
423
291
|
var RESPONSE_VAULT_MAX_EXECUTION_LEASE_MS = 5 * 60 * 1e3;
|
|
424
292
|
var RESPONSE_VAULT_EXECUTION_LOCK_WAIT_MS = 5 * 1e3;
|
|
425
293
|
var RESPONSE_VAULT_CANONICAL_OPAQUE = /^[A-Za-z0-9_-]{43}$/;
|
|
426
|
-
var RESPONSE_VAULT_TERMINAL_PROOF_BYTES =
|
|
427
|
-
var RESPONSE_VAULT_TERMINAL_PROOF_LENGTH =
|
|
294
|
+
var RESPONSE_VAULT_TERMINAL_PROOF_BYTES = 74;
|
|
295
|
+
var RESPONSE_VAULT_TERMINAL_PROOF_LENGTH = 99;
|
|
428
296
|
var RESPONSE_VAULT_REQUEST_URI_PREFIX = "urn:ietf:params:oauth:request_uri:";
|
|
429
297
|
var RESPONSE_VAULT_TERMINAL_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
430
298
|
"invalid_request",
|
|
@@ -700,6 +568,181 @@ var ResponseVaultExecutionBusyError = class extends ResponseVaultAuthorizationBu
|
|
|
700
568
|
this.name = "ResponseVaultExecutionBusyError";
|
|
701
569
|
}
|
|
702
570
|
};
|
|
571
|
+
var ML_DSA_87 = "ML-DSA-87";
|
|
572
|
+
async function assertMLDSA87VerificationSupport() {
|
|
573
|
+
if (typeof globalThis.crypto?.subtle?.verify !== "function") {
|
|
574
|
+
throw new Error("WebCrypto ML-DSA-87 verification is unavailable");
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
await jose.importJWK(
|
|
578
|
+
{ kty: "AKP", alg: ML_DSA_87, pub: "A".repeat(3456), key_ops: ["verify"] },
|
|
579
|
+
ML_DSA_87
|
|
580
|
+
);
|
|
581
|
+
} catch {
|
|
582
|
+
throw new Error("WebCrypto ML-DSA-87 verification is unavailable");
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
var managerKeys = /* @__PURE__ */ new WeakMap();
|
|
586
|
+
var MAX_DPOP_PROOF_BYTES = 24 << 10;
|
|
587
|
+
var P256_COORDINATE = /^[A-Za-z0-9_-]{43}$/;
|
|
588
|
+
var ML_DSA_87_PUBLIC_KEY = /^[A-Za-z0-9_-]{3456}$/;
|
|
589
|
+
function canonicalPublicJWK(exported, algorithm) {
|
|
590
|
+
if (algorithm === ML_DSA_87) {
|
|
591
|
+
if (exported.kty !== "AKP" || exported.alg !== algorithm || typeof exported.pub !== "string" || exported.pub.length !== 3456 || !ML_DSA_87_PUBLIC_KEY.test(exported.pub) || "priv" in exported) {
|
|
592
|
+
throw new Error("DPoP: exported ML-DSA-87 public key is invalid");
|
|
593
|
+
}
|
|
594
|
+
return { kty: "AKP", alg: algorithm, pub: exported.pub };
|
|
595
|
+
}
|
|
596
|
+
if (exported.kty !== "EC" || exported.crv !== "P-256" || typeof exported.x !== "string" || !P256_COORDINATE.test(exported.x) || typeof exported.y !== "string" || !P256_COORDINATE.test(exported.y) || typeof exported.d === "string") {
|
|
597
|
+
throw new Error("DPoP: exported public key is invalid");
|
|
598
|
+
}
|
|
599
|
+
return {
|
|
600
|
+
crv: "P-256",
|
|
601
|
+
kty: "EC",
|
|
602
|
+
x: exported.x,
|
|
603
|
+
y: exported.y
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function proofAlgorithm(keyPair) {
|
|
607
|
+
const { publicKey, privateKey } = keyPair;
|
|
608
|
+
if (privateKey.type !== "private" || privateKey.extractable !== false || privateKey.usages.length !== 1 || privateKey.usages[0] !== "sign" || publicKey.type !== "public") {
|
|
609
|
+
return null;
|
|
610
|
+
}
|
|
611
|
+
const privateAlgorithm = privateKey.algorithm;
|
|
612
|
+
const publicAlgorithm = publicKey.algorithm;
|
|
613
|
+
if (privateAlgorithm.name === ML_DSA_87 && publicAlgorithm.name === ML_DSA_87) {
|
|
614
|
+
return ML_DSA_87;
|
|
615
|
+
}
|
|
616
|
+
if (privateAlgorithm.name === "ECDSA" && privateAlgorithm.namedCurve === "P-256" && publicAlgorithm.name === "ECDSA" && publicAlgorithm.namedCurve === "P-256") {
|
|
617
|
+
return "ES256";
|
|
618
|
+
}
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
function restoreDPoPKeyManager(keyPair) {
|
|
622
|
+
const restoredAlgorithm = proofAlgorithm(keyPair);
|
|
623
|
+
if (!restoredAlgorithm) {
|
|
624
|
+
throw new Error("DPoP: stored authorization key is invalid");
|
|
625
|
+
}
|
|
626
|
+
const algorithm = restoredAlgorithm;
|
|
627
|
+
let cachedJWK = null;
|
|
628
|
+
let cachedThumbprint = null;
|
|
629
|
+
async function pubJWK() {
|
|
630
|
+
if (!cachedJWK) {
|
|
631
|
+
cachedJWK = canonicalPublicJWK(
|
|
632
|
+
await crypto.subtle.exportKey("jwk", keyPair.publicKey),
|
|
633
|
+
algorithm
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
return { ...cachedJWK };
|
|
637
|
+
}
|
|
638
|
+
const manager = {
|
|
639
|
+
async publicJWK() {
|
|
640
|
+
return pubJWK();
|
|
641
|
+
},
|
|
642
|
+
async thumbprint() {
|
|
643
|
+
if (!cachedThumbprint) {
|
|
644
|
+
cachedThumbprint = await jose.calculateJwkThumbprint(
|
|
645
|
+
await pubJWK(),
|
|
646
|
+
"sha256"
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
return cachedThumbprint;
|
|
650
|
+
},
|
|
651
|
+
async signProof(method, url, options) {
|
|
652
|
+
const jwk = await pubJWK();
|
|
653
|
+
const header = {
|
|
654
|
+
typ: "dpop+jwt",
|
|
655
|
+
alg: algorithm,
|
|
656
|
+
jwk
|
|
657
|
+
};
|
|
658
|
+
const payload = {
|
|
659
|
+
jti: newJTI(),
|
|
660
|
+
htm: method.toUpperCase(),
|
|
661
|
+
htu: canonicalizeURL(url),
|
|
662
|
+
iat: Math.floor(Date.now() / 1e3)
|
|
663
|
+
};
|
|
664
|
+
if (options?.accessToken) {
|
|
665
|
+
payload.ath = await accessTokenHash(options.accessToken);
|
|
666
|
+
}
|
|
667
|
+
if (options?.nonce) {
|
|
668
|
+
payload.nonce = options.nonce;
|
|
669
|
+
}
|
|
670
|
+
const headerB64 = stringToBase64Url(JSON.stringify(header));
|
|
671
|
+
const payloadB64 = stringToBase64Url(JSON.stringify(payload));
|
|
672
|
+
const signingInput = `${headerB64}.${payloadB64}`;
|
|
673
|
+
const sigRaw = await crypto.subtle.sign(
|
|
674
|
+
algorithm === "ES256" ? { name: "ECDSA", hash: "SHA-256" } : algorithm,
|
|
675
|
+
keyPair.privateKey,
|
|
676
|
+
new TextEncoder().encode(signingInput)
|
|
677
|
+
);
|
|
678
|
+
const sigB64 = bytesToBase64Url(new Uint8Array(sigRaw));
|
|
679
|
+
const proof = `${signingInput}.${sigB64}`;
|
|
680
|
+
if (proof.length > MAX_DPOP_PROOF_BYTES) {
|
|
681
|
+
throw new Error("DPoP: proof exceeds size limit");
|
|
682
|
+
}
|
|
683
|
+
return proof;
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
managerKeys.set(manager, keyPair);
|
|
687
|
+
return manager;
|
|
688
|
+
}
|
|
689
|
+
function dpopKeyPair(manager) {
|
|
690
|
+
const keyPair = managerKeys.get(manager);
|
|
691
|
+
if (!keyPair) {
|
|
692
|
+
throw new Error("DPoP: key manager was not created by this SDK");
|
|
693
|
+
}
|
|
694
|
+
return keyPair;
|
|
695
|
+
}
|
|
696
|
+
function assertMLDSA87DPoPKey(keyPair) {
|
|
697
|
+
if (!keyPair || proofAlgorithm(keyPair) !== ML_DSA_87) {
|
|
698
|
+
throw new Error("DPoP: ML-DSA-87 is required for the authorization key");
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
async function createDPoPKeyManager(algorithm = ML_DSA_87) {
|
|
702
|
+
if (typeof crypto === "undefined" || typeof crypto.subtle === "undefined") {
|
|
703
|
+
return null;
|
|
704
|
+
}
|
|
705
|
+
let keyPair;
|
|
706
|
+
try {
|
|
707
|
+
keyPair = algorithm === ML_DSA_87 ? await crypto.subtle.generateKey(algorithm, false, ["sign", "verify"]) : await crypto.subtle.generateKey(
|
|
708
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
709
|
+
false,
|
|
710
|
+
["sign"]
|
|
711
|
+
);
|
|
712
|
+
} catch {
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
715
|
+
if (!("privateKey" in keyPair) || proofAlgorithm(keyPair) !== algorithm) {
|
|
716
|
+
throw new Error("DPoP: WebCrypto returned an unexpected proof key");
|
|
717
|
+
}
|
|
718
|
+
return restoreDPoPKeyManager(keyPair);
|
|
719
|
+
}
|
|
720
|
+
function canonicalizeURL(raw) {
|
|
721
|
+
let u;
|
|
722
|
+
try {
|
|
723
|
+
u = new URL(raw);
|
|
724
|
+
} catch {
|
|
725
|
+
throw new Error(`DPoP: cannot canonicalize htu, invalid URL: ${raw}`);
|
|
726
|
+
}
|
|
727
|
+
u.search = "";
|
|
728
|
+
u.hash = "";
|
|
729
|
+
return u.toString();
|
|
730
|
+
}
|
|
731
|
+
async function accessTokenHash(accessToken) {
|
|
732
|
+
const digest = await crypto.subtle.digest(
|
|
733
|
+
"SHA-256",
|
|
734
|
+
new TextEncoder().encode(accessToken)
|
|
735
|
+
);
|
|
736
|
+
return bytesToBase64Url(new Uint8Array(digest));
|
|
737
|
+
}
|
|
738
|
+
function newJTI() {
|
|
739
|
+
if (typeof crypto.randomUUID === "function") {
|
|
740
|
+
return crypto.randomUUID();
|
|
741
|
+
}
|
|
742
|
+
const bytes = new Uint8Array(16);
|
|
743
|
+
crypto.getRandomValues(bytes);
|
|
744
|
+
return bytesToBase64Url(bytes);
|
|
745
|
+
}
|
|
703
746
|
|
|
704
747
|
// src/oidc/response-vault-storage-validation.ts
|
|
705
748
|
function randomOpaque() {
|
|
@@ -4423,7 +4466,7 @@ function bootstrapAttemptChallenge(envelope, requestStartedAt) {
|
|
|
4423
4466
|
);
|
|
4424
4467
|
try {
|
|
4425
4468
|
const raw = base64ToBytes(capability);
|
|
4426
|
-
if (bytesToBase64Url(raw) !== capability || raw[0] !==
|
|
4469
|
+
if (bytesToBase64Url(raw) !== capability || raw[0] !== 2 || raw[1] !== 3) {
|
|
4427
4470
|
throw new Error();
|
|
4428
4471
|
}
|
|
4429
4472
|
let proofDeadline = 0n;
|
|
@@ -4633,6 +4676,11 @@ var ResponseVaultContext = class {
|
|
|
4633
4676
|
throw new Error("response vault: authorization authority was superseded");
|
|
4634
4677
|
}
|
|
4635
4678
|
}
|
|
4679
|
+
assertActiveProofKey(authorization) {
|
|
4680
|
+
if (this.config.dpopAlgorithm !== "ES256") {
|
|
4681
|
+
assertMLDSA87DPoPKey(dpopKeyPair(authorization.dpopKey));
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4636
4684
|
activeReference() {
|
|
4637
4685
|
const value = this.storage().getItem(this.pointerKey);
|
|
4638
4686
|
if (value === null) return null;
|
|
@@ -5847,6 +5895,11 @@ var ResponseVaultCustodyLayer = class extends ResponseVaultRejection {
|
|
|
5847
5895
|
if (abandonedCleanupError !== void 0) {
|
|
5848
5896
|
throw new ResponseVaultCleanupPendingError(void 0);
|
|
5849
5897
|
}
|
|
5898
|
+
try {
|
|
5899
|
+
this.assertActiveProofKey(authorization);
|
|
5900
|
+
} catch (error) {
|
|
5901
|
+
failAfterCleanup(error);
|
|
5902
|
+
}
|
|
5850
5903
|
this.setActive(authorization.reference);
|
|
5851
5904
|
return authorization;
|
|
5852
5905
|
}
|
|
@@ -6513,7 +6566,8 @@ function userFromTokenResponse(tokens) {
|
|
|
6513
6566
|
var ORDINARY_AUTHORIZATION_DB_NAME = "atol-sdk-browser-auth";
|
|
6514
6567
|
var ORDINARY_AUTHORIZATION_DB_VERSION = 2;
|
|
6515
6568
|
var ORDINARY_AUTHORIZATION_STORE = "ordinary-authorizations";
|
|
6516
|
-
var
|
|
6569
|
+
var HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION = 2;
|
|
6570
|
+
var ORDINARY_AUTHORIZATION_RECORD_VERSION = 3;
|
|
6517
6571
|
var ORDINARY_AUTHORIZATION_POINTER_VERSION = 1;
|
|
6518
6572
|
var ORDINARY_AUTHORIZATION_PROTOCOL_VERSION = 2;
|
|
6519
6573
|
var AUTHORIZATION_CODE_LIFETIME_SECONDS = 600;
|
|
@@ -6524,12 +6578,13 @@ var CALLBACK_CLAIM_LIFETIME_MS = 2 * 6e4;
|
|
|
6524
6578
|
var CALLBACK_EXCHANGE_TIMEOUT_MS = 3e4;
|
|
6525
6579
|
var MAX_PAR_RESPONSE_BYTES = 16 * 1024;
|
|
6526
6580
|
var MAX_SETTLEMENT_RESPONSE_BYTES = 1024;
|
|
6527
|
-
var TERMINAL_PROOF_BYTES =
|
|
6528
|
-
var TERMINAL_PROOF_LENGTH =
|
|
6581
|
+
var TERMINAL_PROOF_BYTES = 74;
|
|
6582
|
+
var TERMINAL_PROOF_LENGTH = 99;
|
|
6529
6583
|
var REQUEST_URI_PREFIX = "urn:ietf:params:oauth:request_uri:";
|
|
6530
6584
|
var OIDC_CLIENT_STATE = /^[0-9a-f]{32}$/;
|
|
6531
6585
|
var CANONICAL_NONCE = /^[0-9a-f]{64}$/;
|
|
6532
6586
|
var CANONICAL_SHA256 = /^[A-Za-z0-9_-]{43}$/;
|
|
6587
|
+
var CANONICAL_SHA384 = /^[A-Za-z0-9_-]{64}$/;
|
|
6533
6588
|
var CANONICAL_AUTHORIZATION_CODE = /^[A-Za-z0-9._~-]{1,8192}$/;
|
|
6534
6589
|
function validCanonicalAttemptCapability(value) {
|
|
6535
6590
|
if (typeof value !== "string" || value.length !== TERMINAL_PROOF_LENGTH) {
|
|
@@ -6537,7 +6592,7 @@ function validCanonicalAttemptCapability(value) {
|
|
|
6537
6592
|
}
|
|
6538
6593
|
try {
|
|
6539
6594
|
const raw = base64ToBytes(value);
|
|
6540
|
-
return raw.length === TERMINAL_PROOF_BYTES && bytesToBase64Url(raw) === value && raw[0] ===
|
|
6595
|
+
return raw.length === TERMINAL_PROOF_BYTES && bytesToBase64Url(raw) === value && raw[0] === 2 && raw[1] === 2;
|
|
6541
6596
|
} catch {
|
|
6542
6597
|
return false;
|
|
6543
6598
|
}
|
|
@@ -6593,16 +6648,32 @@ function validCanonicalSHA256(value) {
|
|
|
6593
6648
|
return false;
|
|
6594
6649
|
}
|
|
6595
6650
|
}
|
|
6651
|
+
function validOrdinaryAuthorizationRequestURI(value, historicalTerminalProof = false) {
|
|
6652
|
+
if (typeof value !== "string" || !value.startsWith(REQUEST_URI_PREFIX)) {
|
|
6653
|
+
return false;
|
|
6654
|
+
}
|
|
6655
|
+
const root = value.slice(REQUEST_URI_PREFIX.length);
|
|
6656
|
+
if (root.length === 64) {
|
|
6657
|
+
return !historicalTerminalProof && CANONICAL_SHA384.test(root);
|
|
6658
|
+
}
|
|
6659
|
+
return validCanonicalSHA256(root);
|
|
6660
|
+
}
|
|
6596
6661
|
function validCanonicalAuthorizationCode(value) {
|
|
6597
6662
|
return CANONICAL_AUTHORIZATION_CODE.test(value);
|
|
6598
6663
|
}
|
|
6599
|
-
|
|
6664
|
+
function isLegacyAuthorizationCodeCommitment(value) {
|
|
6665
|
+
return value !== null && validCanonicalSHA256(value);
|
|
6666
|
+
}
|
|
6667
|
+
function validAuthorizationCodeCommitment(value) {
|
|
6668
|
+
return typeof value === "string" && CANONICAL_SHA384.test(value);
|
|
6669
|
+
}
|
|
6670
|
+
async function authorizationCodeCommitment(value) {
|
|
6600
6671
|
if (!validCanonicalAuthorizationCode(value)) {
|
|
6601
6672
|
throw new Error("ordinary browser authorization: callback code is invalid");
|
|
6602
6673
|
}
|
|
6603
6674
|
const digest = await crypto.subtle.digest(
|
|
6604
|
-
"SHA-
|
|
6605
|
-
new TextEncoder().encode(value)
|
|
6675
|
+
"SHA-384",
|
|
6676
|
+
new TextEncoder().encode(`atol.ordinary-authorization.callback-code.v2\0${value}`)
|
|
6606
6677
|
);
|
|
6607
6678
|
return bytesToBase64Url(new Uint8Array(digest));
|
|
6608
6679
|
}
|
|
@@ -7293,9 +7364,7 @@ function admittedSilentAuthorizationURL(opts) {
|
|
|
7293
7364
|
}
|
|
7294
7365
|
const names = new Set(entries.map(([name]) => name));
|
|
7295
7366
|
const requestUri = authorization.searchParams.get("request_uri");
|
|
7296
|
-
if (names.size !== 2 || !names.has("client_id") || !names.has("request_uri") ||
|
|
7297
|
-
requestUri.slice(REQUEST_URI_PREFIX.length)
|
|
7298
|
-
)) {
|
|
7367
|
+
if (names.size !== 2 || !names.has("client_id") || !names.has("request_uri") || !validOrdinaryAuthorizationRequestURI(requestUri)) {
|
|
7299
7368
|
throw new Error(
|
|
7300
7369
|
"silent authorization: admitted PAR navigation URL is invalid"
|
|
7301
7370
|
);
|
|
@@ -7540,16 +7609,16 @@ function createBrowserAuthActions(runtime) {
|
|
|
7540
7609
|
runtime.redirectUri
|
|
7541
7610
|
);
|
|
7542
7611
|
if (precedingLogout) await precedingLogout;
|
|
7543
|
-
const authorizationGeneration = credentialGenerationForLogin(
|
|
7544
|
-
runtime.credentialGenerationBinding
|
|
7545
|
-
);
|
|
7546
|
-
onGeneration?.(authorizationGeneration);
|
|
7547
7612
|
const authorizationEpoch = runtime.credentialEpoch;
|
|
7548
7613
|
await runtime.credentialMutationTail;
|
|
7549
7614
|
await runtime.lifecycleOps.ensureRuntimeInitialized();
|
|
7550
7615
|
if (runtime.destroyed || authorizationEpoch !== runtime.credentialEpoch) {
|
|
7551
7616
|
throw new StaleCredentialTransactionError();
|
|
7552
7617
|
}
|
|
7618
|
+
const authorizationGeneration = credentialGenerationForLogin(
|
|
7619
|
+
runtime.credentialGenerationBinding
|
|
7620
|
+
);
|
|
7621
|
+
onGeneration?.(authorizationGeneration);
|
|
7553
7622
|
runtime.sessionOps.assertCredentialAuthority(
|
|
7554
7623
|
authorizationGeneration
|
|
7555
7624
|
);
|
|
@@ -7595,7 +7664,8 @@ function createBrowserAuthActions(runtime) {
|
|
|
7595
7664
|
returnTo,
|
|
7596
7665
|
authorizationGeneration
|
|
7597
7666
|
),
|
|
7598
|
-
createDPoPKey:
|
|
7667
|
+
createDPoPKey: runtime.createDPoPKey,
|
|
7668
|
+
requireMLDSA87DPoP: runtime.requireMLDSA87 && runtime.useDPoP
|
|
7599
7669
|
});
|
|
7600
7670
|
}
|
|
7601
7671
|
function beginLogin(options) {
|
|
@@ -8017,6 +8087,9 @@ function assertOrdinaryAuthorizationDPoPBinding(binding, custody) {
|
|
|
8017
8087
|
return dpop;
|
|
8018
8088
|
}
|
|
8019
8089
|
async function exchangeOrdinaryAuthorizationCode(binding, callback, dpop) {
|
|
8090
|
+
if (binding.useDPoP && binding.requireMLDSA87) {
|
|
8091
|
+
assertMLDSA87DPoPKey(dpop ? dpopKeyPair(dpop) : null);
|
|
8092
|
+
}
|
|
8020
8093
|
const controller = new AbortController();
|
|
8021
8094
|
const timeout = setTimeout(
|
|
8022
8095
|
() => controller.abort(),
|
|
@@ -8126,6 +8199,93 @@ function stripOrdinaryAuthorizationResponseFromHistory(redirectUri) {
|
|
|
8126
8199
|
}
|
|
8127
8200
|
}
|
|
8128
8201
|
|
|
8202
|
+
// src/oidc/ordinary-authorization-lock.ts
|
|
8203
|
+
async function acquireOrdinaryAuthorizationCallbackLock(record) {
|
|
8204
|
+
if (typeof navigator === "undefined" || !navigator.locks || typeof navigator.locks.request !== "function") {
|
|
8205
|
+
throw new Error(
|
|
8206
|
+
"ordinary browser authorization: Web Locks is required"
|
|
8207
|
+
);
|
|
8208
|
+
}
|
|
8209
|
+
if (record.version !== HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION && record.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION) {
|
|
8210
|
+
throw new Error("ordinary browser authorization: unsupported lock format");
|
|
8211
|
+
}
|
|
8212
|
+
const historical = record.version === HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION;
|
|
8213
|
+
const digest = await crypto.subtle.digest(
|
|
8214
|
+
historical ? "SHA-256" : "SHA-384",
|
|
8215
|
+
new TextEncoder().encode(record.slotKey)
|
|
8216
|
+
);
|
|
8217
|
+
const namespace = historical ? "atol:ordinary-callback:" : "atol:ordinary-callback:v3:";
|
|
8218
|
+
const name = namespace + bytesToBase64Url(new Uint8Array(digest));
|
|
8219
|
+
let releaseHold;
|
|
8220
|
+
const hold = new Promise((resolve) => {
|
|
8221
|
+
releaseHold = resolve;
|
|
8222
|
+
});
|
|
8223
|
+
let resolveAcquired;
|
|
8224
|
+
let rejectAcquired;
|
|
8225
|
+
const acquired = new Promise((resolve, reject) => {
|
|
8226
|
+
resolveAcquired = resolve;
|
|
8227
|
+
rejectAcquired = reject;
|
|
8228
|
+
});
|
|
8229
|
+
let acquisitionSettled = false;
|
|
8230
|
+
const request = navigator.locks.request(
|
|
8231
|
+
name,
|
|
8232
|
+
{ mode: "exclusive", ifAvailable: true },
|
|
8233
|
+
async (lock) => {
|
|
8234
|
+
if (!lock) {
|
|
8235
|
+
acquisitionSettled = true;
|
|
8236
|
+
rejectAcquired(new OrdinaryAuthorizationPendingError());
|
|
8237
|
+
return;
|
|
8238
|
+
}
|
|
8239
|
+
acquisitionSettled = true;
|
|
8240
|
+
resolveAcquired();
|
|
8241
|
+
await hold;
|
|
8242
|
+
}
|
|
8243
|
+
);
|
|
8244
|
+
void request.catch((error) => {
|
|
8245
|
+
if (!acquisitionSettled) rejectAcquired(error);
|
|
8246
|
+
});
|
|
8247
|
+
try {
|
|
8248
|
+
await acquired;
|
|
8249
|
+
} catch (error) {
|
|
8250
|
+
releaseHold();
|
|
8251
|
+
try {
|
|
8252
|
+
await request;
|
|
8253
|
+
} catch (requestError) {
|
|
8254
|
+
throw requestError;
|
|
8255
|
+
}
|
|
8256
|
+
throw error;
|
|
8257
|
+
}
|
|
8258
|
+
let released = false;
|
|
8259
|
+
return {
|
|
8260
|
+
release: async () => {
|
|
8261
|
+
if (released) return;
|
|
8262
|
+
released = true;
|
|
8263
|
+
releaseHold();
|
|
8264
|
+
await request;
|
|
8265
|
+
}
|
|
8266
|
+
};
|
|
8267
|
+
}
|
|
8268
|
+
|
|
8269
|
+
// src/oidc/ordinary-authorization-legacy-proof.ts
|
|
8270
|
+
function legacyOrdinaryAuthorizationProofDeadline(value, kind) {
|
|
8271
|
+
if (typeof value !== "string" || value.length !== 78) return null;
|
|
8272
|
+
try {
|
|
8273
|
+
const raw = base64ToBytes(value);
|
|
8274
|
+
if (raw.length !== 58 || bytesToBase64Url(raw) !== value || raw[0] !== 1 || raw[1] !== kind) return null;
|
|
8275
|
+
let deadline = 0n;
|
|
8276
|
+
for (let index = 18; index < 26; index++) {
|
|
8277
|
+
deadline = deadline << 8n | BigInt(raw[index]);
|
|
8278
|
+
}
|
|
8279
|
+
return deadline > 0n ? deadline : null;
|
|
8280
|
+
} catch {
|
|
8281
|
+
return null;
|
|
8282
|
+
}
|
|
8283
|
+
}
|
|
8284
|
+
function isLegacyOrdinaryAuthorizationRecord(record) {
|
|
8285
|
+
const attempt = new URLSearchParams(record.form).get("atol_attempt_capability");
|
|
8286
|
+
return legacyOrdinaryAuthorizationProofDeadline(attempt, 2) !== null;
|
|
8287
|
+
}
|
|
8288
|
+
|
|
8129
8289
|
// src/oidc/ordinary-authorization-protocol.ts
|
|
8130
8290
|
function ordinaryAuthorizationDiscoveryContract(metadata, binding) {
|
|
8131
8291
|
if (metadata.issuer !== binding.issuer) {
|
|
@@ -8191,7 +8351,7 @@ function validOrdinaryAuthorizationTerminalProof(value, rootExpiresAt) {
|
|
|
8191
8351
|
}
|
|
8192
8352
|
try {
|
|
8193
8353
|
const raw = base64ToBytes(value);
|
|
8194
|
-
if (raw.length !== TERMINAL_PROOF_BYTES || bytesToBase64Url(raw) !== value || raw[0] !==
|
|
8354
|
+
if (raw.length !== TERMINAL_PROOF_BYTES || bytesToBase64Url(raw) !== value || raw[0] !== 2 || raw[1] !== 1) {
|
|
8195
8355
|
return false;
|
|
8196
8356
|
}
|
|
8197
8357
|
let deadline = 0n;
|
|
@@ -8273,9 +8433,7 @@ function admittedOrdinaryAuthorizationRecord(record, responseText) {
|
|
|
8273
8433
|
"atol_browser_authorization_version",
|
|
8274
8434
|
"atol_browser_authorization_expires_at",
|
|
8275
8435
|
"terminal_proof"
|
|
8276
|
-
]) || record.parPhase !== "submitted" || typeof response.
|
|
8277
|
-
response.request_uri.slice(REQUEST_URI_PREFIX.length)
|
|
8278
|
-
) || !Number.isInteger(response.expires_in) || response.expires_in <= 0 || response.expires_in > record.ceremonyLifetimeSeconds || response.authorization_code_expires_in !== record.authorizationCodeLifetimeSeconds || response.atol_browser_authorization_version !== record.protocolVersion || typeof response.atol_browser_authorization_expires_at !== "string" || record.attemptExpiresAtMs === null || !new URLSearchParams(record.form).has(
|
|
8436
|
+
]) || record.parPhase !== "submitted" || !validOrdinaryAuthorizationRequestURI(response.request_uri) || !Number.isInteger(response.expires_in) || response.expires_in <= 0 || response.expires_in > record.ceremonyLifetimeSeconds || response.authorization_code_expires_in !== record.authorizationCodeLifetimeSeconds || response.atol_browser_authorization_version !== record.protocolVersion || typeof response.atol_browser_authorization_expires_at !== "string" || record.attemptExpiresAtMs === null || !new URLSearchParams(record.form).has(
|
|
8279
8437
|
"atol_attempt_capability"
|
|
8280
8438
|
)) {
|
|
8281
8439
|
throw new Error(
|
|
@@ -8414,7 +8572,7 @@ function readBoundedParResponse(response, signal) {
|
|
|
8414
8572
|
);
|
|
8415
8573
|
}
|
|
8416
8574
|
function ordinaryAuthorizationNavigationURL(record) {
|
|
8417
|
-
if (record.parPhase !== "admitted" || record.
|
|
8575
|
+
if (record.parPhase !== "admitted" || record.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION || isLegacyOrdinaryAuthorizationRecord(record) || !validOrdinaryAuthorizationRequestURI(record.requestUri) || record.terminalProof === null || record.attemptExpiresAtMs === null || Date.now() >= record.attemptExpiresAtMs) {
|
|
8418
8576
|
throw new Error(
|
|
8419
8577
|
"ordinary browser authorization: admitted root is expired"
|
|
8420
8578
|
);
|
|
@@ -8434,13 +8592,10 @@ var OrdinaryAuthorizationSettlementInvalidError = class extends Error {
|
|
|
8434
8592
|
this.name = "OrdinaryAuthorizationSettlementInvalidError";
|
|
8435
8593
|
}
|
|
8436
8594
|
};
|
|
8437
|
-
function assertSettlementAuthority(authority, mode) {
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
) || !validCanonicalSHA256(authority.cancellationSecret) ||
|
|
8441
|
-
authority.terminalProof,
|
|
8442
|
-
authority.rootExpiresAt
|
|
8443
|
-
)) || mode === "terminal_only" && authority.terminalProof === null) {
|
|
8595
|
+
function assertSettlementAuthority(authority, mode, historicalTerminalProof) {
|
|
8596
|
+
const deadline = historicalTerminalProof ? legacyOrdinaryAuthorizationProofDeadline(authority.terminalProof, 1) : null;
|
|
8597
|
+
const proofValid = authority.terminalProof === null || authority.rootExpiresAt !== null && (historicalTerminalProof ? deadline !== null && deadline === rfc3339NanoNanoseconds(authority.rootExpiresAt) : validOrdinaryAuthorizationTerminalProof(authority.terminalProof, authority.rootExpiresAt));
|
|
8598
|
+
if (authority.settlementEndpoint !== `${authority.issuer}/auth/par/settlement` || !validOrdinaryAuthorizationRequestURI(authority.requestUri, historicalTerminalProof) || !validCanonicalSHA256(authority.cancellationSecret) || !proofValid || mode === "terminal_only" && authority.terminalProof === null) {
|
|
8444
8599
|
throw new Error(
|
|
8445
8600
|
"ordinary browser authorization: settlement authority is invalid"
|
|
8446
8601
|
);
|
|
@@ -8482,7 +8637,13 @@ function settlementBody(authority, mode) {
|
|
|
8482
8637
|
});
|
|
8483
8638
|
}
|
|
8484
8639
|
async function settleOrdinaryAuthorization(authority, mode) {
|
|
8485
|
-
|
|
8640
|
+
return settle(authority, mode, false);
|
|
8641
|
+
}
|
|
8642
|
+
function classifyLegacyOrdinaryAuthorization(authority) {
|
|
8643
|
+
return settle(authority, "terminal_only", true);
|
|
8644
|
+
}
|
|
8645
|
+
async function settle(authority, mode, historicalTerminalProof) {
|
|
8646
|
+
assertSettlementAuthority(authority, mode, historicalTerminalProof);
|
|
8486
8647
|
const controller = new AbortController();
|
|
8487
8648
|
const timeout = setTimeout(
|
|
8488
8649
|
() => controller.abort(),
|
|
@@ -8663,7 +8824,7 @@ function parseOrdinaryAuthorizationPointer(raw) {
|
|
|
8663
8824
|
}
|
|
8664
8825
|
|
|
8665
8826
|
// src/oidc/ordinary-authorization-validation.ts
|
|
8666
|
-
function canonicalOrdinaryAuthorizationForm(authorizationURL, binding, created) {
|
|
8827
|
+
function canonicalOrdinaryAuthorizationForm(authorizationURL, binding, created, historicalCustody = false) {
|
|
8667
8828
|
const parsed = new URL(authorizationURL);
|
|
8668
8829
|
if (`${parsed.origin}${parsed.pathname}` !== `${binding.issuer}/auth/authorize` || parsed.username !== "" || parsed.password !== "" || parsed.hash !== "") {
|
|
8669
8830
|
throw new Error(
|
|
@@ -8681,9 +8842,7 @@ function canonicalOrdinaryAuthorizationForm(authorizationURL, binding, created)
|
|
|
8681
8842
|
seen.add(name);
|
|
8682
8843
|
values.set(name, value);
|
|
8683
8844
|
}
|
|
8684
|
-
if (values.get("response_type") !== "code" || values.get("client_id") !== binding.clientId || values.get("redirect_uri") !== binding.redirectUri || values.get("scope") !== binding.scope || !binding.scope.split(" ").includes("openid") || values.get("state") !== created.stateId || !OIDC_CLIENT_STATE.test(created.stateId) || values.get("nonce") !== created.nonce || !CANONICAL_NONCE.test(created.nonce) || values.get("code_challenge") !== created.codeChallenge || !validCanonicalSHA256(created.codeChallenge) || values.get("code_challenge_method") !== "S256" || values.has("atol_attempt_capability") && !validCanonicalAttemptCapability(
|
|
8685
|
-
values.get("atol_attempt_capability")
|
|
8686
|
-
) || values.has("dpop_jkt") && !validCanonicalSHA256(values.get("dpop_jkt"))) {
|
|
8845
|
+
if (values.get("response_type") !== "code" || values.get("client_id") !== binding.clientId || values.get("redirect_uri") !== binding.redirectUri || values.get("scope") !== binding.scope || !binding.scope.split(" ").includes("openid") || values.get("state") !== created.stateId || !OIDC_CLIENT_STATE.test(created.stateId) || values.get("nonce") !== created.nonce || !CANONICAL_NONCE.test(created.nonce) || values.get("code_challenge") !== created.codeChallenge || !validCanonicalSHA256(created.codeChallenge) || values.get("code_challenge_method") !== "S256" || values.has("atol_attempt_capability") && (historicalCustody ? legacyOrdinaryAuthorizationProofDeadline(values.get("atol_attempt_capability"), 2) === null : !validCanonicalAttemptCapability(values.get("atol_attempt_capability"))) || values.has("dpop_jkt") && !validCanonicalSHA256(values.get("dpop_jkt"))) {
|
|
8687
8846
|
throw new Error(
|
|
8688
8847
|
"ordinary browser authorization: generated form binding is invalid"
|
|
8689
8848
|
);
|
|
@@ -8699,19 +8858,21 @@ function assertOrdinaryAuthorizationRecord(record, binding, generation, intent)
|
|
|
8699
8858
|
binding,
|
|
8700
8859
|
generation.tabOwner
|
|
8701
8860
|
);
|
|
8702
|
-
if (record.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION || !Number.isSafeInteger(record.revision) || record.revision <= 0 || record.slotKey !== expectedSlot || !OIDC_CLIENT_STATE.test(record.stateId) || record.issuer !== binding.issuer || record.clientId !== binding.clientId || record.redirectUri !== binding.redirectUri || record.scope !== binding.scope || !sameCredentialGeneration2(record.credentialGeneration, generation) || record.intent !== intent || typeof record.stateStorage !== "string" || record.stateStorage.length === 0 || record.stateStorage.length > 32 * 1024 || !Number.isSafeInteger(record.stateCreatedAt) || record.stateCreatedAt < 0 || typeof record.form !== "string" || record.form.length === 0 || record.form.length > 16 * 1024 || !Number.isSafeInteger(record.createdAt) || record.createdAt < 0 || !Number.isSafeInteger(record.provisionalExpiresAt) || record.provisionalExpiresAt !== record.createdAt + (record.ceremonyLifetimeSeconds + record.authorizationCodeLifetimeSeconds) * 1e3 || record.attemptExpiresAtMs !== null && (!Number.isSafeInteger(record.attemptExpiresAtMs) || record.attemptExpiresAtMs <= record.createdAt || record.attemptExpiresAtMs > record.provisionalExpiresAt) || record.protocolVersion !== ORDINARY_AUTHORIZATION_PROTOCOL_VERSION || !Number.isSafeInteger(record.ceremonyLifetimeSeconds) || record.ceremonyLifetimeSeconds <= 0 || record.ceremonyLifetimeSeconds > MAX_CEREMONY_LIFETIME_SECONDS || record.authorizationCodeLifetimeSeconds !== AUTHORIZATION_CODE_LIFETIME_SECONDS || record.pushedAuthorizationRequestEndpoint !== `${binding.issuer}/auth/par` || record.preNavigationCancellationEndpoint !== `${binding.issuer}/auth/par/pre-navigation-cancellation` || record.settlementEndpoint !== `${binding.issuer}/auth/par/settlement` || record.authorizationEndpoint !== `${binding.issuer}/auth/authorize` || record.dpopJkt === null !== (record.keys === null) || record.dpopJkt !== null && !validCanonicalSHA256(record.dpopJkt) || !validCanonicalSHA256(record.cancellationSecret) || record.parPhase !== "prepared" && record.parPhase !== "submitted" && record.parPhase !== "admitted" || record.parPhase === "prepared" && record.attemptExpiresAtMs !== null || record.parPhase === "admitted" && record.attemptExpiresAtMs === null || record.parPhase === "admitted" !== (record.requestUri !== null) || record.parPhase === "admitted" !== (record.terminalProof !== null) || record.parPhase === "admitted" !== (record.rootExpiresAt !== null) || record.parPhase === "admitted" !== (record.rootExpiresAtMs !== null) || record.parPhase === "admitted" !== (record.custodyExpiresAtMs !== null) || record.callbackClaimId === null !== (record.callbackClaimExpiresAtMs === null) || record.callbackCode === null !== (record.callbackCodeHash === null) || record.callbackCode !== null && !validCanonicalAuthorizationCode(record.callbackCode) || record.callbackCodeHash !== null && !
|
|
8861
|
+
if (record.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION && record.version !== HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION || !Number.isSafeInteger(record.revision) || record.revision <= 0 || record.slotKey !== expectedSlot || !OIDC_CLIENT_STATE.test(record.stateId) || record.issuer !== binding.issuer || record.clientId !== binding.clientId || record.redirectUri !== binding.redirectUri || record.scope !== binding.scope || !sameCredentialGeneration2(record.credentialGeneration, generation) || record.intent !== intent || typeof record.stateStorage !== "string" || record.stateStorage.length === 0 || record.stateStorage.length > 32 * 1024 || !Number.isSafeInteger(record.stateCreatedAt) || record.stateCreatedAt < 0 || typeof record.form !== "string" || record.form.length === 0 || record.form.length > 16 * 1024 || !Number.isSafeInteger(record.createdAt) || record.createdAt < 0 || !Number.isSafeInteger(record.provisionalExpiresAt) || record.provisionalExpiresAt !== record.createdAt + (record.ceremonyLifetimeSeconds + record.authorizationCodeLifetimeSeconds) * 1e3 || record.attemptExpiresAtMs !== null && (!Number.isSafeInteger(record.attemptExpiresAtMs) || record.attemptExpiresAtMs <= record.createdAt || record.attemptExpiresAtMs > record.provisionalExpiresAt) || record.protocolVersion !== ORDINARY_AUTHORIZATION_PROTOCOL_VERSION || !Number.isSafeInteger(record.ceremonyLifetimeSeconds) || record.ceremonyLifetimeSeconds <= 0 || record.ceremonyLifetimeSeconds > MAX_CEREMONY_LIFETIME_SECONDS || record.authorizationCodeLifetimeSeconds !== AUTHORIZATION_CODE_LIFETIME_SECONDS || record.pushedAuthorizationRequestEndpoint !== `${binding.issuer}/auth/par` || record.preNavigationCancellationEndpoint !== `${binding.issuer}/auth/par/pre-navigation-cancellation` || record.settlementEndpoint !== `${binding.issuer}/auth/par/settlement` || record.authorizationEndpoint !== `${binding.issuer}/auth/authorize` || record.dpopJkt === null !== (record.keys === null) || record.dpopJkt !== null && !validCanonicalSHA256(record.dpopJkt) || !validCanonicalSHA256(record.cancellationSecret) || record.parPhase !== "prepared" && record.parPhase !== "submitted" && record.parPhase !== "admitted" || record.parPhase === "prepared" && record.attemptExpiresAtMs !== null || record.parPhase === "admitted" && record.attemptExpiresAtMs === null || record.parPhase === "admitted" !== (record.requestUri !== null) || record.parPhase === "admitted" !== (record.terminalProof !== null) || record.parPhase === "admitted" !== (record.rootExpiresAt !== null) || record.parPhase === "admitted" !== (record.rootExpiresAtMs !== null) || record.parPhase === "admitted" !== (record.custodyExpiresAtMs !== null) || record.callbackClaimId === null !== (record.callbackClaimExpiresAtMs === null) || record.callbackCode === null !== (record.callbackCodeHash === null) || record.callbackCode !== null && !validCanonicalAuthorizationCode(record.callbackCode) || record.callbackCodeHash !== null && !validAuthorizationCodeCommitment(record.callbackCodeHash) && !isLegacyAuthorizationCodeCommitment(record.callbackCodeHash) || typeof record.compensationRequired !== "boolean" || record.compensationRequired && record.callbackCode === null || typeof record.rejectionRequired !== "boolean" || record.rejectionRequired && record.parPhase !== "admitted" || record.rejectionRequired && record.callbackClaimId !== null || typeof record.cleanupStarted !== "boolean" || record.cleanupStarted && record.callbackClaimId !== null || record.callbackClaimId !== null && (!validCanonicalSHA256(record.callbackClaimId) || !Number.isSafeInteger(record.callbackClaimExpiresAtMs) || record.callbackClaimExpiresAtMs <= 0)) {
|
|
8703
8862
|
throw new Error("ordinary browser authorization: custody binding mismatch");
|
|
8704
8863
|
}
|
|
8705
8864
|
const parameters = new URLSearchParams(record.form);
|
|
8865
|
+
const historicalCustody = isLegacyOrdinaryAuthorizationRecord(record);
|
|
8706
8866
|
const intentRecord = parseOrdinaryAuthorizationIntent(record.intent);
|
|
8707
|
-
if (canonicalOrdinaryAuthorizationForm(
|
|
8867
|
+
if (record.version === ORDINARY_AUTHORIZATION_RECORD_VERSION && (historicalCustody || isLegacyAuthorizationCodeCommitment(record.callbackCodeHash)) || historicalCustody && record.callbackCodeHash !== null && !isLegacyAuthorizationCodeCommitment(record.callbackCodeHash) || canonicalOrdinaryAuthorizationForm(
|
|
8708
8868
|
`${record.authorizationEndpoint}?${record.form}`,
|
|
8709
8869
|
binding,
|
|
8710
8870
|
{
|
|
8711
8871
|
stateId: record.stateId,
|
|
8712
8872
|
nonce: parameters.get("nonce") ?? "",
|
|
8713
8873
|
codeChallenge: parameters.get("code_challenge") ?? ""
|
|
8714
|
-
}
|
|
8874
|
+
},
|
|
8875
|
+
historicalCustody
|
|
8715
8876
|
) !== record.form || parameters.get("dpop_jkt") !== record.dpopJkt || parameters.has("atol_attempt_capability") !== (record.attemptExpiresAtMs !== null) || parameters.get("response_mode") !== intentRecord.responseMode || parameters.get("prompt") !== intentRecord.prompt || parameters.get("max_age") !== (intentRecord.maxAge === null ? null : String(intentRecord.maxAge)) || parameters.get("acr_values") !== intentRecord.acrValues || Object.entries(intentRecord.extraQueryParams).some(
|
|
8716
8877
|
([name, value]) => parameters.get(name) !== value
|
|
8717
8878
|
) || intentRecord.dpopRequired && record.dpopJkt === null || !intentRecord.dpopEnabled && record.dpopJkt !== null) {
|
|
@@ -8721,16 +8882,7 @@ function assertOrdinaryAuthorizationRecord(record, binding, generation, intent)
|
|
|
8721
8882
|
const parsedDeadline = rfc3339NanoMilliseconds(
|
|
8722
8883
|
record.rootExpiresAt
|
|
8723
8884
|
);
|
|
8724
|
-
if (!record.requestUri
|
|
8725
|
-
record.requestUri.slice(REQUEST_URI_PREFIX.length)
|
|
8726
|
-
) || !validOrdinaryAuthorizationTerminalProof(
|
|
8727
|
-
record.terminalProof,
|
|
8728
|
-
record.rootExpiresAt
|
|
8729
|
-
) || ordinaryAuthorizationAttemptCapabilityDeadline(
|
|
8730
|
-
parameters.get("atol_attempt_capability")
|
|
8731
|
-
) !== rfc3339NanoNanoseconds(
|
|
8732
|
-
record.rootExpiresAt
|
|
8733
|
-
) || parsedDeadline !== record.rootExpiresAtMs || Math.min(
|
|
8885
|
+
if (!validOrdinaryAuthorizationRequestURI(record.requestUri, historicalCustody) || !storedOrdinaryAuthorizationProofsMatch(record, parameters, historicalCustody) || parsedDeadline !== record.rootExpiresAtMs || Math.min(
|
|
8734
8886
|
record.attemptExpiresAtMs + record.authorizationCodeLifetimeSeconds * 1e3,
|
|
8735
8887
|
record.provisionalExpiresAt
|
|
8736
8888
|
) !== record.custodyExpiresAtMs) {
|
|
@@ -8740,6 +8892,15 @@ function assertOrdinaryAuthorizationRecord(record, binding, generation, intent)
|
|
|
8740
8892
|
}
|
|
8741
8893
|
}
|
|
8742
8894
|
}
|
|
8895
|
+
function storedOrdinaryAuthorizationProofsMatch(record, parameters, historicalCustody) {
|
|
8896
|
+
const rootExpiresAt = record.rootExpiresAt;
|
|
8897
|
+
const deadline = rfc3339NanoNanoseconds(rootExpiresAt);
|
|
8898
|
+
const attempt = parameters.get("atol_attempt_capability");
|
|
8899
|
+
if (historicalCustody) {
|
|
8900
|
+
return deadline !== null && legacyOrdinaryAuthorizationProofDeadline(attempt, 2) === deadline && legacyOrdinaryAuthorizationProofDeadline(record.terminalProof, 1) === deadline;
|
|
8901
|
+
}
|
|
8902
|
+
return validOrdinaryAuthorizationTerminalProof(record.terminalProof, rootExpiresAt) && ordinaryAuthorizationAttemptCapabilityDeadline(attempt) === deadline;
|
|
8903
|
+
}
|
|
8743
8904
|
async function assertOrdinaryAuthorizationRecordState(record) {
|
|
8744
8905
|
const state = parseUniqueJSONObject(record.stateStorage, 32 * 1024);
|
|
8745
8906
|
if (!hasExactMembers(
|
|
@@ -8796,6 +8957,15 @@ async function assertOrdinaryAuthorizationRecordState(record) {
|
|
|
8796
8957
|
"ordinary browser authorization: stored application state mismatch"
|
|
8797
8958
|
);
|
|
8798
8959
|
}
|
|
8960
|
+
if (record.callbackCode !== null) {
|
|
8961
|
+
const commitment = isLegacyAuthorizationCodeCommitment(record.callbackCodeHash) ? bytesToBase64Url(new Uint8Array(await crypto.subtle.digest(
|
|
8962
|
+
"SHA-256",
|
|
8963
|
+
new TextEncoder().encode(record.callbackCode)
|
|
8964
|
+
))) : await authorizationCodeCommitment(record.callbackCode);
|
|
8965
|
+
if (commitment !== record.callbackCodeHash) {
|
|
8966
|
+
throw new Error("ordinary browser authorization: stored callback code commitment mismatch");
|
|
8967
|
+
}
|
|
8968
|
+
}
|
|
8799
8969
|
}
|
|
8800
8970
|
function assertOrdinaryAuthorizationCallbackMatches(record, callback, generation) {
|
|
8801
8971
|
const form = new URLSearchParams(record.form);
|
|
@@ -8876,11 +9046,6 @@ async function classifyOrdinaryAuthorizationRecordEnvelope(value) {
|
|
|
8876
9046
|
});
|
|
8877
9047
|
assertOrdinaryAuthorizationRecord(record, binding, generation, record.intent);
|
|
8878
9048
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
8879
|
-
if (record.callbackCode !== null && await authorizationCodeSHA256(record.callbackCode) !== record.callbackCodeHash) {
|
|
8880
|
-
throw new Error(
|
|
8881
|
-
"ordinary browser authorization: unrecognized custody record"
|
|
8882
|
-
);
|
|
8883
|
-
}
|
|
8884
9049
|
if (record.keys !== null) {
|
|
8885
9050
|
if (typeof record.keys !== "object" || !hasExactMembers(record.keys, [
|
|
8886
9051
|
"privateKey",
|
|
@@ -9054,11 +9219,11 @@ async function markOrdinaryAuthorizationPARSubmitted(expected) {
|
|
|
9054
9219
|
store.get(expected.slotKey),
|
|
9055
9220
|
"PAR submission read"
|
|
9056
9221
|
);
|
|
9057
|
-
if (current && (current.parPhase === "submitted" || current.parPhase === "admitted") && current.stateId === expected.stateId && current.form === expected.form && current.cancellationSecret === expected.cancellationSecret && !current.cleanupStarted && !current.rejectionRequired) {
|
|
9222
|
+
if (current && (current.parPhase === "submitted" || current.parPhase === "admitted") && current.version === expected.version && current.stateId === expected.stateId && current.form === expected.form && current.cancellationSecret === expected.cancellationSecret && !current.cleanupStarted && !current.rejectionRequired) {
|
|
9058
9223
|
await ordinaryAuthorizationTransactionDone(transaction, "stable PAR submission");
|
|
9059
9224
|
return current;
|
|
9060
9225
|
}
|
|
9061
|
-
if (!current || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.cancellationSecret !== expected.cancellationSecret || current.parPhase !== "prepared" || current.cleanupStarted || current.rejectionRequired) {
|
|
9226
|
+
if (!current || current.version !== expected.version || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.cancellationSecret !== expected.cancellationSecret || current.parPhase !== "prepared" || current.cleanupStarted || current.rejectionRequired) {
|
|
9062
9227
|
transaction.abort();
|
|
9063
9228
|
throw new OrdinaryAuthorizationPendingError();
|
|
9064
9229
|
}
|
|
@@ -9111,11 +9276,11 @@ async function bindOrdinaryAuthorizationAttemptCapability(expected, attemptCapab
|
|
|
9111
9276
|
store.get(expected.slotKey),
|
|
9112
9277
|
"attempt capability read"
|
|
9113
9278
|
);
|
|
9114
|
-
if (current?.form === updatedForm && current.attemptExpiresAtMs === clippedExpiresAt && current.stateId === expected.stateId && current.cancellationSecret === expected.cancellationSecret && current.parPhase === "submitted" && !current.cleanupStarted && !current.rejectionRequired) {
|
|
9279
|
+
if (current?.form === updatedForm && current.attemptExpiresAtMs === clippedExpiresAt && current.version === expected.version && current.stateId === expected.stateId && current.cancellationSecret === expected.cancellationSecret && current.parPhase === "submitted" && !current.cleanupStarted && !current.rejectionRequired) {
|
|
9115
9280
|
await ordinaryAuthorizationTransactionDone(transaction, "stable attempt capability binding");
|
|
9116
9281
|
return current;
|
|
9117
9282
|
}
|
|
9118
|
-
if (!current || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.cancellationSecret !== expected.cancellationSecret || current.parPhase !== "submitted" || current.cleanupStarted || current.rejectionRequired) {
|
|
9283
|
+
if (!current || current.version !== expected.version || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.cancellationSecret !== expected.cancellationSecret || current.parPhase !== "submitted" || current.cleanupStarted || current.rejectionRequired) {
|
|
9119
9284
|
transaction.abort();
|
|
9120
9285
|
throw new OrdinaryAuthorizationPendingError();
|
|
9121
9286
|
}
|
|
@@ -9144,16 +9309,17 @@ async function replaceOrdinaryAuthorizationRecord(expected, replacement) {
|
|
|
9144
9309
|
store.get(expected.slotKey),
|
|
9145
9310
|
"record bind read"
|
|
9146
9311
|
);
|
|
9147
|
-
if (current && !current.cleanupStarted && current.stateId === expected.stateId && current.form === expected.form && current.stateStorage === expected.stateStorage && current.parPhase === "admitted" && !current.rejectionRequired && current.requestUri === replacement.requestUri && current.terminalProof === replacement.terminalProof && current.rootExpiresAt === replacement.rootExpiresAt && current.rootExpiresAtMs === replacement.rootExpiresAtMs && current.custodyExpiresAtMs === replacement.custodyExpiresAtMs) {
|
|
9312
|
+
if (current && !current.cleanupStarted && current.version === expected.version && current.stateId === expected.stateId && current.form === expected.form && current.stateStorage === expected.stateStorage && current.parPhase === "admitted" && !current.rejectionRequired && current.requestUri === replacement.requestUri && current.terminalProof === replacement.terminalProof && current.rootExpiresAt === replacement.rootExpiresAt && current.rootExpiresAtMs === replacement.rootExpiresAtMs && current.custodyExpiresAtMs === replacement.custodyExpiresAtMs) {
|
|
9148
9313
|
await ordinaryAuthorizationTransactionDone(transaction, "stable record bind");
|
|
9149
9314
|
return current;
|
|
9150
9315
|
}
|
|
9151
|
-
if (!current || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.stateStorage !== expected.stateStorage || current.parPhase !== "submitted" || current.requestUri !== expected.requestUri || current.terminalProof !== expected.terminalProof || current.rootExpiresAt !== expected.rootExpiresAt || current.cleanupStarted || current.rejectionRequired) {
|
|
9316
|
+
if (!current || current.version !== expected.version || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.stateStorage !== expected.stateStorage || current.parPhase !== "submitted" || current.requestUri !== expected.requestUri || current.terminalProof !== expected.terminalProof || current.rootExpiresAt !== expected.rootExpiresAt || current.cleanupStarted || current.rejectionRequired) {
|
|
9152
9317
|
transaction.abort();
|
|
9153
9318
|
throw new Error("ordinary browser authorization: custody was superseded");
|
|
9154
9319
|
}
|
|
9155
9320
|
const next = {
|
|
9156
9321
|
...replacement,
|
|
9322
|
+
version: current.version,
|
|
9157
9323
|
revision: current.revision + 1
|
|
9158
9324
|
};
|
|
9159
9325
|
store.put(next);
|
|
@@ -9175,11 +9341,11 @@ async function requireOrdinaryAuthorizationRejection(expected) {
|
|
|
9175
9341
|
store.get(expected.slotKey),
|
|
9176
9342
|
"rejection transition read"
|
|
9177
9343
|
);
|
|
9178
|
-
if (current?.rejectionRequired && current.parPhase === "admitted" && current.stateId === expected.stateId && current.form === expected.form) {
|
|
9344
|
+
if (current?.rejectionRequired && current.parPhase === "admitted" && current.version === expected.version && current.stateId === expected.stateId && current.form === expected.form) {
|
|
9179
9345
|
await ordinaryAuthorizationTransactionDone(transaction, "stable rejection transition");
|
|
9180
9346
|
return current;
|
|
9181
9347
|
}
|
|
9182
|
-
if (!current || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.parPhase !== "admitted" || current.cleanupStarted) {
|
|
9348
|
+
if (!current || current.version !== expected.version || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.parPhase !== "admitted" || current.cleanupStarted) {
|
|
9183
9349
|
transaction.abort();
|
|
9184
9350
|
throw new OrdinaryAuthorizationPendingError();
|
|
9185
9351
|
}
|
|
@@ -9203,7 +9369,7 @@ function newClaimID() {
|
|
|
9203
9369
|
return bytesToBase64Url(value);
|
|
9204
9370
|
}
|
|
9205
9371
|
async function claimOrdinaryAuthorizationRecord(expected, callbackCode, callbackCodeHash) {
|
|
9206
|
-
if (callbackCode === null !== (callbackCodeHash === null) || callbackCode !== null && !validCanonicalAuthorizationCode(callbackCode) || callbackCodeHash !== null && !
|
|
9372
|
+
if (callbackCode === null !== (callbackCodeHash === null) || callbackCode !== null && !validCanonicalAuthorizationCode(callbackCode) || callbackCodeHash !== null && !validAuthorizationCodeCommitment(callbackCodeHash)) {
|
|
9207
9373
|
throw new Error("ordinary browser authorization: callback code is invalid");
|
|
9208
9374
|
}
|
|
9209
9375
|
const db = await openOrdinaryAuthorizationDB();
|
|
@@ -9218,7 +9384,7 @@ async function claimOrdinaryAuthorizationRecord(expected, callbackCode, callback
|
|
|
9218
9384
|
"callback claim read"
|
|
9219
9385
|
);
|
|
9220
9386
|
const now = Date.now();
|
|
9221
|
-
if (!current || current.revision !== expected.revision || current.stateId !== expected.stateId || current.parPhase !== "admitted" || current.rejectionRequired || current.cleanupStarted || current.callbackCode !== null && current.callbackCode !== callbackCode || current.callbackCodeHash !== null && current.callbackCodeHash !== callbackCodeHash || current.callbackCode === null && current.compensationRequired || current.callbackClaimId !== null && current.callbackClaimExpiresAtMs > now) {
|
|
9387
|
+
if (!current || current.version !== expected.version || current.revision !== expected.revision || current.stateId !== expected.stateId || current.parPhase !== "admitted" || current.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION || isLegacyOrdinaryAuthorizationRecord(current) || current.rejectionRequired || current.cleanupStarted || current.callbackCode !== null && current.callbackCode !== callbackCode || current.callbackCodeHash !== null && current.callbackCodeHash !== callbackCodeHash || current.callbackCode === null && current.compensationRequired || current.callbackClaimId !== null && current.callbackClaimExpiresAtMs > now) {
|
|
9222
9388
|
transaction.abort();
|
|
9223
9389
|
throw new OrdinaryAuthorizationPendingError();
|
|
9224
9390
|
}
|
|
@@ -9256,7 +9422,7 @@ async function markOrdinaryAuthorizationCodeIssued(expected) {
|
|
|
9256
9422
|
store.get(expected.slotKey),
|
|
9257
9423
|
"code issuance transition read"
|
|
9258
9424
|
);
|
|
9259
|
-
if (!current || current.revision !== expected.revision || current.stateId !== expected.stateId || current.callbackClaimId !== expected.callbackClaimId || current.callbackClaimId === null || current.callbackCode === null || current.callbackCodeHash === null || current.compensationRequired || current.rejectionRequired || current.cleanupStarted) {
|
|
9425
|
+
if (!current || current.version !== expected.version || current.revision !== expected.revision || current.stateId !== expected.stateId || current.callbackClaimId !== expected.callbackClaimId || current.callbackClaimId === null || current.callbackCode === null || current.callbackCodeHash === null || current.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION || isLegacyOrdinaryAuthorizationRecord(current) || !validAuthorizationCodeCommitment(current.callbackCodeHash) || current.compensationRequired || current.rejectionRequired || current.cleanupStarted) {
|
|
9260
9426
|
transaction.abort();
|
|
9261
9427
|
throw new Error(
|
|
9262
9428
|
"ordinary browser authorization: code issuance was superseded"
|
|
@@ -9286,11 +9452,11 @@ async function startOrdinaryAuthorizationCleanup(expected) {
|
|
|
9286
9452
|
store.get(expected.slotKey),
|
|
9287
9453
|
"cleanup transition read"
|
|
9288
9454
|
);
|
|
9289
|
-
if (current?.cleanupStarted && current.stateId === expected.stateId && current.form === expected.form && current.stateStorage === expected.stateStorage && current.cancellationSecret === expected.cancellationSecret) {
|
|
9455
|
+
if (current?.cleanupStarted && current.version === expected.version && current.stateId === expected.stateId && current.form === expected.form && current.stateStorage === expected.stateStorage && current.cancellationSecret === expected.cancellationSecret) {
|
|
9290
9456
|
await ordinaryAuthorizationTransactionDone(transaction, "stable cleanup transition");
|
|
9291
9457
|
return current;
|
|
9292
9458
|
}
|
|
9293
|
-
if (!current || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.stateStorage !== expected.stateStorage || current.cancellationSecret !== expected.cancellationSecret || current.cleanupStarted) {
|
|
9459
|
+
if (!current || current.version !== expected.version || current.revision !== expected.revision || current.stateId !== expected.stateId || current.form !== expected.form || current.stateStorage !== expected.stateStorage || current.cancellationSecret !== expected.cancellationSecret || current.cleanupStarted) {
|
|
9294
9460
|
transaction.abort();
|
|
9295
9461
|
throw new Error("ordinary browser authorization: cleanup was superseded");
|
|
9296
9462
|
}
|
|
@@ -9320,7 +9486,7 @@ async function releaseOrdinaryAuthorizationClaim(expected) {
|
|
|
9320
9486
|
store.get(expected.slotKey),
|
|
9321
9487
|
"callback release read"
|
|
9322
9488
|
);
|
|
9323
|
-
if (!current || current.revision !== expected.revision || current.callbackClaimId !== expected.callbackClaimId || current.callbackClaimId === null || current.cleanupStarted) {
|
|
9489
|
+
if (!current || current.version !== expected.version || current.revision !== expected.revision || current.callbackClaimId !== expected.callbackClaimId || current.callbackClaimId === null || current.cleanupStarted) {
|
|
9324
9490
|
transaction.abort();
|
|
9325
9491
|
throw new Error(
|
|
9326
9492
|
"ordinary browser authorization: callback release was superseded"
|
|
@@ -9354,7 +9520,7 @@ async function deleteOrdinaryAuthorizationRecordRevision(expected) {
|
|
|
9354
9520
|
await ordinaryAuthorizationTransactionDone(transaction, "idempotent record discard");
|
|
9355
9521
|
return;
|
|
9356
9522
|
}
|
|
9357
|
-
if (current.revision !== expected.revision || current.stateId !== expected.stateId || !current.cleanupStarted) {
|
|
9523
|
+
if (current.version !== expected.version || current.revision !== expected.revision || current.stateId !== expected.stateId || !current.cleanupStarted) {
|
|
9358
9524
|
transaction.abort();
|
|
9359
9525
|
throw new Error("ordinary browser authorization: discard was superseded");
|
|
9360
9526
|
}
|
|
@@ -9370,6 +9536,10 @@ function validOrdinaryPARResponseHeaders(response) {
|
|
|
9370
9536
|
return response.headers.get("cache-control") === "no-store" && response.headers.get("content-type") === "application/json" && response.headers.get("atol-browser-authorization") === "v2";
|
|
9371
9537
|
}
|
|
9372
9538
|
async function postOrdinaryPAR(record, signal) {
|
|
9539
|
+
const cancellationChallenge = record.version === HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION && record.parPhase === "submitted" && record.attemptExpiresAtMs === null && !new URLSearchParams(record.form).has("atol_attempt_capability");
|
|
9540
|
+
if (isLegacyOrdinaryAuthorizationRecord(record) || record.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION && !cancellationChallenge) {
|
|
9541
|
+
throw new OrdinaryAuthorizationPendingError();
|
|
9542
|
+
}
|
|
9373
9543
|
const startedAt = Date.now();
|
|
9374
9544
|
try {
|
|
9375
9545
|
const response = await fetch(record.pushedAuthorizationRequestEndpoint, {
|
|
@@ -9548,6 +9718,34 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9548
9718
|
await settleOrdinaryAuthorization(rejecting, "reject");
|
|
9549
9719
|
await this.startAndFinishCleanup(rejecting);
|
|
9550
9720
|
}
|
|
9721
|
+
async retireObsoleteCustody(record, checkOwner = true) {
|
|
9722
|
+
if (record.version !== HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION) return false;
|
|
9723
|
+
const lock = await acquireOrdinaryAuthorizationCallbackLock(record);
|
|
9724
|
+
try {
|
|
9725
|
+
if (checkOwner) {
|
|
9726
|
+
assertCredentialGenerationSnapshot(this.binding, record.credentialGeneration);
|
|
9727
|
+
const pointer = parseOrdinaryAuthorizationPointer(
|
|
9728
|
+
ordinaryAuthorizationPointerStorage().getItem(this.storageKey)
|
|
9729
|
+
);
|
|
9730
|
+
if (pointer) this.assertExactPointer(record);
|
|
9731
|
+
}
|
|
9732
|
+
if (record.cleanupStarted) {
|
|
9733
|
+
await this.finishCleanup(record);
|
|
9734
|
+
} else if (record.parPhase === "prepared") {
|
|
9735
|
+
await this.cleanupPreparedRecordWithoutPointer(record);
|
|
9736
|
+
} else if (record.parPhase === "submitted") {
|
|
9737
|
+
await this.rejectSubmittedAndCleanup(record);
|
|
9738
|
+
} else if (isLegacyOrdinaryAuthorizationRecord(record)) {
|
|
9739
|
+
await classifyLegacyOrdinaryAuthorization(record);
|
|
9740
|
+
await this.startAndFinishCleanup(record);
|
|
9741
|
+
} else {
|
|
9742
|
+
await this.rejectAndCleanup(record);
|
|
9743
|
+
}
|
|
9744
|
+
} finally {
|
|
9745
|
+
await lock.release();
|
|
9746
|
+
}
|
|
9747
|
+
return true;
|
|
9748
|
+
}
|
|
9551
9749
|
async rejectSubmittedAndCleanup(record) {
|
|
9552
9750
|
const settled = await cancelSubmittedOrdinaryAuthorization(record);
|
|
9553
9751
|
await this.startAndFinishCleanup(settled);
|
|
@@ -9589,6 +9787,7 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9589
9787
|
record.intent
|
|
9590
9788
|
);
|
|
9591
9789
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
9790
|
+
if (await this.retireObsoleteCustody(record)) return;
|
|
9592
9791
|
if (record.cleanupStarted) {
|
|
9593
9792
|
await this.finishCleanup(record);
|
|
9594
9793
|
} else if (record.parPhase === "admitted") {
|
|
@@ -9610,6 +9809,12 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9610
9809
|
(record) => record.issuer === this.binding.issuer && record.clientId === this.binding.clientId && new URL(record.redirectUri).origin === new URL(this.binding.redirectUri).origin
|
|
9611
9810
|
);
|
|
9612
9811
|
for (const record of matching) {
|
|
9812
|
+
try {
|
|
9813
|
+
if (await this.retireObsoleteCustody(record, false)) continue;
|
|
9814
|
+
} catch (error) {
|
|
9815
|
+
if (error instanceof OrdinaryAuthorizationPendingError && record.version === HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION && record.credentialGeneration.tabOwner !== currentTabOwnerGeneration(this.binding)) continue;
|
|
9816
|
+
throw error;
|
|
9817
|
+
}
|
|
9613
9818
|
if (record.cleanupStarted) {
|
|
9614
9819
|
await this.finishCleanup(record);
|
|
9615
9820
|
} else if (record.parPhase === "admitted") {
|
|
@@ -9625,70 +9830,6 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9625
9830
|
}
|
|
9626
9831
|
};
|
|
9627
9832
|
|
|
9628
|
-
// src/oidc/ordinary-authorization-lock.ts
|
|
9629
|
-
async function acquireOrdinaryAuthorizationCallbackLock(slotKey2) {
|
|
9630
|
-
if (typeof navigator === "undefined" || !navigator.locks || typeof navigator.locks.request !== "function") {
|
|
9631
|
-
throw new Error(
|
|
9632
|
-
"ordinary browser authorization: Web Locks is required"
|
|
9633
|
-
);
|
|
9634
|
-
}
|
|
9635
|
-
const digest = await crypto.subtle.digest(
|
|
9636
|
-
"SHA-256",
|
|
9637
|
-
new TextEncoder().encode(slotKey2)
|
|
9638
|
-
);
|
|
9639
|
-
const name = `atol:ordinary-callback:${bytesToBase64Url(
|
|
9640
|
-
new Uint8Array(digest)
|
|
9641
|
-
)}`;
|
|
9642
|
-
let releaseHold;
|
|
9643
|
-
const hold = new Promise((resolve) => {
|
|
9644
|
-
releaseHold = resolve;
|
|
9645
|
-
});
|
|
9646
|
-
let resolveAcquired;
|
|
9647
|
-
let rejectAcquired;
|
|
9648
|
-
const acquired = new Promise((resolve, reject) => {
|
|
9649
|
-
resolveAcquired = resolve;
|
|
9650
|
-
rejectAcquired = reject;
|
|
9651
|
-
});
|
|
9652
|
-
let acquisitionSettled = false;
|
|
9653
|
-
const request = navigator.locks.request(
|
|
9654
|
-
name,
|
|
9655
|
-
{ mode: "exclusive", ifAvailable: true },
|
|
9656
|
-
async (lock) => {
|
|
9657
|
-
if (!lock) {
|
|
9658
|
-
acquisitionSettled = true;
|
|
9659
|
-
rejectAcquired(new OrdinaryAuthorizationPendingError());
|
|
9660
|
-
return;
|
|
9661
|
-
}
|
|
9662
|
-
acquisitionSettled = true;
|
|
9663
|
-
resolveAcquired();
|
|
9664
|
-
await hold;
|
|
9665
|
-
}
|
|
9666
|
-
);
|
|
9667
|
-
void request.catch((error) => {
|
|
9668
|
-
if (!acquisitionSettled) rejectAcquired(error);
|
|
9669
|
-
});
|
|
9670
|
-
try {
|
|
9671
|
-
await acquired;
|
|
9672
|
-
} catch (error) {
|
|
9673
|
-
releaseHold();
|
|
9674
|
-
try {
|
|
9675
|
-
await request;
|
|
9676
|
-
} catch (requestError) {
|
|
9677
|
-
throw requestError;
|
|
9678
|
-
}
|
|
9679
|
-
throw error;
|
|
9680
|
-
}
|
|
9681
|
-
let released = false;
|
|
9682
|
-
return {
|
|
9683
|
-
release: async () => {
|
|
9684
|
-
if (released) return;
|
|
9685
|
-
released = true;
|
|
9686
|
-
releaseHold();
|
|
9687
|
-
await request;
|
|
9688
|
-
}
|
|
9689
|
-
};
|
|
9690
|
-
}
|
|
9691
|
-
|
|
9692
9833
|
// src/oidc/ordinary-authorization-callback.ts
|
|
9693
9834
|
function callbackFromRecord(record) {
|
|
9694
9835
|
if (record.callbackCode === null) {
|
|
@@ -9758,6 +9899,11 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9758
9899
|
record.intent
|
|
9759
9900
|
);
|
|
9760
9901
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
9902
|
+
if (record.version === HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION) {
|
|
9903
|
+
assertOrdinaryAuthorizationCallbackMatches(record, callback, generation);
|
|
9904
|
+
await this.retireObsoleteCustodyForResponse(record, callback);
|
|
9905
|
+
throw new Error("ordinary browser authorization: obsolete callback was settled");
|
|
9906
|
+
}
|
|
9761
9907
|
if (record.cleanupStarted) {
|
|
9762
9908
|
await this.cleanup.finishCleanup(record);
|
|
9763
9909
|
throw new Error(
|
|
@@ -9775,15 +9921,13 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9775
9921
|
callback,
|
|
9776
9922
|
generation
|
|
9777
9923
|
);
|
|
9778
|
-
const processLock = await acquireOrdinaryAuthorizationCallbackLock(
|
|
9779
|
-
record.slotKey
|
|
9780
|
-
);
|
|
9924
|
+
const processLock = await acquireOrdinaryAuthorizationCallbackLock(record);
|
|
9781
9925
|
let claimed;
|
|
9782
9926
|
try {
|
|
9783
9927
|
claimed = await claimOrdinaryAuthorizationRecord(
|
|
9784
9928
|
record,
|
|
9785
9929
|
callback.code ?? null,
|
|
9786
|
-
callback.code === void 0 ? null : await
|
|
9930
|
+
callback.code === void 0 ? null : await authorizationCodeCommitment(callback.code)
|
|
9787
9931
|
);
|
|
9788
9932
|
} catch (error) {
|
|
9789
9933
|
await processLock.release();
|
|
@@ -9811,7 +9955,7 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9811
9955
|
}
|
|
9812
9956
|
let settled = false;
|
|
9813
9957
|
const compensationRequired = claimed.compensationRequired;
|
|
9814
|
-
const
|
|
9958
|
+
const settle2 = async () => {
|
|
9815
9959
|
if (settled) {
|
|
9816
9960
|
throw new Error(
|
|
9817
9961
|
"ordinary browser authorization: callback custody is already settled"
|
|
@@ -9860,7 +10004,7 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9860
10004
|
throw error;
|
|
9861
10005
|
}
|
|
9862
10006
|
},
|
|
9863
|
-
complete:
|
|
10007
|
+
complete: settle2,
|
|
9864
10008
|
discard: async () => {
|
|
9865
10009
|
if (settled) {
|
|
9866
10010
|
throw new Error(
|
|
@@ -9900,6 +10044,7 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9900
10044
|
record.intent
|
|
9901
10045
|
);
|
|
9902
10046
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
10047
|
+
if (await this.retireObsoleteCustody(record)) return null;
|
|
9903
10048
|
if (record.cleanupStarted) {
|
|
9904
10049
|
await this.cleanup.finishCleanup(record);
|
|
9905
10050
|
return null;
|
|
@@ -9947,6 +10092,10 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9947
10092
|
callback,
|
|
9948
10093
|
generation
|
|
9949
10094
|
);
|
|
10095
|
+
if (record.version === HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION) {
|
|
10096
|
+
await this.retireObsoleteCustodyForResponse(record, callback);
|
|
10097
|
+
return;
|
|
10098
|
+
}
|
|
9950
10099
|
if (callback.code !== void 0) {
|
|
9951
10100
|
record = await this.rejectCallbackCode(
|
|
9952
10101
|
record,
|
|
@@ -9978,9 +10127,20 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9978
10127
|
record.intent
|
|
9979
10128
|
);
|
|
9980
10129
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
9981
|
-
await this.
|
|
10130
|
+
if (!await this.retireObsoleteCustody(record)) {
|
|
10131
|
+
await this.cleanup.finishCleanup(record);
|
|
10132
|
+
}
|
|
9982
10133
|
return true;
|
|
9983
10134
|
}
|
|
10135
|
+
retireObsoleteCustody(record) {
|
|
10136
|
+
return this.cleanup.retireObsoleteCustody(record);
|
|
10137
|
+
}
|
|
10138
|
+
async retireObsoleteCustodyForResponse(record, callback) {
|
|
10139
|
+
if (record.callbackCode !== null && callback.code !== record.callbackCode) {
|
|
10140
|
+
throw new Error("ordinary browser authorization: obsolete callback code mismatch");
|
|
10141
|
+
}
|
|
10142
|
+
await this.retireObsoleteCustody(record);
|
|
10143
|
+
}
|
|
9984
10144
|
async invalidateCurrent(generation) {
|
|
9985
10145
|
return this.cleanup.invalidateCurrent(generation);
|
|
9986
10146
|
}
|
|
@@ -9988,15 +10148,13 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9988
10148
|
return this.cleanup.invalidateSignedOutLifecycle();
|
|
9989
10149
|
}
|
|
9990
10150
|
async rejectCallbackCode(record, code) {
|
|
9991
|
-
const processLock = await acquireOrdinaryAuthorizationCallbackLock(
|
|
9992
|
-
record.slotKey
|
|
9993
|
-
);
|
|
10151
|
+
const processLock = await acquireOrdinaryAuthorizationCallbackLock(record);
|
|
9994
10152
|
let claimed = null;
|
|
9995
10153
|
try {
|
|
9996
10154
|
claimed = await claimOrdinaryAuthorizationRecord(
|
|
9997
10155
|
record,
|
|
9998
10156
|
code,
|
|
9999
|
-
await
|
|
10157
|
+
await authorizationCodeCommitment(code)
|
|
10000
10158
|
);
|
|
10001
10159
|
try {
|
|
10002
10160
|
return await requireOrdinaryAuthorizationRejection(claimed);
|
|
@@ -10053,6 +10211,9 @@ async function rejectOrRetainInvalidAdmission(submitted) {
|
|
|
10053
10211
|
throw new OrdinaryAuthorizationPendingError();
|
|
10054
10212
|
}
|
|
10055
10213
|
async function admitOrdinaryAuthorization(record) {
|
|
10214
|
+
if (record.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION) {
|
|
10215
|
+
throw new OrdinaryAuthorizationPendingError();
|
|
10216
|
+
}
|
|
10056
10217
|
if (ordinaryAuthorizationRecordExpired(record)) {
|
|
10057
10218
|
if (record.parPhase === "submitted") {
|
|
10058
10219
|
return rejectOrRetainInvalidAdmission(record);
|
|
@@ -10152,7 +10313,11 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10152
10313
|
const generation = start.credentialGeneration;
|
|
10153
10314
|
const intent = serializedOrdinaryAuthorizationIntent(start.intent);
|
|
10154
10315
|
assertCredentialGenerationSnapshot(this.binding, generation);
|
|
10155
|
-
const pending = await this.pendingRecord(
|
|
10316
|
+
const pending = await this.pendingRecord(
|
|
10317
|
+
generation,
|
|
10318
|
+
intent,
|
|
10319
|
+
start.requireMLDSA87DPoP
|
|
10320
|
+
);
|
|
10156
10321
|
if (pending) {
|
|
10157
10322
|
await ensureAuthorizationRequestState(
|
|
10158
10323
|
this.manager,
|
|
@@ -10174,6 +10339,9 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10174
10339
|
return;
|
|
10175
10340
|
}
|
|
10176
10341
|
const dpopKey = start.intent.dpopEnabled ? await start.createDPoPKey() : null;
|
|
10342
|
+
if (start.requireMLDSA87DPoP) {
|
|
10343
|
+
assertMLDSA87DPoPKey(dpopKey ? dpopKeyPair(dpopKey) : null);
|
|
10344
|
+
}
|
|
10177
10345
|
if (start.intent.dpopRequired && !dpopKey) {
|
|
10178
10346
|
throw new Error(
|
|
10179
10347
|
"DPoP is required but WebCrypto could not create an authorization key"
|
|
@@ -10286,7 +10454,11 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10286
10454
|
created.stateId,
|
|
10287
10455
|
created.stateStorage
|
|
10288
10456
|
);
|
|
10289
|
-
const winner = await this.pendingRecord(
|
|
10457
|
+
const winner = await this.pendingRecord(
|
|
10458
|
+
generation,
|
|
10459
|
+
intent,
|
|
10460
|
+
start.requireMLDSA87DPoP
|
|
10461
|
+
);
|
|
10290
10462
|
if (!winner) throw error;
|
|
10291
10463
|
await ensureAuthorizationRequestState(
|
|
10292
10464
|
this.manager,
|
|
@@ -10351,7 +10523,7 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10351
10523
|
invalidateSignedOutLifecycle() {
|
|
10352
10524
|
return this.callbacks.invalidateSignedOutLifecycle();
|
|
10353
10525
|
}
|
|
10354
|
-
async pendingRecord(generation, intent) {
|
|
10526
|
+
async pendingRecord(generation, intent, requireMLDSA87DPoP) {
|
|
10355
10527
|
const record = await loadOrdinaryAuthorizationRecord(
|
|
10356
10528
|
ordinaryAuthorizationSlotKey(
|
|
10357
10529
|
this.binding,
|
|
@@ -10377,6 +10549,7 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10377
10549
|
record.intent
|
|
10378
10550
|
);
|
|
10379
10551
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
10552
|
+
if (await this.callbacks.retireObsoleteCustody(record)) return null;
|
|
10380
10553
|
if (record.intent !== intent) {
|
|
10381
10554
|
const pending = parseOrdinaryAuthorizationIntent(record.intent);
|
|
10382
10555
|
throw new OrdinaryAuthorizationIntentConflictError(
|
|
@@ -10391,6 +10564,7 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10391
10564
|
await this.callbacks.invalidateCurrent(generation);
|
|
10392
10565
|
return null;
|
|
10393
10566
|
}
|
|
10567
|
+
if (requireMLDSA87DPoP) assertMLDSA87DPoPKey(record.keys);
|
|
10394
10568
|
const expected = {
|
|
10395
10569
|
stateId: record.stateId,
|
|
10396
10570
|
tabOwnerGeneration: generation.tabOwner
|
|
@@ -10659,6 +10833,7 @@ var ResponseVaultRelay = class extends ResponseVaultSettlement {
|
|
|
10659
10833
|
throw new Error("response vault: relay binding is incomplete");
|
|
10660
10834
|
}
|
|
10661
10835
|
this.assertAuthorizationCurrent(authorization);
|
|
10836
|
+
this.assertActiveProofKey(authorization);
|
|
10662
10837
|
const endpoints = await this.endpointRegistry();
|
|
10663
10838
|
this.assertAuthorizationCurrent(authorization);
|
|
10664
10839
|
const proof = await authorization.dpopKey.signProof(
|
|
@@ -11066,21 +11241,17 @@ var ResponseVaultAdmission = class extends ResponseVaultRelay {
|
|
|
11066
11241
|
throw new ResponseVaultAuthorizationBusyError();
|
|
11067
11242
|
}
|
|
11068
11243
|
} else {
|
|
11069
|
-
await this.
|
|
11070
|
-
this.assertLifecycle(lifecycleEpoch);
|
|
11071
|
-
if (expectedGeneration) {
|
|
11072
|
-
assertCredentialGenerationSnapshot(this.config, expectedGeneration);
|
|
11073
|
-
}
|
|
11074
|
-
const dpopKey = await createDPoPKeyManager();
|
|
11075
|
-
this.assertLifecycle(lifecycleEpoch);
|
|
11076
|
-
if (expectedGeneration) {
|
|
11077
|
-
assertCredentialGenerationSnapshot(this.config, expectedGeneration);
|
|
11078
|
-
}
|
|
11244
|
+
const dpopKey = await createDPoPKeyManager(this.config.dpopAlgorithm);
|
|
11079
11245
|
if (!dpopKey) {
|
|
11080
11246
|
throw new Error(
|
|
11081
11247
|
"response vault: WebCrypto could not create a DPoP key"
|
|
11082
11248
|
);
|
|
11083
11249
|
}
|
|
11250
|
+
await this.endpointRegistry();
|
|
11251
|
+
this.assertLifecycle(lifecycleEpoch);
|
|
11252
|
+
if (expectedGeneration) {
|
|
11253
|
+
assertCredentialGenerationSnapshot(this.config, expectedGeneration);
|
|
11254
|
+
}
|
|
11084
11255
|
const codeVerifier = randomOpaque2();
|
|
11085
11256
|
const challenge = await codeChallenge(codeVerifier);
|
|
11086
11257
|
this.assertLifecycle(lifecycleEpoch);
|
|
@@ -11573,13 +11744,16 @@ function createBrowserAuthCallbackOperations(runtime) {
|
|
|
11573
11744
|
}
|
|
11574
11745
|
const completionEpoch = runtime.credentialEpoch;
|
|
11575
11746
|
const completion = (async () => {
|
|
11747
|
+
const callbackAuthority = persistedCredentialAuthority(
|
|
11748
|
+
runtime.credentialGenerationBinding
|
|
11749
|
+
);
|
|
11750
|
+
if (runtime.requireMLDSA87 && !callbackAuthority?.signedOut) {
|
|
11751
|
+
await runtime.lifecycleOps.ensureRuntimeInitialized();
|
|
11752
|
+
}
|
|
11576
11753
|
let returnToApplied = false;
|
|
11577
11754
|
let preserveCallbackForRetry = false;
|
|
11578
11755
|
try {
|
|
11579
|
-
|
|
11580
|
-
runtime.credentialGenerationBinding
|
|
11581
|
-
);
|
|
11582
|
-
if (callbackAuthority.signedOut) {
|
|
11756
|
+
if (callbackAuthority?.signedOut) {
|
|
11583
11757
|
if (runtime.responseVault) {
|
|
11584
11758
|
if (await runtime.lifecycleOps.settleSignedOutStartup(
|
|
11585
11759
|
callbackAuthority.generation
|
|
@@ -11587,7 +11761,6 @@ function createBrowserAuthCallbackOperations(runtime) {
|
|
|
11587
11761
|
throw new StaleCredentialTransactionError();
|
|
11588
11762
|
}
|
|
11589
11763
|
} else {
|
|
11590
|
-
await runtime.lifecycleOps.ensureRuntimeInitialized();
|
|
11591
11764
|
const callback2 = await readAuthorizationCodeResponseState(
|
|
11592
11765
|
runtime.manager,
|
|
11593
11766
|
window.location.href
|
|
@@ -11804,6 +11977,7 @@ function createBrowserAuthCallbackOperations(runtime) {
|
|
|
11804
11977
|
// src/client/browser-auth-context.ts
|
|
11805
11978
|
var BrowserAuthRuntime = class {
|
|
11806
11979
|
constructor(config) {
|
|
11980
|
+
this.createDPoPKey = () => createDPoPKeyManager(this.requireMLDSA87 ? ML_DSA_87 : "ES256");
|
|
11807
11981
|
this.currentUser = null;
|
|
11808
11982
|
this.fragmentKEK = null;
|
|
11809
11983
|
this.vault = null;
|
|
@@ -11865,12 +12039,14 @@ var BrowserAuthRuntime = class {
|
|
|
11865
12039
|
throw new Error("response-vault authorization requires an audience");
|
|
11866
12040
|
}
|
|
11867
12041
|
this.useDPoP = this.useResponseVault || dpopEnabled(config.dpop);
|
|
11868
|
-
this.
|
|
12042
|
+
this.requireMLDSA87 = config.requireMLDSA87 !== false;
|
|
12043
|
+
this.requireDPoP = this.useResponseVault || dpopRequired(config.dpop) || this.useDPoP && this.requireMLDSA87;
|
|
11869
12044
|
this.ordinaryExchangeBinding = {
|
|
11870
12045
|
issuer: this.issuer,
|
|
11871
12046
|
clientId: this.clientId,
|
|
11872
12047
|
useDPoP: this.useDPoP,
|
|
11873
|
-
requireDPoP: this.requireDPoP
|
|
12048
|
+
requireDPoP: this.requireDPoP,
|
|
12049
|
+
requireMLDSA87: this.requireMLDSA87
|
|
11874
12050
|
};
|
|
11875
12051
|
this.useRefreshTokens = config.useRefreshTokens ?? false;
|
|
11876
12052
|
this.useRefreshTokensFallback = config.useRefreshTokensFallback ?? false;
|
|
@@ -11880,6 +12056,9 @@ var BrowserAuthRuntime = class {
|
|
|
11880
12056
|
"response-vault v1 does not support deriveEncryptionKey"
|
|
11881
12057
|
);
|
|
11882
12058
|
}
|
|
12059
|
+
if (this.requireMLDSA87 && config.allowTestSessions) {
|
|
12060
|
+
throw new Error("ML-DSA-87 mode requires verified credentials");
|
|
12061
|
+
}
|
|
11883
12062
|
this.allowTestSessions = config.allowTestSessions ?? false;
|
|
11884
12063
|
this.initialTestSession = this.allowTestSessions ? config.initialTestSession : void 0;
|
|
11885
12064
|
if (this.allowTestSessions && typeof console !== "undefined") {
|
|
@@ -11901,7 +12080,8 @@ var BrowserAuthRuntime = class {
|
|
|
11901
12080
|
clientId: this.clientId,
|
|
11902
12081
|
redirectUri: this.redirectUri,
|
|
11903
12082
|
audience: this.audience,
|
|
11904
|
-
scope: this.scope
|
|
12083
|
+
scope: this.scope,
|
|
12084
|
+
dpopAlgorithm: this.requireMLDSA87 ? ML_DSA_87 : "ES256"
|
|
11905
12085
|
}) : null;
|
|
11906
12086
|
this.ordinaryAuthorization = this.responseVault ? null : new OrdinaryBrowserAuthorization(this.manager, {
|
|
11907
12087
|
issuer: this.issuer,
|
|
@@ -11954,6 +12134,7 @@ var BrowserAuthRuntime = class {
|
|
|
11954
12134
|
return result;
|
|
11955
12135
|
}
|
|
11956
12136
|
};
|
|
12137
|
+
var MAX_JWT_BYTES = 24 << 10;
|
|
11957
12138
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
11958
12139
|
function discover(authority) {
|
|
11959
12140
|
const cached = discoveryCache.get(authority);
|
|
@@ -12011,8 +12192,12 @@ function discover(authority) {
|
|
|
12011
12192
|
return promise;
|
|
12012
12193
|
}
|
|
12013
12194
|
async function verifyIdToken(idToken, opts) {
|
|
12195
|
+
const token = boundedJWT(idToken);
|
|
12196
|
+
const requireMLDSA87 = opts.requireMLDSA87 !== false;
|
|
12197
|
+
if (requireMLDSA87) await assertMLDSA87VerificationSupport();
|
|
12014
12198
|
const { issuer, jwks } = await discover(opts.authority);
|
|
12015
|
-
const { payload } = await jose.jwtVerify(
|
|
12199
|
+
const { payload } = await jose.jwtVerify(token, jwks, {
|
|
12200
|
+
algorithms: requireMLDSA87 ? [ML_DSA_87] : void 0,
|
|
12016
12201
|
issuer,
|
|
12017
12202
|
audience: opts.clientId,
|
|
12018
12203
|
requiredClaims: ["sub", "exp", "iat"]
|
|
@@ -12032,8 +12217,12 @@ async function verifyIdToken(idToken, opts) {
|
|
|
12032
12217
|
return payload;
|
|
12033
12218
|
}
|
|
12034
12219
|
async function verifyAccessToken(accessToken, opts) {
|
|
12220
|
+
const token = boundedJWT(accessToken);
|
|
12221
|
+
const requireMLDSA87 = opts.requireMLDSA87 !== false;
|
|
12222
|
+
if (requireMLDSA87) await assertMLDSA87VerificationSupport();
|
|
12035
12223
|
const { issuer, jwks } = await discover(opts.authority);
|
|
12036
|
-
const { payload, protectedHeader } = await jose.jwtVerify(
|
|
12224
|
+
const { payload, protectedHeader } = await jose.jwtVerify(token, jwks, {
|
|
12225
|
+
algorithms: requireMLDSA87 ? [ML_DSA_87] : void 0,
|
|
12037
12226
|
issuer,
|
|
12038
12227
|
audience: opts.audience,
|
|
12039
12228
|
requiredClaims: ["sub", "exp", "iat"]
|
|
@@ -12046,6 +12235,12 @@ async function verifyAccessToken(accessToken, opts) {
|
|
|
12046
12235
|
}
|
|
12047
12236
|
return payload;
|
|
12048
12237
|
}
|
|
12238
|
+
function boundedJWT(token) {
|
|
12239
|
+
if (token.length > MAX_JWT_BYTES) {
|
|
12240
|
+
throw new Error("JWT exceeds size limit");
|
|
12241
|
+
}
|
|
12242
|
+
return token;
|
|
12243
|
+
}
|
|
12049
12244
|
function _resetDiscoveryCache() {
|
|
12050
12245
|
discoveryCache.clear();
|
|
12051
12246
|
}
|
|
@@ -12085,7 +12280,8 @@ function createBrowserAuthCredentialOperations(runtime) {
|
|
|
12085
12280
|
} else {
|
|
12086
12281
|
accessClaims = await verifyAccessToken(tokens.access_token, {
|
|
12087
12282
|
authority: runtime.issuer,
|
|
12088
|
-
audience: runtime.audience ?? runtime.issuer
|
|
12283
|
+
audience: runtime.audience ?? runtime.issuer,
|
|
12284
|
+
requireMLDSA87: runtime.requireMLDSA87
|
|
12089
12285
|
});
|
|
12090
12286
|
}
|
|
12091
12287
|
if (!options.testSession) {
|
|
@@ -12094,6 +12290,9 @@ function createBrowserAuthCredentialOperations(runtime) {
|
|
|
12094
12290
|
}
|
|
12095
12291
|
const tokenType = tokens.token_type.toLowerCase();
|
|
12096
12292
|
const proofKey = options.dpopKey === void 0 ? runtime.dpop : options.dpopKey;
|
|
12293
|
+
if (runtime.requireMLDSA87 && runtime.useDPoP && (!proofKey || (await proofKey.publicJWK()).alg !== "ML-DSA-87")) {
|
|
12294
|
+
throw new Error("DPoP: credentials require an ML-DSA-87 proof key");
|
|
12295
|
+
}
|
|
12097
12296
|
if (proofKey) {
|
|
12098
12297
|
if (tokenType !== "dpop") {
|
|
12099
12298
|
throw new Error(
|
|
@@ -12130,7 +12329,8 @@ function createBrowserAuthCredentialOperations(runtime) {
|
|
|
12130
12329
|
idClaims = await verifyIdToken(idToken, {
|
|
12131
12330
|
authority: runtime.issuer,
|
|
12132
12331
|
clientId: runtime.clientId,
|
|
12133
|
-
nonce: options.expectedNonce
|
|
12332
|
+
nonce: options.expectedNonce,
|
|
12333
|
+
requireMLDSA87: runtime.requireMLDSA87
|
|
12134
12334
|
});
|
|
12135
12335
|
}
|
|
12136
12336
|
const accessSubject = accessClaims.sub;
|
|
@@ -12391,27 +12591,37 @@ function kekBase64ToBytes(b64) {
|
|
|
12391
12591
|
}
|
|
12392
12592
|
async function unwrapDEK(kekBase64, wrappedDEKBase64) {
|
|
12393
12593
|
const kek = kekBase64ToBytes(kekBase64);
|
|
12394
|
-
|
|
12395
|
-
|
|
12594
|
+
try {
|
|
12595
|
+
return await unwrapDEKWithKEK(kek, wrappedDEKBase64);
|
|
12596
|
+
} finally {
|
|
12597
|
+
kek.fill(0);
|
|
12598
|
+
}
|
|
12599
|
+
}
|
|
12600
|
+
async function unwrapDEKWithKEK(kek, formatted) {
|
|
12601
|
+
const isV2 = formatted.startsWith("v2.");
|
|
12602
|
+
const encoded = isV2 ? formatted.slice(3) : formatted;
|
|
12603
|
+
if (isV2) {
|
|
12604
|
+
if (kek.length !== 32 || encoded.length !== 80 || /[^A-Za-z0-9_-]/.test(encoded)) {
|
|
12605
|
+
throw new Error("unwrapDEK: invalid v2 wrapped DEK or KEK length");
|
|
12606
|
+
}
|
|
12607
|
+
} else if (kek.length !== 16 && kek.length !== 24 && kek.length !== 32) {
|
|
12396
12608
|
throw new Error(`unwrapDEK: KEK must be 16/24/32 bytes, got ${kek.length}`);
|
|
12397
12609
|
}
|
|
12610
|
+
const wrapped = base64ToBytes(encoded);
|
|
12398
12611
|
if (wrapped.length < 12 + 16) {
|
|
12399
12612
|
throw new Error("unwrapDEK: wrapped DEK shorter than nonce+tag");
|
|
12400
12613
|
}
|
|
12401
12614
|
const nonce = wrapped.slice(0, 12);
|
|
12402
|
-
const ciphertext = wrapped.slice(12);
|
|
12403
12615
|
const key = await crypto.subtle.importKey(
|
|
12404
12616
|
"raw",
|
|
12405
|
-
kek
|
|
12617
|
+
kek,
|
|
12406
12618
|
{ name: "AES-GCM" },
|
|
12407
12619
|
false,
|
|
12408
12620
|
["decrypt"]
|
|
12409
12621
|
);
|
|
12410
|
-
const
|
|
12411
|
-
|
|
12412
|
-
|
|
12413
|
-
ciphertext
|
|
12414
|
-
);
|
|
12622
|
+
const params = { name: "AES-GCM", iv: nonce.buffer };
|
|
12623
|
+
if (isV2) params.additionalData = new TextEncoder().encode("atol.dek.wrap.v2");
|
|
12624
|
+
const plaintext = await crypto.subtle.decrypt(params, key, wrapped.slice(12));
|
|
12415
12625
|
return new Uint8Array(plaintext);
|
|
12416
12626
|
}
|
|
12417
12627
|
|
|
@@ -12550,15 +12760,16 @@ function createBrowserAuthLifecycleOperations(runtime) {
|
|
|
12550
12760
|
if (runtime.destroyed) {
|
|
12551
12761
|
throw new Error("auth client has been destroyed");
|
|
12552
12762
|
}
|
|
12763
|
+
if (runtime.requireMLDSA87) await assertMLDSA87VerificationSupport();
|
|
12553
12764
|
if (runtime.deriveEncryptionKey) {
|
|
12554
12765
|
runtime.fragmentKEK = extractKEKFromFragment();
|
|
12555
12766
|
}
|
|
12556
|
-
if (runtime.useDPoP && !runtime.responseVault) {
|
|
12557
|
-
const initializedDPoP = await
|
|
12767
|
+
if (runtime.useDPoP && (!runtime.responseVault || runtime.requireMLDSA87)) {
|
|
12768
|
+
const initializedDPoP = await runtime.createDPoPKey();
|
|
12558
12769
|
if (runtime.destroyed) {
|
|
12559
12770
|
throw new Error("auth client has been destroyed");
|
|
12560
12771
|
}
|
|
12561
|
-
runtime.dpop = initializedDPoP;
|
|
12772
|
+
if (!runtime.responseVault) runtime.dpop = initializedDPoP;
|
|
12562
12773
|
if (!initializedDPoP && runtime.requireDPoP) {
|
|
12563
12774
|
throw new Error(
|
|
12564
12775
|
"DPoP is required but WebCrypto could not create a key"
|
|
@@ -12817,7 +13028,8 @@ function createBrowserAuthRenewalOperations(runtime) {
|
|
|
12817
13028
|
credentialGeneration: expectedGeneration,
|
|
12818
13029
|
nonce: generateAuthorizationNonce(),
|
|
12819
13030
|
state: authorizationState(void 0, expectedGeneration),
|
|
12820
|
-
createDPoPKey:
|
|
13031
|
+
createDPoPKey: runtime.createDPoPKey,
|
|
13032
|
+
requireMLDSA87DPoP: runtime.requireMLDSA87 && runtime.useDPoP
|
|
12821
13033
|
};
|
|
12822
13034
|
let lastError;
|
|
12823
13035
|
let callbackGrant;
|
|
@@ -13218,27 +13430,6 @@ function randomIV() {
|
|
|
13218
13430
|
function zero(bytes) {
|
|
13219
13431
|
for (let i = 0; i < bytes.length; i++) bytes[i] = 0;
|
|
13220
13432
|
}
|
|
13221
|
-
async function unwrapDEKWithKEK(kek, wrappedDEKBase64) {
|
|
13222
|
-
const wrapped = base64ToBytes(wrappedDEKBase64);
|
|
13223
|
-
if (wrapped.length < 12 + 16) {
|
|
13224
|
-
throw new Error("KEKVault: wrapped DEK shorter than nonce+tag");
|
|
13225
|
-
}
|
|
13226
|
-
const nonce = wrapped.slice(0, 12);
|
|
13227
|
-
const ciphertext = wrapped.slice(12);
|
|
13228
|
-
const key = await crypto.subtle.importKey(
|
|
13229
|
-
"raw",
|
|
13230
|
-
kek.buffer,
|
|
13231
|
-
{ name: "AES-GCM" },
|
|
13232
|
-
false,
|
|
13233
|
-
["decrypt"]
|
|
13234
|
-
);
|
|
13235
|
-
const plaintext = await crypto.subtle.decrypt(
|
|
13236
|
-
{ name: "AES-GCM", iv: nonce.buffer },
|
|
13237
|
-
key,
|
|
13238
|
-
ciphertext
|
|
13239
|
-
);
|
|
13240
|
-
return new Uint8Array(plaintext);
|
|
13241
|
-
}
|
|
13242
13433
|
var KEKVault = class {
|
|
13243
13434
|
/**
|
|
13244
13435
|
* Stash the KEK under a fresh device key, then unwrap the DEK and
|
|
@@ -13258,33 +13449,36 @@ var KEKVault = class {
|
|
|
13258
13449
|
if (wrappedDEKBase64 === "") {
|
|
13259
13450
|
throw new Error("KEKVault.provision: wrappedDEK is empty");
|
|
13260
13451
|
}
|
|
13261
|
-
const deviceKey = await crypto.subtle.generateKey(
|
|
13262
|
-
{ name: "AES-GCM", length: 256 },
|
|
13263
|
-
false,
|
|
13264
|
-
["encrypt", "decrypt"]
|
|
13265
|
-
);
|
|
13266
|
-
const iv = randomIV();
|
|
13267
|
-
const ciphertext = new Uint8Array(
|
|
13268
|
-
await crypto.subtle.encrypt(
|
|
13269
|
-
{ name: "AES-GCM", iv: iv.buffer },
|
|
13270
|
-
deviceKey,
|
|
13271
|
-
kekBytes.buffer
|
|
13272
|
-
)
|
|
13273
|
-
);
|
|
13274
|
-
const dek = await unwrapDEKWithKEK(kekBytes, wrappedDEKBase64);
|
|
13275
|
-
const db = await openDB2();
|
|
13276
13452
|
try {
|
|
13277
|
-
await
|
|
13278
|
-
|
|
13279
|
-
|
|
13280
|
-
|
|
13281
|
-
|
|
13282
|
-
|
|
13453
|
+
const deviceKey = await crypto.subtle.generateKey(
|
|
13454
|
+
{ name: "AES-GCM", length: 256 },
|
|
13455
|
+
false,
|
|
13456
|
+
["encrypt", "decrypt"]
|
|
13457
|
+
);
|
|
13458
|
+
const iv = randomIV();
|
|
13459
|
+
const ciphertext = new Uint8Array(
|
|
13460
|
+
await crypto.subtle.encrypt(
|
|
13461
|
+
{ name: "AES-GCM", iv: iv.buffer },
|
|
13462
|
+
deviceKey,
|
|
13463
|
+
kekBytes
|
|
13464
|
+
)
|
|
13465
|
+
);
|
|
13466
|
+
const dek = await unwrapDEKWithKEK(kekBytes, wrappedDEKBase64);
|
|
13467
|
+
const db = await openDB2();
|
|
13468
|
+
try {
|
|
13469
|
+
await writeRecord(db, {
|
|
13470
|
+
deviceKey,
|
|
13471
|
+
encryptedKEK: ciphertext,
|
|
13472
|
+
iv,
|
|
13473
|
+
version: CURRENT_VERSION
|
|
13474
|
+
});
|
|
13475
|
+
} finally {
|
|
13476
|
+
db.close();
|
|
13477
|
+
}
|
|
13478
|
+
return dek;
|
|
13283
13479
|
} finally {
|
|
13284
|
-
|
|
13480
|
+
zero(kekBytes);
|
|
13285
13481
|
}
|
|
13286
|
-
zero(kekBytes);
|
|
13287
|
-
return dek;
|
|
13288
13482
|
}
|
|
13289
13483
|
/**
|
|
13290
13484
|
* Rehydrate the DEK from the vault on silent-auth or page reload.
|
|
@@ -13744,6 +13938,7 @@ exports.DEFAULT_AUTHORIZE_TIMEOUT_MS = DEFAULT_AUTHORIZE_TIMEOUT_MS;
|
|
|
13744
13938
|
exports.DEFAULT_SILENT_RENEW_RETRY_COUNT = DEFAULT_SILENT_RENEW_RETRY_COUNT;
|
|
13745
13939
|
exports.KEKVault = KEKVault;
|
|
13746
13940
|
exports.LoginRequiredError = LoginRequiredError;
|
|
13941
|
+
exports.ML_DSA_87 = ML_DSA_87;
|
|
13747
13942
|
exports.NetworkError = NetworkError;
|
|
13748
13943
|
exports.OAuthProtocolError = OAuthProtocolError;
|
|
13749
13944
|
exports.OrdinaryAuthorizationIntentConflictError = OrdinaryAuthorizationIntentConflictError;
|