Skip to content

Commit f683509

Browse files
authored
Merge pull request #1026 from ArkadiuszNitkaSWI/fix-aws-signer
Fix AWS KMS Signer 4KB Message Size Limit
2 parents 9752719 + 6394e3e commit f683509

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ tests/htmlcov/*
1616
.DS_Store
1717
.python-version
1818

19+
# PyCharm IDE
20+
.idea/
21+
1922
# Sphinx documentation
2023
docs/_build/

securesystemslib/signer/_aws_signer.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import hashlib
56
import logging
67
from 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

Comments
 (0)