initial commit
This commit is contained in:
32
server/node_modules/jose/dist/browser/runtime/aeskw.js
generated
vendored
Normal file
32
server/node_modules/jose/dist/browser/runtime/aeskw.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import bogusWebCrypto from './bogus.js';
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { types } from './is_key_like.js';
|
||||
function checkKeySize(key, alg) {
|
||||
if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
|
||||
throw new TypeError(`Invalid key size for alg: ${alg}`);
|
||||
}
|
||||
}
|
||||
function getCryptoKey(key, alg, usage) {
|
||||
if (isCryptoKey(key)) {
|
||||
checkEncCryptoKey(key, alg, usage);
|
||||
return key;
|
||||
}
|
||||
if (key instanceof Uint8Array) {
|
||||
return crypto.subtle.importKey('raw', key, 'AES-KW', true, [usage]);
|
||||
}
|
||||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
||||
}
|
||||
export const wrap = async (alg, key, cek) => {
|
||||
const cryptoKey = await getCryptoKey(key, alg, 'wrapKey');
|
||||
checkKeySize(cryptoKey, alg);
|
||||
const cryptoKeyCek = await crypto.subtle.importKey('raw', cek, ...bogusWebCrypto);
|
||||
return new Uint8Array(await crypto.subtle.wrapKey('raw', cryptoKeyCek, cryptoKey, 'AES-KW'));
|
||||
};
|
||||
export const unwrap = async (alg, key, encryptedKey) => {
|
||||
const cryptoKey = await getCryptoKey(key, alg, 'unwrapKey');
|
||||
checkKeySize(cryptoKey, alg);
|
||||
const cryptoKeyCek = await crypto.subtle.unwrapKey('raw', encryptedKey, cryptoKey, 'AES-KW', ...bogusWebCrypto);
|
||||
return new Uint8Array(await crypto.subtle.exportKey('raw', cryptoKeyCek));
|
||||
};
|
||||
202
server/node_modules/jose/dist/browser/runtime/asn1.js
generated
vendored
Normal file
202
server/node_modules/jose/dist/browser/runtime/asn1.js
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { encodeBase64, decodeBase64 } from './base64url.js';
|
||||
import formatPEM from '../lib/format_pem.js';
|
||||
import { JOSENotSupported } from '../util/errors.js';
|
||||
import { types } from './is_key_like.js';
|
||||
const genericExport = async (keyType, keyFormat, key) => {
|
||||
if (!isCryptoKey(key)) {
|
||||
throw new TypeError(invalidKeyInput(key, ...types));
|
||||
}
|
||||
if (!key.extractable) {
|
||||
throw new TypeError('CryptoKey is not extractable');
|
||||
}
|
||||
if (key.type !== keyType) {
|
||||
throw new TypeError(`key is not a ${keyType} key`);
|
||||
}
|
||||
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
||||
};
|
||||
export const toSPKI = (key) => {
|
||||
return genericExport('public', 'spki', key);
|
||||
};
|
||||
export const toPKCS8 = (key) => {
|
||||
return genericExport('private', 'pkcs8', key);
|
||||
};
|
||||
const findOid = (keyData, oid, from = 0) => {
|
||||
if (from === 0) {
|
||||
oid.unshift(oid.length);
|
||||
oid.unshift(0x06);
|
||||
}
|
||||
let i = keyData.indexOf(oid[0], from);
|
||||
if (i === -1)
|
||||
return false;
|
||||
const sub = keyData.subarray(i, i + oid.length);
|
||||
if (sub.length !== oid.length)
|
||||
return false;
|
||||
return sub.every((value, index) => value === oid[index]) || findOid(keyData, oid, i + 1);
|
||||
};
|
||||
const getNamedCurve = (keyData) => {
|
||||
switch (true) {
|
||||
case findOid(keyData, [0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07]):
|
||||
return 'P-256';
|
||||
case findOid(keyData, [0x2b, 0x81, 0x04, 0x00, 0x22]):
|
||||
return 'P-384';
|
||||
case findOid(keyData, [0x2b, 0x81, 0x04, 0x00, 0x23]):
|
||||
return 'P-521';
|
||||
case findOid(keyData, [0x2b, 0x65, 0x6e]):
|
||||
return 'X25519';
|
||||
case findOid(keyData, [0x2b, 0x65, 0x6f]):
|
||||
return 'X448';
|
||||
case findOid(keyData, [0x2b, 0x65, 0x70]):
|
||||
return 'Ed25519';
|
||||
case findOid(keyData, [0x2b, 0x65, 0x71]):
|
||||
return 'Ed448';
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported EC Key Curve or OKP Key Sub Type');
|
||||
}
|
||||
};
|
||||
const genericImport = async (replace, keyFormat, pem, alg, options) => {
|
||||
var _a;
|
||||
let algorithm;
|
||||
let keyUsages;
|
||||
const keyData = new Uint8Array(atob(pem.replace(replace, ''))
|
||||
.split('')
|
||||
.map((c) => c.charCodeAt(0)));
|
||||
const isPublic = keyFormat === 'spki';
|
||||
switch (alg) {
|
||||
case 'PS256':
|
||||
case 'PS384':
|
||||
case 'PS512':
|
||||
algorithm = { name: 'RSA-PSS', hash: `SHA-${alg.slice(-3)}` };
|
||||
keyUsages = isPublic ? ['verify'] : ['sign'];
|
||||
break;
|
||||
case 'RS256':
|
||||
case 'RS384':
|
||||
case 'RS512':
|
||||
algorithm = { name: 'RSASSA-PKCS1-v1_5', hash: `SHA-${alg.slice(-3)}` };
|
||||
keyUsages = isPublic ? ['verify'] : ['sign'];
|
||||
break;
|
||||
case 'RSA-OAEP':
|
||||
case 'RSA-OAEP-256':
|
||||
case 'RSA-OAEP-384':
|
||||
case 'RSA-OAEP-512':
|
||||
algorithm = {
|
||||
name: 'RSA-OAEP',
|
||||
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
|
||||
};
|
||||
keyUsages = isPublic ? ['encrypt', 'wrapKey'] : ['decrypt', 'unwrapKey'];
|
||||
break;
|
||||
case 'ES256':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-256' };
|
||||
keyUsages = isPublic ? ['verify'] : ['sign'];
|
||||
break;
|
||||
case 'ES384':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-384' };
|
||||
keyUsages = isPublic ? ['verify'] : ['sign'];
|
||||
break;
|
||||
case 'ES512':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-521' };
|
||||
keyUsages = isPublic ? ['verify'] : ['sign'];
|
||||
break;
|
||||
case 'ECDH-ES':
|
||||
case 'ECDH-ES+A128KW':
|
||||
case 'ECDH-ES+A192KW':
|
||||
case 'ECDH-ES+A256KW': {
|
||||
const namedCurve = getNamedCurve(keyData);
|
||||
algorithm = namedCurve.startsWith('P-') ? { name: 'ECDH', namedCurve } : { name: namedCurve };
|
||||
keyUsages = isPublic ? [] : ['deriveBits'];
|
||||
break;
|
||||
}
|
||||
case 'EdDSA':
|
||||
algorithm = { name: getNamedCurve(keyData) };
|
||||
keyUsages = isPublic ? ['verify'] : ['sign'];
|
||||
break;
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
||||
}
|
||||
return crypto.subtle.importKey(keyFormat, keyData, algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
|
||||
};
|
||||
export const fromPKCS8 = (pem, alg, options) => {
|
||||
return genericImport(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, 'pkcs8', pem, alg, options);
|
||||
};
|
||||
export const fromSPKI = (pem, alg, options) => {
|
||||
return genericImport(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, 'spki', pem, alg, options);
|
||||
};
|
||||
function getElement(seq) {
|
||||
let result = [];
|
||||
let next = 0;
|
||||
while (next < seq.length) {
|
||||
let nextPart = parseElement(seq.subarray(next));
|
||||
result.push(nextPart);
|
||||
next += nextPart.byteLength;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function parseElement(bytes) {
|
||||
let position = 0;
|
||||
let tag = bytes[0] & 0x1f;
|
||||
position++;
|
||||
if (tag === 0x1f) {
|
||||
tag = 0;
|
||||
while (bytes[position] >= 0x80) {
|
||||
tag = tag * 128 + bytes[position] - 0x80;
|
||||
position++;
|
||||
}
|
||||
tag = tag * 128 + bytes[position] - 0x80;
|
||||
position++;
|
||||
}
|
||||
let length = 0;
|
||||
if (bytes[position] < 0x80) {
|
||||
length = bytes[position];
|
||||
position++;
|
||||
}
|
||||
else if (length === 0x80) {
|
||||
length = 0;
|
||||
while (bytes[position + length] !== 0 || bytes[position + length + 1] !== 0) {
|
||||
if (length > bytes.byteLength) {
|
||||
throw new TypeError('invalid indefinite form length');
|
||||
}
|
||||
length++;
|
||||
}
|
||||
const byteLength = position + length + 2;
|
||||
return {
|
||||
byteLength,
|
||||
contents: bytes.subarray(position, position + length),
|
||||
raw: bytes.subarray(0, byteLength),
|
||||
};
|
||||
}
|
||||
else {
|
||||
let numberOfDigits = bytes[position] & 0x7f;
|
||||
position++;
|
||||
length = 0;
|
||||
for (let i = 0; i < numberOfDigits; i++) {
|
||||
length = length * 256 + bytes[position];
|
||||
position++;
|
||||
}
|
||||
}
|
||||
const byteLength = position + length;
|
||||
return {
|
||||
byteLength,
|
||||
contents: bytes.subarray(position, byteLength),
|
||||
raw: bytes.subarray(0, byteLength),
|
||||
};
|
||||
}
|
||||
function spkiFromX509(buf) {
|
||||
const tbsCertificate = getElement(getElement(parseElement(buf).contents)[0].contents);
|
||||
return encodeBase64(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
|
||||
}
|
||||
function getSPKI(x509) {
|
||||
const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, '');
|
||||
const raw = decodeBase64(pem);
|
||||
return formatPEM(spkiFromX509(raw), 'PUBLIC KEY');
|
||||
}
|
||||
export const fromX509 = (pem, alg, options) => {
|
||||
let spki;
|
||||
try {
|
||||
spki = getSPKI(pem);
|
||||
}
|
||||
catch (cause) {
|
||||
throw new TypeError('Failed to parse the X.509 certificate', { cause });
|
||||
}
|
||||
return fromSPKI(spki, alg, options);
|
||||
};
|
||||
37
server/node_modules/jose/dist/browser/runtime/base64url.js
generated
vendored
Normal file
37
server/node_modules/jose/dist/browser/runtime/base64url.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { encoder, decoder } from '../lib/buffer_utils.js';
|
||||
export const encodeBase64 = (input) => {
|
||||
let unencoded = input;
|
||||
if (typeof unencoded === 'string') {
|
||||
unencoded = encoder.encode(unencoded);
|
||||
}
|
||||
const CHUNK_SIZE = 0x8000;
|
||||
const arr = [];
|
||||
for (let i = 0; i < unencoded.length; i += CHUNK_SIZE) {
|
||||
arr.push(String.fromCharCode.apply(null, unencoded.subarray(i, i + CHUNK_SIZE)));
|
||||
}
|
||||
return btoa(arr.join(''));
|
||||
};
|
||||
export const encode = (input) => {
|
||||
return encodeBase64(input).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
||||
};
|
||||
export const decodeBase64 = (encoded) => {
|
||||
const binary = atob(encoded);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let i = 0; i < binary.length; i++) {
|
||||
bytes[i] = binary.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
export const decode = (input) => {
|
||||
let encoded = input;
|
||||
if (encoded instanceof Uint8Array) {
|
||||
encoded = decoder.decode(encoded);
|
||||
}
|
||||
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, '');
|
||||
try {
|
||||
return decodeBase64(encoded);
|
||||
}
|
||||
catch (_a) {
|
||||
throw new TypeError('The input to be decoded is not correctly encoded.');
|
||||
}
|
||||
};
|
||||
6
server/node_modules/jose/dist/browser/runtime/bogus.js
generated
vendored
Normal file
6
server/node_modules/jose/dist/browser/runtime/bogus.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
const bogusWebCrypto = [
|
||||
{ hash: 'SHA-256', name: 'HMAC' },
|
||||
true,
|
||||
['sign'],
|
||||
];
|
||||
export default bogusWebCrypto;
|
||||
8
server/node_modules/jose/dist/browser/runtime/check_cek_length.js
generated
vendored
Normal file
8
server/node_modules/jose/dist/browser/runtime/check_cek_length.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { JWEInvalid } from '../util/errors.js';
|
||||
const checkCekLength = (cek, expected) => {
|
||||
const actual = cek.byteLength << 3;
|
||||
if (actual !== expected) {
|
||||
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
||||
}
|
||||
};
|
||||
export default checkCekLength;
|
||||
8
server/node_modules/jose/dist/browser/runtime/check_key_length.js
generated
vendored
Normal file
8
server/node_modules/jose/dist/browser/runtime/check_key_length.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export default (alg, key) => {
|
||||
if (alg.startsWith('RS') || alg.startsWith('PS')) {
|
||||
const { modulusLength } = key.algorithm;
|
||||
if (typeof modulusLength !== 'number' || modulusLength < 2048) {
|
||||
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
||||
}
|
||||
}
|
||||
};
|
||||
85
server/node_modules/jose/dist/browser/runtime/decrypt.js
generated
vendored
Normal file
85
server/node_modules/jose/dist/browser/runtime/decrypt.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
import { concat, uint64be } from '../lib/buffer_utils.js';
|
||||
import checkIvLength from '../lib/check_iv_length.js';
|
||||
import checkCekLength from './check_cek_length.js';
|
||||
import timingSafeEqual from './timing_safe_equal.js';
|
||||
import { JOSENotSupported, JWEDecryptionFailed } from '../util/errors.js';
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { types } from './is_key_like.js';
|
||||
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
||||
if (!(cek instanceof Uint8Array)) {
|
||||
throw new TypeError(invalidKeyInput(cek, 'Uint8Array'));
|
||||
}
|
||||
const keySize = parseInt(enc.slice(1, 4), 10);
|
||||
const encKey = await crypto.subtle.importKey('raw', cek.subarray(keySize >> 3), 'AES-CBC', false, ['decrypt']);
|
||||
const macKey = await crypto.subtle.importKey('raw', cek.subarray(0, keySize >> 3), {
|
||||
hash: `SHA-${keySize << 1}`,
|
||||
name: 'HMAC',
|
||||
}, false, ['sign']);
|
||||
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
||||
const expectedTag = new Uint8Array((await crypto.subtle.sign('HMAC', macKey, macData)).slice(0, keySize >> 3));
|
||||
let macCheckPassed;
|
||||
try {
|
||||
macCheckPassed = timingSafeEqual(tag, expectedTag);
|
||||
}
|
||||
catch (_a) {
|
||||
}
|
||||
if (!macCheckPassed) {
|
||||
throw new JWEDecryptionFailed();
|
||||
}
|
||||
let plaintext;
|
||||
try {
|
||||
plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv, name: 'AES-CBC' }, encKey, ciphertext));
|
||||
}
|
||||
catch (_b) {
|
||||
}
|
||||
if (!plaintext) {
|
||||
throw new JWEDecryptionFailed();
|
||||
}
|
||||
return plaintext;
|
||||
}
|
||||
async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
||||
let encKey;
|
||||
if (cek instanceof Uint8Array) {
|
||||
encKey = await crypto.subtle.importKey('raw', cek, 'AES-GCM', false, ['decrypt']);
|
||||
}
|
||||
else {
|
||||
checkEncCryptoKey(cek, enc, 'decrypt');
|
||||
encKey = cek;
|
||||
}
|
||||
try {
|
||||
return new Uint8Array(await crypto.subtle.decrypt({
|
||||
additionalData: aad,
|
||||
iv,
|
||||
name: 'AES-GCM',
|
||||
tagLength: 128,
|
||||
}, encKey, concat(ciphertext, tag)));
|
||||
}
|
||||
catch (_a) {
|
||||
throw new JWEDecryptionFailed();
|
||||
}
|
||||
}
|
||||
const decrypt = async (enc, cek, ciphertext, iv, tag, aad) => {
|
||||
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
||||
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array'));
|
||||
}
|
||||
checkIvLength(enc, iv);
|
||||
switch (enc) {
|
||||
case 'A128CBC-HS256':
|
||||
case 'A192CBC-HS384':
|
||||
case 'A256CBC-HS512':
|
||||
if (cek instanceof Uint8Array)
|
||||
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
||||
return cbcDecrypt(enc, cek, ciphertext, iv, tag, aad);
|
||||
case 'A128GCM':
|
||||
case 'A192GCM':
|
||||
case 'A256GCM':
|
||||
if (cek instanceof Uint8Array)
|
||||
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
||||
return gcmDecrypt(enc, cek, ciphertext, iv, tag, aad);
|
||||
default:
|
||||
throw new JOSENotSupported('Unsupported JWE Content Encryption Algorithm');
|
||||
}
|
||||
};
|
||||
export default decrypt;
|
||||
6
server/node_modules/jose/dist/browser/runtime/digest.js
generated
vendored
Normal file
6
server/node_modules/jose/dist/browser/runtime/digest.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import crypto from './webcrypto.js';
|
||||
const digest = async (algorithm, data) => {
|
||||
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
||||
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
||||
};
|
||||
export default digest;
|
||||
46
server/node_modules/jose/dist/browser/runtime/ecdhes.js
generated
vendored
Normal file
46
server/node_modules/jose/dist/browser/runtime/ecdhes.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import { encoder, concat, uint32be, lengthAndInput, concatKdf } from '../lib/buffer_utils.js';
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { types } from './is_key_like.js';
|
||||
export async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) {
|
||||
if (!isCryptoKey(publicKey)) {
|
||||
throw new TypeError(invalidKeyInput(publicKey, ...types));
|
||||
}
|
||||
checkEncCryptoKey(publicKey, 'ECDH');
|
||||
if (!isCryptoKey(privateKey)) {
|
||||
throw new TypeError(invalidKeyInput(privateKey, ...types));
|
||||
}
|
||||
checkEncCryptoKey(privateKey, 'ECDH', 'deriveBits');
|
||||
const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
|
||||
let length;
|
||||
if (publicKey.algorithm.name === 'X25519') {
|
||||
length = 256;
|
||||
}
|
||||
else if (publicKey.algorithm.name === 'X448') {
|
||||
length = 448;
|
||||
}
|
||||
else {
|
||||
length =
|
||||
Math.ceil(parseInt(publicKey.algorithm.namedCurve.substr(-3), 10) / 8) << 3;
|
||||
}
|
||||
const sharedSecret = new Uint8Array(await crypto.subtle.deriveBits({
|
||||
name: publicKey.algorithm.name,
|
||||
public: publicKey,
|
||||
}, privateKey, length));
|
||||
return concatKdf(sharedSecret, keyLength, value);
|
||||
}
|
||||
export async function generateEpk(key) {
|
||||
if (!isCryptoKey(key)) {
|
||||
throw new TypeError(invalidKeyInput(key, ...types));
|
||||
}
|
||||
return crypto.subtle.generateKey(key.algorithm, true, ['deriveBits']);
|
||||
}
|
||||
export function ecdhAllowed(key) {
|
||||
if (!isCryptoKey(key)) {
|
||||
throw new TypeError(invalidKeyInput(key, ...types));
|
||||
}
|
||||
return (['P-256', 'P-384', 'P-521'].includes(key.algorithm.namedCurve) ||
|
||||
key.algorithm.name === 'X25519' ||
|
||||
key.algorithm.name === 'X448');
|
||||
}
|
||||
68
server/node_modules/jose/dist/browser/runtime/encrypt.js
generated
vendored
Normal file
68
server/node_modules/jose/dist/browser/runtime/encrypt.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import { concat, uint64be } from '../lib/buffer_utils.js';
|
||||
import checkIvLength from '../lib/check_iv_length.js';
|
||||
import checkCekLength from './check_cek_length.js';
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { JOSENotSupported } from '../util/errors.js';
|
||||
import { types } from './is_key_like.js';
|
||||
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
||||
if (!(cek instanceof Uint8Array)) {
|
||||
throw new TypeError(invalidKeyInput(cek, 'Uint8Array'));
|
||||
}
|
||||
const keySize = parseInt(enc.slice(1, 4), 10);
|
||||
const encKey = await crypto.subtle.importKey('raw', cek.subarray(keySize >> 3), 'AES-CBC', false, ['encrypt']);
|
||||
const macKey = await crypto.subtle.importKey('raw', cek.subarray(0, keySize >> 3), {
|
||||
hash: `SHA-${keySize << 1}`,
|
||||
name: 'HMAC',
|
||||
}, false, ['sign']);
|
||||
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
||||
iv,
|
||||
name: 'AES-CBC',
|
||||
}, encKey, plaintext));
|
||||
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
||||
const tag = new Uint8Array((await crypto.subtle.sign('HMAC', macKey, macData)).slice(0, keySize >> 3));
|
||||
return { ciphertext, tag };
|
||||
}
|
||||
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
||||
let encKey;
|
||||
if (cek instanceof Uint8Array) {
|
||||
encKey = await crypto.subtle.importKey('raw', cek, 'AES-GCM', false, ['encrypt']);
|
||||
}
|
||||
else {
|
||||
checkEncCryptoKey(cek, enc, 'encrypt');
|
||||
encKey = cek;
|
||||
}
|
||||
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
||||
additionalData: aad,
|
||||
iv,
|
||||
name: 'AES-GCM',
|
||||
tagLength: 128,
|
||||
}, encKey, plaintext));
|
||||
const tag = encrypted.slice(-16);
|
||||
const ciphertext = encrypted.slice(0, -16);
|
||||
return { ciphertext, tag };
|
||||
}
|
||||
const encrypt = async (enc, plaintext, cek, iv, aad) => {
|
||||
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
||||
throw new TypeError(invalidKeyInput(cek, ...types, 'Uint8Array'));
|
||||
}
|
||||
checkIvLength(enc, iv);
|
||||
switch (enc) {
|
||||
case 'A128CBC-HS256':
|
||||
case 'A192CBC-HS384':
|
||||
case 'A256CBC-HS512':
|
||||
if (cek instanceof Uint8Array)
|
||||
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
||||
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
||||
case 'A128GCM':
|
||||
case 'A192GCM':
|
||||
case 'A256GCM':
|
||||
if (cek instanceof Uint8Array)
|
||||
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
||||
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
||||
default:
|
||||
throw new JOSENotSupported('Unsupported JWE Content Encryption Algorithm');
|
||||
}
|
||||
};
|
||||
export default encrypt;
|
||||
34
server/node_modules/jose/dist/browser/runtime/fetch_jwks.js
generated
vendored
Normal file
34
server/node_modules/jose/dist/browser/runtime/fetch_jwks.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { JOSEError, JWKSTimeout } from '../util/errors.js';
|
||||
const fetchJwks = async (url, timeout, options) => {
|
||||
let controller;
|
||||
let id;
|
||||
let timedOut = false;
|
||||
if (typeof AbortController === 'function') {
|
||||
controller = new AbortController();
|
||||
id = setTimeout(() => {
|
||||
timedOut = true;
|
||||
controller.abort();
|
||||
}, timeout);
|
||||
}
|
||||
const response = await fetch(url.href, {
|
||||
signal: controller ? controller.signal : undefined,
|
||||
redirect: 'manual',
|
||||
headers: options.headers,
|
||||
}).catch((err) => {
|
||||
if (timedOut)
|
||||
throw new JWKSTimeout();
|
||||
throw err;
|
||||
});
|
||||
if (id !== undefined)
|
||||
clearTimeout(id);
|
||||
if (response.status !== 200) {
|
||||
throw new JOSEError('Expected 200 OK from the JSON Web Key Set HTTP response');
|
||||
}
|
||||
try {
|
||||
return await response.json();
|
||||
}
|
||||
catch (_a) {
|
||||
throw new JOSEError('Failed to parse the JSON Web Key Set HTTP response as JSON');
|
||||
}
|
||||
};
|
||||
export default fetchJwks;
|
||||
141
server/node_modules/jose/dist/browser/runtime/generate.js
generated
vendored
Normal file
141
server/node_modules/jose/dist/browser/runtime/generate.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
import crypto from './webcrypto.js';
|
||||
import { JOSENotSupported } from '../util/errors.js';
|
||||
import random from './random.js';
|
||||
export async function generateSecret(alg, options) {
|
||||
var _a;
|
||||
let length;
|
||||
let algorithm;
|
||||
let keyUsages;
|
||||
switch (alg) {
|
||||
case 'HS256':
|
||||
case 'HS384':
|
||||
case 'HS512':
|
||||
length = parseInt(alg.slice(-3), 10);
|
||||
algorithm = { name: 'HMAC', hash: `SHA-${length}`, length };
|
||||
keyUsages = ['sign', 'verify'];
|
||||
break;
|
||||
case 'A128CBC-HS256':
|
||||
case 'A192CBC-HS384':
|
||||
case 'A256CBC-HS512':
|
||||
length = parseInt(alg.slice(-3), 10);
|
||||
return random(new Uint8Array(length >> 3));
|
||||
case 'A128KW':
|
||||
case 'A192KW':
|
||||
case 'A256KW':
|
||||
length = parseInt(alg.slice(1, 4), 10);
|
||||
algorithm = { name: 'AES-KW', length };
|
||||
keyUsages = ['wrapKey', 'unwrapKey'];
|
||||
break;
|
||||
case 'A128GCMKW':
|
||||
case 'A192GCMKW':
|
||||
case 'A256GCMKW':
|
||||
case 'A128GCM':
|
||||
case 'A192GCM':
|
||||
case 'A256GCM':
|
||||
length = parseInt(alg.slice(1, 4), 10);
|
||||
algorithm = { name: 'AES-GCM', length };
|
||||
keyUsages = ['encrypt', 'decrypt'];
|
||||
break;
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
||||
}
|
||||
return crypto.subtle.generateKey(algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
|
||||
}
|
||||
function getModulusLengthOption(options) {
|
||||
var _a;
|
||||
const modulusLength = (_a = options === null || options === void 0 ? void 0 : options.modulusLength) !== null && _a !== void 0 ? _a : 2048;
|
||||
if (typeof modulusLength !== 'number' || modulusLength < 2048) {
|
||||
throw new JOSENotSupported('Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used');
|
||||
}
|
||||
return modulusLength;
|
||||
}
|
||||
export async function generateKeyPair(alg, options) {
|
||||
var _a, _b, _c;
|
||||
let algorithm;
|
||||
let keyUsages;
|
||||
switch (alg) {
|
||||
case 'PS256':
|
||||
case 'PS384':
|
||||
case 'PS512':
|
||||
algorithm = {
|
||||
name: 'RSA-PSS',
|
||||
hash: `SHA-${alg.slice(-3)}`,
|
||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
||||
modulusLength: getModulusLengthOption(options),
|
||||
};
|
||||
keyUsages = ['sign', 'verify'];
|
||||
break;
|
||||
case 'RS256':
|
||||
case 'RS384':
|
||||
case 'RS512':
|
||||
algorithm = {
|
||||
name: 'RSASSA-PKCS1-v1_5',
|
||||
hash: `SHA-${alg.slice(-3)}`,
|
||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
||||
modulusLength: getModulusLengthOption(options),
|
||||
};
|
||||
keyUsages = ['sign', 'verify'];
|
||||
break;
|
||||
case 'RSA-OAEP':
|
||||
case 'RSA-OAEP-256':
|
||||
case 'RSA-OAEP-384':
|
||||
case 'RSA-OAEP-512':
|
||||
algorithm = {
|
||||
name: 'RSA-OAEP',
|
||||
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
|
||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
||||
modulusLength: getModulusLengthOption(options),
|
||||
};
|
||||
keyUsages = ['decrypt', 'unwrapKey', 'encrypt', 'wrapKey'];
|
||||
break;
|
||||
case 'ES256':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-256' };
|
||||
keyUsages = ['sign', 'verify'];
|
||||
break;
|
||||
case 'ES384':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-384' };
|
||||
keyUsages = ['sign', 'verify'];
|
||||
break;
|
||||
case 'ES512':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-521' };
|
||||
keyUsages = ['sign', 'verify'];
|
||||
break;
|
||||
case 'EdDSA':
|
||||
keyUsages = ['sign', 'verify'];
|
||||
const crv = (_a = options === null || options === void 0 ? void 0 : options.crv) !== null && _a !== void 0 ? _a : 'Ed25519';
|
||||
switch (crv) {
|
||||
case 'Ed25519':
|
||||
case 'Ed448':
|
||||
algorithm = { name: crv };
|
||||
break;
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported crv option provided');
|
||||
}
|
||||
break;
|
||||
case 'ECDH-ES':
|
||||
case 'ECDH-ES+A128KW':
|
||||
case 'ECDH-ES+A192KW':
|
||||
case 'ECDH-ES+A256KW': {
|
||||
keyUsages = ['deriveKey', 'deriveBits'];
|
||||
const crv = (_b = options === null || options === void 0 ? void 0 : options.crv) !== null && _b !== void 0 ? _b : 'P-256';
|
||||
switch (crv) {
|
||||
case 'P-256':
|
||||
case 'P-384':
|
||||
case 'P-521': {
|
||||
algorithm = { name: 'ECDH', namedCurve: crv };
|
||||
break;
|
||||
}
|
||||
case 'X25519':
|
||||
case 'X448':
|
||||
algorithm = { name: crv };
|
||||
break;
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448');
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
||||
}
|
||||
return (crypto.subtle.generateKey(algorithm, (_c = options === null || options === void 0 ? void 0 : options.extractable) !== null && _c !== void 0 ? _c : false, keyUsages));
|
||||
}
|
||||
17
server/node_modules/jose/dist/browser/runtime/get_sign_verify_key.js
generated
vendored
Normal file
17
server/node_modules/jose/dist/browser/runtime/get_sign_verify_key.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import { checkSigCryptoKey } from '../lib/crypto_key.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { types } from './is_key_like.js';
|
||||
export default function getCryptoKey(alg, key, usage) {
|
||||
if (isCryptoKey(key)) {
|
||||
checkSigCryptoKey(key, alg, usage);
|
||||
return key;
|
||||
}
|
||||
if (key instanceof Uint8Array) {
|
||||
if (!alg.startsWith('HS')) {
|
||||
throw new TypeError(invalidKeyInput(key, ...types));
|
||||
}
|
||||
return crypto.subtle.importKey('raw', key, { hash: `SHA-${alg.slice(-3)}`, name: 'HMAC' }, false, [usage]);
|
||||
}
|
||||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
||||
}
|
||||
5
server/node_modules/jose/dist/browser/runtime/is_key_like.js
generated
vendored
Normal file
5
server/node_modules/jose/dist/browser/runtime/is_key_like.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { isCryptoKey } from './webcrypto.js';
|
||||
export default (key) => {
|
||||
return isCryptoKey(key);
|
||||
};
|
||||
export const types = ['CryptoKey'];
|
||||
143
server/node_modules/jose/dist/browser/runtime/jwk_to_key.js
generated
vendored
Normal file
143
server/node_modules/jose/dist/browser/runtime/jwk_to_key.js
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
import crypto from './webcrypto.js';
|
||||
import { JOSENotSupported } from '../util/errors.js';
|
||||
import { decode as base64url } from './base64url.js';
|
||||
function subtleMapping(jwk) {
|
||||
let algorithm;
|
||||
let keyUsages;
|
||||
switch (jwk.kty) {
|
||||
case 'oct': {
|
||||
switch (jwk.alg) {
|
||||
case 'HS256':
|
||||
case 'HS384':
|
||||
case 'HS512':
|
||||
algorithm = { name: 'HMAC', hash: `SHA-${jwk.alg.slice(-3)}` };
|
||||
keyUsages = ['sign', 'verify'];
|
||||
break;
|
||||
case 'A128CBC-HS256':
|
||||
case 'A192CBC-HS384':
|
||||
case 'A256CBC-HS512':
|
||||
throw new JOSENotSupported(`${jwk.alg} keys cannot be imported as CryptoKey instances`);
|
||||
case 'A128GCM':
|
||||
case 'A192GCM':
|
||||
case 'A256GCM':
|
||||
case 'A128GCMKW':
|
||||
case 'A192GCMKW':
|
||||
case 'A256GCMKW':
|
||||
algorithm = { name: 'AES-GCM' };
|
||||
keyUsages = ['encrypt', 'decrypt'];
|
||||
break;
|
||||
case 'A128KW':
|
||||
case 'A192KW':
|
||||
case 'A256KW':
|
||||
algorithm = { name: 'AES-KW' };
|
||||
keyUsages = ['wrapKey', 'unwrapKey'];
|
||||
break;
|
||||
case 'PBES2-HS256+A128KW':
|
||||
case 'PBES2-HS384+A192KW':
|
||||
case 'PBES2-HS512+A256KW':
|
||||
algorithm = { name: 'PBKDF2' };
|
||||
keyUsages = ['deriveBits'];
|
||||
break;
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'RSA': {
|
||||
switch (jwk.alg) {
|
||||
case 'PS256':
|
||||
case 'PS384':
|
||||
case 'PS512':
|
||||
algorithm = { name: 'RSA-PSS', hash: `SHA-${jwk.alg.slice(-3)}` };
|
||||
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
||||
break;
|
||||
case 'RS256':
|
||||
case 'RS384':
|
||||
case 'RS512':
|
||||
algorithm = { name: 'RSASSA-PKCS1-v1_5', hash: `SHA-${jwk.alg.slice(-3)}` };
|
||||
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
||||
break;
|
||||
case 'RSA-OAEP':
|
||||
case 'RSA-OAEP-256':
|
||||
case 'RSA-OAEP-384':
|
||||
case 'RSA-OAEP-512':
|
||||
algorithm = {
|
||||
name: 'RSA-OAEP',
|
||||
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`,
|
||||
};
|
||||
keyUsages = jwk.d ? ['decrypt', 'unwrapKey'] : ['encrypt', 'wrapKey'];
|
||||
break;
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'EC': {
|
||||
switch (jwk.alg) {
|
||||
case 'ES256':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-256' };
|
||||
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
||||
break;
|
||||
case 'ES384':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-384' };
|
||||
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
||||
break;
|
||||
case 'ES512':
|
||||
algorithm = { name: 'ECDSA', namedCurve: 'P-521' };
|
||||
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
||||
break;
|
||||
case 'ECDH-ES':
|
||||
case 'ECDH-ES+A128KW':
|
||||
case 'ECDH-ES+A192KW':
|
||||
case 'ECDH-ES+A256KW':
|
||||
algorithm = { name: 'ECDH', namedCurve: jwk.crv };
|
||||
keyUsages = jwk.d ? ['deriveBits'] : [];
|
||||
break;
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'OKP': {
|
||||
switch (jwk.alg) {
|
||||
case 'EdDSA':
|
||||
algorithm = { name: jwk.crv };
|
||||
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
||||
break;
|
||||
case 'ECDH-ES':
|
||||
case 'ECDH-ES+A128KW':
|
||||
case 'ECDH-ES+A192KW':
|
||||
case 'ECDH-ES+A256KW':
|
||||
algorithm = { name: jwk.crv };
|
||||
keyUsages = jwk.d ? ['deriveBits'] : [];
|
||||
break;
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
||||
}
|
||||
return { algorithm, keyUsages };
|
||||
}
|
||||
const parse = async (jwk) => {
|
||||
var _a, _b;
|
||||
if (!jwk.alg) {
|
||||
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
||||
}
|
||||
const { algorithm, keyUsages } = subtleMapping(jwk);
|
||||
const rest = [
|
||||
algorithm,
|
||||
(_a = jwk.ext) !== null && _a !== void 0 ? _a : false,
|
||||
(_b = jwk.key_ops) !== null && _b !== void 0 ? _b : keyUsages,
|
||||
];
|
||||
if (algorithm.name === 'PBKDF2') {
|
||||
return crypto.subtle.importKey('raw', base64url(jwk.k), ...rest);
|
||||
}
|
||||
const keyData = { ...jwk };
|
||||
delete keyData.alg;
|
||||
delete keyData.use;
|
||||
return crypto.subtle.importKey('jwk', keyData, ...rest);
|
||||
};
|
||||
export default parse;
|
||||
21
server/node_modules/jose/dist/browser/runtime/key_to_jwk.js
generated
vendored
Normal file
21
server/node_modules/jose/dist/browser/runtime/key_to_jwk.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { encode as base64url } from './base64url.js';
|
||||
import { types } from './is_key_like.js';
|
||||
const keyToJWK = async (key) => {
|
||||
if (key instanceof Uint8Array) {
|
||||
return {
|
||||
kty: 'oct',
|
||||
k: base64url(key),
|
||||
};
|
||||
}
|
||||
if (!isCryptoKey(key)) {
|
||||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
||||
}
|
||||
if (!key.extractable) {
|
||||
throw new TypeError('non-extractable CryptoKey cannot be exported as a JWK');
|
||||
}
|
||||
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey('jwk', key);
|
||||
return jwk;
|
||||
};
|
||||
export default keyToJWK;
|
||||
51
server/node_modules/jose/dist/browser/runtime/pbes2kw.js
generated
vendored
Normal file
51
server/node_modules/jose/dist/browser/runtime/pbes2kw.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import random from './random.js';
|
||||
import { p2s as concatSalt } from '../lib/buffer_utils.js';
|
||||
import { encode as base64url } from './base64url.js';
|
||||
import { wrap, unwrap } from './aeskw.js';
|
||||
import checkP2s from '../lib/check_p2s.js';
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { types } from './is_key_like.js';
|
||||
function getCryptoKey(key, alg) {
|
||||
if (key instanceof Uint8Array) {
|
||||
return crypto.subtle.importKey('raw', key, 'PBKDF2', false, ['deriveBits']);
|
||||
}
|
||||
if (isCryptoKey(key)) {
|
||||
checkEncCryptoKey(key, alg, 'deriveBits', 'deriveKey');
|
||||
return key;
|
||||
}
|
||||
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
|
||||
}
|
||||
async function deriveKey(p2s, alg, p2c, key) {
|
||||
checkP2s(p2s);
|
||||
const salt = concatSalt(alg, p2s);
|
||||
const keylen = parseInt(alg.slice(13, 16), 10);
|
||||
const subtleAlg = {
|
||||
hash: `SHA-${alg.slice(8, 11)}`,
|
||||
iterations: p2c,
|
||||
name: 'PBKDF2',
|
||||
salt,
|
||||
};
|
||||
const wrapAlg = {
|
||||
length: keylen,
|
||||
name: 'AES-KW',
|
||||
};
|
||||
const cryptoKey = await getCryptoKey(key, alg);
|
||||
if (cryptoKey.usages.includes('deriveBits')) {
|
||||
return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
|
||||
}
|
||||
if (cryptoKey.usages.includes('deriveKey')) {
|
||||
return crypto.subtle.deriveKey(subtleAlg, cryptoKey, wrapAlg, false, ['wrapKey', 'unwrapKey']);
|
||||
}
|
||||
throw new TypeError('PBKDF2 key "usages" must include "deriveBits" or "deriveKey"');
|
||||
}
|
||||
export const encrypt = async (alg, key, cek, p2c = 2048, p2s = random(new Uint8Array(16))) => {
|
||||
const derived = await deriveKey(p2s, alg, p2c, key);
|
||||
const encryptedKey = await wrap(alg.slice(-6), derived, cek);
|
||||
return { encryptedKey, p2c, p2s: base64url(p2s) };
|
||||
};
|
||||
export const decrypt = async (alg, key, encryptedKey, p2c, p2s) => {
|
||||
const derived = await deriveKey(p2s, alg, p2c, key);
|
||||
return unwrap(alg.slice(-6), derived, encryptedKey);
|
||||
};
|
||||
2
server/node_modules/jose/dist/browser/runtime/random.js
generated
vendored
Normal file
2
server/node_modules/jose/dist/browser/runtime/random.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import crypto from './webcrypto.js';
|
||||
export default crypto.getRandomValues.bind(crypto);
|
||||
37
server/node_modules/jose/dist/browser/runtime/rsaes.js
generated
vendored
Normal file
37
server/node_modules/jose/dist/browser/runtime/rsaes.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import subtleAlgorithm from './subtle_rsaes.js';
|
||||
import bogusWebCrypto from './bogus.js';
|
||||
import crypto, { isCryptoKey } from './webcrypto.js';
|
||||
import { checkEncCryptoKey } from '../lib/crypto_key.js';
|
||||
import checkKeyLength from './check_key_length.js';
|
||||
import invalidKeyInput from '../lib/invalid_key_input.js';
|
||||
import { types } from './is_key_like.js';
|
||||
export const encrypt = async (alg, key, cek) => {
|
||||
if (!isCryptoKey(key)) {
|
||||
throw new TypeError(invalidKeyInput(key, ...types));
|
||||
}
|
||||
checkEncCryptoKey(key, alg, 'encrypt', 'wrapKey');
|
||||
checkKeyLength(alg, key);
|
||||
if (key.usages.includes('encrypt')) {
|
||||
return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm(alg), key, cek));
|
||||
}
|
||||
if (key.usages.includes('wrapKey')) {
|
||||
const cryptoKeyCek = await crypto.subtle.importKey('raw', cek, ...bogusWebCrypto);
|
||||
return new Uint8Array(await crypto.subtle.wrapKey('raw', cryptoKeyCek, key, subtleAlgorithm(alg)));
|
||||
}
|
||||
throw new TypeError('RSA-OAEP key "usages" must include "encrypt" or "wrapKey" for this operation');
|
||||
};
|
||||
export const decrypt = async (alg, key, encryptedKey) => {
|
||||
if (!isCryptoKey(key)) {
|
||||
throw new TypeError(invalidKeyInput(key, ...types));
|
||||
}
|
||||
checkEncCryptoKey(key, alg, 'decrypt', 'unwrapKey');
|
||||
checkKeyLength(alg, key);
|
||||
if (key.usages.includes('decrypt')) {
|
||||
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm(alg), key, encryptedKey));
|
||||
}
|
||||
if (key.usages.includes('unwrapKey')) {
|
||||
const cryptoKeyCek = await crypto.subtle.unwrapKey('raw', encryptedKey, key, subtleAlgorithm(alg), ...bogusWebCrypto);
|
||||
return new Uint8Array(await crypto.subtle.exportKey('raw', cryptoKeyCek));
|
||||
}
|
||||
throw new TypeError('RSA-OAEP key "usages" must include "decrypt" or "unwrapKey" for this operation');
|
||||
};
|
||||
1
server/node_modules/jose/dist/browser/runtime/runtime.js
generated
vendored
Normal file
1
server/node_modules/jose/dist/browser/runtime/runtime.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default 'WebCryptoAPI';
|
||||
11
server/node_modules/jose/dist/browser/runtime/sign.js
generated
vendored
Normal file
11
server/node_modules/jose/dist/browser/runtime/sign.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import subtleAlgorithm from './subtle_dsa.js';
|
||||
import crypto from './webcrypto.js';
|
||||
import checkKeyLength from './check_key_length.js';
|
||||
import getSignKey from './get_sign_verify_key.js';
|
||||
const sign = async (alg, key, data) => {
|
||||
const cryptoKey = await getSignKey(alg, key, 'sign');
|
||||
checkKeyLength(alg, cryptoKey);
|
||||
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
||||
return new Uint8Array(signature);
|
||||
};
|
||||
export default sign;
|
||||
26
server/node_modules/jose/dist/browser/runtime/subtle_dsa.js
generated
vendored
Normal file
26
server/node_modules/jose/dist/browser/runtime/subtle_dsa.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { JOSENotSupported } from '../util/errors.js';
|
||||
export default function subtleDsa(alg, algorithm) {
|
||||
const hash = `SHA-${alg.slice(-3)}`;
|
||||
switch (alg) {
|
||||
case 'HS256':
|
||||
case 'HS384':
|
||||
case 'HS512':
|
||||
return { hash, name: 'HMAC' };
|
||||
case 'PS256':
|
||||
case 'PS384':
|
||||
case 'PS512':
|
||||
return { hash, name: 'RSA-PSS', saltLength: alg.slice(-3) >> 3 };
|
||||
case 'RS256':
|
||||
case 'RS384':
|
||||
case 'RS512':
|
||||
return { hash, name: 'RSASSA-PKCS1-v1_5' };
|
||||
case 'ES256':
|
||||
case 'ES384':
|
||||
case 'ES512':
|
||||
return { hash, name: 'ECDSA', namedCurve: algorithm.namedCurve };
|
||||
case 'EdDSA':
|
||||
return { name: algorithm.name };
|
||||
default:
|
||||
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
||||
}
|
||||
}
|
||||
12
server/node_modules/jose/dist/browser/runtime/subtle_rsaes.js
generated
vendored
Normal file
12
server/node_modules/jose/dist/browser/runtime/subtle_rsaes.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { JOSENotSupported } from '../util/errors.js';
|
||||
export default function subtleRsaEs(alg) {
|
||||
switch (alg) {
|
||||
case 'RSA-OAEP':
|
||||
case 'RSA-OAEP-256':
|
||||
case 'RSA-OAEP-384':
|
||||
case 'RSA-OAEP-512':
|
||||
return 'RSA-OAEP';
|
||||
default:
|
||||
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
||||
}
|
||||
}
|
||||
19
server/node_modules/jose/dist/browser/runtime/timing_safe_equal.js
generated
vendored
Normal file
19
server/node_modules/jose/dist/browser/runtime/timing_safe_equal.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
const timingSafeEqual = (a, b) => {
|
||||
if (!(a instanceof Uint8Array)) {
|
||||
throw new TypeError('First argument must be a buffer');
|
||||
}
|
||||
if (!(b instanceof Uint8Array)) {
|
||||
throw new TypeError('Second argument must be a buffer');
|
||||
}
|
||||
if (a.length !== b.length) {
|
||||
throw new TypeError('Input buffers must have the same length');
|
||||
}
|
||||
const len = a.length;
|
||||
let out = 0;
|
||||
let i = -1;
|
||||
while (++i < len) {
|
||||
out |= a[i] ^ b[i];
|
||||
}
|
||||
return out === 0;
|
||||
};
|
||||
export default timingSafeEqual;
|
||||
16
server/node_modules/jose/dist/browser/runtime/verify.js
generated
vendored
Normal file
16
server/node_modules/jose/dist/browser/runtime/verify.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import subtleAlgorithm from './subtle_dsa.js';
|
||||
import crypto from './webcrypto.js';
|
||||
import checkKeyLength from './check_key_length.js';
|
||||
import getVerifyKey from './get_sign_verify_key.js';
|
||||
const verify = async (alg, key, signature, data) => {
|
||||
const cryptoKey = await getVerifyKey(alg, key, 'verify');
|
||||
checkKeyLength(alg, cryptoKey);
|
||||
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
||||
try {
|
||||
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
||||
}
|
||||
catch (_a) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
export default verify;
|
||||
2
server/node_modules/jose/dist/browser/runtime/webcrypto.js
generated
vendored
Normal file
2
server/node_modules/jose/dist/browser/runtime/webcrypto.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export default crypto;
|
||||
export const isCryptoKey = (key) => key instanceof CryptoKey;
|
||||
7
server/node_modules/jose/dist/browser/runtime/zlib.js
generated
vendored
Normal file
7
server/node_modules/jose/dist/browser/runtime/zlib.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { JOSENotSupported } from '../util/errors.js';
|
||||
export const inflate = async () => {
|
||||
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported by your javascript runtime. You need to use the `inflateRaw` decrypt option to provide Inflate Raw implementation.');
|
||||
};
|
||||
export const deflate = async () => {
|
||||
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported by your javascript runtime. You need to use the `deflateRaw` encrypt option to provide Deflate Raw implementation.');
|
||||
};
|
||||
Reference in New Issue
Block a user