GRPC C++  1.30.0
tls_credentials_options.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2019 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H
20 #define GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H
21 
23 #include <grpc/status.h>
24 #include <grpc/support/log.h>
25 #include <grpcpp/support/config.h>
26 
27 #include <memory>
28 #include <vector>
29 
38 
39 namespace grpc_impl {
40 namespace experimental {
41 
45  public:
46  struct PemKeyCertPair {
49  };
50 
52  const grpc::string pem_root_certs() const { return pem_root_certs_; }
53  const std::vector<PemKeyCertPair>& pem_key_cert_pair_list() const {
54  return pem_key_cert_pair_list_;
55  }
56  int version() const { return version_; }
57 
61  void add_pem_key_cert_pair(const PemKeyCertPair& pem_key_cert_pair);
62  void set_key_materials(
64  const std::vector<PemKeyCertPair>& pem_key_cert_pair_list);
65  void set_version(int version) { version_ = version; };
66 
67  private:
68  int version_ = 0;
69  std::vector<PemKeyCertPair> pem_key_cert_pair_list_;
70  grpc::string pem_root_certs_;
71 };
72 
82  public:
88 
90  void* cb_user_data() const;
94 
97  void set_cb_user_data(void* cb_user_data);
98  void set_pem_root_certs(const grpc::string& pem_root_certs);
100  const TlsKeyMaterialsConfig::PemKeyCertPair& pem_key_cert_pair);
101  void set_key_materials(const grpc::string& pem_root_certs,
102  std::vector<TlsKeyMaterialsConfig::PemKeyCertPair>
103  pem_key_cert_pair_list);
105  const std::shared_ptr<TlsKeyMaterialsConfig>& key_materials_config);
108 
111 
112  private:
114 };
115 
121  virtual ~TlsCredentialReloadInterface() = default;
123  virtual int Schedule(TlsCredentialReloadArg* arg) = 0;
125  virtual void Cancel(TlsCredentialReloadArg* /* arg */) {}
126 };
127 
131  public:
132  TlsCredentialReloadConfig(std::shared_ptr<TlsCredentialReloadInterface>
133  credential_reload_interface);
135 
137  if (credential_reload_interface_ == nullptr) {
138  gpr_log(GPR_ERROR, "credential reload interface is nullptr");
139  if (arg != nullptr) {
141  arg->set_error_details(
142  "the interface of the credential reload config is nullptr");
143  }
144  return 1;
145  }
146  return credential_reload_interface_->Schedule(arg);
147  }
148 
149  void Cancel(TlsCredentialReloadArg* arg) const {
150  if (credential_reload_interface_ == nullptr) {
151  gpr_log(GPR_ERROR, "credential reload interface is nullptr");
152  if (arg != nullptr) {
154  arg->set_error_details(
155  "the interface of the credential reload config is nullptr");
156  }
157  return;
158  }
159  credential_reload_interface_->Cancel(arg);
160  }
161 
163  grpc_tls_credential_reload_config* c_config() const { return c_config_; }
164 
165  private:
167  std::shared_ptr<TlsCredentialReloadInterface> credential_reload_interface_;
168 };
169 
180  public:
186 
188  void* cb_user_data() const;
189  int success() const;
190  grpc::string target_name() const;
191  grpc::string peer_cert() const;
193  grpc_status_code status() const;
194  grpc::string error_details() const;
195 
197  void set_cb_user_data(void* cb_user_data);
198  void set_success(int success);
200  void set_peer_cert(const grpc::string& peer_cert);
204 
207 
208  private:
210 };
211 
219  virtual ~TlsServerAuthorizationCheckInterface() = default;
221  virtual int Schedule(TlsServerAuthorizationCheckArg* arg) = 0;
223  virtual void Cancel(TlsServerAuthorizationCheckArg* /* arg */) {}
224 };
225 
230  public:
232  std::shared_ptr<TlsServerAuthorizationCheckInterface>
233  server_authorization_check_interface);
235 
237  if (server_authorization_check_interface_ == nullptr) {
238  gpr_log(GPR_ERROR, "server authorization check interface is nullptr");
239  if (arg != nullptr) {
241  arg->set_error_details(
242  "the interface of the server authorization check config is "
243  "nullptr");
244  }
245  return 1;
246  }
247  return server_authorization_check_interface_->Schedule(arg);
248  }
249 
251  if (server_authorization_check_interface_ == nullptr) {
252  gpr_log(GPR_ERROR, "server authorization check interface is nullptr");
253  if (arg != nullptr) {
255  arg->set_error_details(
256  "the interface of the server authorization check config is "
257  "nullptr");
258  }
259  return;
260  }
261  server_authorization_check_interface_->Cancel(arg);
262  }
263 
266  return c_config_;
267  }
268 
269  private:
271  std::shared_ptr<TlsServerAuthorizationCheckInterface>
272  server_authorization_check_interface_;
273 };
274 
280  public:
281  // Constructor for client.
282  explicit TlsCredentialsOptions(
284  std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config,
285  std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config,
286  std::shared_ptr<TlsServerAuthorizationCheckConfig>
288 
289  // Constructor for server.
290  explicit TlsCredentialsOptions(
292  std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config,
293  std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config);
294 
295  // This constructor will be deprecated.
299  std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config,
300  std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config,
301  std::shared_ptr<TlsServerAuthorizationCheckConfig>
304 
307  return cert_request_type_;
308  }
310  return server_verification_option_;
311  }
312  std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config() const {
313  return key_materials_config_;
314  }
315  std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config() const {
316  return credential_reload_config_;
317  }
318  std::shared_ptr<TlsServerAuthorizationCheckConfig>
320  return server_authorization_check_config_;
321  }
323  return c_credentials_options_;
324  }
325 
326  private:
331  grpc_ssl_client_certificate_request_type cert_request_type_;
334  grpc_tls_server_verification_option server_verification_option_;
335  std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config_;
336  std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config_;
337  std::shared_ptr<TlsServerAuthorizationCheckConfig>
338  server_authorization_check_config_;
339  grpc_tls_credentials_options* c_credentials_options_;
340 };
341 
342 } // namespace experimental
343 } // namespace grpc_impl
344 
345 #endif // GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H
grpc_impl::experimental::TlsKeyMaterialsConfig::PemKeyCertPair
Definition: tls_credentials_options.h:46
grpc_impl::experimental::TlsCredentialReloadConfig::Schedule
int Schedule(TlsCredentialReloadArg *arg) const
Definition: tls_credentials_options.h:136
grpc_impl::experimental::TlsCredentialReloadConfig
TLS credential reloag config, wraps grpc_tls_credential_reload_config.
Definition: tls_credentials_options.h:130
grpc_impl::experimental::TlsKeyMaterialsConfig::version
int version() const
Definition: tls_credentials_options.h:56
grpc_tls_server_authorization_check_config
struct grpc_tls_server_authorization_check_config grpc_tls_server_authorization_check_config
Config for TLS server authorization check.
Definition: grpc_security.h:732
grpc_impl::experimental::TlsKeyMaterialsConfig
TLS key materials config, wrapper for grpc_tls_key_materials_config.
Definition: tls_credentials_options.h:44
grpc_impl::experimental::TlsServerAuthorizationCheckConfig::c_config
grpc_tls_server_authorization_check_config * c_config() const
Returns C struct for the server authorization check config.
Definition: tls_credentials_options.h:265
grpc_impl::experimental::TlsServerAuthorizationCheckConfig::~TlsServerAuthorizationCheckConfig
~TlsServerAuthorizationCheckConfig()
grpc_impl::experimental::TlsCredentialReloadConfig::TlsCredentialReloadConfig
TlsCredentialReloadConfig(std::shared_ptr< TlsCredentialReloadInterface > credential_reload_interface)
grpc_impl::experimental::TlsServerAuthorizationCheckInterface::Cancel
virtual void Cancel(TlsServerAuthorizationCheckArg *)
A callback that cancels a server authorization check request.
Definition: tls_credentials_options.h:223
grpc_status_code
grpc_status_code
Definition: status.h:26
grpc_impl::experimental::TlsCredentialsOptions::server_verification_option
grpc_tls_server_verification_option server_verification_option() const
Definition: tls_credentials_options.h:309
grpc_impl::experimental::TlsKeyMaterialsConfig::pem_root_certs
const grpc::string pem_root_certs() const
Getters for member fields.
Definition: tls_credentials_options.h:52
grpc_impl::experimental::TlsKeyMaterialsConfig::set_pem_root_certs
void set_pem_root_certs(const grpc::string &pem_root_certs)
Setter for key materials that will be called by the user.
grpc_impl::experimental::TlsCredentialReloadArg::set_key_materials_config
void set_key_materials_config(const std::shared_ptr< TlsKeyMaterialsConfig > &key_materials_config)
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
Log a message.
grpc_impl::experimental::TlsCredentialReloadConfig::~TlsCredentialReloadConfig
~TlsCredentialReloadConfig()
grpc_impl::experimental::TlsCredentialReloadArg
TLS credential reload arguments, wraps grpc_tls_credential_reload_arg.
Definition: tls_credentials_options.h:81
grpc_impl::experimental::TlsCredentialReloadArg::set_key_materials
void set_key_materials(const grpc::string &pem_root_certs, std::vector< TlsKeyMaterialsConfig::PemKeyCertPair > pem_key_cert_pair_list)
grpc_ssl_certificate_config_reload_status
grpc_ssl_certificate_config_reload_status
Callback results for dynamically loading a SSL certificate config.
Definition: grpc_security_constants.h:56
grpc_impl::experimental::TlsServerAuthorizationCheckArg::peer_cert
grpc::string peer_cert() const
grpc_impl::experimental::TlsCredentialReloadArg::cb_user_data
void * cb_user_data() const
Getters for member fields.
grpc_impl::experimental::TlsCredentialReloadInterface
An interface that the application derives and uses to instantiate a TlsCredentialReloadConfig instanc...
Definition: tls_credentials_options.h:120
grpc_impl::experimental::TlsCredentialsOptions::TlsCredentialsOptions
TlsCredentialsOptions(grpc_tls_server_verification_option server_verification_option, std::shared_ptr< TlsKeyMaterialsConfig > key_materials_config, std::shared_ptr< TlsCredentialReloadConfig > credential_reload_config, std::shared_ptr< TlsServerAuthorizationCheckConfig > server_authorization_check_config)
grpc_impl::experimental::TlsServerAuthorizationCheckArg::set_success
void set_success(int success)
grpc_impl::experimental::TlsServerAuthorizationCheckInterface
An interface that the application derives and uses to instantiate a TlsServerAuthorizationCheckConfig...
Definition: tls_credentials_options.h:218
grpc_impl::experimental::TlsServerAuthorizationCheckArg::set_target_name
void set_target_name(const grpc::string &target_name)
grpc_impl::experimental::TlsCredentialReloadConfig::c_config
grpc_tls_credential_reload_config * c_config() const
Returns a C struct for the credential reload config.
Definition: tls_credentials_options.h:163
grpc_impl::experimental::TlsCredentialReloadArg::error_details
grpc::string error_details() const
grpc_impl::experimental::TlsCredentialReloadInterface::Schedule
virtual int Schedule(TlsCredentialReloadArg *arg)=0
A callback that invokes the credential reload.
grpc_impl::experimental::TlsServerAuthorizationCheckArg::OnServerAuthorizationCheckDoneCallback
void OnServerAuthorizationCheckDoneCallback()
Calls the C arg's callback function.
grpc_impl::experimental::TlsServerAuthorizationCheckInterface::~TlsServerAuthorizationCheckInterface
virtual ~TlsServerAuthorizationCheckInterface()=default
grpc_tls_credential_reload_config
struct grpc_tls_credential_reload_config grpc_tls_credential_reload_config
Config for TLS credential reload.
Definition: grpc_security.h:727
grpc_impl::experimental::TlsCredentialReloadArg::set_cb_user_data
void set_cb_user_data(void *cb_user_data)
Setters for member fields.
grpc_impl::experimental::TlsCredentialsOptions::cert_request_type
grpc_ssl_client_certificate_request_type cert_request_type() const
Getters for member fields.
Definition: tls_credentials_options.h:306
grpc_impl::experimental::TlsCredentialReloadInterface::Cancel
virtual void Cancel(TlsCredentialReloadArg *)
A callback that cancels a credential reload request.
Definition: tls_credentials_options.h:125
grpc_impl::experimental::TlsCredentialReloadArg::add_pem_key_cert_pair
void add_pem_key_cert_pair(const TlsKeyMaterialsConfig::PemKeyCertPair &pem_key_cert_pair)
grpc_impl::experimental::TlsKeyMaterialsConfig::PemKeyCertPair::cert_chain
grpc::string cert_chain
Definition: tls_credentials_options.h:48
grpc_impl::experimental::TlsKeyMaterialsConfig::set_version
void set_version(int version)
Definition: tls_credentials_options.h:65
grpc_impl::experimental::TlsCredentialReloadArg::set_error_details
void set_error_details(const grpc::string &error_details)
grpc_impl::experimental::TlsServerAuthorizationCheckArg::~TlsServerAuthorizationCheckArg
~TlsServerAuthorizationCheckArg()
status.h
grpc_impl::experimental::TlsCredentialsOptions::c_credentials_options
grpc_tls_credentials_options * c_credentials_options() const
Definition: tls_credentials_options.h:322
grpc_impl::experimental::TlsServerAuthorizationCheckConfig::TlsServerAuthorizationCheckConfig
TlsServerAuthorizationCheckConfig(std::shared_ptr< TlsServerAuthorizationCheckInterface > server_authorization_check_interface)
grpc_impl::experimental::TlsServerAuthorizationCheckArg::TlsServerAuthorizationCheckArg
TlsServerAuthorizationCheckArg(grpc_tls_server_authorization_check_arg *arg)
TlsServerAuthorizationCheckArg does not take ownership of the C arg passed to the constructor.
grpc_impl::experimental::TlsCredentialsOptions
TLS credentials options, wrapper for grpc_tls_credentials_options.
Definition: tls_credentials_options.h:279
grpc_impl::experimental::TlsCredentialReloadArg::~TlsCredentialReloadArg
~TlsCredentialReloadArg()
log.h
GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_FAIL
Definition: grpc_security_constants.h:59
grpc_impl::experimental::TlsServerAuthorizationCheckArg::set_peer_cert_full_chain
void set_peer_cert_full_chain(const grpc::string &peer_cert_full_chain)
grpc_impl::experimental::TlsServerAuthorizationCheckInterface::Schedule
virtual int Schedule(TlsServerAuthorizationCheckArg *arg)=0
A callback that invokes the server authorization check.
grpc_ssl_client_certificate_request_type
grpc_ssl_client_certificate_request_type
Definition: grpc_security_constants.h:62
grpc_impl::experimental::TlsCredentialReloadArg::set_pem_root_certs
void set_pem_root_certs(const grpc::string &pem_root_certs)
grpc_impl::experimental::TlsCredentialReloadArg::set_status
void set_status(grpc_ssl_certificate_config_reload_status status)
grpc_tls_server_verification_option
grpc_tls_server_verification_option
Definition: grpc_security_constants.h:122
grpc_impl::experimental::TlsServerAuthorizationCheckArg::target_name
grpc::string target_name() const
grpc_impl::experimental::TlsKeyMaterialsConfig::pem_key_cert_pair_list
const std::vector< PemKeyCertPair > & pem_key_cert_pair_list() const
Definition: tls_credentials_options.h:53
grpc_impl::experimental::TlsServerAuthorizationCheckArg::set_cb_user_data
void set_cb_user_data(void *cb_user_data)
Setters for member fields.
GRPC_STATUS_NOT_FOUND
Some requested entity (e.g., file or directory) was not found.
Definition: status.h:54
grpc_impl::experimental::TlsServerAuthorizationCheckArg::success
int success() const
grpc_tls_credentials_options
struct grpc_tls_credentials_options grpc_tls_credentials_options
TLS credentials options.
Definition: grpc_security.h:737
grpc_impl::experimental::TlsServerAuthorizationCheckArg::set_status
void set_status(grpc_status_code status)
grpc_impl::experimental::TlsServerAuthorizationCheckArg::set_peer_cert
void set_peer_cert(const grpc::string &peer_cert)
grpc_tls_credential_reload_arg
A struct containing all information necessary to schedule/cancel a credential reload request.
Definition: grpc_security.h:859
grpc_impl::experimental::TlsCredentialReloadArg::is_pem_key_cert_pair_list_empty
bool is_pem_key_cert_pair_list_empty() const
grpc_impl::experimental::TlsCredentialsOptions::credential_reload_config
std::shared_ptr< TlsCredentialReloadConfig > credential_reload_config() const
Definition: tls_credentials_options.h:315
config.h
grpc_impl::experimental::TlsCredentialReloadArg::status
grpc_ssl_certificate_config_reload_status status() const
grpc_impl::experimental::TlsCredentialsOptions::~TlsCredentialsOptions
~TlsCredentialsOptions()
grpc_security_constants.h
grpc::string
std::string string
Definition: config.h:35
grpc_impl::experimental::TlsServerAuthorizationCheckArg::cb_user_data
void * cb_user_data() const
Getters for member fields.
grpc_impl::experimental::TlsServerAuthorizationCheckArg
TLS server authorization check arguments, wraps grpc_tls_server_authorization_check_arg.
Definition: tls_credentials_options.h:179
grpc_impl
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
grpc_impl::experimental::TlsServerAuthorizationCheckConfig
TLS server authorization check config, wraps grps_tls_server_authorization_check_config.
Definition: tls_credentials_options.h:229
grpc_impl::experimental::TlsKeyMaterialsConfig::set_key_materials
void set_key_materials(const grpc::string &pem_root_certs, const std::vector< PemKeyCertPair > &pem_key_cert_pair_list)
GPR_ERROR
#define GPR_ERROR
Definition: log.h:57
grpc_impl::experimental::TlsCredentialReloadArg::TlsCredentialReloadArg
TlsCredentialReloadArg(grpc_tls_credential_reload_arg *arg)
TlsCredentialReloadArg does not take ownership of the C arg that is passed to the constructor.
grpc_tls_server_authorization_check_arg
A struct containing all information necessary to schedule/cancel a server authorization check request...
Definition: grpc_security.h:934
grpc_impl::experimental::TlsCredentialReloadInterface::~TlsCredentialReloadInterface
virtual ~TlsCredentialReloadInterface()=default
grpc_impl::experimental::TlsKeyMaterialsConfig::add_pem_key_cert_pair
void add_pem_key_cert_pair(const PemKeyCertPair &pem_key_cert_pair)
grpc_impl::experimental::TlsCredentialsOptions::server_authorization_check_config
std::shared_ptr< TlsServerAuthorizationCheckConfig > server_authorization_check_config() const
Definition: tls_credentials_options.h:319
grpc_impl::experimental::TlsCredentialReloadConfig::Cancel
void Cancel(TlsCredentialReloadArg *arg) const
Definition: tls_credentials_options.h:149
grpc_impl::experimental::TlsServerAuthorizationCheckConfig::Schedule
int Schedule(TlsServerAuthorizationCheckArg *arg) const
Definition: tls_credentials_options.h:236
grpc_impl::experimental::TlsServerAuthorizationCheckArg::set_error_details
void set_error_details(const grpc::string &error_details)
grpc_impl::experimental::TlsServerAuthorizationCheckArg::status
grpc_status_code status() const
grpc_impl::experimental::TlsServerAuthorizationCheckArg::peer_cert_full_chain
grpc::string peer_cert_full_chain() const
grpc_impl::experimental::TlsKeyMaterialsConfig::PemKeyCertPair::private_key
grpc::string private_key
Definition: tls_credentials_options.h:47
grpc_impl::experimental::TlsCredentialReloadArg::OnCredentialReloadDoneCallback
void OnCredentialReloadDoneCallback()
Calls the C arg's callback function.
grpc_impl::experimental::TlsServerAuthorizationCheckConfig::Cancel
void Cancel(TlsServerAuthorizationCheckArg *arg) const
Definition: tls_credentials_options.h:250
grpc_impl::experimental::TlsCredentialsOptions::key_materials_config
std::shared_ptr< TlsKeyMaterialsConfig > key_materials_config() const
Definition: tls_credentials_options.h:312
grpc_impl::experimental::TlsServerAuthorizationCheckArg::error_details
grpc::string error_details() const