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 22 #include <grpc/support/port_platform.h> 23 24 #include "src/core/lib/iomgr/pollset.h" 25 #include "src/core/lib/security/credentials/credentials.h" 26 27 extern grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount; 28 29 struct gpr_arena; 30 31 /* --- grpc_auth_context --- 32 33 High level authentication context object. Can optionally be chained. */ 34 35 /* Property names are always NULL terminated. */ 36 37 typedef struct { 38 grpc_auth_property* array; 39 size_t count; 40 size_t capacity; 41 } grpc_auth_property_array; 42 43 struct grpc_auth_context { 44 struct grpc_auth_context* chained; 45 grpc_auth_property_array properties; 46 gpr_refcount refcount; 47 const char* peer_identity_property_name; 48 grpc_pollset* pollset; 49 }; 50 51 /* Creation. */ 52 grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained); 53 54 /* Refcounting. */ 55 #ifndef NDEBUG 56 #define GRPC_AUTH_CONTEXT_REF(p, r) \ 57 grpc_auth_context_ref((p), __FILE__, __LINE__, (r)) 58 #define GRPC_AUTH_CONTEXT_UNREF(p, r) \ 59 grpc_auth_context_unref((p), __FILE__, __LINE__, (r)) 60 grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* policy, 61 const char* file, int line, 62 const char* reason); 63 void grpc_auth_context_unref(grpc_auth_context* policy, const char* file, 64 int line, const char* reason); 65 #else 66 #define GRPC_AUTH_CONTEXT_REF(p, r) grpc_auth_context_ref((p)) 67 #define GRPC_AUTH_CONTEXT_UNREF(p, r) grpc_auth_context_unref((p)) 68 grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* policy); 69 void grpc_auth_context_unref(grpc_auth_context* policy); 70 #endif 71 72 void grpc_auth_property_reset(grpc_auth_property* property); 73 74 /* --- grpc_security_context_extension --- 75 76 Extension to the security context that may be set in a filter and accessed 77 later by a higher level method on a grpc_call object. */ 78 79 typedef struct { 80 void* instance; 81 void (*destroy)(void*); 82 } grpc_security_context_extension; 83 84 /* --- grpc_client_security_context --- 85 86 Internal client-side security context. */ 87 88 typedef struct { 89 grpc_call_credentials* creds; 90 grpc_auth_context* auth_context; 91 grpc_security_context_extension extension; 92 } grpc_client_security_context; 93 94 grpc_client_security_context* grpc_client_security_context_create( 95 gpr_arena* arena); 96 void grpc_client_security_context_destroy(void* ctx); 97 98 /* --- grpc_server_security_context --- 99 100 Internal server-side security context. */ 101 102 typedef struct { 103 grpc_auth_context* auth_context; 104 grpc_security_context_extension extension; 105 } grpc_server_security_context; 106 107 grpc_server_security_context* grpc_server_security_context_create( 108 gpr_arena* arena); 109 void grpc_server_security_context_destroy(void* ctx); 110 111 /* --- Channel args for auth context --- */ 112 #define GRPC_AUTH_CONTEXT_ARG "grpc.auth_context" 113 114 grpc_arg grpc_auth_context_to_arg(grpc_auth_context* c); 115 grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg); 116 grpc_auth_context* grpc_find_auth_context_in_args( 117 const grpc_channel_args* args); 118 119 #endif /* GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H */ 120