• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H
20 #define GRPC_CORE_EXT_XDS_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include "src/core/ext/xds/certificate_provider_factory.h"
25 #include "src/core/lib/backoff/backoff.h"
26 #include "src/core/lib/gprpp/ref_counted.h"
27 
28 namespace grpc_core {
29 
30 class GoogleMeshCaCertificateProviderFactory
31     : public CertificateProviderFactory {
32  public:
33   class Config : public CertificateProviderFactory::Config {
34    public:
35     struct StsConfig {
36       std::string token_exchange_service_uri;
37       std::string resource;
38       std::string audience;
39       std::string scope;
40       std::string requested_token_type;
41       std::string subject_token_path;
42       std::string subject_token_type;
43       std::string actor_token_path;
44       std::string actor_token_type;
45     };
46 
47     const char* name() const override;
48 
49     std::string ToString() const override;
50 
endpoint()51     const std::string& endpoint() const { return endpoint_; }
52 
sts_config()53     const StsConfig& sts_config() const { return sts_config_; }
54 
timeout()55     grpc_millis timeout() const { return timeout_; }
56 
certificate_lifetime()57     grpc_millis certificate_lifetime() const { return certificate_lifetime_; }
58 
renewal_grace_period()59     grpc_millis renewal_grace_period() const { return renewal_grace_period_; }
60 
key_size()61     uint32_t key_size() const { return key_size_; }
62 
location()63     const std::string& location() const { return location_; }
64 
65     static RefCountedPtr<Config> Parse(const Json& config_json,
66                                        grpc_error_handle* error);
67 
68    private:
69     // Helpers for parsing the config
70     std::vector<grpc_error_handle> ParseJsonObjectStsService(
71         const Json::Object& sts_service);
72     std::vector<grpc_error_handle> ParseJsonObjectCallCredentials(
73         const Json::Object& call_credentials);
74     std::vector<grpc_error_handle> ParseJsonObjectGoogleGrpc(
75         const Json::Object& google_grpc);
76     std::vector<grpc_error_handle> ParseJsonObjectGrpcServices(
77         const Json::Object& grpc_service);
78     std::vector<grpc_error_handle> ParseJsonObjectServer(
79         const Json::Object& server);
80 
81     std::string endpoint_;
82     StsConfig sts_config_;
83     grpc_millis timeout_;
84     grpc_millis certificate_lifetime_;
85     grpc_millis renewal_grace_period_;
86     uint32_t key_size_;
87     std::string location_;
88   };
89 
90   const char* name() const override;
91 
92   RefCountedPtr<CertificateProviderFactory::Config>
93   CreateCertificateProviderConfig(const Json& config_json,
94                                   grpc_error_handle* error) override;
95 
CreateCertificateProvider(RefCountedPtr<CertificateProviderFactory::Config>)96   RefCountedPtr<grpc_tls_certificate_provider> CreateCertificateProvider(
97       RefCountedPtr<CertificateProviderFactory::Config> /*config*/) override {
98     // TODO(yashykt) : To be implemented
99     return nullptr;
100   }
101 };
102 
103 }  // namespace grpc_core
104 
105 #endif  // GRPC_CORE_EXT_XDS_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H
106