security_context.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_CONTEXT_SECURITY_CONTEXT_H
20 #define GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H
21 
23 
24 #include <stddef.h>
25 
26 #include <utility>
27 
28 #include "absl/strings/string_view.h"
29 
30 #include <grpc/grpc_security.h>
32 #include <grpc/support/alloc.h>
33 
40 #include "src/core/lib/security/credentials/credentials.h" // IWYU pragma: keep
41 
43 
44 /* --- grpc_auth_context ---
45 
46  High level authentication context object. Can optionally be chained. */
47 
48 /* Property names are always NULL terminated. */
49 
52  size_t count = 0;
53  size_t capacity = 0;
54 };
55 
57 
58 #define GRPC_AUTH_CONTEXT_ARG "grpc.auth_context"
59 
60 // This type is forward declared as a C struct and we cannot define it as a
61 // class. Otherwise, compiler will complain about type mismatch due to
62 // -Wmismatched-tags.
64  : public grpc_core::RefCounted<grpc_auth_context,
65  grpc_core::NonPolymorphicRefCount> {
66  public:
70  grpc_core::NonPolymorphicRefCount>(
72  ? "auth_context_refcount"
73  : nullptr),
75  if (chained_ != nullptr) {
77  }
78  }
79 
81  chained_.reset(DEBUG_LOCATION, "chained");
82  if (properties_.array != nullptr) {
83  for (size_t i = 0; i < properties_.count; i++) {
85  }
87  }
88  }
89 
92  const grpc_auth_context* b) {
93  return QsortCompare(a, b);
94  }
95 
96  const grpc_auth_context* chained() const { return chained_.get(); }
97  const grpc_auth_property_array& properties() const { return properties_; }
98 
99  bool is_authenticated() const {
100  return peer_identity_property_name_ != nullptr;
101  }
102  const char* peer_identity_property_name() const {
104  }
107  }
108 
109  void ensure_capacity();
110  void add_property(const char* name, const char* value, size_t value_length);
111  void add_cstring_property(const char* name, const char* value);
112 
113  private:
116  const char* peer_identity_property_name_ = nullptr;
117 };
118 
119 /* --- grpc_security_context_extension ---
120 
121  Extension to the security context that may be set in a filter and accessed
122  later by a higher level method on a grpc_call object. */
123 
125  void* instance = nullptr;
126  void (*destroy)(void*) = nullptr;
127 };
128 
129 /* --- grpc_client_security_context ---
130 
131  Internal client-side security context. */
132 
136  : creds(std::move(creds)) {}
138 
142 };
143 
147 
148 /* --- grpc_server_security_context ---
149 
150  Internal server-side security context. */
151 
153  grpc_server_security_context() = default;
155 
158 };
159 
163 
164 /* --- Channel args for auth context --- */
165 
169  const grpc_channel_args* args);
170 
171 #endif /* GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H */
grpc_arg
Definition: grpc_types.h:103
trace.h
grpc_auth_context_from_arg
grpc_auth_context * grpc_auth_context_from_arg(const grpc_arg *arg)
Definition: security_context.cc:311
grpc_server_security_context_destroy
void grpc_server_security_context_destroy(void *ctx)
Definition: security_context.cc:134
grpc_auth_context
Definition: security_context.h:63
ctx
Definition: benchmark-async.c:30
grpc_server_security_context_create
grpc_server_security_context * grpc_server_security_context_create(grpc_core::Arena *arena)
Definition: security_context.cc:129
grpc_auth_context::peer_identity_property_name_
const char * peer_identity_property_name_
Definition: security_context.h:116
grpc_auth_context::add_cstring_property
void add_cstring_property(const char *name, const char *value)
Definition: security_context.cc:259
grpc_core::RefCountedPtr::get
T * get() const
Definition: ref_counted_ptr.h:146
grpc_security_context_extension::destroy
void(* destroy)(void *)
Definition: security_context.h:126
grpc_core
Definition: call_metric_recorder.h:31
grpc_auth_context_to_arg
grpc_arg grpc_auth_context_to_arg(grpc_auth_context *c)
Definition: security_context.cc:305
grpc_core::RefCountedPtr::reset
void reset(T *value=nullptr)
Definition: ref_counted_ptr.h:111
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_auth_context::ChannelArgName
static absl::string_view ChannelArgName()
Definition: security_context.h:90
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
useful.h
grpc_client_security_context::extension
grpc_security_context_extension extension
Definition: security_context.h:141
arena.h
grpc_call_credentials
Definition: src/core/lib/security/credentials/credentials.h:189
grpc_find_auth_context_in_args
grpc_auth_context * grpc_find_auth_context_in_args(const grpc_channel_args *args)
Definition: security_context.cc:321
setup.name
name
Definition: setup.py:542
grpc_trace_auth_context_refcount
grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
grpc_security.h
grpc_core::Arena
Definition: src/core/lib/resource_quota/arena.h:45
credentials.h
grpc_channel_args
Definition: grpc_types.h:132
GRPC_TRACE_FLAG_ENABLED
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: debug/trace.h:114
grpc_auth_context::set_peer_identity_property_name
void set_peer_identity_property_name(const char *name)
Definition: security_context.h:105
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
grpc_types.h
DEBUG_LOCATION
#define DEBUG_LOCATION
Definition: debug_location.h:41
grpc_auth_property_array::capacity
size_t capacity
Definition: security_context.h:53
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::RefCountedPtr< grpc_auth_context >
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_auth_context::properties
const grpc_auth_property_array & properties() const
Definition: security_context.h:97
array
Definition: undname.c:101
grpc_auth_context::properties_
grpc_auth_property_array properties_
Definition: security_context.h:115
grpc_auth_property_array::array
grpc_auth_property * array
Definition: security_context.h:51
arg
Definition: cmdline.cc:40
grpc_client_security_context::creds
grpc_core::RefCountedPtr< grpc_call_credentials > creds
Definition: security_context.h:139
grpc_auth_property_array
Definition: security_context.h:50
grpc_core::RefCounted
Definition: ref_counted.h:280
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
grpc_auth_context::chained
const grpc_auth_context * chained() const
Definition: security_context.h:96
grpc_server_security_context
Definition: security_context.h:152
grpc_core::TraceFlag
Definition: debug/trace.h:63
grpc_auth_property
Definition: grpc_security.h:43
grpc_client_security_context::~grpc_client_security_context
~grpc_client_security_context()
Definition: security_context.cc:101
value
const char * value
Definition: hpack_parser_table.cc:165
grpc_client_security_context
Definition: security_context.h:133
grpc_auth_property_reset
void grpc_auth_property_reset(grpc_auth_property *property)
Definition: security_context.cc:277
grpc_client_security_context_destroy
void grpc_client_security_context_destroy(void *ctx)
Definition: security_context.cc:114
grpc_auth_context::peer_identity_property_name
const char * peer_identity_property_name() const
Definition: security_context.h:102
grpc_client_security_context::auth_context
grpc_core::RefCountedPtr< grpc_auth_context > auth_context
Definition: security_context.h:140
grpc_security_context_extension
Definition: security_context.h:124
debug_location.h
GRPC_AUTH_CONTEXT_ARG
#define GRPC_AUTH_CONTEXT_ARG
Definition: security_context.h:58
grpc_core::QsortCompare
int QsortCompare(const T &a, const T &b)
Definition: useful.h:95
ref_counted.h
grpc_server_security_context::grpc_server_security_context
grpc_server_security_context()=default
grpc_auth_context::ChannelArgsCompare
static int ChannelArgsCompare(const grpc_auth_context *a, const grpc_auth_context *b)
Definition: security_context.h:91
grpc_auth_context::is_authenticated
bool is_authenticated() const
Definition: security_context.h:99
alloc.h
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_auth_context::add_property
void add_property(const char *name, const char *value, size_t value_length)
Definition: security_context.cc:235
grpc_auth_context::chained_
grpc_core::RefCountedPtr< grpc_auth_context > chained_
Definition: security_context.h:114
grpc_client_security_context_create
grpc_client_security_context * grpc_client_security_context_create(grpc_core::Arena *arena, grpc_call_credentials *creds)
Definition: security_context.cc:108
ref_counted_ptr.h
grpc_security_context_extension::instance
void * instance
Definition: security_context.h:125
grpc_server_security_context::extension
grpc_security_context_extension extension
Definition: security_context.h:157
grpc_auth_context::~grpc_auth_context
~grpc_auth_context()
Definition: security_context.h:80
grpc_core::RefCounted< grpc_auth_context, grpc_core::NonPolymorphicRefCount >::RefCounted
RefCounted(const RefCounted &)=delete
grpc_client_security_context::grpc_client_security_context
grpc_client_security_context(grpc_core::RefCountedPtr< grpc_call_credentials > creds)
Definition: security_context.h:134
grpc_server_security_context::~grpc_server_security_context
~grpc_server_security_context()
Definition: security_context.cc:122
grpc_auth_property_array::count
size_t count
Definition: security_context.h:52
grpc_auth_context::ensure_capacity
void ensure_capacity()
Definition: security_context.cc:226
grpc_auth_context::grpc_auth_context
grpc_auth_context(grpc_core::RefCountedPtr< grpc_auth_context > chained)
Definition: security_context.h:67
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
port_platform.h
grpc_server_security_context::auth_context
grpc_core::RefCountedPtr< grpc_auth_context > auth_context
Definition: security_context.h:156


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