修改后台权限
This commit is contained in:
18
node_modules/jose/dist/webapi/jws/compact/sign.js
generated
vendored
Normal file
18
node_modules/jose/dist/webapi/jws/compact/sign.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { FlattenedSign } from '../flattened/sign.js';
|
||||
export class CompactSign {
|
||||
#flattened;
|
||||
constructor(payload) {
|
||||
this.#flattened = new FlattenedSign(payload);
|
||||
}
|
||||
setProtectedHeader(protectedHeader) {
|
||||
this.#flattened.setProtectedHeader(protectedHeader);
|
||||
return this;
|
||||
}
|
||||
async sign(key, options) {
|
||||
const jws = await this.#flattened.sign(key, options);
|
||||
if (jws.payload === undefined) {
|
||||
throw new TypeError('use the flattened module for creating JWS with b64: false');
|
||||
}
|
||||
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
||||
}
|
||||
}
|
||||
21
node_modules/jose/dist/webapi/jws/compact/verify.js
generated
vendored
Normal file
21
node_modules/jose/dist/webapi/jws/compact/verify.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { flattenedVerify } from '../flattened/verify.js';
|
||||
import { JWSInvalid } from '../../util/errors.js';
|
||||
import { decoder } from '../../lib/buffer_utils.js';
|
||||
export async function compactVerify(jws, key, options) {
|
||||
if (jws instanceof Uint8Array) {
|
||||
jws = decoder.decode(jws);
|
||||
}
|
||||
if (typeof jws !== 'string') {
|
||||
throw new JWSInvalid('Compact JWS must be a string or Uint8Array');
|
||||
}
|
||||
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split('.');
|
||||
if (length !== 3) {
|
||||
throw new JWSInvalid('Invalid Compact JWS');
|
||||
}
|
||||
const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
|
||||
const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
|
||||
if (typeof key === 'function') {
|
||||
return { ...result, key: verified.key };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
89
node_modules/jose/dist/webapi/jws/flattened/sign.js
generated
vendored
Normal file
89
node_modules/jose/dist/webapi/jws/flattened/sign.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
import { encode as b64u } from '../../util/base64url.js';
|
||||
import { sign } from '../../lib/signing.js';
|
||||
import { isDisjoint } from '../../lib/type_checks.js';
|
||||
import { JWSInvalid } from '../../util/errors.js';
|
||||
import { concat, encode } from '../../lib/buffer_utils.js';
|
||||
import { checkKeyType } from '../../lib/check_key_type.js';
|
||||
import { validateCrit } from '../../lib/validate_crit.js';
|
||||
import { normalizeKey } from '../../lib/normalize_key.js';
|
||||
import { assertNotSet } from '../../lib/helpers.js';
|
||||
export class FlattenedSign {
|
||||
#payload;
|
||||
#protectedHeader;
|
||||
#unprotectedHeader;
|
||||
constructor(payload) {
|
||||
if (!(payload instanceof Uint8Array)) {
|
||||
throw new TypeError('payload must be an instance of Uint8Array');
|
||||
}
|
||||
this.#payload = payload;
|
||||
}
|
||||
setProtectedHeader(protectedHeader) {
|
||||
assertNotSet(this.#protectedHeader, 'setProtectedHeader');
|
||||
this.#protectedHeader = protectedHeader;
|
||||
return this;
|
||||
}
|
||||
setUnprotectedHeader(unprotectedHeader) {
|
||||
assertNotSet(this.#unprotectedHeader, 'setUnprotectedHeader');
|
||||
this.#unprotectedHeader = unprotectedHeader;
|
||||
return this;
|
||||
}
|
||||
async sign(key, options) {
|
||||
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
||||
throw new JWSInvalid('either setProtectedHeader or setUnprotectedHeader must be called before #sign()');
|
||||
}
|
||||
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
|
||||
throw new JWSInvalid('JWS Protected and JWS Unprotected Header Parameter names must be disjoint');
|
||||
}
|
||||
const joseHeader = {
|
||||
...this.#protectedHeader,
|
||||
...this.#unprotectedHeader,
|
||||
};
|
||||
const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options?.crit, this.#protectedHeader, joseHeader);
|
||||
let b64 = true;
|
||||
if (extensions.has('b64')) {
|
||||
b64 = this.#protectedHeader.b64;
|
||||
if (typeof b64 !== 'boolean') {
|
||||
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
||||
}
|
||||
}
|
||||
const { alg } = joseHeader;
|
||||
if (typeof alg !== 'string' || !alg) {
|
||||
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
||||
}
|
||||
checkKeyType(alg, key, 'sign');
|
||||
let payloadS;
|
||||
let payloadB;
|
||||
if (b64) {
|
||||
payloadS = b64u(this.#payload);
|
||||
payloadB = encode(payloadS);
|
||||
}
|
||||
else {
|
||||
payloadB = this.#payload;
|
||||
payloadS = '';
|
||||
}
|
||||
let protectedHeaderString;
|
||||
let protectedHeaderBytes;
|
||||
if (this.#protectedHeader) {
|
||||
protectedHeaderString = b64u(JSON.stringify(this.#protectedHeader));
|
||||
protectedHeaderBytes = encode(protectedHeaderString);
|
||||
}
|
||||
else {
|
||||
protectedHeaderString = '';
|
||||
protectedHeaderBytes = new Uint8Array();
|
||||
}
|
||||
const data = concat(protectedHeaderBytes, encode('.'), payloadB);
|
||||
const k = await normalizeKey(key, alg);
|
||||
const signature = await sign(alg, k, data);
|
||||
const jws = {
|
||||
signature: b64u(signature),
|
||||
payload: payloadS,
|
||||
};
|
||||
if (this.#unprotectedHeader) {
|
||||
jws.header = this.#unprotectedHeader;
|
||||
}
|
||||
if (this.#protectedHeader) {
|
||||
jws.protected = protectedHeaderString;
|
||||
}
|
||||
return jws;
|
||||
}
|
||||
}
|
||||
110
node_modules/jose/dist/webapi/jws/flattened/verify.js
generated
vendored
Normal file
110
node_modules/jose/dist/webapi/jws/flattened/verify.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
import { decode as b64u } from '../../util/base64url.js';
|
||||
import { verify } from '../../lib/signing.js';
|
||||
import { JOSEAlgNotAllowed, JWSInvalid, JWSSignatureVerificationFailed } from '../../util/errors.js';
|
||||
import { concat, encoder, decoder, encode } from '../../lib/buffer_utils.js';
|
||||
import { decodeBase64url } from '../../lib/helpers.js';
|
||||
import { isDisjoint } from '../../lib/type_checks.js';
|
||||
import { isObject } from '../../lib/type_checks.js';
|
||||
import { checkKeyType } from '../../lib/check_key_type.js';
|
||||
import { validateCrit } from '../../lib/validate_crit.js';
|
||||
import { validateAlgorithms } from '../../lib/validate_algorithms.js';
|
||||
import { normalizeKey } from '../../lib/normalize_key.js';
|
||||
export async function flattenedVerify(jws, key, options) {
|
||||
if (!isObject(jws)) {
|
||||
throw new JWSInvalid('Flattened JWS must be an object');
|
||||
}
|
||||
if (jws.protected === undefined && jws.header === undefined) {
|
||||
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
||||
}
|
||||
if (jws.protected !== undefined && typeof jws.protected !== 'string') {
|
||||
throw new JWSInvalid('JWS Protected Header incorrect type');
|
||||
}
|
||||
if (jws.payload === undefined) {
|
||||
throw new JWSInvalid('JWS Payload missing');
|
||||
}
|
||||
if (typeof jws.signature !== 'string') {
|
||||
throw new JWSInvalid('JWS Signature missing or incorrect type');
|
||||
}
|
||||
if (jws.header !== undefined && !isObject(jws.header)) {
|
||||
throw new JWSInvalid('JWS Unprotected Header incorrect type');
|
||||
}
|
||||
let parsedProt = {};
|
||||
if (jws.protected) {
|
||||
try {
|
||||
const protectedHeader = b64u(jws.protected);
|
||||
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
||||
}
|
||||
catch {
|
||||
throw new JWSInvalid('JWS Protected Header is invalid');
|
||||
}
|
||||
}
|
||||
if (!isDisjoint(parsedProt, jws.header)) {
|
||||
throw new JWSInvalid('JWS Protected and JWS Unprotected Header Parameter names must be disjoint');
|
||||
}
|
||||
const joseHeader = {
|
||||
...parsedProt,
|
||||
...jws.header,
|
||||
};
|
||||
const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options?.crit, parsedProt, joseHeader);
|
||||
let b64 = true;
|
||||
if (extensions.has('b64')) {
|
||||
b64 = parsedProt.b64;
|
||||
if (typeof b64 !== 'boolean') {
|
||||
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
||||
}
|
||||
}
|
||||
const { alg } = joseHeader;
|
||||
if (typeof alg !== 'string' || !alg) {
|
||||
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
||||
}
|
||||
const algorithms = options && validateAlgorithms('algorithms', options.algorithms);
|
||||
if (algorithms && !algorithms.has(alg)) {
|
||||
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
||||
}
|
||||
if (b64) {
|
||||
if (typeof jws.payload !== 'string') {
|
||||
throw new JWSInvalid('JWS Payload must be a string');
|
||||
}
|
||||
}
|
||||
else if (typeof jws.payload !== 'string' && !(jws.payload instanceof Uint8Array)) {
|
||||
throw new JWSInvalid('JWS Payload must be a string or an Uint8Array instance');
|
||||
}
|
||||
let resolvedKey = false;
|
||||
if (typeof key === 'function') {
|
||||
key = await key(parsedProt, jws);
|
||||
resolvedKey = true;
|
||||
}
|
||||
checkKeyType(alg, key, 'verify');
|
||||
const data = concat(jws.protected !== undefined ? encode(jws.protected) : new Uint8Array(), encode('.'), typeof jws.payload === 'string'
|
||||
? b64
|
||||
? encode(jws.payload)
|
||||
: encoder.encode(jws.payload)
|
||||
: jws.payload);
|
||||
const signature = decodeBase64url(jws.signature, 'signature', JWSInvalid);
|
||||
const k = await normalizeKey(key, alg);
|
||||
const verified = await verify(alg, k, signature, data);
|
||||
if (!verified) {
|
||||
throw new JWSSignatureVerificationFailed();
|
||||
}
|
||||
let payload;
|
||||
if (b64) {
|
||||
payload = decodeBase64url(jws.payload, 'payload', JWSInvalid);
|
||||
}
|
||||
else if (typeof jws.payload === 'string') {
|
||||
payload = encoder.encode(jws.payload);
|
||||
}
|
||||
else {
|
||||
payload = jws.payload;
|
||||
}
|
||||
const result = { payload };
|
||||
if (jws.protected !== undefined) {
|
||||
result.protectedHeader = parsedProt;
|
||||
}
|
||||
if (jws.header !== undefined) {
|
||||
result.unprotectedHeader = jws.header;
|
||||
}
|
||||
if (resolvedKey) {
|
||||
return { ...result, key: k };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
70
node_modules/jose/dist/webapi/jws/general/sign.js
generated
vendored
Normal file
70
node_modules/jose/dist/webapi/jws/general/sign.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import { FlattenedSign } from '../flattened/sign.js';
|
||||
import { JWSInvalid } from '../../util/errors.js';
|
||||
import { assertNotSet } from '../../lib/helpers.js';
|
||||
class IndividualSignature {
|
||||
#parent;
|
||||
protectedHeader;
|
||||
unprotectedHeader;
|
||||
options;
|
||||
key;
|
||||
constructor(sig, key, options) {
|
||||
this.#parent = sig;
|
||||
this.key = key;
|
||||
this.options = options;
|
||||
}
|
||||
setProtectedHeader(protectedHeader) {
|
||||
assertNotSet(this.protectedHeader, 'setProtectedHeader');
|
||||
this.protectedHeader = protectedHeader;
|
||||
return this;
|
||||
}
|
||||
setUnprotectedHeader(unprotectedHeader) {
|
||||
assertNotSet(this.unprotectedHeader, 'setUnprotectedHeader');
|
||||
this.unprotectedHeader = unprotectedHeader;
|
||||
return this;
|
||||
}
|
||||
addSignature(...args) {
|
||||
return this.#parent.addSignature(...args);
|
||||
}
|
||||
sign(...args) {
|
||||
return this.#parent.sign(...args);
|
||||
}
|
||||
done() {
|
||||
return this.#parent;
|
||||
}
|
||||
}
|
||||
export class GeneralSign {
|
||||
#payload;
|
||||
#signatures = [];
|
||||
constructor(payload) {
|
||||
this.#payload = payload;
|
||||
}
|
||||
addSignature(key, options) {
|
||||
const signature = new IndividualSignature(this, key, options);
|
||||
this.#signatures.push(signature);
|
||||
return signature;
|
||||
}
|
||||
async sign() {
|
||||
if (!this.#signatures.length) {
|
||||
throw new JWSInvalid('at least one signature must be added');
|
||||
}
|
||||
const jws = {
|
||||
signatures: [],
|
||||
payload: '',
|
||||
};
|
||||
for (let i = 0; i < this.#signatures.length; i++) {
|
||||
const signature = this.#signatures[i];
|
||||
const flattened = new FlattenedSign(this.#payload);
|
||||
flattened.setProtectedHeader(signature.protectedHeader);
|
||||
flattened.setUnprotectedHeader(signature.unprotectedHeader);
|
||||
const { payload, ...rest } = await flattened.sign(signature.key, signature.options);
|
||||
if (i === 0) {
|
||||
jws.payload = payload;
|
||||
}
|
||||
else if (jws.payload !== payload) {
|
||||
throw new JWSInvalid('inconsistent use of JWS Unencoded Payload (RFC7797)');
|
||||
}
|
||||
jws.signatures.push(rest);
|
||||
}
|
||||
return jws;
|
||||
}
|
||||
}
|
||||
24
node_modules/jose/dist/webapi/jws/general/verify.js
generated
vendored
Normal file
24
node_modules/jose/dist/webapi/jws/general/verify.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { flattenedVerify } from '../flattened/verify.js';
|
||||
import { JWSInvalid, JWSSignatureVerificationFailed } from '../../util/errors.js';
|
||||
import { isObject } from '../../lib/type_checks.js';
|
||||
export async function generalVerify(jws, key, options) {
|
||||
if (!isObject(jws)) {
|
||||
throw new JWSInvalid('General JWS must be an object');
|
||||
}
|
||||
if (!Array.isArray(jws.signatures) || !jws.signatures.every(isObject)) {
|
||||
throw new JWSInvalid('JWS Signatures missing or incorrect type');
|
||||
}
|
||||
for (const signature of jws.signatures) {
|
||||
try {
|
||||
return await flattenedVerify({
|
||||
header: signature.header,
|
||||
payload: jws.payload,
|
||||
protected: signature.protected,
|
||||
signature: signature.signature,
|
||||
}, key, options);
|
||||
}
|
||||
catch {
|
||||
}
|
||||
}
|
||||
throw new JWSSignatureVerificationFailed();
|
||||
}
|
||||
Reference in New Issue
Block a user