Skip to content

Commit

Permalink
Consistent signature validation for short signatures (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin committed Oct 13, 2023
1 parent 49e2e25 commit a916a84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/windows/bcrypt_rsa.c
Expand Up @@ -232,6 +232,13 @@ static int s_rsa_verify(
struct aws_byte_cursor signature) {
struct bcrypt_rsa_key_pair *key_pair_impl = key_pair->impl;

/* BCrypt raises invalid argument if signature does not have correct size.
* Verify size here and raise appropriate error and treat all other errors
* from BCrypt (including invalid arg) in reinterp. */
if (signature.len != aws_rsa_key_pair_signature_length(key_pair)) {
return aws_raise_error(AWS_ERROR_CAL_SIGNATURE_VALIDATION_FAILED);
}

union sign_padding_info padding_info;
if (s_sign_padding_info_init(&padding_info, algorithm)) {
return aws_raise_error(AWS_ERROR_CAL_UNSUPPORTED_ALGORITHM);
Expand Down
6 changes: 6 additions & 0 deletions tests/rsa_test.c
Expand Up @@ -729,6 +729,12 @@ static int s_rsa_signing_mismatch_pkcs1_sha256(struct aws_allocator *allocator,
aws_rsa_key_pair_verify_signature(
key_pair_private, AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256, hash_cur, signature_cur));

struct aws_byte_cursor short_signature_cur = aws_byte_cursor_from_c_str("bad signature");
ASSERT_ERROR(
AWS_ERROR_CAL_SIGNATURE_VALIDATION_FAILED,
aws_rsa_key_pair_verify_signature(
key_pair_private, AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256, hash_cur, short_signature_cur));

aws_byte_buf_clean_up(&hash_value);
aws_byte_buf_clean_up(&signature_buf);
aws_byte_buf_clean_up(&public_key_buf);
Expand Down

0 comments on commit a916a84

Please sign in to comment.