Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
David Garcia Quintas | 3598d44 | 2016-03-15 14:53:05 -0700 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame] | 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 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_SECURITY_SECURITY_CONTEXT_H |
| 35 | #define GRPC_CORE_LIB_SECURITY_SECURITY_CONTEXT_H |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame] | 36 | |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 37 | #include "src/core/iomgr/pollset.h" |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame] | 38 | #include "src/core/security/credentials.h" |
| 39 | |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 40 | /* --- grpc_auth_context --- |
| 41 | |
| 42 | High level authentication context object. Can optionally be chained. */ |
| 43 | |
| 44 | /* Property names are always NULL terminated. */ |
| 45 | |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 46 | typedef struct { |
| 47 | grpc_auth_property *array; |
| 48 | size_t count; |
| 49 | size_t capacity; |
| 50 | } grpc_auth_property_array; |
| 51 | |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 52 | struct grpc_auth_context { |
| 53 | struct grpc_auth_context *chained; |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 54 | grpc_auth_property_array properties; |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 55 | gpr_refcount refcount; |
| 56 | const char *peer_identity_property_name; |
Julien Boeuf | 77a7b87 | 2015-08-05 20:11:02 -0700 | [diff] [blame] | 57 | grpc_pollset *pollset; |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Julien Boeuf | 77a7b87 | 2015-08-05 20:11:02 -0700 | [diff] [blame] | 60 | /* Creation. */ |
| 61 | grpc_auth_context *grpc_auth_context_create(grpc_auth_context *chained); |
| 62 | |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 63 | /* Refcounting. */ |
Craig Tiller | 991edad | 2015-06-30 11:40:41 -0700 | [diff] [blame] | 64 | #ifdef GRPC_AUTH_CONTEXT_REFCOUNT_DEBUG |
| 65 | #define GRPC_AUTH_CONTEXT_REF(p, r) \ |
| 66 | grpc_auth_context_ref((p), __FILE__, __LINE__, (r)) |
| 67 | #define GRPC_AUTH_CONTEXT_UNREF(p, r) \ |
| 68 | grpc_auth_context_unref((p), __FILE__, __LINE__, (r)) |
| 69 | grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *policy, |
| 70 | const char *file, int line, |
| 71 | const char *reason); |
| 72 | void grpc_auth_context_unref(grpc_auth_context *policy, const char *file, |
| 73 | int line, const char *reason); |
| 74 | #else |
| 75 | #define GRPC_AUTH_CONTEXT_REF(p, r) grpc_auth_context_ref((p)) |
| 76 | #define GRPC_AUTH_CONTEXT_UNREF(p, r) grpc_auth_context_unref((p)) |
| 77 | grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *policy); |
| 78 | void grpc_auth_context_unref(grpc_auth_context *policy); |
| 79 | #endif |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 80 | |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 81 | void grpc_auth_property_reset(grpc_auth_property *property); |
| 82 | |
| 83 | /* --- grpc_client_security_context --- |
| 84 | |
| 85 | Internal client-side security context. */ |
| 86 | |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame] | 87 | typedef struct { |
Julien Boeuf | 441176d | 2015-10-09 21:14:07 -0700 | [diff] [blame] | 88 | grpc_call_credentials *creds; |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 89 | grpc_auth_context *auth_context; |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame] | 90 | } grpc_client_security_context; |
| 91 | |
| 92 | grpc_client_security_context *grpc_client_security_context_create(void); |
| 93 | void grpc_client_security_context_destroy(void *ctx); |
| 94 | |
Julien Boeuf | 84d964a | 2015-04-29 11:31:06 -0700 | [diff] [blame] | 95 | /* --- grpc_server_security_context --- |
| 96 | |
| 97 | Internal server-side security context. */ |
| 98 | |
| 99 | typedef struct { |
| 100 | grpc_auth_context *auth_context; |
| 101 | } grpc_server_security_context; |
| 102 | |
| 103 | grpc_server_security_context *grpc_server_security_context_create(void); |
| 104 | void grpc_server_security_context_destroy(void *ctx); |
| 105 | |
Julien Boeuf | 9a52908 | 2015-10-08 13:12:14 -0700 | [diff] [blame] | 106 | /* --- Channel args for auth context --- */ |
| 107 | #define GRPC_AUTH_CONTEXT_ARG "grpc.auth_context" |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 108 | |
Julien Boeuf | 9a52908 | 2015-10-08 13:12:14 -0700 | [diff] [blame] | 109 | grpc_arg grpc_auth_context_to_arg(grpc_auth_context *c); |
| 110 | grpc_auth_context *grpc_auth_context_from_arg(const grpc_arg *arg); |
| 111 | grpc_auth_context *grpc_find_auth_context_in_args( |
Julien Boeuf | 66a27da | 2015-07-21 17:17:35 -0700 | [diff] [blame] | 112 | const grpc_channel_args *args); |
yang-g | 3abe60b | 2015-07-06 14:00:36 -0700 | [diff] [blame] | 113 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 114 | #endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONTEXT_H */ |