@@ -51,7 +51,7 @@ class HeaderVerifier(Verifier):
5151 """
5252
5353 def __init__ (self , headers , secret , required_headers = None , method = None ,
54- path = None , host = None , sign_header = 'authorization' , sign_algorithm = None ):
54+ path = None , host = None , sign_header = 'authorization' , algorithm = None , sign_algorithm = None ):
5555 """
5656 Instantiate a HeaderVerifier object.
5757
@@ -70,6 +70,7 @@ def __init__(self, headers, secret, required_headers=None, method=None,
7070 header, if not supplied in :param:headers.
7171 :param sign_header: Optional. The header where the signature is.
7272 Default is 'authorization'.
73+ :param algorithm: Algorithm derived from keyId (required for draft version >= 12)
7374 :param sign_algorithm: Required for 'hs2019' algorithm, specifies the
7475 digital signature algorithm (derived from keyId) to use.
7576 """
@@ -95,11 +96,7 @@ def __init__(self, headers, secret, required_headers=None, method=None,
9596 self .method = method
9697 self .path = path
9798 self .host = host
98-
99- if 'algorithm' in self .auth_dict and self .auth_dict ['algorithm' ] != self .algorithm :
100- raise HttpSigException (
101- "Algorithm mismath, signature parameter algorithm was: {}, but algorithm dervice from key is: {}" .format (
102- self .auth_dict ['algorithm' ], self .algorithm ))
99+ self .derived_algorithm = algorithm
103100
104101 if self .auth_dict ['algorithm' ] != DEFAULT_ALGORITHM :
105102 print ("Algorithm: {} is deprecated please update to {}" .format (self .auth_dict ['algorithm' ], DEFAULT_ALGORITHM ))
@@ -118,6 +115,11 @@ def verify(self):
118115 not found in the signature.
119116 Returns True or False.
120117 """
118+ if 'algorithm' in self .auth_dict and self .derived_algorithm is not None and self .auth_dict ['algorithm' ] != self .derived_algorithm :
119+ print ("Algorithm mismatch, signature parameter algorithm was: {}, but algorithm derived from key is: {}" .format (
120+ self .auth_dict ['algorithm' ], self .derived_algorithm ))
121+ return False
122+
121123 auth_headers = self .auth_dict .get ('headers' , 'date' ).split (' ' )
122124
123125 if len (set (self .required_headers ) - set (auth_headers )) > 0 :
0 commit comments