GRPC Core  4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
grpc_security.h
Go to the documentation of this file.
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 
34 #ifndef GRPC_GRPC_SECURITY_H
35 #define GRPC_GRPC_SECURITY_H
36 
37 #include <grpc/grpc.h>
39 #include <grpc/status.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
48 
51  size_t index;
52  const char *name;
54 
56 typedef struct grpc_auth_property {
57  char *name;
58  char *value;
59  size_t value_length;
61 
65 
69 
74 
78  const grpc_auth_context *ctx, const char *name);
79 
83  const grpc_auth_context *ctx);
84 
87  const grpc_auth_context *ctx);
88 
92 
95 
103  const char *name, const char *value,
104  size_t value_length);
105 
108  const char *name,
109  const char *value);
110 
114  grpc_auth_context *ctx, const char *name);
115 
122 
126 
131 
139  char **pem_root_certs);
140 
148 
150 typedef struct {
153  const char *private_key;
154 
157  const char *cert_chain;
159 
172  const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pair,
173  void *reserved);
174 
182 
186 
189  grpc_channel_credentials *channel_creds, grpc_call_credentials *call_creds,
190  void *reserved);
191 
195  void *reserved);
196 
201  void *reserved);
202 
204 
212  gpr_timespec token_lifetime,
213  void *reserved);
214 
222  const char *json_refresh_token, void *reserved);
223 
227  const char *access_token, void *reserved);
228 
231  const char *authorization_token, const char *authority_selector,
232  void *reserved);
233 
246  void *user_data, const grpc_metadata *creds_md, size_t num_creds_md,
247  grpc_status_code status, const char *error_details);
248 
251 typedef struct {
253  const char *service_url;
254 
258  const char *method_name;
259 
262 
264  void *reserved;
266 
272 typedef struct {
278  void (*get_metadata)(void *state, grpc_auth_metadata_context context,
279  grpc_credentials_plugin_metadata_cb cb, void *user_data);
280 
282  void (*destroy)(void *state);
283 
285  void *state;
286 
288  const char *type;
290 
293  grpc_metadata_credentials_plugin plugin, void *reserved);
294 
299  grpc_channel_credentials *creds, const char *target,
300  const grpc_channel_args *args, void *reserved);
301 
307 
312 
326  const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs,
327  size_t num_key_cert_pairs, int force_client_auth, void *reserved);
328 
333  const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs,
334  size_t num_key_cert_pairs,
335  grpc_ssl_client_certificate_request_type client_certificate_request,
336  void *reserved);
337 
344  const char *addr,
345  grpc_server_credentials *creds);
346 
352  grpc_call_credentials *creds);
353 
366  void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md,
367  const grpc_metadata *response_md, size_t num_response_md,
368  grpc_status_code status, const char *error_details);
369 
371 typedef struct {
376  void (*process)(void *state, grpc_auth_context *context,
377  const grpc_metadata *md, size_t num_md,
378  grpc_process_auth_metadata_done_cb cb, void *user_data);
379  void (*destroy)(void *state);
380  void *state;
382 
385 
386 #ifdef __cplusplus
387 }
388 #endif
389 
390 #endif /* GRPC_GRPC_SECURITY_H */
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:86
GRPCAPI grpc_auth_property_iterator grpc_auth_context_find_properties_by_name(const grpc_auth_context *ctx, const char *name)
Finds a property in the context.
GRPCAPI void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx, const char *name, const char *value)
Add a C string property.
void(* grpc_process_auth_metadata_done_cb)(void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md, const grpc_metadata *response_md, size_t num_response_md, grpc_status_code status, const char *error_details)
— Auth Metadata Processing —
Definition: grpc_security.h:365
GRPCAPI grpc_auth_property_iterator grpc_auth_context_property_iterator(const grpc_auth_context *ctx)
Iterates over the auth context.
size_t value_length
Definition: grpc_security.h:59
struct grpc_server_credentials grpc_server_credentials
— grpc_server_credentials object.
Definition: grpc_security.h:306
GRPCAPI grpc_call_error grpc_call_set_credentials(grpc_call *call, grpc_call_credentials *creds)
— Call specific credentials.
An array of arguments that can be passed around.
Definition: grpc_types.h:143
char * value
Definition: grpc_security.h:58
GRPCAPI grpc_channel_credentials * grpc_composite_channel_credentials_create(grpc_channel_credentials *channel_creds, grpc_call_credentials *call_creds, void *reserved)
Creates a composite channel credentials object.
struct grpc_channel grpc_channel
The Channel interface allows creation of Call objects.
Definition: grpc_types.h:78
GRPCAPI grpc_call_credentials * grpc_service_account_jwt_access_credentials_create(const char *json_key, gpr_timespec token_lifetime, void *reserved)
Creates a JWT credentials object.
GRPCAPI void grpc_server_credentials_set_auth_metadata_processor(grpc_server_credentials *creds, grpc_auth_metadata_processor processor)
grpc_metadata_credentials plugin is an API user provided structure used to create grpc_credentials ob...
Definition: grpc_security.h:272
const char * method_name
The method name of the RPC being called (not fully qualified).
Definition: grpc_security.h:258
const char * type
Type of credentials that this plugin is implementing.
Definition: grpc_security.h:288
const char * private_key
private_key is the NULL-terminated string containing the PEM encoding of the client's private key...
Definition: grpc_security.h:153
GRPCAPI grpc_call_credentials * grpc_google_refresh_token_credentials_create(const char *json_refresh_token, void *reserved)
Creates an Oauth2 Refresh Token credentials object for connecting to Google.
struct grpc_server grpc_server
A server listens to some port and responds to request calls.
Definition: grpc_types.h:81
GRPCAPI grpc_channel_credentials * grpc_ssl_credentials_create(const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pair, void *reserved)
Creates an SSL credentials object.
void * state
Definition: grpc_security.h:380
char * name
Definition: grpc_security.h:57
void * reserved
Reserved for future use.
Definition: grpc_security.h:264
GRPCAPI grpc_channel * grpc_secure_channel_create(grpc_channel_credentials *creds, const char *target, const grpc_channel_args *args, void *reserved)
— Secure channel creation.
GRPCAPI gpr_timespec grpc_max_auth_token_lifetime()
GRPCAPI void grpc_auth_context_add_property(grpc_auth_context *ctx, const char *name, const char *value, size_t value_length)
– The following auth context methods should only be called by a server metadata processor to set prop...
GRPCAPI grpc_channel_credentials * grpc_google_default_credentials_create(void)
Creates default credentials to connect to a google gRPC service.
GRPCAPI void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb)
Setup a callback to override the default TLS/SSL roots.
grpc_call_error
Result of a grpc call.
Definition: grpc_types.h:311
GRPCAPI grpc_auth_context * grpc_call_auth_context(grpc_call *call)
Gets the auth context from the call.
GRPCAPI int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr, grpc_server_credentials *creds)
— Server-side secure ports.
const grpc_auth_context * ctx
Definition: grpc_security.h:50
GRPCAPI const grpc_auth_property * grpc_auth_property_iterator_next(grpc_auth_property_iterator *it)
Returns NULL when the iterator is at the end.
const char * service_url
The fully qualifed service url.
Definition: grpc_security.h:253
const char * name
Definition: grpc_security.h:52
GRPCAPI void grpc_call_credentials_release(grpc_call_credentials *creds)
Releases a call credentials object.
size_t index
Definition: grpc_security.h:51
Definition: grpc_security.h:49
struct grpc_call_credentials grpc_call_credentials
— grpc_call_credentials object.
Definition: grpc_security.h:181
Object that holds a private key / certificate chain pair in PEM format.
Definition: grpc_security.h:150
const grpc_auth_context * channel_auth_context
The auth_context of the channel which gives the server's identity.
Definition: grpc_security.h:261
A single metadata element.
Definition: grpc_types.h:384
struct grpc_auth_context grpc_auth_context
— Authentication Context.
Definition: grpc_security.h:47
struct grpc_auth_property_iterator grpc_auth_property_iterator
GRPCAPI grpc_auth_property_iterator grpc_auth_context_peer_identity(const grpc_auth_context *ctx)
Gets the peer identity.
grpc_ssl_client_certificate_request_type
Definition: grpc_security_constants.h:66
const char * cert_chain
cert_chain is the NULL-terminated string containing the PEM encoding of the client's certificate chai...
Definition: grpc_security.h:157
GRPCAPI grpc_server_credentials * grpc_ssl_server_credentials_create(const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs, size_t num_key_cert_pairs, int force_client_auth, void *reserved)
Deprecated in favor of grpc_ssl_server_credentials_create_ex.
grpc_ssl_roots_override_result
Results for the SSL roots override callback.
Definition: grpc_security_constants.h:60
Pluggable server-side metadata processor object.
Definition: grpc_security.h:371
#define GRPCAPI
Definition: port_platform.h:420
struct grpc_channel_credentials grpc_channel_credentials
— grpc_channel_credentials object.
Definition: grpc_security.h:121
void * state
State that will be set as the first parameter of the methods above.
Definition: grpc_security.h:285
GRPCAPI void grpc_server_credentials_release(grpc_server_credentials *creds)
Releases a server_credentials object.
GRPCAPI grpc_call_credentials * grpc_google_compute_engine_credentials_create(void *reserved)
Creates a compute engine credentials object for connecting to Google.
value, if not NULL, is guaranteed to be NULL terminated.
Definition: grpc_security.h:56
GRPCAPI grpc_call_credentials * grpc_composite_call_credentials_create(grpc_call_credentials *creds1, grpc_call_credentials *creds2, void *reserved)
Creates a composite call credentials object.
GRPCAPI grpc_call_credentials * grpc_metadata_credentials_create_from_plugin(grpc_metadata_credentials_plugin plugin, void *reserved)
Creates a credentials object from a plugin.
GRPCAPI grpc_call_credentials * grpc_google_iam_credentials_create(const char *authorization_token, const char *authority_selector, void *reserved)
Creates an IAM credentials object for connecting to Google.
struct grpc_auth_property grpc_auth_property
value, if not NULL, is guaranteed to be NULL terminated.
GRPCAPI void grpc_auth_context_release(grpc_auth_context *context)
Releases the auth context returned from grpc_call_auth_context.
GRPCAPI int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context *ctx, const char *name)
Sets the property name.
GRPCAPI grpc_call_credentials * grpc_access_token_credentials_create(const char *access_token, void *reserved)
Creates an Oauth2 Access Token credentials with an access token that was aquired by an out of band me...
GRPCAPI const char * grpc_auth_context_peer_identity_property_name(const grpc_auth_context *ctx)
Gets the name of the property that indicates the peer identity.
Analogous to struct timespec.
Definition: gpr_types.h:62
void(* grpc_credentials_plugin_metadata_cb)(void *user_data, const grpc_metadata *creds_md, size_t num_creds_md, grpc_status_code status, const char *error_details)
Callback function to be called by the metadata credentials plugin implementation when the metadata is...
Definition: grpc_security.h:245
GRPCAPI grpc_server_credentials * grpc_ssl_server_credentials_create_ex(const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pairs, size_t num_key_cert_pairs, grpc_ssl_client_certificate_request_type client_certificate_request, void *reserved)
Same as grpc_ssl_server_credentials_create method except uses grpc_ssl_client_certificate_request_typ...
grpc_status_code
Definition: status.h:41
GRPCAPI int grpc_auth_context_peer_is_authenticated(const grpc_auth_context *ctx)
Returns 1 if the peer is authenticated, 0 otherwise.
Context that can be used by metadata credentials plugin in order to create auth related metadata...
Definition: grpc_security.h:251
grpc_ssl_roots_override_result(* grpc_ssl_roots_override_callback)(char **pem_root_certs)
Callback for getting the SSL roots override from the application.
Definition: grpc_security.h:138
GRPCAPI void grpc_channel_credentials_release(grpc_channel_credentials *creds)
Releases a channel credentials object.