Files
NapCatQQ/.pnpm-store/v3/files/ba/26e6c48c8ae94baadad88aa06bab7c00f14b84df2663165f3c5c3654d46cc3935d38d6ab9cbaa75270819a99df6d0bbacc012b8b5d589376f45aefd6b0443f
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

38 lines
1.5 KiB
Plaintext

import { convertX509PublicKeyToCOSE } from '../helpers/convertX509PublicKeyToCOSE.js';
import { isoBase64URL, isoUint8Array } from '../helpers/iso/index.js';
import { COSEALG, COSEKEYS, isCOSEPublicKeyEC2, isCOSEPublicKeyRSA } from '../helpers/cose.js';
import { verifyEC2 } from '../helpers/iso/isoCrypto/verifyEC2.js';
import { verifyRSA } from '../helpers/iso/isoCrypto/verifyRSA.js';
/**
* Lightweight verification for FIDO MDS JWTs. Supports use of EC2 and RSA.
*
* If this ever needs to support more JWS algorithms, here's the list of them:
*
* https://www.rfc-editor.org/rfc/rfc7518.html#section-3.1
*
* (Pulled from https://www.rfc-editor.org/rfc/rfc7515#section-4.1.1)
*/
export function verifyJWT(jwt, leafCert) {
const [header, payload, signature] = jwt.split('.');
const certCOSE = convertX509PublicKeyToCOSE(leafCert);
const data = isoUint8Array.fromUTF8String(`${header}.${payload}`);
const signatureBytes = isoBase64URL.toBuffer(signature);
if (isCOSEPublicKeyEC2(certCOSE)) {
return verifyEC2({
data,
signature: signatureBytes,
cosePublicKey: certCOSE,
shaHashOverride: COSEALG.ES256,
});
}
else if (isCOSEPublicKeyRSA(certCOSE)) {
return verifyRSA({
data,
signature: signatureBytes,
cosePublicKey: certCOSE,
});
}
const kty = certCOSE.get(COSEKEYS.kty);
throw new Error(`JWT verification with public key of kty ${kty} is not supported by this method`);
}