Socket
Socket
Sign inDemoInstall

jose

Package Overview
Dependencies
Maintainers
1
Versions
210
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jose - npm Package Compare versions

Comparing version 4.12.0 to 4.12.1

90

dist/browser/key/import.js

@@ -1,76 +0,6 @@

import { decode as decodeBase64URL, encodeBase64, decodeBase64 } from '../runtime/base64url.js';
import { fromSPKI as importPublic } from '../runtime/asn1.js';
import { fromPKCS8 as importPrivate } from '../runtime/asn1.js';
import { decode as decodeBase64URL } from '../runtime/base64url.js';
import { fromSPKI, fromPKCS8, fromX509 } from '../runtime/asn1.js';
import asKeyObject from '../runtime/jwk_to_key.js';
import { JOSENotSupported } from '../util/errors.js';
import formatPEM from '../lib/format_pem.js';
import isObject from '../lib/is_object.js';
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 async function importSPKI(spki, alg, options) {

@@ -80,3 +10,3 @@ if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {

}
return importPublic(spki, alg, options);
return fromSPKI(spki, alg, options);
}

@@ -87,10 +17,3 @@ export async function importX509(x509, alg, options) {

}
let spki;
try {
spki = getSPKI(x509);
}
catch (cause) {
throw new TypeError('failed to parse the X.509 certificate', { cause });
}
return importPublic(spki, alg, options);
return fromX509(x509, alg, options);
}

@@ -101,3 +24,3 @@ export async function importPKCS8(pkcs8, alg, options) {

}
return importPrivate(pkcs8, alg, options);
return fromPKCS8(pkcs8, alg, options);
}

@@ -110,5 +33,2 @@ export async function importJWK(jwk, alg, octAsKeyObject) {

alg || (alg = jwk.alg);
if (typeof alg !== 'string' || !alg) {
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
}
switch (jwk.kty) {

@@ -115,0 +35,0 @@ case 'oct':

80

dist/browser/runtime/asn1.js
import { isCloudflareWorkers } from './env.js';
import crypto, { isCryptoKey } from './webcrypto.js';
import invalidKeyInput from '../lib/invalid_key_input.js';
import { encodeBase64 } from './base64url.js';
import { encodeBase64, decodeBase64 } from './base64url.js';
import formatPEM from '../lib/format_pem.js';

@@ -137,1 +137,79 @@ import { JOSENotSupported } from '../util/errors.js';

};
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);
};

@@ -127,2 +127,5 @@ import { isCloudflareWorkers } from './env.js';

var _a, _b;
if (!jwk.alg) {
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
}
const { algorithm, keyUsages } = subtleMapping(jwk);

@@ -129,0 +132,0 @@ const rest = [

@@ -6,75 +6,5 @@ "use strict";

const asn1_js_1 = require("../runtime/asn1.js");
const asn1_js_2 = require("../runtime/asn1.js");
const jwk_to_key_js_1 = require("../runtime/jwk_to_key.js");
const errors_js_1 = require("../util/errors.js");
const format_pem_js_1 = require("../lib/format_pem.js");
const is_object_js_1 = require("../lib/is_object.js");
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 (0, base64url_js_1.encodeBase64)(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
}
function getSPKI(x509) {
const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, '');
const raw = (0, base64url_js_1.decodeBase64)(pem);
return (0, format_pem_js_1.default)(spkiFromX509(raw), 'PUBLIC KEY');
}
async function importSPKI(spki, alg, options) {

@@ -91,10 +21,3 @@ if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {

}
let spki;
try {
spki = getSPKI(x509);
}
catch (cause) {
throw new TypeError('failed to parse the X.509 certificate', { cause });
}
return (0, asn1_js_1.fromSPKI)(spki, alg, options);
return (0, asn1_js_1.fromX509)(x509, alg, options);
}

@@ -106,3 +29,3 @@ exports.importX509 = importX509;

}
return (0, asn1_js_2.fromPKCS8)(pkcs8, alg, options);
return (0, asn1_js_1.fromPKCS8)(pkcs8, alg, options);
}

@@ -116,5 +39,2 @@ exports.importPKCS8 = importPKCS8;

alg || (alg = jwk.alg);
if (typeof alg !== 'string' || !alg) {
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
}
switch (jwk.kty) {

@@ -121,0 +41,0 @@ case 'oct':

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromSPKI = exports.fromPKCS8 = exports.toPKCS8 = exports.toSPKI = void 0;
exports.fromX509 = exports.fromSPKI = exports.fromPKCS8 = exports.toPKCS8 = exports.toSPKI = void 0;
const crypto_1 = require("crypto");

@@ -49,1 +49,7 @@ const buffer_1 = require("buffer");

exports.fromSPKI = fromSPKI;
const fromX509 = (pem) => (0, crypto_1.createPublicKey)({
key: pem,
type: 'spki',
format: 'pem',
});
exports.fromX509 = fromX509;

@@ -1,76 +0,6 @@

import { decode as decodeBase64URL, encodeBase64, decodeBase64 } from '../runtime/base64url.js';
import { fromSPKI as importPublic } from '../runtime/asn1.js';
import { fromPKCS8 as importPrivate } from '../runtime/asn1.js';
import { decode as decodeBase64URL } from '../runtime/base64url.js';
import { fromSPKI, fromPKCS8, fromX509 } from '../runtime/asn1.js';
import asKeyObject from '../runtime/jwk_to_key.js';
import { JOSENotSupported } from '../util/errors.js';
import formatPEM from '../lib/format_pem.js';
import isObject from '../lib/is_object.js';
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 async function importSPKI(spki, alg, options) {

@@ -80,3 +10,3 @@ if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {

}
return importPublic(spki, alg, options);
return fromSPKI(spki, alg, options);
}

@@ -87,10 +17,3 @@ export async function importX509(x509, alg, options) {

}
let spki;
try {
spki = getSPKI(x509);
}
catch (cause) {
throw new TypeError('failed to parse the X.509 certificate', { cause });
}
return importPublic(spki, alg, options);
return fromX509(x509, alg, options);
}

@@ -101,3 +24,3 @@ export async function importPKCS8(pkcs8, alg, options) {

}
return importPrivate(pkcs8, alg, options);
return fromPKCS8(pkcs8, alg, options);
}

@@ -110,5 +33,2 @@ export async function importJWK(jwk, alg, octAsKeyObject) {

alg || (alg = jwk.alg);
if (typeof alg !== 'string' || !alg) {
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
}
switch (jwk.kty) {

@@ -115,0 +35,0 @@ case 'oct':

@@ -42,1 +42,6 @@ import { createPrivateKey, createPublicKey, KeyObject } from 'crypto';

});
export const fromX509 = (pem) => createPublicKey({
key: pem,
type: 'spki',
format: 'pem',
});

@@ -20,3 +20,3 @@ import type { KeyLike } from '../types';

/**
* (Web Cryptography API specific) The value to use as
* (Only effective in Web Crypto API runtimes) The value to use as
* [SubtleCrypto.generateKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey)

@@ -31,3 +31,3 @@ * `extractable` argument. Default is false.

*
* Note: Under Web Cryptography API runtime the `privateKey` is generated with `extractable` set to
* Note: Under Web Crypto API runtime the `privateKey` is generated with `extractable` set to
* `false` by default.

@@ -34,0 +34,0 @@ *

import type { KeyLike } from '../types';
export interface GenerateSecretOptions {
/**
* (Web Cryptography API specific) The value to use as
* (Only effective in Web Crypto API runtimes) The value to use as
* [SubtleCrypto.generateKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey)

@@ -13,4 +13,4 @@ * `extractable` argument. Default is false.

*
* Note: Under Web Cryptography API runtime the secret key is generated with `extractable` set to
* `false` by default.
* Note: Under Web Crypto API runtime the secret key is generated with `extractable` set to `false`
* by default.
*

@@ -17,0 +17,0 @@ * @example Usage

import type { JWK, KeyLike } from '../types';
export interface PEMImportOptions {
/**
* (Web Cryptography API specific) The value to use as
* (Only effective in Web Crypto API runtimes) The value to use as
* [SubtleCrypto.importKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey)

@@ -27,3 +27,4 @@ * `extractable` argument. Default is false.

* @param pem PEM-encoded SPKI string
* @param alg JSON Web Algorithm identifier to be used with the imported key.
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
* with the imported key, its presence is only enforced in Web Crypto API runtimes.
*/

@@ -55,3 +56,4 @@ export declare function importSPKI(spki: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;

* @param pem X.509 certificate string
* @param alg JSON Web Algorithm identifier to be used with the imported key.
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
* with the imported key, its presence is only enforced in Web Crypto API runtimes.
*/

@@ -77,3 +79,4 @@ export declare function importX509(x509: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;

* @param pem PEM-encoded PKCS#8 string
* @param alg JSON Web Algorithm identifier to be used with the imported key.
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
* with the imported key, its presence is only enforced in Web Crypto API runtimes.
*/

@@ -113,4 +116,5 @@ export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;

* @param jwk JSON Web Key.
* @param alg JSON Web Algorithm identifier to be used with the imported key. Default is the "alg"
* property on the JWK.
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
* with the imported key. Default is the "alg" property on the JWK, its presence is only enforced
* in Web Crypto API runtimes.
* @param octAsKeyObject Forces a symmetric key to be imported to a KeyObject or CryptoKey. Default

@@ -117,0 +121,0 @@ * is true unless JWK "ext" (Extractable) is true.

@@ -39,3 +39,3 @@ /**

*
* @example Import a X.509 Certificate
* @example Import SPKI from an X.509 Certificate
*

@@ -42,0 +42,0 @@ * ```js

{
"name": "jose",
"version": "4.12.0",
"version": "4.12.1",
"description": "'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes",

@@ -5,0 +5,0 @@ "keywords": [

@@ -41,3 +41,3 @@ # jose

```js
import * as jose from 'https://deno.land/x/jose@v4.12.0/index.ts'
import * as jose from 'https://deno.land/x/jose@v4.12.1/index.ts'
```

@@ -44,0 +44,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc