22
33from __future__ import annotations
44
5+ import hashlib
56import logging
67from urllib import parse
78
@@ -32,6 +33,8 @@ class AWSSigner(Signer):
3233 AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN. These will
3334 be recognized by the boto3 SDK, which underlies the aws_kms Python module.
3435
36+ The signer computes hash digests locally and sends only the digest to AWS KMS.
37+
3538 For more details on AWS authentication, refer to the AWS Command Line
3639 Interface User Guide:
3740 https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html
@@ -187,8 +190,8 @@ def import_(
187190 def sign (self , payload : bytes ) -> Signature :
188191 """Sign the payload with the AWS KMS key
189192
190- This method sends the payload to AWS KMS, where it is signed using the specified
191- key and algorithm using the raw message type .
193+ This method computes the hash of the payload locally and sends only the
194+ digest to AWS KMS for signing .
192195
193196 Arguments:
194197 payload (bytes): The payload to be signed.
@@ -200,10 +203,15 @@ def sign(self, payload: bytes) -> Signature:
200203 Signature: A signature object containing the key ID and the signature.
201204 """
202205 try :
206+ hash_algorithm = self .public_key .get_hash_algorithm_name ()
207+ hasher = hashlib .new (hash_algorithm )
208+ hasher .update (payload )
209+ digest = hasher .digest ()
210+
203211 sign_request = self .client .sign (
204212 KeyId = self .aws_key_id ,
205- Message = payload ,
206- MessageType = "RAW " ,
213+ Message = digest ,
214+ MessageType = "DIGEST " ,
207215 SigningAlgorithm = self .aws_algo ,
208216 )
209217
0 commit comments