GRPC C++  1.80.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 
22 #include <grpc/grpc_security.h>
24 #include <grpc/status.h>
28 #include <grpcpp/support/config.h>
29 
30 #include <memory>
31 #include <vector>
32 
33 namespace grpc {
34 namespace experimental {
35 
36 // Base class of configurable options specified by users to configure their
37 // certain security features supported in TLS. It is used for experimental
38 // purposes for now and it is subject to change.
40  public:
41  // Constructor for base class TlsCredentialsOptions.
42  //
43  // @param certificate_provider the provider which fetches TLS credentials that
44  // will be used in the TLS handshake
47 
48  // Copy constructor does a deep copy of the underlying pointer. No assignment
49  // permitted
52 
53  // ---- Setters for member fields ----
54  // Sets the certificate provider used to store root certs and identity certs.
55  [[deprecated(
56  "Use set_root_certificate_provider() or "
57  "set_identity_certificate_provider() instead.")]]
59  std::shared_ptr<CertificateProviderInterface> certificate_provider);
61  std::shared_ptr<CertificateProviderInterface> certificate_provider);
63  std::shared_ptr<CertificateProviderInterface> certificate_provider);
64  // Watches the updates of root certificates with name |root_cert_name|.
65  // If used in TLS credentials, setting this field is optional for both the
66  // client side and the server side.
67  // If this is not set on the client side, we will use the root certificates
68  // stored in the default system location, since client side must provide root
69  // certificates in TLS(no matter single-side TLS or mutual TLS).
70  // If this is not set on the server side, we will not watch any root
71  // certificate updates, and assume no root certificates needed for the server
72  // (in the one-side TLS scenario, the server is not required to provide root
73  // certs). We don't support default root certs on server side.
74  [[deprecated("Use set_root_certificate_provider()")]]
75  void watch_root_certs();
76  // Sets the name of root certificates being watched, if |watch_root_certs| is
77  // called. If not set, an empty string will be used as the name.
78  //
79  // @param root_cert_name the name of root certs being set.
80  void set_root_cert_name(const std::string& root_cert_name);
81  // Watches the updates of identity key-cert pairs with name
82  // |identity_cert_name|. If used in TLS credentials, it is required to be set
83  // on the server side, and optional for the client side(in the one-side
84  // TLS scenario, the client is not required to provide identity certs).
85  [[deprecated("Use set_identity_certificate_provider()")]]
87  // Sets the name of identity key-cert pairs being watched, if
88  // |watch_identity_key_cert_pairs| is called. If not set, an empty string will
89  // be used as the name.
90  //
91  // @param identity_cert_name the name of identity key-cert pairs being set.
92  void set_identity_cert_name(const std::string& identity_cert_name);
93  // Sets the Tls session key logging configuration. If not set, tls
94  // session key logging is disabled. Note that this should be used only for
95  // debugging purposes. It should never be used in a production environment
96  // due to security concerns.
97  //
98  // @param tls_session_key_log_file_path: Path where tls session keys would
99  // be logged.
101  const std::string& tls_session_key_log_file_path);
102  // Sets the certificate verifier used to perform post-handshake peer identity
103  // checks.
105  std::shared_ptr<CertificateVerifier> certificate_verifier);
106  // Sets the options of whether to check the hostname of the peer on a per-call
107  // basis. This is usually used in a combination with virtual hosting at the
108  // client side, where each individual call on a channel can have a different
109  // host associated with it.
110  // This check is intended to verify that the host specified for the individual
111  // call is covered by the cert that the peer presented.
112  // We will perform such checks by default. This should be disabled if
113  // verifiers other than the host name verifier is used.
114  // Deprecated: This function will be removed in the 1.66 release. This will be
115  // replaced by and handled within the custom verifier settings.
116  void set_check_call_host(bool check_call_host);
117 
118  // Deprecated in favor of set_crl_provider. The
119  // crl provider interface provides a significantly more flexible approach to
120  // using CRLs. See gRFC A69 for details.
121  // If set, gRPC will read all hashed x.509 CRL files in the directory and
122  // enforce the CRL files on all TLS handshakes. Only supported for OpenSSL
123  // version > 1.1.
124  // Deprecated: This function will be removed in the 1.66 release. Use the
125  // set_crl_provider function instead.
126  void set_crl_directory(const std::string& path);
127 
128  void set_crl_provider(std::shared_ptr<CrlProvider> crl_provider);
129 
130  // Sets the minimum TLS version that will be negotiated during the TLS
131  // handshake. If not set, the underlying SSL library will use TLS v1.2.
132  // @param tls_version: The minimum TLS version.
133  void set_min_tls_version(grpc_tls_version tls_version);
134  // Sets the maximum TLS version that will be negotiated during the TLS
135  // handshake. If not set, the underlying SSL library will use TLS v1.3.
136  // @param tls_version: The maximum TLS version.
137  void set_max_tls_version(grpc_tls_version tls_version);
138 
139  // ----- Getters for member fields ----
140  // Returns a deep copy of the internal c options. The caller takes ownership
141  // of the returned pointer. This function shall be used only internally.
143 
144  protected:
145  // Returns the internal c options. The caller does not take ownership of
146  // the returned pointer.
148  return c_credentials_options_;
149  }
150 
151  private:
152  std::shared_ptr<CertificateProviderInterface> legacy_certificate_provider_;
153  std::shared_ptr<CertificateProviderInterface> root_certificate_provider_;
154  std::shared_ptr<CertificateProviderInterface> identity_certificate_provider_;
155  std::shared_ptr<CertificateVerifier> certificate_verifier_;
156  grpc_tls_credentials_options* c_credentials_options_ = nullptr;
157  bool is_watching_roots_ = false;
158  bool is_watching_identity_ = false;
159 };
160 
161 // Contains configurable options on the client side.
162 // Client side doesn't need to always use certificate provider. When the
163 // certificate provider is not set, we will use the root certificates stored
164 // in the system default locations, and assume client won't provide any
165 // identity certificates(single side TLS).
166 // It is used for experimental purposes for now and it is subject to change.
168  public:
169  // Sets the decision of whether to do a crypto check on the server certs.
170  // The default is true.
171  void set_verify_server_certs(bool verify_server_certs);
172 
173  // Overrides the SNI that the client sends in the TLS handshake. nullopt
174  // indicates that SNI should not be overridden. An empty string value
175  // indicates that SNI should not be sent at all. The default is nullopt.
176  void set_sni_override(std::optional<std::string> sni_override);
177 
178  private:
179 };
180 
181 // Contains configurable options on the server side.
182 // It is used for experimental purposes for now and it is subject to change.
184  public:
185  // Server side is required to use an identity provider, because server always
186  // needs to use identity certs.
187  static absl::StatusOr<TlsServerCredentialsOptions> Create(
188  std::shared_ptr<CertificateProviderInterface>
189  identity_certificate_provider) {
190  if (identity_certificate_provider == nullptr) {
191  return absl::InvalidArgumentError(
192  "identity certificate provider must be non-null");
193  }
196  std::move(identity_certificate_provider));
197  return options;
198  }
199 
200  [[deprecated("Use Create() instead.")]]
202  std::shared_ptr<CertificateProviderInterface> certificate_provider)
204  set_certificate_provider(certificate_provider);
205  }
206 
207  // Sets option to request the certificates from the client.
208  // The default is GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE.
210  grpc_ssl_client_certificate_request_type cert_request_type);
211 
212  // Sets whether or not a TLS server should send a list of CA names in the
213  // ServerHello. This list of CA names is read from the server's trust bundle,
214  // so that the client can use this list as a hint to know which certificate it
215  // should send to the server.
216  //
217  // By default, this option is turned off.
218  //
219  // WARNING: This API is extremely dangerous and should not be used. If the
220  // server's trust bundle is too large, then the TLS server will be unable to
221  // form a ServerHello, and hence will be unusable.
222  // Deprecated: This function will be removed in the 1.66 release.
223  void set_send_client_ca_list(bool send_client_ca_list);
224 
225  private:
226  // Default ctor, to be used by Create().
227  TlsServerCredentialsOptions() = default;
228 };
229 
230 } // namespace experimental
231 } // namespace grpc
232 
233 #endif // GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H
grpc::experimental::TlsServerCredentialsOptions::set_cert_request_type
void set_cert_request_type(grpc_ssl_client_certificate_request_type cert_request_type)
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::experimental::TlsCredentialsOptions::watch_root_certs
void watch_root_certs()
grpc::experimental::TlsCredentialsOptions::set_check_call_host
void set_check_call_host(bool check_call_host)
grpc::experimental::TlsChannelCredentialsOptions::set_sni_override
void set_sni_override(std::optional< std::string > sni_override)
grpc::experimental::TlsServerCredentialsOptions::TlsServerCredentialsOptions
TlsServerCredentialsOptions(std::shared_ptr< CertificateProviderInterface > certificate_provider)
Definition: tls_credentials_options.h:201
grpc::experimental::TlsCredentialsOptions::set_crl_provider
void set_crl_provider(std::shared_ptr< CrlProvider > crl_provider)
grpc_security.h
grpc::experimental::TlsCredentialsOptions::set_root_cert_name
void set_root_cert_name(const std::string &root_cert_name)
grpc::experimental::TlsCredentialsOptions::set_root_certificate_provider
void set_root_certificate_provider(std::shared_ptr< CertificateProviderInterface > certificate_provider)
status.h
grpc::experimental::TlsCredentialsOptions::set_certificate_provider
void set_certificate_provider(std::shared_ptr< CertificateProviderInterface > certificate_provider)
grpc::experimental::TlsCredentialsOptions::c_credentials_options
grpc_tls_credentials_options * c_credentials_options() const
grpc::experimental::TlsChannelCredentialsOptions
Definition: tls_credentials_options.h:167
tls_crl_provider.h
grpc::experimental::TlsCredentialsOptions::set_max_tls_version
void set_max_tls_version(grpc_tls_version tls_version)
grpc::experimental::TlsCredentialsOptions::mutable_c_credentials_options
grpc_tls_credentials_options * mutable_c_credentials_options()
Definition: tls_credentials_options.h:147
grpc::experimental::TlsServerCredentialsOptions::Create
static absl::StatusOr< TlsServerCredentialsOptions > Create(std::shared_ptr< CertificateProviderInterface > identity_certificate_provider)
Definition: tls_credentials_options.h:187
grpc_ssl_client_certificate_request_type
grpc_ssl_client_certificate_request_type
Definition: grpc_security_constants.h:79
tls_certificate_verifier.h
grpc_tls_version
grpc_tls_version
The TLS versions that are supported by the SSL stack.
Definition: grpc_security_constants.h:146
grpc::experimental::TlsCredentialsOptions::~TlsCredentialsOptions
~TlsCredentialsOptions()
grpc::experimental::TlsCredentialsOptions::set_identity_cert_name
void set_identity_cert_name(const std::string &identity_cert_name)
tls_certificate_provider.h
grpc::experimental::TlsChannelCredentialsOptions::set_verify_server_certs
void set_verify_server_certs(bool verify_server_certs)
grpc::experimental::TlsServerCredentialsOptions::set_send_client_ca_list
void set_send_client_ca_list(bool send_client_ca_list)
grpc::experimental::TlsCredentialsOptions::TlsCredentialsOptions
TlsCredentialsOptions()
grpc::experimental::TlsCredentialsOptions::set_min_tls_version
void set_min_tls_version(grpc_tls_version tls_version)
grpc::experimental::TlsServerCredentialsOptions
Definition: tls_credentials_options.h:183
grpc::experimental::TlsCredentialsOptions::watch_identity_key_cert_pairs
void watch_identity_key_cert_pairs()
config.h
grpc::experimental::TlsCredentialsOptions::set_tls_session_key_log_file_path
void set_tls_session_key_log_file_path(const std::string &tls_session_key_log_file_path)
grpc::experimental::TlsCredentialsOptions
Definition: tls_credentials_options.h:39
grpc_security_constants.h
grpc_tls_credentials_options
struct grpc_tls_credentials_options grpc_tls_credentials_options
EXPERIMENTAL API - Subject to change.
Definition: credentials.h:598
grpc::experimental::TlsCredentialsOptions::set_certificate_verifier
void set_certificate_verifier(std::shared_ptr< CertificateVerifier > certificate_verifier)
grpc::experimental::TlsCredentialsOptions::operator=
TlsCredentialsOptions & operator=(const TlsCredentialsOptions &other)=delete
grpc::experimental::TlsCredentialsOptions::set_identity_certificate_provider
void set_identity_certificate_provider(std::shared_ptr< CertificateProviderInterface > certificate_provider)
grpc::experimental::TlsCredentialsOptions::set_crl_directory
void set_crl_directory(const std::string &path)