Skip to content

fix: hash payload before signing/verifying with Aws KMS #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025

Conversation

jcmelati
Copy link
Contributor

No description provided.

@@ -110,10 +111,14 @@ actual class AwsKmsCryptoProvider actual constructor(
?: throw IllegalArgumentException("Key does not have a signature algorithm set")
}

// Create a digest of the input data
val hashedInput = MessageDigest.getInstance(algorithm.digestAlgorithm?.name).digest(input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is correct? In other words does AWS expect the hashed inputs? Is that a param?
Let's say I am using Scep256r1/ES256 as signature alg, then normally the signing part itself would perform the hashing internally, as Secp256r1/ES256 is EcDSA with SHA256

Copy link
Contributor Author

@jcmelati jcmelati May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should have been opened as a draft.

As per AWS docs Use the Message parameter to specify the message or message digest to sign. You can submit messages of up to 4096 bytes. To sign a larger message, generate a hash digest of the message, and then provide the hash digest in the Message parameter. To indicate whether the message is a full message or a digest, use the MessageType parameter.

I need to test it further before making it a PR. For the last part of the question, I will need to understand better those scenarios and create tests that cover them.

@jcmelati jcmelati marked this pull request as draft May 2, 2025 09:26
@jcmelati jcmelati marked this pull request as ready for review May 2, 2025 14:51
@jcmelati jcmelati merged commit 2c7981e into develop May 2, 2025
1 check passed
@jcmelati jcmelati deleted the aws_kms_payload_digest branch May 2, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants