Skip to content

Commit c78802f

Browse files
committed
set errors from kms
1 parent c6bd720 commit c78802f

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/libmongoc/src/mongoc/mongoc-crypt.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,14 @@ _state_need_kms (_state_machine_t *state_machine, bson_error_t *error)
590590
continue;
591591
} else {
592592
/* TLS errors are set in _get_stream */
593+
bson_error_t kms_error;
594+
BSON_ASSERT (!_kms_ctx_check_error (kms_ctx, &kms_error, true));
595+
bson_set_error (error,
596+
MONGOC_ERROR_STREAM,
597+
MONGOC_ERROR_STREAM_SOCKET,
598+
"%s. Failed to create KMS stream: %s",
599+
kms_error.message,
600+
endpoint);
593601
goto fail;
594602
}
595603
}
@@ -601,8 +609,14 @@ _state_need_kms (_state_machine_t *state_machine, bson_error_t *error)
601609
if (mongocrypt_kms_ctx_fail (kms_ctx)) {
602610
continue;
603611
} else {
604-
bson_set_error (
605-
error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_SOCKET, "Failed to write to KMS stream: %s", endpoint);
612+
bson_error_t kms_error;
613+
BSON_ASSERT (!_kms_ctx_check_error (kms_ctx, &kms_error, true));
614+
bson_set_error (error,
615+
MONGOC_ERROR_STREAM,
616+
MONGOC_ERROR_STREAM_SOCKET,
617+
"%s. Failed to write to KMS stream: %s",
618+
kms_error.message,
619+
endpoint);
606620
goto fail;
607621
}
608622
}
@@ -624,18 +638,15 @@ _state_need_kms (_state_machine_t *state_machine, bson_error_t *error)
624638
if (mongocrypt_kms_ctx_fail (kms_ctx)) {
625639
break; // Stop reading reply.
626640
} else {
627-
if (read_ret == -1) {
628-
bson_set_error (error,
629-
MONGOC_ERROR_STREAM,
630-
MONGOC_ERROR_STREAM_SOCKET,
631-
"failed to read from KMS stream: %d",
632-
errno);
633-
goto fail;
634-
} else {
635-
bson_set_error (
636-
error, MONGOC_ERROR_STREAM, MONGOC_ERROR_STREAM_SOCKET, "unexpected EOF from KMS stream");
637-
goto fail;
638-
}
641+
bson_error_t kms_error;
642+
BSON_ASSERT (!_kms_ctx_check_error (kms_ctx, &kms_error, true));
643+
bson_set_error (error,
644+
MONGOC_ERROR_STREAM,
645+
MONGOC_ERROR_STREAM_SOCKET,
646+
"%s. Failed to read from KMS stream to: %s",
647+
kms_error.message,
648+
endpoint);
649+
goto fail;
639650
}
640651
}
641652
mongocrypt_binary_destroy (http_reply);

0 commit comments

Comments
 (0)