@@ -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 """
@@ -89,11 +90,7 @@ def __init__(self, headers, secret, required_headers=None, method=None,
8990 self .method = method
9091 self .path = path
9192 self .host = host
92-
93- if 'algorithm' in self .auth_dict and self .auth_dict ['algorithm' ] != self .algorithm :
94- raise HttpSigException (
95- "Algorithm mismath, signature parameter algorithm was: {}, but algorithm dervice from key is: {}" .format (
96- self .auth_dict ['algorithm' ], self .algorithm ))
93+ self .derived_algorithm = algorithm
9794
9895 if self .auth_dict ['algorithm' ] != DEFAULT_ALGORITHM :
9996 print ("Algorithm: {} is deprecated please update to {}" .format (self .auth_dict ['algorithm' ], DEFAULT_ALGORITHM ))
@@ -112,6 +109,11 @@ def verify(self):
112109 not found in the signature.
113110 Returns True or False.
114111 """
112+ if 'algorithm' in self .auth_dict and self .derived_algorithm is not None and self .auth_dict ['algorithm' ] != self .derived_algorithm :
113+ print ("Algorithm mismatch, signature parameter algorithm was: {}, but algorithm derived from key is: {}" .format (
114+ self .auth_dict ['algorithm' ], self .derived_algorithm ))
115+ return False
116+
115117 auth_headers = self .auth_dict .get ('headers' , 'date' ).split (' ' )
116118
117119 if len (set (self .required_headers ) - set (auth_headers )) > 0 :
0 commit comments