[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log

In this CL we are migrating from gRPCs own gpr logging mechanism to absl logging mechanism. The intention is to deprecate gpr_log in the future.
We have the following mapping
1. gpr_log(GPR_INFO,...) -> LOG(INFO)
2. gpr_log(GPR_ERROR,...) -> LOG(ERROR)
3. gpr_log(GPR_DEBUG,...) -> VLOG(2)
Reviewers need to check :
1. If the above mapping is correct.
2. The content of the log is as before.
gpr_log format strings did not use string_view or std::string . absl LOG accepts these. So there will be some elimination of string_view and std::string related conversions. This is expected.

PiperOrigin-RevId: 634264627
pull/36617/head
Tanvi Jagtap 6 months ago committed by Copybara-Service
parent ed5893120e
commit f088d2aa0b
  1. 25
      src/core/tsi/alts/frame_protector/alts_frame_protector.cc
  2. 52
      src/core/tsi/alts/handshaker/alts_handshaker_client.cc
  3. 3
      src/core/tsi/alts/handshaker/alts_tsi_utils.cc
  4. 3
      src/core/tsi/alts/handshaker/transport_security_common_api.cc
  5. 9
      src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc
  6. 8
      src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc
  7. 7
      src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc
  8. 21
      src/core/tsi/fake_transport_security.cc
  9. 11
      src/core/tsi/local_transport_security.cc
  10. 8
      src/core/tsi/ssl/session_cache/ssl_session_cache.cc
  11. 37
      src/core/tsi/ssl_transport_security.cc
  12. 35
      src/core/tsi/ssl_transport_security_utils.cc
  13. 3
      src/core/xds/grpc/xds_client_grpc.cc

@ -24,10 +24,10 @@
#include <algorithm>
#include <memory>
#include "absl/log/log.h"
#include "absl/types/span.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/memory.h"
@ -70,7 +70,7 @@ static tsi_result seal(alts_frame_protector* impl) {
&output_size, &error_details);
impl->in_place_protect_bytes_buffered = output_size;
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "%s", error_details);
LOG(ERROR) << error_details;
gpr_free(error_details);
return TSI_INTERNAL_ERROR;
}
@ -88,7 +88,7 @@ static tsi_result alts_protect_flush(tsi_frame_protector* self,
if (self == nullptr || protected_output_frames == nullptr ||
protected_output_frames_size == nullptr ||
still_pending_size == nullptr) {
gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_protect_flush().");
LOG(ERROR) << "Invalid nullptr arguments to alts_protect_flush().";
return TSI_INVALID_ARGUMENT;
}
alts_frame_protector* impl = reinterpret_cast<alts_frame_protector*>(self);
@ -113,7 +113,7 @@ static tsi_result alts_protect_flush(tsi_frame_protector* self,
}
if (!alts_reset_frame_writer(impl->writer, impl->in_place_protect_buffer,
impl->in_place_protect_bytes_buffered)) {
gpr_log(GPR_ERROR, "Couldn't reset frame writer.");
LOG(ERROR) << "Couldn't reset frame writer.";
return TSI_INTERNAL_ERROR;
}
}
@ -126,7 +126,7 @@ static tsi_result alts_protect_flush(tsi_frame_protector* self,
size_t written_frame_bytes = *protected_output_frames_size;
if (!alts_write_frame_bytes(impl->writer, protected_output_frames,
&written_frame_bytes)) {
gpr_log(GPR_ERROR, "Couldn't write frame bytes.");
LOG(ERROR) << "Couldn't write frame bytes.";
return TSI_INTERNAL_ERROR;
}
*protected_output_frames_size = written_frame_bytes;
@ -149,7 +149,7 @@ static tsi_result alts_protect(tsi_frame_protector* self,
if (self == nullptr || unprotected_bytes == nullptr ||
unprotected_bytes_size == nullptr || protected_output_frames == nullptr ||
protected_output_frames_size == nullptr) {
gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_protect().");
LOG(ERROR) << "Invalid nullptr arguments to alts_protect().";
return TSI_INVALID_ARGUMENT;
}
alts_frame_protector* impl = reinterpret_cast<alts_frame_protector*>(self);
@ -202,7 +202,7 @@ static tsi_result unseal(alts_frame_protector* impl) {
impl->max_unprotected_frame_size,
alts_get_output_bytes_read(impl->reader), &output_size, &error_details);
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "%s", error_details);
LOG(ERROR) << error_details;
gpr_free(error_details);
return TSI_DATA_CORRUPTED;
}
@ -241,7 +241,7 @@ static tsi_result alts_unprotect(tsi_frame_protector* self,
if (self == nullptr || protected_frames_bytes == nullptr ||
protected_frames_bytes_size == nullptr || unprotected_bytes == nullptr ||
unprotected_bytes_size == nullptr) {
gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_unprotect().");
LOG(ERROR) << "Invalid nullptr arguments to alts_unprotect().";
return TSI_INVALID_ARGUMENT;
}
alts_frame_protector* impl = reinterpret_cast<alts_frame_protector*>(self);
@ -256,7 +256,7 @@ static tsi_result alts_unprotect(tsi_frame_protector* self,
impl->in_place_unprotect_bytes_processed + impl->overhead_length))) {
if (!alts_reset_frame_reader(impl->reader,
impl->in_place_unprotect_buffer)) {
gpr_log(GPR_ERROR, "Couldn't reset frame reader.");
LOG(ERROR) << "Couldn't reset frame reader.";
return TSI_INTERNAL_ERROR;
}
impl->in_place_unprotect_bytes_processed = 0;
@ -276,7 +276,7 @@ static tsi_result alts_unprotect(tsi_frame_protector* self,
size_t read_frames_bytes_size = *protected_frames_bytes_size;
if (!alts_read_frame_bytes(impl->reader, protected_frames_bytes,
&read_frames_bytes_size)) {
gpr_log(GPR_ERROR, "Failed to process frame.");
LOG(ERROR) << "Failed to process frame.";
return TSI_INTERNAL_ERROR;
}
*protected_frames_bytes_size = read_frames_bytes_size;
@ -370,8 +370,7 @@ tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size,
size_t* max_protected_frame_size,
tsi_frame_protector** self) {
if (key == nullptr || self == nullptr) {
gpr_log(GPR_ERROR,
"Invalid nullptr arguments to alts_create_frame_protector().");
LOG(ERROR) << "Invalid nullptr arguments to alts_create_frame_protector().";
return TSI_INTERNAL_ERROR;
}
char* error_details = nullptr;
@ -379,7 +378,7 @@ tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size,
grpc_status_code status = create_alts_crypters(
key, key_size, is_client, is_rekey, impl, &error_details);
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to create ALTS crypters, %s.", error_details);
LOG(ERROR) << "Failed to create ALTS crypters, " << error_details;
gpr_free(error_details);
return TSI_INTERNAL_ERROR;
}

@ -21,6 +21,7 @@
#include <list>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/numbers.h"
#include "upb/mem/arena.hpp"
@ -205,13 +206,13 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
alts_tsi_handshaker* handshaker = client->handshaker;
// Invalid input check.
if (client->cb == nullptr) {
gpr_log(GPR_ERROR,
"client->cb is nullptr in alts_tsi_handshaker_handle_response()");
LOG(ERROR)
<< "client->cb is nullptr in alts_tsi_handshaker_handle_response()";
return;
}
if (handshaker == nullptr) {
gpr_log(GPR_ERROR,
"handshaker is nullptr in alts_tsi_handshaker_handle_response()");
LOG(ERROR)
<< "handshaker is nullptr in alts_tsi_handshaker_handle_response()";
handle_response_done(
client, TSI_INTERNAL_ERROR,
"handshaker is nullptr in alts_tsi_handshaker_handle_response()",
@ -220,14 +221,14 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
}
// TSI handshake has been shutdown.
if (alts_tsi_handshaker_has_shutdown(handshaker)) {
gpr_log(GPR_INFO, "TSI handshake shutdown");
LOG(INFO) << "TSI handshake shutdown";
handle_response_done(client, TSI_HANDSHAKE_SHUTDOWN,
"TSI handshake shutdown", nullptr, 0, nullptr);
return;
}
// Check for failed grpc read.
if (!is_ok || client->inject_read_failure) {
gpr_log(GPR_INFO, "read failed on grpc call to handshaker service");
LOG(INFO) << "read failed on grpc call to handshaker service";
handle_response_done(client, TSI_INTERNAL_ERROR,
"read failed on grpc call to handshaker service",
nullptr, 0, nullptr);
@ -249,7 +250,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
client->recv_buffer = nullptr;
// Invalid handshaker response check.
if (resp == nullptr) {
gpr_log(GPR_ERROR, "alts_tsi_utils_deserialize_response() failed");
LOG(ERROR) << "alts_tsi_utils_deserialize_response() failed";
handle_response_done(client, TSI_DATA_CORRUPTED,
"alts_tsi_utils_deserialize_response() failed",
nullptr, 0, nullptr);
@ -258,7 +259,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
const grpc_gcp_HandshakerStatus* resp_status =
grpc_gcp_HandshakerResp_status(resp);
if (resp_status == nullptr) {
gpr_log(GPR_ERROR, "No status in HandshakerResp");
LOG(ERROR) << "No status in HandshakerResp";
handle_response_done(client, TSI_DATA_CORRUPTED,
"No status in HandshakerResp", nullptr, 0, nullptr);
return;
@ -281,7 +282,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
tsi_result status =
alts_tsi_handshaker_result_create(resp, client->is_client, &result);
if (status != TSI_OK) {
gpr_log(GPR_ERROR, "alts_tsi_handshaker_result_create() failed");
LOG(ERROR) << "alts_tsi_handshaker_result_create() failed";
handle_response_done(client, status,
"alts_tsi_handshaker_result_create() failed",
nullptr, 0, nullptr);
@ -299,7 +300,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
if (details.size > 0) {
error = absl::StrCat("Status ", code, " from handshaker service: ",
absl::string_view(details.data, details.size));
gpr_log(GPR_ERROR, "%s", error.c_str());
LOG(ERROR) << error;
}
}
// TODO(apolcyn): consider short ciruiting handle_response_done and
@ -357,7 +358,7 @@ static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client,
if (client->grpc_caller(client->call, ops, static_cast<size_t>(op - ops),
&client->on_handshaker_service_resp_recv) !=
GRPC_CALL_OK) {
gpr_log(GPR_ERROR, "Start batch operation failed");
LOG(ERROR) << "Start batch operation failed";
return TSI_INTERNAL_ERROR;
}
return TSI_OK;
@ -544,21 +545,21 @@ static grpc_byte_buffer* get_serialized_start_client(
static tsi_result handshaker_client_start_client(alts_handshaker_client* c) {
if (c == nullptr) {
gpr_log(GPR_ERROR, "client is nullptr in handshaker_client_start_client()");
LOG(ERROR) << "client is nullptr in handshaker_client_start_client()";
return TSI_INVALID_ARGUMENT;
}
grpc_byte_buffer* buffer = get_serialized_start_client(c);
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
if (buffer == nullptr) {
gpr_log(GPR_ERROR, "get_serialized_start_client() failed");
LOG(ERROR) << "get_serialized_start_client() failed";
return TSI_INTERNAL_ERROR;
}
handshaker_client_send_buffer_destroy(client);
client->send_buffer = buffer;
tsi_result result = make_grpc_call(&client->base, true /* is_start */);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "make_grpc_call() failed");
LOG(ERROR) << "make_grpc_call() failed";
}
return result;
}
@ -603,21 +604,21 @@ static grpc_byte_buffer* get_serialized_start_server(
static tsi_result handshaker_client_start_server(alts_handshaker_client* c,
grpc_slice* bytes_received) {
if (c == nullptr || bytes_received == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to handshaker_client_start_server()");
LOG(ERROR) << "Invalid arguments to handshaker_client_start_server()";
return TSI_INVALID_ARGUMENT;
}
alts_grpc_handshaker_client* client =
reinterpret_cast<alts_grpc_handshaker_client*>(c);
grpc_byte_buffer* buffer = get_serialized_start_server(c, bytes_received);
if (buffer == nullptr) {
gpr_log(GPR_ERROR, "get_serialized_start_server() failed");
LOG(ERROR) << "get_serialized_start_server() failed";
return TSI_INTERNAL_ERROR;
}
handshaker_client_send_buffer_destroy(client);
client->send_buffer = buffer;
tsi_result result = make_grpc_call(&client->base, true /* is_start */);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "make_grpc_call() failed");
LOG(ERROR) << "make_grpc_call() failed";
}
return result;
}
@ -640,7 +641,7 @@ static grpc_byte_buffer* get_serialized_next(grpc_slice* bytes_received) {
static tsi_result handshaker_client_next(alts_handshaker_client* c,
grpc_slice* bytes_received) {
if (c == nullptr || bytes_received == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to handshaker_client_next()");
LOG(ERROR) << "Invalid arguments to handshaker_client_next()";
return TSI_INVALID_ARGUMENT;
}
alts_grpc_handshaker_client* client =
@ -649,14 +650,14 @@ static tsi_result handshaker_client_next(alts_handshaker_client* c,
client->recv_bytes = grpc_core::CSliceRef(*bytes_received);
grpc_byte_buffer* buffer = get_serialized_next(bytes_received);
if (buffer == nullptr) {
gpr_log(GPR_ERROR, "get_serialized_next() failed");
LOG(ERROR) << "get_serialized_next() failed";
return TSI_INTERNAL_ERROR;
}
handshaker_client_send_buffer_destroy(client);
client->send_buffer = buffer;
tsi_result result = make_grpc_call(&client->base, false /* is_start */);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "make_grpc_call() failed");
LOG(ERROR) << "make_grpc_call() failed";
}
return result;
}
@ -716,7 +717,7 @@ alts_handshaker_client* alts_grpc_handshaker_client_create(
void* user_data, alts_handshaker_client_vtable* vtable_for_testing,
bool is_client, size_t max_frame_size, std::string* error) {
if (channel == nullptr || handshaker_service_url == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to alts_handshaker_client_create()");
LOG(ERROR) << "Invalid arguments to alts_handshaker_client_create()";
return nullptr;
}
alts_grpc_handshaker_client* client = new alts_grpc_handshaker_client();
@ -891,8 +892,7 @@ tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client) {
client->vtable->client_start != nullptr) {
return client->vtable->client_start(client);
}
gpr_log(GPR_ERROR,
"client or client->vtable has not been initialized properly");
LOG(ERROR) << "client or client->vtable has not been initialized properly";
return TSI_INVALID_ARGUMENT;
}
@ -902,8 +902,7 @@ tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client,
client->vtable->server_start != nullptr) {
return client->vtable->server_start(client, bytes_received);
}
gpr_log(GPR_ERROR,
"client or client->vtable has not been initialized properly");
LOG(ERROR) << "client or client->vtable has not been initialized properly";
return TSI_INVALID_ARGUMENT;
}
@ -913,8 +912,7 @@ tsi_result alts_handshaker_client_next(alts_handshaker_client* client,
client->vtable->next != nullptr) {
return client->vtable->next(client, bytes_received);
}
gpr_log(GPR_ERROR,
"client or client->vtable has not been initialized properly");
LOG(ERROR) << "client or client->vtable has not been initialized properly";
return TSI_INVALID_ARGUMENT;
}

@ -19,6 +19,7 @@
#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/byte_buffer_reader.h>
#include <grpc/support/port_platform.h>
@ -59,7 +60,7 @@ grpc_gcp_HandshakerResp* alts_tsi_utils_deserialize_response(
grpc_core::CSliceUnref(slice);
grpc_byte_buffer_reader_destroy(&bbr);
if (resp == nullptr) {
gpr_log(GPR_ERROR, "grpc_gcp_handshaker_resp_decode() failed");
LOG(ERROR) << "grpc_gcp_handshaker_resp_decode() failed";
return nullptr;
}
return resp;

@ -18,6 +18,7 @@
#include "src/core/tsi/alts/handshaker/transport_security_common_api.h"
#include "absl/log/log.h"
#include "upb/mem/arena.hpp"
#include <grpc/support/port_platform.h>
@ -100,7 +101,7 @@ bool grpc_gcp_rpc_protocol_versions_decode(
reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(slice)),
GRPC_SLICE_LENGTH(slice), arena.ptr());
if (versions_msg == nullptr) {
gpr_log(GPR_ERROR, "cannot deserialize RpcProtocolVersions message");
LOG(ERROR) << "cannot deserialize RpcProtocolVersions message";
return false;
}
grpc_gcp_rpc_protocol_versions_assign_from_upb(versions, versions_msg);

@ -21,6 +21,7 @@
#include <string.h>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -69,7 +70,7 @@ static tsi_result alts_grpc_integrity_only_extra_copy_protect(
grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect(
rp->iovec_rp, rp->iovec_buf, 1, header_iovec, tag_iovec, &error_details);
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to protect, %s", error_details);
LOG(ERROR) << "Failed to protect, " << error_details;
gpr_free(error_details);
return TSI_INTERNAL_ERROR;
}
@ -109,7 +110,7 @@ static tsi_result alts_grpc_integrity_only_protect(
rp->iovec_rp, rp->iovec_buf, unprotected_slices->count, header_iovec,
tag_iovec, &error_details);
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to protect, %s", error_details);
LOG(ERROR) << "Failed to protect, " << error_details;
gpr_free(error_details);
return TSI_INTERNAL_ERROR;
}
@ -132,7 +133,7 @@ static tsi_result alts_grpc_integrity_only_unprotect(
return TSI_INVALID_ARGUMENT;
}
if (protected_slices->length < rp->header_length + rp->tag_length) {
gpr_log(GPR_ERROR, "Protected slices do not have sufficient data.");
LOG(ERROR) << "Protected slices do not have sufficient data.";
return TSI_INVALID_ARGUMENT;
}
// In this method, rp points to alts_grpc_record_protocol struct
@ -171,7 +172,7 @@ static tsi_result alts_grpc_integrity_only_unprotect(
integrity_only_record_protocol->data_sb.count, header_iovec, tag_iovec,
&error_details);
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details);
LOG(ERROR) << "Failed to unprotect, " << error_details;
gpr_free(error_details);
return TSI_INTERNAL_ERROR;
}

@ -18,6 +18,8 @@
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h"
#include "absl/log/log.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -60,7 +62,7 @@ static tsi_result alts_grpc_privacy_integrity_protect(
rp->iovec_rp, rp->iovec_buf, unprotected_slices->count,
protected_iovec, &error_details);
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to protect, %s", error_details);
LOG(ERROR) << "Failed to protect, " << error_details;
gpr_free(error_details);
grpc_core::CSliceUnref(protected_slice);
return TSI_INTERNAL_ERROR;
@ -84,7 +86,7 @@ static tsi_result alts_grpc_privacy_integrity_unprotect(
// Allocates memory for output frame. In privacy-integrity unprotect, the
// unprotected data are stored in a newly allocated buffer.
if (protected_slices->length < rp->header_length + rp->tag_length) {
gpr_log(GPR_ERROR, "Protected slices do not have sufficient data.");
LOG(ERROR) << "Protected slices do not have sufficient data.";
return TSI_INVALID_ARGUMENT;
}
size_t unprotected_frame_size =
@ -105,7 +107,7 @@ static tsi_result alts_grpc_privacy_integrity_unprotect(
rp->iovec_rp, header_iovec, rp->iovec_buf, protected_slices->count,
unprotected_iovec, &error_details);
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details);
LOG(ERROR) << "Failed to unprotect, " << error_details;
gpr_free(error_details);
grpc_core::CSliceUnref(unprotected_slice);
return TSI_INTERNAL_ERROR;

@ -24,6 +24,7 @@
#include <utility>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -93,7 +94,7 @@ static bool read_frame_size(const grpc_slice_buffer* sb,
(static_cast<uint32_t>(frame_size_buffer[1]) << 8) |
static_cast<uint32_t>(frame_size_buffer[0]);
if (frame_size > kMaxFrameLength) {
gpr_log(GPR_ERROR, "Frame size is larger than maximum frame size");
LOG(ERROR) << "Frame size is larger than maximum frame size";
return false;
}
// Returns frame size including frame length field.
@ -124,7 +125,7 @@ static tsi_result create_alts_grpc_record_protocol(
kAesGcmTagLength, &crypter,
&error_details);
if (status != GRPC_STATUS_OK) {
gpr_log(GPR_ERROR, "Failed to create AEAD crypter, %s", error_details);
LOG(ERROR) << "Failed to create AEAD crypter, " << error_details;
gpr_free(error_details);
return TSI_INTERNAL_ERROR;
}
@ -153,7 +154,7 @@ static tsi_result alts_zero_copy_grpc_protector_protect(
grpc_slice_buffer* protected_slices) {
if (self == nullptr || unprotected_slices == nullptr ||
protected_slices == nullptr) {
gpr_log(GPR_ERROR, "Invalid nullptr arguments to zero-copy grpc protect.");
LOG(ERROR) << "Invalid nullptr arguments to zero-copy grpc protect.";
return TSI_INVALID_ARGUMENT;
}
alts_zero_copy_grpc_protector* protector =

@ -22,6 +22,7 @@
#include <string.h>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -31,7 +32,7 @@
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/tsi/transport_security_grpc.h"
#include "src/core/util/useful.h"
#include "src/core/tsi/transport_security_interface.h"
// --- Constants. ---
#define TSI_FAKE_FRAME_HEADER_SIZE 4
@ -91,7 +92,7 @@ static const char* tsi_fake_handshake_message_strings[] = {
static const char* tsi_fake_handshake_message_to_string(int msg) {
if (msg < 0 || msg >= TSI_FAKE_HANDSHAKE_MESSAGE_MAX) {
gpr_log(GPR_ERROR, "Invalid message %d", msg);
LOG(ERROR) << "Invalid message " << msg;
return "UNKNOWN";
}
return tsi_fake_handshake_message_strings[msg];
@ -107,7 +108,7 @@ static tsi_result tsi_fake_handshake_message_from_string(
return TSI_OK;
}
}
gpr_log(GPR_ERROR, "Invalid handshake message.");
LOG(ERROR) << "Invalid handshake message.";
if (error != nullptr) *error = "invalid handshake message";
return TSI_DATA_CORRUPTED;
}
@ -312,8 +313,8 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self,
result = tsi_fake_frame_decode(frame_header, &written_in_frame_size, frame,
/*error=*/nullptr);
if (result != TSI_INCOMPLETE_DATA) {
gpr_log(GPR_ERROR, "tsi_fake_frame_decode returned %s",
tsi_result_to_string(result));
LOG(ERROR) << "tsi_fake_frame_decode returned "
<< tsi_result_to_string(result);
return result;
}
}
@ -469,7 +470,7 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect(
if (impl->parsed_frame_size == 0) {
impl->parsed_frame_size = read_frame_size(&impl->protected_sb);
if (impl->parsed_frame_size <= 4) {
gpr_log(GPR_ERROR, "Invalid frame size.");
LOG(ERROR) << "Invalid frame size.";
return TSI_DATA_CORRUPTED;
}
}
@ -653,7 +654,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer(
impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) {
// We're done.
if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) {
gpr_log(GPR_INFO, "Server is done.");
LOG(INFO) << "Server is done.";
}
impl->result = TSI_OK;
} else {
@ -694,15 +695,15 @@ static tsi_result fake_handshaker_process_bytes_from_peer(
tsi_fake_handshake_message_to_string(expected_msg));
}
if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) {
gpr_log(GPR_INFO, "%s received %s.", impl->is_client ? "Client" : "Server",
tsi_fake_handshake_message_to_string(received_msg));
LOG(INFO) << (impl->is_client ? "Client" : "Server") << " received "
<< tsi_fake_handshake_message_to_string(received_msg);
}
tsi_fake_frame_reset(&impl->incoming_frame, 0 /* needs_draining */);
impl->needs_incoming_message = 0;
if (impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) {
// We're done.
if (GRPC_TRACE_FLAG_ENABLED(tsi_tracing_enabled)) {
gpr_log(GPR_INFO, "%s is done.", impl->is_client ? "Client" : "Server");
LOG(INFO) << (impl->is_client ? "Client" : "Server") << " is done.";
}
impl->result = TSI_OK;
}

@ -22,8 +22,9 @@
#include <stdlib.h>
#include <string.h>
#include "absl/log/log.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>
@ -68,7 +69,7 @@ tsi_result handshaker_result_get_unused_bytes(const tsi_handshaker_result* self,
const unsigned char** bytes,
size_t* bytes_size) {
if (self == nullptr || bytes == nullptr || bytes_size == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to get_unused_bytes()");
LOG(ERROR) << "Invalid arguments to get_unused_bytes()";
return TSI_INVALID_ARGUMENT;
}
auto* result = reinterpret_cast<local_tsi_handshaker_result*>(
@ -101,7 +102,7 @@ tsi_result create_handshaker_result(const unsigned char* received_bytes,
size_t received_bytes_size,
tsi_handshaker_result** self) {
if (self == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to create_handshaker_result()");
LOG(ERROR) << "Invalid arguments to create_handshaker_result()";
return TSI_INVALID_ARGUMENT;
}
local_tsi_handshaker_result* result =
@ -128,7 +129,7 @@ tsi_result handshaker_next(tsi_handshaker* self,
tsi_handshaker_on_next_done_cb /*cb*/,
void* /*user_data*/, std::string* error) {
if (self == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to handshaker_next()");
LOG(ERROR) << "Invalid arguments to handshaker_next()";
if (error != nullptr) *error = "invalid argument";
return TSI_INVALID_ARGUMENT;
}
@ -164,7 +165,7 @@ const tsi_handshaker_vtable handshaker_vtable = {
tsi_result tsi_local_handshaker_create(tsi_handshaker** self) {
if (self == nullptr) {
gpr_log(GPR_ERROR, "Invalid arguments to local_tsi_handshaker_create()");
LOG(ERROR) << "Invalid arguments to local_tsi_handshaker_create()";
return TSI_INVALID_ARGUMENT;
}
local_tsi_handshaker* handshaker = grpc_core::Zalloc<local_tsi_handshaker>();

@ -19,6 +19,7 @@
#include "src/core/tsi/ssl/session_cache/ssl_session_cache.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -64,9 +65,8 @@ class SslSessionLRUCache::Node {
SslSessionLRUCache::SslSessionLRUCache(size_t capacity) : capacity_(capacity) {
if (capacity == 0) {
gpr_log(
GPR_ERROR,
"SslSessionLRUCache capacity is zero. SSL sessions cannot be resumed.");
LOG(ERROR) << "SslSessionLRUCache capacity is zero. SSL sessions cannot be "
"resumed.";
}
}
@ -100,7 +100,7 @@ SslSessionLRUCache::Node* SslSessionLRUCache::FindLocked(
void SslSessionLRUCache::Put(const char* key, SslSessionPtr session) {
if (session == nullptr) {
gpr_log(GPR_ERROR, "Attempted to put null SSL session in session cache.");
LOG(ERROR) << "Attempted to put null SSL session in session cache.";
return;
}
grpc_core::MutexLock lock(&lock_);

@ -23,6 +23,8 @@
#include <grpc/support/port_platform.h>
#include "src/core/tsi/transport_security_interface.h"
// TODO(jboeuf): refactor inet_ntop into a portability header.
// Note: for whomever reads this and tries to refactor this, this
// can't be in grpc, it has to be in gpr.
@ -293,8 +295,7 @@ static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8,
}
common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry);
if (common_name_asn1 == nullptr) {
gpr_log(GPR_ERROR,
"Could not get common name entry asn1 from certificate.");
LOG(ERROR) << "Could not get common name entry asn1 from certificate.";
return TSI_INTERNAL_ERROR;
}
utf8_returned_size = ASN1_STRING_to_UTF8(utf8, common_name_asn1);
@ -804,7 +805,7 @@ static tsi_result populate_ssl_context(
}
if ((cipher_list != nullptr) &&
!SSL_CTX_set_cipher_list(context, cipher_list)) {
gpr_log(GPR_ERROR, "Invalid cipher list: %s.", cipher_list);
LOG(ERROR) << "Invalid cipher list: " << cipher_list;
return TSI_INVALID_ARGUMENT;
}
{
@ -862,8 +863,7 @@ static tsi_result build_alpn_protocol_name_list(
size_t length =
alpn_protocols[i] == nullptr ? 0 : strlen(alpn_protocols[i]);
if (length == 0 || length > 255) {
gpr_log(GPR_ERROR, "Invalid protocol name length: %d.",
static_cast<int>(length));
LOG(ERROR) << "Invalid protocol name length: " << length;
return TSI_INVALID_ARGUMENT;
}
*protocol_name_list_length += length + 1;
@ -892,13 +892,12 @@ static tsi_result build_alpn_protocol_name_list(
static int verify_cb(int ok, X509_STORE_CTX* ctx) {
int cert_error = X509_STORE_CTX_get_error(ctx);
if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL) {
gpr_log(GPR_INFO,
"Certificate verification failed to find relevant CRL file. "
"Ignoring error.");
LOG(INFO) << "Certificate verification failed to find relevant CRL file. "
"Ignoring error.";
return 1;
}
if (cert_error != 0) {
gpr_log(GPR_ERROR, "Certificate verify failed with code %d", cert_error);
LOG(ERROR) << "Certificate verify failed with code " << cert_error;
}
return ok;
}
@ -942,8 +941,8 @@ static int RootCertExtractCallback(X509_STORE_CTX* ctx, void* /*arg*/) {
if (ssl_index < 0) {
char err_str[256];
ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
gpr_log(GPR_ERROR,
"error getting the SSL index from the X509_STORE_CTX: %s", err_str);
LOG(ERROR) << "error getting the SSL index from the X509_STORE_CTX: "
<< err_str;
return ret;
}
SSL* ssl = static_cast<SSL*>(X509_STORE_CTX_get_ex_data(ctx, ssl_index));
@ -987,8 +986,7 @@ static grpc_core::experimental::CrlProvider* GetCrlProvider(
}
SSL* ssl = static_cast<SSL*>(X509_STORE_CTX_get_ex_data(ctx, ssl_index));
if (ssl == nullptr) {
gpr_log(GPR_INFO,
"error while fetching from CrlProvider. SSL object is null");
LOG(INFO) << "error while fetching from CrlProvider. SSL object is null";
return nullptr;
}
SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(ssl);
@ -1175,8 +1173,8 @@ static tsi_result tsi_set_min_and_max_tls_versions(
SSL_CTX* ssl_context, tsi_tls_version min_tls_version,
tsi_tls_version max_tls_version) {
if (ssl_context == nullptr) {
gpr_log(GPR_INFO,
"Invalid nullptr argument to |tsi_set_min_and_max_tls_versions|.");
LOG(INFO) << "Invalid nullptr argument to "
"|tsi_set_min_and_max_tls_versions|.";
return TSI_INVALID_ARGUMENT;
}
#if OPENSSL_VERSION_NUMBER >= 0x10100000
@ -2085,8 +2083,7 @@ static int does_entry_match_name(absl::string_view entry,
entry.remove_prefix(2); // Remove *.
size_t dot = name_subdomain.find('.');
if (dot == absl::string_view::npos || dot == name_subdomain.size() - 1) {
gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s",
std::string(name_subdomain).c_str());
LOG(ERROR) << "Invalid toplevel subdomain: " << name_subdomain;
return 0;
}
if (name_subdomain.back() == '.') {
@ -2113,7 +2110,7 @@ static int ssl_server_handshaker_factory_servername_callback(SSL* ssl,
return SSL_TLSEXT_ERR_OK;
}
}
gpr_log(GPR_ERROR, "No match found for server name: %s.", servername);
LOG(ERROR) << "No match found for server name: " << servername;
return SSL_TLSEXT_ERR_NOACK;
}
@ -2297,8 +2294,8 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
options->alpn_protocols, options->num_alpn_protocols,
&impl->alpn_protocol_list, &impl->alpn_protocol_list_length);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Building alpn list failed with error %s.",
tsi_result_to_string(result));
LOG(ERROR) << "Building alpn list failed with error "
<< tsi_result_to_string(result);
break;
}
#if TSI_OPENSSL_ALPN_SUPPORT

@ -24,6 +24,7 @@
#include <openssl/x509v3.h>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
@ -63,7 +64,7 @@ void LogSslErrorStack(void) {
while ((err = ERR_get_error()) != 0) {
char details[256];
ERR_error_string_n(static_cast<uint32_t>(err), details, sizeof(details));
gpr_log(GPR_ERROR, "%s", details);
LOG(ERROR) << details;
}
}
@ -76,12 +77,12 @@ tsi_result DoSslWrite(SSL* ssl, unsigned char* unprotected_bytes,
if (ssl_write_result < 0) {
ssl_write_result = SSL_get_error(ssl, ssl_write_result);
if (ssl_write_result == SSL_ERROR_WANT_READ) {
gpr_log(GPR_ERROR,
"Peer tried to renegotiate SSL connection. This is unsupported.");
LOG(ERROR)
<< "Peer tried to renegotiate SSL connection. This is unsupported.";
return TSI_UNIMPLEMENTED;
} else {
gpr_log(GPR_ERROR, "SSL_write failed with error %s.",
SslErrorString(ssl_write_result));
LOG(ERROR) << "SSL_write failed with error "
<< SslErrorString(ssl_write_result);
return TSI_INTERNAL_ERROR;
}
}
@ -107,12 +108,12 @@ tsi_result DoSslRead(SSL* ssl, unsigned char* unprotected_bytes,
"Peer tried to renegotiate SSL connection. This is unsupported.");
return TSI_UNIMPLEMENTED;
case SSL_ERROR_SSL:
gpr_log(GPR_ERROR, "Corruption detected.");
LOG(ERROR) << "Corruption detected.";
LogSslErrorStack();
return TSI_DATA_CORRUPTED;
default:
gpr_log(GPR_ERROR, "SSL_read failed with error %s.",
SslErrorString(read_from_ssl));
LOG(ERROR) << "SSL_read failed with error "
<< SslErrorString(read_from_ssl);
return TSI_PROTOCOL_FAILURE;
}
}
@ -139,8 +140,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes,
read_from_ssl = BIO_read(network_io, protected_output_frames,
static_cast<int>(*protected_output_frames_size));
if (read_from_ssl < 0) {
gpr_log(GPR_ERROR,
"Could not read from BIO even though some data is pending");
LOG(ERROR) << "Could not read from BIO even though some data is pending";
return TSI_INTERNAL_ERROR;
}
*protected_output_frames_size = static_cast<size_t>(read_from_ssl);
@ -166,7 +166,7 @@ tsi_result SslProtectorProtect(const unsigned char* unprotected_bytes,
read_from_ssl = BIO_read(network_io, protected_output_frames,
static_cast<int>(*protected_output_frames_size));
if (read_from_ssl < 0) {
gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write.");
LOG(ERROR) << "Could not read from BIO after SSL_write.";
return TSI_INTERNAL_ERROR;
}
*protected_output_frames_size = static_cast<size_t>(read_from_ssl);
@ -200,7 +200,7 @@ tsi_result SslProtectorProtectFlush(size_t& buffer_offset,
read_from_ssl = BIO_read(network_io, protected_output_frames,
static_cast<int>(*protected_output_frames_size));
if (read_from_ssl <= 0) {
gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write.");
LOG(ERROR) << "Could not read from BIO after SSL_write.";
return TSI_INTERNAL_ERROR;
}
*protected_output_frames_size = static_cast<size_t>(read_from_ssl);
@ -237,8 +237,8 @@ tsi_result SslProtectorUnprotect(const unsigned char* protected_frames_bytes,
written_into_ssl = BIO_write(network_io, protected_frames_bytes,
static_cast<int>(*protected_frames_bytes_size));
if (written_into_ssl < 0) {
gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d",
written_into_ssl);
LOG(ERROR) << "Sending protected frame to ssl failed with "
<< written_into_ssl;
return TSI_INTERNAL_ERROR;
}
*protected_frames_bytes_size = static_cast<size_t>(written_into_ssl);
@ -260,16 +260,15 @@ bool VerifyCrlSignature(X509_CRL* crl, X509* issuer) {
if (ikey == nullptr) {
// Can't verify signature because we couldn't get the pubkey, fail the
// check.
gpr_log(GPR_DEBUG, "Could not public key from certificate.");
VLOG(2) << "Could not public key from certificate.";
EVP_PKEY_free(ikey);
return false;
}
int ret = X509_CRL_verify(crl, ikey);
if (ret < 0) {
gpr_log(GPR_DEBUG,
"There was an unexpected problem checking the CRL signature.");
VLOG(2) << "There was an unexpected problem checking the CRL signature.";
} else if (ret == 0) {
gpr_log(GPR_DEBUG, "CRL failed verification.");
VLOG(2) << "CRL failed verification.";
}
EVP_PKEY_free(ikey);
return ret == 1;

@ -24,6 +24,7 @@
#include <vector>
#include "absl/base/thread_annotations.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
@ -220,7 +221,7 @@ absl::StatusOr<std::string> GetBootstrapContents(const char* fallback_config) {
// Finally, try fallback config.
if (fallback_config != nullptr) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_xds_client_trace)) {
gpr_log(GPR_INFO, "Got bootstrap contents from fallback config");
LOG(INFO) << "Got bootstrap contents from fallback config";
}
return fallback_config;
}

Loading…
Cancel
Save