Skip to content

Commit

Permalink
fix: Adjust signature verification for rsaEncryption algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Jul 22, 2024
1 parent ef24a16 commit a9c594b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/SignedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,12 +847,11 @@ export class SignedData extends PkiObject implements ISignedData {
}
//#endregion

const signAlg = crypto.getAlgorithmByOID(signerInfo.signatureAlgorithm.algorithmId, true);
// In some cases, the signature algorithm may not include a hash component.
// In such scenarios, we utilize the hash mechanism specified in signerInfo.digestAlgorithm.
const verifyResult = ("hash" in signAlg)
? await crypto.verifyWithPublicKey(data, signerInfo.signature, signerCert.subjectPublicKeyInfo, signerCert.signatureAlgorithm)
: await crypto.verifyWithPublicKey(data, signerInfo.signature, signerCert.subjectPublicKeyInfo, signerCert.signatureAlgorithm, shaAlgorithm);
// This adjustment is specifically for cases where the signature algorithm is rsaEncryption.
// In such cases, we rely on the hash mechanism defined in signerInfo.digestAlgorithm for verification.
const verifyResult = signerInfo.signatureAlgorithm.algorithmId === "1.2.840.113549.1.1.1"
? await crypto.verifyWithPublicKey(data, signerInfo.signature, signerCert.subjectPublicKeyInfo, signerCert.signatureAlgorithm, shaAlgorithm)
: await crypto.verifyWithPublicKey(data, signerInfo.signature, signerCert.subjectPublicKeyInfo, signerCert.signatureAlgorithm);

//#region Make a final result

Expand Down

0 comments on commit a9c594b

Please sign in to comment.