@@ -38,7 +38,6 @@ __export(src_exports, {
38
38
SignatureHeaderClockInvalidError : ( ) => SignatureHeaderClockInvalidError ,
39
39
SignatureHeaderContentLackedError : ( ) => SignatureHeaderContentLackedError ,
40
40
SignatureHeaderNotFoundError : ( ) => SignatureHeaderNotFoundError ,
41
- SignatureMissmatchWithProvidedAlgorithmError : ( ) => SignatureMissmatchWithProvidedAlgorithmError ,
42
41
checkClockSkew : ( ) => checkClockSkew ,
43
42
detectAndVerifyAlgorithm : ( ) => detectAndVerifyAlgorithm ,
44
43
digestHeaderRegEx : ( ) => digestHeaderRegEx ,
@@ -578,18 +577,18 @@ function verifyDigestHeader(request, rawBody, failOnNoDigest = true, errorLogger
578
577
}
579
578
580
579
// src/shared/verify.ts
581
- var SignatureMissmatchWithProvidedAlgorithmError = class extends Error {
582
- constructor ( providedAlgorithm , detectedAlgorithm , realKeyType ) {
583
- super ( `Provided algorithm does not match the public key type: provided=${ detectedAlgorithm } (${ providedAlgorithm } }, real=${ realKeyType } ` ) ;
584
- }
585
- } ;
586
- function detectAndVerifyAlgorithm ( algorithm , publicKey ) {
580
+ function buildErrorMessage ( providedAlgorithm , detectedAlgorithm , realKeyType ) {
581
+ return `Provided algorithm does not match the public key type: provided=${ detectedAlgorithm } (${ providedAlgorithm } }, real=${ realKeyType } ` ;
582
+ }
583
+ function detectAndVerifyAlgorithm ( algorithm , publicKey , errorLogger ) {
587
584
algorithm = algorithm ?. toLowerCase ( ) ;
588
585
const realKeyType = publicKey . asymmetricKeyType ;
589
586
if ( algorithm && algorithm !== "hs2019" && realKeyType ) {
590
587
const providedKeyAlgorithm = algorithm . split ( "-" ) [ 0 ] ;
591
588
if ( providedKeyAlgorithm !== realKeyType . toLowerCase ( ) && ! ( providedKeyAlgorithm === "ecdsa" && realKeyType === "ec" ) ) {
592
- throw new SignatureMissmatchWithProvidedAlgorithmError ( algorithm , providedKeyAlgorithm , realKeyType ) ;
589
+ if ( errorLogger )
590
+ errorLogger ( buildErrorMessage ( providedKeyAlgorithm , realKeyType , realKeyType ) ) ;
591
+ return null ;
593
592
}
594
593
}
595
594
if ( algorithm === "ed25519" || algorithm === "ed25519-sha512" || realKeyType === "ed25519" ) {
@@ -622,7 +621,9 @@ function detectAndVerifyAlgorithm(algorithm, publicKey) {
622
621
hashAlg : algoSplitted . length === 1 ? null : algoSplitted [ algoSplitted . length - 1 ]
623
622
} ;
624
623
}
625
- throw new Error ( "Algorithm not found" ) ;
624
+ if ( errorLogger )
625
+ errorLogger ( "Algorithm is not detected" ) ;
626
+ return null ;
626
627
}
627
628
628
629
// src/draft/verify.ts
@@ -631,6 +632,8 @@ function verifyDraftSignature(parsed, publicKeyPem, errorLogger) {
631
632
const publicKey = crypto4 . createPublicKey ( publicKeyPem ) ;
632
633
try {
633
634
const detected = detectAndVerifyAlgorithm ( parsed . params . algorithm , publicKey ) ;
635
+ if ( ! detected )
636
+ return false ;
634
637
return crypto4 . verify ( detected . hashAlg , Buffer . from ( parsed . signingString ) , publicKey , Buffer . from ( parsed . params . signature , "base64" ) ) ;
635
638
} catch ( e ) {
636
639
if ( errorLogger )
@@ -648,7 +651,6 @@ function verifyDraftSignature(parsed, publicKeyPem, errorLogger) {
648
651
SignatureHeaderClockInvalidError,
649
652
SignatureHeaderContentLackedError,
650
653
SignatureHeaderNotFoundError,
651
- SignatureMissmatchWithProvidedAlgorithmError,
652
654
checkClockSkew,
653
655
detectAndVerifyAlgorithm,
654
656
digestHeaderRegEx,
0 commit comments