Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, 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 | |
Nicolas "Pixel" Noble | 1ff52d5 | 2015-03-01 05:24:36 +0100 | [diff] [blame] | 34 | #ifndef GRPC_GRPC_SECURITY_H |
| 35 | #define GRPC_GRPC_SECURITY_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
Nicolas "Pixel" Noble | 1ed15e2 | 2015-06-09 02:24:35 +0200 | [diff] [blame] | 37 | #include <grpc/grpc.h> |
| 38 | #include <grpc/status.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 44 | /* --- Authentication Context. --- */ |
| 45 | |
| 46 | #define GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME "transport_security_type" |
| 47 | #define GRPC_SSL_TRANSPORT_SECURITY_TYPE "ssl" |
| 48 | |
| 49 | #define GRPC_X509_CN_PROPERTY_NAME "x509_common_name" |
| 50 | #define GRPC_X509_SAN_PROPERTY_NAME "x509_subject_alternative_name" |
| 51 | |
| 52 | typedef struct grpc_auth_context grpc_auth_context; |
| 53 | |
| 54 | typedef struct grpc_auth_property_iterator { |
| 55 | const grpc_auth_context *ctx; |
| 56 | size_t index; |
| 57 | const char *name; |
| 58 | } grpc_auth_property_iterator; |
| 59 | |
| 60 | /* value, if not NULL, is guaranteed to be NULL terminated. */ |
| 61 | typedef struct grpc_auth_property { |
| 62 | char *name; |
| 63 | char *value; |
| 64 | size_t value_length; |
| 65 | } grpc_auth_property; |
| 66 | |
| 67 | /* Returns NULL when the iterator is at the end. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 68 | GRPC_API const grpc_auth_property *grpc_auth_property_iterator_next( |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 69 | grpc_auth_property_iterator *it); |
| 70 | |
| 71 | /* Iterates over the auth context. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 72 | GRPC_API grpc_auth_property_iterator grpc_auth_context_property_iterator( |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 73 | const grpc_auth_context *ctx); |
| 74 | |
| 75 | /* Gets the peer identity. Returns an empty iterator (first _next will return |
| 76 | NULL) if the peer is not authenticated. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 77 | GRPC_API grpc_auth_property_iterator grpc_auth_context_peer_identity( |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 78 | const grpc_auth_context *ctx); |
| 79 | |
| 80 | /* Finds a property in the context. May return an empty iterator (first _next |
| 81 | will return NULL) if no property with this name was found in the context. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 82 | GRPC_API grpc_auth_property_iterator grpc_auth_context_find_properties_by_name( |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 83 | const grpc_auth_context *ctx, const char *name); |
| 84 | |
| 85 | /* Gets the name of the property that indicates the peer identity. Will return |
| 86 | NULL if the peer is not authenticated. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 87 | GRPC_API const char *grpc_auth_context_peer_identity_property_name( |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 88 | const grpc_auth_context *ctx); |
| 89 | |
| 90 | /* Returns 1 if the peer is authenticated, 0 otherwise. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 91 | GRPC_API int grpc_auth_context_peer_is_authenticated(const grpc_auth_context *ctx); |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 92 | |
| 93 | /* Gets the auth context from the call. Caller needs to call |
| 94 | grpc_auth_context_release on the returned context. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 95 | GRPC_API grpc_auth_context *grpc_call_auth_context(grpc_call *call); |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 96 | |
| 97 | /* Releases the auth context returned from grpc_call_auth_context. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 98 | GRPC_API void grpc_auth_context_release(grpc_auth_context *context); |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 99 | |
| 100 | /* -- |
| 101 | The following auth context methods should only be called by a server metadata |
| 102 | processor to set properties extracted from auth metadata. |
| 103 | -- */ |
| 104 | |
| 105 | /* Add a property. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 106 | GRPC_API void grpc_auth_context_add_property(grpc_auth_context *ctx, const char *name, |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 107 | const char *value, size_t value_length); |
| 108 | |
| 109 | /* Add a C string property. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 110 | GRPC_API void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx, |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 111 | const char *name, |
| 112 | const char *value); |
| 113 | |
| 114 | /* Sets the property name. Returns 1 if successful or 0 in case of failure |
| 115 | (which means that no property with this name exists). */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 116 | GRPC_API int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context *ctx, |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 117 | const char *name); |
| 118 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 119 | /* --- grpc_channel_credentials object. --- |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 120 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 121 | A channel credentials object represents a way to authenticate a client on a |
| 122 | channel. */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 123 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 124 | typedef struct grpc_channel_credentials grpc_channel_credentials; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 125 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 126 | /* Releases a channel credentials object. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 127 | The creator of the credentials object is responsible for its release. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 128 | GRPC_API void grpc_channel_credentials_release(grpc_channel_credentials *creds); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 129 | |
Julien Boeuf | b037bb6 | 2015-07-08 14:58:14 -0700 | [diff] [blame] | 130 | /* Environment variable that points to the google default application |
| 131 | credentials json key or refresh token. Used in the |
| 132 | grpc_google_default_credentials_create function. */ |
| 133 | #define GRPC_GOOGLE_CREDENTIALS_ENV_VAR "GOOGLE_APPLICATION_CREDENTIALS" |
| 134 | |
Julien Boeuf | c66f2a8 | 2015-02-23 13:00:36 -0800 | [diff] [blame] | 135 | /* Creates default credentials to connect to a google gRPC service. |
| 136 | WARNING: Do NOT use this credentials to connect to a non-google service as |
| 137 | this could result in an oauth2 token leak. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 138 | GRPC_API grpc_channel_credentials *grpc_google_default_credentials_create(void); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 139 | |
Julien Boeuf | 026a417 | 2015-02-02 18:36:37 -0800 | [diff] [blame] | 140 | /* Environment variable that points to the default SSL roots file. This file |
| 141 | must be a PEM encoded file with all the roots such as the one that can be |
| 142 | downloaded from https://pki.google.com/roots.pem. */ |
| 143 | #define GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR \ |
| 144 | "GRPC_DEFAULT_SSL_ROOTS_FILE_PATH" |
| 145 | |
Julien Boeuf | 8fbcc43 | 2015-01-15 16:44:13 -0800 | [diff] [blame] | 146 | /* Object that holds a private key / certificate chain pair in PEM format. */ |
| 147 | typedef struct { |
| 148 | /* private_key is the NULL-terminated string containing the PEM encoding of |
| 149 | the client's private key. */ |
| 150 | const char *private_key; |
| 151 | |
Julien Boeuf | 68ad53e | 2015-01-20 22:37:03 -0800 | [diff] [blame] | 152 | /* cert_chain is the NULL-terminated string containing the PEM encoding of |
| 153 | the client's certificate chain. */ |
Julien Boeuf | 8fbcc43 | 2015-01-15 16:44:13 -0800 | [diff] [blame] | 154 | const char *cert_chain; |
| 155 | } grpc_ssl_pem_key_cert_pair; |
| 156 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 157 | /* Creates an SSL credentials object. |
Julien Boeuf | 8fbcc43 | 2015-01-15 16:44:13 -0800 | [diff] [blame] | 158 | - pem_roots_cert is the NULL-terminated string containing the PEM encoding |
Julien Boeuf | 3e00179 | 2015-02-20 15:02:36 -0800 | [diff] [blame] | 159 | of the server root certificates. If this parameter is NULL, the |
| 160 | implementation will first try to dereference the file pointed by the |
| 161 | GRPC_DEFAULT_SSL_ROOTS_FILE_PATH environment variable, and if that fails, |
| 162 | get the roots from a well-known place on disk (in the grpc install |
| 163 | directory). |
Julien Boeuf | 8fbcc43 | 2015-01-15 16:44:13 -0800 | [diff] [blame] | 164 | - pem_key_cert_pair is a pointer on the object containing client's private |
| 165 | key and certificate chain. This parameter can be NULL if the client does |
Julien Boeuf | 5029b30 | 2015-07-21 23:02:16 -0700 | [diff] [blame] | 166 | not have such a key/cert pair. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 167 | GRPC_API grpc_channel_credentials *grpc_ssl_credentials_create( |
Julien Boeuf | 8b78c28 | 2015-08-14 13:39:19 -0700 | [diff] [blame] | 168 | const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pair, |
| 169 | void *reserved); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 170 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 171 | /* --- grpc_call_credentials object. |
| 172 | |
| 173 | A call credentials object represents a way to authenticate on a particular |
| 174 | call. These credentials can be composed with a channel credentials object |
| 175 | so that they are sent with every call on this channel. */ |
| 176 | |
| 177 | typedef struct grpc_call_credentials grpc_call_credentials; |
| 178 | |
Julien Boeuf | 441176d | 2015-10-09 21:14:07 -0700 | [diff] [blame] | 179 | /* Releases a call credentials object. |
| 180 | The creator of the credentials object is responsible for its release. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 181 | GRPC_API void grpc_call_credentials_release(grpc_call_credentials *creds); |
Julien Boeuf | 441176d | 2015-10-09 21:14:07 -0700 | [diff] [blame] | 182 | |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 183 | /* Creates a composite channel credentials object. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 184 | GRPC_API grpc_channel_credentials *grpc_composite_channel_credentials_create( |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 185 | grpc_channel_credentials *channel_creds, grpc_call_credentials *call_creds, |
| 186 | void *reserved); |
| 187 | |
| 188 | /* Creates a composite call credentials object. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 189 | GRPC_API grpc_call_credentials *grpc_composite_call_credentials_create( |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 190 | grpc_call_credentials *creds1, grpc_call_credentials *creds2, |
| 191 | void *reserved); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 192 | |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 193 | /* Creates a compute engine credentials object for connecting to Google. |
Julien Boeuf | c66f2a8 | 2015-02-23 13:00:36 -0800 | [diff] [blame] | 194 | WARNING: Do NOT use this credentials to connect to a non-google service as |
| 195 | this could result in an oauth2 token leak. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 196 | GRPC_API grpc_call_credentials *grpc_google_compute_engine_credentials_create( |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 197 | void *reserved); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 198 | |
jboeuf | ab4f914 | 2014-12-16 16:32:39 -0800 | [diff] [blame] | 199 | extern const gpr_timespec grpc_max_auth_token_lifetime; |
jboeuf | befd265 | 2014-12-12 15:39:47 -0800 | [diff] [blame] | 200 | |
Julien Boeuf | f47a5cb | 2015-02-18 12:24:08 -0800 | [diff] [blame] | 201 | /* Creates a JWT credentials object. May return NULL if the input is invalid. |
| 202 | - json_key is the JSON key string containing the client's private key. |
| 203 | - token_lifetime is the lifetime of each Json Web Token (JWT) created with |
| 204 | this credentials. It should not exceed grpc_max_auth_token_lifetime or |
| 205 | will be cropped to this value. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 206 | GRPC_API grpc_call_credentials *grpc_service_account_jwt_access_credentials_create( |
Julien Boeuf | 8b78c28 | 2015-08-14 13:39:19 -0700 | [diff] [blame] | 207 | const char *json_key, gpr_timespec token_lifetime, void *reserved); |
Julien Boeuf | f47a5cb | 2015-02-18 12:24:08 -0800 | [diff] [blame] | 208 | |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 209 | /* Creates an Oauth2 Refresh Token credentials object for connecting to Google. |
| 210 | May return NULL if the input is invalid. |
Julien Boeuf | 9835cf0 | 2015-03-09 16:56:44 -0700 | [diff] [blame] | 211 | WARNING: Do NOT use this credentials to connect to a non-google service as |
| 212 | this could result in an oauth2 token leak. |
| 213 | - json_refresh_token is the JSON string containing the refresh token itself |
| 214 | along with a client_id and client_secret. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 215 | GRPC_API grpc_call_credentials *grpc_google_refresh_token_credentials_create( |
Julien Boeuf | 8b78c28 | 2015-08-14 13:39:19 -0700 | [diff] [blame] | 216 | const char *json_refresh_token, void *reserved); |
Julien Boeuf | 9835cf0 | 2015-03-09 16:56:44 -0700 | [diff] [blame] | 217 | |
Julien Boeuf | 2805be1 | 2015-07-01 02:47:18 -0700 | [diff] [blame] | 218 | /* Creates an Oauth2 Access Token credentials with an access token that was |
| 219 | aquired by an out of band mechanism. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 220 | GRPC_API grpc_call_credentials *grpc_access_token_credentials_create( |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 221 | const char *access_token, void *reserved); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 222 | |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 223 | /* Creates an IAM credentials object for connecting to Google. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 224 | GRPC_API grpc_call_credentials *grpc_google_iam_credentials_create( |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 225 | const char *authorization_token, const char *authority_selector, |
| 226 | void *reserved); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 227 | |
Julien Boeuf | 8b5bb27 | 2015-08-31 13:25:21 -0700 | [diff] [blame] | 228 | /* Callback function to be called by the metadata credentials plugin |
Julien Boeuf | 97f80fa | 2015-09-15 16:17:31 -0700 | [diff] [blame] | 229 | implementation when the metadata is ready. |
| 230 | - user_data is the opaque pointer that was passed in the get_metadata method |
| 231 | of the grpc_metadata_credentials_plugin (see below). |
| 232 | - creds_md is an array of credentials metadata produced by the plugin. It |
| 233 | may be set to NULL in case of an error. |
| 234 | - num_creds_md is the number of items in the creds_md array. |
| 235 | - status must be GRPC_STATUS_OK in case of success or another specific error |
| 236 | code otherwise. |
| 237 | - error_details contains details about the error if any. In case of success |
| 238 | it should be NULL and will be otherwise ignored. */ |
Julien Boeuf | 8b5bb27 | 2015-08-31 13:25:21 -0700 | [diff] [blame] | 239 | typedef void (*grpc_credentials_plugin_metadata_cb)( |
| 240 | void *user_data, const grpc_metadata *creds_md, size_t num_creds_md, |
| 241 | grpc_status_code status, const char *error_details); |
| 242 | |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 243 | /* Context that can be used by metadata credentials plugin in order to create |
| 244 | auth related metadata. */ |
| 245 | typedef struct { |
| 246 | /* The fully qualifed service url. */ |
| 247 | const char *service_url; |
| 248 | |
Julien Boeuf | 3c957e6 | 2015-11-18 21:33:58 -0800 | [diff] [blame] | 249 | /* The method name of the RPC being called (not fully qualified). |
Julien Boeuf | eb029c9 | 2015-11-25 13:47:56 -0800 | [diff] [blame] | 250 | The fully qualified method name can be built from the service_url: |
| 251 | full_qualified_method_name = ctx->service_url + '/' + ctx->method_name. */ |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 252 | const char *method_name; |
| 253 | |
| 254 | /* The auth_context of the channel which gives the server's identity. */ |
| 255 | const grpc_auth_context *channel_auth_context; |
| 256 | |
| 257 | /* Reserved for future use. */ |
| 258 | void *reserved; |
| 259 | } grpc_auth_metadata_context; |
| 260 | |
Julien Boeuf | 97f80fa | 2015-09-15 16:17:31 -0700 | [diff] [blame] | 261 | /* grpc_metadata_credentials plugin is an API user provided structure used to |
| 262 | create grpc_credentials objects that can be set on a channel (composed) or |
| 263 | a call. See grpc_credentials_metadata_create_from_plugin below. |
| 264 | The grpc client stack will call the get_metadata method of the plugin for |
| 265 | every call in scope for the credentials created from it. */ |
Julien Boeuf | 8b5bb27 | 2015-08-31 13:25:21 -0700 | [diff] [blame] | 266 | typedef struct { |
| 267 | /* The implementation of this method has to be non-blocking. |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 268 | - context is the information that can be used by the plugin to create auth |
| 269 | metadata. |
Julien Boeuf | 8b5bb27 | 2015-08-31 13:25:21 -0700 | [diff] [blame] | 270 | - cb is the callback that needs to be called when the metadata is ready. |
| 271 | - user_data needs to be passed as the first parameter of the callback. */ |
Julien Boeuf | ea44bba | 2015-11-18 15:56:01 -0800 | [diff] [blame] | 272 | void (*get_metadata)(void *state, grpc_auth_metadata_context context, |
Julien Boeuf | 8b5bb27 | 2015-08-31 13:25:21 -0700 | [diff] [blame] | 273 | grpc_credentials_plugin_metadata_cb cb, void *user_data); |
| 274 | |
| 275 | /* Destroys the plugin state. */ |
| 276 | void (*destroy)(void *state); |
| 277 | |
| 278 | /* State that will be set as the first parameter of the methods above. */ |
| 279 | void *state; |
Julien Boeuf | caf9935 | 2015-11-19 22:00:30 -0800 | [diff] [blame] | 280 | |
| 281 | /* Type of credentials that this plugin is implementing. */ |
| 282 | const char *type; |
Julien Boeuf | 8b5bb27 | 2015-08-31 13:25:21 -0700 | [diff] [blame] | 283 | } grpc_metadata_credentials_plugin; |
| 284 | |
Julien Boeuf | 29ee3f4 | 2015-08-31 13:27:33 -0700 | [diff] [blame] | 285 | /* Creates a credentials object from a plugin. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 286 | GRPC_API grpc_call_credentials *grpc_metadata_credentials_create_from_plugin( |
Julien Boeuf | 8b5bb27 | 2015-08-31 13:25:21 -0700 | [diff] [blame] | 287 | grpc_metadata_credentials_plugin plugin, void *reserved); |
| 288 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 289 | /* --- Secure channel creation. --- */ |
| 290 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 291 | /* Creates a secure channel using the passed-in credentials. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 292 | GRPC_API grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 293 | const char *target, |
Julien Boeuf | 8b78c28 | 2015-08-14 13:39:19 -0700 | [diff] [blame] | 294 | const grpc_channel_args *args, |
| 295 | void *reserved); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 296 | |
| 297 | /* --- grpc_server_credentials object. --- |
| 298 | |
| 299 | A server credentials object represents a way to authenticate a server. */ |
| 300 | |
| 301 | typedef struct grpc_server_credentials grpc_server_credentials; |
| 302 | |
| 303 | /* Releases a server_credentials object. |
| 304 | The creator of the server_credentials object is responsible for its release. |
| 305 | */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 306 | GRPC_API void grpc_server_credentials_release(grpc_server_credentials *creds); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 307 | |
| 308 | /* Creates an SSL server_credentials object. |
Julien Boeuf | 8fbcc43 | 2015-01-15 16:44:13 -0800 | [diff] [blame] | 309 | - pem_roots_cert is the NULL-terminated string containing the PEM encoding of |
| 310 | the client root certificates. This parameter may be NULL if the server does |
| 311 | not want the client to be authenticated with SSL. |
| 312 | - pem_key_cert_pairs is an array private key / certificate chains of the |
| 313 | server. This parameter cannot be NULL. |
| 314 | - num_key_cert_pairs indicates the number of items in the private_key_files |
Julien Boeuf | 5029b30 | 2015-07-21 23:02:16 -0700 | [diff] [blame] | 315 | and cert_chain_files parameters. It should be at least 1. |
| 316 | - force_client_auth, if set to non-zero will force the client to authenticate |
| 317 | with an SSL cert. Note that this option is ignored if pem_root_certs is |
| 318 | NULL. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 319 | GRPC_API grpc_server_credentials *grpc_ssl_server_credentials_create( |
Julien Boeuf | 8fbcc43 | 2015-01-15 16:44:13 -0800 | [diff] [blame] | 320 | const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs, |
Julien Boeuf | 8b78c28 | 2015-08-14 13:39:19 -0700 | [diff] [blame] | 321 | size_t num_key_cert_pairs, int force_client_auth, void *reserved); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 322 | |
Jan Tattermusch | b0829eb | 2015-03-03 09:30:55 -0800 | [diff] [blame] | 323 | /* --- Server-side secure ports. --- */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 324 | |
Craig Tiller | d251ab9 | 2015-02-17 17:22:14 -0800 | [diff] [blame] | 325 | /* Add a HTTP2 over an encrypted link over tcp listener. |
Craig Tiller | d251ab9 | 2015-02-17 17:22:14 -0800 | [diff] [blame] | 326 | Returns bound port number on success, 0 on failure. |
| 327 | REQUIRES: server not started */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 328 | GRPC_API int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr, |
Craig Tiller | 759026c | 2015-02-22 23:09:45 -0800 | [diff] [blame] | 329 | grpc_server_credentials *creds); |
Craig Tiller | d251ab9 | 2015-02-17 17:22:14 -0800 | [diff] [blame] | 330 | |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame] | 331 | /* --- Call specific credentials. --- */ |
| 332 | |
| 333 | /* Sets a credentials to a call. Can only be called on the client side before |
| 334 | grpc_call_start_batch. */ |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 335 | GRPC_API grpc_call_error grpc_call_set_credentials(grpc_call *call, |
Julien Boeuf | acd835f | 2015-10-09 15:20:57 -0700 | [diff] [blame] | 336 | grpc_call_credentials *creds); |
Julien Boeuf | 9f218dd | 2015-04-23 10:24:02 -0700 | [diff] [blame] | 337 | |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 338 | /* --- Auth Metadata Processing --- */ |
| 339 | |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 340 | /* Callback function that is called when the metadata processing is done. |
Julien Boeuf | ee3dbb0 | 2015-08-19 22:17:03 -0700 | [diff] [blame] | 341 | - Consumed metadata will be removed from the set of metadata available on the |
| 342 | call. consumed_md may be NULL if no metadata has been consumed. |
| 343 | - Response metadata will be set on the response. response_md may be NULL. |
| 344 | - status is GRPC_STATUS_OK for success or a specific status for an error. |
| 345 | Common error status for auth metadata processing is either |
| 346 | GRPC_STATUS_UNAUTHENTICATED in case of an authentication failure or |
| 347 | GRPC_STATUS PERMISSION_DENIED in case of an authorization failure. |
| 348 | - error_details gives details about the error. May be NULL. */ |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 349 | typedef void (*grpc_process_auth_metadata_done_cb)( |
| 350 | void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md, |
Julien Boeuf | ee3dbb0 | 2015-08-19 22:17:03 -0700 | [diff] [blame] | 351 | const grpc_metadata *response_md, size_t num_response_md, |
| 352 | grpc_status_code status, const char *error_details); |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 353 | |
Julien Boeuf | 77a7b87 | 2015-08-05 20:11:02 -0700 | [diff] [blame] | 354 | /* Pluggable server-side metadata processor object. */ |
Julien Boeuf | a87d6c2 | 2015-07-17 15:51:46 -0700 | [diff] [blame] | 355 | typedef struct { |
Julien Boeuf | 77a7b87 | 2015-08-05 20:11:02 -0700 | [diff] [blame] | 356 | /* The context object is read/write: it contains the properties of the |
| 357 | channel peer and it is the job of the process function to augment it with |
Julien Boeuf | bf25bb0 | 2015-08-14 12:36:11 -0700 | [diff] [blame] | 358 | properties derived from the passed-in metadata. |
| 359 | The lifetime of these objects is guaranteed until cb is invoked. */ |
Julien Boeuf | 77a7b87 | 2015-08-05 20:11:02 -0700 | [diff] [blame] | 360 | void (*process)(void *state, grpc_auth_context *context, |
Julien Boeuf | bf25bb0 | 2015-08-14 12:36:11 -0700 | [diff] [blame] | 361 | const grpc_metadata *md, size_t num_md, |
Julien Boeuf | 77a7b87 | 2015-08-05 20:11:02 -0700 | [diff] [blame] | 362 | grpc_process_auth_metadata_done_cb cb, void *user_data); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 363 | void (*destroy)(void *state); |
Julien Boeuf | a87d6c2 | 2015-07-17 15:51:46 -0700 | [diff] [blame] | 364 | void *state; |
| 365 | } grpc_auth_metadata_processor; |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 366 | |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame^] | 367 | GRPC_API void grpc_server_credentials_set_auth_metadata_processor( |
Julien Boeuf | 6bdc9b4 | 2015-07-19 21:56:02 -0700 | [diff] [blame] | 368 | grpc_server_credentials *creds, grpc_auth_metadata_processor processor); |
Julien Boeuf | ea456fc | 2015-07-07 15:23:30 -0700 | [diff] [blame] | 369 | |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 370 | #ifdef __cplusplus |
| 371 | } |
| 372 | #endif |
| 373 | |
Craig Tiller | 9a57633 | 2015-06-17 10:21:49 -0700 | [diff] [blame] | 374 | #endif /* GRPC_GRPC_SECURITY_H */ |