1010
1111
1212DEFAULT_SIGN_ALGORITHM = "hs2019"
13+ DEFAULT_SALT_LENGTH = 20
1314
1415
1516class Signer (object ):
@@ -19,9 +20,11 @@ class Signer(object):
1920
2021 Password-protected keyfiles are not supported.
2122 """
22- def __init__ (self , secret , algorithm = None , sign_algorithm = None ):
23+ def __init__ (self , secret , algorithm = None , sign_algorithm = None , salt_length = None ):
2324 if algorithm is None :
2425 algorithm = DEFAULT_SIGN_ALGORITHM
26+ if salt_length is None :
27+ salt_length = DEFAULT_SALT_LENGTH
2528
2629 assert algorithm in ALGORITHMS , "Unknown algorithm"
2730 assert sign_algorithm is None or sign_algorithm in SIGN_ALGORITHMS , "Unsupported digital signature algorithm"
@@ -58,7 +61,7 @@ def __init__(self, secret, algorithm=None, sign_algorithm=None):
5861 elif self .sign_algorithm == "PSS" :
5962 try :
6063 rsa_key = RSA .importKey (secret )
61- self ._rsa = PKCS1_PSS .new (rsa_key )
64+ self ._rsa = PKCS1_PSS .new (rsa_key , saltLen = salt_length )
6265 self ._hash = HASHES [self .hash_algorithm ]
6366 except ValueError :
6467 raise HttpSigException ("Invalid key." )
@@ -100,18 +103,19 @@ class HeaderSigner(Signer):
100103 to use
101104 :arg secret: a PEM-encoded RSA private key or an HMAC secret (must
102105 match the algorithm)
103- :arg algorithm: one of the seven specified algorithms
104- :arg sign_algorithm: required for 'hs2019' algorithm. Sign algorithm for the secret
105- :arg headers: a list of http headers to be included in the signing
106+ :param algorithm: one of the seven specified algorithms
107+ :param sign_algorithm: required for 'hs2019' algorithm. Sign algorithm for the secret
108+ :param sign_algorithm: Custom salt length for 'hs2019' and 'PSS' sign algorithm.
109+ :param headers: a list of http headers to be included in the signing
106110 string, defaulting to ['date'].
107- :arg sign_header: header used to include signature, defaulting to
111+ :param sign_header: header used to include signature, defaulting to
108112 'authorization'.
109113 """
110- def __init__ (self , key_id , secret , algorithm = None , sign_algorithm = None , headers = None , sign_header = 'authorization' ):
114+ def __init__ (self , key_id , secret , algorithm = None , sign_algorithm = None , salt_length = None , headers = None , sign_header = 'authorization' ):
111115 if algorithm is None :
112116 algorithm = DEFAULT_SIGN_ALGORITHM
113117
114- super (HeaderSigner , self ).__init__ (secret = secret , algorithm = algorithm , sign_algorithm = sign_algorithm )
118+ super (HeaderSigner , self ).__init__ (secret = secret , algorithm = algorithm , sign_algorithm = sign_algorithm , salt_length = salt_length )
115119 self .headers = headers or ['date' ]
116120 self .signature_template = build_signature_template (
117121 key_id , algorithm , headers , sign_header )
0 commit comments