insecure_security_connector.cc
Go to the documentation of this file.
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 
20 
22 
23 #include <string.h>
24 
26 #include <grpc/support/log.h>
27 
36 
37 namespace grpc_core {
38 
39 const char kInsecureTransportSecurityType[] = "insecure";
40 
41 namespace {
42 
43 RefCountedPtr<grpc_auth_context> MakeAuthContext() {
44  auto ctx = MakeRefCounted<grpc_auth_context>(nullptr);
48  const char* security_level = tsi_security_level_to_string(TSI_SECURITY_NONE);
51  security_level, strlen(security_level));
52  return ctx;
53 }
54 
55 } // namespace
56 
58  return MakeAuthContext();
59 }
60 
63  return ImmediateOkStatus();
64 }
65 
66 // add_handshakers should have been a no-op but we need to add a minimalist
67 // security handshaker so that check_peer is invoked and an auth_context is
68 // created with the security level of TSI_SECURITY_NONE.
70  const grpc_channel_args* args, grpc_pollset_set* /* interested_parties */,
71  HandshakeManager* handshake_manager) {
72  tsi_handshaker* handshaker = nullptr;
73  // Re-use local_tsi_handshaker_create as a minimalist handshaker.
75  handshake_manager->Add(SecurityHandshakerCreate(handshaker, this, args));
76 }
77 
79  tsi_peer peer, grpc_endpoint* /*ep*/,
81  grpc_closure* on_peer_checked) {
82  *auth_context = MakeAuthContext();
83  tsi_peer_destruct(&peer);
84  ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, GRPC_ERROR_NONE);
85 }
86 
88  const grpc_security_connector* other_sc) const {
90  static_cast<const grpc_channel_security_connector*>(other_sc));
91 }
92 
93 // add_handshakers should have been a no-op but we need to add a minimalist
94 // security handshaker so that check_peer is invoked and an auth_context is
95 // created with the security level of TSI_SECURITY_NONE.
97  const grpc_channel_args* args, grpc_pollset_set* /* interested_parties */,
98  HandshakeManager* handshake_manager) {
99  tsi_handshaker* handshaker = nullptr;
100  // Re-use local_tsi_handshaker_create as a minimalist handshaker.
102  handshake_manager->Add(SecurityHandshakerCreate(handshaker, this, args));
103 }
104 
106  tsi_peer peer, grpc_endpoint* /*ep*/,
107  RefCountedPtr<grpc_auth_context>* auth_context,
108  grpc_closure* on_peer_checked) {
109  *auth_context = MakeAuthContext();
110  tsi_peer_destruct(&peer);
111  ExecCtx::Run(DEBUG_LOCATION, on_peer_checked, GRPC_ERROR_NONE);
112 }
113 
115  const grpc_security_connector* other) const {
117  static_cast<const grpc_server_security_connector*>(other));
118 }
119 
120 } // namespace grpc_core
tsi_security_level_to_string
const char * tsi_security_level_to_string(tsi_security_level security_level)
Definition: transport_security.cc:70
GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME
#define GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME
Definition: grpc_security_constants.h:47
grpc_core::InsecureServerSecurityConnector::cmp
int cmp(const grpc_security_connector *other) const override
Definition: insecure_security_connector.cc:114
grpc_auth_context
Definition: security_context.h:63
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
log.h
ctx
Definition: benchmark-async.c:30
grpc_server_security_connector
Definition: security_connector.h:171
tsi_handshaker
Definition: transport_security.h:84
grpc_core::SecurityHandshakerCreate
RefCountedPtr< Handshaker > SecurityHandshakerCreate(tsi_handshaker *handshaker, grpc_security_connector *connector, const grpc_channel_args *args)
Creates a security handshaker using handshaker.
Definition: security_handshaker.cc:658
grpc_core
Definition: call_metric_recorder.h:31
grpc_pollset_set
struct grpc_pollset_set grpc_pollset_set
Definition: iomgr_fwd.h:23
string.h
local_transport_security.h
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
ctx
static struct test_ctx ctx
Definition: test-ipc-send-recv.c:65
grpc_core::InsecureChannelSecurityConnector::check_peer
void check_peer(tsi_peer peer, grpc_endpoint *ep, RefCountedPtr< grpc_auth_context > *auth_context, grpc_closure *on_peer_checked) override
Definition: insecure_security_connector.cc:78
grpc_channel_args
Definition: grpc_types.h:132
grpc_core::kInsecureTransportSecurityType
const char kInsecureTransportSecurityType[]
Definition: insecure_security_connector.cc:39
grpc_security_connector
Definition: security_connector.h:61
TSI_OK
@ TSI_OK
Definition: transport_security_interface.h:32
DEBUG_LOCATION
#define DEBUG_LOCATION
Definition: debug_location.h:41
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME
#define GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME
Definition: grpc_security_constants.h:26
grpc_core::RefCountedPtr< grpc_auth_context >
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_core::HandshakeManager::Add
void Add(RefCountedPtr< Handshaker > handshaker)
Definition: src/core/lib/transport/handshaker.cc:63
grpc_auth_context_add_cstring_property
GRPCAPI void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx, const char *name, const char *value)
Definition: security_context.cc:268
TSI_SECURITY_NONE
@ TSI_SECURITY_NONE
Definition: transport_security_interface.h:54
grpc_core::InsecureChannelSecurityConnector::CheckCallHost
ArenaPromise< absl::Status > CheckCallHost(absl::string_view host, grpc_auth_context *auth_context) override
Definition: insecure_security_connector.cc:61
promise.h
grpc_core::InsecureChannelSecurityConnector::add_handshakers
void add_handshakers(const grpc_channel_args *args, grpc_pollset_set *, HandshakeManager *handshake_manager) override
Registers handshakers with handshake_mgr.
Definition: insecure_security_connector.cc:69
tsi_local_handshaker_create
tsi_result tsi_local_handshaker_create(tsi_handshaker **self)
Definition: local_transport_security.cc:161
grpc_channel_security_connector::channel_security_connector_cmp
int channel_security_connector_cmp(const grpc_channel_security_connector *other) const
Definition: security_connector.cc:45
security_handshaker.h
tsi_peer
Definition: transport_security_interface.h:238
security_context.h
grpc_core::ImmediateOkStatus
Definition: promise/promise.h:78
debug_location.h
grpc_core::ArenaPromise
Definition: arena_promise.h:152
poll.h
grpc_core::TestOnlyMakeInsecureAuthContext
RefCountedPtr< grpc_auth_context > TestOnlyMakeInsecureAuthContext()
Definition: insecure_security_connector.cc:57
insecure_security_connector.h
grpc_security_constants.h
grpc_core::InsecureServerSecurityConnector::check_peer
void check_peer(tsi_peer peer, grpc_endpoint *ep, RefCountedPtr< grpc_auth_context > *auth_context, grpc_closure *on_peer_checked) override
Definition: insecure_security_connector.cc:105
exec_ctx.h
grpc_auth_context_add_property
GRPCAPI void grpc_auth_context_add_property(grpc_auth_context *ctx, const char *name, const char *value, size_t value_length)
Definition: security_context.cc:248
grpc_core::ExecCtx::Run
static void Run(const DebugLocation &location, grpc_closure *closure, grpc_error_handle error)
Definition: exec_ctx.cc:98
ref_counted_ptr.h
grpc_channel_security_connector
Definition: security_connector.h:118
grpc_core::HandshakeManager
Definition: handshaker.h:98
grpc_core::InsecureChannelSecurityConnector::cmp
int cmp(const grpc_security_connector *other_sc) const override
Definition: insecure_security_connector.cc:87
grpc_closure
Definition: closure.h:56
tsi_peer_destruct
void tsi_peer_destruct(tsi_peer *self)
Definition: transport_security.cc:320
grpc_endpoint
Definition: endpoint.h:105
grpc_core::InsecureServerSecurityConnector::add_handshakers
void add_handshakers(const grpc_channel_args *args, grpc_pollset_set *, HandshakeManager *handshake_manager) override
Definition: insecure_security_connector.cc:96
grpc_server_security_connector::server_security_connector_cmp
int server_security_connector_cmp(const grpc_server_security_connector *other) const
Definition: security_connector.cc:67
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:06