transport_security_test_lib.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_TEST_CORE_TSI_TRANSPORT_SECURITY_TEST_LIB_H_
20 #define GRPC_TEST_CORE_TSI_TRANSPORT_SECURITY_TEST_LIB_H_
21 
22 #include <grpc/support/sync.h>
23 
25 
26 #define TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE 32
27 #define TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE 128
28 #define TSI_TEST_SMALL_READ_BUFFER_ALLOCATED_SIZE 41
29 #define TSI_TEST_SMALL_PROTECTED_BUFFER_SIZE 37
30 #define TSI_TEST_SMALL_MESSAGE_BUFFER_ALLOCATED_SIZE 42
31 #define TSI_TEST_SMALL_CLIENT_MAX_OUTPUT_PROTECTED_FRAME_SIZE 39
32 #define TSI_TEST_SMALL_SERVER_MAX_OUTPUT_PROTECTED_FRAME_SIZE 43
33 #define TSI_TEST_DEFAULT_BUFFER_SIZE 4096
34 #define TSI_TEST_DEFAULT_PROTECTED_BUFFER_SIZE 16384
35 #define TSI_TEST_DEFAULT_CHANNEL_SIZE 32768
36 #define TSI_TEST_BIG_MESSAGE_SIZE 17000
37 #define TSI_TEST_SMALL_MESSAGE_SIZE 10
38 #define TSI_TEST_NUM_OF_ARGUMENTS 7
39 #define TSI_TEST_NUM_OF_COMBINATIONS 128
40 #define TSI_TEST_UNUSED_BYTES "HELLO GOOGLE"
41 
42 /* --- tsi_test_fixture object ---
43  The tests for specific TSI implementations should create their own
44  custom "subclass" of this fixture, which wraps all information
45  that will be used to test correctness of TSI handshakes and frame
46  protect/unprotect operations with respect to TSI implementations. */
48 
49 /* --- tsi_test_frame_protector_fixture object ---
50  The object wraps all necessary information used to test correctness of TSI
51  frame protector implementations. */
54 
55 /* --- tsi_test_frame_protector_config object ---
56  This object is used to configure different parameters of TSI frame protector
57  APIs. */
59 
60 /* --- tsi_test_channel object ---
61  This object represents simulated channels between the client and server
62  from/to which they could read/write the exchanged information. */
64 
65 /* V-table for tsi_test_fixture operations that are implemented differently in
66  different TSI implementations. */
67 typedef struct tsi_test_fixture_vtable {
72 
75  /* client/server TSI handshaker used to perform TSI handshakes, and will get
76  instantiated during the call to setup_handshakers. */
79  /* client/server TSI handshaker results used to store the result of TSI
80  handshake. If the handshake fails, the result will store NULL upon
81  finishing the handshake. */
84  /* size of buffer used to store data received from the peer. */
86  /* tsi_test_channel instance. */
88  /* tsi_test_frame_protector_config instance */
90  /* a flag indicating if client has finished TSI handshake first (i.e., before
91  server).
92  The flag should be referred if and only if TSI handshake finishes
93  successfully. */
95  /* a flag indicating whether to test tsi_handshaker_result_get_unused_bytes()
96  for TSI implementation. This field is true by default, and false
97  for SSL TSI implementation due to grpc issue #12164
98  (https://github.com/grpc/grpc/issues/12164).
99  */
101  /* These objects will be used coordinate client/server handshakers with TSI
102  thread to perform TSI handshakes in an asynchronous manner (for GTS TSI
103  implementations).
104  */
107  bool notified;
108 };
109 
111  /* client/server TSI frame protectors whose ownership are transferred. */
114  /* tsi_test_channel instance. */
116  /* tsi_test_frame_protector_config instance */
118 };
119 
121  /* simulated channels between client and server. If the server (client)
122  wants to send data to the client (server), he will write data to
123  client_channel (server_channel), which will be read by client (server). */
126  /* size of data written to the client/server channel. */
129  /* size of data read from the client/server channel */
132 };
133 
135  /* size of buffer used to store protected frames to be unprotected. */
137  /* size of buffer used to store bytes resulted from unprotect operations. */
139  /* size of buffer used to store frames resulted from protect operations. */
141  /* size of client/server maximum frame size. */
144  /* pointer that points to client/server message to be protected. */
147  /* size of client/server message. */
150 };
151 
152 /* This method creates a tsi_test_frame_protector_config instance. Each
153  parameter of this function is a boolean value indicating whether to set the
154  corresponding parameter with a default value or not. If it's false, it will
155  be set with a specific value which is usually much smaller than the default.
156  Both values are defined with #define directive. */
158  bool use_default_read_buffer_allocated_size,
159  bool use_default_message_buffer_allocated_size,
160  bool use_default_protected_buffer_size, bool use_default_client_message,
161  bool use_default_server_message,
162  bool use_default_client_max_output_protected_frame_size,
163  bool use_default_server_max_output_protected_frame_size);
164 
165 /* This method sets different buffer and frame sizes of a
166  tsi_test_frame_protector_config instance with user provided values. */
168  tsi_test_frame_protector_config* config, size_t read_buffer_allocated_size,
169  size_t message_buffer_allocated_size, size_t protected_buffer_size,
170  size_t client_max_output_protected_frame_size,
171  size_t server_max_output_protected_frame_size);
172 
173 /* This method destroys a tsi_test_frame_protector_config instance. */
176 
177 /* This method initializes members of tsi_test_fixture instance.
178  Note that the struct instance should be allocated before making
179  this call. */
181 
182 /* This method destroys a tsi_test_fixture instance. Note that the
183  fixture intance must be dynamically allocated and will be freed by
184  this function. */
186 
187 /* This method creates a tsi_test_frame_protector_fixture instance. */
189 
190 /* This method initializes members of tsi_test_frame_protector_fixture instance.
191  Note that the struct instance should be allocated before making
192  this call. */
195  tsi_frame_protector* client_frame_protector,
196  tsi_frame_protector* server_frame_protector);
197 
198 /* This method destroys a tsi_test_frame_protector_fixture instance. Note that
199  the fixture intance must be dynamically allocated and will be freed by this
200  function. */
203 
204 /* This method performs a protect opeation on raw data and sends the result to
205  peer. */
208  tsi_frame_protector* protector, bool is_client);
209 
210 /* This method receives message from peer and unprotects it. */
213  tsi_frame_protector* protector, unsigned char* message,
214  size_t* bytes_received, bool is_client);
215 
216 /* This method performs a full TSI handshake between a client and a server.
217  Note that the test library will implement the new TSI handshaker API to
218  perform handshakes. */
220 
221 /* This method performs a round trip test between the client and the server.
222  That is, the client sends a protected message to a server who receives the
223  message, and unprotects it. The same operation is triggered again with
224  the client and server switching its role. */
226 
227 /* This method performs the above round trip test without doing handshakes. */
230 
231 #endif // GRPC_TEST_CORE_TSI_TRANSPORT_SECURITY_TEST_LIB_H_
tsi_test_do_handshake
void tsi_test_do_handshake(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.cc:386
tsi_test_channel::client_channel
uint8_t * client_channel
Definition: transport_security_test_lib.h:124
tsi_test_fixture::server_handshaker
tsi_handshaker * server_handshaker
Definition: transport_security_test_lib.h:78
tsi_test_fixture::client_result
tsi_handshaker_result * client_result
Definition: transport_security_test_lib.h:82
tsi_test_channel::bytes_read_from_client_channel
size_t bytes_read_from_client_channel
Definition: transport_security_test_lib.h:130
tsi_test_channel::server_channel
uint8_t * server_channel
Definition: transport_security_test_lib.h:125
tsi_test_fixture_vtable
Definition: transport_security_test_lib.h:67
tsi_handshaker
Definition: transport_security.h:84
tsi_test_frame_protector_config::protected_buffer_size
size_t protected_buffer_size
Definition: transport_security_test_lib.h:140
gpr_cv
pthread_cond_t gpr_cv
Definition: impl/codegen/sync_posix.h:48
tsi_test_fixture::test_unused_bytes
bool test_unused_bytes
Definition: transport_security_test_lib.h:100
tsi_test_frame_protector_fixture
Definition: transport_security_test_lib.h:110
bytes_received
static int bytes_received
Definition: test-callback-stack.c:44
tsi_test_do_round_trip
void tsi_test_do_round_trip(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.cc:459
tsi_test_fixture::handshake_buffer_size
size_t handshake_buffer_size
Definition: transport_security_test_lib.h:85
tsi_test_frame_protector_fixture::channel
tsi_test_channel * channel
Definition: transport_security_test_lib.h:115
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
tsi_test_fixture_init
void tsi_test_fixture_init(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.cc:607
tsi_test_fixture::notified
bool notified
Definition: transport_security_test_lib.h:107
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
tsi_test_frame_protector_config::server_message_size
size_t server_message_size
Definition: transport_security_test_lib.h:149
tsi_test_frame_protector_config::client_message
uint8_t * client_message
Definition: transport_security_test_lib.h:145
tsi_test_channel
Definition: transport_security_test_lib.h:120
tsi_test_fixture::mu
gpr_mu mu
Definition: transport_security_test_lib.h:106
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
tsi_test_frame_protector_fixture::server_frame_protector
tsi_frame_protector * server_frame_protector
Definition: transport_security_test_lib.h:113
fixture
static const char fixture[]
Definition: test-fs-copyfile.c:36
tsi_test_frame_protector_send_message_to_peer
void tsi_test_frame_protector_send_message_to_peer(tsi_test_frame_protector_config *config, tsi_test_channel *channel, tsi_frame_protector *protector, bool is_client)
Definition: transport_security_test_lib.cc:187
tsi_test_fixture_vtable::check_handshaker_peers
void(* check_handshaker_peers)(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.h:69
tsi_test_frame_protector_receive_message_from_peer
void tsi_test_frame_protector_receive_message_from_peer(tsi_test_frame_protector_config *config, tsi_test_channel *channel, tsi_frame_protector *protector, unsigned char *message, size_t *bytes_received, bool is_client)
Definition: transport_security_test_lib.cc:237
tsi_test_fixture::config
tsi_test_frame_protector_config * config
Definition: transport_security_test_lib.h:89
tsi_test_frame_protector_config::read_buffer_allocated_size
size_t read_buffer_allocated_size
Definition: transport_security_test_lib.h:136
tsi_test_frame_protector_config_set_buffer_size
void tsi_test_frame_protector_config_set_buffer_size(tsi_test_frame_protector_config *config, size_t read_buffer_allocated_size, size_t message_buffer_allocated_size, size_t protected_buffer_size, size_t client_max_output_protected_frame_size, size_t server_max_output_protected_frame_size)
Definition: transport_security_test_lib.cc:560
tsi_test_fixture_vtable
struct tsi_test_fixture_vtable tsi_test_fixture_vtable
tsi_test_fixture::vtable
const tsi_test_fixture_vtable * vtable
Definition: transport_security_test_lib.h:74
tsi_test_fixture_vtable::destruct
void(* destruct)(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.h:70
tsi_test_fixture_vtable::setup_handshakers
void(* setup_handshakers)(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.h:68
transport_security_interface.h
tsi_test_fixture::cv
gpr_cv cv
Definition: transport_security_test_lib.h:105
tsi_test_frame_protector_fixture_create
tsi_test_frame_protector_fixture * tsi_test_frame_protector_fixture_create()
Definition: transport_security_test_lib.cc:637
tsi_test_channel::bytes_written_to_server_channel
size_t bytes_written_to_server_channel
Definition: transport_security_test_lib.h:128
tsi_test_frame_protector_config::client_max_output_protected_frame_size
size_t client_max_output_protected_frame_size
Definition: transport_security_test_lib.h:142
tsi_test_frame_protector_config_create
tsi_test_frame_protector_config * tsi_test_frame_protector_config_create(bool use_default_read_buffer_allocated_size, bool use_default_message_buffer_allocated_size, bool use_default_protected_buffer_size, bool use_default_client_message, bool use_default_server_message, bool use_default_client_max_output_protected_frame_size, bool use_default_server_max_output_protected_frame_size)
Definition: transport_security_test_lib.cc:503
gpr_mu
pthread_mutex_t gpr_mu
Definition: impl/codegen/sync_posix.h:47
tsi_test_channel::bytes_written_to_client_channel
size_t bytes_written_to_client_channel
Definition: transport_security_test_lib.h:127
tsi_test_frame_protector_config::client_message_size
size_t client_message_size
Definition: transport_security_test_lib.h:148
tsi_test_frame_protector_config
Definition: transport_security_test_lib.h:134
tsi_test_channel::bytes_read_from_server_channel
size_t bytes_read_from_server_channel
Definition: transport_security_test_lib.h:131
tsi_test_frame_protector_fixture_destroy
void tsi_test_frame_protector_fixture_destroy(tsi_test_frame_protector_fixture *fixture)
Definition: transport_security_test_lib.cc:656
tsi_test_fixture
Definition: transport_security_test_lib.h:73
tsi_test_fixture::has_client_finished_first
bool has_client_finished_first
Definition: transport_security_test_lib.h:94
tsi_test_frame_protector_config::server_message
uint8_t * server_message
Definition: transport_security_test_lib.h:146
config_s
Definition: bloaty/third_party/zlib/deflate.c:120
tsi_test_frame_protector_config::server_max_output_protected_frame_size
size_t server_max_output_protected_frame_size
Definition: transport_security_test_lib.h:143
tsi_handshaker_result
Definition: transport_security.h:121
tsi_test_frame_protector_config::message_buffer_allocated_size
size_t message_buffer_allocated_size
Definition: transport_security_test_lib.h:138
tsi_test_frame_protector_fixture::client_frame_protector
tsi_frame_protector * client_frame_protector
Definition: transport_security_test_lib.h:112
tsi_frame_protector
Definition: transport_security.h:51
tsi_test_fixture::server_result
tsi_handshaker_result * server_result
Definition: transport_security_test_lib.h:83
tsi_test_fixture::client_handshaker
tsi_handshaker * client_handshaker
Definition: transport_security_test_lib.h:77
tsi_test_frame_protector_fixture::config
tsi_test_frame_protector_config * config
Definition: transport_security_test_lib.h:117
sync.h
tsi_test_frame_protector_do_round_trip_no_handshake
void tsi_test_frame_protector_do_round_trip_no_handshake(tsi_test_frame_protector_fixture *fixture)
Definition: transport_security_test_lib.cc:451
tsi_test_frame_protector_fixture_init
void tsi_test_frame_protector_fixture_init(tsi_test_frame_protector_fixture *fixture, tsi_frame_protector *client_frame_protector, tsi_frame_protector *server_frame_protector)
Definition: transport_security_test_lib.cc:647
tsi_test_frame_protector_config_destroy
void tsi_test_frame_protector_config_destroy(tsi_test_frame_protector_config *config)
Definition: transport_security_test_lib.cc:575
tsi_test_fixture_destroy
void tsi_test_fixture_destroy(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.cc:620
tsi_test_fixture::channel
tsi_test_channel * channel
Definition: transport_security_test_lib.h:87


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:40