Restored tls_credentials_options.cc

pull/19778/head
Matthew Stevenson 5 years ago
parent 791e9ffa32
commit 0e65b7a20c
  1. 320
      src/cpp/common/tls_credentials_options.cc

@ -33,22 +33,26 @@ void TlsKeyMaterialsConfig::set_key_materials(
namespace { namespace {
/** Creates a new C struct for the key materials. **/ /** Creates a new C struct for the key materials. **/
grpc_tls_key_materials_config* c_key_materials(::std::shared_ptr<TlsKeyMaterialsConfig> config) { grpc_tls_key_materials_config* c_key_materials(const ::std::shared_ptr<TlsKeyMaterialsConfig>& config) {
grpc_tls_key_materials_config* c_config = grpc_tls_key_materials_config* c_config =
grpc_tls_key_materials_config_create(); grpc_tls_key_materials_config_create();
::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1> ::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1>
c_pem_key_cert_pair_list; c_pem_key_cert_pair_list;
for (auto key_cert_pair = config->pem_key_cert_pair_list().begin(); for (auto key_cert_pair = config->pem_key_cert_pair_list().begin();
key_cert_pair != config->pem_key_cert_pair_list().end(); key_cert_pair++) { key_cert_pair != config->pem_key_cert_pair_list().end(); key_cert_pair++) {
grpc_ssl_pem_key_cert_pair* ssl_pair =
(grpc_ssl_pem_key_cert_pair*)gpr_malloc(
sizeof(grpc_ssl_pem_key_cert_pair));
ssl_pair->private_key = gpr_strdup(key_cert_pair->private_key.c_str());
ssl_pair->cert_chain = gpr_strdup(key_cert_pair->cert_chain.c_str());
::grpc_core::PemKeyCertPair c_pem_key_cert_pair = ::grpc_core::PemKeyCertPair c_pem_key_cert_pair =
::grpc_core::PemKeyCertPair(key_cert_pair->private_key.c_str(), ::grpc_core::PemKeyCertPair(ssl_pair);
key_cert_pair->cert_chain.c_str());
c_pem_key_cert_pair_list.push_back(::std::move(c_pem_key_cert_pair)); c_pem_key_cert_pair_list.push_back(::std::move(c_pem_key_cert_pair));
} }
::grpc_core::UniquePtr<char> c_pem_root_certs( ::grpc_core::UniquePtr<char> c_pem_root_certs(gpr_strdup(config->pem_root_certs().c_str()));
gpr_strdup(config->pem_root_certs().c_str()));
c_config->set_key_materials(::std::move(c_pem_root_certs), c_config->set_key_materials(::std::move(c_pem_root_certs),
::std::move(c_pem_key_cert_pair_list)); ::std::move(c_pem_key_cert_pair_list));
c_config->set_version(config->version());
return c_config; return c_config;
} }
@ -71,204 +75,232 @@ grpc_tls_key_materials_config* c_key_materials(::std::shared_ptr<TlsKeyMaterials
cpp_config->set_key_materials( cpp_config->set_key_materials(
::std::move(gpr_strdup(config->pem_root_certs())), ::std::move(gpr_strdup(config->pem_root_certs())),
::std::move(cpp_pem_key_cert_pair_list)); ::std::move(cpp_pem_key_cert_pair_list));
cpp_config->set_version(config->version());
return cpp_config; return cpp_config;
} }
} // namespace } // namespace
/** TLS credential reload arg API implementation **/ /** TLS credential reload arg API implementation **/
TlsCredentialReloadArg::TlsCredentialReloadArg() {}
TlsCredentialReloadArg::TlsCredentialReloadArg(
grpc_tls_credential_reload_arg arg) {
c_arg_ = arg;
}
TlsCredentialReloadArg::~TlsCredentialReloadArg() {}
void* TlsCredentialReloadArg::cb_user_data() const { void* TlsCredentialReloadArg::cb_user_data() const {
return c_arg_->cb_user_data; return c_arg_.cb_user_data;
} }
/** This function creates a new TlsKeyMaterialsConfig instance whose fields are /** This function creates a new TlsKeyMaterialsConfig instance whose fields are
* not shared with the corresponding key materials config fields of the * not shared with the corresponding key materials config fields of the
* TlsCredentialReloadArg instance. **/ * TlsCredentialReloadArg instance. **/
::std::shared_ptr<TlsKeyMaterialsConfig> TlsCredentialReloadArg::key_materials_config() const { ::std::shared_ptr<TlsKeyMaterialsConfig> TlsCredentialReloadArg::key_materials_config() const {
return tls_key_materials_c_to_cpp(c_arg_->key_materials_config); return tls_key_materials_c_to_cpp(c_arg_.key_materials_config);
} }
grpc_ssl_certificate_config_reload_status TlsCredentialReloadArg::status() const { grpc_ssl_certificate_config_reload_status TlsCredentialReloadArg::status() const {
return c_arg_->status; return c_arg_.status;
} }
grpc::string TlsCredentialReloadArg::error_details() const { ::std::shared_ptr<grpc::string> TlsCredentialReloadArg::error_details() const {
return static_cast<grpc::string>(c_arg_->error_details); ::std::shared_ptr<grpc::string> cpp_error_details(new grpc::string(c_arg_.error_details));
return cpp_error_details;
} }
void TlsCredentialReloadArg::set_cb_user_data(void* cb_user_data) { void TlsCredentialReloadArg::set_cb_user_data(void* cb_user_data) {
c_arg_->cb_user_data = cb_user_data; c_arg_.cb_user_data = cb_user_data;
} }
void TlsCredentialReloadArg::set_key_materials_config( void TlsCredentialReloadArg::set_key_materials_config(
::std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config) { ::std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config) {
c_arg_->key_materials_config = c_key_materials(key_materials_config); c_arg_.key_materials_config = c_key_materials(key_materials_config);
} }
void TlsCredentialReloadArg::set_status( void TlsCredentialReloadArg::set_status(
grpc_ssl_certificate_config_reload_status status) { grpc_ssl_certificate_config_reload_status status) {
c_arg_->status = status; c_arg_.status = status;
} }
void TlsCredentialReloadArg::set_error_details(grpc::string error_details) { void TlsCredentialReloadArg::set_error_details(grpc::string error_details) {
c_arg_->error_details = gpr_strdup(error_details.c_str()); c_arg_.error_details = gpr_strdup(error_details.c_str());
} }
namespace { void TlsCredentialReloadArg::callback() {
/** Creates a smart pointer to a C++ version of the credential reload argument, c_arg_.cb(&c_arg_);
* with the callback function set to a nullptr. **/
::std::unique_ptr<TlsCredentialReloadArg> tls_credential_reload_arg_c_to_cpp(const grpc_tls_credential_reload_arg* arg) {
::std::unique_ptr<TlsCredentialReloadArg> cpp_arg(new TlsCredentialReloadArg());
cpp_arg->set_cb_user_data(arg->cb_user_data);
cpp_arg->set_key_materials_config(
tls_key_materials_c_to_cpp(arg->key_materials_config));
cpp_arg->set_status(arg->status);
cpp_arg->set_error_details(arg->error_details);
return cpp_arg;
} }
} // namespace
void TlsCredentialReloadArg::callback() { void TlsCredentialReloadArg::callback() {
c_arg_->cb(c_arg_); 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) {
TlsCredentialReloadConfig* cpp_config =
static_cast<TlsCredentialReloadConfig*>(arg->config->context());
TlsCredentialReloadArg cpp_arg(*arg);
int schedule_output = cpp_config->Schedule(&cpp_arg);
arg->cb_user_data = cpp_arg.cb_user_data();
arg->key_materials_config = c_key_materials(cpp_arg.key_materials_config());
arg->status = cpp_arg.status();
arg->error_details = gpr_strdup(cpp_arg.error_details()->c_str());
return schedule_output;
}
void tls_credential_reload_config_c_cancel(
void* config_user_data, grpc_tls_credential_reload_arg* arg) {
TlsCredentialReloadConfig* cpp_config =
static_cast<TlsCredentialReloadConfig*>(arg->config->context());
TlsCredentialReloadArg cpp_arg(*arg);
cpp_config->Cancel(&cpp_arg);
arg->cb_user_data = cpp_arg.cb_user_data();
arg->key_materials_config = c_key_materials(cpp_arg.key_materials_config());
arg->status = cpp_arg.status();
arg->error_details = cpp_arg.error_details()->c_str();
}
} // namespace
/** gRPC TLS credential reload config API implementation **/ /** gRPC TLS credential reload config API implementation **/
TlsCredentialReloadConfig::TlsCredentialReloadConfig( TlsCredentialReloadConfig::TlsCredentialReloadConfig(
const void* config_user_data, const void* config_user_data,
int (*schedule)(void* config_user_data, TlsCredentialReloadArg* arg), int (*schedule)(void* config_user_data, TlsCredentialReloadArg* arg),
void (*cancel)(void* config_user_data, TlsCredentialReloadArg* arg), void (*cancel)(void* config_user_data, TlsCredentialReloadArg* arg),
void (*destruct)(void* config_user_data)) void (*destruct)(void* config_user_data)) {
: config_user_data_(const_cast<void*>(config_user_data)), config_user_data_ = const_cast<void*>(config_user_data);
schedule_(schedule), schedule_ = schedule;
cancel_(cancel), cancel_ = cancel;
destruct_(destruct) {} destruct_ = destruct;
c_config_ = grpc_tls_credential_reload_config_create(
config_user_data_, &tls_credential_reload_config_c_schedule,
&tls_credential_reload_config_c_cancel, destruct_);
c_config_->set_context(static_cast<void*>(this));
}
TlsCredentialReloadConfig::~TlsCredentialReloadConfig() {} TlsCredentialReloadConfig::~TlsCredentialReloadConfig() {}
grpc_tls_credential_reload_config* /** gRPC TLS server authorization check arg API implementation **/
TlsCredentialReloadConfig::c_credential_reload() const { TlsServerAuthorizationCheckArg::TlsServerAuthorizationCheckArg() {}
typedef int (*grpcpp_tls_credential_reload_schedule)(
void* config_user_data, TlsCredentialReloadArg* arg); TlsServerAuthorizationCheckArg::TlsServerAuthorizationCheckArg(
grpcpp_tls_credential_reload_schedule cpp_schedule = schedule_; grpc_tls_server_authorization_check_arg arg) {
typedef int (*grpc_tls_credential_reload_schedule)( c_arg_ = arg;
void* config_user_data, grpc_tls_credential_reload_arg* arg);
std::function<int(void*, grpc_tls_credential_reload_arg*)> c_schedule =
[cpp_schedule](void* config_user_data,
grpc_tls_credential_reload_arg* arg) {
return cpp_schedule(config_user_data,
tls_credential_reload_arg_c_to_cpp(arg).get());
};
typedef void (*grpcpp_tls_credential_reload_cancel)(
void* config_user_data, TlsCredentialReloadArg* arg);
grpcpp_tls_credential_reload_cancel cpp_cancel = cancel_;
typedef void (*grpc_tls_credential_reload_cancel)(
void* config_user_data, grpc_tls_credential_reload_arg* arg);
std::function<void(void*, grpc_tls_credential_reload_arg*)> c_cancel =
[cpp_cancel](void* config_user_data,
grpc_tls_credential_reload_arg* arg) {
return cpp_cancel(config_user_data,
tls_credential_reload_arg_c_to_cpp(arg).get());
};
grpc_tls_credential_reload_config* c_config =
grpc_tls_credential_reload_config_create(
const_cast<void*>(config_user_data_),
*(c_schedule.target<grpc_tls_credential_reload_schedule>()),
*(c_cancel.target<grpc_tls_credential_reload_cancel>()), destruct_);
return c_config;
} }
/** gRPC TLS server authorization check arg API implementation **/ TlsServerAuthorizationCheckArg::~TlsServerAuthorizationCheckArg() {}
void* TlsServerAuthorizationCheckArg::cb_user_data() const {
return c_arg_.cb_user_data;
}
int TlsServerAuthorizationCheckArg::success() const { return c_arg_.success; }
::std::shared_ptr<grpc::string> TlsServerAuthorizationCheckArg::target_name()
const {
::std::shared_ptr<grpc::string> cpp_target_name(
new grpc::string(c_arg_.target_name));
return cpp_target_name;
}
::std::shared_ptr<grpc::string> TlsServerAuthorizationCheckArg::peer_cert()
const {
::std::shared_ptr<grpc::string> cpp_peer_cert(
new grpc::string(c_arg_.peer_cert));
return cpp_peer_cert;
}
::std::unique_ptr<TlsServerAuthorizationCheckArg> grpc_status_code TlsServerAuthorizationCheckArg::status() const {
tls_server_authorization_check_arg_c_to_cpp( return c_arg_.status;
const grpc_tls_server_authorization_check_arg* arg) {
::std::unique_ptr<TlsServerAuthorizationCheckArg> cpp_arg(
new TlsServerAuthorizationCheckArg());
cpp_arg->set_cb(
static_cast<grpcpp_tls_on_server_authorization_check_done_cb>(nullptr));
cpp_arg->set_cb_user_data(arg->cb_user_data);
cpp_arg->set_success(arg->success);
cpp_arg->set_target_name(arg->target_name);
cpp_arg->set_peer_cert(arg->peer_cert);
cpp_arg->set_status(arg->status);
cpp_arg->set_error_details(arg->error_details);
return cpp_arg;
}
grpc_tls_on_server_authorization_check_done_cb
TlsServerAuthorizationCheckArg::c_callback() const {
grpcpp_tls_on_server_authorization_check_done_cb cpp_cb = cb_;
std::function<void(grpc_tls_server_authorization_check_arg*)> c_cb =
[cpp_cb](grpc_tls_server_authorization_check_arg* arg) {
return cpp_cb(tls_server_authorization_check_arg_c_to_cpp(arg).get());
};
return *(c_cb.target<grpc_tls_on_server_authorization_check_done_cb>());
}
grpc_tls_server_authorization_check_arg*
TlsServerAuthorizationCheckArg::c_server_authorization_check_arg() const {
grpc_tls_server_authorization_check_arg* c_arg =
new grpc_tls_server_authorization_check_arg();
c_arg->cb = this->c_callback();
c_arg->cb_user_data = cb_user_data_;
c_arg->success = success_;
c_arg->target_name = gpr_strdup(target_name_.c_str());
c_arg->peer_cert = gpr_strdup(peer_cert_.c_str());
c_arg->status = status_;
c_arg->error_details = gpr_strdup(error_details_.c_str());
return c_arg;
} }
::std::shared_ptr<grpc::string> TlsServerAuthorizationCheckArg::error_details()
const {
::std::shared_ptr<grpc::string> cpp_error_details(
new grpc::string(c_arg_.error_details));
return cpp_error_details;
}
void TlsServerAuthorizationCheckArg::set_cb_user_data(void* cb_user_data) {
c_arg_.cb_user_data = cb_user_data;
}
void TlsServerAuthorizationCheckArg::set_success(int success) {
c_arg_.success = success;
}
void TlsServerAuthorizationCheckArg::set_target_name(
const grpc::string& target_name) {
c_arg_.target_name = gpr_strdup(target_name.c_str());
}
void TlsServerAuthorizationCheckArg::set_peer_cert(
const grpc::string& peer_cert) {
c_arg_.peer_cert = gpr_strdup(peer_cert.c_str());
}
void TlsServerAuthorizationCheckArg::set_status(grpc_status_code status) {
c_arg_.status = status;
}
void TlsServerAuthorizationCheckArg::set_error_details(
const grpc::string& 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) {
TlsServerAuthorizationCheckConfig* cpp_config =
static_cast<TlsServerAuthorizationCheckConfig*>(arg->config->context());
TlsServerAuthorizationCheckArg cpp_arg(*arg);
int schedule_output = cpp_config->Schedule(&cpp_arg);
arg->cb_user_data = cpp_arg.cb_user_data();
arg->success = cpp_arg.success();
arg->target_name = gpr_strdup(cpp_arg.target_name()->c_str());
arg->peer_cert = gpr_strdup(cpp_arg.peer_cert()->c_str());
arg->status = cpp_arg.status();
arg->error_details = gpr_strdup(cpp_arg.error_details()->c_str());
return schedule_output;
}
void tls_server_authorization_check_config_c_cancel(
void* config_user_data, grpc_tls_server_authorization_check_arg* arg) {
TlsServerAuthorizationCheckConfig* cpp_config =
static_cast<TlsServerAuthorizationCheckConfig*>(arg->config->context());
TlsServerAuthorizationCheckArg cpp_arg(*arg);
cpp_config->Cancel(&cpp_arg);
arg->cb_user_data = cpp_arg.cb_user_data();
arg->success = cpp_arg.success();
arg->target_name = gpr_strdup(cpp_arg.target_name()->c_str());
arg->peer_cert = gpr_strdup(cpp_arg.peer_cert()->c_str());
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 **/ /** gRPC TLS server authorization check config API implementation **/
TlsServerAuthorizationCheckConfig::TlsServerAuthorizationCheckConfig( TlsServerAuthorizationCheckConfig::TlsServerAuthorizationCheckConfig(
const void* config_user_data, const void* config_user_data,
int (*schedule)(void* config_user_data, int (*schedule)(void* config_user_data,
TlsServerAuthorizationCheckArg* arg), TlsServerAuthorizationCheckArg* arg),
void (*cancel)(void* config_user_data, TlsServerAuthorizationCheckArg* arg), void (*cancel)(void* config_user_data, TlsServerAuthorizationCheckArg* arg),
void (*destruct)(void* config_user_data)) void (*destruct)(void* config_user_data)) {
: config_user_data_(const_cast<void*>(config_user_data)), config_user_data_ = const_cast<void*>(config_user_data);
schedule_(schedule), schedule_ = schedule;
cancel_(cancel), cancel_ = cancel;
destruct_(destruct) {} destruct_ = destruct;
c_config_ = grpc_tls_server_authorization_check_config_create(
config_user_data_, &tls_server_authorization_check_config_c_schedule,
&tls_server_authorization_check_config_c_cancel, destruct_);
c_config_->set_context(static_cast<void*>(this));
}
TlsServerAuthorizationCheckConfig::~TlsServerAuthorizationCheckConfig() {}
grpc_tls_server_authorization_check_config* TlsServerAuthorizationCheckConfig::~TlsServerAuthorizationCheckConfig() {}
TlsServerAuthorizationCheckConfig::c_server_authorization_check() const {
typedef int (*grpcpp_tls_server_authorization_check_schedule)(
void* config_user_data, TlsServerAuthorizationCheckArg* arg);
grpcpp_tls_server_authorization_check_schedule cpp_schedule = schedule_;
typedef int (*grpc_tls_server_authorization_check_schedule)(
void* config_user_data, grpc_tls_server_authorization_check_arg* arg);
std::function<int(void*, grpc_tls_server_authorization_check_arg*)>
c_schedule =
[cpp_schedule](void* config_user_data,
grpc_tls_server_authorization_check_arg* arg) {
return cpp_schedule(
config_user_data,
tls_server_authorization_check_arg_c_to_cpp(arg).get());
};
typedef void (*grpcpp_tls_server_authorization_check_cancel)(
void* config_user_data, TlsServerAuthorizationCheckArg* arg);
grpcpp_tls_server_authorization_check_cancel cpp_cancel = cancel_;
typedef void (*grpc_tls_server_authorization_check_cancel)(
void* config_user_data, grpc_tls_server_authorization_check_arg* arg);
std::function<void(void*, grpc_tls_server_authorization_check_arg*)>
c_cancel = [cpp_cancel](void* config_user_data,
grpc_tls_server_authorization_check_arg* arg) {
return cpp_cancel(
config_user_data,
tls_server_authorization_check_arg_c_to_cpp(arg).get());
};
grpc_tls_server_authorization_check_config* c_config =
grpc_tls_server_authorization_check_config_create(
const_cast<void*>(config_user_data_),
*(c_schedule.target<grpc_tls_server_authorization_check_schedule>()),
*(c_cancel.target<grpc_tls_server_authorization_check_cancel>()),
destruct_);
return c_config;
}
/** gRPC TLS credential options API implementation **/ /** gRPC TLS credential options API implementation **/
grpc_tls_credentials_options* TlsCredentialsOptions::c_credentials_options() grpc_tls_credentials_options* TlsCredentialsOptions::c_credentials_options()

Loading…
Cancel
Save