From 798f13ec91a6c010b54f8333653004ef511c80b9 Mon Sep 17 00:00:00 2001 From: DmitriyMusatkin Date: Wed, 30 Oct 2024 15:42:56 -0700 Subject: [PATCH] duh --- source/rsa.c | 3 +-- source/unix/openssl_rsa.c | 9 ++++++--- source/windows/bcrypt_rsa.c | 6 ++++-- tests/CMakeLists.txt | 2 +- tests/rsa_test.c | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/source/rsa.c b/source/rsa.c index 990f5e8e..c0d798bd 100644 --- a/source/rsa.c +++ b/source/rsa.c @@ -145,8 +145,7 @@ int aws_rsa_key_pair_sign_message( AWS_PRECONDITION(aws_byte_cursor_is_valid(&digest)); AWS_FATAL_ASSERT( - algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256 || - algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1 || + algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256 || algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1 || algorithm == AWS_CAL_RSA_SIGNATURE_PSS_SHA256); if (digest.len > AWS_SHA256_LEN) { diff --git a/source/unix/openssl_rsa.c b/source/unix/openssl_rsa.c index 1d492d54..97dd4795 100644 --- a/source/unix/openssl_rsa.c +++ b/source/unix/openssl_rsa.c @@ -238,10 +238,13 @@ static int s_set_signature_ctx_from_algo(EVP_PKEY_CTX *ctx, enum aws_rsa_signatu return AWS_OP_ERR; } if (algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256 && - s_reinterpret_evp_error_as_crt(EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()), "EVP_PKEY_CTX_set_signature_md")) { + s_reinterpret_evp_error_as_crt( + EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()), "EVP_PKEY_CTX_set_signature_md")) { return AWS_OP_ERR; - } else if (algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1 && - s_reinterpret_evp_error_as_crt(EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha1()), "EVP_PKEY_CTX_set_signature_md")) { + } else if ( + algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1 && + s_reinterpret_evp_error_as_crt( + EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha1()), "EVP_PKEY_CTX_set_signature_md")) { } else { AWS_LOGF_ERROR(AWS_LS_CAL_RSA, "Unsupported RSA signing algorithm: %d", algorithm); diff --git a/source/windows/bcrypt_rsa.c b/source/windows/bcrypt_rsa.c index d9301928..2a3fe885 100644 --- a/source/windows/bcrypt_rsa.c +++ b/source/windows/bcrypt_rsa.c @@ -206,7 +206,8 @@ static int s_rsa_sign( } ULONG length_written = 0; - bool is_pkcs1_padding = (algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256 || algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1); + bool is_pkcs1_padding = + (algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256 || algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1); NTSTATUS status = BCryptSignHash( key_pair_impl->key_handle, &padding_info, @@ -248,7 +249,8 @@ static int s_rsa_verify( return aws_raise_error(AWS_ERROR_CAL_UNSUPPORTED_ALGORITHM); } /* okay, now we've got a windows compatible signature, let's verify it. */ - bool is_pkcs1_padding = (algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256 || algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1); + bool is_pkcs1_padding = + (algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA256 || algorithm == AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1); NTSTATUS status = BCryptVerifySignature( key_pair_impl->key_handle, &padding_info, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 08c8320d..346e38a6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -77,7 +77,7 @@ add_test_case(rsa_encryption_roundtrip_oaep_sha256_from_user) add_test_case(rsa_encryption_roundtrip_oaep_sha512_from_user) add_test_case(rsa_signing_roundtrip_pkcs1_sha256_from_user) add_test_case(rsa_signing_roundtrip_pss_sha256_from_user) -add_test_case(rsa_signing_roundtrip_pss_sha1_from_user) +add_test_case(rsa_signing_roundtrip_pkcs1_sha1_from_user) add_test_case(rsa_getters) add_test_case(rsa_private_pkcs1_der_parsing) add_test_case(rsa_public_pkcs1_der_parsing) diff --git a/tests/rsa_test.c b/tests/rsa_test.c index bdd491f0..8c11abd0 100644 --- a/tests/rsa_test.c +++ b/tests/rsa_test.c @@ -821,8 +821,8 @@ static int s_rsa_signing_mismatch_pkcs1_sha1(struct aws_allocator *allocator, vo struct aws_byte_buf signature_buf; ASSERT_SUCCESS(aws_byte_buf_init(&signature_buf, allocator, aws_rsa_key_pair_signature_length(key_pair_private))); - ASSERT_SUCCESS(aws_rsa_key_pair_sign_message( - key_pair_private, AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1, hash_cur, &signature_buf)); + ASSERT_SUCCESS( + aws_rsa_key_pair_sign_message(key_pair_private, AWS_CAL_RSA_SIGNATURE_PKCS1_5_SHA1, hash_cur, &signature_buf)); struct aws_byte_cursor signature_cur = aws_byte_cursor_from_buf(&signature_buf); hash[5] += 59; /* modify digest to force signature mismatch */