From 52b72c00f113f258d95bd3cb7f3783fd760bf15f Mon Sep 17 00:00:00 2001 From: Matthew Stevenson Date: Tue, 20 Aug 2019 14:23:08 -0700 Subject: [PATCH] Debugging after restores --- include/grpc/grpc_security.h | 2 +- .../grpcpp/security/tls_credentials_options.h | 50 ++++++++--------- src/cpp/common/tls_credentials_options.cc | 54 ++++++++----------- test/cpp/client/credentials_test.cc | 18 +++---- 4 files changed, 57 insertions(+), 67 deletions(-) diff --git a/include/grpc/grpc_security.h b/include/grpc/grpc_security.h index 98657d53cfc..d63802c9782 100644 --- a/include/grpc/grpc_security.h +++ b/include/grpc/grpc_security.h @@ -882,7 +882,7 @@ struct grpc_tls_server_authorization_check_arg { const char* peer_cert; grpc_status_code status; const char* error_details; - grpc_tls_server_authorization_check_arg* config; + grpc_tls_server_authorization_check_config* config; }; /** Create a grpc_tls_server_authorization_check_config instance. diff --git a/include/grpcpp/security/tls_credentials_options.h b/include/grpcpp/security/tls_credentials_options.h index c5173b8524f..7db070d7e8f 100644 --- a/include/grpcpp/security/tls_credentials_options.h +++ b/include/grpcpp/security/tls_credentials_options.h @@ -39,28 +39,28 @@ class TlsKeyMaterialsConfig { /** Getters for member fields. **/ const grpc::string pem_root_certs() const { return pem_root_certs_; } - const ::std::vector& pem_key_cert_pair_list() const { + const std::vector& pem_key_cert_pair_list() const { return pem_key_cert_pair_list_; } - const int version() const { return version_; } + int version() const { return version_; } /** Setter for key materials that will be called by the user. The setter * transfers ownership of the arguments to the config. **/ void set_key_materials(grpc::string pem_root_certs, - ::std::vector pem_key_cert_pair_list); + std::vector pem_key_cert_pair_list); void set_version(int version) { version_ = version;}; private: int version_; - ::std::vector pem_key_cert_pair_list_; + std::vector pem_key_cert_pair_list_; grpc::string pem_root_certs_; }; /** The following 2 functions are exposed for testing purposes. **/ grpc_tls_key_materials_config* c_key_materials( - const ::std::shared_ptr& config); + const std::shared_ptr& config); -::std::shared_ptr tls_key_materials_c_to_cpp( +std::shared_ptr tls_key_materials_c_to_cpp( const grpc_tls_key_materials_config* config); @@ -73,19 +73,19 @@ class TlsCredentialReloadArg { /** Getters for member fields. The callback function is not exposed. **/ void* cb_user_data() const; - ::std::shared_ptr key_materials_config() const; + std::shared_ptr key_materials_config() const; grpc_ssl_certificate_config_reload_status status() const; - ::std::shared_ptr error_details() const; + std::shared_ptr error_details() const; /** Setters for member fields. **/ void set_cb_user_data(void* cb_user_data); void set_key_materials_config( - ::std::shared_ptr key_materials_config); + std::shared_ptr key_materials_config); void set_status(grpc_ssl_certificate_config_reload_status status); void set_error_details(const grpc::string& error_details); /** Calls the C arg's callback function. **/ - void callback() ; + void callback(); private: grpc_tls_credential_reload_arg c_arg_; @@ -144,10 +144,10 @@ class TlsServerAuthorizationCheckArg { /** Getters for member fields. **/ void* cb_user_data() const; int success() const; - ::std::shared_ptr target_name() const; - ::std::shared_ptr peer_cert() const; + std::shared_ptr target_name() const; + std::shared_ptr peer_cert() const; grpc_status_code status() const; - ::std::shared_ptr error_details() const; + std::shared_ptr error_details() const; /** Setters for member fields. **/ void set_cb_user_data(void* cb_user_data); @@ -202,7 +202,7 @@ class TlsServerAuthorizationCheckConfig { } private: - grpc_tls_server_authorization_check_arg* c_config_; + grpc_tls_server_authorization_check_config* c_config_; void* config_user_data_; int (*schedule_)(void* config_user_data, TlsServerAuthorizationCheckArg* arg); void (*cancel_)(void* config_user_data, TlsServerAuthorizationCheckArg* arg); @@ -216,14 +216,14 @@ class TlsCredentialsOptions { grpc_ssl_client_certificate_request_type cert_request_type() const { return cert_request_type_; } - ::std::shared_ptr key_materials_config() const { + std::shared_ptr key_materials_config() const { return key_materials_config_; } - ::std::shared_ptr credential_reload_config() + std::shared_ptr credential_reload_config() const { return credential_reload_config_; } - ::std::shared_ptr + std::shared_ptr server_authorization_check_config() const { return server_authorization_check_config_; } @@ -234,15 +234,15 @@ class TlsCredentialsOptions { cert_request_type_ = type; } void set_key_materials_config(std::shared_ptr config) { - key_materials_config_ = ::std::move(config); + key_materials_config_ = std::move(config); } void set_credential_reload_config( - ::std::shared_ptr config) { - credential_reload_config_ = ::std::move(config); + std::shared_ptr config) { + credential_reload_config_ = std::move(config); } void set_server_authorization_check_config( - ::std::shared_ptr config) { - server_authorization_check_config_ = ::std::move(config); + std::shared_ptr config) { + server_authorization_check_config_ = std::move(config); } /** Creates C struct for TLS credential options. **/ @@ -250,9 +250,9 @@ class TlsCredentialsOptions { private: grpc_ssl_client_certificate_request_type cert_request_type_; - ::std::shared_ptr key_materials_config_; - ::std::shared_ptr credential_reload_config_; - ::std::shared_ptr + std::shared_ptr key_materials_config_; + std::shared_ptr credential_reload_config_; + std::shared_ptr server_authorization_check_config_; }; diff --git a/src/cpp/common/tls_credentials_options.cc b/src/cpp/common/tls_credentials_options.cc index 162e15d92e7..a48e9f94ba6 100644 --- a/src/cpp/common/tls_credentials_options.cc +++ b/src/cpp/common/tls_credentials_options.cc @@ -26,14 +26,13 @@ namespace experimental { /** TLS key materials config API implementation **/ void TlsKeyMaterialsConfig::set_key_materials( grpc::string pem_root_certs, - ::std::vector pem_key_cert_pair_list) { - pem_key_cert_pair_list_ = ::std::move(pem_key_cert_pair_list); - pem_root_certs_ = ::std::move(pem_root_certs); + std::vector pem_key_cert_pair_list) { + pem_key_cert_pair_list_ = std::move(pem_key_cert_pair_list); + pem_root_certs_ = std::move(pem_root_certs); } -namespace { /** Creates a new C struct for the key materials. **/ -grpc_tls_key_materials_config* c_key_materials(const ::std::shared_ptr& config) { +grpc_tls_key_materials_config* c_key_materials(const std::shared_ptr& config) { grpc_tls_key_materials_config* c_config = grpc_tls_key_materials_config_create(); ::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1> @@ -50,18 +49,18 @@ grpc_tls_key_materials_config* c_key_materials(const ::std::shared_ptr c_pem_root_certs(gpr_strdup(config->pem_root_certs().c_str())); - c_config->set_key_materials(::std::move(c_pem_root_certs), - ::std::move(c_pem_key_cert_pair_list)); + c_config->set_key_materials(std::move(c_pem_root_certs), + std::move(c_pem_key_cert_pair_list)); c_config->set_version(config->version()); return c_config; } /** Creates a new TlsKeyMaterialsConfig from a C struct config. **/ -::std::shared_ptr tls_key_materials_c_to_cpp( +std::shared_ptr tls_key_materials_c_to_cpp( const grpc_tls_key_materials_config* config) { - ::std::shared_ptr cpp_config( + std::shared_ptr cpp_config( new TlsKeyMaterialsConfig()); - ::std::vector + std::vector cpp_pem_key_cert_pair_list; grpc_tls_key_materials_config::PemKeyCertPairList pem_key_cert_pair_list = config->pem_key_cert_pair_list(); @@ -73,12 +72,11 @@ grpc_tls_key_materials_config* c_key_materials(const ::std::shared_ptrset_key_materials( - ::std::move(gpr_strdup(config->pem_root_certs())), - ::std::move(cpp_pem_key_cert_pair_list)); + std::move(gpr_strdup(config->pem_root_certs())), + std::move(cpp_pem_key_cert_pair_list)); cpp_config->set_version(config->version()); return cpp_config; } -} // namespace /** TLS credential reload arg API implementation **/ TlsCredentialReloadArg::TlsCredentialReloadArg() {} @@ -97,7 +95,7 @@ void* TlsCredentialReloadArg::cb_user_data() const { /** This function creates a new TlsKeyMaterialsConfig instance whose fields are * not shared with the corresponding key materials config fields of the * TlsCredentialReloadArg instance. **/ -::std::shared_ptr TlsCredentialReloadArg::key_materials_config() const { +std::shared_ptr TlsCredentialReloadArg::key_materials_config() const { return tls_key_materials_c_to_cpp(c_arg_.key_materials_config); } @@ -105,8 +103,8 @@ grpc_ssl_certificate_config_reload_status TlsCredentialReloadArg::status() const return c_arg_.status; } -::std::shared_ptr TlsCredentialReloadArg::error_details() const { - ::std::shared_ptr cpp_error_details(new grpc::string(c_arg_.error_details)); +std::shared_ptr TlsCredentialReloadArg::error_details() const { + std::shared_ptr cpp_error_details(new grpc::string(c_arg_.error_details)); return cpp_error_details; } @@ -115,7 +113,7 @@ void TlsCredentialReloadArg::set_cb_user_data(void* cb_user_data) { } void TlsCredentialReloadArg::set_key_materials_config( - ::std::shared_ptr key_materials_config) { + std::shared_ptr key_materials_config) { c_arg_.key_materials_config = c_key_materials(key_materials_config); } @@ -124,7 +122,7 @@ void TlsCredentialReloadArg::set_status( c_arg_.status = status; } -void TlsCredentialReloadArg::set_error_details(grpc::string error_details) { +void TlsCredentialReloadArg::set_error_details(const grpc::string& error_details) { c_arg_.error_details = gpr_strdup(error_details.c_str()); } @@ -132,11 +130,6 @@ void TlsCredentialReloadArg::callback() { c_arg_.cb(&c_arg_); } -void TlsCredentialReloadArg::callback() { - c_arg_.cb(c_arg_); -} - -namespace { /** The C schedule and cancel functions for the credential reload config. **/ int tls_credential_reload_config_c_schedule( void* config_user_data, grpc_tls_credential_reload_arg* arg) { @@ -162,7 +155,6 @@ void tls_credential_reload_config_c_cancel( arg->status = cpp_arg.status(); arg->error_details = cpp_arg.error_details()->c_str(); } -} // namespace /** gRPC TLS credential reload config API implementation **/ TlsCredentialReloadConfig::TlsCredentialReloadConfig( @@ -198,16 +190,16 @@ void* TlsServerAuthorizationCheckArg::cb_user_data() const { int TlsServerAuthorizationCheckArg::success() const { return c_arg_.success; } -::std::shared_ptr TlsServerAuthorizationCheckArg::target_name() +std::shared_ptr TlsServerAuthorizationCheckArg::target_name() const { - ::std::shared_ptr cpp_target_name( + std::shared_ptr cpp_target_name( new grpc::string(c_arg_.target_name)); return cpp_target_name; } -::std::shared_ptr TlsServerAuthorizationCheckArg::peer_cert() +std::shared_ptr TlsServerAuthorizationCheckArg::peer_cert() const { - ::std::shared_ptr cpp_peer_cert( + std::shared_ptr cpp_peer_cert( new grpc::string(c_arg_.peer_cert)); return cpp_peer_cert; } @@ -216,9 +208,9 @@ grpc_status_code TlsServerAuthorizationCheckArg::status() const { return c_arg_.status; } -::std::shared_ptr TlsServerAuthorizationCheckArg::error_details() +std::shared_ptr TlsServerAuthorizationCheckArg::error_details() const { - ::std::shared_ptr cpp_error_details( + std::shared_ptr cpp_error_details( new grpc::string(c_arg_.error_details)); return cpp_error_details; } @@ -250,7 +242,6 @@ void TlsServerAuthorizationCheckArg::set_error_details( c_arg_.error_details = gpr_strdup(error_details.c_str()); } -namespace { /** The C schedule and cancel functions for the credential reload config. **/ int tls_server_authorization_check_config_c_schedule( void* config_user_data, grpc_tls_server_authorization_check_arg* arg) { @@ -280,7 +271,6 @@ void tls_server_authorization_check_config_c_cancel( arg->status = cpp_arg.status(); arg->error_details = gpr_strdup(cpp_arg.error_details()->c_str()); } -} // namespace /** gRPC TLS server authorization check config API implementation **/ TlsServerAuthorizationCheckConfig::TlsServerAuthorizationCheckConfig( diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index e2342552d46..93aa45e05c4 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -50,9 +50,9 @@ static int tls_credential_reload_sync(void* config_user_data, GPR_ASSERT(arg != nullptr); struct TlsKeyMaterialsConfig::PemKeyCertPair pair3 = {"private_key3", "cert_chain3"}; - ::std::shared_ptr key_materials_config = + std::shared_ptr key_materials_config = arg->key_materials_config(); - ::std::vector pair_list = + std::vector pair_list = key_materials_config->pem_key_cert_pair_list(); pair_list.push_back(pair3); key_materials_config->set_key_materials("new_pem_root_certs", pair_list); @@ -257,7 +257,7 @@ TEST_F(CredentialsTest, TlsKeyMaterialsConfigCppToC) { TlsKeyMaterialsConfig config; struct TlsKeyMaterialsConfig::PemKeyCertPair pair = {"private_key", "cert_chain"}; - ::std::vector pair_list = {pair}; + std::vector pair_list = {pair}; config.set_key_materials("pem_root_certs", pair_list); grpc_tls_key_materials_config* c_config = config.c_key_materials(); EXPECT_STREQ("pem_root_certs", c_config->pem_root_certs()); @@ -286,10 +286,10 @@ TEST_F(CredentialsTest, TlsKeyMaterialsCtoCpp) { c_config.set_key_materials( ::grpc_core::UniquePtr(gpr_strdup("pem_root_certs")), pem_key_cert_pair_list); - ::std::shared_ptr cpp_config = + std::shared_ptr cpp_config = ::grpc_impl::experimental::tls_key_materials_c_to_cpp(&c_config); EXPECT_STREQ("pem_root_certs", cpp_config->pem_root_certs().c_str()); - ::std::vector cpp_pair_list = + std::vector cpp_pair_list = cpp_config->pem_key_cert_pair_list(); EXPECT_EQ(1, static_cast(cpp_pair_list.size())); EXPECT_STREQ("private_key", cpp_pair_list[0].private_key.c_str()); @@ -313,13 +313,13 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigSchedule) { nullptr, nullptr); TlsCredentialReloadArg arg; arg.set_cb_user_data(static_cast(nullptr)); - ::std::shared_ptr key_materials_config( + std::shared_ptr key_materials_config( new TlsKeyMaterialsConfig()); struct TlsKeyMaterialsConfig::PemKeyCertPair pair1 = {"private_key1", "cert_chain1"}; struct TlsKeyMaterialsConfig::PemKeyCertPair pair2 = {"private_key2", "cert_chain2"}; - ::std::vector pair_list = {pair1, + std::vector pair_list = {pair1, pair2}; key_materials_config->set_key_materials("pem_root_certs", pair_list); arg.set_key_materials_config(key_materials_config); @@ -422,11 +422,11 @@ typedef class ::grpc_impl::experimental::TlsCredentialsOptions TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) { TlsCredentialsOptions options; options.set_cert_request_type(GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY); - ::std::shared_ptr key_materials_config( + std::shared_ptr key_materials_config( new TlsKeyMaterialsConfig()); struct TlsKeyMaterialsConfig::PemKeyCertPair pair = {"private_key", "cert_chain"}; - ::std::vector pair_list = {pair}; + std::vector pair_list = {pair}; key_materials_config->set_key_materials("pem_root_certs", pair_list); options.set_key_materials_config(key_materials_config); // TODO: add instances of credential reload and server authorization check to