• 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_SRC_CORE_LIB_SECURITY_CREDENTIALS_XDS_XDS_CREDENTIALS_H
20 #define GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_XDS_XDS_CREDENTIALS_H
21 
22 #include <grpc/credentials.h>
23 #include <grpc/grpc.h>
24 #include <grpc/grpc_security.h>
25 #include <grpc/support/port_platform.h>
26 #include <stddef.h>
27 
28 #include <functional>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 #include "absl/status/status.h"
34 #include "src/core/lib/channel/channel_args.h"
35 #include "src/core/lib/security/credentials/credentials.h"
36 #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.h"
37 #include "src/core/lib/security/security_connector/security_connector.h"
38 #include "src/core/util/matchers.h"
39 #include "src/core/util/ref_counted_ptr.h"
40 #include "src/core/util/unique_type_name.h"
41 #include "src/core/xds/grpc/xds_certificate_provider.h"
42 
43 namespace grpc_core {
44 
45 class XdsCertificateVerifier : public grpc_tls_certificate_verifier {
46  public:
47   explicit XdsCertificateVerifier(
48       RefCountedPtr<XdsCertificateProvider> xds_certificate_provider);
49 
50   bool Verify(grpc_tls_custom_verification_check_request* request,
51               std::function<void(absl::Status)>,
52               absl::Status* sync_status) override;
53   void Cancel(grpc_tls_custom_verification_check_request*) override;
54 
55   UniqueTypeName type() const override;
56 
57  private:
58   int CompareImpl(const grpc_tls_certificate_verifier* other) const override;
59 
60   RefCountedPtr<XdsCertificateProvider> xds_certificate_provider_;
61 };
62 
63 class XdsCredentials final : public grpc_channel_credentials {
64  public:
XdsCredentials(RefCountedPtr<grpc_channel_credentials> fallback_credentials)65   explicit XdsCredentials(
66       RefCountedPtr<grpc_channel_credentials> fallback_credentials)
67       : fallback_credentials_(std::move(fallback_credentials)) {}
68 
69   RefCountedPtr<grpc_channel_security_connector> create_security_connector(
70       RefCountedPtr<grpc_call_credentials> call_creds, const char* target_name,
71       ChannelArgs* args) override;
72 
73   static UniqueTypeName Type();
74 
type()75   UniqueTypeName type() const override { return Type(); }
76 
77  private:
cmp_impl(const grpc_channel_credentials * other)78   int cmp_impl(const grpc_channel_credentials* other) const override {
79     auto* o = static_cast<const XdsCredentials*>(other);
80     return fallback_credentials_->cmp(o->fallback_credentials_.get());
81   }
82 
83   RefCountedPtr<grpc_channel_credentials> fallback_credentials_;
84 };
85 
86 class XdsServerCredentials final : public grpc_server_credentials {
87  public:
XdsServerCredentials(RefCountedPtr<grpc_server_credentials> fallback_credentials)88   explicit XdsServerCredentials(
89       RefCountedPtr<grpc_server_credentials> fallback_credentials)
90       : fallback_credentials_(std::move(fallback_credentials)) {}
91 
92   RefCountedPtr<grpc_server_security_connector> create_security_connector(
93       const ChannelArgs& /* args */) override;
94 
95   static UniqueTypeName Type();
96 
type()97   UniqueTypeName type() const override { return Type(); }
98 
99  private:
100   RefCountedPtr<grpc_server_credentials> fallback_credentials_;
101 };
102 
103 bool TestOnlyXdsVerifySubjectAlternativeNames(
104     const char* const* subject_alternative_names,
105     size_t subject_alternative_names_size,
106     const std::vector<StringMatcher>& matchers);
107 
108 }  // namespace grpc_core
109 
110 #endif  // GRPC_SRC_CORE_LIB_SECURITY_CREDENTIALS_XDS_XDS_CREDENTIALS_H
111