GRPC Core  9.0.0
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 <stdbool.h>
25 
26 #include <grpc/grpc_security.h>
27 
35 
37 
39 
40 /* --- security_connector object. ---
41 
42  A security connector object represents away to configure the underlying
43  transport security mechanism and check the resulting trusted peer. */
44 
45 #define GRPC_ARG_SECURITY_CONNECTOR "grpc.security_connector"
46 
48  : public grpc_core::RefCounted<grpc_security_connector> {
49  public:
50  explicit grpc_security_connector(const char* url_scheme)
53  url_scheme_(url_scheme) {}
54  virtual ~grpc_security_connector() = default;
55 
56  /* Check the peer. Callee takes ownership of the peer object.
57  When done, sets *auth_context and invokes on_peer_checked. */
58  virtual void check_peer(
59  tsi_peer peer, grpc_endpoint* ep,
61  grpc_closure* on_peer_checked) = 0;
62 
63  /* Compares two security connectors. */
64  virtual int cmp(const grpc_security_connector* other) const = 0;
65 
66  const char* url_scheme() const { return url_scheme_; }
67 
68  private:
69  const char* url_scheme_;
70 };
71 
72 /* Util to encapsulate the connector in a channel arg. */
74 
75 /* Util to get the connector from a channel arg. */
77 
78 /* Util to find the connector from channel args. */
80  const grpc_channel_args* args);
81 
82 /* --- channel_security_connector object. ---
83 
84  A channel security connector object represents a way to configure the
85  underlying transport security mechanism on the client side. */
86 
88  public:
90  const char* url_scheme,
93  /*,
94  grpc_channel_args* channel_args = nullptr*/);
96 
102  grpc_auth_context* auth_context,
103  grpc_closure* on_call_host_checked,
104  grpc_error** error) = 0;
108  virtual void cancel_check_call_host(grpc_closure* on_call_host_checked,
109  grpc_error* error) = 0;
111  virtual void add_handshakers(const grpc_channel_args* args,
112  grpc_pollset_set* interested_parties,
113  grpc_core::HandshakeManager* handshake_mgr) = 0;
114 
116  return channel_creds_.get();
117  }
119  return channel_creds_.get();
120  }
122  return request_metadata_creds_.get();
123  }
125  return request_metadata_creds_.get();
126  }
127 
128  protected:
129  // Helper methods to be used in subclasses.
131  const grpc_channel_security_connector* other) const;
132 
133  // grpc_channel_args* channel_args() const { return channel_args_.get(); }
136  // void clear_channel_arg() { channel_args_.reset(); }
137 
138  private:
140  grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds_;
141  std::unique_ptr<grpc_channel_args> channel_args_;
142 };
143 
144 /* --- server_security_connector object. ---
145 
146  A server security connector object represents a way to configure the
147  underlying transport security mechanism on the server side. */
148 
150  public:
152  const char* url_scheme,
154  ~grpc_server_security_connector() override = default;
155 
156  virtual void add_handshakers(const grpc_channel_args* args,
157  grpc_pollset_set* interested_parties,
158  grpc_core::HandshakeManager* handshake_mgr) = 0;
159 
161  return server_creds_.get();
162  }
164  return server_creds_.get();
165  }
166 
167  protected:
168  // Helper methods to be used in subclasses.
170  const grpc_server_security_connector* other) const;
171 
172  private:
174 };
175 
176 #endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_SECURITY_CONNECTOR_H */
Definition: security_connector.h:87
virtual void cancel_check_call_host(grpc_closure *on_call_host_checked, grpc_error *error)=0
Cancels a pending asynchronous call to grpc_channel_security_connector_check_call_host() with on_call...
grpc_channel_credentials * mutable_channel_creds()
Definition: security_connector.h:118
grpc_channel_security_connector(const char *url_scheme, grpc_core::RefCountedPtr< grpc_channel_credentials > channel_creds, grpc_core::RefCountedPtr< grpc_call_credentials > request_metadata_creds)
Definition: security_connector.cc:49
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_call_credentials * mutable_request_metadata_creds()
Definition: security_connector.h:124
const grpc_call_credentials * request_metadata_creds() const
Definition: security_connector.h:121
~grpc_channel_security_connector() override
Definition: security_connector.cc:57
const grpc_channel_credentials * channel_creds() const
Definition: security_connector.h:115
virtual bool check_call_host(grpc_core::StringView host, grpc_auth_context *auth_context, grpc_closure *on_call_host_checked, grpc_error **error)=0
Checks that the host that will be set for a call is acceptable.
int channel_security_connector_cmp(const grpc_channel_security_connector *other) const
Definition: security_connector.cc:65
Definition: handshaker.h:91
Definition: ref_counted.h:248
T * get() const
Definition: ref_counted_ptr.h:144
Definition: string_view.h:69
Definition: trace.h:61
Definition: security_connector.h:48
const char * url_scheme() const
Definition: security_connector.h:66
grpc_security_connector(const char *url_scheme)
Definition: security_connector.h:50
virtual void check_peer(tsi_peer peer, grpc_endpoint *ep, grpc_core::RefCountedPtr< grpc_auth_context > *auth_context, grpc_closure *on_peer_checked)=0
virtual int cmp(const grpc_security_connector *other) const =0
virtual ~grpc_security_connector()=default
Definition: security_connector.h:149
int server_security_connector_cmp(const grpc_server_security_connector *other) const
Definition: security_connector.cc:76
grpc_server_security_connector(const char *url_scheme, grpc_core::RefCountedPtr< grpc_server_credentials > server_creds)
Definition: security_connector.cc:43
const grpc_server_credentials * server_creds() const
Definition: security_connector.h:160
grpc_server_credentials * mutable_server_creds()
Definition: security_connector.h:163
virtual void add_handshakers(const grpc_channel_args *args, grpc_pollset_set *interested_parties, grpc_core::HandshakeManager *handshake_mgr)=0
~grpc_server_security_connector() override=default
Round Robin Policy.
Definition: backend_metric.cc:24
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
grpc_security_connector * grpc_security_connector_find_in_args(const grpc_channel_args *args)
Definition: security_connector.cc:119
grpc_security_status
Definition: security_connector.h:38
@ GRPC_SECURITY_ERROR
Definition: security_connector.h:38
@ GRPC_SECURITY_OK
Definition: security_connector.h:38
grpc_core::DebugOnlyTraceFlag grpc_trace_security_connector_refcount
grpc_security_connector * grpc_security_connector_from_arg(const grpc_arg *arg)
Definition: security_connector.cc:109
grpc_arg grpc_security_connector_to_arg(grpc_security_connector *sc)
Definition: security_connector.cc:104
A single argument...
Definition: grpc_types.h:103
Definition: security_context.h:51
Definition: credentials.h:226
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Definition: credentials.h:100
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
Definition: endpoint.h:102
Definition: error_internal.h:39
Definition: credentials.h:264
Definition: transport_security_interface.h:198