Skip to content

Commit f8dba59

Browse files
MONGOCRYPT-791 remove trace logging
1 parent 7bf1e14 commit f8dba59

15 files changed

+6
-221
lines changed

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,6 @@ else ()
184184
message (FATAL_ERROR "Unknown crypto provider ${MONGOCRYPT_CRYPTO}")
185185
endif ()
186186

187-
set (MONGOCRYPT_ENABLE_TRACE 0)
188-
if (ENABLE_TRACE)
189-
message (WARNING "Building with trace logging. This is highly insecure. Do not use in a production environment")
190-
set (MONGOCRYPT_ENABLE_TRACE 1)
191-
endif ()
192-
193187
set (BUILD_VERSION "0.0.0" CACHE STRING "Library version")
194188
if (BUILD_VERSION STREQUAL "0.0.0")
195189
if (EXISTS ${CMAKE_BINARY_DIR}/VERSION_CURRENT)

bindings/python/pymongocrypt/binding.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ def _parse_version(version):
260260
MONGOCRYPT_LOG_LEVEL_ERROR = 1,
261261
MONGOCRYPT_LOG_LEVEL_WARNING = 2,
262262
MONGOCRYPT_LOG_LEVEL_INFO = 3,
263-
MONGOCRYPT_LOG_LEVEL_TRACE = 4
264263
} mongocrypt_log_level_t;
265264
266265
/**

integrating.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ executable included with libmongocrypt. It uses mock responses from
7272
mongod, mongocryptd, and KMS. Reimplement the state machine loop
7373
(`_run_state_machine`) in example-state-machine with your binding.
7474

75-
To debug, configure with the cmake option `-DENABLE_TRACE=ON`, and set the environment variable `MONGOCRYPT_TRACE=ON` to log the arguments to mongocrypt functions. Note, this is insecure and should only be used for debugging.
76-
7775
Seek help in the slack channel \#drivers-fle.
7876

7977
## Part 2: Integrate into Driver ##

src/mongocrypt-config.h.in

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,10 @@
7373

7474

7575
/*
76-
* MONGOCRYPT_ENABLE_TRACE is set from configure to determine if we are
77-
* compiled with tracing support.
76+
* MONGOCRYPT_ENABLE_TRACE is automatically disabled as
77+
* trace logging is no longer supported.
7878
*/
79-
#define MONGOCRYPT_ENABLE_TRACE @MONGOCRYPT_ENABLE_TRACE@
80-
81-
#if MONGOCRYPT_ENABLE_TRACE != 1
82-
# undef MONGOCRYPT_ENABLE_TRACE
83-
#endif
79+
#define MONGOCRYPT_ENABLE_TRACE 0
8480

8581
/* clang-format on */
8682

src/mongocrypt-ctx-decrypt.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -778,14 +778,6 @@ bool mongocrypt_ctx_explicit_decrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_bina
778778
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid msg");
779779
}
780780

781-
if (ctx->crypt->log.trace_enabled) {
782-
char *msg_val;
783-
msg_val = _mongocrypt_new_json_string_from_binary(msg);
784-
_mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "msg", msg_val);
785-
786-
bson_free(msg_val);
787-
}
788-
789781
/* Expect msg to be the BSON a document of the form:
790782
{ "v" : (BSON BINARY value of subtype 6) }
791783
*/
@@ -866,12 +858,6 @@ bool mongocrypt_ctx_decrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *doc
866858
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid doc");
867859
}
868860

869-
if (ctx->crypt->log.trace_enabled) {
870-
char *doc_val;
871-
doc_val = _mongocrypt_new_json_string_from_binary(doc);
872-
_mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "doc", doc_val);
873-
bson_free(doc_val);
874-
}
875861
dctx = (_mongocrypt_ctx_decrypt_t *)ctx;
876862
ctx->type = _MONGOCRYPT_TYPE_DECRYPT;
877863
ctx->vtable.finalize = _finalize;

src/mongocrypt-ctx-encrypt.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,13 +2026,6 @@ static bool explicit_encrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *ms
20262026
return _mongocrypt_ctx_fail_w_msg(ctx, "msg must be bson");
20272027
}
20282028

2029-
if (ctx->crypt->log.trace_enabled) {
2030-
char *cmd_val;
2031-
cmd_val = _mongocrypt_new_json_string_from_binary(msg);
2032-
_mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "msg", cmd_val);
2033-
bson_free(cmd_val);
2034-
}
2035-
20362029
if (!bson_iter_init_find(&iter, &as_bson, "v")) {
20372030
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid msg, must contain 'v'");
20382031
}
@@ -2577,22 +2570,6 @@ bool mongocrypt_ctx_encrypt_init(mongocrypt_ctx_t *ctx, const char *db, int32_t
25772570
return _mongocrypt_ctx_fail_w_msg(ctx, "algorithm must not be set for auto encryption");
25782571
}
25792572

2580-
if (ctx->crypt->log.trace_enabled) {
2581-
char *cmd_val;
2582-
cmd_val = _mongocrypt_new_json_string_from_binary(cmd);
2583-
_mongocrypt_log(&ctx->crypt->log,
2584-
MONGOCRYPT_LOG_LEVEL_TRACE,
2585-
"%s (%s=\"%s\", %s=%d, %s=\"%s\")",
2586-
BSON_FUNC,
2587-
"db",
2588-
ectx->cmd_db,
2589-
"db_len",
2590-
db_len,
2591-
"cmd",
2592-
cmd_val);
2593-
bson_free(cmd_val);
2594-
}
2595-
25962573
// Check if an isMaster request to mongocryptd is needed to detect feature support:
25972574
if (needs_ismaster_check(ctx)) {
25982575
ectx->ismaster.needed = true;

src/mongocrypt-ctx.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,6 @@ bool mongocrypt_ctx_setopt_key_id(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *ke
7777
return false;
7878
}
7979

80-
if (ctx->crypt->log.trace_enabled && key_id && key_id->data) {
81-
char *key_id_val;
82-
/* this should never happen, so assert rather than return false */
83-
BSON_ASSERT(key_id->len <= INT_MAX);
84-
key_id_val = _mongocrypt_new_string_from_bytes(key_id->data, (int)key_id->len);
85-
_mongocrypt_log(&ctx->crypt->log,
86-
MONGOCRYPT_LOG_LEVEL_TRACE,
87-
"%s (%s=\"%s\")",
88-
BSON_FUNC,
89-
"key_id",
90-
key_id_val);
91-
bson_free(key_id_val);
92-
}
93-
9480
return _set_binary_opt(ctx, key_id, &ctx->opts.key_id, BSON_SUBTYPE_UUID);
9581
}
9682

@@ -241,15 +227,6 @@ bool mongocrypt_ctx_setopt_algorithm(mongocrypt_ctx_t *ctx, const char *algorith
241227
}
242228

243229
const size_t calculated_len = len == -1 ? strlen(algorithm) : (size_t)len;
244-
if (ctx->crypt->log.trace_enabled) {
245-
_mongocrypt_log(&ctx->crypt->log,
246-
MONGOCRYPT_LOG_LEVEL_TRACE,
247-
"%s (%s=\"%.*s\")",
248-
BSON_FUNC,
249-
"algorithm",
250-
calculated_len <= (size_t)INT_MAX ? (int)calculated_len : INT_MAX,
251-
algorithm);
252-
}
253230

254231
mstr_view algo_str = mstrv_view_data(algorithm, calculated_len);
255232
if (mstr_eq_ignore_case(algo_str, mstrv_lit(MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR))) {
@@ -443,14 +420,6 @@ bool mongocrypt_ctx_mongo_feed(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *in) {
443420
return _mongocrypt_ctx_fail_w_msg(ctx, "invalid NULL input");
444421
}
445422

446-
if (ctx->crypt->log.trace_enabled) {
447-
char *in_val;
448-
449-
in_val = _mongocrypt_new_json_string_from_binary(in);
450-
_mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "in", in_val);
451-
bson_free(in_val);
452-
}
453-
454423
switch (ctx->state) {
455424
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
456425
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO: CHECK_AND_CALL(mongo_feed_collinfo, ctx, in);
@@ -729,21 +698,6 @@ bool mongocrypt_ctx_setopt_masterkey_aws(mongocrypt_ctx_t *ctx,
729698
mongocrypt_binary_destroy(bin);
730699
bson_destroy(&as_bson);
731700

732-
if (ctx->crypt->log.trace_enabled) {
733-
_mongocrypt_log(&ctx->crypt->log,
734-
MONGOCRYPT_LOG_LEVEL_TRACE,
735-
"%s (%s=\"%s\", %s=%d, %s=\"%s\", %s=%d)",
736-
BSON_FUNC,
737-
"region",
738-
ctx->opts.kek.provider.aws.region,
739-
"region_len",
740-
region_len,
741-
"cmk",
742-
ctx->opts.kek.provider.aws.cmk,
743-
"cmk_len",
744-
cmk_len);
745-
}
746-
747701
return ret;
748702
}
749703

@@ -1012,12 +966,6 @@ bool mongocrypt_ctx_setopt_key_encryption_key(mongocrypt_ctx_t *ctx, mongocrypt_
1012966
return _mongocrypt_ctx_fail(ctx);
1013967
}
1014968

1015-
if (ctx->crypt->log.trace_enabled) {
1016-
char *bin_str = bson_as_canonical_extended_json(&as_bson, NULL);
1017-
_mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "bin", bin_str);
1018-
bson_free(bin_str);
1019-
}
1020-
1021969
return true;
1022970
}
1023971

src/mongocrypt-kms-ctx.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,16 +1194,6 @@ bool mongocrypt_kms_ctx_feed(mongocrypt_kms_ctx_t *kms, mongocrypt_binary_t *byt
11941194
return false;
11951195
}
11961196

1197-
if (kms->log && kms->log->trace_enabled) {
1198-
_mongocrypt_log(kms->log,
1199-
MONGOCRYPT_LOG_LEVEL_TRACE,
1200-
"%s (%s=\"%.*s\")",
1201-
BSON_FUNC,
1202-
"bytes",
1203-
mongocrypt_binary_len(bytes),
1204-
mongocrypt_binary_data(bytes));
1205-
}
1206-
12071197
if (!kms_response_parser_feed(kms->parser, bytes->data, bytes->len)) {
12081198
if (is_kms(kms->req_type)) {
12091199
/* The KMIP response parser does not suport kms_response_parser_status.

src/mongocrypt-log-private.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ typedef struct {
2424
mongocrypt_mutex_t mutex; /* protects fn and ctx. */
2525
mongocrypt_log_fn_t fn;
2626
void *ctx;
27-
bool trace_enabled;
2827
} _mongocrypt_log_t;
2928

3029
void _mongocrypt_stdout_log_fn(mongocrypt_log_level_t level, const char *message, uint32_t message_len, void *ctx);
@@ -38,42 +37,11 @@ void _mongocrypt_log_cleanup(_mongocrypt_log_t *log);
3837

3938
void _mongocrypt_log_set_fn(_mongocrypt_log_t *log, mongocrypt_log_fn_t fn, void *ctx);
4039

41-
#ifdef MONGOCRYPT_ENABLE_TRACE
42-
43-
#define CRYPT_TRACEF(log, fmt, ...) \
44-
_mongocrypt_log(log, MONGOCRYPT_LOG_LEVEL_TRACE, "(%s:%d) " fmt, BSON_FUNC, __LINE__, __VA_ARGS__)
45-
46-
#define CRYPT_TRACE(log, msg) CRYPT_TRACEF(crypt, "%s", msg)
47-
48-
#define CRYPT_ENTRY(log) _mongocrypt_log(crypt, MONGOCRYPT_LOG_LEVEL_TRACE, "entry (%s:%d)", BSON_FUNC, __LINE__)
49-
50-
#define CRYPT_EXIT(log) \
51-
do { \
52-
_mongocrypt_log(crypt, MONGOCRYPT_LOG_LEVEL_TRACE, "exit (%s:%d)", BSON_FUNC, __LINE__); \
53-
return; \
54-
} while (0)
55-
56-
#define CRYPT_RETURN(log, x) \
57-
do { \
58-
_mongocrypt_log(log, MONGOCRYPT_LOG_LEVEL_TRACE, "return (%s:%d)", BSON_FUNC, __LINE__); \
59-
return (x); \
60-
} while (0)
61-
62-
#define CRYPT_GOTO(log, x) \
63-
do { \
64-
_mongocrypt_log(log, MONGOCRYPT_LOG_LEVEL_TRACE, "goto (%s:%d)", BSON_FUNC, __LINE__); \
65-
goto x; \
66-
} while (0)
67-
68-
#else
69-
7040
#define CRYPT_TRACEF(log, fmt, ...)
7141
#define CRYPT_TRACE(log, msg)
7242
#define CRYPT_ENTRY(log)
7343
#define CRYPT_EXIT(log)
7444
#define CRYPT_RETURN(log, x) return (x);
7545
#define CRYPT_GOTO(log, x) goto x;
7646

77-
#endif /* MONGOCRYPT_ENABLE_TRACE */
78-
7947
#endif /* MONGOCRYPT_LOG_PRIVATE_H */

src/mongocrypt-log.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ void _mongocrypt_log_init(_mongocrypt_log_t *log) {
2626
_mongocrypt_mutex_init(&log->mutex);
2727
/* Initially, no log function is set. */
2828
_mongocrypt_log_set_fn(log, NULL, NULL);
29-
#ifdef MONGOCRYPT_ENABLE_TRACE
30-
log->trace_enabled = (getenv("MONGOCRYPT_TRACE") != NULL);
31-
#endif
3229
}
3330

3431
void _mongocrypt_log_cleanup(_mongocrypt_log_t *log) {
@@ -47,7 +44,7 @@ void _mongocrypt_stdout_log_fn(mongocrypt_log_level_t level, const char *message
4744
case MONGOCRYPT_LOG_LEVEL_ERROR: printf("ERROR"); break;
4845
case MONGOCRYPT_LOG_LEVEL_WARNING: printf("WARNING"); break;
4946
case MONGOCRYPT_LOG_LEVEL_INFO: printf("INFO"); break;
50-
case MONGOCRYPT_LOG_LEVEL_TRACE: printf("TRACE"); break;
47+
case MONGOCRYPT_LOG_LEVEL_TRACE: printf("TRACE"); break; /* UNUSED */
5148
default: printf("UNKNOWN"); break;
5249
}
5350
printf(" %s\n", message);
@@ -69,10 +66,6 @@ void _mongocrypt_log(_mongocrypt_log_t *log, mongocrypt_log_level_t level, const
6966
BSON_ASSERT_PARAM(log);
7067
BSON_ASSERT_PARAM(format);
7168

72-
if (level == MONGOCRYPT_LOG_LEVEL_TRACE && !log->trace_enabled) {
73-
return;
74-
}
75-
7669
va_start(args, format);
7770
message = bson_strdupv_printf(format, args);
7871
va_end(args);

0 commit comments

Comments
 (0)