security_context.h 3.7 KB

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