Skip to content

CDRIVER-5872 update kms-message to commit 34a9572 #1838

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 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .evergreen/scripts/kms-divergence-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LIBMONGOCRYPT_DIR="$MONGOC_DIR/libmongocrypt-for-kms-divergence-check"

# LIBMONGOCRYPT_GITREF is expected to refer to the version of libmongocrypt
# where kms-message was last copied.
LIBMONGOCRYPT_GITREF="ea8af831bf067cc7eed7417ff4aef3c14cf1e67a"
LIBMONGOCRYPT_GITREF="34a9572c416e0827a1fa988baf88411c4b5f2c7b"

cleanup() {
if [ -d "$LIBMONGOCRYPT_DIR" ]; then
Expand Down
4 changes: 2 additions & 2 deletions src/kms-message/src/kms_crypto_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ kms_sign_rsaes_pkcs1_v1_5 (void *unused_ctx,

success = CryptDecodeObjectEx (X509_ASN_ENCODING,
PKCS_PRIVATE_KEY_INFO,
private_key,
(BYTE*) private_key,
(DWORD) private_key_len,
0,
NULL,
Expand All @@ -182,7 +182,7 @@ kms_sign_rsaes_pkcs1_v1_5 (void *unused_ctx,

success = CryptDecodeObjectEx (X509_ASN_ENCODING,
PKCS_PRIVATE_KEY_INFO,
private_key,
(BYTE*) private_key,
(DWORD) private_key_len,
0,
NULL,
Expand Down
6 changes: 3 additions & 3 deletions src/kms-message/src/kms_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ kms_request_get_signed (kms_request_t *request)
}

if (!check_and_prohibit_kmip (request)) {
return false;
return NULL;
}

if (!finalize (request)) {
Expand Down Expand Up @@ -857,11 +857,11 @@ kms_request_to_string (kms_request_t *request)
size_t i;

if (!finalize (request)) {
return false;
return NULL;
}

if (!check_and_prohibit_kmip (request)) {
return false;
return NULL;
}

if (request->to_string) {
Expand Down
10 changes: 5 additions & 5 deletions src/kms-message/test/test_kmip_reader_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ kms_kmip_writer_test_evaluate (kmip_writer_t *writer,
actual_hex = data_to_hex (actual_buf, actual_len);

if (0 != strcmp (expected_hex, actual_hex)) {
fprintf (stderr,
"expected '%s' but got '%s' for test description: %s\n",
expected_hex,
actual_hex,
desc);
TEST_STDERR_PRINTF (
"expected '%s' but got '%s' for test description: %s\n",
expected_hex,
actual_hex,
desc);
abort ();
}

Expand Down
33 changes: 25 additions & 8 deletions src/kms-message/test/test_kms_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,31 @@
#include <stdio.h>
#include <string.h>

#define TEST_ERROR(...) \
do { \
fprintf ( \
stderr, "test error %s:%d %s(): ", __FILE__, __LINE__, __FUNCTION__); \
fprintf (stderr, __VA_ARGS__); \
fprintf (stderr, "\n"); \
fflush (stderr); \
abort (); \
// TEST_PRINTF ensures stdout and stderr are flushed.
#define TEST_PRINTF(...) \
if (1) { \
fflush (stderr); \
fprintf (stdout, __VA_ARGS__); \
fflush (stdout); \
} else \
((void) 0)

// TEST_STDERR_PRINTF ensures stdout and stderr are flushed.
#define TEST_STDERR_PRINTF(...) \
if (1) { \
fflush (stdout); \
fprintf (stderr, __VA_ARGS__); \
fflush (stderr); \
} else \
((void) 0)

#define TEST_ERROR(...) \
do { \
TEST_STDERR_PRINTF ( \
"test error %s:%d %s(): ", __FILE__, __LINE__, __FUNCTION__); \
TEST_STDERR_PRINTF (__VA_ARGS__); \
TEST_STDERR_PRINTF ("\n"); \
abort (); \
} while (0)

#define ASSERT(stmt) \
Expand Down
4 changes: 2 additions & 2 deletions src/kms-message/test/test_kms_azure_online.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ test_getenv (const char *key)
{
char *value = getenv (key);
if (!value) {
fprintf (
stderr, "Environment variable: %s not set (@@ctest-skip@@)", key);
TEST_STDERR_PRINTF ("Environment variable: %s not set (@@ctest-skip@@)\n",
key);
exit (2);
}
TEST_TRACE ("Env: %s = %s", key, value);
Expand Down
6 changes: 3 additions & 3 deletions src/kms-message/test/test_kms_gcp_online.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ test_getenv (const char *key)
{
char *value = getenv (key);
if (!value) {
fprintf (
stderr, "Environment variable: %s not set (@@ctest-skip@@)", key);
TEST_STDERR_PRINTF ("Environment variable: %s not set (@@ctest-skip@@)\n",
key);
exit (2);
}
TEST_TRACE ("Env: %s = %s", key, value);
Expand Down Expand Up @@ -185,7 +185,7 @@ test_gcp (void)
opt);
ASSERT (req);
if (kms_request_get_error (req)) {
printf ("error: %s\n", kms_request_get_error (req));
TEST_STDERR_PRINTF ("error: %s\n", kms_request_get_error (req));
ASSERT (false);
}
req_str = kms_request_to_string (req);
Expand Down
20 changes: 10 additions & 10 deletions src/kms-message/test/test_kms_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ all_aws_sig_v4_tests (const char *path, const char *selected)
}

if (skip_aws_test (test_name) && !selected) {
printf ("SKIP: %s\n", test_name);
TEST_PRINTF ("SKIP: %s\n", test_name);
goto done;
}

Expand All @@ -407,7 +407,7 @@ all_aws_sig_v4_tests (const char *path, const char *selected)
continue;
}

printf ("%s\n", path);
TEST_PRINTF ("%s\n", path);
aws_sig_v4_test (path);
ran_tests = true;
}
Expand Down Expand Up @@ -903,7 +903,7 @@ parser_testcase_run (parser_testcase_t *testcase)
size_t ret = fread (buf, 1, (size_t) bytes_to_read, response_file);

if (!kms_response_parser_feed (parser, buf, (int) ret)) {
printf ("feed error: %s\n", parser->error);
TEST_PRINTF ("feed error: %s\n", parser->error);
ASSERT (false);
}
}
Expand Down Expand Up @@ -945,7 +945,7 @@ kms_response_parser_files (void)
size_t i;

for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {
printf (" parser testcase: %d\n", (int) i);
TEST_PRINTF (" parser testcase: %d\n", (int) i);
parser_testcase_run (tests + i);
}
}
Expand Down Expand Up @@ -1081,8 +1081,8 @@ kms_signature_test (void)
signature_b64 = kms_message_raw_to_b64 (signature_raw, 256);

if (0 != strcmp (signature_b64, expected_signature)) {
printf ("generated signature: %s\n", signature_b64);
printf ("but expected signature: %s\n", expected_signature);
TEST_PRINTF ("generated signature: %s\n", signature_b64);
TEST_PRINTF ("but expected signature: %s\n", expected_signature);
abort ();
}

Expand Down Expand Up @@ -1197,7 +1197,7 @@ test_request_newlines (void)
#define RUN_TEST(_func) \
do { \
if (!selector || 0 == kms_strcasecmp (#_func, selector)) { \
printf ("%s\n", #_func); \
TEST_PRINTF ("%s\n", #_func); \
_func (); \
ran_tests = true; \
} \
Expand Down Expand Up @@ -1232,15 +1232,15 @@ main (int argc, char *argv[])
help = "Usage: test_kms_request [TEST_NAME]";

if (argc > 2) {
fprintf (stderr, "%s\n", help);
TEST_STDERR_PRINTF ("%s\n", help);
abort ();
} else if (argc == 2) {
selector = argv[1];
}

int ret = kms_message_init ();
if (ret != 0) {
printf ("kms_message_init failed: 0x%x\n", ret);
TEST_PRINTF ("kms_message_init failed: 0x%x\n", ret);
abort ();
}

Expand Down Expand Up @@ -1292,7 +1292,7 @@ main (int argc, char *argv[])

if (!ran_tests) {
KMS_ASSERT (argc == 2);
fprintf (stderr, "No such test: \"%s\"\n", argv[1]);
TEST_STDERR_PRINTF ("No such test: \"%s\"\n", argv[1]);
abort ();
}

Expand Down