jose-node-esm-runtime
Advanced tools
Comparing version 4.3.7 to 4.3.8
@@ -6,3 +6,3 @@ import fetchJwks from '../runtime/fetch_jwks.js'; | ||
function getKtyFromAlg(alg) { | ||
switch (typeof alg === 'string' && alg.substr(0, 2)) { | ||
switch (typeof alg === 'string' && alg.slice(0, 2)) { | ||
case 'RS': | ||
@@ -9,0 +9,0 @@ case 'PS': |
@@ -6,3 +6,3 @@ import encrypt from '../runtime/encrypt.js'; | ||
export async function wrap(alg, key, cek, iv) { | ||
const jweAlgorithm = alg.substr(0, 7); | ||
const jweAlgorithm = alg.slice(0, 7); | ||
iv || (iv = generateIv(jweAlgorithm)); | ||
@@ -13,4 +13,4 @@ const { ciphertext: encryptedKey, tag } = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array(0)); | ||
export async function unwrap(alg, key, encryptedKey, iv, tag) { | ||
const jweAlgorithm = alg.substr(0, 7); | ||
const jweAlgorithm = alg.slice(0, 7); | ||
return decrypt(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array(0)); | ||
} |
@@ -9,3 +9,3 @@ import { isCloudflareWorkers, isNodeJs } from '../runtime/env.js'; | ||
function getHashLength(hash) { | ||
return parseInt(hash.name.substr(4), 10); | ||
return parseInt(hash.name.slice(4), 10); | ||
} | ||
@@ -47,3 +47,3 @@ function getNamedCurve(alg) { | ||
throw unusable('HMAC'); | ||
const expected = parseInt(alg.substr(2), 10); | ||
const expected = parseInt(alg.slice(2), 10); | ||
const actual = getHashLength(key.algorithm.hash); | ||
@@ -59,3 +59,3 @@ if (actual !== expected) | ||
throw unusable('RSASSA-PKCS1-v1_5'); | ||
const expected = parseInt(alg.substr(2), 10); | ||
const expected = parseInt(alg.slice(2), 10); | ||
const actual = getHashLength(key.algorithm.hash); | ||
@@ -71,3 +71,3 @@ if (actual !== expected) | ||
throw unusable('RSA-PSS'); | ||
const expected = parseInt(alg.substr(2), 10); | ||
const expected = parseInt(alg.slice(2), 10); | ||
const actual = getHashLength(key.algorithm.hash); | ||
@@ -111,3 +111,3 @@ if (actual !== expected) | ||
throw unusable('AES-GCM'); | ||
const expected = parseInt(alg.substr(1, 3), 10); | ||
const expected = parseInt(alg.slice(1, 4), 10); | ||
const actual = key.algorithm.length; | ||
@@ -123,3 +123,3 @@ if (actual !== expected) | ||
throw unusable('AES-KW'); | ||
const expected = parseInt(alg.substr(1, 3), 10); | ||
const expected = parseInt(alg.slice(1, 4), 10); | ||
const actual = key.algorithm.length; | ||
@@ -146,3 +146,3 @@ if (actual !== expected) | ||
throw unusable('RSA-OAEP'); | ||
const expected = parseInt(alg.substr(9), 10) || 1; | ||
const expected = parseInt(alg.slice(9), 10) || 1; | ||
const actual = getHashLength(key.algorithm.hash); | ||
@@ -149,0 +149,0 @@ if (actual !== expected) |
@@ -43,3 +43,3 @@ import { unwrap as aesKw } from '../runtime/aeskw.js'; | ||
} | ||
const sharedSecret = await ECDH.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, alg === 'ECDH-ES' ? cekLength(joseHeader.enc) : parseInt(alg.substr(-5, 3), 10), partyUInfo, partyVInfo); | ||
const sharedSecret = await ECDH.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, alg === 'ECDH-ES' ? cekLength(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo); | ||
if (alg === 'ECDH-ES') | ||
@@ -49,3 +49,3 @@ return sharedSecret; | ||
throw new JWEInvalid('JWE Encrypted Key missing'); | ||
return aesKw(alg.substr(-6), sharedSecret, encryptedKey); | ||
return aesKw(alg.slice(-6), sharedSecret, encryptedKey); | ||
} | ||
@@ -52,0 +52,0 @@ case 'RSA1_5': |
@@ -30,5 +30,5 @@ import { wrap as aesKw } from '../runtime/aeskw.js'; | ||
let { epk: ephemeralKey } = providedParameters; | ||
ephemeralKey || (ephemeralKey = await ECDH.generateEpk(key)); | ||
ephemeralKey || (ephemeralKey = (await ECDH.generateEpk(key)).privateKey); | ||
const { x, y, crv, kty } = await exportJWK(ephemeralKey); | ||
const sharedSecret = await ECDH.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, alg === 'ECDH-ES' ? cekLength(enc) : parseInt(alg.substr(-5, 3), 10), apu, apv); | ||
const sharedSecret = await ECDH.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, alg === 'ECDH-ES' ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv); | ||
parameters = { epk: { x, y, crv, kty } }; | ||
@@ -44,3 +44,3 @@ if (apu) | ||
cek = providedCek || generateCek(enc); | ||
const kwAlg = alg.substr(-6); | ||
const kwAlg = alg.slice(-6); | ||
encryptedKey = await aesKw(kwAlg, sharedSecret, cek); | ||
@@ -47,0 +47,0 @@ break; |
@@ -12,3 +12,3 @@ import { Buffer } from 'buffer'; | ||
function checkKeySize(key, alg) { | ||
if (key.symmetricKeySize << 3 !== parseInt(alg.substr(1, 3), 10)) { | ||
if (key.symmetricKeySize << 3 !== parseInt(alg.slice(1, 4), 10)) { | ||
throw new TypeError(`Invalid key size for alg: ${alg}`); | ||
@@ -31,3 +31,3 @@ } | ||
export const wrap = (alg, key, cek) => { | ||
const size = parseInt(alg.substr(1, 3), 10); | ||
const size = parseInt(alg.slice(1, 4), 10); | ||
const algorithm = `aes${size}-wrap`; | ||
@@ -43,3 +43,3 @@ if (!supported(algorithm)) { | ||
export const unwrap = (alg, key, encryptedKey) => { | ||
const size = parseInt(alg.substr(1, 3), 10); | ||
const size = parseInt(alg.slice(1, 4), 10); | ||
const algorithm = `aes${size}-wrap`; | ||
@@ -46,0 +46,0 @@ if (!supported(algorithm)) { |
@@ -9,3 +9,3 @@ import { JWEInvalid, JOSENotSupported } from '../util/errors.js'; | ||
case 'A256CBC-HS512': | ||
expected = parseInt(enc.substr(-3), 10); | ||
expected = parseInt(enc.slice(-3), 10); | ||
break; | ||
@@ -15,3 +15,3 @@ case 'A128GCM': | ||
case 'A256GCM': | ||
expected = parseInt(enc.substr(1, 3), 10); | ||
expected = parseInt(enc.slice(1, 4), 10); | ||
break; | ||
@@ -18,0 +18,0 @@ default: |
@@ -15,3 +15,3 @@ import { createDecipheriv, KeyObject } from 'crypto'; | ||
function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) { | ||
const keySize = parseInt(enc.substr(1, 3), 10); | ||
const keySize = parseInt(enc.slice(1, 4), 10); | ||
if (isKeyObject(cek)) { | ||
@@ -22,3 +22,3 @@ cek = cek.export(); | ||
const macKey = cek.subarray(0, keySize >> 3); | ||
const macSize = parseInt(enc.substr(-3), 10); | ||
const macSize = parseInt(enc.slice(-3), 10); | ||
const algorithm = `aes-${keySize}-cbc`; | ||
@@ -51,3 +51,3 @@ if (!supported(algorithm)) { | ||
function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) { | ||
const keySize = parseInt(enc.substr(1, 3), 10); | ||
const keySize = parseInt(enc.slice(1, 4), 10); | ||
const algorithm = `aes-${keySize}-gcm`; | ||
@@ -54,0 +54,0 @@ if (!supported(algorithm)) { |
@@ -13,3 +13,3 @@ import { diffieHellman, generateKeyPair as generateKeyPairCb, KeyObject } from 'crypto'; | ||
const generateKeyPair = promisify(generateKeyPairCb); | ||
export const deriveKey = (publicKee, privateKee, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) => { | ||
export async function deriveKey(publicKee, privateKee, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) { | ||
let publicKey; | ||
@@ -40,4 +40,4 @@ if (isCryptoKey(publicKee)) { | ||
return concatKdf(digest, sharedSecret, keyLength, value); | ||
}; | ||
export const generateEpk = async (kee) => { | ||
} | ||
export async function generateEpk(kee) { | ||
let key; | ||
@@ -55,9 +55,9 @@ if (isCryptoKey(kee)) { | ||
case 'x25519': | ||
return (await generateKeyPair('x25519')).privateKey; | ||
return generateKeyPair('x25519'); | ||
case 'x448': { | ||
return (await generateKeyPair('x448')).privateKey; | ||
return generateKeyPair('x448'); | ||
} | ||
case 'ec': { | ||
const namedCurve = getNamedCurve(key); | ||
return (await generateKeyPair('ec', { namedCurve })).privateKey; | ||
return generateKeyPair('ec', { namedCurve }); | ||
} | ||
@@ -67,3 +67,3 @@ default: | ||
} | ||
}; | ||
} | ||
export const ecdhAllowed = (key) => ['P-256', 'P-384', 'P-521', 'X25519', 'X448'].includes(getNamedCurve(key)); |
@@ -14,3 +14,3 @@ import { createCipheriv, KeyObject } from 'crypto'; | ||
function cbcEncrypt(enc, plaintext, cek, iv, aad) { | ||
const keySize = parseInt(enc.substr(1, 3), 10); | ||
const keySize = parseInt(enc.slice(1, 4), 10); | ||
if (isKeyObject(cek)) { | ||
@@ -27,3 +27,3 @@ cek = cek.export(); | ||
const ciphertext = concat(cipher.update(plaintext), cipher.final()); | ||
const macSize = parseInt(enc.substr(-3), 10); | ||
const macSize = parseInt(enc.slice(-3), 10); | ||
const tag = cbcTag(aad, iv, ciphertext, macSize, macKey, keySize); | ||
@@ -33,3 +33,3 @@ return { ciphertext, tag }; | ||
function gcmEncrypt(enc, plaintext, cek, iv, aad) { | ||
const keySize = parseInt(enc.substr(1, 3), 10); | ||
const keySize = parseInt(enc.slice(1, 4), 10); | ||
const algorithm = `aes-${keySize}-gcm`; | ||
@@ -36,0 +36,0 @@ if (!supported(algorithm)) { |
@@ -16,3 +16,3 @@ import { createSecretKey, generateKeyPair as generateKeyPairCb } from 'crypto'; | ||
case 'A256CBC-HS512': | ||
length = parseInt(alg.substr(-3), 10); | ||
length = parseInt(alg.slice(-3), 10); | ||
break; | ||
@@ -28,3 +28,3 @@ case 'A128KW': | ||
case 'A256GCM': | ||
length = parseInt(alg.substring(1, 4), 10); | ||
length = parseInt(alg.slice(1, 4), 10); | ||
break; | ||
@@ -31,0 +31,0 @@ default: |
@@ -45,6 +45,6 @@ import { Buffer } from 'buffer'; | ||
case 'ed448': | ||
return `Ed${key.asymmetricKeyType.substr(2)}`; | ||
return `Ed${key.asymmetricKeyType.slice(2)}`; | ||
case 'x25519': | ||
case 'x448': | ||
return `X${key.asymmetricKeyType.substr(1)}`; | ||
return `X${key.asymmetricKeyType.slice(1)}`; | ||
case 'ec': { | ||
@@ -51,0 +51,0 @@ if (weakMap.has(key)) { |
@@ -9,3 +9,3 @@ import { Buffer } from 'buffer'; | ||
const [major, minor] = process.version | ||
.substr(1) | ||
.slice(1) | ||
.split('.') | ||
@@ -12,0 +12,0 @@ .map((str) => parseInt(str, 10)); |
@@ -11,3 +11,3 @@ import { KeyObject, createPublicKey } from 'crypto'; | ||
const [major, minor] = process.version | ||
.substr(1) | ||
.slice(1) | ||
.split('.') | ||
@@ -14,0 +14,0 @@ .map((str) => parseInt(str, 10)); |
@@ -6,3 +6,3 @@ import { constants } from 'crypto'; | ||
const [major, minor] = process.version | ||
.substr(1) | ||
.slice(1) | ||
.split('.') | ||
@@ -42,3 +42,3 @@ .map((str) => parseInt(str, 10)); | ||
const { hashAlgorithm, mgf1HashAlgorithm, saltLength } = key.asymmetricKeyDetails; | ||
const length = parseInt(alg.substr(-3), 10); | ||
const length = parseInt(alg.slice(-3), 10); | ||
if (hashAlgorithm !== undefined && | ||
@@ -45,0 +45,0 @@ (hashAlgorithm !== `sha${length}` || mgf1HashAlgorithm !== hashAlgorithm)) { |
@@ -30,6 +30,6 @@ import { promisify } from 'util'; | ||
const salt = concatSalt(alg, p2s); | ||
const keylen = parseInt(alg.substr(13, 3), 10) >> 3; | ||
const keylen = parseInt(alg.slice(13, 16), 10) >> 3; | ||
const password = getPassword(key, alg); | ||
const derivedKey = await pbkdf2(password, salt, p2c, keylen, `sha${alg.substr(8, 3)}`); | ||
const encryptedKey = await wrap(alg.substr(-6), derivedKey, cek); | ||
const derivedKey = await pbkdf2(password, salt, p2c, keylen, `sha${alg.slice(8, 11)}`); | ||
const encryptedKey = await wrap(alg.slice(-6), derivedKey, cek); | ||
return { encryptedKey, p2c, p2s: base64url(p2s) }; | ||
@@ -40,6 +40,6 @@ }; | ||
const salt = concatSalt(alg, p2s); | ||
const keylen = parseInt(alg.substr(13, 3), 10) >> 3; | ||
const keylen = parseInt(alg.slice(13, 16), 10) >> 3; | ||
const password = getPassword(key, alg); | ||
const derivedKey = await pbkdf2(password, salt, p2c, keylen, `sha${alg.substr(8, 3)}`); | ||
return unwrap(alg.substr(-6), derivedKey, encryptedKey); | ||
const derivedKey = await pbkdf2(password, salt, p2c, keylen, `sha${alg.slice(8, 11)}`); | ||
return unwrap(alg.slice(-6), derivedKey, encryptedKey); | ||
}; |
@@ -8,3 +8,3 @@ import * as crypto from 'crypto'; | ||
const [major, minor] = process.version | ||
.substr(1) | ||
.slice(1) | ||
.split('.') | ||
@@ -11,0 +11,0 @@ .map((str) => parseInt(str, 10)); |
{ | ||
"name": "jose-node-esm-runtime", | ||
"version": "4.3.7", | ||
"version": "4.3.8", | ||
"homepage": "https://github.com/panva/jose", | ||
@@ -5,0 +5,0 @@ "repository": "panva/jose", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
174990