gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
transport_security.h
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_INTERNAL_CORE_TSI_TRANSPORT_SECURITY_H
35 #define GRPC_INTERNAL_CORE_TSI_TRANSPORT_SECURITY_H
36 
37 #include "src/core/tsi/transport_security_interface.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 extern int tsi_tracing_enabled;
44 
45 /* Base for tsi_frame_protector implementations.
46  See transport_security_interface.h for documentation. */
47 typedef struct {
48  tsi_result (*protect)(tsi_frame_protector* self,
49  const unsigned char* unprotected_bytes,
50  size_t* unprotected_bytes_size,
51  unsigned char* protected_output_frames,
52  size_t* protected_output_frames_size);
53  tsi_result (*protect_flush)(tsi_frame_protector* self,
54  unsigned char* protected_output_frames,
55  size_t* protected_output_frames_size,
56  size_t* still_pending_size);
57  tsi_result (*unprotect)(tsi_frame_protector* self,
58  const unsigned char* protected_frames_bytes,
59  size_t* protected_frames_bytes_size,
60  unsigned char* unprotected_bytes,
61  size_t* unprotected_bytes_size);
62  void (*destroy)(tsi_frame_protector* self);
64 
66  const tsi_frame_protector_vtable* vtable;
67 };
68 
69 /* Base for tsi_handshaker implementations.
70  See transport_security_interface.h for documentation. */
71 typedef struct {
72  tsi_result (*get_bytes_to_send_to_peer)(tsi_handshaker* self,
73  unsigned char* bytes,
74  size_t* bytes_size);
75  tsi_result (*process_bytes_from_peer)(tsi_handshaker* self,
76  const unsigned char* bytes,
77  size_t* bytes_size);
78  tsi_result (*get_result)(tsi_handshaker* self);
79  tsi_result (*extract_peer)(tsi_handshaker* self, tsi_peer* peer);
80  tsi_result (*create_frame_protector)(tsi_handshaker* self,
81  size_t* max_protected_frame_size,
82  tsi_frame_protector** protector);
83  void (*destroy)(tsi_handshaker* self);
85 
87  const tsi_handshaker_vtable* vtable;
88  int frame_protector_created;
89 };
90 
91 /* Peer and property construction/destruction functions. */
92 tsi_result tsi_construct_peer(size_t property_count, tsi_peer* peer);
93 tsi_peer_property tsi_init_peer_property(void);
94 void tsi_peer_property_destruct(tsi_peer_property* property);
95 tsi_result tsi_construct_string_peer_property(const char* name,
96  const char* value,
97  size_t value_length,
98  tsi_peer_property* property);
99 tsi_result tsi_construct_allocated_string_peer_property(
100  const char* name, size_t value_length, tsi_peer_property* property);
101 tsi_result tsi_construct_string_peer_property_from_cstring(
102  const char* name, const char* value, tsi_peer_property* property);
103 
104 /* Utils. */
105 char* tsi_strdup(const char* src); /* Sadly, no strdup in C89. */
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif /* GRPC_INTERNAL_CORE_TSI_TRANSPORT_SECURITY_H */
Definition: transport_security.h:65
Definition: transport_security_interface.h:192
Definition: transport_security.h:47
Definition: transport_security.h:71
Definition: transport_security.h:86
Definition: transport_security_interface.h:184