Imported Upstream version 1.34.0
[platform/upstream/grpc.git] / src / core / ext / xds / xds_certificate_provider.h
1 //
2 //
3 // Copyright 2020 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 GRPC_CORE_EXT_XDS_XDS_CERTIFICATE_PROVIDER_H
20 #define GRPC_CORE_EXT_XDS_XDS_CERTIFICATE_PROVIDER_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h"
25
26 namespace grpc_core {
27
28 class XdsCertificateProvider : public grpc_tls_certificate_provider {
29  public:
30   XdsCertificateProvider(
31       absl::string_view root_cert_name,
32       RefCountedPtr<grpc_tls_certificate_distributor> root_cert_distributor,
33       absl::string_view identity_cert_name,
34       RefCountedPtr<grpc_tls_certificate_distributor>
35           identity_cert_distributor);
36
37   void UpdateRootCertNameAndDistributor(
38       absl::string_view root_cert_name,
39       RefCountedPtr<grpc_tls_certificate_distributor> root_cert_distributor);
40   void UpdateIdentityCertNameAndDistributor(
41       absl::string_view identity_cert_name,
42       RefCountedPtr<grpc_tls_certificate_distributor>
43           identity_cert_distributor);
44
45   grpc_core::RefCountedPtr<grpc_tls_certificate_distributor> distributor()
46       const override {
47     return distributor_;
48   }
49
50  private:
51   void WatchStatusCallback(std::string cert_name, bool root_being_watched,
52                            bool identity_being_watched);
53   void UpdateRootCertWatcher(
54       grpc_tls_certificate_distributor* root_cert_distributor);
55   void UpdateIdentityCertWatcher(
56       grpc_tls_certificate_distributor* identity_cert_distributor);
57
58   Mutex mu_;
59   bool watching_root_certs_ = false;
60   bool watching_identity_certs_ = false;
61   std::string root_cert_name_;
62   std::string identity_cert_name_;
63   RefCountedPtr<grpc_tls_certificate_distributor> root_cert_distributor_;
64   RefCountedPtr<grpc_tls_certificate_distributor> identity_cert_distributor_;
65   RefCountedPtr<grpc_tls_certificate_distributor> distributor_;
66   grpc_tls_certificate_distributor::TlsCertificatesWatcherInterface*
67       root_cert_watcher_ = nullptr;
68   grpc_tls_certificate_distributor::TlsCertificatesWatcherInterface*
69       identity_cert_watcher_ = nullptr;
70 };
71
72 }  // namespace grpc_core
73
74 #endif  // GRPC_CORE_EXT_XDS_XDS_CERTIFICATE_PROVIDER_H