@atol-sh/js 0.4.2 → 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 +21 -0
- package/README.md +83 -10
- package/RESPONSE_VAULT_PROTOCOL.md +14 -4
- package/dist/index.cjs +554 -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 +555 -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;
|
|
@@ -5656,6 +5704,7 @@ var ResponseVaultCustodyLayer = class extends ResponseVaultRejection {
|
|
|
5656
5704
|
if (cancellation.reference.id === activeReferenceId) continue;
|
|
5657
5705
|
const owned = cancellation.binding.issuer === this.config.issuer && cancellation.binding.clientId === this.config.clientId && cancellation.binding.redirectUri === this.config.redirectUri && cancellation.binding.audience === this.config.audience && cancellation.binding.scope === this.config.scope && cancellation.credentialGeneration.tabOwner === currentGeneration.tabOwner;
|
|
5658
5706
|
if (!owned) continue;
|
|
5707
|
+
if (cancellation.expiresAt > Date.now()) continue;
|
|
5659
5708
|
try {
|
|
5660
5709
|
await this.probePublishedTerminal(cancellation);
|
|
5661
5710
|
} catch (error) {
|
|
@@ -5846,6 +5895,11 @@ var ResponseVaultCustodyLayer = class extends ResponseVaultRejection {
|
|
|
5846
5895
|
if (abandonedCleanupError !== void 0) {
|
|
5847
5896
|
throw new ResponseVaultCleanupPendingError(void 0);
|
|
5848
5897
|
}
|
|
5898
|
+
try {
|
|
5899
|
+
this.assertActiveProofKey(authorization);
|
|
5900
|
+
} catch (error) {
|
|
5901
|
+
failAfterCleanup(error);
|
|
5902
|
+
}
|
|
5849
5903
|
this.setActive(authorization.reference);
|
|
5850
5904
|
return authorization;
|
|
5851
5905
|
}
|
|
@@ -6512,7 +6566,8 @@ function userFromTokenResponse(tokens) {
|
|
|
6512
6566
|
var ORDINARY_AUTHORIZATION_DB_NAME = "atol-sdk-browser-auth";
|
|
6513
6567
|
var ORDINARY_AUTHORIZATION_DB_VERSION = 2;
|
|
6514
6568
|
var ORDINARY_AUTHORIZATION_STORE = "ordinary-authorizations";
|
|
6515
|
-
var
|
|
6569
|
+
var HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION = 2;
|
|
6570
|
+
var ORDINARY_AUTHORIZATION_RECORD_VERSION = 3;
|
|
6516
6571
|
var ORDINARY_AUTHORIZATION_POINTER_VERSION = 1;
|
|
6517
6572
|
var ORDINARY_AUTHORIZATION_PROTOCOL_VERSION = 2;
|
|
6518
6573
|
var AUTHORIZATION_CODE_LIFETIME_SECONDS = 600;
|
|
@@ -6523,12 +6578,13 @@ var CALLBACK_CLAIM_LIFETIME_MS = 2 * 6e4;
|
|
|
6523
6578
|
var CALLBACK_EXCHANGE_TIMEOUT_MS = 3e4;
|
|
6524
6579
|
var MAX_PAR_RESPONSE_BYTES = 16 * 1024;
|
|
6525
6580
|
var MAX_SETTLEMENT_RESPONSE_BYTES = 1024;
|
|
6526
|
-
var TERMINAL_PROOF_BYTES =
|
|
6527
|
-
var TERMINAL_PROOF_LENGTH =
|
|
6581
|
+
var TERMINAL_PROOF_BYTES = 74;
|
|
6582
|
+
var TERMINAL_PROOF_LENGTH = 99;
|
|
6528
6583
|
var REQUEST_URI_PREFIX = "urn:ietf:params:oauth:request_uri:";
|
|
6529
6584
|
var OIDC_CLIENT_STATE = /^[0-9a-f]{32}$/;
|
|
6530
6585
|
var CANONICAL_NONCE = /^[0-9a-f]{64}$/;
|
|
6531
6586
|
var CANONICAL_SHA256 = /^[A-Za-z0-9_-]{43}$/;
|
|
6587
|
+
var CANONICAL_SHA384 = /^[A-Za-z0-9_-]{64}$/;
|
|
6532
6588
|
var CANONICAL_AUTHORIZATION_CODE = /^[A-Za-z0-9._~-]{1,8192}$/;
|
|
6533
6589
|
function validCanonicalAttemptCapability(value) {
|
|
6534
6590
|
if (typeof value !== "string" || value.length !== TERMINAL_PROOF_LENGTH) {
|
|
@@ -6536,7 +6592,7 @@ function validCanonicalAttemptCapability(value) {
|
|
|
6536
6592
|
}
|
|
6537
6593
|
try {
|
|
6538
6594
|
const raw = base64ToBytes(value);
|
|
6539
|
-
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;
|
|
6540
6596
|
} catch {
|
|
6541
6597
|
return false;
|
|
6542
6598
|
}
|
|
@@ -6592,16 +6648,32 @@ function validCanonicalSHA256(value) {
|
|
|
6592
6648
|
return false;
|
|
6593
6649
|
}
|
|
6594
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
|
+
}
|
|
6595
6661
|
function validCanonicalAuthorizationCode(value) {
|
|
6596
6662
|
return CANONICAL_AUTHORIZATION_CODE.test(value);
|
|
6597
6663
|
}
|
|
6598
|
-
|
|
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) {
|
|
6599
6671
|
if (!validCanonicalAuthorizationCode(value)) {
|
|
6600
6672
|
throw new Error("ordinary browser authorization: callback code is invalid");
|
|
6601
6673
|
}
|
|
6602
6674
|
const digest = await crypto.subtle.digest(
|
|
6603
|
-
"SHA-
|
|
6604
|
-
new TextEncoder().encode(value)
|
|
6675
|
+
"SHA-384",
|
|
6676
|
+
new TextEncoder().encode(`atol.ordinary-authorization.callback-code.v2\0${value}`)
|
|
6605
6677
|
);
|
|
6606
6678
|
return bytesToBase64Url(new Uint8Array(digest));
|
|
6607
6679
|
}
|
|
@@ -7292,9 +7364,7 @@ function admittedSilentAuthorizationURL(opts) {
|
|
|
7292
7364
|
}
|
|
7293
7365
|
const names = new Set(entries.map(([name]) => name));
|
|
7294
7366
|
const requestUri = authorization.searchParams.get("request_uri");
|
|
7295
|
-
if (names.size !== 2 || !names.has("client_id") || !names.has("request_uri") ||
|
|
7296
|
-
requestUri.slice(REQUEST_URI_PREFIX.length)
|
|
7297
|
-
)) {
|
|
7367
|
+
if (names.size !== 2 || !names.has("client_id") || !names.has("request_uri") || !validOrdinaryAuthorizationRequestURI(requestUri)) {
|
|
7298
7368
|
throw new Error(
|
|
7299
7369
|
"silent authorization: admitted PAR navigation URL is invalid"
|
|
7300
7370
|
);
|
|
@@ -7539,16 +7609,16 @@ function createBrowserAuthActions(runtime) {
|
|
|
7539
7609
|
runtime.redirectUri
|
|
7540
7610
|
);
|
|
7541
7611
|
if (precedingLogout) await precedingLogout;
|
|
7542
|
-
const authorizationGeneration = credentialGenerationForLogin(
|
|
7543
|
-
runtime.credentialGenerationBinding
|
|
7544
|
-
);
|
|
7545
|
-
onGeneration?.(authorizationGeneration);
|
|
7546
7612
|
const authorizationEpoch = runtime.credentialEpoch;
|
|
7547
7613
|
await runtime.credentialMutationTail;
|
|
7548
7614
|
await runtime.lifecycleOps.ensureRuntimeInitialized();
|
|
7549
7615
|
if (runtime.destroyed || authorizationEpoch !== runtime.credentialEpoch) {
|
|
7550
7616
|
throw new StaleCredentialTransactionError();
|
|
7551
7617
|
}
|
|
7618
|
+
const authorizationGeneration = credentialGenerationForLogin(
|
|
7619
|
+
runtime.credentialGenerationBinding
|
|
7620
|
+
);
|
|
7621
|
+
onGeneration?.(authorizationGeneration);
|
|
7552
7622
|
runtime.sessionOps.assertCredentialAuthority(
|
|
7553
7623
|
authorizationGeneration
|
|
7554
7624
|
);
|
|
@@ -7594,7 +7664,8 @@ function createBrowserAuthActions(runtime) {
|
|
|
7594
7664
|
returnTo,
|
|
7595
7665
|
authorizationGeneration
|
|
7596
7666
|
),
|
|
7597
|
-
createDPoPKey:
|
|
7667
|
+
createDPoPKey: runtime.createDPoPKey,
|
|
7668
|
+
requireMLDSA87DPoP: runtime.requireMLDSA87 && runtime.useDPoP
|
|
7598
7669
|
});
|
|
7599
7670
|
}
|
|
7600
7671
|
function beginLogin(options) {
|
|
@@ -8016,6 +8087,9 @@ function assertOrdinaryAuthorizationDPoPBinding(binding, custody) {
|
|
|
8016
8087
|
return dpop;
|
|
8017
8088
|
}
|
|
8018
8089
|
async function exchangeOrdinaryAuthorizationCode(binding, callback, dpop) {
|
|
8090
|
+
if (binding.useDPoP && binding.requireMLDSA87) {
|
|
8091
|
+
assertMLDSA87DPoPKey(dpop ? dpopKeyPair(dpop) : null);
|
|
8092
|
+
}
|
|
8019
8093
|
const controller = new AbortController();
|
|
8020
8094
|
const timeout = setTimeout(
|
|
8021
8095
|
() => controller.abort(),
|
|
@@ -8125,6 +8199,93 @@ function stripOrdinaryAuthorizationResponseFromHistory(redirectUri) {
|
|
|
8125
8199
|
}
|
|
8126
8200
|
}
|
|
8127
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
|
+
|
|
8128
8289
|
// src/oidc/ordinary-authorization-protocol.ts
|
|
8129
8290
|
function ordinaryAuthorizationDiscoveryContract(metadata, binding) {
|
|
8130
8291
|
if (metadata.issuer !== binding.issuer) {
|
|
@@ -8190,7 +8351,7 @@ function validOrdinaryAuthorizationTerminalProof(value, rootExpiresAt) {
|
|
|
8190
8351
|
}
|
|
8191
8352
|
try {
|
|
8192
8353
|
const raw = base64ToBytes(value);
|
|
8193
|
-
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) {
|
|
8194
8355
|
return false;
|
|
8195
8356
|
}
|
|
8196
8357
|
let deadline = 0n;
|
|
@@ -8272,9 +8433,7 @@ function admittedOrdinaryAuthorizationRecord(record, responseText) {
|
|
|
8272
8433
|
"atol_browser_authorization_version",
|
|
8273
8434
|
"atol_browser_authorization_expires_at",
|
|
8274
8435
|
"terminal_proof"
|
|
8275
|
-
]) || record.parPhase !== "submitted" || typeof response.
|
|
8276
|
-
response.request_uri.slice(REQUEST_URI_PREFIX.length)
|
|
8277
|
-
) || !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(
|
|
8278
8437
|
"atol_attempt_capability"
|
|
8279
8438
|
)) {
|
|
8280
8439
|
throw new Error(
|
|
@@ -8413,7 +8572,7 @@ function readBoundedParResponse(response, signal) {
|
|
|
8413
8572
|
);
|
|
8414
8573
|
}
|
|
8415
8574
|
function ordinaryAuthorizationNavigationURL(record) {
|
|
8416
|
-
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) {
|
|
8417
8576
|
throw new Error(
|
|
8418
8577
|
"ordinary browser authorization: admitted root is expired"
|
|
8419
8578
|
);
|
|
@@ -8433,13 +8592,10 @@ var OrdinaryAuthorizationSettlementInvalidError = class extends Error {
|
|
|
8433
8592
|
this.name = "OrdinaryAuthorizationSettlementInvalidError";
|
|
8434
8593
|
}
|
|
8435
8594
|
};
|
|
8436
|
-
function assertSettlementAuthority(authority, mode) {
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
) || !validCanonicalSHA256(authority.cancellationSecret) ||
|
|
8440
|
-
authority.terminalProof,
|
|
8441
|
-
authority.rootExpiresAt
|
|
8442
|
-
)) || 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) {
|
|
8443
8599
|
throw new Error(
|
|
8444
8600
|
"ordinary browser authorization: settlement authority is invalid"
|
|
8445
8601
|
);
|
|
@@ -8481,7 +8637,13 @@ function settlementBody(authority, mode) {
|
|
|
8481
8637
|
});
|
|
8482
8638
|
}
|
|
8483
8639
|
async function settleOrdinaryAuthorization(authority, mode) {
|
|
8484
|
-
|
|
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);
|
|
8485
8647
|
const controller = new AbortController();
|
|
8486
8648
|
const timeout = setTimeout(
|
|
8487
8649
|
() => controller.abort(),
|
|
@@ -8662,7 +8824,7 @@ function parseOrdinaryAuthorizationPointer(raw) {
|
|
|
8662
8824
|
}
|
|
8663
8825
|
|
|
8664
8826
|
// src/oidc/ordinary-authorization-validation.ts
|
|
8665
|
-
function canonicalOrdinaryAuthorizationForm(authorizationURL, binding, created) {
|
|
8827
|
+
function canonicalOrdinaryAuthorizationForm(authorizationURL, binding, created, historicalCustody = false) {
|
|
8666
8828
|
const parsed = new URL(authorizationURL);
|
|
8667
8829
|
if (`${parsed.origin}${parsed.pathname}` !== `${binding.issuer}/auth/authorize` || parsed.username !== "" || parsed.password !== "" || parsed.hash !== "") {
|
|
8668
8830
|
throw new Error(
|
|
@@ -8680,9 +8842,7 @@ function canonicalOrdinaryAuthorizationForm(authorizationURL, binding, created)
|
|
|
8680
8842
|
seen.add(name);
|
|
8681
8843
|
values.set(name, value);
|
|
8682
8844
|
}
|
|
8683
|
-
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(
|
|
8684
|
-
values.get("atol_attempt_capability")
|
|
8685
|
-
) || 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"))) {
|
|
8686
8846
|
throw new Error(
|
|
8687
8847
|
"ordinary browser authorization: generated form binding is invalid"
|
|
8688
8848
|
);
|
|
@@ -8698,19 +8858,21 @@ function assertOrdinaryAuthorizationRecord(record, binding, generation, intent)
|
|
|
8698
8858
|
binding,
|
|
8699
8859
|
generation.tabOwner
|
|
8700
8860
|
);
|
|
8701
|
-
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)) {
|
|
8702
8862
|
throw new Error("ordinary browser authorization: custody binding mismatch");
|
|
8703
8863
|
}
|
|
8704
8864
|
const parameters = new URLSearchParams(record.form);
|
|
8865
|
+
const historicalCustody = isLegacyOrdinaryAuthorizationRecord(record);
|
|
8705
8866
|
const intentRecord = parseOrdinaryAuthorizationIntent(record.intent);
|
|
8706
|
-
if (canonicalOrdinaryAuthorizationForm(
|
|
8867
|
+
if (record.version === ORDINARY_AUTHORIZATION_RECORD_VERSION && (historicalCustody || isLegacyAuthorizationCodeCommitment(record.callbackCodeHash)) || historicalCustody && record.callbackCodeHash !== null && !isLegacyAuthorizationCodeCommitment(record.callbackCodeHash) || canonicalOrdinaryAuthorizationForm(
|
|
8707
8868
|
`${record.authorizationEndpoint}?${record.form}`,
|
|
8708
8869
|
binding,
|
|
8709
8870
|
{
|
|
8710
8871
|
stateId: record.stateId,
|
|
8711
8872
|
nonce: parameters.get("nonce") ?? "",
|
|
8712
8873
|
codeChallenge: parameters.get("code_challenge") ?? ""
|
|
8713
|
-
}
|
|
8874
|
+
},
|
|
8875
|
+
historicalCustody
|
|
8714
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(
|
|
8715
8877
|
([name, value]) => parameters.get(name) !== value
|
|
8716
8878
|
) || intentRecord.dpopRequired && record.dpopJkt === null || !intentRecord.dpopEnabled && record.dpopJkt !== null) {
|
|
@@ -8720,16 +8882,7 @@ function assertOrdinaryAuthorizationRecord(record, binding, generation, intent)
|
|
|
8720
8882
|
const parsedDeadline = rfc3339NanoMilliseconds(
|
|
8721
8883
|
record.rootExpiresAt
|
|
8722
8884
|
);
|
|
8723
|
-
if (!record.requestUri
|
|
8724
|
-
record.requestUri.slice(REQUEST_URI_PREFIX.length)
|
|
8725
|
-
) || !validOrdinaryAuthorizationTerminalProof(
|
|
8726
|
-
record.terminalProof,
|
|
8727
|
-
record.rootExpiresAt
|
|
8728
|
-
) || ordinaryAuthorizationAttemptCapabilityDeadline(
|
|
8729
|
-
parameters.get("atol_attempt_capability")
|
|
8730
|
-
) !== rfc3339NanoNanoseconds(
|
|
8731
|
-
record.rootExpiresAt
|
|
8732
|
-
) || parsedDeadline !== record.rootExpiresAtMs || Math.min(
|
|
8885
|
+
if (!validOrdinaryAuthorizationRequestURI(record.requestUri, historicalCustody) || !storedOrdinaryAuthorizationProofsMatch(record, parameters, historicalCustody) || parsedDeadline !== record.rootExpiresAtMs || Math.min(
|
|
8733
8886
|
record.attemptExpiresAtMs + record.authorizationCodeLifetimeSeconds * 1e3,
|
|
8734
8887
|
record.provisionalExpiresAt
|
|
8735
8888
|
) !== record.custodyExpiresAtMs) {
|
|
@@ -8739,6 +8892,15 @@ function assertOrdinaryAuthorizationRecord(record, binding, generation, intent)
|
|
|
8739
8892
|
}
|
|
8740
8893
|
}
|
|
8741
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
|
+
}
|
|
8742
8904
|
async function assertOrdinaryAuthorizationRecordState(record) {
|
|
8743
8905
|
const state = parseUniqueJSONObject(record.stateStorage, 32 * 1024);
|
|
8744
8906
|
if (!hasExactMembers(
|
|
@@ -8795,6 +8957,15 @@ async function assertOrdinaryAuthorizationRecordState(record) {
|
|
|
8795
8957
|
"ordinary browser authorization: stored application state mismatch"
|
|
8796
8958
|
);
|
|
8797
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
|
+
}
|
|
8798
8969
|
}
|
|
8799
8970
|
function assertOrdinaryAuthorizationCallbackMatches(record, callback, generation) {
|
|
8800
8971
|
const form = new URLSearchParams(record.form);
|
|
@@ -8875,11 +9046,6 @@ async function classifyOrdinaryAuthorizationRecordEnvelope(value) {
|
|
|
8875
9046
|
});
|
|
8876
9047
|
assertOrdinaryAuthorizationRecord(record, binding, generation, record.intent);
|
|
8877
9048
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
8878
|
-
if (record.callbackCode !== null && await authorizationCodeSHA256(record.callbackCode) !== record.callbackCodeHash) {
|
|
8879
|
-
throw new Error(
|
|
8880
|
-
"ordinary browser authorization: unrecognized custody record"
|
|
8881
|
-
);
|
|
8882
|
-
}
|
|
8883
9049
|
if (record.keys !== null) {
|
|
8884
9050
|
if (typeof record.keys !== "object" || !hasExactMembers(record.keys, [
|
|
8885
9051
|
"privateKey",
|
|
@@ -9053,11 +9219,11 @@ async function markOrdinaryAuthorizationPARSubmitted(expected) {
|
|
|
9053
9219
|
store.get(expected.slotKey),
|
|
9054
9220
|
"PAR submission read"
|
|
9055
9221
|
);
|
|
9056
|
-
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) {
|
|
9057
9223
|
await ordinaryAuthorizationTransactionDone(transaction, "stable PAR submission");
|
|
9058
9224
|
return current;
|
|
9059
9225
|
}
|
|
9060
|
-
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) {
|
|
9061
9227
|
transaction.abort();
|
|
9062
9228
|
throw new OrdinaryAuthorizationPendingError();
|
|
9063
9229
|
}
|
|
@@ -9110,11 +9276,11 @@ async function bindOrdinaryAuthorizationAttemptCapability(expected, attemptCapab
|
|
|
9110
9276
|
store.get(expected.slotKey),
|
|
9111
9277
|
"attempt capability read"
|
|
9112
9278
|
);
|
|
9113
|
-
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) {
|
|
9114
9280
|
await ordinaryAuthorizationTransactionDone(transaction, "stable attempt capability binding");
|
|
9115
9281
|
return current;
|
|
9116
9282
|
}
|
|
9117
|
-
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) {
|
|
9118
9284
|
transaction.abort();
|
|
9119
9285
|
throw new OrdinaryAuthorizationPendingError();
|
|
9120
9286
|
}
|
|
@@ -9143,16 +9309,17 @@ async function replaceOrdinaryAuthorizationRecord(expected, replacement) {
|
|
|
9143
9309
|
store.get(expected.slotKey),
|
|
9144
9310
|
"record bind read"
|
|
9145
9311
|
);
|
|
9146
|
-
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) {
|
|
9147
9313
|
await ordinaryAuthorizationTransactionDone(transaction, "stable record bind");
|
|
9148
9314
|
return current;
|
|
9149
9315
|
}
|
|
9150
|
-
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) {
|
|
9151
9317
|
transaction.abort();
|
|
9152
9318
|
throw new Error("ordinary browser authorization: custody was superseded");
|
|
9153
9319
|
}
|
|
9154
9320
|
const next = {
|
|
9155
9321
|
...replacement,
|
|
9322
|
+
version: current.version,
|
|
9156
9323
|
revision: current.revision + 1
|
|
9157
9324
|
};
|
|
9158
9325
|
store.put(next);
|
|
@@ -9174,11 +9341,11 @@ async function requireOrdinaryAuthorizationRejection(expected) {
|
|
|
9174
9341
|
store.get(expected.slotKey),
|
|
9175
9342
|
"rejection transition read"
|
|
9176
9343
|
);
|
|
9177
|
-
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) {
|
|
9178
9345
|
await ordinaryAuthorizationTransactionDone(transaction, "stable rejection transition");
|
|
9179
9346
|
return current;
|
|
9180
9347
|
}
|
|
9181
|
-
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) {
|
|
9182
9349
|
transaction.abort();
|
|
9183
9350
|
throw new OrdinaryAuthorizationPendingError();
|
|
9184
9351
|
}
|
|
@@ -9202,7 +9369,7 @@ function newClaimID() {
|
|
|
9202
9369
|
return bytesToBase64Url(value);
|
|
9203
9370
|
}
|
|
9204
9371
|
async function claimOrdinaryAuthorizationRecord(expected, callbackCode, callbackCodeHash) {
|
|
9205
|
-
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)) {
|
|
9206
9373
|
throw new Error("ordinary browser authorization: callback code is invalid");
|
|
9207
9374
|
}
|
|
9208
9375
|
const db = await openOrdinaryAuthorizationDB();
|
|
@@ -9217,7 +9384,7 @@ async function claimOrdinaryAuthorizationRecord(expected, callbackCode, callback
|
|
|
9217
9384
|
"callback claim read"
|
|
9218
9385
|
);
|
|
9219
9386
|
const now = Date.now();
|
|
9220
|
-
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) {
|
|
9221
9388
|
transaction.abort();
|
|
9222
9389
|
throw new OrdinaryAuthorizationPendingError();
|
|
9223
9390
|
}
|
|
@@ -9255,7 +9422,7 @@ async function markOrdinaryAuthorizationCodeIssued(expected) {
|
|
|
9255
9422
|
store.get(expected.slotKey),
|
|
9256
9423
|
"code issuance transition read"
|
|
9257
9424
|
);
|
|
9258
|
-
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) {
|
|
9259
9426
|
transaction.abort();
|
|
9260
9427
|
throw new Error(
|
|
9261
9428
|
"ordinary browser authorization: code issuance was superseded"
|
|
@@ -9285,11 +9452,11 @@ async function startOrdinaryAuthorizationCleanup(expected) {
|
|
|
9285
9452
|
store.get(expected.slotKey),
|
|
9286
9453
|
"cleanup transition read"
|
|
9287
9454
|
);
|
|
9288
|
-
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) {
|
|
9289
9456
|
await ordinaryAuthorizationTransactionDone(transaction, "stable cleanup transition");
|
|
9290
9457
|
return current;
|
|
9291
9458
|
}
|
|
9292
|
-
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) {
|
|
9293
9460
|
transaction.abort();
|
|
9294
9461
|
throw new Error("ordinary browser authorization: cleanup was superseded");
|
|
9295
9462
|
}
|
|
@@ -9319,7 +9486,7 @@ async function releaseOrdinaryAuthorizationClaim(expected) {
|
|
|
9319
9486
|
store.get(expected.slotKey),
|
|
9320
9487
|
"callback release read"
|
|
9321
9488
|
);
|
|
9322
|
-
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) {
|
|
9323
9490
|
transaction.abort();
|
|
9324
9491
|
throw new Error(
|
|
9325
9492
|
"ordinary browser authorization: callback release was superseded"
|
|
@@ -9353,7 +9520,7 @@ async function deleteOrdinaryAuthorizationRecordRevision(expected) {
|
|
|
9353
9520
|
await ordinaryAuthorizationTransactionDone(transaction, "idempotent record discard");
|
|
9354
9521
|
return;
|
|
9355
9522
|
}
|
|
9356
|
-
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) {
|
|
9357
9524
|
transaction.abort();
|
|
9358
9525
|
throw new Error("ordinary browser authorization: discard was superseded");
|
|
9359
9526
|
}
|
|
@@ -9369,6 +9536,10 @@ function validOrdinaryPARResponseHeaders(response) {
|
|
|
9369
9536
|
return response.headers.get("cache-control") === "no-store" && response.headers.get("content-type") === "application/json" && response.headers.get("atol-browser-authorization") === "v2";
|
|
9370
9537
|
}
|
|
9371
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
|
+
}
|
|
9372
9543
|
const startedAt = Date.now();
|
|
9373
9544
|
try {
|
|
9374
9545
|
const response = await fetch(record.pushedAuthorizationRequestEndpoint, {
|
|
@@ -9547,6 +9718,34 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9547
9718
|
await settleOrdinaryAuthorization(rejecting, "reject");
|
|
9548
9719
|
await this.startAndFinishCleanup(rejecting);
|
|
9549
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
|
+
}
|
|
9550
9749
|
async rejectSubmittedAndCleanup(record) {
|
|
9551
9750
|
const settled = await cancelSubmittedOrdinaryAuthorization(record);
|
|
9552
9751
|
await this.startAndFinishCleanup(settled);
|
|
@@ -9588,6 +9787,7 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9588
9787
|
record.intent
|
|
9589
9788
|
);
|
|
9590
9789
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
9790
|
+
if (await this.retireObsoleteCustody(record)) return;
|
|
9591
9791
|
if (record.cleanupStarted) {
|
|
9592
9792
|
await this.finishCleanup(record);
|
|
9593
9793
|
} else if (record.parPhase === "admitted") {
|
|
@@ -9609,6 +9809,12 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9609
9809
|
(record) => record.issuer === this.binding.issuer && record.clientId === this.binding.clientId && new URL(record.redirectUri).origin === new URL(this.binding.redirectUri).origin
|
|
9610
9810
|
);
|
|
9611
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
|
+
}
|
|
9612
9818
|
if (record.cleanupStarted) {
|
|
9613
9819
|
await this.finishCleanup(record);
|
|
9614
9820
|
} else if (record.parPhase === "admitted") {
|
|
@@ -9624,70 +9830,6 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9624
9830
|
}
|
|
9625
9831
|
};
|
|
9626
9832
|
|
|
9627
|
-
// src/oidc/ordinary-authorization-lock.ts
|
|
9628
|
-
async function acquireOrdinaryAuthorizationCallbackLock(slotKey2) {
|
|
9629
|
-
if (typeof navigator === "undefined" || !navigator.locks || typeof navigator.locks.request !== "function") {
|
|
9630
|
-
throw new Error(
|
|
9631
|
-
"ordinary browser authorization: Web Locks is required"
|
|
9632
|
-
);
|
|
9633
|
-
}
|
|
9634
|
-
const digest = await crypto.subtle.digest(
|
|
9635
|
-
"SHA-256",
|
|
9636
|
-
new TextEncoder().encode(slotKey2)
|
|
9637
|
-
);
|
|
9638
|
-
const name = `atol:ordinary-callback:${bytesToBase64Url(
|
|
9639
|
-
new Uint8Array(digest)
|
|
9640
|
-
)}`;
|
|
9641
|
-
let releaseHold;
|
|
9642
|
-
const hold = new Promise((resolve) => {
|
|
9643
|
-
releaseHold = resolve;
|
|
9644
|
-
});
|
|
9645
|
-
let resolveAcquired;
|
|
9646
|
-
let rejectAcquired;
|
|
9647
|
-
const acquired = new Promise((resolve, reject) => {
|
|
9648
|
-
resolveAcquired = resolve;
|
|
9649
|
-
rejectAcquired = reject;
|
|
9650
|
-
});
|
|
9651
|
-
let acquisitionSettled = false;
|
|
9652
|
-
const request = navigator.locks.request(
|
|
9653
|
-
name,
|
|
9654
|
-
{ mode: "exclusive", ifAvailable: true },
|
|
9655
|
-
async (lock) => {
|
|
9656
|
-
if (!lock) {
|
|
9657
|
-
acquisitionSettled = true;
|
|
9658
|
-
rejectAcquired(new OrdinaryAuthorizationPendingError());
|
|
9659
|
-
return;
|
|
9660
|
-
}
|
|
9661
|
-
acquisitionSettled = true;
|
|
9662
|
-
resolveAcquired();
|
|
9663
|
-
await hold;
|
|
9664
|
-
}
|
|
9665
|
-
);
|
|
9666
|
-
void request.catch((error) => {
|
|
9667
|
-
if (!acquisitionSettled) rejectAcquired(error);
|
|
9668
|
-
});
|
|
9669
|
-
try {
|
|
9670
|
-
await acquired;
|
|
9671
|
-
} catch (error) {
|
|
9672
|
-
releaseHold();
|
|
9673
|
-
try {
|
|
9674
|
-
await request;
|
|
9675
|
-
} catch (requestError) {
|
|
9676
|
-
throw requestError;
|
|
9677
|
-
}
|
|
9678
|
-
throw error;
|
|
9679
|
-
}
|
|
9680
|
-
let released = false;
|
|
9681
|
-
return {
|
|
9682
|
-
release: async () => {
|
|
9683
|
-
if (released) return;
|
|
9684
|
-
released = true;
|
|
9685
|
-
releaseHold();
|
|
9686
|
-
await request;
|
|
9687
|
-
}
|
|
9688
|
-
};
|
|
9689
|
-
}
|
|
9690
|
-
|
|
9691
9833
|
// src/oidc/ordinary-authorization-callback.ts
|
|
9692
9834
|
function callbackFromRecord(record) {
|
|
9693
9835
|
if (record.callbackCode === null) {
|
|
@@ -9757,6 +9899,11 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9757
9899
|
record.intent
|
|
9758
9900
|
);
|
|
9759
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
|
+
}
|
|
9760
9907
|
if (record.cleanupStarted) {
|
|
9761
9908
|
await this.cleanup.finishCleanup(record);
|
|
9762
9909
|
throw new Error(
|
|
@@ -9774,15 +9921,13 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9774
9921
|
callback,
|
|
9775
9922
|
generation
|
|
9776
9923
|
);
|
|
9777
|
-
const processLock = await acquireOrdinaryAuthorizationCallbackLock(
|
|
9778
|
-
record.slotKey
|
|
9779
|
-
);
|
|
9924
|
+
const processLock = await acquireOrdinaryAuthorizationCallbackLock(record);
|
|
9780
9925
|
let claimed;
|
|
9781
9926
|
try {
|
|
9782
9927
|
claimed = await claimOrdinaryAuthorizationRecord(
|
|
9783
9928
|
record,
|
|
9784
9929
|
callback.code ?? null,
|
|
9785
|
-
callback.code === void 0 ? null : await
|
|
9930
|
+
callback.code === void 0 ? null : await authorizationCodeCommitment(callback.code)
|
|
9786
9931
|
);
|
|
9787
9932
|
} catch (error) {
|
|
9788
9933
|
await processLock.release();
|
|
@@ -9810,7 +9955,7 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9810
9955
|
}
|
|
9811
9956
|
let settled = false;
|
|
9812
9957
|
const compensationRequired = claimed.compensationRequired;
|
|
9813
|
-
const
|
|
9958
|
+
const settle2 = async () => {
|
|
9814
9959
|
if (settled) {
|
|
9815
9960
|
throw new Error(
|
|
9816
9961
|
"ordinary browser authorization: callback custody is already settled"
|
|
@@ -9859,7 +10004,7 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9859
10004
|
throw error;
|
|
9860
10005
|
}
|
|
9861
10006
|
},
|
|
9862
|
-
complete:
|
|
10007
|
+
complete: settle2,
|
|
9863
10008
|
discard: async () => {
|
|
9864
10009
|
if (settled) {
|
|
9865
10010
|
throw new Error(
|
|
@@ -9899,6 +10044,7 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9899
10044
|
record.intent
|
|
9900
10045
|
);
|
|
9901
10046
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
10047
|
+
if (await this.retireObsoleteCustody(record)) return null;
|
|
9902
10048
|
if (record.cleanupStarted) {
|
|
9903
10049
|
await this.cleanup.finishCleanup(record);
|
|
9904
10050
|
return null;
|
|
@@ -9946,6 +10092,10 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9946
10092
|
callback,
|
|
9947
10093
|
generation
|
|
9948
10094
|
);
|
|
10095
|
+
if (record.version === HISTORICAL_ORDINARY_AUTHORIZATION_RECORD_VERSION) {
|
|
10096
|
+
await this.retireObsoleteCustodyForResponse(record, callback);
|
|
10097
|
+
return;
|
|
10098
|
+
}
|
|
9949
10099
|
if (callback.code !== void 0) {
|
|
9950
10100
|
record = await this.rejectCallbackCode(
|
|
9951
10101
|
record,
|
|
@@ -9977,9 +10127,20 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9977
10127
|
record.intent
|
|
9978
10128
|
);
|
|
9979
10129
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
9980
|
-
await this.
|
|
10130
|
+
if (!await this.retireObsoleteCustody(record)) {
|
|
10131
|
+
await this.cleanup.finishCleanup(record);
|
|
10132
|
+
}
|
|
9981
10133
|
return true;
|
|
9982
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
|
+
}
|
|
9983
10144
|
async invalidateCurrent(generation) {
|
|
9984
10145
|
return this.cleanup.invalidateCurrent(generation);
|
|
9985
10146
|
}
|
|
@@ -9987,15 +10148,13 @@ var OrdinaryAuthorizationCallbackController = class {
|
|
|
9987
10148
|
return this.cleanup.invalidateSignedOutLifecycle();
|
|
9988
10149
|
}
|
|
9989
10150
|
async rejectCallbackCode(record, code) {
|
|
9990
|
-
const processLock = await acquireOrdinaryAuthorizationCallbackLock(
|
|
9991
|
-
record.slotKey
|
|
9992
|
-
);
|
|
10151
|
+
const processLock = await acquireOrdinaryAuthorizationCallbackLock(record);
|
|
9993
10152
|
let claimed = null;
|
|
9994
10153
|
try {
|
|
9995
10154
|
claimed = await claimOrdinaryAuthorizationRecord(
|
|
9996
10155
|
record,
|
|
9997
10156
|
code,
|
|
9998
|
-
await
|
|
10157
|
+
await authorizationCodeCommitment(code)
|
|
9999
10158
|
);
|
|
10000
10159
|
try {
|
|
10001
10160
|
return await requireOrdinaryAuthorizationRejection(claimed);
|
|
@@ -10052,6 +10211,9 @@ async function rejectOrRetainInvalidAdmission(submitted) {
|
|
|
10052
10211
|
throw new OrdinaryAuthorizationPendingError();
|
|
10053
10212
|
}
|
|
10054
10213
|
async function admitOrdinaryAuthorization(record) {
|
|
10214
|
+
if (record.version !== ORDINARY_AUTHORIZATION_RECORD_VERSION) {
|
|
10215
|
+
throw new OrdinaryAuthorizationPendingError();
|
|
10216
|
+
}
|
|
10055
10217
|
if (ordinaryAuthorizationRecordExpired(record)) {
|
|
10056
10218
|
if (record.parPhase === "submitted") {
|
|
10057
10219
|
return rejectOrRetainInvalidAdmission(record);
|
|
@@ -10151,7 +10313,11 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10151
10313
|
const generation = start.credentialGeneration;
|
|
10152
10314
|
const intent = serializedOrdinaryAuthorizationIntent(start.intent);
|
|
10153
10315
|
assertCredentialGenerationSnapshot(this.binding, generation);
|
|
10154
|
-
const pending = await this.pendingRecord(
|
|
10316
|
+
const pending = await this.pendingRecord(
|
|
10317
|
+
generation,
|
|
10318
|
+
intent,
|
|
10319
|
+
start.requireMLDSA87DPoP
|
|
10320
|
+
);
|
|
10155
10321
|
if (pending) {
|
|
10156
10322
|
await ensureAuthorizationRequestState(
|
|
10157
10323
|
this.manager,
|
|
@@ -10173,6 +10339,9 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10173
10339
|
return;
|
|
10174
10340
|
}
|
|
10175
10341
|
const dpopKey = start.intent.dpopEnabled ? await start.createDPoPKey() : null;
|
|
10342
|
+
if (start.requireMLDSA87DPoP) {
|
|
10343
|
+
assertMLDSA87DPoPKey(dpopKey ? dpopKeyPair(dpopKey) : null);
|
|
10344
|
+
}
|
|
10176
10345
|
if (start.intent.dpopRequired && !dpopKey) {
|
|
10177
10346
|
throw new Error(
|
|
10178
10347
|
"DPoP is required but WebCrypto could not create an authorization key"
|
|
@@ -10285,7 +10454,11 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10285
10454
|
created.stateId,
|
|
10286
10455
|
created.stateStorage
|
|
10287
10456
|
);
|
|
10288
|
-
const winner = await this.pendingRecord(
|
|
10457
|
+
const winner = await this.pendingRecord(
|
|
10458
|
+
generation,
|
|
10459
|
+
intent,
|
|
10460
|
+
start.requireMLDSA87DPoP
|
|
10461
|
+
);
|
|
10289
10462
|
if (!winner) throw error;
|
|
10290
10463
|
await ensureAuthorizationRequestState(
|
|
10291
10464
|
this.manager,
|
|
@@ -10350,7 +10523,7 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10350
10523
|
invalidateSignedOutLifecycle() {
|
|
10351
10524
|
return this.callbacks.invalidateSignedOutLifecycle();
|
|
10352
10525
|
}
|
|
10353
|
-
async pendingRecord(generation, intent) {
|
|
10526
|
+
async pendingRecord(generation, intent, requireMLDSA87DPoP) {
|
|
10354
10527
|
const record = await loadOrdinaryAuthorizationRecord(
|
|
10355
10528
|
ordinaryAuthorizationSlotKey(
|
|
10356
10529
|
this.binding,
|
|
@@ -10376,6 +10549,7 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10376
10549
|
record.intent
|
|
10377
10550
|
);
|
|
10378
10551
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
10552
|
+
if (await this.callbacks.retireObsoleteCustody(record)) return null;
|
|
10379
10553
|
if (record.intent !== intent) {
|
|
10380
10554
|
const pending = parseOrdinaryAuthorizationIntent(record.intent);
|
|
10381
10555
|
throw new OrdinaryAuthorizationIntentConflictError(
|
|
@@ -10390,6 +10564,7 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10390
10564
|
await this.callbacks.invalidateCurrent(generation);
|
|
10391
10565
|
return null;
|
|
10392
10566
|
}
|
|
10567
|
+
if (requireMLDSA87DPoP) assertMLDSA87DPoPKey(record.keys);
|
|
10393
10568
|
const expected = {
|
|
10394
10569
|
stateId: record.stateId,
|
|
10395
10570
|
tabOwnerGeneration: generation.tabOwner
|
|
@@ -10658,6 +10833,7 @@ var ResponseVaultRelay = class extends ResponseVaultSettlement {
|
|
|
10658
10833
|
throw new Error("response vault: relay binding is incomplete");
|
|
10659
10834
|
}
|
|
10660
10835
|
this.assertAuthorizationCurrent(authorization);
|
|
10836
|
+
this.assertActiveProofKey(authorization);
|
|
10661
10837
|
const endpoints = await this.endpointRegistry();
|
|
10662
10838
|
this.assertAuthorizationCurrent(authorization);
|
|
10663
10839
|
const proof = await authorization.dpopKey.signProof(
|
|
@@ -11065,21 +11241,17 @@ var ResponseVaultAdmission = class extends ResponseVaultRelay {
|
|
|
11065
11241
|
throw new ResponseVaultAuthorizationBusyError();
|
|
11066
11242
|
}
|
|
11067
11243
|
} else {
|
|
11068
|
-
await this.
|
|
11069
|
-
this.assertLifecycle(lifecycleEpoch);
|
|
11070
|
-
if (expectedGeneration) {
|
|
11071
|
-
assertCredentialGenerationSnapshot(this.config, expectedGeneration);
|
|
11072
|
-
}
|
|
11073
|
-
const dpopKey = await createDPoPKeyManager();
|
|
11074
|
-
this.assertLifecycle(lifecycleEpoch);
|
|
11075
|
-
if (expectedGeneration) {
|
|
11076
|
-
assertCredentialGenerationSnapshot(this.config, expectedGeneration);
|
|
11077
|
-
}
|
|
11244
|
+
const dpopKey = await createDPoPKeyManager(this.config.dpopAlgorithm);
|
|
11078
11245
|
if (!dpopKey) {
|
|
11079
11246
|
throw new Error(
|
|
11080
11247
|
"response vault: WebCrypto could not create a DPoP key"
|
|
11081
11248
|
);
|
|
11082
11249
|
}
|
|
11250
|
+
await this.endpointRegistry();
|
|
11251
|
+
this.assertLifecycle(lifecycleEpoch);
|
|
11252
|
+
if (expectedGeneration) {
|
|
11253
|
+
assertCredentialGenerationSnapshot(this.config, expectedGeneration);
|
|
11254
|
+
}
|
|
11083
11255
|
const codeVerifier = randomOpaque2();
|
|
11084
11256
|
const challenge = await codeChallenge(codeVerifier);
|
|
11085
11257
|
this.assertLifecycle(lifecycleEpoch);
|
|
@@ -11572,13 +11744,16 @@ function createBrowserAuthCallbackOperations(runtime) {
|
|
|
11572
11744
|
}
|
|
11573
11745
|
const completionEpoch = runtime.credentialEpoch;
|
|
11574
11746
|
const completion = (async () => {
|
|
11747
|
+
const callbackAuthority = persistedCredentialAuthority(
|
|
11748
|
+
runtime.credentialGenerationBinding
|
|
11749
|
+
);
|
|
11750
|
+
if (runtime.requireMLDSA87 && !callbackAuthority?.signedOut) {
|
|
11751
|
+
await runtime.lifecycleOps.ensureRuntimeInitialized();
|
|
11752
|
+
}
|
|
11575
11753
|
let returnToApplied = false;
|
|
11576
11754
|
let preserveCallbackForRetry = false;
|
|
11577
11755
|
try {
|
|
11578
|
-
|
|
11579
|
-
runtime.credentialGenerationBinding
|
|
11580
|
-
);
|
|
11581
|
-
if (callbackAuthority.signedOut) {
|
|
11756
|
+
if (callbackAuthority?.signedOut) {
|
|
11582
11757
|
if (runtime.responseVault) {
|
|
11583
11758
|
if (await runtime.lifecycleOps.settleSignedOutStartup(
|
|
11584
11759
|
callbackAuthority.generation
|
|
@@ -11586,7 +11761,6 @@ function createBrowserAuthCallbackOperations(runtime) {
|
|
|
11586
11761
|
throw new StaleCredentialTransactionError();
|
|
11587
11762
|
}
|
|
11588
11763
|
} else {
|
|
11589
|
-
await runtime.lifecycleOps.ensureRuntimeInitialized();
|
|
11590
11764
|
const callback2 = await readAuthorizationCodeResponseState(
|
|
11591
11765
|
runtime.manager,
|
|
11592
11766
|
window.location.href
|
|
@@ -11803,6 +11977,7 @@ function createBrowserAuthCallbackOperations(runtime) {
|
|
|
11803
11977
|
// src/client/browser-auth-context.ts
|
|
11804
11978
|
var BrowserAuthRuntime = class {
|
|
11805
11979
|
constructor(config) {
|
|
11980
|
+
this.createDPoPKey = () => createDPoPKeyManager(this.requireMLDSA87 ? ML_DSA_87 : "ES256");
|
|
11806
11981
|
this.currentUser = null;
|
|
11807
11982
|
this.fragmentKEK = null;
|
|
11808
11983
|
this.vault = null;
|
|
@@ -11864,12 +12039,14 @@ var BrowserAuthRuntime = class {
|
|
|
11864
12039
|
throw new Error("response-vault authorization requires an audience");
|
|
11865
12040
|
}
|
|
11866
12041
|
this.useDPoP = this.useResponseVault || dpopEnabled(config.dpop);
|
|
11867
|
-
this.
|
|
12042
|
+
this.requireMLDSA87 = config.requireMLDSA87 !== false;
|
|
12043
|
+
this.requireDPoP = this.useResponseVault || dpopRequired(config.dpop) || this.useDPoP && this.requireMLDSA87;
|
|
11868
12044
|
this.ordinaryExchangeBinding = {
|
|
11869
12045
|
issuer: this.issuer,
|
|
11870
12046
|
clientId: this.clientId,
|
|
11871
12047
|
useDPoP: this.useDPoP,
|
|
11872
|
-
requireDPoP: this.requireDPoP
|
|
12048
|
+
requireDPoP: this.requireDPoP,
|
|
12049
|
+
requireMLDSA87: this.requireMLDSA87
|
|
11873
12050
|
};
|
|
11874
12051
|
this.useRefreshTokens = config.useRefreshTokens ?? false;
|
|
11875
12052
|
this.useRefreshTokensFallback = config.useRefreshTokensFallback ?? false;
|
|
@@ -11879,6 +12056,9 @@ var BrowserAuthRuntime = class {
|
|
|
11879
12056
|
"response-vault v1 does not support deriveEncryptionKey"
|
|
11880
12057
|
);
|
|
11881
12058
|
}
|
|
12059
|
+
if (this.requireMLDSA87 && config.allowTestSessions) {
|
|
12060
|
+
throw new Error("ML-DSA-87 mode requires verified credentials");
|
|
12061
|
+
}
|
|
11882
12062
|
this.allowTestSessions = config.allowTestSessions ?? false;
|
|
11883
12063
|
this.initialTestSession = this.allowTestSessions ? config.initialTestSession : void 0;
|
|
11884
12064
|
if (this.allowTestSessions && typeof console !== "undefined") {
|
|
@@ -11900,7 +12080,8 @@ var BrowserAuthRuntime = class {
|
|
|
11900
12080
|
clientId: this.clientId,
|
|
11901
12081
|
redirectUri: this.redirectUri,
|
|
11902
12082
|
audience: this.audience,
|
|
11903
|
-
scope: this.scope
|
|
12083
|
+
scope: this.scope,
|
|
12084
|
+
dpopAlgorithm: this.requireMLDSA87 ? ML_DSA_87 : "ES256"
|
|
11904
12085
|
}) : null;
|
|
11905
12086
|
this.ordinaryAuthorization = this.responseVault ? null : new OrdinaryBrowserAuthorization(this.manager, {
|
|
11906
12087
|
issuer: this.issuer,
|
|
@@ -11953,6 +12134,7 @@ var BrowserAuthRuntime = class {
|
|
|
11953
12134
|
return result;
|
|
11954
12135
|
}
|
|
11955
12136
|
};
|
|
12137
|
+
var MAX_JWT_BYTES = 24 << 10;
|
|
11956
12138
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
11957
12139
|
function discover(authority) {
|
|
11958
12140
|
const cached = discoveryCache.get(authority);
|
|
@@ -12010,8 +12192,12 @@ function discover(authority) {
|
|
|
12010
12192
|
return promise;
|
|
12011
12193
|
}
|
|
12012
12194
|
async function verifyIdToken(idToken, opts) {
|
|
12195
|
+
const token = boundedJWT(idToken);
|
|
12196
|
+
const requireMLDSA87 = opts.requireMLDSA87 !== false;
|
|
12197
|
+
if (requireMLDSA87) await assertMLDSA87VerificationSupport();
|
|
12013
12198
|
const { issuer, jwks } = await discover(opts.authority);
|
|
12014
|
-
const { payload } = await jose.jwtVerify(
|
|
12199
|
+
const { payload } = await jose.jwtVerify(token, jwks, {
|
|
12200
|
+
algorithms: requireMLDSA87 ? [ML_DSA_87] : void 0,
|
|
12015
12201
|
issuer,
|
|
12016
12202
|
audience: opts.clientId,
|
|
12017
12203
|
requiredClaims: ["sub", "exp", "iat"]
|
|
@@ -12031,8 +12217,12 @@ async function verifyIdToken(idToken, opts) {
|
|
|
12031
12217
|
return payload;
|
|
12032
12218
|
}
|
|
12033
12219
|
async function verifyAccessToken(accessToken, opts) {
|
|
12220
|
+
const token = boundedJWT(accessToken);
|
|
12221
|
+
const requireMLDSA87 = opts.requireMLDSA87 !== false;
|
|
12222
|
+
if (requireMLDSA87) await assertMLDSA87VerificationSupport();
|
|
12034
12223
|
const { issuer, jwks } = await discover(opts.authority);
|
|
12035
|
-
const { payload, protectedHeader } = await jose.jwtVerify(
|
|
12224
|
+
const { payload, protectedHeader } = await jose.jwtVerify(token, jwks, {
|
|
12225
|
+
algorithms: requireMLDSA87 ? [ML_DSA_87] : void 0,
|
|
12036
12226
|
issuer,
|
|
12037
12227
|
audience: opts.audience,
|
|
12038
12228
|
requiredClaims: ["sub", "exp", "iat"]
|
|
@@ -12045,6 +12235,12 @@ async function verifyAccessToken(accessToken, opts) {
|
|
|
12045
12235
|
}
|
|
12046
12236
|
return payload;
|
|
12047
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
|
+
}
|
|
12048
12244
|
function _resetDiscoveryCache() {
|
|
12049
12245
|
discoveryCache.clear();
|
|
12050
12246
|
}
|
|
@@ -12084,7 +12280,8 @@ function createBrowserAuthCredentialOperations(runtime) {
|
|
|
12084
12280
|
} else {
|
|
12085
12281
|
accessClaims = await verifyAccessToken(tokens.access_token, {
|
|
12086
12282
|
authority: runtime.issuer,
|
|
12087
|
-
audience: runtime.audience ?? runtime.issuer
|
|
12283
|
+
audience: runtime.audience ?? runtime.issuer,
|
|
12284
|
+
requireMLDSA87: runtime.requireMLDSA87
|
|
12088
12285
|
});
|
|
12089
12286
|
}
|
|
12090
12287
|
if (!options.testSession) {
|
|
@@ -12093,6 +12290,9 @@ function createBrowserAuthCredentialOperations(runtime) {
|
|
|
12093
12290
|
}
|
|
12094
12291
|
const tokenType = tokens.token_type.toLowerCase();
|
|
12095
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
|
+
}
|
|
12096
12296
|
if (proofKey) {
|
|
12097
12297
|
if (tokenType !== "dpop") {
|
|
12098
12298
|
throw new Error(
|
|
@@ -12129,7 +12329,8 @@ function createBrowserAuthCredentialOperations(runtime) {
|
|
|
12129
12329
|
idClaims = await verifyIdToken(idToken, {
|
|
12130
12330
|
authority: runtime.issuer,
|
|
12131
12331
|
clientId: runtime.clientId,
|
|
12132
|
-
nonce: options.expectedNonce
|
|
12332
|
+
nonce: options.expectedNonce,
|
|
12333
|
+
requireMLDSA87: runtime.requireMLDSA87
|
|
12133
12334
|
});
|
|
12134
12335
|
}
|
|
12135
12336
|
const accessSubject = accessClaims.sub;
|
|
@@ -12390,27 +12591,37 @@ function kekBase64ToBytes(b64) {
|
|
|
12390
12591
|
}
|
|
12391
12592
|
async function unwrapDEK(kekBase64, wrappedDEKBase64) {
|
|
12392
12593
|
const kek = kekBase64ToBytes(kekBase64);
|
|
12393
|
-
|
|
12394
|
-
|
|
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) {
|
|
12395
12608
|
throw new Error(`unwrapDEK: KEK must be 16/24/32 bytes, got ${kek.length}`);
|
|
12396
12609
|
}
|
|
12610
|
+
const wrapped = base64ToBytes(encoded);
|
|
12397
12611
|
if (wrapped.length < 12 + 16) {
|
|
12398
12612
|
throw new Error("unwrapDEK: wrapped DEK shorter than nonce+tag");
|
|
12399
12613
|
}
|
|
12400
12614
|
const nonce = wrapped.slice(0, 12);
|
|
12401
|
-
const ciphertext = wrapped.slice(12);
|
|
12402
12615
|
const key = await crypto.subtle.importKey(
|
|
12403
12616
|
"raw",
|
|
12404
|
-
kek
|
|
12617
|
+
kek,
|
|
12405
12618
|
{ name: "AES-GCM" },
|
|
12406
12619
|
false,
|
|
12407
12620
|
["decrypt"]
|
|
12408
12621
|
);
|
|
12409
|
-
const
|
|
12410
|
-
|
|
12411
|
-
|
|
12412
|
-
ciphertext
|
|
12413
|
-
);
|
|
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));
|
|
12414
12625
|
return new Uint8Array(plaintext);
|
|
12415
12626
|
}
|
|
12416
12627
|
|
|
@@ -12549,15 +12760,16 @@ function createBrowserAuthLifecycleOperations(runtime) {
|
|
|
12549
12760
|
if (runtime.destroyed) {
|
|
12550
12761
|
throw new Error("auth client has been destroyed");
|
|
12551
12762
|
}
|
|
12763
|
+
if (runtime.requireMLDSA87) await assertMLDSA87VerificationSupport();
|
|
12552
12764
|
if (runtime.deriveEncryptionKey) {
|
|
12553
12765
|
runtime.fragmentKEK = extractKEKFromFragment();
|
|
12554
12766
|
}
|
|
12555
|
-
if (runtime.useDPoP && !runtime.responseVault) {
|
|
12556
|
-
const initializedDPoP = await
|
|
12767
|
+
if (runtime.useDPoP && (!runtime.responseVault || runtime.requireMLDSA87)) {
|
|
12768
|
+
const initializedDPoP = await runtime.createDPoPKey();
|
|
12557
12769
|
if (runtime.destroyed) {
|
|
12558
12770
|
throw new Error("auth client has been destroyed");
|
|
12559
12771
|
}
|
|
12560
|
-
runtime.dpop = initializedDPoP;
|
|
12772
|
+
if (!runtime.responseVault) runtime.dpop = initializedDPoP;
|
|
12561
12773
|
if (!initializedDPoP && runtime.requireDPoP) {
|
|
12562
12774
|
throw new Error(
|
|
12563
12775
|
"DPoP is required but WebCrypto could not create a key"
|
|
@@ -12816,7 +13028,8 @@ function createBrowserAuthRenewalOperations(runtime) {
|
|
|
12816
13028
|
credentialGeneration: expectedGeneration,
|
|
12817
13029
|
nonce: generateAuthorizationNonce(),
|
|
12818
13030
|
state: authorizationState(void 0, expectedGeneration),
|
|
12819
|
-
createDPoPKey:
|
|
13031
|
+
createDPoPKey: runtime.createDPoPKey,
|
|
13032
|
+
requireMLDSA87DPoP: runtime.requireMLDSA87 && runtime.useDPoP
|
|
12820
13033
|
};
|
|
12821
13034
|
let lastError;
|
|
12822
13035
|
let callbackGrant;
|
|
@@ -13217,27 +13430,6 @@ function randomIV() {
|
|
|
13217
13430
|
function zero(bytes) {
|
|
13218
13431
|
for (let i = 0; i < bytes.length; i++) bytes[i] = 0;
|
|
13219
13432
|
}
|
|
13220
|
-
async function unwrapDEKWithKEK(kek, wrappedDEKBase64) {
|
|
13221
|
-
const wrapped = base64ToBytes(wrappedDEKBase64);
|
|
13222
|
-
if (wrapped.length < 12 + 16) {
|
|
13223
|
-
throw new Error("KEKVault: wrapped DEK shorter than nonce+tag");
|
|
13224
|
-
}
|
|
13225
|
-
const nonce = wrapped.slice(0, 12);
|
|
13226
|
-
const ciphertext = wrapped.slice(12);
|
|
13227
|
-
const key = await crypto.subtle.importKey(
|
|
13228
|
-
"raw",
|
|
13229
|
-
kek.buffer,
|
|
13230
|
-
{ name: "AES-GCM" },
|
|
13231
|
-
false,
|
|
13232
|
-
["decrypt"]
|
|
13233
|
-
);
|
|
13234
|
-
const plaintext = await crypto.subtle.decrypt(
|
|
13235
|
-
{ name: "AES-GCM", iv: nonce.buffer },
|
|
13236
|
-
key,
|
|
13237
|
-
ciphertext
|
|
13238
|
-
);
|
|
13239
|
-
return new Uint8Array(plaintext);
|
|
13240
|
-
}
|
|
13241
13433
|
var KEKVault = class {
|
|
13242
13434
|
/**
|
|
13243
13435
|
* Stash the KEK under a fresh device key, then unwrap the DEK and
|
|
@@ -13257,33 +13449,36 @@ var KEKVault = class {
|
|
|
13257
13449
|
if (wrappedDEKBase64 === "") {
|
|
13258
13450
|
throw new Error("KEKVault.provision: wrappedDEK is empty");
|
|
13259
13451
|
}
|
|
13260
|
-
const deviceKey = await crypto.subtle.generateKey(
|
|
13261
|
-
{ name: "AES-GCM", length: 256 },
|
|
13262
|
-
false,
|
|
13263
|
-
["encrypt", "decrypt"]
|
|
13264
|
-
);
|
|
13265
|
-
const iv = randomIV();
|
|
13266
|
-
const ciphertext = new Uint8Array(
|
|
13267
|
-
await crypto.subtle.encrypt(
|
|
13268
|
-
{ name: "AES-GCM", iv: iv.buffer },
|
|
13269
|
-
deviceKey,
|
|
13270
|
-
kekBytes.buffer
|
|
13271
|
-
)
|
|
13272
|
-
);
|
|
13273
|
-
const dek = await unwrapDEKWithKEK(kekBytes, wrappedDEKBase64);
|
|
13274
|
-
const db = await openDB2();
|
|
13275
13452
|
try {
|
|
13276
|
-
await
|
|
13277
|
-
|
|
13278
|
-
|
|
13279
|
-
|
|
13280
|
-
|
|
13281
|
-
|
|
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;
|
|
13282
13479
|
} finally {
|
|
13283
|
-
|
|
13480
|
+
zero(kekBytes);
|
|
13284
13481
|
}
|
|
13285
|
-
zero(kekBytes);
|
|
13286
|
-
return dek;
|
|
13287
13482
|
}
|
|
13288
13483
|
/**
|
|
13289
13484
|
* Rehydrate the DEK from the vault on silent-auth or page reload.
|
|
@@ -13743,6 +13938,7 @@ exports.DEFAULT_AUTHORIZE_TIMEOUT_MS = DEFAULT_AUTHORIZE_TIMEOUT_MS;
|
|
|
13743
13938
|
exports.DEFAULT_SILENT_RENEW_RETRY_COUNT = DEFAULT_SILENT_RENEW_RETRY_COUNT;
|
|
13744
13939
|
exports.KEKVault = KEKVault;
|
|
13745
13940
|
exports.LoginRequiredError = LoginRequiredError;
|
|
13941
|
+
exports.ML_DSA_87 = ML_DSA_87;
|
|
13746
13942
|
exports.NetworkError = NetworkError;
|
|
13747
13943
|
exports.OAuthProtocolError = OAuthProtocolError;
|
|
13748
13944
|
exports.OrdinaryAuthorizationIntentConflictError = OrdinaryAuthorizationIntentConflictError;
|