aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/security/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/security/transport')
-rw-r--r--src/core/lib/security/transport/client_auth_filter.cc48
-rw-r--r--src/core/lib/security/transport/lb_targets_info.cc4
-rw-r--r--src/core/lib/security/transport/secure_endpoint.cc8
-rw-r--r--src/core/lib/security/transport/security_connector.cc183
-rw-r--r--src/core/lib/security/transport/security_handshaker.cc82
-rw-r--r--src/core/lib/security/transport/server_auth_filter.cc17
6 files changed, 173 insertions, 169 deletions
diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc
index cf382e8940..cd3c2e3f19 100644
--- a/src/core/lib/security/transport/client_auth_filter.cc
+++ b/src/core/lib/security/transport/client_auth_filter.cc
@@ -67,18 +67,18 @@ typedef struct {
void grpc_auth_metadata_context_reset(
grpc_auth_metadata_context* auth_md_context) {
- if (auth_md_context->service_url != NULL) {
+ if (auth_md_context->service_url != nullptr) {
gpr_free((char*)auth_md_context->service_url);
- auth_md_context->service_url = NULL;
+ auth_md_context->service_url = nullptr;
}
- if (auth_md_context->method_name != NULL) {
+ if (auth_md_context->method_name != nullptr) {
gpr_free((char*)auth_md_context->method_name);
- auth_md_context->method_name = NULL;
+ auth_md_context->method_name = nullptr;
}
GRPC_AUTH_CONTEXT_UNREF(
(grpc_auth_context*)auth_md_context->channel_auth_context,
"grpc_auth_metadata_context");
- auth_md_context->channel_auth_context = NULL;
+ auth_md_context->channel_auth_context = nullptr;
}
static void add_error(grpc_error** combined, grpc_error* error) {
@@ -124,10 +124,10 @@ void grpc_auth_metadata_context_build(
grpc_auth_metadata_context* auth_md_context) {
char* service = grpc_slice_to_c_string(call_method);
char* last_slash = strrchr(service, '/');
- char* method_name = NULL;
- char* service_url = NULL;
+ char* method_name = nullptr;
+ char* service_url = nullptr;
grpc_auth_metadata_context_reset(auth_md_context);
- if (last_slash == NULL) {
+ if (last_slash == nullptr) {
gpr_log(GPR_ERROR, "No '/' found in fully qualified method name");
service[0] = '\0';
method_name = gpr_strdup("");
@@ -138,15 +138,15 @@ void grpc_auth_metadata_context_build(
method_name = gpr_strdup(last_slash + 1);
}
char* host_and_port = grpc_slice_to_c_string(call_host);
- if (url_scheme != NULL && strcmp(url_scheme, GRPC_SSL_URL_SCHEME) == 0) {
+ if (url_scheme != nullptr && strcmp(url_scheme, GRPC_SSL_URL_SCHEME) == 0) {
/* Remove the port if it is 443. */
char* port_delimiter = strrchr(host_and_port, ':');
- if (port_delimiter != NULL && strcmp(port_delimiter + 1, "443") == 0) {
+ if (port_delimiter != nullptr && strcmp(port_delimiter + 1, "443") == 0) {
*port_delimiter = '\0';
}
}
- gpr_asprintf(&service_url, "%s://%s%s", url_scheme == NULL ? "" : url_scheme,
- host_and_port, service);
+ gpr_asprintf(&service_url, "%s://%s%s",
+ url_scheme == nullptr ? "" : url_scheme, host_and_port, service);
auth_md_context->service_url = service_url;
auth_md_context->method_name = method_name;
auth_md_context->channel_auth_context =
@@ -175,18 +175,18 @@ static void send_security_metadata(grpc_call_element* elem,
.value;
grpc_call_credentials* channel_call_creds =
chand->security_connector->request_metadata_creds;
- int call_creds_has_md = (ctx != NULL) && (ctx->creds != NULL);
+ int call_creds_has_md = (ctx != nullptr) && (ctx->creds != nullptr);
- if (channel_call_creds == NULL && !call_creds_has_md) {
+ if (channel_call_creds == nullptr && !call_creds_has_md) {
/* Skip sending metadata altogether. */
grpc_call_next_op(elem, batch);
return;
}
- if (channel_call_creds != NULL && call_creds_has_md) {
+ if (channel_call_creds != nullptr && call_creds_has_md) {
calld->creds = grpc_composite_call_credentials_create(channel_call_creds,
- ctx->creds, NULL);
- if (calld->creds == NULL) {
+ ctx->creds, nullptr);
+ if (calld->creds == nullptr) {
grpc_transport_stream_op_batch_finish_with_failure(
batch,
grpc_error_set_int(
@@ -205,7 +205,7 @@ static void send_security_metadata(grpc_call_element* elem,
chand->security_connector->base.url_scheme, calld->host, calld->method,
chand->auth_context, &calld->auth_md_context);
- GPR_ASSERT(calld->pollent != NULL);
+ GPR_ASSERT(calld->pollent != nullptr);
GRPC_CLOSURE_INIT(&calld->async_result_closure, on_credentials_metadata,
batch, grpc_schedule_on_exec_ctx);
@@ -271,8 +271,8 @@ static void auth_start_transport_stream_op_batch(
channel_data* chand = (channel_data*)elem->channel_data;
if (!batch->cancel_stream) {
- GPR_ASSERT(batch->payload->context != NULL);
- if (batch->payload->context[GRPC_CONTEXT_SECURITY].value == NULL) {
+ GPR_ASSERT(batch->payload->context != nullptr);
+ if (batch->payload->context[GRPC_CONTEXT_SECURITY].value == nullptr) {
batch->payload->context[GRPC_CONTEXT_SECURITY].value =
grpc_client_security_context_create();
batch->payload->context[GRPC_CONTEXT_SECURITY].destroy =
@@ -290,7 +290,7 @@ static void auth_start_transport_stream_op_batch(
if (batch->send_initial_metadata) {
for (grpc_linked_mdelem* l = batch->payload->send_initial_metadata
.send_initial_metadata->list.head;
- l != NULL; l = l->next) {
+ l != nullptr; l = l->next) {
grpc_mdelem md = l->md;
/* Pointer comparison is OK for md_elems created from the same context.
*/
@@ -376,13 +376,13 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
grpc_channel_element_args* args) {
grpc_security_connector* sc =
grpc_security_connector_find_in_args(args->channel_args);
- if (sc == NULL) {
+ if (sc == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Security connector missing from client auth filter args");
}
grpc_auth_context* auth_context =
grpc_find_auth_context_in_args(args->channel_args);
- if (auth_context == NULL) {
+ if (auth_context == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Auth context missing from client auth filter args");
}
@@ -409,7 +409,7 @@ static void destroy_channel_elem(grpc_channel_element* elem) {
/* grab pointers to our data from the channel element */
channel_data* chand = (channel_data*)elem->channel_data;
grpc_channel_security_connector* sc = chand->security_connector;
- if (sc != NULL) {
+ if (sc != nullptr) {
GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "client_auth_filter");
}
GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "client_auth_filter");
diff --git a/src/core/lib/security/transport/lb_targets_info.cc b/src/core/lib/security/transport/lb_targets_info.cc
index f2e2399a7e..183b1ebf35 100644
--- a/src/core/lib/security/transport/lb_targets_info.cc
+++ b/src/core/lib/security/transport/lb_targets_info.cc
@@ -49,9 +49,9 @@ grpc_slice_hash_table* grpc_lb_targets_info_find_in_args(
const grpc_channel_args* args) {
const grpc_arg* targets_info_arg =
grpc_channel_args_find(args, GRPC_ARG_LB_SECURE_NAMING_MAP);
- if (targets_info_arg != NULL) {
+ if (targets_info_arg != nullptr) {
GPR_ASSERT(targets_info_arg->type == GRPC_ARG_POINTER);
return (grpc_slice_hash_table*)targets_info_arg->value.pointer.p;
}
- return NULL;
+ return nullptr;
}
diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc
index 41456f994d..4ea40e7fa1 100644
--- a/src/core/lib/security/transport/secure_endpoint.cc
+++ b/src/core/lib/security/transport/secure_endpoint.cc
@@ -136,7 +136,7 @@ static void call_read_cb(secure_endpoint* ep, grpc_error* error) {
gpr_free(data);
}
}
- ep->read_buffer = NULL;
+ ep->read_buffer = nullptr;
GRPC_CLOSURE_SCHED(ep->read_cb, error);
SECURE_ENDPOINT_UNREF(ep, "read");
}
@@ -156,7 +156,7 @@ static void on_read(void* user_data, grpc_error* error) {
return;
}
- if (ep->zero_copy_protector != NULL) {
+ if (ep->zero_copy_protector != nullptr) {
// Use zero-copy grpc protector to unprotect.
result = tsi_zero_copy_grpc_protector_unprotect(
ep->zero_copy_protector, &ep->source_buffer, ep->read_buffer);
@@ -272,7 +272,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
}
}
- if (ep->zero_copy_protector != NULL) {
+ if (ep->zero_copy_protector != nullptr) {
// Use zero-copy grpc protector to protect.
result = tsi_zero_copy_grpc_protector_protect(ep->zero_copy_protector,
slices, &ep->output_buffer);
@@ -420,7 +420,7 @@ grpc_endpoint* grpc_secure_endpoint_create(
ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
grpc_slice_buffer_init(&ep->output_buffer);
grpc_slice_buffer_init(&ep->source_buffer);
- ep->read_buffer = NULL;
+ ep->read_buffer = nullptr;
GRPC_CLOSURE_INIT(&ep->on_read, on_read, ep, grpc_schedule_on_exec_ctx);
gpr_mu_init(&ep->protector_mu);
gpr_ref_init(&ep->ref, 1);
diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc
index c35385c33f..0c99268578 100644
--- a/src/core/lib/security/transport/security_connector.cc
+++ b/src/core/lib/security/transport/security_connector.cc
@@ -60,7 +60,7 @@ static const char* installed_roots_path =
/* -- Overridden default roots. -- */
-static grpc_ssl_roots_override_callback ssl_roots_override_cb = NULL;
+static grpc_ssl_roots_override_callback ssl_roots_override_cb = nullptr;
void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) {
ssl_roots_override_cb = cb;
@@ -74,11 +74,11 @@ void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) {
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384"
static gpr_once cipher_suites_once = GPR_ONCE_INIT;
-static const char* cipher_suites = NULL;
+static const char* cipher_suites = nullptr;
static void init_cipher_suites(void) {
char* overridden = gpr_getenv("GRPC_SSL_CIPHER_SUITES");
- cipher_suites = overridden != NULL ? overridden : GRPC_SSL_CIPHER_SUITES;
+ cipher_suites = overridden != nullptr ? overridden : GRPC_SSL_CIPHER_SUITES;
}
static const char* ssl_cipher_suites(void) {
@@ -92,24 +92,24 @@ static const char* ssl_cipher_suites(void) {
const tsi_peer_property* tsi_peer_get_property_by_name(const tsi_peer* peer,
const char* name) {
size_t i;
- if (peer == NULL) return NULL;
+ if (peer == nullptr) return nullptr;
for (i = 0; i < peer->property_count; i++) {
const tsi_peer_property* property = &peer->properties[i];
- if (name == NULL && property->name == NULL) {
+ if (name == nullptr && property->name == nullptr) {
return property;
}
- if (name != NULL && property->name != NULL &&
+ if (name != nullptr && property->name != nullptr &&
strcmp(property->name, name) == 0) {
return property;
}
}
- return NULL;
+ return nullptr;
}
void grpc_channel_security_connector_add_handshakers(
grpc_channel_security_connector* connector,
grpc_handshake_manager* handshake_mgr) {
- if (connector != NULL) {
+ if (connector != nullptr) {
connector->add_handshakers(connector, handshake_mgr);
}
}
@@ -117,7 +117,7 @@ void grpc_channel_security_connector_add_handshakers(
void grpc_server_security_connector_add_handshakers(
grpc_server_security_connector* connector,
grpc_handshake_manager* handshake_mgr) {
- if (connector != NULL) {
+ if (connector != nullptr) {
connector->add_handshakers(connector, handshake_mgr);
}
}
@@ -126,7 +126,7 @@ void grpc_security_connector_check_peer(grpc_security_connector* sc,
tsi_peer peer,
grpc_auth_context** auth_context,
grpc_closure* on_peer_checked) {
- if (sc == NULL) {
+ if (sc == nullptr) {
GRPC_CLOSURE_SCHED(on_peer_checked,
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"cannot check peer -- no security connector"));
@@ -138,7 +138,7 @@ void grpc_security_connector_check_peer(grpc_security_connector* sc,
int grpc_security_connector_cmp(grpc_security_connector* sc,
grpc_security_connector* other) {
- if (sc == NULL || other == NULL) return GPR_ICMP(sc, other);
+ if (sc == nullptr || other == nullptr) return GPR_ICMP(sc, other);
int c = GPR_ICMP(sc->vtable, other->vtable);
if (c != 0) return c;
return sc->vtable->cmp(sc, other);
@@ -146,8 +146,8 @@ int grpc_security_connector_cmp(grpc_security_connector* sc,
int grpc_channel_security_connector_cmp(grpc_channel_security_connector* sc1,
grpc_channel_security_connector* sc2) {
- GPR_ASSERT(sc1->channel_creds != NULL);
- GPR_ASSERT(sc2->channel_creds != NULL);
+ GPR_ASSERT(sc1->channel_creds != nullptr);
+ GPR_ASSERT(sc2->channel_creds != nullptr);
int c = GPR_ICMP(sc1->channel_creds, sc2->channel_creds);
if (c != 0) return c;
c = GPR_ICMP(sc1->request_metadata_creds, sc2->request_metadata_creds);
@@ -162,8 +162,8 @@ int grpc_channel_security_connector_cmp(grpc_channel_security_connector* sc1,
int grpc_server_security_connector_cmp(grpc_server_security_connector* sc1,
grpc_server_security_connector* sc2) {
- GPR_ASSERT(sc1->server_creds != NULL);
- GPR_ASSERT(sc2->server_creds != NULL);
+ GPR_ASSERT(sc1->server_creds != nullptr);
+ GPR_ASSERT(sc2->server_creds != nullptr);
int c = GPR_ICMP(sc1->server_creds, sc2->server_creds);
if (c != 0) return c;
return GPR_ICMP((void*)sc1->add_handshakers, (void*)sc2->add_handshakers);
@@ -173,7 +173,7 @@ bool grpc_channel_security_connector_check_call_host(
grpc_channel_security_connector* sc, const char* host,
grpc_auth_context* auth_context, grpc_closure* on_call_host_checked,
grpc_error** error) {
- if (sc == NULL || sc->check_call_host == NULL) {
+ if (sc == nullptr || sc->check_call_host == nullptr) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"cannot check call host -- no security connector");
return true;
@@ -185,7 +185,7 @@ bool grpc_channel_security_connector_check_call_host(
void grpc_channel_security_connector_cancel_check_call_host(
grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked,
grpc_error* error) {
- if (sc == NULL || sc->cancel_check_call_host == NULL) {
+ if (sc == nullptr || sc->cancel_check_call_host == nullptr) {
GRPC_ERROR_UNREF(error);
return;
}
@@ -196,7 +196,7 @@ void grpc_channel_security_connector_cancel_check_call_host(
grpc_security_connector* grpc_security_connector_ref(
grpc_security_connector* sc, const char* file, int line,
const char* reason) {
- if (sc == NULL) return NULL;
+ if (sc == nullptr) return nullptr;
if (GRPC_TRACER_ON(grpc_trace_security_connector_refcount)) {
gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
@@ -206,7 +206,7 @@ grpc_security_connector* grpc_security_connector_ref(
#else
grpc_security_connector* grpc_security_connector_ref(
grpc_security_connector* sc) {
- if (sc == NULL) return NULL;
+ if (sc == nullptr) return nullptr;
#endif
gpr_ref(&sc->refcount);
return sc;
@@ -216,7 +216,7 @@ grpc_security_connector* grpc_security_connector_ref(
void grpc_security_connector_unref(grpc_security_connector* sc,
const char* file, int line,
const char* reason) {
- if (sc == NULL) return;
+ if (sc == nullptr) return;
if (GRPC_TRACER_ON(grpc_trace_security_connector_refcount)) {
gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
@@ -225,7 +225,7 @@ void grpc_security_connector_unref(grpc_security_connector* sc,
}
#else
void grpc_security_connector_unref(grpc_security_connector* sc) {
- if (sc == NULL) return;
+ if (sc == nullptr) return;
#endif
if (gpr_unref(&sc->refcount)) sc->vtable->destroy(sc);
}
@@ -254,11 +254,11 @@ grpc_arg grpc_security_connector_to_arg(grpc_security_connector* sc) {
}
grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) {
- if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR)) return NULL;
+ if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR)) return nullptr;
if (arg->type != GRPC_ARG_POINTER) {
gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type,
GRPC_ARG_SECURITY_CONNECTOR);
- return NULL;
+ return nullptr;
}
return (grpc_security_connector*)arg->value.pointer.p;
}
@@ -266,13 +266,13 @@ grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) {
grpc_security_connector* grpc_security_connector_find_in_args(
const grpc_channel_args* args) {
size_t i;
- if (args == NULL) return NULL;
+ if (args == nullptr) return nullptr;
for (i = 0; i < args->num_args; i++) {
grpc_security_connector* sc =
grpc_security_connector_from_arg(&args->args[i]);
- if (sc != NULL) return sc;
+ if (sc != nullptr) return sc;
}
- return NULL;
+ return nullptr;
}
static tsi_client_certificate_request_type
@@ -321,14 +321,14 @@ static void fake_server_destroy(grpc_security_connector* sc) { gpr_free(sc); }
static bool fake_check_target(const char* target_type, const char* target,
const char* set_str) {
- GPR_ASSERT(target_type != NULL);
- GPR_ASSERT(target != NULL);
- char** set = NULL;
+ GPR_ASSERT(target_type != nullptr);
+ GPR_ASSERT(target != nullptr);
+ char** set = nullptr;
size_t set_size = 0;
gpr_string_split(set_str, ",", &set, &set_size);
bool found = false;
for (size_t i = 0; i < set_size; ++i) {
- if (set[i] != NULL && strcmp(target, set[i]) == 0) found = true;
+ if (set[i] != nullptr && strcmp(target, set[i]) == 0) found = true;
}
for (size_t i = 0; i < set_size; ++i) {
gpr_free(set[i]);
@@ -340,8 +340,8 @@ static bool fake_check_target(const char* target_type, const char* target,
static void fake_secure_name_check(const char* target,
const char* expected_targets,
bool is_lb_channel) {
- if (expected_targets == NULL) return;
- char** lbs_and_backends = NULL;
+ if (expected_targets == nullptr) return;
+ char** lbs_and_backends = nullptr;
size_t lbs_and_backends_size = 0;
bool success = false;
gpr_string_split(expected_targets, ";", &lbs_and_backends,
@@ -386,18 +386,18 @@ static void fake_check_peer(grpc_security_connector* sc, tsi_peer peer,
grpc_closure* on_peer_checked) {
const char* prop_name;
grpc_error* error = GRPC_ERROR_NONE;
- *auth_context = NULL;
+ *auth_context = nullptr;
if (peer.property_count != 1) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Fake peers should only have 1 property.");
goto end;
}
prop_name = peer.properties[0].name;
- if (prop_name == NULL ||
+ if (prop_name == nullptr ||
strcmp(prop_name, TSI_CERTIFICATE_TYPE_PEER_PROPERTY)) {
char* msg;
gpr_asprintf(&msg, "Unexpected property in fake peer: %s.",
- prop_name == NULL ? "<EMPTY>" : prop_name);
+ prop_name == nullptr ? "<EMPTY>" : prop_name);
error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
gpr_free(msg);
goto end;
@@ -408,7 +408,7 @@ static void fake_check_peer(grpc_security_connector* sc, tsi_peer peer,
"Invalid value for cert type property.");
goto end;
}
- *auth_context = grpc_auth_context_create(NULL);
+ *auth_context = grpc_auth_context_create(nullptr);
grpc_auth_context_add_cstring_property(
*auth_context, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
GRPC_FAKE_TRANSPORT_SECURITY_TYPE);
@@ -442,7 +442,7 @@ static int fake_channel_cmp(grpc_security_connector* sc1,
if (c != 0) return c;
c = strcmp(c1->target, c2->target);
if (c != 0) return c;
- if (c1->expected_targets == NULL || c2->expected_targets == NULL) {
+ if (c1->expected_targets == nullptr || c2->expected_targets == nullptr) {
c = GPR_ICMP(c1->expected_targets, c2->expected_targets);
} else {
c = strcmp(c1->expected_targets, c2->expected_targets);
@@ -513,7 +513,7 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create(
c->target = gpr_strdup(target);
const char* expected_targets = grpc_fake_transport_get_expected_targets(args);
c->expected_targets = gpr_strdup(expected_targets);
- c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != NULL);
+ c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != nullptr);
return &c->base;
}
@@ -546,11 +546,11 @@ typedef struct {
static bool server_connector_has_cert_config_fetcher(
grpc_ssl_server_security_connector* c) {
- GPR_ASSERT(c != NULL);
+ GPR_ASSERT(c != nullptr);
grpc_ssl_server_credentials* server_creds =
(grpc_ssl_server_credentials*)c->base.server_creds;
- GPR_ASSERT(server_creds != NULL);
- return server_creds->certificate_config_fetcher.cb != NULL;
+ GPR_ASSERT(server_creds != nullptr);
+ return server_creds->certificate_config_fetcher.cb != nullptr;
}
static void ssl_channel_destroy(grpc_security_connector* sc) {
@@ -559,9 +559,9 @@ static void ssl_channel_destroy(grpc_security_connector* sc) {
grpc_channel_credentials_unref(c->base.channel_creds);
grpc_call_credentials_unref(c->base.request_metadata_creds);
tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory);
- c->client_handshaker_factory = NULL;
- if (c->target_name != NULL) gpr_free(c->target_name);
- if (c->overridden_target_name != NULL) gpr_free(c->overridden_target_name);
+ c->client_handshaker_factory = nullptr;
+ if (c->target_name != nullptr) gpr_free(c->target_name);
+ if (c->overridden_target_name != nullptr) gpr_free(c->overridden_target_name);
gpr_free(sc);
}
@@ -570,7 +570,7 @@ static void ssl_server_destroy(grpc_security_connector* sc) {
(grpc_ssl_server_security_connector*)sc;
grpc_server_credentials_unref(c->base.server_creds);
tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory);
- c->server_handshaker_factory = NULL;
+ c->server_handshaker_factory = nullptr;
gpr_free(sc);
}
@@ -579,11 +579,11 @@ static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc,
grpc_ssl_channel_security_connector* c =
(grpc_ssl_channel_security_connector*)sc;
// Instantiate TSI handshaker.
- tsi_handshaker* tsi_hs = NULL;
+ tsi_handshaker* tsi_hs = nullptr;
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
c->client_handshaker_factory,
- c->overridden_target_name != NULL ? c->overridden_target_name
- : c->target_name,
+ c->overridden_target_name != nullptr ? c->overridden_target_name
+ : c->target_name,
&tsi_hs);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
@@ -597,7 +597,7 @@ static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc,
}
static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) {
- GPR_ASSERT(num_alpn_protocols != NULL);
+ GPR_ASSERT(num_alpn_protocols != nullptr);
*num_alpn_protocols = grpc_chttp2_num_alpn_versions();
const char** alpn_protocol_strings =
(const char**)gpr_malloc(sizeof(const char*) * (*num_alpn_protocols));
@@ -614,7 +614,7 @@ static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) {
static bool try_replace_server_handshaker_factory(
grpc_ssl_server_security_connector* sc,
const grpc_ssl_server_certificate_config* config) {
- if (config == NULL) {
+ if (config == nullptr) {
gpr_log(GPR_ERROR,
"Server certificate config callback returned invalid (NULL) "
"config.");
@@ -627,7 +627,7 @@ static bool try_replace_server_handshaker_factory(
fill_alpn_protocol_strings(&num_alpn_protocols);
tsi_ssl_pem_key_cert_pair* cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs(
config->pem_key_cert_pairs, config->num_key_cert_pairs);
- tsi_ssl_server_handshaker_factory* new_handshaker_factory = NULL;
+ tsi_ssl_server_handshaker_factory* new_handshaker_factory = nullptr;
grpc_ssl_server_credentials* server_creds =
(grpc_ssl_server_credentials*)sc->base.server_creds;
tsi_result result = tsi_create_ssl_server_handshaker_factory_ex(
@@ -654,10 +654,10 @@ static bool try_replace_server_handshaker_factory(
* an error. Returns true if new credentials were sucessfully loaded. */
static bool try_fetch_ssl_server_credentials(
grpc_ssl_server_security_connector* sc) {
- grpc_ssl_server_certificate_config* certificate_config = NULL;
+ grpc_ssl_server_certificate_config* certificate_config = nullptr;
bool status;
- GPR_ASSERT(sc != NULL);
+ GPR_ASSERT(sc != nullptr);
if (!server_connector_has_cert_config_fetcher(sc)) return false;
grpc_ssl_server_credentials* server_creds =
@@ -679,7 +679,7 @@ static bool try_fetch_ssl_server_credentials(
status = false;
}
- if (certificate_config != NULL) {
+ if (certificate_config != nullptr) {
grpc_ssl_server_certificate_config_destroy(certificate_config);
}
return status;
@@ -691,7 +691,7 @@ static void ssl_server_add_handshakers(grpc_server_security_connector* sc,
(grpc_ssl_server_security_connector*)sc;
// Instantiate TSI handshaker.
try_fetch_ssl_server_credentials(c);
- tsi_handshaker* tsi_hs = NULL;
+ tsi_handshaker* tsi_hs = nullptr;
tsi_result result = tsi_ssl_server_handshaker_factory_create_handshaker(
c->server_handshaker_factory, &tsi_hs);
if (result != TSI_OK) {
@@ -706,10 +706,10 @@ static void ssl_server_add_handshakers(grpc_server_security_connector* sc,
}
static int ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) {
- char* allocated_name = NULL;
+ char* allocated_name = nullptr;
int r;
- if (strchr(peer_name, ':') != NULL) {
+ if (strchr(peer_name, ':') != nullptr) {
char* ignored_port;
gpr_split_host_port(peer_name, &allocated_name, &ignored_port);
gpr_free(ignored_port);
@@ -723,21 +723,21 @@ static int ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) {
grpc_auth_context* tsi_ssl_peer_to_auth_context(const tsi_peer* peer) {
size_t i;
- grpc_auth_context* ctx = NULL;
- const char* peer_identity_property_name = NULL;
+ grpc_auth_context* ctx = nullptr;
+ const char* peer_identity_property_name = nullptr;
/* The caller has checked the certificate type property. */
GPR_ASSERT(peer->property_count >= 1);
- ctx = grpc_auth_context_create(NULL);
+ ctx = grpc_auth_context_create(nullptr);
grpc_auth_context_add_cstring_property(
ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
GRPC_SSL_TRANSPORT_SECURITY_TYPE);
for (i = 0; i < peer->property_count; i++) {
const tsi_peer_property* prop = &peer->properties[i];
- if (prop->name == NULL) continue;
+ if (prop->name == nullptr) continue;
if (strcmp(prop->name, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY) == 0) {
/* If there is no subject alt name, have the CN as the identity. */
- if (peer_identity_property_name == NULL) {
+ if (peer_identity_property_name == nullptr) {
peer_identity_property_name = GRPC_X509_CN_PROPERTY_NAME;
}
grpc_auth_context_add_property(ctx, GRPC_X509_CN_PROPERTY_NAME,
@@ -752,7 +752,7 @@ grpc_auth_context* tsi_ssl_peer_to_auth_context(const tsi_peer* peer) {
prop->value.data, prop->value.length);
}
}
- if (peer_identity_property_name != NULL) {
+ if (peer_identity_property_name != nullptr) {
GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(
ctx, peer_identity_property_name) == 1);
}
@@ -765,7 +765,7 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc,
/* Check the ALPN. */
const tsi_peer_property* p =
tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL);
- if (p == NULL) {
+ if (p == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Cannot check peer: missing selected ALPN property.");
}
@@ -775,7 +775,7 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc,
}
/* Check the peer name if specified. */
- if (peer_name != NULL && !ssl_host_matches_name(peer, peer_name)) {
+ if (peer_name != nullptr && !ssl_host_matches_name(peer, peer_name)) {
char* msg;
gpr_asprintf(&msg, "Peer name %s is not in peer certificate", peer_name);
grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
@@ -792,7 +792,7 @@ static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer,
grpc_ssl_channel_security_connector* c =
(grpc_ssl_channel_security_connector*)sc;
grpc_error* error = ssl_check_peer(sc,
- c->overridden_target_name != NULL
+ c->overridden_target_name != nullptr
? c->overridden_target_name
: c->target_name,
&peer, auth_context);
@@ -803,7 +803,7 @@ static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer,
static void ssl_server_check_peer(grpc_security_connector* sc, tsi_peer peer,
grpc_auth_context** auth_context,
grpc_closure* on_peer_checked) {
- grpc_error* error = ssl_check_peer(sc, NULL, &peer, auth_context);
+ grpc_error* error = ssl_check_peer(sc, nullptr, &peer, auth_context);
tsi_peer_destruct(&peer);
GRPC_CLOSURE_SCHED(on_peer_checked, error);
}
@@ -818,8 +818,8 @@ static int ssl_channel_cmp(grpc_security_connector* sc1,
if (c != 0) return c;
c = strcmp(c1->target_name, c2->target_name);
if (c != 0) return c;
- return (c1->overridden_target_name == NULL ||
- c2->overridden_target_name == NULL)
+ return (c1->overridden_target_name == nullptr ||
+ c2->overridden_target_name == nullptr)
? GPR_ICMP(c1->overridden_target_name, c2->overridden_target_name)
: strcmp(c1->overridden_target_name, c2->overridden_target_name);
}
@@ -849,13 +849,13 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context(
memset(&peer, 0, sizeof(peer));
it = grpc_auth_context_property_iterator(auth_context);
- while (grpc_auth_property_iterator_next(&it) != NULL) max_num_props++;
+ while (grpc_auth_property_iterator_next(&it) != nullptr) max_num_props++;
if (max_num_props > 0) {
peer.properties = (tsi_peer_property*)gpr_malloc(max_num_props *
sizeof(tsi_peer_property));
it = grpc_auth_context_property_iterator(auth_context);
- while ((prop = grpc_auth_property_iterator_next(&it)) != NULL) {
+ while ((prop = grpc_auth_property_iterator_next(&it)) != nullptr) {
if (strcmp(prop->name, GRPC_X509_SAN_PROPERTY_NAME) == 0) {
add_shallow_auth_property_to_peer(
&peer, prop, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY);
@@ -872,7 +872,7 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context(
}
void tsi_shallow_peer_destruct(tsi_peer* peer) {
- if (peer->properties != NULL) gpr_free(peer->properties);
+ if (peer->properties != nullptr) gpr_free(peer->properties);
}
static bool ssl_channel_check_call_host(grpc_channel_security_connector* sc,
@@ -888,7 +888,8 @@ static bool ssl_channel_check_call_host(grpc_channel_security_connector* sc,
/* If the target name was overridden, then the original target_name was
'checked' transitively during the previous peer check at the end of the
handshake. */
- if (c->overridden_target_name != NULL && strcmp(host, c->target_name) == 0) {
+ if (c->overridden_target_name != nullptr &&
+ strcmp(host, c->target_name) == 0) {
status = GRPC_SECURITY_OK;
}
if (status != GRPC_SECURITY_OK) {
@@ -918,7 +919,7 @@ static grpc_slice compute_default_pem_root_certs_once(void) {
/* First try to load the roots from the environment. */
char* default_root_certs_path =
gpr_getenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR);
- if (default_root_certs_path != NULL) {
+ if (default_root_certs_path != nullptr) {
GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(default_root_certs_path, 1, &result));
gpr_free(default_root_certs_path);
@@ -926,11 +927,11 @@ static grpc_slice compute_default_pem_root_certs_once(void) {
/* Try overridden roots if needed. */
grpc_ssl_roots_override_result ovrd_res = GRPC_SSL_ROOTS_OVERRIDE_FAIL;
- if (GRPC_SLICE_IS_EMPTY(result) && ssl_roots_override_cb != NULL) {
- char* pem_root_certs = NULL;
+ if (GRPC_SLICE_IS_EMPTY(result) && ssl_roots_override_cb != nullptr) {
+ char* pem_root_certs = nullptr;
ovrd_res = ssl_roots_override_cb(&pem_root_certs);
if (ovrd_res == GRPC_SSL_ROOTS_OVERRIDE_OK) {
- GPR_ASSERT(pem_root_certs != NULL);
+ GPR_ASSERT(pem_root_certs != nullptr);
result = grpc_slice_from_copied_buffer(
pem_root_certs,
strlen(pem_root_certs) + 1); // NULL terminator.
@@ -963,7 +964,7 @@ const char* grpc_get_default_ssl_roots(void) {
static gpr_once once = GPR_ONCE_INIT;
gpr_once_init(&once, init_default_pem_root_certs);
return GRPC_SLICE_IS_EMPTY(default_pem_root_certs)
- ? NULL
+ ? nullptr
: (const char*)GRPC_SLICE_START_PTR(default_pem_root_certs);
}
@@ -981,13 +982,13 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
char* port;
bool has_key_cert_pair;
- if (config == NULL || target_name == NULL) {
+ if (config == nullptr || target_name == nullptr) {
gpr_log(GPR_ERROR, "An ssl channel needs a config and a target name.");
goto error;
}
- if (config->pem_root_certs == NULL) {
+ if (config->pem_root_certs == nullptr) {
pem_root_certs = grpc_get_default_ssl_roots();
- if (pem_root_certs == NULL) {
+ if (pem_root_certs == nullptr) {
gpr_log(GPR_ERROR, "Could not get default pem root certs.");
goto error;
}
@@ -1009,22 +1010,22 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
c->base.add_handshakers = ssl_channel_add_handshakers;
gpr_split_host_port(target_name, &c->target_name, &port);
gpr_free(port);
- if (overridden_target_name != NULL) {
+ if (overridden_target_name != nullptr) {
c->overridden_target_name = gpr_strdup(overridden_target_name);
}
- has_key_cert_pair = config->pem_key_cert_pair != NULL &&
- config->pem_key_cert_pair->private_key != NULL &&
- config->pem_key_cert_pair->cert_chain != NULL;
+ has_key_cert_pair = config->pem_key_cert_pair != nullptr &&
+ config->pem_key_cert_pair->private_key != nullptr &&
+ config->pem_key_cert_pair->cert_chain != nullptr;
result = tsi_create_ssl_client_handshaker_factory(
- has_key_cert_pair ? config->pem_key_cert_pair : NULL, pem_root_certs,
+ has_key_cert_pair ? config->pem_key_cert_pair : nullptr, pem_root_certs,
ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
&c->client_handshaker_factory);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
tsi_result_to_string(result));
ssl_channel_destroy(&c->base.base);
- *sc = NULL;
+ *sc = nullptr;
goto error;
}
*sc = &c->base;
@@ -1057,8 +1058,8 @@ grpc_security_status grpc_ssl_server_security_connector_create(
(grpc_ssl_server_credentials*)gsc;
grpc_security_status retval = GRPC_SECURITY_OK;
- GPR_ASSERT(server_credentials != NULL);
- GPR_ASSERT(sc != NULL);
+ GPR_ASSERT(server_credentials != nullptr);
+ GPR_ASSERT(sc != nullptr);
grpc_ssl_server_security_connector* c =
grpc_ssl_server_security_connector_initialize(gsc);
@@ -1091,8 +1092,8 @@ grpc_security_status grpc_ssl_server_security_connector_create(
if (retval == GRPC_SECURITY_OK) {
*sc = &c->base;
} else {
- if (c != NULL) ssl_server_destroy(&c->base.base);
- if (sc != NULL) *sc = NULL;
+ if (c != nullptr) ssl_server_destroy(&c->base.base);
+ if (sc != nullptr) *sc = nullptr;
}
return retval;
}
diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc
index 0df3375d34..25a1e59ace 100644
--- a/src/core/lib/security/transport/security_handshaker.cc
+++ b/src/core/lib/security/transport/security_handshaker.cc
@@ -65,15 +65,33 @@ typedef struct {
tsi_handshaker_result* handshaker_result;
} security_handshaker;
+static size_t move_read_buffer_into_handshake_buffer(security_handshaker* h) {
+ size_t bytes_in_read_buffer = h->args->read_buffer->length;
+ if (h->handshake_buffer_size < bytes_in_read_buffer) {
+ h->handshake_buffer =
+ (uint8_t*)gpr_realloc(h->handshake_buffer, bytes_in_read_buffer);
+ h->handshake_buffer_size = bytes_in_read_buffer;
+ }
+ size_t offset = 0;
+ while (h->args->read_buffer->count > 0) {
+ grpc_slice next_slice = grpc_slice_buffer_take_first(h->args->read_buffer);
+ memcpy(h->handshake_buffer + offset, GRPC_SLICE_START_PTR(next_slice),
+ GRPC_SLICE_LENGTH(next_slice));
+ offset += GRPC_SLICE_LENGTH(next_slice);
+ grpc_slice_unref_internal(next_slice);
+ }
+ return bytes_in_read_buffer;
+}
+
static void security_handshaker_unref(security_handshaker* h) {
if (gpr_unref(&h->refs)) {
gpr_mu_destroy(&h->mu);
tsi_handshaker_destroy(h->handshaker);
tsi_handshaker_result_destroy(h->handshaker_result);
- if (h->endpoint_to_destroy != NULL) {
+ if (h->endpoint_to_destroy != nullptr) {
grpc_endpoint_destroy(h->endpoint_to_destroy);
}
- if (h->read_buffer_to_destroy != NULL) {
+ if (h->read_buffer_to_destroy != nullptr) {
grpc_slice_buffer_destroy_internal(h->read_buffer_to_destroy);
gpr_free(h->read_buffer_to_destroy);
}
@@ -89,11 +107,11 @@ static void security_handshaker_unref(security_handshaker* h) {
// later destruction.
static void cleanup_args_for_failure_locked(security_handshaker* h) {
h->endpoint_to_destroy = h->args->endpoint;
- h->args->endpoint = NULL;
+ h->args->endpoint = nullptr;
h->read_buffer_to_destroy = h->args->read_buffer;
- h->args->read_buffer = NULL;
+ h->args->read_buffer = nullptr;
grpc_channel_args_destroy(h->args->args);
- h->args->args = NULL;
+ h->args->args = nullptr;
}
// If the handshake failed or we're shutting down, clean up and invoke the
@@ -131,9 +149,9 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) {
return;
}
// Create zero-copy frame protector, if implemented.
- tsi_zero_copy_grpc_protector* zero_copy_protector = NULL;
+ tsi_zero_copy_grpc_protector* zero_copy_protector = nullptr;
tsi_result result = tsi_handshaker_result_create_zero_copy_grpc_protector(
- h->handshaker_result, NULL, &zero_copy_protector);
+ h->handshaker_result, nullptr, &zero_copy_protector);
if (result != TSI_OK && result != TSI_UNIMPLEMENTED) {
error = grpc_set_tsi_error_result(
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
@@ -143,10 +161,10 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) {
return;
}
// Create frame protector if zero-copy frame protector is NULL.
- tsi_frame_protector* protector = NULL;
- if (zero_copy_protector == NULL) {
+ tsi_frame_protector* protector = nullptr;
+ if (zero_copy_protector == nullptr) {
result = tsi_handshaker_result_create_frame_protector(h->handshaker_result,
- NULL, &protector);
+ nullptr, &protector);
if (result != TSI_OK) {
error = grpc_set_tsi_error_result(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Frame protector creation failed"),
@@ -156,7 +174,7 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) {
}
}
// Get unused bytes.
- const unsigned char* unused_bytes = NULL;
+ const unsigned char* unused_bytes = nullptr;
size_t unused_bytes_size = 0;
result = tsi_handshaker_result_get_unused_bytes(
h->handshaker_result, &unused_bytes, &unused_bytes_size);
@@ -169,12 +187,10 @@ static void on_peer_checked_inner(security_handshaker* h, grpc_error* error) {
grpc_slice_unref_internal(slice);
} else {
h->args->endpoint = grpc_secure_endpoint_create(
- protector, zero_copy_protector, h->args->endpoint, NULL, 0);
+ protector, zero_copy_protector, h->args->endpoint, nullptr, 0);
}
tsi_handshaker_result_destroy(h->handshaker_result);
- h->handshaker_result = NULL;
- // Clear out the read buffer before it gets passed to the transport.
- grpc_slice_buffer_reset_and_unref_internal(h->args->read_buffer);
+ h->handshaker_result = nullptr;
// Add auth context to channel args.
grpc_arg auth_context_arg = grpc_auth_context_to_arg(h->auth_context);
grpc_channel_args* tmp_args = h->args->args;
@@ -226,8 +242,8 @@ static grpc_error* on_handshake_next_done_locked(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake failed"), result);
}
// Update handshaker result.
- if (handshaker_result != NULL) {
- GPR_ASSERT(h->handshaker_result == NULL);
+ if (handshaker_result != nullptr) {
+ GPR_ASSERT(h->handshaker_result == nullptr);
h->handshaker_result = handshaker_result;
}
if (bytes_to_send_size > 0) {
@@ -238,7 +254,7 @@ static grpc_error* on_handshake_next_done_locked(
grpc_slice_buffer_add(&h->outgoing, to_send);
grpc_endpoint_write(h->args->endpoint, &h->outgoing,
&h->on_handshake_data_sent_to_peer);
- } else if (handshaker_result == NULL) {
+ } else if (handshaker_result == nullptr) {
// There is nothing to send, but need to read from peer.
grpc_endpoint_read(h->args->endpoint, h->args->read_buffer,
&h->on_handshake_data_received_from_peer);
@@ -272,9 +288,9 @@ static grpc_error* do_handshaker_next_locked(
security_handshaker* h, const unsigned char* bytes_received,
size_t bytes_received_size) {
// Invoke TSI handshaker.
- const unsigned char* bytes_to_send = NULL;
+ const unsigned char* bytes_to_send = nullptr;
size_t bytes_to_send_size = 0;
- tsi_handshaker_result* handshaker_result = NULL;
+ tsi_handshaker_result* handshaker_result = nullptr;
tsi_result result = tsi_handshaker_next(
h->handshaker, bytes_received, bytes_received_size, &bytes_to_send,
&bytes_to_send_size, &handshaker_result,
@@ -302,23 +318,7 @@ static void on_handshake_data_received_from_peer(void* arg, grpc_error* error) {
return;
}
// Copy all slices received.
- size_t i;
- size_t bytes_received_size = 0;
- for (i = 0; i < h->args->read_buffer->count; i++) {
- bytes_received_size += GRPC_SLICE_LENGTH(h->args->read_buffer->slices[i]);
- }
- if (bytes_received_size > h->handshake_buffer_size) {
- h->handshake_buffer =
- (uint8_t*)gpr_realloc(h->handshake_buffer, bytes_received_size);
- h->handshake_buffer_size = bytes_received_size;
- }
- size_t offset = 0;
- for (i = 0; i < h->args->read_buffer->count; i++) {
- size_t slice_size = GPR_SLICE_LENGTH(h->args->read_buffer->slices[i]);
- memcpy(h->handshake_buffer + offset,
- GRPC_SLICE_START_PTR(h->args->read_buffer->slices[i]), slice_size);
- offset += slice_size;
- }
+ size_t bytes_received_size = move_read_buffer_into_handshake_buffer(h);
// Call TSI handshaker.
error =
do_handshaker_next_locked(h, h->handshake_buffer, bytes_received_size);
@@ -344,7 +344,7 @@ static void on_handshake_data_sent_to_peer(void* arg, grpc_error* error) {
return;
}
// We may be done.
- if (h->handshaker_result == NULL) {
+ if (h->handshaker_result == nullptr) {
grpc_endpoint_read(h->args->endpoint, h->args->read_buffer,
&h->on_handshake_data_received_from_peer);
} else {
@@ -390,7 +390,9 @@ static void security_handshaker_do_handshake(grpc_handshaker* handshaker,
h->args = args;
h->on_handshake_done = on_handshake_done;
gpr_ref(&h->refs);
- grpc_error* error = do_handshaker_next_locked(h, NULL, 0);
+ size_t bytes_received_size = move_read_buffer_into_handshake_buffer(h);
+ grpc_error* error =
+ do_handshaker_next_locked(h, h->handshake_buffer, bytes_received_size);
if (error != GRPC_ERROR_NONE) {
security_handshake_failed_locked(h, error);
gpr_mu_unlock(&h->mu);
@@ -506,7 +508,7 @@ grpc_handshaker* grpc_security_handshaker_create(
tsi_handshaker* handshaker, grpc_security_connector* connector) {
// If no TSI handshaker was created, return a handshaker that always fails.
// Otherwise, return a real security handshaker.
- if (handshaker == NULL) {
+ if (handshaker == nullptr) {
return fail_handshaker_create();
} else {
return security_handshaker_create(handshaker, connector);
diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc
index 5f5ff7c09c..3566ddf64e 100644
--- a/src/core/lib/security/transport/server_auth_filter.cc
+++ b/src/core/lib/security/transport/server_auth_filter.cc
@@ -56,8 +56,8 @@ static grpc_metadata_array metadata_batch_to_md_array(
grpc_linked_mdelem* l;
grpc_metadata_array result;
grpc_metadata_array_init(&result);
- for (l = batch->list.head; l != NULL; l = l->next) {
- grpc_metadata* usr_md = NULL;
+ for (l = batch->list.head; l != nullptr; l = l->next) {
+ grpc_metadata* usr_md = nullptr;
grpc_mdelem md = l->md;
grpc_slice key = GRPC_MDKEY(md);
grpc_slice value = GRPC_MDVALUE(md);
@@ -96,7 +96,7 @@ static void on_md_processing_done_inner(grpc_call_element* elem,
call_data* calld = (call_data*)elem->call_data;
grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch;
/* TODO(jboeuf): Implement support for response_md. */
- if (response_md != NULL && num_response_md > 0) {
+ if (response_md != nullptr && num_response_md > 0) {
gpr_log(GPR_INFO,
"response_md in auth metadata processing not supported for now. "
"Ignoring...");
@@ -124,7 +124,7 @@ static void on_md_processing_done(
(gpr_atm)STATE_DONE)) {
grpc_error* error = GRPC_ERROR_NONE;
if (status != GRPC_STATUS_OK) {
- if (error_details == NULL) {
+ if (error_details == nullptr) {
error_details = "Authentication metadata processing failed.";
}
error = grpc_error_set_int(
@@ -150,7 +150,8 @@ static void cancel_call(void* arg, grpc_error* error) {
if (error != GRPC_ERROR_NONE &&
gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT,
(gpr_atm)STATE_CANCELLED)) {
- on_md_processing_done_inner(elem, NULL, 0, NULL, 0, GRPC_ERROR_REF(error));
+ on_md_processing_done_inner(elem, nullptr, 0, nullptr, 0,
+ GRPC_ERROR_REF(error));
}
GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_call");
}
@@ -161,7 +162,7 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) {
call_data* calld = (call_data*)elem->call_data;
grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch;
if (error == GRPC_ERROR_NONE) {
- if (chand->creds != NULL && chand->creds->processor.process != NULL) {
+ if (chand->creds != nullptr && chand->creds->processor.process != nullptr) {
// We're calling out to the application, so we need to make sure
// to drop the call combiner early if we get cancelled.
GRPC_CALL_STACK_REF(calld->owning_call, "cancel_call");
@@ -212,7 +213,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem,
grpc_server_security_context_create();
server_ctx->auth_context = grpc_auth_context_create(chand->auth_context);
calld->auth_context = server_ctx->auth_context;
- if (args->context[GRPC_CONTEXT_SECURITY].value != NULL) {
+ if (args->context[GRPC_CONTEXT_SECURITY].value != nullptr) {
args->context[GRPC_CONTEXT_SECURITY].destroy(
args->context[GRPC_CONTEXT_SECURITY].value);
}
@@ -234,7 +235,7 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
channel_data* chand = (channel_data*)elem->channel_data;
grpc_auth_context* auth_context =
grpc_find_auth_context_in_args(args->channel_args);
- GPR_ASSERT(auth_context != NULL);
+ GPR_ASSERT(auth_context != nullptr);
chand->auth_context =
GRPC_AUTH_CONTEXT_REF(auth_context, "server_auth_filter");
grpc_server_credentials* creds =