@@ -38,7 +38,6 @@ __export(src_exports, {
3838 SignatureHeaderClockInvalidError : ( ) => SignatureHeaderClockInvalidError ,
3939 SignatureHeaderContentLackedError : ( ) => SignatureHeaderContentLackedError ,
4040 SignatureHeaderNotFoundError : ( ) => SignatureHeaderNotFoundError ,
41- SignatureMissmatchWithProvidedAlgorithmError : ( ) => SignatureMissmatchWithProvidedAlgorithmError ,
4241 checkClockSkew : ( ) => checkClockSkew ,
4342 detectAndVerifyAlgorithm : ( ) => detectAndVerifyAlgorithm ,
4443 digestHeaderRegEx : ( ) => digestHeaderRegEx ,
@@ -578,18 +577,18 @@ function verifyDigestHeader(request, rawBody, failOnNoDigest = true, errorLogger
578577}
579578
580579// 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 ) {
587584 algorithm = algorithm ?. toLowerCase ( ) ;
588585 const realKeyType = publicKey . asymmetricKeyType ;
589586 if ( algorithm && algorithm !== "hs2019" && realKeyType ) {
590587 const providedKeyAlgorithm = algorithm . split ( "-" ) [ 0 ] ;
591588 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 ;
593592 }
594593 }
595594 if ( algorithm === "ed25519" || algorithm === "ed25519-sha512" || realKeyType === "ed25519" ) {
@@ -622,7 +621,9 @@ function detectAndVerifyAlgorithm(algorithm, publicKey) {
622621 hashAlg : algoSplitted . length === 1 ? null : algoSplitted [ algoSplitted . length - 1 ]
623622 } ;
624623 }
625- throw new Error ( "Algorithm not found" ) ;
624+ if ( errorLogger )
625+ errorLogger ( "Algorithm is not detected" ) ;
626+ return null ;
626627}
627628
628629// src/draft/verify.ts
@@ -631,6 +632,8 @@ function verifyDraftSignature(parsed, publicKeyPem, errorLogger) {
631632 const publicKey = crypto4 . createPublicKey ( publicKeyPem ) ;
632633 try {
633634 const detected = detectAndVerifyAlgorithm ( parsed . params . algorithm , publicKey ) ;
635+ if ( ! detected )
636+ return false ;
634637 return crypto4 . verify ( detected . hashAlg , Buffer . from ( parsed . signingString ) , publicKey , Buffer . from ( parsed . params . signature , "base64" ) ) ;
635638 } catch ( e ) {
636639 if ( errorLogger )
@@ -648,7 +651,6 @@ function verifyDraftSignature(parsed, publicKeyPem, errorLogger) {
648651 SignatureHeaderClockInvalidError,
649652 SignatureHeaderContentLackedError,
650653 SignatureHeaderNotFoundError,
651- SignatureMissmatchWithProvidedAlgorithmError,
652654 checkClockSkew,
653655 detectAndVerifyAlgorithm,
654656 digestHeaderRegEx,
0 commit comments