jose 6.0.3 → 6.0.5
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/dist/types/index.d.ts +6 -0
- package/dist/types/jwe/general/encrypt.d.ts +1 -0
- package/dist/types/jws/general/sign.d.ts +1 -0
- package/dist/types/jwt/unsecured.d.ts +1 -0
- package/dist/types/key/generate_key_pair.d.ts +2 -0
- package/dist/types/key/generate_secret.d.ts +1 -0
- package/dist/types/key/import.d.ts +1 -0
- package/dist/types/types.d.ts +8 -6
- package/dist/webapi/jwks/remote.js +1 -1
- package/dist/webapi/lib/asn1.js +9 -3
- package/dist/webapi/lib/base64url.js +21 -15
- package/dist/webapi/lib/buffer_utils.js +0 -4
- package/dist/webapi/lib/decrypt.js +9 -10
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -45,4 +45,10 @@ export { generateSecret } from './key/generate_secret.js';
|
|
|
45
45
|
export type { GenerateSecretOptions } from './key/generate_secret.js';
|
|
46
46
|
export * as base64url from './util/base64url.js';
|
|
47
47
|
export type { CompactDecryptResult, CompactJWEHeaderParameters, CompactJWSHeaderParameters, CompactVerifyResult, CritOption, CryptoKey, DecryptOptions, EncryptOptions, FlattenedDecryptResult, FlattenedJWE, FlattenedJWS, FlattenedJWSInput, FlattenedVerifyResult, GeneralDecryptResult, GeneralJWE, GeneralJWS, GeneralJWSInput, GeneralVerifyResult, GetKeyFunction, JoseHeaderParameters, JSONWebKeySet, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWK_EC_Private, JWK_EC_Public, JWK_oct, JWK_OKP_Private, JWK_OKP_Public, JWK_RSA_Private, JWK_RSA_Public, JWK, JWKParameters, JWSHeaderParameters, JWTClaimVerificationOptions, JWTDecryptResult, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject, ResolvedKey, SignOptions, VerifyOptions, } from './types.d.ts';
|
|
48
|
+
/**
|
|
49
|
+
* In prior releases this indicated whether a Node.js-specific build was loaded, this is now fixed
|
|
50
|
+
* to `"WebCryptoAPI"`
|
|
51
|
+
*
|
|
52
|
+
* @deprecated
|
|
53
|
+
*/
|
|
48
54
|
export declare const cryptoRuntime = "WebCryptoAPI";
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type * as types from '../types.d.ts';
|
|
7
7
|
import { ProduceJWT } from './produce.js';
|
|
8
|
+
/** Result of decoding an Unsecured JWT. */
|
|
8
9
|
export interface UnsecuredResult<PayloadType = types.JWTPayload> {
|
|
9
10
|
payload: PayloadType & types.JWTPayload;
|
|
10
11
|
header: types.JWSHeaderParameters;
|
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import type * as types from '../types.d.ts';
|
|
7
|
+
/** Asymmetric key pair generation function result. */
|
|
7
8
|
export interface GenerateKeyPairResult {
|
|
8
9
|
/** The generated Private Key. */
|
|
9
10
|
privateKey: types.CryptoKey;
|
|
10
11
|
/** Public Key corresponding to the generated Private Key. */
|
|
11
12
|
publicKey: types.CryptoKey;
|
|
12
13
|
}
|
|
14
|
+
/** Asymmetric key pair generation function options. */
|
|
13
15
|
export interface GenerateKeyPairOptions {
|
|
14
16
|
/**
|
|
15
17
|
* The EC "crv" (Curve) or OKP "crv" (Subtype of Key Pair) value to generate. The curve must be
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import type * as types from '../types.d.ts';
|
|
7
|
+
/** Secret generation function options. */
|
|
7
8
|
export interface GenerateSecretOptions {
|
|
8
9
|
/** The value to use as {@link !SubtleCrypto.generateKey} `extractable` argument. Default is false. */
|
|
9
10
|
extractable?: boolean;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Generic JSON Web Key Parameters. */
|
|
2
2
|
export interface JWKParameters {
|
|
3
3
|
/** JWK "kty" (Key Type) Parameter */
|
|
4
|
-
kty
|
|
4
|
+
kty?: string
|
|
5
5
|
/**
|
|
6
6
|
* JWK "alg" (Algorithm) Parameter
|
|
7
7
|
*
|
|
@@ -216,8 +216,8 @@ export interface GeneralJWSInput {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
|
-
* Flattened JWS
|
|
220
|
-
* ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) is used.
|
|
219
|
+
* Flattened JWS JSON Serialization Syntax token. Payload is returned as an empty string when JWS
|
|
220
|
+
* Unencoded Payload ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) is used.
|
|
221
221
|
*/
|
|
222
222
|
export interface FlattenedJWS extends Partial<FlattenedJWSInput> {
|
|
223
223
|
payload: string
|
|
@@ -225,8 +225,8 @@ export interface FlattenedJWS extends Partial<FlattenedJWSInput> {
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
/**
|
|
228
|
-
* General JWS
|
|
229
|
-
* ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) is used.
|
|
228
|
+
* General JWS JSON Serialization Syntax token. Payload is returned as an empty string when JWS
|
|
229
|
+
* Unencoded Payload ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) is used.
|
|
230
230
|
*/
|
|
231
231
|
export interface GeneralJWS {
|
|
232
232
|
payload: string
|
|
@@ -307,7 +307,7 @@ export interface JWEKeyManagementHeaderParameters {
|
|
|
307
307
|
epk?: CryptoKey | KeyObject
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
/** Flattened JWE
|
|
310
|
+
/** Flattened JWE JSON Serialization Syntax token. */
|
|
311
311
|
export interface FlattenedJWE {
|
|
312
312
|
/**
|
|
313
313
|
* The "aad" member MUST be present and contain the value BASE64URL(JWE AAD)) when the JWE AAD
|
|
@@ -361,6 +361,7 @@ export interface FlattenedJWE {
|
|
|
361
361
|
unprotected?: JWEHeaderParameters
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
/** General JWE JSON Serialization Syntax token. */
|
|
364
365
|
export interface GeneralJWE extends Omit<FlattenedJWE, 'encrypted_key' | 'header'> {
|
|
365
366
|
recipients: Pick<FlattenedJWE, 'encrypted_key' | 'header'>[]
|
|
366
367
|
}
|
|
@@ -647,6 +648,7 @@ export interface JWTDecryptResult<PayloadType = JWTPayload> {
|
|
|
647
648
|
protectedHeader: CompactJWEHeaderParameters
|
|
648
649
|
}
|
|
649
650
|
|
|
651
|
+
/** When key resolver functions are used this becomes part of successful resolves */
|
|
650
652
|
export interface ResolvedKey {
|
|
651
653
|
/** Key resolved from the key resolver function. */
|
|
652
654
|
key: CryptoKey | Uint8Array
|
|
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
|
|
|
9
9
|
let USER_AGENT;
|
|
10
10
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
11
11
|
const NAME = 'jose';
|
|
12
|
-
const VERSION = 'v6.0.
|
|
12
|
+
const VERSION = 'v6.0.5';
|
|
13
13
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
14
|
}
|
|
15
15
|
export const customFetch = Symbol();
|
package/dist/webapi/lib/asn1.js
CHANGED
|
@@ -185,11 +185,17 @@ function spkiFromX509(buf) {
|
|
|
185
185
|
const tbsCertificate = getElement(getElement(parseElement(buf).contents)[0].contents);
|
|
186
186
|
return encodeBase64(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
|
|
187
187
|
}
|
|
188
|
-
let
|
|
188
|
+
let createPublicKey;
|
|
189
189
|
function getSPKI(x509) {
|
|
190
|
-
|
|
190
|
+
try {
|
|
191
|
+
createPublicKey ??= globalThis.process?.getBuiltinModule?.('node:crypto')?.createPublicKey;
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
createPublicKey = 0;
|
|
195
|
+
}
|
|
196
|
+
if (createPublicKey) {
|
|
191
197
|
try {
|
|
192
|
-
return new
|
|
198
|
+
return new createPublicKey(x509).export({ format: 'pem', type: 'spki' });
|
|
193
199
|
}
|
|
194
200
|
catch { }
|
|
195
201
|
}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import { encoder, decoder
|
|
1
|
+
import { encoder, decoder } from '../lib/buffer_utils.js';
|
|
2
2
|
export function encodeBase64(input) {
|
|
3
|
-
if (
|
|
4
|
-
return
|
|
5
|
-
let unencoded = input;
|
|
6
|
-
if (typeof unencoded === 'string') {
|
|
7
|
-
unencoded = encoder.encode(unencoded);
|
|
3
|
+
if (Uint8Array.prototype.toBase64) {
|
|
4
|
+
return input.toBase64();
|
|
8
5
|
}
|
|
9
6
|
const CHUNK_SIZE = 0x8000;
|
|
10
7
|
const arr = [];
|
|
11
|
-
for (let i = 0; i <
|
|
12
|
-
arr.push(String.fromCharCode.apply(null,
|
|
8
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
9
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
13
10
|
}
|
|
14
11
|
return btoa(arr.join(''));
|
|
15
12
|
}
|
|
16
13
|
export function encode(input) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
let unencoded = input;
|
|
15
|
+
if (typeof unencoded === 'string') {
|
|
16
|
+
unencoded = encoder.encode(unencoded);
|
|
17
|
+
}
|
|
18
|
+
if (Uint8Array.prototype.toBase64) {
|
|
19
|
+
return unencoded.toBase64({ alphabet: 'base64url', omitPadding: true });
|
|
20
|
+
}
|
|
21
|
+
return encodeBase64(unencoded).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
20
22
|
}
|
|
21
23
|
export function decodeBase64(encoded) {
|
|
22
|
-
if (
|
|
23
|
-
return
|
|
24
|
+
if (Uint8Array.fromBase64) {
|
|
25
|
+
return Uint8Array.fromBase64(encoded);
|
|
26
|
+
}
|
|
24
27
|
const binary = atob(encoded);
|
|
25
28
|
const bytes = new Uint8Array(binary.length);
|
|
26
29
|
for (let i = 0; i < binary.length; i++) {
|
|
@@ -29,12 +32,15 @@ export function decodeBase64(encoded) {
|
|
|
29
32
|
return bytes;
|
|
30
33
|
}
|
|
31
34
|
export function decode(input) {
|
|
35
|
+
if (Uint8Array.fromBase64) {
|
|
36
|
+
return Uint8Array.fromBase64(typeof input === 'string' ? input : decoder.decode(input), {
|
|
37
|
+
alphabet: 'base64url',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
32
40
|
let encoded = input;
|
|
33
41
|
if (encoded instanceof Uint8Array) {
|
|
34
42
|
encoded = decoder.decode(encoded);
|
|
35
43
|
}
|
|
36
|
-
if (Buffer)
|
|
37
|
-
return Buffer.from(encoded, 'base64url');
|
|
38
44
|
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, '');
|
|
39
45
|
try {
|
|
40
46
|
return decodeBase64(encoded);
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
export const encoder = new TextEncoder();
|
|
2
2
|
export const decoder = new TextDecoder();
|
|
3
3
|
const MAX_INT32 = 2 ** 32;
|
|
4
|
-
const Buffer = globalThis.process?.getBuiltinModule?.('node:buffer')?.Buffer;
|
|
5
|
-
export { Buffer };
|
|
6
4
|
export function concat(...buffers) {
|
|
7
|
-
if (Buffer)
|
|
8
|
-
return Buffer.concat(buffers);
|
|
9
5
|
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
10
6
|
const buf = new Uint8Array(size);
|
|
11
7
|
let i = 0;
|
|
@@ -5,25 +5,24 @@ import { JOSENotSupported, JWEDecryptionFailed, JWEInvalid } from '../util/error
|
|
|
5
5
|
import { checkEncCryptoKey } from './crypto_key.js';
|
|
6
6
|
import invalidKeyInput from './invalid_key_input.js';
|
|
7
7
|
import { isCryptoKey } from './is_key_like.js';
|
|
8
|
-
|
|
9
|
-
timingSafeEqual ||= (a, b) => {
|
|
8
|
+
async function timingSafeEqual(a, b) {
|
|
10
9
|
if (!(a instanceof Uint8Array)) {
|
|
11
10
|
throw new TypeError('First argument must be a buffer');
|
|
12
11
|
}
|
|
13
12
|
if (!(b instanceof Uint8Array)) {
|
|
14
13
|
throw new TypeError('Second argument must be a buffer');
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
15
|
+
const algorithm = { name: 'HMAC', hash: 'SHA-256' };
|
|
16
|
+
const key = (await crypto.subtle.generateKey(algorithm, false, ['sign']));
|
|
17
|
+
const aHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, a));
|
|
18
|
+
const bHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, b));
|
|
20
19
|
let out = 0;
|
|
21
20
|
let i = -1;
|
|
22
|
-
while (++i <
|
|
23
|
-
out |=
|
|
21
|
+
while (++i < 32) {
|
|
22
|
+
out |= aHmac[i] ^ bHmac[i];
|
|
24
23
|
}
|
|
25
24
|
return out === 0;
|
|
26
|
-
}
|
|
25
|
+
}
|
|
27
26
|
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
28
27
|
if (!(cek instanceof Uint8Array)) {
|
|
29
28
|
throw new TypeError(invalidKeyInput(cek, 'Uint8Array'));
|
|
@@ -38,7 +37,7 @@ async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
38
37
|
const expectedTag = new Uint8Array((await crypto.subtle.sign('HMAC', macKey, macData)).slice(0, keySize >> 3));
|
|
39
38
|
let macCheckPassed;
|
|
40
39
|
try {
|
|
41
|
-
macCheckPassed = timingSafeEqual(tag, expectedTag);
|
|
40
|
+
macCheckPassed = await timingSafeEqual(tag, expectedTag);
|
|
42
41
|
}
|
|
43
42
|
catch {
|
|
44
43
|
}
|