Imported Upstream version 1.36.0
[platform/upstream/grpc.git] / src / core / lib / security / credentials / xds / xds_credentials.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_LIB_SECURITY_CREDENTIALS_XDS_XDS_CREDENTIALS_H
20 #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_XDS_XDS_CREDENTIALS_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include <grpc/grpc_security.h>
25
26 #include "src/core/ext/xds/xds_api.h"
27 #include "src/core/lib/security/credentials/credentials.h"
28
29 namespace grpc_core {
30
31 extern const char kCredentialsTypeXds[];
32
33 class XdsCredentials final : public grpc_channel_credentials {
34  public:
35   explicit XdsCredentials(
36       RefCountedPtr<grpc_channel_credentials> fallback_credentials)
37       : grpc_channel_credentials(kCredentialsTypeXds),
38         fallback_credentials_(std::move(fallback_credentials)) {}
39
40   RefCountedPtr<grpc_channel_security_connector> create_security_connector(
41       RefCountedPtr<grpc_call_credentials> call_creds, const char* target_name,
42       const grpc_channel_args* args, grpc_channel_args** new_args) override;
43
44  private:
45   RefCountedPtr<grpc_channel_credentials> fallback_credentials_;
46 };
47
48 class XdsServerCredentials final : public grpc_server_credentials {
49  public:
50   explicit XdsServerCredentials(
51       RefCountedPtr<grpc_server_credentials> fallback_credentials)
52       : grpc_server_credentials(kCredentialsTypeXds),
53         fallback_credentials_(std::move(fallback_credentials)) {}
54
55   RefCountedPtr<grpc_server_security_connector> create_security_connector(
56       const grpc_channel_args* /* args */) override;
57
58  private:
59   RefCountedPtr<grpc_server_credentials> fallback_credentials_;
60 };
61
62 bool TestOnlyXdsVerifySubjectAlternativeNames(
63     const char* const* subject_alternative_names,
64     size_t subject_alternative_names_size,
65     const std::vector<StringMatcher>& matchers);
66
67 }  // namespace grpc_core
68
69 #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_XDS_XDS_CREDENTIALS_H */