diff options
Diffstat (limited to 'src/core/lib/security/credentials')
12 files changed, 338 insertions, 338 deletions
diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc index 5eb7f9d09e..867b851dc1 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.cc +++ b/src/core/lib/security/credentials/composite/composite_credentials.cc @@ -144,9 +144,9 @@ grpc_call_credentials* grpc_composite_call_credentials_create( "grpc_composite_call_credentials_create(creds1=%p, creds2=%p, " "reserved=%p)", 3, (creds1, creds2, reserved)); - GPR_ASSERT(reserved == NULL); - GPR_ASSERT(creds1 != NULL); - GPR_ASSERT(creds2 != NULL); + GPR_ASSERT(reserved == nullptr); + GPR_ASSERT(creds1 != nullptr); + GPR_ASSERT(creds2 != nullptr); c = (grpc_composite_call_credentials*)gpr_zalloc( sizeof(grpc_composite_call_credentials)); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE; @@ -183,19 +183,19 @@ grpc_call_credentials* grpc_credentials_contains_type( grpc_call_credentials** composite_creds) { size_t i; if (strcmp(creds->type, type) == 0) { - if (composite_creds != NULL) *composite_creds = NULL; + if (composite_creds != nullptr) *composite_creds = nullptr; return creds; } else if (strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0) { const grpc_call_credentials_array* inner_creds_array = grpc_composite_call_credentials_get_credentials(creds); for (i = 0; i < inner_creds_array->num_creds; i++) { if (strcmp(type, inner_creds_array->creds_array[i]->type) == 0) { - if (composite_creds != NULL) *composite_creds = creds; + if (composite_creds != nullptr) *composite_creds = creds; return inner_creds_array->creds_array[i]; } } } - return NULL; + return nullptr; } /* -- Composite channel credentials. -- */ @@ -217,14 +217,14 @@ static grpc_security_status composite_channel_create_security_connector( (grpc_composite_channel_credentials*)creds; grpc_security_status status = GRPC_SECURITY_ERROR; - GPR_ASSERT(c->inner_creds != NULL && c->call_creds != NULL && - c->inner_creds->vtable != NULL && - c->inner_creds->vtable->create_security_connector != NULL); + GPR_ASSERT(c->inner_creds != nullptr && c->call_creds != nullptr && + c->inner_creds->vtable != nullptr && + c->inner_creds->vtable->create_security_connector != nullptr); /* If we are passed a call_creds, create a call composite to pass it downstream. */ - if (call_creds != NULL) { + if (call_creds != nullptr) { grpc_call_credentials* composite_call_creds = - grpc_composite_call_credentials_create(c->call_creds, call_creds, NULL); + grpc_composite_call_credentials_create(c->call_creds, call_creds, nullptr); status = c->inner_creds->vtable->create_security_connector( exec_ctx, c->inner_creds, composite_call_creds, target, args, sc, new_args); @@ -253,7 +253,7 @@ grpc_channel_credentials* grpc_composite_channel_credentials_create( void* reserved) { grpc_composite_channel_credentials* c = (grpc_composite_channel_credentials*)gpr_zalloc(sizeof(*c)); - GPR_ASSERT(channel_creds != NULL && call_creds != NULL && reserved == NULL); + GPR_ASSERT(channel_creds != nullptr && call_creds != nullptr && reserved == nullptr); GRPC_API_TRACE( "grpc_composite_channel_credentials_create(channel_creds=%p, " "call_creds=%p, reserved=%p)", diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index e60d022f1b..b29abdc6aa 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -55,16 +55,16 @@ void grpc_credentials_metadata_request_destroy( grpc_channel_credentials* grpc_channel_credentials_ref( grpc_channel_credentials* creds) { - if (creds == NULL) return NULL; + if (creds == nullptr) return nullptr; gpr_ref(&creds->refcount); return creds; } void grpc_channel_credentials_unref(grpc_exec_ctx* exec_ctx, grpc_channel_credentials* creds) { - if (creds == NULL) return; + if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { - if (creds->vtable->destruct != NULL) { + if (creds->vtable->destruct != nullptr) { creds->vtable->destruct(exec_ctx, creds); } gpr_free(creds); @@ -79,16 +79,16 @@ void grpc_channel_credentials_release(grpc_channel_credentials* creds) { } grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds) { - if (creds == NULL) return NULL; + if (creds == nullptr) return nullptr; gpr_ref(&creds->refcount); return creds; } void grpc_call_credentials_unref(grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds) { - if (creds == NULL) return; + if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { - if (creds->vtable->destruct != NULL) { + if (creds->vtable->destruct != nullptr) { creds->vtable->destruct(exec_ctx, creds); } gpr_free(creds); @@ -107,7 +107,7 @@ bool grpc_call_credentials_get_request_metadata( grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - if (creds == NULL || creds->vtable->get_request_metadata == NULL) { + if (creds == nullptr || creds->vtable->get_request_metadata == nullptr) { return true; } return creds->vtable->get_request_metadata( @@ -117,7 +117,7 @@ bool grpc_call_credentials_get_request_metadata( void grpc_call_credentials_cancel_get_request_metadata( grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_error* error) { - if (creds == NULL || creds->vtable->cancel_get_request_metadata == NULL) { + if (creds == nullptr || creds->vtable->cancel_get_request_metadata == nullptr) { return; } creds->vtable->cancel_get_request_metadata(exec_ctx, creds, md_array, error); @@ -127,20 +127,20 @@ grpc_security_status grpc_channel_credentials_create_security_connector( grpc_exec_ctx* exec_ctx, grpc_channel_credentials* channel_creds, const char* target, const grpc_channel_args* args, grpc_channel_security_connector** sc, grpc_channel_args** new_args) { - *new_args = NULL; - if (channel_creds == NULL) { + *new_args = nullptr; + if (channel_creds == nullptr) { return GRPC_SECURITY_ERROR; } - GPR_ASSERT(channel_creds->vtable->create_security_connector != NULL); + GPR_ASSERT(channel_creds->vtable->create_security_connector != nullptr); return channel_creds->vtable->create_security_connector( - exec_ctx, channel_creds, NULL, target, args, sc, new_args); + exec_ctx, channel_creds, nullptr, target, args, sc, new_args); } grpc_channel_credentials* grpc_channel_credentials_duplicate_without_call_credentials( grpc_channel_credentials* channel_creds) { - if (channel_creds != NULL && channel_creds->vtable != NULL && - channel_creds->vtable->duplicate_without_call_credentials != NULL) { + if (channel_creds != nullptr && channel_creds->vtable != nullptr && + channel_creds->vtable->duplicate_without_call_credentials != nullptr) { return channel_creds->vtable->duplicate_without_call_credentials( channel_creds); } else { @@ -171,11 +171,11 @@ grpc_arg grpc_channel_credentials_to_arg( grpc_channel_credentials* grpc_channel_credentials_from_arg( const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_ARG_CHANNEL_CREDENTIALS)) return NULL; + if (strcmp(arg->key, GRPC_ARG_CHANNEL_CREDENTIALS)) return nullptr; if (arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, GRPC_ARG_CHANNEL_CREDENTIALS); - return NULL; + return nullptr; } return (grpc_channel_credentials*)arg->value.pointer.p; } @@ -183,30 +183,30 @@ grpc_channel_credentials* grpc_channel_credentials_from_arg( grpc_channel_credentials* grpc_channel_credentials_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_channel_credentials* credentials = grpc_channel_credentials_from_arg(&args->args[i]); - if (credentials != NULL) return credentials; + if (credentials != nullptr) return credentials; } - return NULL; + return nullptr; } grpc_server_credentials* grpc_server_credentials_ref( grpc_server_credentials* creds) { - if (creds == NULL) return NULL; + if (creds == nullptr) return nullptr; gpr_ref(&creds->refcount); return creds; } void grpc_server_credentials_unref(grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds) { - if (creds == NULL) return; + if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { - if (creds->vtable->destruct != NULL) { + if (creds->vtable->destruct != nullptr) { creds->vtable->destruct(exec_ctx, creds); } - if (creds->processor.destroy != NULL && creds->processor.state != NULL) { + if (creds->processor.destroy != nullptr && creds->processor.state != nullptr) { creds->processor.destroy(creds->processor.state); } gpr_free(creds); @@ -223,7 +223,7 @@ void grpc_server_credentials_release(grpc_server_credentials* creds) { grpc_security_status grpc_server_credentials_create_security_connector( grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds, grpc_server_security_connector** sc) { - if (creds == NULL || creds->vtable->create_security_connector == NULL) { + if (creds == nullptr || creds->vtable->create_security_connector == nullptr) { gpr_log(GPR_ERROR, "Server credentials cannot create security context."); return GRPC_SECURITY_ERROR; } @@ -237,8 +237,8 @@ void grpc_server_credentials_set_auth_metadata_processor( "creds=%p, " "processor=grpc_auth_metadata_processor { process: %p, state: %p })", 3, (creds, (void*)(intptr_t)processor.process, processor.state)); - if (creds == NULL) return; - if (creds->processor.destroy != NULL && creds->processor.state != NULL) { + if (creds == nullptr) return; + if (creds->processor.destroy != nullptr && creds->processor.state != nullptr) { creds->processor.destroy(creds->processor.state); } creds->processor = processor; @@ -267,11 +267,11 @@ grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials* p) { } grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_SERVER_CREDENTIALS_ARG) != 0) return NULL; + if (strcmp(arg->key, GRPC_SERVER_CREDENTIALS_ARG) != 0) return nullptr; if (arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, GRPC_SERVER_CREDENTIALS_ARG); - return NULL; + return nullptr; } return (grpc_server_credentials*)arg->value.pointer.p; } @@ -279,11 +279,11 @@ grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) { grpc_server_credentials* grpc_find_server_credentials_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_server_credentials* p = grpc_server_credentials_from_arg(&args->args[i]); - if (p != NULL) return p; + if (p != nullptr) return p; } - return NULL; + return nullptr; } diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc index 17700f5651..a535a317ee 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.cc +++ b/src/core/lib/security/credentials/fake/fake_credentials.cc @@ -53,11 +53,11 @@ fake_transport_security_server_create_security_connector( static grpc_channel_credentials_vtable fake_transport_security_credentials_vtable = { - NULL, fake_transport_security_create_security_connector, NULL}; + nullptr, fake_transport_security_create_security_connector, nullptr}; static grpc_server_credentials_vtable fake_transport_security_server_credentials_vtable = { - NULL, fake_transport_security_server_create_security_connector}; + nullptr, fake_transport_security_server_create_security_connector}; grpc_channel_credentials* grpc_fake_transport_security_credentials_create( void) { @@ -89,11 +89,11 @@ const char* grpc_fake_transport_get_expected_targets( const grpc_channel_args* args) { const grpc_arg* expected_target_arg = grpc_channel_args_find(args, GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS); - if (expected_target_arg != NULL && + if (expected_target_arg != nullptr && expected_target_arg->type == GRPC_ARG_STRING) { return expected_target_arg->value.string; } - return NULL; + return nullptr; } /* -- Metadata-only test credentials. -- */ diff --git a/src/core/lib/security/credentials/google_default/credentials_generic.cc b/src/core/lib/security/credentials/google_default/credentials_generic.cc index c2a336ff07..58ee080cf3 100644 --- a/src/core/lib/security/credentials/google_default/credentials_generic.cc +++ b/src/core/lib/security/credentials/google_default/credentials_generic.cc @@ -26,12 +26,12 @@ #include "src/core/lib/support/string.h" char* grpc_get_well_known_google_credentials_file_path_impl(void) { - char* result = NULL; + char* result = nullptr; char* base = gpr_getenv(GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR); - if (base == NULL) { + if (base == nullptr) { gpr_log(GPR_ERROR, "Could not get " GRPC_GOOGLE_CREDENTIALS_ENV_VAR " environment variable."); - return NULL; + return nullptr; } gpr_asprintf(&result, "%s/%s", base, GRPC_GOOGLE_CREDENTIALS_PATH_SUFFIX); gpr_free(base); diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index 3ce19e9a05..b4df1dc116 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -43,7 +43,7 @@ /* -- Default credentials. -- */ -static grpc_channel_credentials* default_credentials = NULL; +static grpc_channel_credentials* default_credentials = nullptr; static int compute_engine_detection_done = 0; static gpr_mu g_state_mu; static gpr_mu* g_polling_mu; @@ -81,7 +81,7 @@ static void on_compute_engine_detection_http_response(grpc_exec_ctx* exec_ctx, GRPC_LOG_IF_ERROR( "Pollset kick", grpc_pollset_kick(exec_ctx, - grpc_polling_entity_pollset(&detector->pollent), NULL)); + grpc_polling_entity_pollset(&detector->pollent), nullptr)); gpr_mu_unlock(g_polling_mu); } @@ -128,7 +128,7 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { called once for the lifetime of the process by the default credentials. */ gpr_mu_lock(g_polling_mu); while (!detector.is_done) { - grpc_pollset_worker* worker = NULL; + grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(exec_ctx, @@ -147,7 +147,7 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { grpc_pollset_shutdown(exec_ctx, grpc_polling_entity_pollset(&detector.pollent), &destroy_closure); - g_polling_mu = NULL; + g_polling_mu = nullptr; grpc_exec_ctx_flush(exec_ctx); gpr_free(grpc_polling_entity_pollset(&detector.pollent)); @@ -159,13 +159,13 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { /* Takes ownership of creds_path if not NULL. */ static grpc_error* create_default_creds_from_path( grpc_exec_ctx* exec_ctx, char* creds_path, grpc_call_credentials** creds) { - grpc_json* json = NULL; + grpc_json* json = nullptr; grpc_auth_json_key key; grpc_auth_refresh_token token; - grpc_call_credentials* result = NULL; + grpc_call_credentials* result = nullptr; grpc_slice creds_data = grpc_empty_slice(); grpc_error* error = GRPC_ERROR_NONE; - if (creds_path == NULL) { + if (creds_path == nullptr) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("creds_path unset"); goto end; } @@ -175,7 +175,7 @@ static grpc_error* create_default_creds_from_path( } json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data)); - if (json == NULL) { + if (json == nullptr) { error = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to parse JSON"), GRPC_ERROR_STR_RAW_BYTES, grpc_slice_ref_internal(creds_data)); @@ -188,7 +188,7 @@ static grpc_error* create_default_creds_from_path( result = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( exec_ctx, key, grpc_max_auth_token_lifetime()); - if (result == NULL) { + if (result == nullptr) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "grpc_service_account_jwt_access_credentials_create_from_auth_json_" "key failed"); @@ -201,7 +201,7 @@ static grpc_error* create_default_creds_from_path( if (grpc_auth_refresh_token_is_valid(&token)) { result = grpc_refresh_token_credentials_create_from_auth_refresh_token(token); - if (result == NULL) { + if (result == nullptr) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "grpc_refresh_token_credentials_create_from_auth_refresh_token " "failed"); @@ -210,17 +210,17 @@ static grpc_error* create_default_creds_from_path( } end: - GPR_ASSERT((result == NULL) + (error == GRPC_ERROR_NONE) == 1); - if (creds_path != NULL) gpr_free(creds_path); + GPR_ASSERT((result == nullptr) + (error == GRPC_ERROR_NONE) == 1); + if (creds_path != nullptr) gpr_free(creds_path); grpc_slice_unref_internal(exec_ctx, creds_data); - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); *creds = result; return error; } grpc_channel_credentials* grpc_google_default_credentials_create(void) { - grpc_channel_credentials* result = NULL; - grpc_call_credentials* call_creds = NULL; + grpc_channel_credentials* result = nullptr; + grpc_call_credentials* call_creds = nullptr; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to create Google credentials"); grpc_error* err; @@ -232,7 +232,7 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { gpr_mu_lock(&g_state_mu); - if (default_credentials != NULL) { + if (default_credentials != nullptr) { result = grpc_channel_credentials_ref(default_credentials); goto end; } @@ -257,8 +257,8 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { is_stack_running_on_compute_engine(&exec_ctx); compute_engine_detection_done = 1; if (need_compute_engine_creds) { - call_creds = grpc_google_compute_engine_credentials_create(NULL); - if (call_creds == NULL) { + call_creds = grpc_google_compute_engine_credentials_create(nullptr); + if (call_creds == nullptr) { error = grpc_error_add_child( error, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to get credentials from network")); @@ -267,17 +267,17 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { } end: - if (result == NULL) { - if (call_creds != NULL) { + if (result == nullptr) { + if (call_creds != nullptr) { /* Blend with default ssl credentials and add a global reference so that it can be cached and re-served. */ grpc_channel_credentials* ssl_creds = - grpc_ssl_credentials_create(NULL, NULL, NULL); + grpc_ssl_credentials_create(nullptr, nullptr, nullptr); default_credentials = grpc_channel_credentials_ref( grpc_composite_channel_credentials_create(ssl_creds, call_creds, - NULL)); - GPR_ASSERT(default_credentials != NULL); + nullptr)); + GPR_ASSERT(default_credentials != nullptr); grpc_channel_credentials_unref(&exec_ctx, ssl_creds); grpc_call_credentials_unref(&exec_ctx, call_creds); result = default_credentials; @@ -286,7 +286,7 @@ end: } } gpr_mu_unlock(&g_state_mu); - if (result == NULL) { + if (result == nullptr) { GRPC_LOG_IF_ERROR("grpc_google_default_credentials_create", error); } else { GRPC_ERROR_UNREF(error); @@ -299,9 +299,9 @@ void grpc_flush_cached_google_default_credentials(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_once_init(&g_once, init_default_credentials); gpr_mu_lock(&g_state_mu); - if (default_credentials != NULL) { + if (default_credentials != nullptr) { grpc_channel_credentials_unref(&exec_ctx, default_credentials); - default_credentials = NULL; + default_credentials = nullptr; } compute_engine_detection_done = 0; gpr_mu_unlock(&g_state_mu); @@ -310,10 +310,10 @@ void grpc_flush_cached_google_default_credentials(void) { /* -- Well known credentials path. -- */ -static grpc_well_known_credentials_path_getter creds_path_getter = NULL; +static grpc_well_known_credentials_path_getter creds_path_getter = nullptr; char* grpc_get_well_known_google_credentials_file_path(void) { - if (creds_path_getter != NULL) return creds_path_getter(); + if (creds_path_getter != nullptr) return creds_path_getter(); return grpc_get_well_known_google_credentials_file_path_impl(); } diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 7410294a20..1741bf3068 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -61,9 +61,9 @@ grpc_call_credentials* grpc_google_iam_credentials_create( "grpc_iam_credentials_create(token=%s, authority_selector=%s, " "reserved=%p)", 3, (token, authority_selector, reserved)); - GPR_ASSERT(reserved == NULL); - GPR_ASSERT(token != NULL); - GPR_ASSERT(authority_selector != NULL); + GPR_ASSERT(reserved == nullptr); + GPR_ASSERT(token != nullptr); + GPR_ASSERT(authority_selector != nullptr); grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)gpr_zalloc(sizeof(*c)); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_IAM; diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc index e195ec7509..07807201ce 100644 --- a/src/core/lib/security/credentials/jwt/json_token.cc +++ b/src/core/lib/security/credentials/jwt/json_token.cc @@ -52,30 +52,30 @@ gpr_timespec grpc_max_auth_token_lifetime() { /* --- Override for testing. --- */ -static grpc_jwt_encode_and_sign_override g_jwt_encode_and_sign_override = NULL; +static grpc_jwt_encode_and_sign_override g_jwt_encode_and_sign_override = nullptr; /* --- grpc_auth_json_key. --- */ int grpc_auth_json_key_is_valid(const grpc_auth_json_key* json_key) { - return (json_key != NULL) && + return (json_key != nullptr) && strcmp(json_key->type, GRPC_AUTH_JSON_TYPE_INVALID); } grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) { grpc_auth_json_key result; - BIO* bio = NULL; + BIO* bio = nullptr; const char* prop_value; int success = 0; memset(&result, 0, sizeof(grpc_auth_json_key)); result.type = GRPC_AUTH_JSON_TYPE_INVALID; - if (json == NULL) { + if (json == nullptr) { gpr_log(GPR_ERROR, "Invalid json."); goto end; } prop_value = grpc_json_get_string_property(json, "type"); - if (prop_value == NULL || + if (prop_value == nullptr || strcmp(prop_value, GRPC_AUTH_JSON_TYPE_SERVICE_ACCOUNT)) { goto end; } @@ -90,7 +90,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) { } prop_value = grpc_json_get_string_property(json, "private_key"); - if (prop_value == NULL) { + if (prop_value == nullptr) { goto end; } bio = BIO_new(BIO_s_mem()); @@ -99,15 +99,15 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) { gpr_log(GPR_ERROR, "Could not write into openssl BIO."); goto end; } - result.private_key = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, (void*)""); - if (result.private_key == NULL) { + result.private_key = PEM_read_bio_RSAPrivateKey(bio, nullptr, nullptr, (void*)""); + if (result.private_key == nullptr) { gpr_log(GPR_ERROR, "Could not deserialize private key."); goto end; } success = 1; end: - if (bio != NULL) BIO_free(bio); + if (bio != nullptr) BIO_free(bio); if (!success) grpc_auth_json_key_destruct(&result); return result; } @@ -117,29 +117,29 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string( char* scratchpad = gpr_strdup(json_string); grpc_json* json = grpc_json_parse_string(scratchpad); grpc_auth_json_key result = grpc_auth_json_key_create_from_json(json); - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); gpr_free(scratchpad); return result; } void grpc_auth_json_key_destruct(grpc_auth_json_key* json_key) { - if (json_key == NULL) return; + if (json_key == nullptr) return; json_key->type = GRPC_AUTH_JSON_TYPE_INVALID; - if (json_key->client_id != NULL) { + if (json_key->client_id != nullptr) { gpr_free(json_key->client_id); - json_key->client_id = NULL; + json_key->client_id = nullptr; } - if (json_key->private_key_id != NULL) { + if (json_key->private_key_id != nullptr) { gpr_free(json_key->private_key_id); - json_key->private_key_id = NULL; + json_key->private_key_id = nullptr; } - if (json_key->client_email != NULL) { + if (json_key->client_email != nullptr) { gpr_free(json_key->client_email); - json_key->client_email = NULL; + json_key->client_email = nullptr; } - if (json_key->private_key != NULL) { + if (json_key->private_key != nullptr) { RSA_free(json_key->private_key); - json_key->private_key = NULL; + json_key->private_key = nullptr; } } @@ -159,11 +159,11 @@ static grpc_json* create_child(grpc_json* brother, grpc_json* parent, static char* encoded_jwt_header(const char* key_id, const char* algorithm) { grpc_json* json = grpc_json_create(GRPC_JSON_OBJECT); - grpc_json* child = NULL; - char* json_str = NULL; - char* result = NULL; + grpc_json* child = nullptr; + char* json_str = nullptr; + char* result = nullptr; - child = create_child(NULL, json, "alg", algorithm, GRPC_JSON_STRING); + child = create_child(nullptr, json, "alg", algorithm, GRPC_JSON_STRING); child = create_child(child, json, "typ", GRPC_JWT_TYPE, GRPC_JSON_STRING); create_child(child, json, "kid", key_id, GRPC_JSON_STRING); @@ -178,9 +178,9 @@ static char* encoded_jwt_claim(const grpc_auth_json_key* json_key, const char* audience, gpr_timespec token_lifetime, const char* scope) { grpc_json* json = grpc_json_create(GRPC_JSON_OBJECT); - grpc_json* child = NULL; - char* json_str = NULL; - char* result = NULL; + grpc_json* child = nullptr; + char* json_str = nullptr; + char* result = nullptr; gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec expiration = gpr_time_add(now, token_lifetime); char now_str[GPR_LTOA_MIN_BUFSIZE]; @@ -193,8 +193,8 @@ static char* encoded_jwt_claim(const grpc_auth_json_key* json_key, int64_ttoa(expiration.tv_sec, expiration_str); child = - create_child(NULL, json, "iss", json_key->client_email, GRPC_JSON_STRING); - if (scope != NULL) { + create_child(nullptr, json, "iss", json_key->client_email, GRPC_JSON_STRING); + if (scope != nullptr) { child = create_child(child, json, "scope", scope, GRPC_JSON_STRING); } else { /* Unscoped JWTs need a sub field. */ @@ -237,7 +237,7 @@ const EVP_MD* openssl_digest_from_algorithm(const char* algorithm) { return EVP_sha256(); } else { gpr_log(GPR_ERROR, "Unknown algorithm %s.", algorithm); - return NULL; + return nullptr; } } @@ -245,19 +245,19 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, const char* signature_algorithm, const char* to_sign) { const EVP_MD* md = openssl_digest_from_algorithm(signature_algorithm); - EVP_MD_CTX* md_ctx = NULL; + EVP_MD_CTX* md_ctx = nullptr; EVP_PKEY* key = EVP_PKEY_new(); size_t sig_len = 0; - unsigned char* sig = NULL; - char* result = NULL; - if (md == NULL) return NULL; + unsigned char* sig = nullptr; + char* result = nullptr; + if (md == nullptr) return nullptr; md_ctx = EVP_MD_CTX_create(); - if (md_ctx == NULL) { + if (md_ctx == nullptr) { gpr_log(GPR_ERROR, "Could not create MD_CTX"); goto end; } EVP_PKEY_set1_RSA(key, json_key->private_key); - if (EVP_DigestSignInit(md_ctx, NULL, md, NULL, key) != 1) { + if (EVP_DigestSignInit(md_ctx, nullptr, md, nullptr, key) != 1) { gpr_log(GPR_ERROR, "DigestInit failed."); goto end; } @@ -265,7 +265,7 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, gpr_log(GPR_ERROR, "DigestUpdate failed."); goto end; } - if (EVP_DigestSignFinal(md_ctx, NULL, &sig_len) != 1) { + if (EVP_DigestSignFinal(md_ctx, nullptr, &sig_len) != 1) { gpr_log(GPR_ERROR, "DigestFinal (get signature length) failed."); goto end; } @@ -277,16 +277,16 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, result = grpc_base64_encode(sig, sig_len, 1, 0); end: - if (key != NULL) EVP_PKEY_free(key); - if (md_ctx != NULL) EVP_MD_CTX_destroy(md_ctx); - if (sig != NULL) gpr_free(sig); + if (key != nullptr) EVP_PKEY_free(key); + if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx); + if (sig != nullptr) gpr_free(sig); return result; } char* grpc_jwt_encode_and_sign(const grpc_auth_json_key* json_key, const char* audience, gpr_timespec token_lifetime, const char* scope) { - if (g_jwt_encode_and_sign_override != NULL) { + if (g_jwt_encode_and_sign_override != nullptr) { return g_jwt_encode_and_sign_override(json_key, audience, token_lifetime, scope); } else { @@ -295,9 +295,9 @@ char* grpc_jwt_encode_and_sign(const grpc_auth_json_key* json_key, encoded_jwt_header(json_key->private_key_id, sig_algo), encoded_jwt_claim(json_key, audience, token_lifetime, scope)); char* sig = compute_and_encode_signature(json_key, sig_algo, to_sign); - if (sig == NULL) { + if (sig == nullptr) { gpr_free(to_sign); - return NULL; + return nullptr; } return dot_concat_and_free_strings(to_sign, sig); } diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index e8baa7e053..d666e6b658 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -34,9 +34,9 @@ static void jwt_reset_cache(grpc_exec_ctx* exec_ctx, grpc_service_account_jwt_access_credentials* c) { GRPC_MDELEM_UNREF(exec_ctx, c->cached.jwt_md); c->cached.jwt_md = GRPC_MDNULL; - if (c->cached.service_url != NULL) { + if (c->cached.service_url != nullptr) { gpr_free(c->cached.service_url); - c->cached.service_url = NULL; + c->cached.service_url = nullptr; } c->cached.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME); } @@ -66,7 +66,7 @@ static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, grpc_mdelem jwt_md = GRPC_MDNULL; { gpr_mu_lock(&c->cache_mu); - if (c->cached.service_url != NULL && + if (c->cached.service_url != nullptr && strcmp(c->cached.service_url, context.service_url) == 0 && !GRPC_MDISNULL(c->cached.jwt_md) && (gpr_time_cmp(gpr_time_sub(c->cached.jwt_expiration, @@ -78,13 +78,13 @@ static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, } if (GRPC_MDISNULL(jwt_md)) { - char* jwt = NULL; + char* jwt = nullptr; /* Generate a new jwt. */ gpr_mu_lock(&c->cache_mu); jwt_reset_cache(exec_ctx, c); jwt = grpc_jwt_encode_and_sign(&c->key, context.service_url, - c->jwt_lifetime, NULL); - if (jwt != NULL) { + c->jwt_lifetime, nullptr); + if (jwt != nullptr) { char* md_value; gpr_asprintf(&md_value, "Bearer %s", jwt); gpr_free(jwt); @@ -126,7 +126,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_service_account_jwt_access_credentials* c; if (!grpc_auth_json_key_is_valid(&key)) { gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation"); - return NULL; + return nullptr; } c = (grpc_service_account_jwt_access_credentials*)gpr_zalloc( sizeof(grpc_service_account_jwt_access_credentials)); @@ -185,7 +185,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create( (int)token_lifetime.clock_type, reserved); gpr_free(clean_json); } - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call_credentials* creds = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 0fce5f5555..105178ff4c 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -70,7 +70,7 @@ static const EVP_MD* evp_md_from_alg(const char* alg) { } else if (strcmp(alg, "RS512") == 0) { return EVP_sha512(); } else { - return NULL; + return nullptr; } } @@ -82,11 +82,11 @@ static grpc_json* parse_json_part_from_jwt(grpc_exec_ctx* exec_ctx, *buffer = grpc_base64_decode_with_len(exec_ctx, str, len, 1); if (GRPC_SLICE_IS_EMPTY(*buffer)) { gpr_log(GPR_ERROR, "Invalid base64."); - return NULL; + return nullptr; } json = grpc_json_parse_string_with_len((char*)GRPC_SLICE_START_PTR(*buffer), GRPC_SLICE_LENGTH(*buffer)); - if (json == NULL) { + if (json == nullptr) { grpc_slice_unref_internal(exec_ctx, *buffer); gpr_log(GPR_ERROR, "JSON parsing error."); } @@ -97,7 +97,7 @@ static const char* validate_string_field(const grpc_json* json, const char* key) { if (json->type != GRPC_JSON_STRING) { gpr_log(GPR_ERROR, "Invalid %s field [%s]", key, json->value); - return NULL; + return nullptr; } return json->value; } @@ -109,7 +109,7 @@ static gpr_timespec validate_time_field(const grpc_json* json, gpr_log(GPR_ERROR, "Invalid %s field [%s]", key, json->value); return result; } - result.tv_sec = strtol(json->value, NULL, 10); + result.tv_sec = strtol(json->value, nullptr, 10); return result; } @@ -134,27 +134,27 @@ static jose_header* jose_header_from_json(grpc_exec_ctx* exec_ctx, grpc_json* cur; jose_header* h = (jose_header*)gpr_zalloc(sizeof(jose_header)); h->buffer = buffer; - for (cur = json->child; cur != NULL; cur = cur->next) { + for (cur = json->child; cur != nullptr; cur = cur->next) { if (strcmp(cur->key, "alg") == 0) { /* We only support RSA-1.5 signatures for now. Beware of this if we add HMAC support: https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/ */ if (cur->type != GRPC_JSON_STRING || strncmp(cur->value, "RS", 2) || - evp_md_from_alg(cur->value) == NULL) { + evp_md_from_alg(cur->value) == nullptr) { gpr_log(GPR_ERROR, "Invalid alg field [%s]", cur->value); goto error; } h->alg = cur->value; } else if (strcmp(cur->key, "typ") == 0) { h->typ = validate_string_field(cur, "typ"); - if (h->typ == NULL) goto error; + if (h->typ == nullptr) goto error; } else if (strcmp(cur->key, "kid") == 0) { h->kid = validate_string_field(cur, "kid"); - if (h->kid == NULL) goto error; + if (h->kid == nullptr) goto error; } } - if (h->alg == NULL) { + if (h->alg == nullptr) { gpr_log(GPR_ERROR, "Missing alg field."); goto error; } @@ -165,7 +165,7 @@ static jose_header* jose_header_from_json(grpc_exec_ctx* exec_ctx, error: grpc_json_destroy(json); jose_header_destroy(exec_ctx, h); - return NULL; + return nullptr; } /* --- JWT claims. see http://tools.ietf.org/html/rfc7519#section-4.1 */ @@ -191,42 +191,42 @@ void grpc_jwt_claims_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_claims* claims) { } const grpc_json* grpc_jwt_claims_json(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->json; } const char* grpc_jwt_claims_subject(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->sub; } const char* grpc_jwt_claims_issuer(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->iss; } const char* grpc_jwt_claims_id(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->jti; } const char* grpc_jwt_claims_audience(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->aud; } gpr_timespec grpc_jwt_claims_issued_at(const grpc_jwt_claims* claims) { - if (claims == NULL) return gpr_inf_past(GPR_CLOCK_REALTIME); + if (claims == nullptr) return gpr_inf_past(GPR_CLOCK_REALTIME); return claims->iat; } gpr_timespec grpc_jwt_claims_expires_at(const grpc_jwt_claims* claims) { - if (claims == NULL) return gpr_inf_future(GPR_CLOCK_REALTIME); + if (claims == nullptr) return gpr_inf_future(GPR_CLOCK_REALTIME); return claims->exp; } gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims* claims) { - if (claims == NULL) return gpr_inf_past(GPR_CLOCK_REALTIME); + if (claims == nullptr) return gpr_inf_past(GPR_CLOCK_REALTIME); return claims->nbf; } @@ -244,19 +244,19 @@ grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, claims->exp = gpr_inf_future(GPR_CLOCK_REALTIME); /* Per the spec, all fields are optional. */ - for (cur = json->child; cur != NULL; cur = cur->next) { + for (cur = json->child; cur != nullptr; cur = cur->next) { if (strcmp(cur->key, "sub") == 0) { claims->sub = validate_string_field(cur, "sub"); - if (claims->sub == NULL) goto error; + if (claims->sub == nullptr) goto error; } else if (strcmp(cur->key, "iss") == 0) { claims->iss = validate_string_field(cur, "iss"); - if (claims->iss == NULL) goto error; + if (claims->iss == nullptr) goto error; } else if (strcmp(cur->key, "aud") == 0) { claims->aud = validate_string_field(cur, "aud"); - if (claims->aud == NULL) goto error; + if (claims->aud == nullptr) goto error; } else if (strcmp(cur->key, "jti") == 0) { claims->jti = validate_string_field(cur, "jti"); - if (claims->jti == NULL) goto error; + if (claims->jti == nullptr) goto error; } else if (strcmp(cur->key, "iat") == 0) { claims->iat = validate_time_field(cur, "iat"); if (gpr_time_cmp(claims->iat, gpr_time_0(GPR_CLOCK_REALTIME)) == 0) @@ -275,7 +275,7 @@ grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, error: grpc_jwt_claims_destroy(exec_ctx, claims); - return NULL; + return nullptr; } grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, @@ -283,7 +283,7 @@ grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, gpr_timespec skewed_now; int audience_ok; - GPR_ASSERT(claims != NULL); + GPR_ASSERT(claims != nullptr); skewed_now = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_clock_skew); @@ -301,23 +301,23 @@ grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, /* This should be probably up to the upper layer to decide but let's harcode the 99% use case here for email issuers, where the JWT must be self issued. */ - if (grpc_jwt_issuer_email_domain(claims->iss) != NULL && - claims->sub != NULL && strcmp(claims->iss, claims->sub) != 0) { + if (grpc_jwt_issuer_email_domain(claims->iss) != nullptr && + claims->sub != nullptr && strcmp(claims->iss, claims->sub) != 0) { gpr_log(GPR_ERROR, "Email issuer (%s) cannot assert another subject (%s) than itself.", claims->iss, claims->sub); return GRPC_JWT_VERIFIER_BAD_SUBJECT; } - if (audience == NULL) { - audience_ok = claims->aud == NULL; + if (audience == nullptr) { + audience_ok = claims->aud == nullptr; } else { - audience_ok = claims->aud != NULL && strcmp(audience, claims->aud) == 0; + audience_ok = claims->aud != nullptr && strcmp(audience, claims->aud) == 0; } if (!audience_ok) { gpr_log(GPR_ERROR, "Audience mismatch: expected %s and found %s.", - audience == NULL ? "NULL" : audience, - claims->aud == NULL ? "NULL" : claims->aud); + audience == nullptr ? "NULL" : audience, + claims->aud == nullptr ? "NULL" : claims->aud); return GRPC_JWT_VERIFIER_BAD_AUDIENCE; } return GRPC_JWT_VERIFIER_OK; @@ -366,8 +366,8 @@ static verifier_cb_ctx* verifier_cb_ctx_create( } void verifier_cb_ctx_destroy(grpc_exec_ctx* exec_ctx, verifier_cb_ctx* ctx) { - if (ctx->audience != NULL) gpr_free(ctx->audience); - if (ctx->claims != NULL) grpc_jwt_claims_destroy(exec_ctx, ctx->claims); + if (ctx->audience != nullptr) gpr_free(ctx->audience); + if (ctx->claims != nullptr) grpc_jwt_claims_destroy(exec_ctx, ctx->claims); grpc_slice_unref_internal(exec_ctx, ctx->signature); grpc_slice_unref_internal(exec_ctx, ctx->signed_data); jose_header_destroy(exec_ctx, ctx->header); @@ -399,20 +399,20 @@ struct grpc_jwt_verifier { }; static grpc_json* json_from_http(const grpc_httpcli_response* response) { - grpc_json* json = NULL; + grpc_json* json = nullptr; - if (response == NULL) { + if (response == nullptr) { gpr_log(GPR_ERROR, "HTTP response is NULL."); - return NULL; + return nullptr; } if (response->status != 200) { gpr_log(GPR_ERROR, "Call to http server failed with error %d.", response->status); - return NULL; + return nullptr; } json = grpc_json_parse_string_with_len(response->body, response->body_length); - if (json == NULL) { + if (json == nullptr) { gpr_log(GPR_ERROR, "Invalid JSON found in response."); } return json; @@ -421,26 +421,26 @@ static grpc_json* json_from_http(const grpc_httpcli_response* response) { static const grpc_json* find_property_by_name(const grpc_json* json, const char* name) { const grpc_json* cur; - for (cur = json->child; cur != NULL; cur = cur->next) { + for (cur = json->child; cur != nullptr; cur = cur->next) { if (strcmp(cur->key, name) == 0) return cur; } - return NULL; + return nullptr; } static EVP_PKEY* extract_pkey_from_x509(const char* x509_str) { - X509* x509 = NULL; - EVP_PKEY* result = NULL; + X509* x509 = nullptr; + EVP_PKEY* result = nullptr; BIO* bio = BIO_new(BIO_s_mem()); size_t len = strlen(x509_str); GPR_ASSERT(len < INT_MAX); BIO_write(bio, x509_str, (int)len); - x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL); - if (x509 == NULL) { + x509 = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr); + if (x509 == nullptr) { gpr_log(GPR_ERROR, "Unable to parse x509 cert."); goto end; } result = X509_get_pubkey(x509); - if (result == NULL) { + if (result == nullptr) { gpr_log(GPR_ERROR, "Cannot find public key in X509 cert."); } @@ -451,17 +451,17 @@ end: } static BIGNUM* bignum_from_base64(grpc_exec_ctx* exec_ctx, const char* b64) { - BIGNUM* result = NULL; + BIGNUM* result = nullptr; grpc_slice bin; - if (b64 == NULL) return NULL; + if (b64 == nullptr) return nullptr; bin = grpc_base64_decode(exec_ctx, b64, 1); if (GRPC_SLICE_IS_EMPTY(bin)) { gpr_log(GPR_ERROR, "Invalid base64 for big num."); - return NULL; + return nullptr; } result = BN_bin2bn(GRPC_SLICE_START_PTR(bin), - TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), NULL); + TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), nullptr); grpc_slice_unref_internal(exec_ctx, bin); return result; } @@ -474,19 +474,19 @@ static int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) { * parameters MUST be non-NULL for n and e. d may be * left NULL (in case only the public key is used). */ - if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) { + if ((r->n == nullptr && n == nullptr) || (r->e == nullptr && e == nullptr)) { return 0; } - if (n != NULL) { + if (n != nullptr) { BN_free(r->n); r->n = n; } - if (e != NULL) { + if (e != nullptr) { BN_free(r->e); r->e = e; } - if (d != NULL) { + if (d != nullptr) { BN_free(r->d); r->d = d; } @@ -498,43 +498,43 @@ static int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) { static EVP_PKEY* pkey_from_jwk(grpc_exec_ctx* exec_ctx, const grpc_json* json, const char* kty) { const grpc_json* key_prop; - RSA* rsa = NULL; - EVP_PKEY* result = NULL; - BIGNUM* tmp_n = NULL; - BIGNUM* tmp_e = NULL; + RSA* rsa = nullptr; + EVP_PKEY* result = nullptr; + BIGNUM* tmp_n = nullptr; + BIGNUM* tmp_e = nullptr; - GPR_ASSERT(kty != NULL && json != NULL); + GPR_ASSERT(kty != nullptr && json != nullptr); if (strcmp(kty, "RSA") != 0) { gpr_log(GPR_ERROR, "Unsupported key type %s.", kty); goto end; } rsa = RSA_new(); - if (rsa == NULL) { + if (rsa == nullptr) { gpr_log(GPR_ERROR, "Could not create rsa key."); goto end; } - for (key_prop = json->child; key_prop != NULL; key_prop = key_prop->next) { + for (key_prop = json->child; key_prop != nullptr; key_prop = key_prop->next) { if (strcmp(key_prop->key, "n") == 0) { tmp_n = bignum_from_base64(exec_ctx, validate_string_field(key_prop, "n")); - if (tmp_n == NULL) goto end; + if (tmp_n == nullptr) goto end; } else if (strcmp(key_prop->key, "e") == 0) { tmp_e = bignum_from_base64(exec_ctx, validate_string_field(key_prop, "e")); - if (tmp_e == NULL) goto end; + if (tmp_e == nullptr) goto end; } } - if (tmp_e == NULL || tmp_n == NULL) { + if (tmp_e == nullptr || tmp_n == nullptr) { gpr_log(GPR_ERROR, "Missing RSA public key field."); goto end; } - if (!RSA_set0_key(rsa, tmp_n, tmp_e, NULL)) { + if (!RSA_set0_key(rsa, tmp_n, tmp_e, nullptr)) { gpr_log(GPR_ERROR, "Cannot set RSA key from inputs."); goto end; } /* RSA_set0_key takes ownership on success. */ - tmp_n = NULL; - tmp_e = NULL; + tmp_n = nullptr; + tmp_e = nullptr; result = EVP_PKEY_new(); EVP_PKEY_set1_RSA(result, rsa); /* uprefs rsa. */ @@ -554,29 +554,29 @@ static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, /* Try to parse the json as a JWK set: https://tools.ietf.org/html/rfc7517#section-5. */ jwk_keys = find_property_by_name(json, "keys"); - if (jwk_keys == NULL) { + if (jwk_keys == nullptr) { /* Use the google proprietary format which is: { <kid1>: <x5091>, <kid2>: <x5092>, ... } */ const grpc_json* cur = find_property_by_name(json, header_kid); - if (cur == NULL) return NULL; + if (cur == nullptr) return nullptr; return extract_pkey_from_x509(cur->value); } if (jwk_keys->type != GRPC_JSON_ARRAY) { gpr_log(GPR_ERROR, "Unexpected value type of keys property in jwks key set."); - return NULL; + return nullptr; } /* Key format is specified in: https://tools.ietf.org/html/rfc7518#section-6. */ - for (jkey = jwk_keys->child; jkey != NULL; jkey = jkey->next) { + for (jkey = jwk_keys->child; jkey != nullptr; jkey = jkey->next) { grpc_json* key_prop; - const char* alg = NULL; - const char* kid = NULL; - const char* kty = NULL; + const char* alg = nullptr; + const char* kid = nullptr; + const char* kty = nullptr; if (jkey->type != GRPC_JSON_OBJECT) continue; - for (key_prop = jkey->child; key_prop != NULL; key_prop = key_prop->next) { + for (key_prop = jkey->child; key_prop != nullptr; key_prop = key_prop->next) { if (strcmp(key_prop->key, "alg") == 0 && key_prop->type == GRPC_JSON_STRING) { alg = key_prop->value; @@ -588,7 +588,7 @@ static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, kty = key_prop->value; } } - if (alg != NULL && kid != NULL && kty != NULL && + if (alg != nullptr && kid != nullptr && kty != nullptr && strcmp(kid, header_kid) == 0 && strcmp(alg, header_alg) == 0) { return pkey_from_jwk(exec_ctx, jkey, kty); } @@ -596,7 +596,7 @@ static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, gpr_log(GPR_ERROR, "Could not find matching key in key set for kid=%s and alg=%s", header_kid, header_alg); - return NULL; + return nullptr; } static int verify_jwt_signature(EVP_PKEY* key, const char* alg, @@ -605,12 +605,12 @@ static int verify_jwt_signature(EVP_PKEY* key, const char* alg, const EVP_MD* md = evp_md_from_alg(alg); int result = 0; - GPR_ASSERT(md != NULL); /* Checked before. */ - if (md_ctx == NULL) { + GPR_ASSERT(md != nullptr); /* Checked before. */ + if (md_ctx == nullptr) { gpr_log(GPR_ERROR, "Could not create EVP_MD_CTX."); goto end; } - if (EVP_DigestVerifyInit(md_ctx, NULL, md, NULL, key) != 1) { + if (EVP_DigestVerifyInit(md_ctx, nullptr, md, nullptr, key) != 1) { gpr_log(GPR_ERROR, "EVP_DigestVerifyInit failed."); goto end; } @@ -635,17 +635,17 @@ static void on_keys_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, grpc_error* error) { verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data; grpc_json* json = json_from_http(&ctx->responses[HTTP_RESPONSE_KEYS]); - EVP_PKEY* verification_key = NULL; + EVP_PKEY* verification_key = nullptr; grpc_jwt_verifier_status status = GRPC_JWT_VERIFIER_GENERIC_ERROR; - grpc_jwt_claims* claims = NULL; + grpc_jwt_claims* claims = nullptr; - if (json == NULL) { + if (json == nullptr) { status = GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR; goto end; } verification_key = find_verification_key(exec_ctx, json, ctx->header->alg, ctx->header->kid); - if (verification_key == NULL) { + if (verification_key == nullptr) { gpr_log(GPR_ERROR, "Could not find verification key with kid %s.", ctx->header->kid); status = GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR; @@ -662,11 +662,11 @@ static void on_keys_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, if (status == GRPC_JWT_VERIFIER_OK) { /* Pass ownership. */ claims = ctx->claims; - ctx->claims = NULL; + ctx->claims = nullptr; } end: - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); EVP_PKEY_free(verification_key); ctx->user_cb(exec_ctx, ctx->user_data, status, claims); verifier_cb_ctx_destroy(exec_ctx, ctx); @@ -680,17 +680,17 @@ static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, grpc_json* json = json_from_http(response); grpc_httpcli_request req; const char* jwks_uri; - grpc_resource_quota* resource_quota = NULL; + grpc_resource_quota* resource_quota = nullptr; /* TODO(jboeuf): Cache the jwks_uri in order to avoid this hop next time. */ - if (json == NULL) goto error; + if (json == nullptr) goto error; cur = find_property_by_name(json, "jwks_uri"); - if (cur == NULL) { + if (cur == nullptr) { gpr_log(GPR_ERROR, "Could not find jwks_uri in openid config."); goto error; } jwks_uri = validate_string_field(cur, "jwks_uri"); - if (jwks_uri == NULL) goto error; + if (jwks_uri == nullptr) goto error; if (strstr(jwks_uri, "https://") != jwks_uri) { gpr_log(GPR_ERROR, "Invalid non https jwks_uri: %s.", jwks_uri); goto error; @@ -699,7 +699,7 @@ static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, req.handshaker = &grpc_httpcli_ssl; req.host = gpr_strdup(jwks_uri); req.http.path = (char*)strchr(jwks_uri, '/'); - if (req.http.path == NULL) { + if (req.http.path == nullptr) { req.http.path = (char*)""; } else { *(req.host + (req.http.path - jwks_uri)) = '\0'; @@ -720,29 +720,29 @@ static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, return; error: - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, - NULL); + nullptr); verifier_cb_ctx_destroy(exec_ctx, ctx); } static email_key_mapping* verifier_get_mapping(grpc_jwt_verifier* v, const char* email_domain) { size_t i; - if (v->mappings == NULL) return NULL; + if (v->mappings == nullptr) return nullptr; for (i = 0; i < v->num_mappings; i++) { if (strcmp(email_domain, v->mappings[i].email_domain) == 0) { return &v->mappings[i]; } } - return NULL; + return nullptr; } static void verifier_put_mapping(grpc_jwt_verifier* v, const char* email_domain, const char* key_url_prefix) { email_key_mapping* mapping = verifier_get_mapping(v, email_domain); GPR_ASSERT(v->num_mappings < v->allocated_mappings); - if (mapping != NULL) { + if (mapping != nullptr) { gpr_free(mapping->key_url_prefix); mapping->key_url_prefix = gpr_strdup(key_url_prefix); return; @@ -757,16 +757,16 @@ static void verifier_put_mapping(grpc_jwt_verifier* v, const char* email_domain, enough for now... */ const char* grpc_jwt_issuer_email_domain(const char* issuer) { const char* at_sign = strchr(issuer, '@'); - if (at_sign == NULL) return NULL; + if (at_sign == nullptr) return nullptr; const char* email_domain = at_sign + 1; - if (*email_domain == '\0') return NULL; + if (*email_domain == '\0') return nullptr; const char* dot = strrchr(email_domain, '.'); - if (dot == NULL || dot == email_domain) return email_domain; + if (dot == nullptr || dot == email_domain) return email_domain; GPR_ASSERT(dot > email_domain); /* There may be a subdomain, we just want the domain. */ dot = (const char*)gpr_memrchr((void*)email_domain, '.', (size_t)(dot - email_domain)); - if (dot == NULL) return email_domain; + if (dot == nullptr) return email_domain; return dot + 1; } @@ -775,21 +775,21 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, verifier_cb_ctx* ctx) { const char* email_domain; grpc_closure* http_cb; - char* path_prefix = NULL; + char* path_prefix = nullptr; const char* iss; grpc_httpcli_request req; - grpc_resource_quota* resource_quota = NULL; + grpc_resource_quota* resource_quota = nullptr; memset(&req, 0, sizeof(grpc_httpcli_request)); req.handshaker = &grpc_httpcli_ssl; http_response_index rsp_idx; - GPR_ASSERT(ctx != NULL && ctx->header != NULL && ctx->claims != NULL); + GPR_ASSERT(ctx != nullptr && ctx->header != nullptr && ctx->claims != nullptr); iss = ctx->claims->iss; - if (ctx->header->kid == NULL) { + if (ctx->header->kid == nullptr) { gpr_log(GPR_ERROR, "Missing kid in jose header."); goto error; } - if (iss == NULL) { + if (iss == nullptr) { gpr_log(GPR_ERROR, "Missing iss in claims."); goto error; } @@ -800,17 +800,17 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, so we will rely instead on email/url mappings if we detect such an issuer. Part 4, on the other hand is implemented by both google and salesforce. */ email_domain = grpc_jwt_issuer_email_domain(iss); - if (email_domain != NULL) { + if (email_domain != nullptr) { email_key_mapping* mapping; - GPR_ASSERT(ctx->verifier != NULL); + GPR_ASSERT(ctx->verifier != nullptr); mapping = verifier_get_mapping(ctx->verifier, email_domain); - if (mapping == NULL) { + if (mapping == nullptr) { gpr_log(GPR_ERROR, "Missing mapping for issuer email."); goto error; } req.host = gpr_strdup(mapping->key_url_prefix); path_prefix = strchr(req.host, '/'); - if (path_prefix == NULL) { + if (path_prefix == nullptr) { gpr_asprintf(&req.http.path, "/%s", iss); } else { *(path_prefix++) = '\0'; @@ -822,7 +822,7 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, } else { req.host = gpr_strdup(strstr(iss, "https://") == iss ? iss + 8 : iss); path_prefix = strchr(req.host, '/'); - if (path_prefix == NULL) { + if (path_prefix == nullptr) { req.http.path = gpr_strdup(GRPC_OPENID_CONFIG_URL_SUFFIX); } else { *(path_prefix++) = 0; @@ -849,7 +849,7 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, error: ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, - NULL); + nullptr); verifier_cb_ctx_destroy(exec_ctx, ctx); } @@ -859,33 +859,33 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, const char* audience, grpc_jwt_verification_done_cb cb, void* user_data) { - const char* dot = NULL; + const char* dot = nullptr; grpc_json* json; - jose_header* header = NULL; - grpc_jwt_claims* claims = NULL; + jose_header* header = nullptr; + grpc_jwt_claims* claims = nullptr; grpc_slice header_buffer; grpc_slice claims_buffer; grpc_slice signature; size_t signed_jwt_len; const char* cur = jwt; - GPR_ASSERT(verifier != NULL && jwt != NULL && audience != NULL && cb != NULL); + GPR_ASSERT(verifier != nullptr && jwt != nullptr && audience != nullptr && cb != nullptr); dot = strchr(cur, '.'); - if (dot == NULL) goto error; + if (dot == nullptr) goto error; json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur), &header_buffer); - if (json == NULL) goto error; + if (json == nullptr) goto error; header = jose_header_from_json(exec_ctx, json, header_buffer); - if (header == NULL) goto error; + if (header == nullptr) goto error; cur = dot + 1; dot = strchr(cur, '.'); - if (dot == NULL) goto error; + if (dot == nullptr) goto error; json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur), &claims_buffer); - if (json == NULL) goto error; + if (json == nullptr) goto error; claims = grpc_jwt_claims_from_json(exec_ctx, json, claims_buffer); - if (claims == NULL) goto error; + if (claims == nullptr) goto error; signed_jwt_len = (size_t)(dot - jwt); cur = dot + 1; @@ -898,9 +898,9 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, return; error: - if (header != NULL) jose_header_destroy(exec_ctx, header); - if (claims != NULL) grpc_jwt_claims_destroy(exec_ctx, claims); - cb(exec_ctx, user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, NULL); + if (header != nullptr) jose_header_destroy(exec_ctx, header); + if (claims != nullptr) grpc_jwt_claims_destroy(exec_ctx, claims); + cb(exec_ctx, user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, nullptr); } grpc_jwt_verifier* grpc_jwt_verifier_create( @@ -917,7 +917,7 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( verifier_put_mapping(v, GRPC_GOOGLE_SERVICE_ACCOUNTS_EMAIL_DOMAIN, GRPC_GOOGLE_SERVICE_ACCOUNTS_KEY_URL_PREFIX); /* User-Provided mappings. */ - if (mappings != NULL) { + if (mappings != nullptr) { size_t i; for (i = 0; i < num_mappings; i++) { verifier_put_mapping(v, mappings[i].email_domain, @@ -929,9 +929,9 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( void grpc_jwt_verifier_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_verifier* v) { size_t i; - if (v == NULL) return; + if (v == nullptr) return; grpc_httpcli_context_destroy(exec_ctx, &v->http_ctx); - if (v->mappings != NULL) { + if (v->mappings != nullptr) { for (i = 0; i < v->num_mappings; i++) { gpr_free(v->mappings[i].email_domain); gpr_free(v->mappings[i].key_url_prefix); diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 2a44211228..943d23f21e 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -33,7 +33,7 @@ int grpc_auth_refresh_token_is_valid( const grpc_auth_refresh_token* refresh_token) { - return (refresh_token != NULL) && + return (refresh_token != nullptr) && strcmp(refresh_token->type, GRPC_AUTH_JSON_TYPE_INVALID); } @@ -45,13 +45,13 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_json( memset(&result, 0, sizeof(grpc_auth_refresh_token)); result.type = GRPC_AUTH_JSON_TYPE_INVALID; - if (json == NULL) { + if (json == nullptr) { gpr_log(GPR_ERROR, "Invalid json."); goto end; } prop_value = grpc_json_get_string_property(json, "type"); - if (prop_value == NULL || + if (prop_value == nullptr || strcmp(prop_value, GRPC_AUTH_JSON_TYPE_AUTHORIZED_USER)) { goto end; } @@ -77,25 +77,25 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_string( grpc_json* json = grpc_json_parse_string(scratchpad); grpc_auth_refresh_token result = grpc_auth_refresh_token_create_from_json(json); - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); gpr_free(scratchpad); return result; } void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) { - if (refresh_token == NULL) return; + if (refresh_token == nullptr) return; refresh_token->type = GRPC_AUTH_JSON_TYPE_INVALID; - if (refresh_token->client_id != NULL) { + if (refresh_token->client_id != nullptr) { gpr_free(refresh_token->client_id); - refresh_token->client_id = NULL; + refresh_token->client_id = nullptr; } - if (refresh_token->client_secret != NULL) { + if (refresh_token->client_secret != nullptr) { gpr_free(refresh_token->client_secret); - refresh_token->client_secret = NULL; + refresh_token->client_secret = nullptr; } - if (refresh_token->refresh_token != NULL) { + if (refresh_token->refresh_token != nullptr) { gpr_free(refresh_token->refresh_token); - refresh_token->refresh_token = NULL; + refresh_token->refresh_token = nullptr; } } @@ -118,12 +118,12 @@ grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( grpc_exec_ctx* exec_ctx, const grpc_http_response* response, grpc_mdelem* token_md, grpc_millis* token_lifetime) { - char* null_terminated_body = NULL; - char* new_access_token = NULL; + char* null_terminated_body = nullptr; + char* new_access_token = nullptr; grpc_credentials_status status = GRPC_CREDENTIALS_OK; - grpc_json* json = NULL; + grpc_json* json = nullptr; - if (response == NULL) { + if (response == nullptr) { gpr_log(GPR_ERROR, "Received NULL response."); status = GRPC_CREDENTIALS_ERROR; goto end; @@ -138,16 +138,16 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( if (response->status != 200) { gpr_log(GPR_ERROR, "Call to http server ended with error %d [%s].", response->status, - null_terminated_body != NULL ? null_terminated_body : ""); + null_terminated_body != nullptr ? null_terminated_body : ""); status = GRPC_CREDENTIALS_ERROR; goto end; } else { - grpc_json* access_token = NULL; - grpc_json* token_type = NULL; - grpc_json* expires_in = NULL; + grpc_json* access_token = nullptr; + grpc_json* token_type = nullptr; + grpc_json* expires_in = nullptr; grpc_json* ptr; json = grpc_json_parse_string(null_terminated_body); - if (json == NULL) { + if (json == nullptr) { gpr_log(GPR_ERROR, "Could not parse JSON from %s", null_terminated_body); status = GRPC_CREDENTIALS_ERROR; goto end; @@ -166,24 +166,24 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( expires_in = ptr; } } - if (access_token == NULL || access_token->type != GRPC_JSON_STRING) { + if (access_token == nullptr || access_token->type != GRPC_JSON_STRING) { gpr_log(GPR_ERROR, "Missing or invalid access_token in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } - if (token_type == NULL || token_type->type != GRPC_JSON_STRING) { + if (token_type == nullptr || token_type->type != GRPC_JSON_STRING) { gpr_log(GPR_ERROR, "Missing or invalid token_type in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } - if (expires_in == NULL || expires_in->type != GRPC_JSON_NUMBER) { + if (expires_in == nullptr || expires_in->type != GRPC_JSON_NUMBER) { gpr_log(GPR_ERROR, "Missing or invalid expires_in in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } gpr_asprintf(&new_access_token, "%s %s", token_type->value, access_token->value); - *token_lifetime = strtol(expires_in->value, NULL, 10) * GPR_MS_PER_SEC; + *token_lifetime = strtol(expires_in->value, nullptr, 10) * GPR_MS_PER_SEC; if (!GRPC_MDISNULL(*token_md)) GRPC_MDELEM_UNREF(exec_ctx, *token_md); *token_md = grpc_mdelem_from_slices( exec_ctx, @@ -197,9 +197,9 @@ end: GRPC_MDELEM_UNREF(exec_ctx, *token_md); *token_md = GRPC_MDNULL; } - if (null_terminated_body != NULL) gpr_free(null_terminated_body); - if (new_access_token != NULL) gpr_free(new_access_token); - if (json != NULL) grpc_json_destroy(json); + if (null_terminated_body != nullptr) gpr_free(null_terminated_body); + if (new_access_token != nullptr) gpr_free(new_access_token); + if (json != nullptr) grpc_json_destroy(json); return status; } @@ -225,10 +225,10 @@ static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx, : 0; grpc_oauth2_pending_get_request_metadata* pending_request = c->pending_requests; - c->pending_requests = NULL; + c->pending_requests = nullptr; gpr_mu_unlock(&c->mu); // Invoke callbacks for all pending requests. - while (pending_request != NULL) { + while (pending_request != nullptr) { if (status == GRPC_CREDENTIALS_OK) { grpc_credentials_mdelem_array_add(pending_request->md_array, access_token_md); @@ -305,13 +305,13 @@ static void oauth2_token_fetcher_cancel_get_request_metadata( grpc_oauth2_token_fetcher_credentials* c = (grpc_oauth2_token_fetcher_credentials*)creds; gpr_mu_lock(&c->mu); - grpc_oauth2_pending_get_request_metadata* prev = NULL; + grpc_oauth2_pending_get_request_metadata* prev = nullptr; grpc_oauth2_pending_get_request_metadata* pending_request = c->pending_requests; - while (pending_request != NULL) { + while (pending_request != nullptr) { if (pending_request->md_array == md_array) { // Remove matching pending request from the list. - if (prev != NULL) { + if (prev != nullptr) { prev->next = pending_request->next; } else { c->pending_requests = pending_request->next; @@ -380,7 +380,7 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create( sizeof(grpc_oauth2_token_fetcher_credentials)); GRPC_API_TRACE("grpc_compute_engine_credentials_create(reserved=%p)", 1, (reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); init_oauth2_token_fetcher(c, compute_engine_fetch_oauth2); c->base.vtable = &compute_engine_vtable; return &c->base; @@ -411,7 +411,7 @@ static void refresh_token_fetch_oauth2( grpc_http_header header = {(char*)"Content-Type", (char*)"application/x-www-form-urlencoded"}; grpc_httpcli_request request; - char* body = NULL; + char* body = nullptr; gpr_asprintf(&body, GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING, c->refresh_token.client_id, c->refresh_token.client_secret, c->refresh_token.refresh_token); @@ -441,7 +441,7 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token( grpc_google_refresh_token_credentials* c; if (!grpc_auth_refresh_token_is_valid(&refresh_token)) { gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation"); - return NULL; + return nullptr; } c = (grpc_google_refresh_token_credentials*)gpr_zalloc( sizeof(grpc_google_refresh_token_credentials)); @@ -455,7 +455,7 @@ static char* create_loggable_refresh_token(grpc_auth_refresh_token* token) { if (strcmp(token->type, GRPC_AUTH_JSON_TYPE_INVALID) == 0) { return gpr_strdup("<Invalid json token>"); } - char* loggable_token = NULL; + char* loggable_token = nullptr; gpr_asprintf(&loggable_token, "{\n type: %s\n client_id: %s\n client_secret: " "<redacted>\n refresh_token: <redacted>\n}", @@ -475,7 +475,7 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create( loggable_token, reserved); gpr_free(loggable_token); } - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); return grpc_refresh_token_credentials_create_from_auth_refresh_token(token); } @@ -517,7 +517,7 @@ grpc_call_credentials* grpc_access_token_credentials_create( "grpc_access_token_credentials_create(access_token=<redacted>, " "reserved=%p)", 1, (reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2; c->base.vtable = &access_token_vtable; gpr_ref_init(&c->base.refcount, 1); diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index e75b00c01a..b83a1b426a 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -38,7 +38,7 @@ static void plugin_destruct(grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds) { grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; gpr_mu_destroy(&c->mu); - if (c->plugin.state != NULL && c->plugin.destroy != NULL) { + if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) { c->plugin.destroy(c->plugin.state); } } @@ -46,12 +46,12 @@ static void plugin_destruct(grpc_exec_ctx* exec_ctx, static void pending_request_remove_locked( grpc_plugin_credentials* c, grpc_plugin_credentials_pending_request* pending_request) { - if (pending_request->prev == NULL) { + if (pending_request->prev == nullptr) { c->pending_requests = pending_request->next; } else { pending_request->prev->next = pending_request->next; } - if (pending_request->next != NULL) { + if (pending_request->next != nullptr) { pending_request->next->prev = pending_request->prev; } } @@ -120,7 +120,7 @@ static void plugin_md_request_metadata_ready(void* request, /* called from application code */ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER( GRPC_EXEC_CTX_FLAG_IS_FINISHED | GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP, - NULL, NULL); + nullptr, nullptr); grpc_plugin_credentials_pending_request* r = (grpc_plugin_credentials_pending_request*)request; if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { @@ -155,7 +155,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, grpc_error** error) { grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; bool retval = true; // Synchronous return. - if (c->plugin.get_metadata != NULL) { + if (c->plugin.get_metadata != nullptr) { // Create pending_request object. grpc_plugin_credentials_pending_request* pending_request = (grpc_plugin_credentials_pending_request*)gpr_zalloc( @@ -165,7 +165,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, pending_request->on_request_metadata = on_request_metadata; // Add it to the pending list. gpr_mu_lock(&c->mu); - if (c->pending_requests != NULL) { + if (c->pending_requests != nullptr) { c->pending_requests->prev = pending_request; } pending_request->next = c->pending_requests; @@ -180,7 +180,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX]; size_t num_creds_md = 0; grpc_status_code status = GRPC_STATUS_OK; - const char* error_details = NULL; + const char* error_details = nullptr; if (!c->plugin.get_metadata(c->plugin.state, context, plugin_md_request_metadata_ready, pending_request, creds_md, &num_creds_md, @@ -235,7 +235,7 @@ static void plugin_cancel_get_request_metadata( gpr_mu_lock(&c->mu); for (grpc_plugin_credentials_pending_request* pending_request = c->pending_requests; - pending_request != NULL; pending_request = pending_request->next) { + pending_request != nullptr; pending_request = pending_request->next) { if (pending_request->md_array == md_array) { if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", c, @@ -261,7 +261,7 @@ grpc_call_credentials* grpc_metadata_credentials_create_from_plugin( grpc_plugin_credentials* c = (grpc_plugin_credentials*)gpr_zalloc(sizeof(*c)); GRPC_API_TRACE("grpc_metadata_credentials_create_from_plugin(reserved=%p)", 1, (reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); c->base.type = plugin.type; c->base.vtable = &plugin_vtable; gpr_ref_init(&c->base.refcount, 1); diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 79e223ddcb..39dd38cf88 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -33,7 +33,7 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp, size_t num_key_cert_pairs) { - if (kp == NULL) return; + if (kp == nullptr) return; for (size_t i = 0; i < num_key_cert_pairs; i++) { gpr_free((void*)kp[i].private_key); gpr_free((void*)kp[i].cert_chain); @@ -55,7 +55,7 @@ static grpc_security_status ssl_create_security_connector( grpc_channel_args** new_args) { grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds; grpc_security_status status = GRPC_SECURITY_OK; - const char* overridden_target_name = NULL; + const char* overridden_target_name = nullptr; for (size_t i = 0; args && i < args->num_args; i++) { grpc_arg* arg = &args->args[i]; if (strcmp(arg->key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == 0 && @@ -77,17 +77,17 @@ static grpc_security_status ssl_create_security_connector( } static grpc_channel_credentials_vtable ssl_vtable = { - ssl_destruct, ssl_create_security_connector, NULL}; + ssl_destruct, ssl_create_security_connector, nullptr}; static void ssl_build_config(const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair, grpc_ssl_config* config) { - if (pem_root_certs != NULL) { + if (pem_root_certs != nullptr) { config->pem_root_certs = gpr_strdup(pem_root_certs); } - if (pem_key_cert_pair != NULL) { - GPR_ASSERT(pem_key_cert_pair->private_key != NULL); - GPR_ASSERT(pem_key_cert_pair->cert_chain != NULL); + if (pem_key_cert_pair != nullptr) { + GPR_ASSERT(pem_key_cert_pair->private_key != nullptr); + GPR_ASSERT(pem_key_cert_pair->cert_chain != nullptr); config->pem_key_cert_pair = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc( sizeof(tsi_ssl_pem_key_cert_pair)); config->pem_key_cert_pair->cert_chain = @@ -107,7 +107,7 @@ grpc_channel_credentials* grpc_ssl_credentials_create( "pem_key_cert_pair=%p, " "reserved=%p)", 3, (pem_root_certs, pem_key_cert_pair, reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL; c->base.vtable = &ssl_vtable; gpr_ref_init(&c->base.refcount, 1); @@ -145,15 +145,15 @@ static grpc_server_credentials_vtable ssl_server_vtable = { tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs( const grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs, size_t num_key_cert_pairs) { - tsi_ssl_pem_key_cert_pair* tsi_pairs = NULL; + tsi_ssl_pem_key_cert_pair* tsi_pairs = nullptr; if (num_key_cert_pairs > 0) { - GPR_ASSERT(pem_key_cert_pairs != NULL); + GPR_ASSERT(pem_key_cert_pairs != nullptr); tsi_pairs = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc( num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair)); } for (size_t i = 0; i < num_key_cert_pairs; i++) { - GPR_ASSERT(pem_key_cert_pairs[i].private_key != NULL); - GPR_ASSERT(pem_key_cert_pairs[i].cert_chain != NULL); + GPR_ASSERT(pem_key_cert_pairs[i].private_key != nullptr); + GPR_ASSERT(pem_key_cert_pairs[i].cert_chain != nullptr); tsi_pairs[i].cert_chain = gpr_strdup(pem_key_cert_pairs[i].cert_chain); tsi_pairs[i].private_key = gpr_strdup(pem_key_cert_pairs[i].private_key); } @@ -166,7 +166,7 @@ static void ssl_build_server_config( grpc_ssl_client_certificate_request_type client_certificate_request, grpc_ssl_server_config* config) { config->client_certificate_request = client_certificate_request; - if (pem_root_certs != NULL) { + if (pem_root_certs != nullptr) { config->pem_root_certs = gpr_strdup(pem_root_certs); } config->pem_key_cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs( @@ -181,18 +181,18 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create( grpc_ssl_server_certificate_config* config = (grpc_ssl_server_certificate_config*)gpr_zalloc( sizeof(grpc_ssl_server_certificate_config)); - if (pem_root_certs != NULL) { + if (pem_root_certs != nullptr) { config->pem_root_certs = gpr_strdup(pem_root_certs); } if (num_key_cert_pairs > 0) { - GPR_ASSERT(pem_key_cert_pairs != NULL); + GPR_ASSERT(pem_key_cert_pairs != nullptr); config->pem_key_cert_pairs = (grpc_ssl_pem_key_cert_pair*)gpr_zalloc( num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair)); } config->num_key_cert_pairs = num_key_cert_pairs; for (size_t i = 0; i < num_key_cert_pairs; i++) { - GPR_ASSERT(pem_key_cert_pairs[i].private_key != NULL); - GPR_ASSERT(pem_key_cert_pairs[i].cert_chain != NULL); + GPR_ASSERT(pem_key_cert_pairs[i].private_key != nullptr); + GPR_ASSERT(pem_key_cert_pairs[i].cert_chain != nullptr); config->pem_key_cert_pairs[i].cert_chain = gpr_strdup(pem_key_cert_pairs[i].cert_chain); config->pem_key_cert_pairs[i].private_key = @@ -203,7 +203,7 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create( void grpc_ssl_server_certificate_config_destroy( grpc_ssl_server_certificate_config* config) { - if (config == NULL) return; + if (config == nullptr) return; for (size_t i = 0; i < config->num_key_cert_pairs; i++) { gpr_free((void*)config->pem_key_cert_pairs[i].private_key); gpr_free((void*)config->pem_key_cert_pairs[i].cert_chain); @@ -217,8 +217,8 @@ grpc_ssl_server_credentials_options* grpc_ssl_server_credentials_create_options_using_config( grpc_ssl_client_certificate_request_type client_certificate_request, grpc_ssl_server_certificate_config* config) { - grpc_ssl_server_credentials_options* options = NULL; - if (config == NULL) { + grpc_ssl_server_credentials_options* options = nullptr; + if (config == nullptr) { gpr_log(GPR_ERROR, "Certificate config must not be NULL."); goto done; } @@ -234,9 +234,9 @@ grpc_ssl_server_credentials_options* grpc_ssl_server_credentials_create_options_using_config_fetcher( grpc_ssl_client_certificate_request_type client_certificate_request, grpc_ssl_server_certificate_config_callback cb, void* user_data) { - if (cb == NULL) { + if (cb == nullptr) { gpr_log(GPR_ERROR, "Invalid certificate config callback parameter."); - return NULL; + return nullptr; } grpc_ssl_server_certificate_config_fetcher* fetcher = @@ -277,7 +277,7 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_ex( 5, (pem_root_certs, pem_key_cert_pairs, (unsigned long)num_key_cert_pairs, client_certificate_request, reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); grpc_ssl_server_certificate_config* cert_config = grpc_ssl_server_certificate_config_create( @@ -291,23 +291,23 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_ex( grpc_server_credentials* grpc_ssl_server_credentials_create_with_options( grpc_ssl_server_credentials_options* options) { - grpc_server_credentials* retval = NULL; - grpc_ssl_server_credentials* c = NULL; + grpc_server_credentials* retval = nullptr; + grpc_ssl_server_credentials* c = nullptr; - if (options == NULL) { + if (options == nullptr) { gpr_log(GPR_ERROR, "Invalid options trying to create SSL server credentials."); goto done; } - if (options->certificate_config == NULL && - options->certificate_config_fetcher == NULL) { + if (options->certificate_config == nullptr && + options->certificate_config_fetcher == nullptr) { gpr_log(GPR_ERROR, "SSL server credentials options must specify either " "certificate config or fetcher."); goto done; - } else if (options->certificate_config_fetcher != NULL && - options->certificate_config_fetcher->cb == NULL) { + } else if (options->certificate_config_fetcher != nullptr && + options->certificate_config_fetcher->cb == nullptr) { gpr_log(GPR_ERROR, "Certificate config fetcher callback must not be NULL."); goto done; } @@ -318,7 +318,7 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options( gpr_ref_init(&c->base.refcount, 1); c->base.vtable = &ssl_server_vtable; - if (options->certificate_config_fetcher != NULL) { + if (options->certificate_config_fetcher != nullptr) { c->config.client_certificate_request = options->client_certificate_request; c->certificate_config_fetcher = *options->certificate_config_fetcher; } else { @@ -337,7 +337,7 @@ done: void grpc_ssl_server_credentials_options_destroy( grpc_ssl_server_credentials_options* o) { - if (o == NULL) return; + if (o == nullptr) return; gpr_free(o->certificate_config_fetcher); grpc_ssl_server_certificate_config_destroy(o->certificate_config); gpr_free(o); |