security_connector.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 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_SECURITY_CONNECTOR_SECURITY_CONNECTOR_H
20 #define GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_SECURITY_CONNECTOR_H
21 
23 
24 #include <memory>
25 
26 #include "absl/status/status.h"
27 #include "absl/strings/string_view.h"
28 
29 #include <grpc/grpc.h>
30 #include <grpc/grpc_security.h>
32 
44 
46 
47 /* --- URL schemes. --- */
48 
49 #define GRPC_SSL_URL_SCHEME "https"
50 #define GRPC_FAKE_SECURITY_URL_SCHEME "http+fake_security"
51 
53 
54 /* --- security_connector object. ---
55 
56  A security connector object represents away to configure the underlying
57  transport security mechanism and check the resulting trusted peer. */
58 
59 #define GRPC_ARG_SECURITY_CONNECTOR "grpc.internal.security_connector"
60 
62  : public grpc_core::RefCounted<grpc_security_connector> {
63  public:
67  ? "security_connector_refcount"
68  : nullptr),
70 
73  }
74 
75  // Checks the peer. Callee takes ownership of the peer object.
76  // When done, sets *auth_context and invokes on_peer_checked.
77  virtual void check_peer(
78  tsi_peer peer, grpc_endpoint* ep,
80  grpc_closure* on_peer_checked) = 0;
81 
82  // Cancels the pending check_peer() request associated with on_peer_checked.
83  // If there is no such request pending, this is a no-op.
84  virtual void cancel_check_peer(grpc_closure* on_peer_checked,
86 
87  /* Compares two security connectors. */
88  virtual int cmp(const grpc_security_connector* other) const = 0;
89 
91  const grpc_security_connector* b) {
92  return a->cmp(b);
93  }
94 
96 
97  virtual grpc_core::UniqueTypeName type() const = 0;
98 
99  private:
101 };
102 
103 /* Util to encapsulate the connector in a channel arg. */
105 
106 /* Util to get the connector from a channel arg. */
108 
109 /* Util to find the connector from channel args. */
111  const grpc_channel_args* args);
112 
113 /* --- channel_security_connector object. ---
114 
115  A channel security connector object represents a way to configure the
116  underlying transport security mechanism on the client side. */
117 
119  public:
124 
128  absl::string_view host, grpc_auth_context* auth_context) = 0;
129 
131  virtual void add_handshakers(const grpc_channel_args* args,
132  grpc_pollset_set* interested_parties,
133  grpc_core::HandshakeManager* handshake_mgr) = 0;
134 
136  return channel_creds_.get();
137  }
139  return channel_creds_.get();
140  }
142  return request_metadata_creds_.get();
143  }
145  return request_metadata_creds_.get();
146  }
147 
148  grpc_core::UniqueTypeName type() const override;
149 
150  protected:
151  // Helper methods to be used in subclasses.
153  const grpc_channel_security_connector* other) const;
154 
155  // grpc_channel_args* channel_args() const { return channel_args_.get(); }
158  // void clear_channel_arg() { channel_args_.reset(); }
159 
160  private:
163  std::unique_ptr<grpc_channel_args> channel_args_;
164 };
165 
166 /* --- server_security_connector object. ---
167 
168  A server security connector object represents a way to configure the
169  underlying transport security mechanism on the server side. */
170 
172  public:
176 
177  virtual void add_handshakers(const grpc_channel_args* args,
178  grpc_pollset_set* interested_parties,
179  grpc_core::HandshakeManager* handshake_mgr) = 0;
180 
182  return server_creds_.get();
183  }
185  return server_creds_.get();
186  }
187 
188  grpc_core::UniqueTypeName type() const override;
189 
190  protected:
191  // Helper methods to be used in subclasses.
193  const grpc_server_security_connector* other) const;
194 
195  private:
197 };
198 
199 #endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_SECURITY_CONNECTOR_H */
grpc_arg
Definition: grpc_types.h:103
trace.h
grpc_auth_context
Definition: security_context.h:63
grpc_security_connector::check_peer
virtual void check_peer(tsi_peer peer, grpc_endpoint *ep, grpc_core::RefCountedPtr< grpc_auth_context > *auth_context, grpc_closure *on_peer_checked)=0
grpc_server_security_connector::add_handshakers
virtual void add_handshakers(const grpc_channel_args *args, grpc_pollset_set *interested_parties, grpc_core::HandshakeManager *handshake_mgr)=0
grpc_server_security_connector
Definition: security_connector.h:171
grpc_core::RefCountedPtr::get
T * get() const
Definition: ref_counted_ptr.h:146
GRPC_SECURITY_ERROR
@ GRPC_SECURITY_ERROR
Definition: security_connector.h:52
grpc_security_connector::grpc_security_connector
grpc_security_connector(absl::string_view url_scheme)
Definition: security_connector.h:64
grpc_core
Definition: call_metric_recorder.h:31
grpc_channel_security_connector::type
grpc_core::UniqueTypeName type() const override
Definition: security_connector.cc:57
grpc_pollset_set
struct grpc_pollset_set grpc_pollset_set
Definition: iomgr_fwd.h:23
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_security_connector::url_scheme
absl::string_view url_scheme() const
Definition: security_connector.h:95
closure.h
grpc_call_credentials
Definition: src/core/lib/security/credentials/credentials.h:189
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
grpc_security.h
grpc_channel_security_connector::grpc_channel_security_connector
grpc_channel_security_connector(absl::string_view url_scheme, grpc_core::RefCountedPtr< grpc_channel_credentials > channel_creds, grpc_core::RefCountedPtr< grpc_call_credentials > request_metadata_creds)
Definition: security_connector.cc:37
grpc_security_connector::ChannelArgName
static absl::string_view ChannelArgName()
Definition: security_connector.h:71
grpc_channel_args
Definition: grpc_types.h:132
GRPC_TRACE_FLAG_ENABLED
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: debug/trace.h:114
grpc_server_security_connector::type
grpc_core::UniqueTypeName type() const override
Definition: security_connector.cc:76
grpc_types.h
grpc_security_connector
Definition: security_connector.h:61
grpc_security_connector::cancel_check_peer
virtual void cancel_check_peer(grpc_closure *on_peer_checked, grpc_error_handle error)=0
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::RefCountedPtr< grpc_auth_context >
grpc_channel_security_connector::CheckCallHost
virtual grpc_core::ArenaPromise< absl::Status > CheckCallHost(absl::string_view host, grpc_auth_context *auth_context)=0
grpc_channel_security_connector::mutable_channel_creds
grpc_channel_credentials * mutable_channel_creds()
Definition: security_connector.h:138
grpc.h
grpc_channel_security_connector::channel_args_
std::unique_ptr< grpc_channel_args > channel_args_
Definition: security_connector.h:163
arg
Definition: cmdline.cc:40
arena_promise.h
grpc_security_connector_to_arg
grpc_arg grpc_security_connector_to_arg(grpc_security_connector *sc)
Definition: security_connector.cc:101
error.h
grpc_trace_security_connector_refcount
grpc_core::DebugOnlyTraceFlag grpc_trace_security_connector_refcount
grpc_security_connector::type
virtual grpc_core::UniqueTypeName type() const =0
grpc_channel_security_connector::add_handshakers
virtual void add_handshakers(const grpc_channel_args *args, grpc_pollset_set *interested_parties, grpc_core::HandshakeManager *handshake_mgr)=0
Registers handshakers with handshake_mgr.
grpc_core::RefCounted
Definition: ref_counted.h:280
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
transport_security_interface.h
grpc_server_security_connector::server_creds_
grpc_core::RefCountedPtr< grpc_server_credentials > server_creds_
Definition: security_connector.h:196
grpc_security_connector_from_arg
grpc_security_connector * grpc_security_connector_from_arg(const grpc_arg *arg)
Definition: security_connector.cc:107
grpc_core::TraceFlag
Definition: debug/trace.h:63
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
grpc_security_connector::ChannelArgsCompare
static int ChannelArgsCompare(const grpc_security_connector *a, const grpc_security_connector *b)
Definition: security_connector.h:90
GRPC_SECURITY_OK
@ GRPC_SECURITY_OK
Definition: security_connector.h:52
grpc_server_credentials
Definition: src/core/lib/security/credentials/credentials.h:259
tsi_peer
Definition: transport_security_interface.h:238
grpc_core::UniqueTypeName
Definition: unique_type_name.h:56
grpc_core::ArenaPromise
Definition: arena_promise.h:152
ref_counted.h
handshaker.h
unique_type_name.h
GRPC_ARG_SECURITY_CONNECTOR
#define GRPC_ARG_SECURITY_CONNECTOR
Definition: security_connector.h:59
ref_counted_ptr.h
grpc_channel_security_connector::request_metadata_creds_
grpc_core::RefCountedPtr< grpc_call_credentials > request_metadata_creds_
Definition: security_connector.h:162
grpc_channel_security_connector
Definition: security_connector.h:118
grpc_server_security_connector::mutable_server_creds
grpc_server_credentials * mutable_server_creds()
Definition: security_connector.h:184
grpc_channel_security_connector::mutable_request_metadata_creds
grpc_call_credentials * mutable_request_metadata_creds()
Definition: security_connector.h:144
grpc_core::HandshakeManager
Definition: handshaker.h:98
iomgr_fwd.h
endpoint.h
grpc_server_security_connector::server_creds
const grpc_server_credentials * server_creds() const
Definition: security_connector.h:181
grpc_channel_security_connector::channel_creds
const grpc_channel_credentials * channel_creds() const
Definition: security_connector.h:135
grpc_error
Definition: error_internal.h:42
grpc_core::RefCounted< grpc_security_connector >::RefCounted
RefCounted(const RefCounted &)=delete
grpc_security_connector::cmp
virtual int cmp(const grpc_security_connector *other) const =0
grpc_closure
Definition: closure.h:56
grpc_channel_security_connector::channel_creds_
grpc_core::RefCountedPtr< grpc_channel_credentials > channel_creds_
Definition: security_connector.h:161
grpc_channel_security_connector::request_metadata_creds
const grpc_call_credentials * request_metadata_creds() const
Definition: security_connector.h:141
grpc_endpoint
Definition: endpoint.h:105
grpc_channel_credentials
Definition: src/core/lib/security/credentials/credentials.h:96
grpc_security_status
grpc_security_status
Definition: security_connector.h:52
grpc_server_security_connector::grpc_server_security_connector
grpc_server_security_connector(absl::string_view url_scheme, grpc_core::RefCountedPtr< grpc_server_credentials > server_creds)
Definition: security_connector.cc:61
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
grpc_security_connector_find_in_args
grpc_security_connector * grpc_security_connector_find_in_args(const grpc_channel_args *args)
Definition: security_connector.cc:117
grpc_security_connector::url_scheme_
absl::string_view url_scheme_
Definition: security_connector.h:100
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:15