Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Julien Boeuf | 4f4d37c | 2016-02-24 22:07:36 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [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_CREDENTIALS_H |
| 35 | #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 37 | #include <grpc/grpc.h> |
| 38 | #include <grpc/grpc_security.h> |
| 39 | #include <grpc/support/sync.h> |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 40 | #include "src/core/transport/metadata_batch.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | |
Matthew Iselin | 1824f05 | 2016-02-10 12:16:06 +1100 | [diff] [blame] | 42 | #include "src/core/http/httpcli.h" |
| 43 | #include "src/core/http/parser.h" |
Julien Boeuf | 5400606 | 2015-07-07 19:13:04 -0700 | [diff] [blame] | 44 | #include "src/core/security/json_token.h" |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 45 | #include "src/core/security/security_connector.h" |
| 46 | |
Matthew Iselin | 1824f05 | 2016-02-10 12:16:06 +1100 | [diff] [blame] | 47 | struct grpc_http_response; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 48 | |
| 49 | /* --- Constants. --- */ |
| 50 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 51 | typedef enum { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 52 | GRPC_CREDENTIALS_OK = 0, |
| 53 | GRPC_CREDENTIALS_ERROR |
| 54 | } grpc_credentials_status; |
| 55 | |
yang-g | 8b25f2a | 2015-07-21 23:54:36 -0700 | [diff] [blame] | 56 | #define GRPC_FAKE_TRANSPORT_SECURITY_TYPE "fake" |
| 57 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 58 | #define GRPC_CHANNEL_CREDENTIALS_TYPE_SSL "Ssl" |
| 59 | #define GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY \ |
| 60 | "FakeTransportSecurity" |
| 61 | |
| 62 | #define GRPC_CALL_CREDENTIALS_TYPE_OAUTH2 "Oauth2" |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 63 | #define GRPC_CALL_CREDENTIALS_TYPE_JWT "Jwt" |
| 64 | #define GRPC_CALL_CREDENTIALS_TYPE_IAM "Iam" |
| 65 | #define GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE "Composite" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 66 | |
Julien Boeuf | 4e02e84 | 2015-10-09 22:49:42 -0700 | [diff] [blame] | 67 | #define GRPC_AUTHORIZATION_METADATA_KEY "authorization" |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 68 | #define GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY \ |
| 69 | "x-goog-iam-authorization-token" |
| 70 | #define GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY "x-goog-iam-authority-selector" |
| 71 | |
Julien Boeuf | cd9b1c8 | 2015-02-20 17:40:41 -0800 | [diff] [blame] | 72 | #define GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY "gcloud" |
| 73 | #define GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE \ |
| 74 | "application_default_credentials.json" |
| 75 | |
Julien Boeuf | 9835cf0 | 2015-03-09 16:56:44 -0700 | [diff] [blame] | 76 | #define GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS 60 |
| 77 | |
| 78 | #define GRPC_COMPUTE_ENGINE_METADATA_HOST "metadata" |
| 79 | #define GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH \ |
| 80 | "/computeMetadata/v1/instance/service-accounts/default/token" |
| 81 | |
| 82 | #define GRPC_GOOGLE_OAUTH2_SERVICE_HOST "www.googleapis.com" |
| 83 | #define GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH "/oauth2/v3/token" |
| 84 | |
| 85 | #define GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX \ |
| 86 | "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" \ |
| 87 | "assertion=" |
| 88 | |
| 89 | #define GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING \ |
| 90 | "client_id=%s&client_secret=%s&refresh_token=%s&grant_type=refresh_token" |
| 91 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 92 | /* --- Google utils --- */ |
| 93 | |
| 94 | /* It is the caller's responsibility to gpr_free the result if not NULL. */ |
| 95 | char *grpc_get_well_known_google_credentials_file_path(void); |
| 96 | |
Julien Boeuf | 2408a1c | 2015-12-09 22:33:41 -0800 | [diff] [blame] | 97 | /* Implementation function for the different platforms. */ |
| 98 | char *grpc_get_well_known_google_credentials_file_path_impl(void); |
| 99 | |
| 100 | /* Override for testing only. Not thread-safe */ |
| 101 | typedef char *(*grpc_well_known_credentials_path_getter)(void); |
| 102 | void grpc_override_well_known_credentials_path_getter( |
| 103 | grpc_well_known_credentials_path_getter getter); |
| 104 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 105 | /* --- grpc_channel_credentials. --- */ |
| 106 | |
| 107 | typedef struct { |
| 108 | void (*destruct)(grpc_channel_credentials *c); |
Julien Boeuf | 441176d | 2015-10-09 21:14:07 -0700 | [diff] [blame] | 109 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 110 | grpc_security_status (*create_security_connector)( |
Julien Boeuf | b73cbc2 | 2015-10-20 21:52:54 -0700 | [diff] [blame] | 111 | grpc_channel_credentials *c, grpc_call_credentials *call_creds, |
| 112 | const char *target, const grpc_channel_args *args, |
| 113 | grpc_channel_security_connector **sc, grpc_channel_args **new_args); |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 114 | } grpc_channel_credentials_vtable; |
| 115 | |
| 116 | struct grpc_channel_credentials { |
| 117 | const grpc_channel_credentials_vtable *vtable; |
| 118 | const char *type; |
| 119 | gpr_refcount refcount; |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | grpc_channel_credentials *grpc_channel_credentials_ref( |
| 123 | grpc_channel_credentials *creds); |
| 124 | void grpc_channel_credentials_unref(grpc_channel_credentials *creds); |
| 125 | |
| 126 | /* Creates a security connector for the channel. May also create new channel |
| 127 | args for the channel to be used in place of the passed in const args if |
| 128 | returned non NULL. In that case the caller is responsible for destroying |
| 129 | new_args after channel creation. */ |
| 130 | grpc_security_status grpc_channel_credentials_create_security_connector( |
| 131 | grpc_channel_credentials *creds, const char *target, |
Julien Boeuf | 441176d | 2015-10-09 21:14:07 -0700 | [diff] [blame] | 132 | const grpc_channel_args *args, grpc_channel_security_connector **sc, |
| 133 | grpc_channel_args **new_args); |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 134 | |
Julien Boeuf | 75c9b6f | 2015-05-29 13:12:12 -0700 | [diff] [blame] | 135 | /* --- grpc_credentials_md. --- */ |
| 136 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 137 | typedef struct { |
Julien Boeuf | 75c9b6f | 2015-05-29 13:12:12 -0700 | [diff] [blame] | 138 | gpr_slice key; |
| 139 | gpr_slice value; |
| 140 | } grpc_credentials_md; |
| 141 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 142 | typedef struct { |
Julien Boeuf | 75c9b6f | 2015-05-29 13:12:12 -0700 | [diff] [blame] | 143 | grpc_credentials_md *entries; |
| 144 | size_t num_entries; |
| 145 | size_t allocated; |
| 146 | gpr_refcount refcount; |
| 147 | } grpc_credentials_md_store; |
| 148 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 149 | grpc_credentials_md_store *grpc_credentials_md_store_create( |
| 150 | size_t initial_capacity); |
Julien Boeuf | 75c9b6f | 2015-05-29 13:12:12 -0700 | [diff] [blame] | 151 | |
| 152 | /* Will ref key and value. */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 153 | void grpc_credentials_md_store_add(grpc_credentials_md_store *store, |
| 154 | gpr_slice key, gpr_slice value); |
| 155 | void grpc_credentials_md_store_add_cstrings(grpc_credentials_md_store *store, |
| 156 | const char *key, const char *value); |
| 157 | grpc_credentials_md_store *grpc_credentials_md_store_ref( |
| 158 | grpc_credentials_md_store *store); |
| 159 | void grpc_credentials_md_store_unref(grpc_credentials_md_store *store); |
Julien Boeuf | 75c9b6f | 2015-05-29 13:12:12 -0700 | [diff] [blame] | 160 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 161 | /* --- grpc_call_credentials. --- */ |
Julien Boeuf | cd9b1c8 | 2015-02-20 17:40:41 -0800 | [diff] [blame] | 162 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 163 | typedef void (*grpc_credentials_metadata_cb)(grpc_exec_ctx *exec_ctx, |
| 164 | void *user_data, |
| 165 | grpc_credentials_md *md_elems, |
| 166 | size_t num_md, |
| 167 | grpc_credentials_status status); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 168 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 169 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 170 | void (*destruct)(grpc_call_credentials *c); |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 171 | void (*get_request_metadata)(grpc_exec_ctx *exec_ctx, |
| 172 | grpc_call_credentials *c, grpc_pollset *pollset, |
Julien Boeuf | 3c957e6 | 2015-11-18 21:33:58 -0800 | [diff] [blame] | 173 | grpc_auth_metadata_context context, |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 174 | grpc_credentials_metadata_cb cb, |
| 175 | void *user_data); |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 176 | } grpc_call_credentials_vtable; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 177 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 178 | struct grpc_call_credentials { |
| 179 | const grpc_call_credentials_vtable *vtable; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 180 | const char *type; |
| 181 | gpr_refcount refcount; |
| 182 | }; |
| 183 | |
Julien Boeuf | 441176d | 2015-10-09 21:14:07 -0700 | [diff] [blame] | 184 | grpc_call_credentials *grpc_call_credentials_ref(grpc_call_credentials *creds); |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 185 | void grpc_call_credentials_unref(grpc_call_credentials *creds); |
Nicolas "Pixel" Noble | f9c58f3 | 2015-12-01 22:40:44 +0100 | [diff] [blame] | 186 | void grpc_call_credentials_get_request_metadata( |
| 187 | grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds, |
| 188 | grpc_pollset *pollset, grpc_auth_metadata_context context, |
| 189 | grpc_credentials_metadata_cb cb, void *user_data); |
Craig Tiller | c4885ed | 2015-04-14 09:51:28 -0700 | [diff] [blame] | 190 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 191 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 192 | grpc_call_credentials **creds_array; |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 193 | size_t num_creds; |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 194 | } grpc_call_credentials_array; |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 195 | |
Craig Tiller | b113649 | 2015-11-18 11:30:17 -0800 | [diff] [blame] | 196 | const grpc_call_credentials_array * |
| 197 | grpc_composite_call_credentials_get_credentials( |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 198 | grpc_call_credentials *composite_creds); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 199 | |
jboeuf | 6ad120e | 2015-01-12 17:08:15 -0800 | [diff] [blame] | 200 | /* Returns creds if creds is of the specified type or the inner creds of the |
| 201 | specified type (if found), if the creds is of type COMPOSITE. |
| 202 | If composite_creds is not NULL, *composite_creds will point to creds if of |
| 203 | type COMPOSITE in case of success. */ |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 204 | grpc_call_credentials *grpc_credentials_contains_type( |
| 205 | grpc_call_credentials *creds, const char *type, |
| 206 | grpc_call_credentials **composite_creds); |
jboeuf | 6ad120e | 2015-01-12 17:08:15 -0800 | [diff] [blame] | 207 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 208 | /* Exposed for testing only. */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 209 | grpc_credentials_status |
| 210 | grpc_oauth2_token_fetcher_credentials_parse_server_response( |
Matthew Iselin | 1824f05 | 2016-02-10 12:16:06 +1100 | [diff] [blame] | 211 | const struct grpc_http_response *response, |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 212 | grpc_credentials_md_store **token_md, gpr_timespec *token_lifetime); |
Julien Boeuf | 2408a1c | 2015-12-09 22:33:41 -0800 | [diff] [blame] | 213 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 214 | void grpc_flush_cached_google_default_credentials(void); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 215 | |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 216 | /* Metadata-only credentials with the specified key and value where |
| 217 | asynchronicity can be simulated for testing. */ |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 218 | grpc_call_credentials *grpc_md_only_test_credentials_create( |
| 219 | const char *md_key, const char *md_value, int is_async); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 220 | |
Julien Boeuf | 5400606 | 2015-07-07 19:13:04 -0700 | [diff] [blame] | 221 | /* Private constructor for jwt credentials from an already parsed json key. |
| 222 | Takes ownership of the key. */ |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 223 | grpc_call_credentials * |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 224 | grpc_service_account_jwt_access_credentials_create_from_auth_json_key( |
| 225 | grpc_auth_json_key key, gpr_timespec token_lifetime); |
Julien Boeuf | 5400606 | 2015-07-07 19:13:04 -0700 | [diff] [blame] | 226 | |
| 227 | /* Private constructor for refresh token credentials from an already parsed |
| 228 | refresh token. Takes ownership of the refresh token. */ |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 229 | grpc_call_credentials * |
| 230 | grpc_refresh_token_credentials_create_from_auth_refresh_token( |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 231 | grpc_auth_refresh_token token); |
Julien Boeuf | 5400606 | 2015-07-07 19:13:04 -0700 | [diff] [blame] | 232 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 233 | /* --- grpc_server_credentials. --- */ |
| 234 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 235 | typedef struct { |
| 236 | void (*destruct)(grpc_server_credentials *c); |
| 237 | grpc_security_status (*create_security_connector)( |
Julien Boeuf | 4f4d37c | 2016-02-24 22:07:36 -0800 | [diff] [blame] | 238 | grpc_server_credentials *c, grpc_server_security_connector **sc); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 239 | } grpc_server_credentials_vtable; |
| 240 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 241 | struct grpc_server_credentials { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 242 | const grpc_server_credentials_vtable *vtable; |
| 243 | const char *type; |
Julien Boeuf | fe1478f | 2015-08-30 21:57:38 -0700 | [diff] [blame] | 244 | gpr_refcount refcount; |
Julien Boeuf | 6bdc9b4 | 2015-07-19 21:56:02 -0700 | [diff] [blame] | 245 | grpc_auth_metadata_processor processor; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 248 | grpc_security_status grpc_server_credentials_create_security_connector( |
Julien Boeuf | 4f4d37c | 2016-02-24 22:07:36 -0800 | [diff] [blame] | 249 | grpc_server_credentials *creds, grpc_server_security_connector **sc); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 250 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 251 | grpc_server_credentials *grpc_server_credentials_ref( |
| 252 | grpc_server_credentials *creds); |
Julien Boeuf | fe1478f | 2015-08-30 21:57:38 -0700 | [diff] [blame] | 253 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 254 | void grpc_server_credentials_unref(grpc_server_credentials *creds); |
Julien Boeuf | fe1478f | 2015-08-30 21:57:38 -0700 | [diff] [blame] | 255 | |
Julien Boeuf | 9a52908 | 2015-10-08 13:12:14 -0700 | [diff] [blame] | 256 | #define GRPC_SERVER_CREDENTIALS_ARG "grpc.server_credentials" |
| 257 | |
| 258 | grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials *c); |
| 259 | grpc_server_credentials *grpc_server_credentials_from_arg(const grpc_arg *arg); |
| 260 | grpc_server_credentials *grpc_find_server_credentials_in_args( |
| 261 | const grpc_channel_args *args); |
| 262 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 263 | /* -- Fake transport security credentials. -- */ |
| 264 | |
| 265 | /* Creates a fake transport security credentials object for testing. */ |
| 266 | grpc_channel_credentials *grpc_fake_transport_security_credentials_create(void); |
| 267 | /* Creates a fake server transport security credentials object for testing. */ |
| 268 | grpc_server_credentials *grpc_fake_transport_security_server_credentials_create( |
| 269 | void); |
| 270 | |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 271 | /* -- Ssl credentials. -- */ |
| 272 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 273 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 274 | grpc_channel_credentials base; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 275 | grpc_ssl_config config; |
| 276 | } grpc_ssl_credentials; |
| 277 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 278 | typedef struct { |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 279 | grpc_server_credentials base; |
| 280 | grpc_ssl_server_config config; |
| 281 | } grpc_ssl_server_credentials; |
| 282 | |
Julien Boeuf | b73cbc2 | 2015-10-20 21:52:54 -0700 | [diff] [blame] | 283 | /* -- Channel composite credentials. -- */ |
| 284 | |
| 285 | typedef struct { |
| 286 | grpc_channel_credentials base; |
| 287 | grpc_channel_credentials *inner_creds; |
| 288 | grpc_call_credentials *call_creds; |
| 289 | } grpc_composite_channel_credentials; |
| 290 | |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 291 | /* -- Jwt credentials -- */ |
| 292 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 293 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 294 | grpc_call_credentials base; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 295 | |
| 296 | /* Have a simple cache for now with just 1 entry. We could have a map based on |
| 297 | the service_url for a more sophisticated one. */ |
| 298 | gpr_mu cache_mu; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 299 | struct { |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 300 | grpc_credentials_md_store *jwt_md; |
| 301 | char *service_url; |
| 302 | gpr_timespec jwt_expiration; |
| 303 | } cached; |
| 304 | |
| 305 | grpc_auth_json_key key; |
| 306 | gpr_timespec jwt_lifetime; |
Julien Boeuf | fe4c3f4 | 2015-07-22 16:20:13 -0700 | [diff] [blame] | 307 | } grpc_service_account_jwt_access_credentials; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 308 | |
| 309 | /* -- Oauth2TokenFetcher credentials -- |
| 310 | |
| 311 | This object is a base for credentials that need to acquire an oauth2 token |
| 312 | from an http service. */ |
| 313 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 314 | typedef struct grpc_credentials_metadata_request |
| 315 | grpc_credentials_metadata_request; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 316 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 317 | typedef void (*grpc_fetch_oauth2_func)(grpc_exec_ctx *exec_ctx, |
| 318 | grpc_credentials_metadata_request *req, |
| 319 | grpc_httpcli_context *http_context, |
| 320 | grpc_pollset *pollset, |
| 321 | grpc_httpcli_response_cb response_cb, |
| 322 | gpr_timespec deadline); |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 323 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 324 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 325 | grpc_call_credentials base; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 326 | gpr_mu mu; |
| 327 | grpc_credentials_md_store *access_token_md; |
| 328 | gpr_timespec token_expiration; |
| 329 | grpc_httpcli_context httpcli_context; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 330 | grpc_fetch_oauth2_func fetch_func; |
| 331 | } grpc_oauth2_token_fetcher_credentials; |
| 332 | |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 333 | /* -- GoogleRefreshToken credentials. -- */ |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 334 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 335 | typedef struct { |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 336 | grpc_oauth2_token_fetcher_credentials base; |
| 337 | grpc_auth_refresh_token refresh_token; |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 338 | } grpc_google_refresh_token_credentials; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 339 | |
Julien Boeuf | 0b1b1a5 | 2015-07-10 08:35:04 -0700 | [diff] [blame] | 340 | /* -- Oauth2 Access Token credentials. -- */ |
| 341 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 342 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 343 | grpc_call_credentials base; |
Julien Boeuf | 0b1b1a5 | 2015-07-10 08:35:04 -0700 | [diff] [blame] | 344 | grpc_credentials_md_store *access_token_md; |
| 345 | } grpc_access_token_credentials; |
| 346 | |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 347 | /* -- Metadata-only Test credentials. -- */ |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 348 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 349 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 350 | grpc_call_credentials base; |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 351 | grpc_credentials_md_store *md_store; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 352 | int is_async; |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 353 | } grpc_md_only_test_credentials; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 354 | |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 355 | /* -- GoogleIAM credentials. -- */ |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 356 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 357 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 358 | grpc_call_credentials base; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 359 | grpc_credentials_md_store *iam_md; |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 360 | } grpc_google_iam_credentials; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 361 | |
| 362 | /* -- Composite credentials. -- */ |
| 363 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 364 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 365 | grpc_call_credentials base; |
| 366 | grpc_call_credentials_array inner; |
Julien Boeuf | b73cbc2 | 2015-10-20 21:52:54 -0700 | [diff] [blame] | 367 | } grpc_composite_call_credentials; |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 368 | |
Julien Boeuf | 2d04118 | 2015-08-31 20:30:09 -0700 | [diff] [blame] | 369 | /* -- Plugin credentials. -- */ |
| 370 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 371 | typedef struct { |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 372 | grpc_call_credentials base; |
Julien Boeuf | 2d04118 | 2015-08-31 20:30:09 -0700 | [diff] [blame] | 373 | grpc_metadata_credentials_plugin plugin; |
| 374 | grpc_credentials_md_store *plugin_md; |
| 375 | } grpc_plugin_credentials; |
| 376 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 377 | #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_H */ |