修改后台权限
This commit is contained in:
23
node_modules/jose/dist/webapi/jwt/decrypt.js
generated
vendored
Normal file
23
node_modules/jose/dist/webapi/jwt/decrypt.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { compactDecrypt } from '../jwe/compact/decrypt.js';
|
||||
import { validateClaimsSet } from '../lib/jwt_claims_set.js';
|
||||
import { JWTClaimValidationFailed } from '../util/errors.js';
|
||||
export async function jwtDecrypt(jwt, key, options) {
|
||||
const decrypted = await compactDecrypt(jwt, key, options);
|
||||
const payload = validateClaimsSet(decrypted.protectedHeader, decrypted.plaintext, options);
|
||||
const { protectedHeader } = decrypted;
|
||||
if (protectedHeader.iss !== undefined && protectedHeader.iss !== payload.iss) {
|
||||
throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, 'iss', 'mismatch');
|
||||
}
|
||||
if (protectedHeader.sub !== undefined && protectedHeader.sub !== payload.sub) {
|
||||
throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, 'sub', 'mismatch');
|
||||
}
|
||||
if (protectedHeader.aud !== undefined &&
|
||||
JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
|
||||
throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, 'aud', 'mismatch');
|
||||
}
|
||||
const result = { payload, protectedHeader };
|
||||
if (typeof key === 'function') {
|
||||
return { ...result, key: decrypted.key };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
101
node_modules/jose/dist/webapi/jwt/encrypt.js
generated
vendored
Normal file
101
node_modules/jose/dist/webapi/jwt/encrypt.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
import { CompactEncrypt } from '../jwe/compact/encrypt.js';
|
||||
import { JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
|
||||
import { assertNotSet } from '../lib/helpers.js';
|
||||
export class EncryptJWT {
|
||||
#cek;
|
||||
#iv;
|
||||
#keyManagementParameters;
|
||||
#protectedHeader;
|
||||
#replicateIssuerAsHeader;
|
||||
#replicateSubjectAsHeader;
|
||||
#replicateAudienceAsHeader;
|
||||
#jwt;
|
||||
constructor(payload = {}) {
|
||||
this.#jwt = new JWTClaimsBuilder(payload);
|
||||
}
|
||||
setIssuer(issuer) {
|
||||
this.#jwt.iss = issuer;
|
||||
return this;
|
||||
}
|
||||
setSubject(subject) {
|
||||
this.#jwt.sub = subject;
|
||||
return this;
|
||||
}
|
||||
setAudience(audience) {
|
||||
this.#jwt.aud = audience;
|
||||
return this;
|
||||
}
|
||||
setJti(jwtId) {
|
||||
this.#jwt.jti = jwtId;
|
||||
return this;
|
||||
}
|
||||
setNotBefore(input) {
|
||||
this.#jwt.nbf = input;
|
||||
return this;
|
||||
}
|
||||
setExpirationTime(input) {
|
||||
this.#jwt.exp = input;
|
||||
return this;
|
||||
}
|
||||
setIssuedAt(input) {
|
||||
this.#jwt.iat = input;
|
||||
return this;
|
||||
}
|
||||
setProtectedHeader(protectedHeader) {
|
||||
assertNotSet(this.#protectedHeader, 'setProtectedHeader');
|
||||
this.#protectedHeader = protectedHeader;
|
||||
return this;
|
||||
}
|
||||
setKeyManagementParameters(parameters) {
|
||||
assertNotSet(this.#keyManagementParameters, 'setKeyManagementParameters');
|
||||
this.#keyManagementParameters = parameters;
|
||||
return this;
|
||||
}
|
||||
setContentEncryptionKey(cek) {
|
||||
assertNotSet(this.#cek, 'setContentEncryptionKey');
|
||||
this.#cek = cek;
|
||||
return this;
|
||||
}
|
||||
setInitializationVector(iv) {
|
||||
assertNotSet(this.#iv, 'setInitializationVector');
|
||||
this.#iv = iv;
|
||||
return this;
|
||||
}
|
||||
replicateIssuerAsHeader() {
|
||||
this.#replicateIssuerAsHeader = true;
|
||||
return this;
|
||||
}
|
||||
replicateSubjectAsHeader() {
|
||||
this.#replicateSubjectAsHeader = true;
|
||||
return this;
|
||||
}
|
||||
replicateAudienceAsHeader() {
|
||||
this.#replicateAudienceAsHeader = true;
|
||||
return this;
|
||||
}
|
||||
async encrypt(key, options) {
|
||||
const enc = new CompactEncrypt(this.#jwt.data());
|
||||
if (this.#protectedHeader &&
|
||||
(this.#replicateIssuerAsHeader ||
|
||||
this.#replicateSubjectAsHeader ||
|
||||
this.#replicateAudienceAsHeader)) {
|
||||
this.#protectedHeader = {
|
||||
...this.#protectedHeader,
|
||||
iss: this.#replicateIssuerAsHeader ? this.#jwt.iss : undefined,
|
||||
sub: this.#replicateSubjectAsHeader ? this.#jwt.sub : undefined,
|
||||
aud: this.#replicateAudienceAsHeader ? this.#jwt.aud : undefined,
|
||||
};
|
||||
}
|
||||
enc.setProtectedHeader(this.#protectedHeader);
|
||||
if (this.#iv) {
|
||||
enc.setInitializationVector(this.#iv);
|
||||
}
|
||||
if (this.#cek) {
|
||||
enc.setContentEncryptionKey(this.#cek);
|
||||
}
|
||||
if (this.#keyManagementParameters) {
|
||||
enc.setKeyManagementParameters(this.#keyManagementParameters);
|
||||
}
|
||||
return enc.encrypt(key, options);
|
||||
}
|
||||
}
|
||||
52
node_modules/jose/dist/webapi/jwt/sign.js
generated
vendored
Normal file
52
node_modules/jose/dist/webapi/jwt/sign.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { CompactSign } from '../jws/compact/sign.js';
|
||||
import { JWTInvalid } from '../util/errors.js';
|
||||
import { JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
|
||||
export class SignJWT {
|
||||
#protectedHeader;
|
||||
#jwt;
|
||||
constructor(payload = {}) {
|
||||
this.#jwt = new JWTClaimsBuilder(payload);
|
||||
}
|
||||
setIssuer(issuer) {
|
||||
this.#jwt.iss = issuer;
|
||||
return this;
|
||||
}
|
||||
setSubject(subject) {
|
||||
this.#jwt.sub = subject;
|
||||
return this;
|
||||
}
|
||||
setAudience(audience) {
|
||||
this.#jwt.aud = audience;
|
||||
return this;
|
||||
}
|
||||
setJti(jwtId) {
|
||||
this.#jwt.jti = jwtId;
|
||||
return this;
|
||||
}
|
||||
setNotBefore(input) {
|
||||
this.#jwt.nbf = input;
|
||||
return this;
|
||||
}
|
||||
setExpirationTime(input) {
|
||||
this.#jwt.exp = input;
|
||||
return this;
|
||||
}
|
||||
setIssuedAt(input) {
|
||||
this.#jwt.iat = input;
|
||||
return this;
|
||||
}
|
||||
setProtectedHeader(protectedHeader) {
|
||||
this.#protectedHeader = protectedHeader;
|
||||
return this;
|
||||
}
|
||||
async sign(key, options) {
|
||||
const sig = new CompactSign(this.#jwt.data());
|
||||
sig.setProtectedHeader(this.#protectedHeader);
|
||||
if (Array.isArray(this.#protectedHeader?.crit) &&
|
||||
this.#protectedHeader.crit.includes('b64') &&
|
||||
this.#protectedHeader.b64 === false) {
|
||||
throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
|
||||
}
|
||||
return sig.sign(key, options);
|
||||
}
|
||||
}
|
||||
63
node_modules/jose/dist/webapi/jwt/unsecured.js
generated
vendored
Normal file
63
node_modules/jose/dist/webapi/jwt/unsecured.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import * as b64u from '../util/base64url.js';
|
||||
import { decoder } from '../lib/buffer_utils.js';
|
||||
import { JWTInvalid } from '../util/errors.js';
|
||||
import { validateClaimsSet, JWTClaimsBuilder } from '../lib/jwt_claims_set.js';
|
||||
export class UnsecuredJWT {
|
||||
#jwt;
|
||||
constructor(payload = {}) {
|
||||
this.#jwt = new JWTClaimsBuilder(payload);
|
||||
}
|
||||
encode() {
|
||||
const header = b64u.encode(JSON.stringify({ alg: 'none' }));
|
||||
const payload = b64u.encode(this.#jwt.data());
|
||||
return `${header}.${payload}.`;
|
||||
}
|
||||
setIssuer(issuer) {
|
||||
this.#jwt.iss = issuer;
|
||||
return this;
|
||||
}
|
||||
setSubject(subject) {
|
||||
this.#jwt.sub = subject;
|
||||
return this;
|
||||
}
|
||||
setAudience(audience) {
|
||||
this.#jwt.aud = audience;
|
||||
return this;
|
||||
}
|
||||
setJti(jwtId) {
|
||||
this.#jwt.jti = jwtId;
|
||||
return this;
|
||||
}
|
||||
setNotBefore(input) {
|
||||
this.#jwt.nbf = input;
|
||||
return this;
|
||||
}
|
||||
setExpirationTime(input) {
|
||||
this.#jwt.exp = input;
|
||||
return this;
|
||||
}
|
||||
setIssuedAt(input) {
|
||||
this.#jwt.iat = input;
|
||||
return this;
|
||||
}
|
||||
static decode(jwt, options) {
|
||||
if (typeof jwt !== 'string') {
|
||||
throw new JWTInvalid('Unsecured JWT must be a string');
|
||||
}
|
||||
const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split('.');
|
||||
if (length !== 3 || signature !== '') {
|
||||
throw new JWTInvalid('Invalid Unsecured JWT');
|
||||
}
|
||||
let header;
|
||||
try {
|
||||
header = JSON.parse(decoder.decode(b64u.decode(encodedHeader)));
|
||||
if (header.alg !== 'none')
|
||||
throw new Error();
|
||||
}
|
||||
catch {
|
||||
throw new JWTInvalid('Invalid Unsecured JWT');
|
||||
}
|
||||
const payload = validateClaimsSet(header, b64u.decode(encodedPayload), options);
|
||||
return { payload, header };
|
||||
}
|
||||
}
|
||||
15
node_modules/jose/dist/webapi/jwt/verify.js
generated
vendored
Normal file
15
node_modules/jose/dist/webapi/jwt/verify.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { compactVerify } from '../jws/compact/verify.js';
|
||||
import { validateClaimsSet } from '../lib/jwt_claims_set.js';
|
||||
import { JWTInvalid } from '../util/errors.js';
|
||||
export async function jwtVerify(jwt, key, options) {
|
||||
const verified = await compactVerify(jwt, key, options);
|
||||
if (verified.protectedHeader.crit?.includes('b64') && verified.protectedHeader.b64 === false) {
|
||||
throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
|
||||
}
|
||||
const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
|
||||
const result = { payload, protectedHeader: verified.protectedHeader };
|
||||
if (typeof key === 'function') {
|
||||
return { ...result, key: verified.key };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user