• 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_SECURITY_CONNECTOR_INSECURE_INSECURE_SECURITY_CONNECTOR_H
20 #define GRPC_SRC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_INSECURE_INSECURE_SECURITY_CONNECTOR_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 
27 #include <utility>
28 
29 #include "absl/status/status.h"
30 #include "absl/strings/string_view.h"
31 #include "src/core/handshaker/handshaker.h"
32 #include "src/core/lib/channel/channel_args.h"
33 #include "src/core/lib/iomgr/closure.h"
34 #include "src/core/lib/iomgr/endpoint.h"
35 #include "src/core/lib/iomgr/error.h"
36 #include "src/core/lib/iomgr/iomgr_fwd.h"
37 #include "src/core/lib/promise/arena_promise.h"
38 #include "src/core/lib/security/credentials/credentials.h"
39 #include "src/core/lib/security/security_connector/security_connector.h"
40 #include "src/core/tsi/transport_security_interface.h"
41 #include "src/core/util/ref_counted_ptr.h"
42 
43 namespace grpc_core {
44 
45 extern const char kInsecureTransportSecurityType[];
46 
47 // Exposed for testing purposes only.
48 // Create an auth context which is necessary to pass the santiy check in
49 // client_auth_filter that verifies if the peer's auth context is obtained
50 // during handshakes.
51 RefCountedPtr<grpc_auth_context> TestOnlyMakeInsecureAuthContext();
52 
53 class InsecureChannelSecurityConnector
54     : public grpc_channel_security_connector {
55  public:
InsecureChannelSecurityConnector(RefCountedPtr<grpc_channel_credentials> channel_creds,RefCountedPtr<grpc_call_credentials> request_metadata_creds)56   InsecureChannelSecurityConnector(
57       RefCountedPtr<grpc_channel_credentials> channel_creds,
58       RefCountedPtr<grpc_call_credentials> request_metadata_creds)
59       : grpc_channel_security_connector("", std::move(channel_creds),
60                                         std::move(request_metadata_creds)) {}
61 
62   ArenaPromise<absl::Status> CheckCallHost(
63       absl::string_view host, grpc_auth_context* auth_context) override;
64 
65   void add_handshakers(const ChannelArgs& args,
66                        grpc_pollset_set* /* interested_parties */,
67                        HandshakeManager* handshake_manager) override;
68 
69   void check_peer(tsi_peer peer, grpc_endpoint* ep, const ChannelArgs& /*args*/,
70                   RefCountedPtr<grpc_auth_context>* auth_context,
71                   grpc_closure* on_peer_checked) override;
72 
cancel_check_peer(grpc_closure *,grpc_error_handle)73   void cancel_check_peer(grpc_closure* /*on_peer_checked*/,
74                          grpc_error_handle /*error*/) override {}
75 
76   int cmp(const grpc_security_connector* other_sc) const override;
77 };
78 
79 class InsecureServerSecurityConnector : public grpc_server_security_connector {
80  public:
InsecureServerSecurityConnector(RefCountedPtr<grpc_server_credentials> server_creds)81   explicit InsecureServerSecurityConnector(
82       RefCountedPtr<grpc_server_credentials> server_creds)
83       : grpc_server_security_connector("" /* url_scheme */,
84                                        std::move(server_creds)) {}
85 
86   void add_handshakers(const ChannelArgs& args,
87                        grpc_pollset_set* /* interested_parties */,
88                        HandshakeManager* handshake_manager) override;
89 
90   void check_peer(tsi_peer peer, grpc_endpoint* ep, const ChannelArgs& /*args*/,
91                   RefCountedPtr<grpc_auth_context>* auth_context,
92                   grpc_closure* on_peer_checked) override;
93 
cancel_check_peer(grpc_closure *,grpc_error_handle)94   void cancel_check_peer(grpc_closure* /*on_peer_checked*/,
95                          grpc_error_handle /*error*/) override {}
96 
97   int cmp(const grpc_security_connector* other) const override;
98 };
99 
100 }  // namespace grpc_core
101 
102 #endif  // GRPC_SRC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_INSECURE_INSECURE_SECURITY_CONNECTOR_H
103