GRPC C++  1.34.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>
26 #include <grpcpp/support/config.h>
27 
28 #include <memory>
29 #include <vector>
30 
31 // TODO(yihuazhang): remove the forward declaration here and include
32 // <grpc/grpc_security.h> directly once the insecure builds are cleaned up.
39 
40 namespace grpc {
41 namespace experimental {
42 
53  public:
59 
61  void* cb_user_data() const;
62  int success() const;
63  std::string target_name() const;
64  std::string peer_cert() const;
65  std::string peer_cert_full_chain() const;
66  grpc_status_code status() const;
67  std::string error_details() const;
68 
70  void set_cb_user_data(void* cb_user_data);
71  void set_success(int success);
72  void set_target_name(const std::string& target_name);
73  void set_peer_cert(const std::string& peer_cert);
74  void set_peer_cert_full_chain(const std::string& peer_cert_full_chain);
76  void set_error_details(const std::string& error_details);
77 
80 
81  private:
83 };
84 
92  virtual ~TlsServerAuthorizationCheckInterface() = default;
94  virtual int Schedule(TlsServerAuthorizationCheckArg* arg) = 0;
96  virtual void Cancel(TlsServerAuthorizationCheckArg* /* arg */) {}
97 };
98 
103  public:
105  std::shared_ptr<TlsServerAuthorizationCheckInterface>
106  server_authorization_check_interface);
108 
110  if (server_authorization_check_interface_ == nullptr) {
111  gpr_log(GPR_ERROR, "server authorization check interface is nullptr");
112  if (arg != nullptr) {
114  arg->set_error_details(
115  "the interface of the server authorization check config is "
116  "nullptr");
117  }
118  return 1;
119  }
120  return server_authorization_check_interface_->Schedule(arg);
121  }
122 
124  if (server_authorization_check_interface_ == nullptr) {
125  gpr_log(GPR_ERROR, "server authorization check interface is nullptr");
126  if (arg != nullptr) {
128  arg->set_error_details(
129  "the interface of the server authorization check config is "
130  "nullptr");
131  }
132  return;
133  }
134  server_authorization_check_interface_->Cancel(arg);
135  }
136 
139  return c_config_;
140  }
141 
142  private:
144  std::shared_ptr<TlsServerAuthorizationCheckInterface>
145  server_authorization_check_interface_;
146 };
147 
148 // Base class of configurable options specified by users to configure their
149 // certain security features supported in TLS. It is used for experimental
150 // purposes for now and it is subject to change.
152  public:
153  // Constructor for base class TlsCredentialsOptions.
154  //
155  // @param certificate_provider the provider which fetches TLS credentials that
156  // will be used in the TLS handshake
157  explicit TlsCredentialsOptions(
158  std::shared_ptr<CertificateProviderInterface> certificate_provider);
159  // ---- Setters for member fields ----
160  // Watches the updates of root certificates with name |root_cert_name|.
161  // If used in TLS credentials, it should always be set unless the root
162  // certificates are not needed(e.g. in the one-side TLS scenario, the server
163  // is not required to verify the client).
164  void watch_root_certs();
165  // Sets the name of root certificates being watched, if |watch_root_certs| is
166  // called. If not set, an empty string will be used as the name.
167  //
168  // @param root_cert_name the name of root certs being set.
169  void set_root_cert_name(const std::string& root_cert_name);
170  // Watches the updates of identity key-cert pairs with name
171  // |identity_cert_name|. If used in TLS credentials, it should always be set
172  // unless the identity certificates are not needed(e.g. in the one-side TLS
173  // scenario, the client is not required to provide certs).
175  // Sets the name of identity key-cert pairs being watched, if
176  // |watch_identity_key_cert_pairs| is called. If not set, an empty string will
177  // be used as the name.
178  //
179  // @param identity_cert_name the name of identity key-cert pairs being set.
180  void set_identity_cert_name(const std::string& identity_cert_name);
181 
182  // ----- Getters for member fields ----
183  // Get the internal c options. This function shall be used only internally.
185  return c_credentials_options_;
186  }
187 
188  private:
189  std::shared_ptr<CertificateProviderInterface> certificate_provider_;
190  grpc_tls_credentials_options* c_credentials_options_ = nullptr;
191 };
192 
193 // Contains configurable options on the client side.
194 // It is used for experimental purposes for now and it is subject to change.
196  public:
198  std::shared_ptr<CertificateProviderInterface> certificate_provider)
199  : TlsCredentialsOptions(std::move(certificate_provider)) {}
200 
201  // Sets the option to verify the server.
202  // The default is GRPC_TLS_SERVER_VERIFICATION.
204  grpc_tls_server_verification_option server_verification_option);
205  // Sets the custom authorization config.
207  std::shared_ptr<TlsServerAuthorizationCheckConfig>
208  authorization_check_config);
209 
210  private:
211 };
212 
213 // Contains configurable options on the server side.
214 // It is used for experimental purposes for now and it is subject to change.
216  public:
218  std::shared_ptr<CertificateProviderInterface> certificate_provider)
219  : TlsCredentialsOptions(std::move(certificate_provider)) {}
220 
221  // Sets option to request the certificates from the client.
222  // The default is GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE.
224  grpc_ssl_client_certificate_request_type cert_request_type);
225 
226  private:
227 };
228 
229 } // namespace experimental
230 } // namespace grpc
231 
232 #endif // GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H
grpc::experimental::TlsServerAuthorizationCheckConfig
TLS server authorization check config, wraps grps_tls_server_authorization_check_config.
Definition: tls_credentials_options.h:102
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:748
grpc::experimental::TlsServerAuthorizationCheckConfig::TlsServerAuthorizationCheckConfig
TlsServerAuthorizationCheckConfig(std::shared_ptr< TlsServerAuthorizationCheckInterface > server_authorization_check_interface)
grpc::experimental::TlsServerAuthorizationCheckConfig::~TlsServerAuthorizationCheckConfig
~TlsServerAuthorizationCheckConfig()
grpc::experimental::TlsServerCredentialsOptions::set_cert_request_type
void set_cert_request_type(grpc_ssl_client_certificate_request_type cert_request_type)
grpc_status_code
grpc_status_code
Definition: status.h:26
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::experimental::TlsServerAuthorizationCheckArg::error_details
std::string error_details() const
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::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::experimental::TlsCredentialsOptions::watch_root_certs
void watch_root_certs()
grpc::experimental::TlsServerAuthorizationCheckInterface::Schedule
virtual int Schedule(TlsServerAuthorizationCheckArg *arg)=0
A callback that invokes the server authorization check.
grpc::experimental::TlsServerAuthorizationCheckArg::peer_cert
std::string peer_cert() const
grpc::experimental::TlsServerAuthorizationCheckConfig::Cancel
void Cancel(TlsServerAuthorizationCheckArg *arg) const
Definition: tls_credentials_options.h:123
grpc::experimental::TlsServerCredentialsOptions::TlsServerCredentialsOptions
TlsServerCredentialsOptions(std::shared_ptr< CertificateProviderInterface > certificate_provider)
Definition: tls_credentials_options.h:217
grpc::experimental::TlsServerAuthorizationCheckArg::set_target_name
void set_target_name(const std::string &target_name)
grpc::experimental::TlsChannelCredentialsOptions::set_server_verification_option
void set_server_verification_option(grpc_tls_server_verification_option server_verification_option)
grpc::experimental::TlsServerAuthorizationCheckInterface::Cancel
virtual void Cancel(TlsServerAuthorizationCheckArg *)
A callback that cancels a server authorization check request.
Definition: tls_credentials_options.h:96
grpc::experimental::TlsCredentialsOptions::set_root_cert_name
void set_root_cert_name(const std::string &root_cert_name)
grpc::experimental::TlsServerAuthorizationCheckArg::target_name
std::string target_name() const
status.h
grpc_tls_certificate_provider
struct grpc_tls_certificate_provider grpc_tls_certificate_provider
A struct provides ways to gain credential data that will be used in the TLS handshake.
Definition: grpc_security.h:761
grpc::experimental::TlsCredentialsOptions::c_credentials_options
grpc_tls_credentials_options * c_credentials_options() const
Definition: tls_credentials_options.h:184
grpc::experimental::TlsServerAuthorizationCheckArg::~TlsServerAuthorizationCheckArg
~TlsServerAuthorizationCheckArg()
grpc::experimental::TlsChannelCredentialsOptions
Definition: tls_credentials_options.h:195
grpc::experimental::TlsServerAuthorizationCheckConfig::Schedule
int Schedule(TlsServerAuthorizationCheckArg *arg) const
Definition: tls_credentials_options.h:109
log.h
grpc::experimental::TlsServerAuthorizationCheckArg::set_peer_cert
void set_peer_cert(const std::string &peer_cert)
grpc::experimental::TlsServerAuthorizationCheckArg
TLS server authorization check arguments, wraps grpc_tls_server_authorization_check_arg.
Definition: tls_credentials_options.h:52
grpc::experimental::TlsServerAuthorizationCheckArg::set_peer_cert_full_chain
void set_peer_cert_full_chain(const std::string &peer_cert_full_chain)
grpc::experimental::TlsServerAuthorizationCheckArg::set_status
void set_status(grpc_status_code status)
grpc_ssl_client_certificate_request_type
grpc_ssl_client_certificate_request_type
Definition: grpc_security_constants.h:62
grpc::experimental::TlsCredentialsOptions::set_identity_cert_name
void set_identity_cert_name(const std::string &identity_cert_name)
grpc_tls_server_verification_option
grpc_tls_server_verification_option
Definition: grpc_security_constants.h:122
grpc::experimental::TlsServerAuthorizationCheckArg::cb_user_data
void * cb_user_data() const
Getters for member fields.
grpc::experimental::TlsCredentialsOptions::TlsCredentialsOptions
TlsCredentialsOptions(std::shared_ptr< CertificateProviderInterface > certificate_provider)
tls_certificate_provider.h
GRPC_STATUS_NOT_FOUND
@ GRPC_STATUS_NOT_FOUND
Some requested entity (e.g., file or directory) was not found.
Definition: status.h:54
grpc::experimental::TlsChannelCredentialsOptions::set_server_authorization_check_config
void set_server_authorization_check_config(std::shared_ptr< TlsServerAuthorizationCheckConfig > authorization_check_config)
grpc::experimental::TlsServerAuthorizationCheckInterface
An interface that the application derives and uses to instantiate a TlsServerAuthorizationCheckConfig...
Definition: tls_credentials_options.h:91
grpc_tls_credentials_options
struct grpc_tls_credentials_options grpc_tls_credentials_options
A struct that can be specified by callers to configure underlying TLS behaviors.
Definition: grpc_security.h:755
grpc::experimental::TlsServerAuthorizationCheckArg::set_success
void set_success(int success)
grpc::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:138
grpc::experimental::TlsServerAuthorizationCheckArg::peer_cert_full_chain
std::string peer_cert_full_chain() const
grpc::experimental::TlsServerCredentialsOptions
Definition: tls_credentials_options.h:215
grpc::experimental::TlsCredentialsOptions::watch_identity_key_cert_pairs
void watch_identity_key_cert_pairs()
config.h
grpc::experimental::TlsServerAuthorizationCheckArg::set_cb_user_data
void set_cb_user_data(void *cb_user_data)
Setters for member fields.
grpc::experimental::TlsServerAuthorizationCheckArg::OnServerAuthorizationCheckDoneCallback
void OnServerAuthorizationCheckDoneCallback()
Calls the C arg's callback function.
grpc::experimental::TlsCredentialsOptions
Definition: tls_credentials_options.h:151
std
Definition: async_unary_call.h:398
grpc_security_constants.h
grpc::experimental::TlsChannelCredentialsOptions::TlsChannelCredentialsOptions
TlsChannelCredentialsOptions(std::shared_ptr< CertificateProviderInterface > certificate_provider)
Definition: tls_credentials_options.h:197
grpc::experimental::TlsServerAuthorizationCheckInterface::~TlsServerAuthorizationCheckInterface
virtual ~TlsServerAuthorizationCheckInterface()=default
grpc::experimental::TlsServerAuthorizationCheckArg::set_error_details
void set_error_details(const std::string &error_details)
GPR_ERROR
#define GPR_ERROR
Definition: log.h:57
grpc_tls_server_authorization_check_arg
A struct containing all information necessary to schedule/cancel a server authorization check request...
Definition: grpc_security.h:932
grpc::experimental::TlsServerAuthorizationCheckArg::status
grpc_status_code status() const
grpc::experimental::TlsServerAuthorizationCheckArg::success
int success() const