blob: ae880ac5c4a9b011995559a25e6be53058595878 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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" Noble1ff52d52015-03-01 05:24:36 +010034#ifndef GRPC_GRPC_SECURITY_H
35#define GRPC_GRPC_SECURITY_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
Nicolas "Pixel" Noble1ed15e22015-06-09 02:24:35 +020037#include <grpc/grpc.h>
38#include <grpc/status.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080039
nnoble0c475f02014-12-05 15:37:39 -080040#ifdef __cplusplus
41extern "C" {
42#endif
43
Julien Boeufea44bba2015-11-18 15:56:01 -080044/* --- 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
52typedef struct grpc_auth_context grpc_auth_context;
53
54typedef 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. */
61typedef 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 Tiller9b426372016-01-29 07:58:22 -080068GRPC_API const grpc_auth_property *grpc_auth_property_iterator_next(
Julien Boeufea44bba2015-11-18 15:56:01 -080069 grpc_auth_property_iterator *it);
70
71/* Iterates over the auth context. */
Craig Tillerd6546c92016-01-29 07:59:35 -080072GRPC_API grpc_auth_property_iterator
73grpc_auth_context_property_iterator(const grpc_auth_context *ctx);
Julien Boeufea44bba2015-11-18 15:56:01 -080074
75/* Gets the peer identity. Returns an empty iterator (first _next will return
76 NULL) if the peer is not authenticated. */
Craig Tillerd6546c92016-01-29 07:59:35 -080077GRPC_API grpc_auth_property_iterator
78grpc_auth_context_peer_identity(const grpc_auth_context *ctx);
Julien Boeufea44bba2015-11-18 15:56:01 -080079
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 Tillerd6546c92016-01-29 07:59:35 -080082GRPC_API grpc_auth_property_iterator
83grpc_auth_context_find_properties_by_name(const grpc_auth_context *ctx,
84 const char *name);
Julien Boeufea44bba2015-11-18 15:56:01 -080085
86/* Gets the name of the property that indicates the peer identity. Will return
87 NULL if the peer is not authenticated. */
Craig Tiller9b426372016-01-29 07:58:22 -080088GRPC_API const char *grpc_auth_context_peer_identity_property_name(
Julien Boeufea44bba2015-11-18 15:56:01 -080089 const grpc_auth_context *ctx);
90
91/* Returns 1 if the peer is authenticated, 0 otherwise. */
Craig Tillerd6546c92016-01-29 07:59:35 -080092GRPC_API int grpc_auth_context_peer_is_authenticated(
93 const grpc_auth_context *ctx);
Julien Boeufea44bba2015-11-18 15:56:01 -080094
95/* Gets the auth context from the call. Caller needs to call
96 grpc_auth_context_release on the returned context. */
Craig Tiller9b426372016-01-29 07:58:22 -080097GRPC_API grpc_auth_context *grpc_call_auth_context(grpc_call *call);
Julien Boeufea44bba2015-11-18 15:56:01 -080098
99/* Releases the auth context returned from grpc_call_auth_context. */
Craig Tiller9b426372016-01-29 07:58:22 -0800100GRPC_API void grpc_auth_context_release(grpc_auth_context *context);
Julien Boeufea44bba2015-11-18 15:56:01 -0800101
102/* --
103 The following auth context methods should only be called by a server metadata
104 processor to set properties extracted from auth metadata.
105 -- */
106
107/* Add a property. */
Craig Tillerd6546c92016-01-29 07:59:35 -0800108GRPC_API void grpc_auth_context_add_property(grpc_auth_context *ctx,
109 const char *name,
110 const char *value,
111 size_t value_length);
Julien Boeufea44bba2015-11-18 15:56:01 -0800112
113/* Add a C string property. */
Craig Tiller9b426372016-01-29 07:58:22 -0800114GRPC_API void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx,
Craig Tillerd6546c92016-01-29 07:59:35 -0800115 const char *name,
116 const char *value);
Julien Boeufea44bba2015-11-18 15:56:01 -0800117
118/* Sets the property name. Returns 1 if successful or 0 in case of failure
119 (which means that no property with this name exists). */
Craig Tillerd6546c92016-01-29 07:59:35 -0800120GRPC_API int grpc_auth_context_set_peer_identity_property_name(
121 grpc_auth_context *ctx, const char *name);
Julien Boeufea44bba2015-11-18 15:56:01 -0800122
Julien Boeufacd835f2015-10-09 15:20:57 -0700123/* --- grpc_channel_credentials object. ---
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800124
Julien Boeufacd835f2015-10-09 15:20:57 -0700125 A channel credentials object represents a way to authenticate a client on a
126 channel. */
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800127
Julien Boeufacd835f2015-10-09 15:20:57 -0700128typedef struct grpc_channel_credentials grpc_channel_credentials;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800129
Julien Boeufacd835f2015-10-09 15:20:57 -0700130/* Releases a channel credentials object.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800131 The creator of the credentials object is responsible for its release. */
Craig Tiller9b426372016-01-29 07:58:22 -0800132GRPC_API void grpc_channel_credentials_release(grpc_channel_credentials *creds);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800133
Julien Boeufb037bb62015-07-08 14:58:14 -0700134/* Environment variable that points to the google default application
135 credentials json key or refresh token. Used in the
136 grpc_google_default_credentials_create function. */
137#define GRPC_GOOGLE_CREDENTIALS_ENV_VAR "GOOGLE_APPLICATION_CREDENTIALS"
138
Julien Boeufc66f2a82015-02-23 13:00:36 -0800139/* Creates default credentials to connect to a google gRPC service.
140 WARNING: Do NOT use this credentials to connect to a non-google service as
141 this could result in an oauth2 token leak. */
Craig Tiller9b426372016-01-29 07:58:22 -0800142GRPC_API grpc_channel_credentials *grpc_google_default_credentials_create(void);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800143
Julien Boeuf026a4172015-02-02 18:36:37 -0800144/* Environment variable that points to the default SSL roots file. This file
145 must be a PEM encoded file with all the roots such as the one that can be
146 downloaded from https://pki.google.com/roots.pem. */
147#define GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR \
148 "GRPC_DEFAULT_SSL_ROOTS_FILE_PATH"
149
Julien Boeuf8fbcc432015-01-15 16:44:13 -0800150/* Object that holds a private key / certificate chain pair in PEM format. */
151typedef struct {
152 /* private_key is the NULL-terminated string containing the PEM encoding of
153 the client's private key. */
154 const char *private_key;
155
Julien Boeuf68ad53e2015-01-20 22:37:03 -0800156 /* cert_chain is the NULL-terminated string containing the PEM encoding of
157 the client's certificate chain. */
Julien Boeuf8fbcc432015-01-15 16:44:13 -0800158 const char *cert_chain;
159} grpc_ssl_pem_key_cert_pair;
160
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800161/* Creates an SSL credentials object.
Julien Boeuf8fbcc432015-01-15 16:44:13 -0800162 - pem_roots_cert is the NULL-terminated string containing the PEM encoding
Julien Boeuf3e001792015-02-20 15:02:36 -0800163 of the server root certificates. If this parameter is NULL, the
164 implementation will first try to dereference the file pointed by the
165 GRPC_DEFAULT_SSL_ROOTS_FILE_PATH environment variable, and if that fails,
166 get the roots from a well-known place on disk (in the grpc install
167 directory).
Julien Boeuf8fbcc432015-01-15 16:44:13 -0800168 - pem_key_cert_pair is a pointer on the object containing client's private
169 key and certificate chain. This parameter can be NULL if the client does
Julien Boeuf5029b302015-07-21 23:02:16 -0700170 not have such a key/cert pair. */
Craig Tiller9b426372016-01-29 07:58:22 -0800171GRPC_API grpc_channel_credentials *grpc_ssl_credentials_create(
Julien Boeuf8b78c282015-08-14 13:39:19 -0700172 const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pair,
173 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800174
Julien Boeufacd835f2015-10-09 15:20:57 -0700175/* --- grpc_call_credentials object.
176
177 A call credentials object represents a way to authenticate on a particular
178 call. These credentials can be composed with a channel credentials object
179 so that they are sent with every call on this channel. */
180
181typedef struct grpc_call_credentials grpc_call_credentials;
182
Julien Boeuf441176d2015-10-09 21:14:07 -0700183/* Releases a call credentials object.
184 The creator of the credentials object is responsible for its release. */
Craig Tiller9b426372016-01-29 07:58:22 -0800185GRPC_API void grpc_call_credentials_release(grpc_call_credentials *creds);
Julien Boeuf441176d2015-10-09 21:14:07 -0700186
Julien Boeufacd835f2015-10-09 15:20:57 -0700187/* Creates a composite channel credentials object. */
Craig Tiller9b426372016-01-29 07:58:22 -0800188GRPC_API grpc_channel_credentials *grpc_composite_channel_credentials_create(
Julien Boeufacd835f2015-10-09 15:20:57 -0700189 grpc_channel_credentials *channel_creds, grpc_call_credentials *call_creds,
190 void *reserved);
191
192/* Creates a composite call credentials object. */
Craig Tiller9b426372016-01-29 07:58:22 -0800193GRPC_API grpc_call_credentials *grpc_composite_call_credentials_create(
Julien Boeufacd835f2015-10-09 15:20:57 -0700194 grpc_call_credentials *creds1, grpc_call_credentials *creds2,
195 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800196
Julien Boeuf510a9202015-08-25 21:51:07 -0700197/* Creates a compute engine credentials object for connecting to Google.
Julien Boeufc66f2a82015-02-23 13:00:36 -0800198 WARNING: Do NOT use this credentials to connect to a non-google service as
199 this could result in an oauth2 token leak. */
Craig Tiller9b426372016-01-29 07:58:22 -0800200GRPC_API grpc_call_credentials *grpc_google_compute_engine_credentials_create(
Julien Boeufacd835f2015-10-09 15:20:57 -0700201 void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800202
jboeufab4f9142014-12-16 16:32:39 -0800203extern const gpr_timespec grpc_max_auth_token_lifetime;
jboeufbefd2652014-12-12 15:39:47 -0800204
Julien Boeuff47a5cb2015-02-18 12:24:08 -0800205/* Creates a JWT credentials object. May return NULL if the input is invalid.
206 - json_key is the JSON key string containing the client's private key.
207 - token_lifetime is the lifetime of each Json Web Token (JWT) created with
208 this credentials. It should not exceed grpc_max_auth_token_lifetime or
209 will be cropped to this value. */
Craig Tillerd6546c92016-01-29 07:59:35 -0800210GRPC_API grpc_call_credentials *
211grpc_service_account_jwt_access_credentials_create(const char *json_key,
212 gpr_timespec token_lifetime,
213 void *reserved);
Julien Boeuff47a5cb2015-02-18 12:24:08 -0800214
Julien Boeuf510a9202015-08-25 21:51:07 -0700215/* Creates an Oauth2 Refresh Token credentials object for connecting to Google.
216 May return NULL if the input is invalid.
Julien Boeuf9835cf02015-03-09 16:56:44 -0700217 WARNING: Do NOT use this credentials to connect to a non-google service as
218 this could result in an oauth2 token leak.
219 - json_refresh_token is the JSON string containing the refresh token itself
220 along with a client_id and client_secret. */
Craig Tiller9b426372016-01-29 07:58:22 -0800221GRPC_API grpc_call_credentials *grpc_google_refresh_token_credentials_create(
Julien Boeuf8b78c282015-08-14 13:39:19 -0700222 const char *json_refresh_token, void *reserved);
Julien Boeuf9835cf02015-03-09 16:56:44 -0700223
Julien Boeuf2805be12015-07-01 02:47:18 -0700224/* Creates an Oauth2 Access Token credentials with an access token that was
225 aquired by an out of band mechanism. */
Craig Tiller9b426372016-01-29 07:58:22 -0800226GRPC_API grpc_call_credentials *grpc_access_token_credentials_create(
Julien Boeufacd835f2015-10-09 15:20:57 -0700227 const char *access_token, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800228
Julien Boeuf510a9202015-08-25 21:51:07 -0700229/* Creates an IAM credentials object for connecting to Google. */
Craig Tiller9b426372016-01-29 07:58:22 -0800230GRPC_API grpc_call_credentials *grpc_google_iam_credentials_create(
Julien Boeuf510a9202015-08-25 21:51:07 -0700231 const char *authorization_token, const char *authority_selector,
232 void *reserved);
nnoble0c475f02014-12-05 15:37:39 -0800233
Julien Boeuf8b5bb272015-08-31 13:25:21 -0700234/* Callback function to be called by the metadata credentials plugin
Julien Boeuf97f80fa2015-09-15 16:17:31 -0700235 implementation when the metadata is ready.
236 - user_data is the opaque pointer that was passed in the get_metadata method
237 of the grpc_metadata_credentials_plugin (see below).
238 - creds_md is an array of credentials metadata produced by the plugin. It
239 may be set to NULL in case of an error.
240 - num_creds_md is the number of items in the creds_md array.
241 - status must be GRPC_STATUS_OK in case of success or another specific error
242 code otherwise.
243 - error_details contains details about the error if any. In case of success
244 it should be NULL and will be otherwise ignored. */
Julien Boeuf8b5bb272015-08-31 13:25:21 -0700245typedef void (*grpc_credentials_plugin_metadata_cb)(
246 void *user_data, const grpc_metadata *creds_md, size_t num_creds_md,
247 grpc_status_code status, const char *error_details);
248
Julien Boeufea44bba2015-11-18 15:56:01 -0800249/* Context that can be used by metadata credentials plugin in order to create
250 auth related metadata. */
251typedef struct {
252 /* The fully qualifed service url. */
253 const char *service_url;
254
Julien Boeuf3c957e62015-11-18 21:33:58 -0800255 /* The method name of the RPC being called (not fully qualified).
Julien Boeufeb029c92015-11-25 13:47:56 -0800256 The fully qualified method name can be built from the service_url:
257 full_qualified_method_name = ctx->service_url + '/' + ctx->method_name. */
Julien Boeufea44bba2015-11-18 15:56:01 -0800258 const char *method_name;
259
260 /* The auth_context of the channel which gives the server's identity. */
261 const grpc_auth_context *channel_auth_context;
262
263 /* Reserved for future use. */
264 void *reserved;
265} grpc_auth_metadata_context;
266
Julien Boeuf97f80fa2015-09-15 16:17:31 -0700267/* grpc_metadata_credentials plugin is an API user provided structure used to
268 create grpc_credentials objects that can be set on a channel (composed) or
269 a call. See grpc_credentials_metadata_create_from_plugin below.
270 The grpc client stack will call the get_metadata method of the plugin for
271 every call in scope for the credentials created from it. */
Julien Boeuf8b5bb272015-08-31 13:25:21 -0700272typedef struct {
273 /* The implementation of this method has to be non-blocking.
Julien Boeufea44bba2015-11-18 15:56:01 -0800274 - context is the information that can be used by the plugin to create auth
275 metadata.
Julien Boeuf8b5bb272015-08-31 13:25:21 -0700276 - cb is the callback that needs to be called when the metadata is ready.
277 - user_data needs to be passed as the first parameter of the callback. */
Julien Boeufea44bba2015-11-18 15:56:01 -0800278 void (*get_metadata)(void *state, grpc_auth_metadata_context context,
Julien Boeuf8b5bb272015-08-31 13:25:21 -0700279 grpc_credentials_plugin_metadata_cb cb, void *user_data);
280
281 /* Destroys the plugin state. */
282 void (*destroy)(void *state);
283
284 /* State that will be set as the first parameter of the methods above. */
285 void *state;
Julien Boeufcaf99352015-11-19 22:00:30 -0800286
287 /* Type of credentials that this plugin is implementing. */
288 const char *type;
Julien Boeuf8b5bb272015-08-31 13:25:21 -0700289} grpc_metadata_credentials_plugin;
290
Julien Boeuf29ee3f42015-08-31 13:27:33 -0700291/* Creates a credentials object from a plugin. */
Craig Tiller9b426372016-01-29 07:58:22 -0800292GRPC_API grpc_call_credentials *grpc_metadata_credentials_create_from_plugin(
Julien Boeuf8b5bb272015-08-31 13:25:21 -0700293 grpc_metadata_credentials_plugin plugin, void *reserved);
294
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800295/* --- Secure channel creation. --- */
296
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800297/* Creates a secure channel using the passed-in credentials. */
Craig Tillerd6546c92016-01-29 07:59:35 -0800298GRPC_API grpc_channel *grpc_secure_channel_create(
299 grpc_channel_credentials *creds, const char *target,
300 const grpc_channel_args *args, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800301
302/* --- grpc_server_credentials object. ---
303
304 A server credentials object represents a way to authenticate a server. */
305
306typedef struct grpc_server_credentials grpc_server_credentials;
307
308/* Releases a server_credentials object.
309 The creator of the server_credentials object is responsible for its release.
310 */
Craig Tiller9b426372016-01-29 07:58:22 -0800311GRPC_API void grpc_server_credentials_release(grpc_server_credentials *creds);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800312
313/* Creates an SSL server_credentials object.
Julien Boeuf8fbcc432015-01-15 16:44:13 -0800314 - pem_roots_cert is the NULL-terminated string containing the PEM encoding of
315 the client root certificates. This parameter may be NULL if the server does
316 not want the client to be authenticated with SSL.
317 - pem_key_cert_pairs is an array private key / certificate chains of the
318 server. This parameter cannot be NULL.
319 - num_key_cert_pairs indicates the number of items in the private_key_files
Julien Boeuf5029b302015-07-21 23:02:16 -0700320 and cert_chain_files parameters. It should be at least 1.
321 - force_client_auth, if set to non-zero will force the client to authenticate
322 with an SSL cert. Note that this option is ignored if pem_root_certs is
323 NULL. */
Craig Tiller9b426372016-01-29 07:58:22 -0800324GRPC_API grpc_server_credentials *grpc_ssl_server_credentials_create(
Julien Boeuf8fbcc432015-01-15 16:44:13 -0800325 const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs,
Julien Boeuf8b78c282015-08-14 13:39:19 -0700326 size_t num_key_cert_pairs, int force_client_auth, void *reserved);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800327
Jan Tattermuschb0829eb2015-03-03 09:30:55 -0800328/* --- Server-side secure ports. --- */
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800329
Craig Tillerd251ab92015-02-17 17:22:14 -0800330/* Add a HTTP2 over an encrypted link over tcp listener.
Craig Tillerd251ab92015-02-17 17:22:14 -0800331 Returns bound port number on success, 0 on failure.
332 REQUIRES: server not started */
Craig Tillerd6546c92016-01-29 07:59:35 -0800333GRPC_API int grpc_server_add_secure_http2_port(grpc_server *server,
334 const char *addr,
335 grpc_server_credentials *creds);
Craig Tillerd251ab92015-02-17 17:22:14 -0800336
Julien Boeuf9f218dd2015-04-23 10:24:02 -0700337/* --- Call specific credentials. --- */
338
339/* Sets a credentials to a call. Can only be called on the client side before
340 grpc_call_start_batch. */
Craig Tillerd6546c92016-01-29 07:59:35 -0800341GRPC_API grpc_call_error
342grpc_call_set_credentials(grpc_call *call, grpc_call_credentials *creds);
Julien Boeuf9f218dd2015-04-23 10:24:02 -0700343
Julien Boeufea456fc2015-07-07 15:23:30 -0700344/* --- Auth Metadata Processing --- */
345
Julien Boeufea456fc2015-07-07 15:23:30 -0700346/* Callback function that is called when the metadata processing is done.
Julien Boeufee3dbb02015-08-19 22:17:03 -0700347 - Consumed metadata will be removed from the set of metadata available on the
348 call. consumed_md may be NULL if no metadata has been consumed.
349 - Response metadata will be set on the response. response_md may be NULL.
350 - status is GRPC_STATUS_OK for success or a specific status for an error.
351 Common error status for auth metadata processing is either
352 GRPC_STATUS_UNAUTHENTICATED in case of an authentication failure or
353 GRPC_STATUS PERMISSION_DENIED in case of an authorization failure.
354 - error_details gives details about the error. May be NULL. */
Julien Boeufea456fc2015-07-07 15:23:30 -0700355typedef void (*grpc_process_auth_metadata_done_cb)(
356 void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md,
Julien Boeufee3dbb02015-08-19 22:17:03 -0700357 const grpc_metadata *response_md, size_t num_response_md,
358 grpc_status_code status, const char *error_details);
Julien Boeufea456fc2015-07-07 15:23:30 -0700359
Julien Boeuf77a7b872015-08-05 20:11:02 -0700360/* Pluggable server-side metadata processor object. */
Julien Boeufa87d6c22015-07-17 15:51:46 -0700361typedef struct {
Julien Boeuf77a7b872015-08-05 20:11:02 -0700362 /* The context object is read/write: it contains the properties of the
363 channel peer and it is the job of the process function to augment it with
Julien Boeufbf25bb02015-08-14 12:36:11 -0700364 properties derived from the passed-in metadata.
365 The lifetime of these objects is guaranteed until cb is invoked. */
Julien Boeuf77a7b872015-08-05 20:11:02 -0700366 void (*process)(void *state, grpc_auth_context *context,
Julien Boeufbf25bb02015-08-14 12:36:11 -0700367 const grpc_metadata *md, size_t num_md,
Julien Boeuf77a7b872015-08-05 20:11:02 -0700368 grpc_process_auth_metadata_done_cb cb, void *user_data);
Julien Boeuf0c711ad2015-08-28 14:10:58 -0700369 void (*destroy)(void *state);
Julien Boeufa87d6c22015-07-17 15:51:46 -0700370 void *state;
371} grpc_auth_metadata_processor;
Julien Boeufea456fc2015-07-07 15:23:30 -0700372
Craig Tiller9b426372016-01-29 07:58:22 -0800373GRPC_API void grpc_server_credentials_set_auth_metadata_processor(
Julien Boeuf6bdc9b42015-07-19 21:56:02 -0700374 grpc_server_credentials *creds, grpc_auth_metadata_processor processor);
Julien Boeufea456fc2015-07-07 15:23:30 -0700375
nnoble0c475f02014-12-05 15:37:39 -0800376#ifdef __cplusplus
377}
378#endif
379
Craig Tiller9a576332015-06-17 10:21:49 -0700380#endif /* GRPC_GRPC_SECURITY_H */