security_context.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. *
  3. * Copyright 2015, Google Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. #ifndef GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H
  34. #define GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H
  35. #include "src/core/lib/iomgr/pollset.h"
  36. #include "src/core/lib/security/credentials/credentials.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /* --- grpc_auth_context ---
  41. High level authentication context object. Can optionally be chained. */
  42. /* Property names are always NULL terminated. */
  43. typedef struct {
  44. grpc_auth_property *array;
  45. size_t count;
  46. size_t capacity;
  47. } grpc_auth_property_array;
  48. struct grpc_auth_context {
  49. struct grpc_auth_context *chained;
  50. grpc_auth_property_array properties;
  51. gpr_refcount refcount;
  52. const char *peer_identity_property_name;
  53. grpc_pollset *pollset;
  54. };
  55. /* Creation. */
  56. grpc_auth_context *grpc_auth_context_create(grpc_auth_context *chained);
  57. /* Refcounting. */
  58. #ifdef GRPC_AUTH_CONTEXT_REFCOUNT_DEBUG
  59. #define GRPC_AUTH_CONTEXT_REF(p, r) \
  60. grpc_auth_context_ref((p), __FILE__, __LINE__, (r))
  61. #define GRPC_AUTH_CONTEXT_UNREF(p, r) \
  62. grpc_auth_context_unref((p), __FILE__, __LINE__, (r))
  63. grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *policy,
  64. const char *file, int line,
  65. const char *reason);
  66. void grpc_auth_context_unref(grpc_auth_context *policy, const char *file,
  67. int line, const char *reason);
  68. #else
  69. #define GRPC_AUTH_CONTEXT_REF(p, r) grpc_auth_context_ref((p))
  70. #define GRPC_AUTH_CONTEXT_UNREF(p, r) grpc_auth_context_unref((p))
  71. grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *policy);
  72. void grpc_auth_context_unref(grpc_auth_context *policy);
  73. #endif
  74. void grpc_auth_property_reset(grpc_auth_property *property);
  75. /* --- grpc_security_context_extension ---
  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. typedef struct {
  79. void *instance;
  80. void (*destroy)(void *);
  81. } grpc_security_context_extension;
  82. /* --- grpc_client_security_context ---
  83. Internal client-side security context. */
  84. typedef struct {
  85. grpc_call_credentials *creds;
  86. grpc_auth_context *auth_context;
  87. grpc_security_context_extension extension;
  88. } grpc_client_security_context;
  89. grpc_client_security_context *grpc_client_security_context_create(void);
  90. void grpc_client_security_context_destroy(void *ctx);
  91. /* --- grpc_server_security_context ---
  92. Internal server-side security context. */
  93. typedef struct {
  94. grpc_auth_context *auth_context;
  95. grpc_security_context_extension extension;
  96. } grpc_server_security_context;
  97. grpc_server_security_context *grpc_server_security_context_create(void);
  98. void grpc_server_security_context_destroy(void *ctx);
  99. /* --- Channel args for auth context --- */
  100. #define GRPC_AUTH_CONTEXT_ARG "grpc.auth_context"
  101. grpc_arg grpc_auth_context_to_arg(grpc_auth_context *c);
  102. grpc_auth_context *grpc_auth_context_from_arg(const grpc_arg *arg);
  103. grpc_auth_context *grpc_find_auth_context_in_args(
  104. const grpc_channel_args *args);
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif /* GRPC_CORE_LIB_SECURITY_CONTEXT_SECURITY_CONTEXT_H */