aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/tsi
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/tsi')
-rw-r--r--test/core/tsi/BUILD14
-rw-r--r--test/core/tsi/fake_transport_security_test.cc (renamed from test/core/tsi/fake_transport_security_test.c)41
-rw-r--r--test/core/tsi/ssl_transport_security_test.cc (renamed from test/core/tsi/ssl_transport_security_test.c)282
-rw-r--r--test/core/tsi/transport_security_test.cc (renamed from test/core/tsi/transport_security_test.c)249
-rw-r--r--test/core/tsi/transport_security_test_lib.cc (renamed from test/core/tsi/transport_security_test_lib.c)315
-rw-r--r--test/core/tsi/transport_security_test_lib.h48
6 files changed, 485 insertions, 464 deletions
diff --git a/test/core/tsi/BUILD b/test/core/tsi/BUILD
index 0c5509dda6..e28c0b5f84 100644
--- a/test/core/tsi/BUILD
+++ b/test/core/tsi/BUILD
@@ -20,7 +20,7 @@ grpc_package(name = "test/core/tsi")
grpc_cc_library(
name = "transport_security_test_lib",
- srcs = ["transport_security_test_lib.c"],
+ srcs = ["transport_security_test_lib.cc"],
hdrs = ["transport_security_test_lib.h"],
deps = [
"//:grpc",
@@ -30,8 +30,8 @@ grpc_cc_library(
grpc_cc_test(
name = "fake_transport_security_test",
- srcs = ["fake_transport_security_test.c"],
- language = "C",
+ srcs = ["fake_transport_security_test.cc"],
+ language = "C++",
deps = [
":transport_security_test_lib",
"//:grpc",
@@ -44,7 +44,7 @@ grpc_cc_test(
grpc_cc_test(
name = "ssl_transport_security_test",
- srcs = ["ssl_transport_security_test.c"],
+ srcs = ["ssl_transport_security_test.cc"],
data = [
"//src/core/tsi/test_creds:badclient.key",
"//src/core/tsi/test_creds:badclient.pem",
@@ -58,7 +58,7 @@ grpc_cc_test(
"//src/core/tsi/test_creds:server1.key",
"//src/core/tsi/test_creds:server1.pem",
],
- language = "C",
+ language = "C++",
deps = [
":transport_security_test_lib",
"//:grpc",
@@ -70,8 +70,8 @@ grpc_cc_test(
grpc_cc_test(
name = "transport_security_test",
- srcs = ["transport_security_test.c"],
- language = "C",
+ srcs = ["transport_security_test.cc"],
+ language = "C++",
deps = [
"//:grpc",
"//:gpr",
diff --git a/test/core/tsi/fake_transport_security_test.c b/test/core/tsi/fake_transport_security_test.cc
index 11be8802b7..73643fc9fd 100644
--- a/test/core/tsi/fake_transport_security_test.c
+++ b/test/core/tsi/fake_transport_security_test.cc
@@ -33,66 +33,67 @@ typedef struct fake_tsi_test_fixture {
tsi_test_fixture base;
} fake_tsi_test_fixture;
-static void fake_test_setup_handshakers(tsi_test_fixture *fixture) {
+static void fake_test_setup_handshakers(tsi_test_fixture* fixture) {
fixture->client_handshaker =
tsi_create_fake_handshaker(true /* is_client. */);
fixture->server_handshaker =
tsi_create_fake_handshaker(false /* is_client. */);
}
-static void validate_handshaker_peers(tsi_handshaker_result *result) {
- GPR_ASSERT(result != NULL);
+static void validate_handshaker_peers(tsi_handshaker_result* result) {
+ GPR_ASSERT(result != nullptr);
tsi_peer peer;
GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK);
- const tsi_peer_property *property =
+ const tsi_peer_property* property =
tsi_peer_get_property_by_name(&peer, TSI_CERTIFICATE_TYPE_PEER_PROPERTY);
- GPR_ASSERT(property != NULL);
+ GPR_ASSERT(property != nullptr);
GPR_ASSERT(memcmp(property->value.data, TSI_FAKE_CERTIFICATE_TYPE,
property->value.length) == 0);
tsi_peer_destruct(&peer);
}
-static void fake_test_check_handshaker_peers(tsi_test_fixture *fixture) {
+static void fake_test_check_handshaker_peers(tsi_test_fixture* fixture) {
validate_handshaker_peers(fixture->client_result);
validate_handshaker_peers(fixture->server_result);
}
-static void fake_test_destruct(tsi_test_fixture *fixture) {}
+static void fake_test_destruct(tsi_test_fixture* fixture) {}
static const struct tsi_test_fixture_vtable vtable = {
fake_test_setup_handshakers, fake_test_check_handshaker_peers,
fake_test_destruct};
-static tsi_test_fixture *fake_tsi_test_fixture_create() {
- fake_tsi_test_fixture *fake_fixture = gpr_zalloc(sizeof(*fake_fixture));
+static tsi_test_fixture* fake_tsi_test_fixture_create() {
+ fake_tsi_test_fixture* fake_fixture =
+ static_cast<fake_tsi_test_fixture*>(gpr_zalloc(sizeof(*fake_fixture)));
tsi_test_fixture_init(&fake_fixture->base);
fake_fixture->base.vtable = &vtable;
return &fake_fixture->base;
}
void fake_tsi_test_do_handshake_tiny_handshake_buffer() {
- tsi_test_fixture *fixture = fake_tsi_test_fixture_create();
+ tsi_test_fixture* fixture = fake_tsi_test_fixture_create();
fixture->handshake_buffer_size = TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void fake_tsi_test_do_handshake_small_handshake_buffer() {
- tsi_test_fixture *fixture = fake_tsi_test_fixture_create();
+ tsi_test_fixture* fixture = fake_tsi_test_fixture_create();
fixture->handshake_buffer_size = TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void fake_tsi_test_do_handshake() {
- tsi_test_fixture *fixture = fake_tsi_test_fixture_create();
+ tsi_test_fixture* fixture = fake_tsi_test_fixture_create();
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void fake_tsi_test_do_round_trip_for_all_configs() {
- unsigned int *bit_array =
- gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS);
+ unsigned int* bit_array = static_cast<unsigned int*>(
+ gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS));
const unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1);
for (unsigned int val = 0; val < TSI_TEST_NUM_OF_COMBINATIONS; val++) {
unsigned int v = val;
@@ -100,8 +101,8 @@ void fake_tsi_test_do_round_trip_for_all_configs() {
bit_array[ind] = (v & mask) ? 1 : 0;
v <<= 1;
}
- tsi_test_fixture *fixture = fake_tsi_test_fixture_create();
- fake_tsi_test_fixture *fake_fixture = (fake_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = fake_tsi_test_fixture_create();
+ fake_tsi_test_fixture* fake_fixture = (fake_tsi_test_fixture*)fixture;
tsi_test_frame_protector_config_destroy(fake_fixture->base.config);
fake_fixture->base.config = tsi_test_frame_protector_config_create(
bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4],
@@ -120,9 +121,9 @@ void fake_tsi_test_do_round_trip_odd_buffer_size() {
for (size_t ind3 = 0; ind3 < size; ind3++) {
for (size_t ind4 = 0; ind4 < size; ind4++) {
for (size_t ind5 = 0; ind5 < size; ind5++) {
- tsi_test_fixture *fixture = fake_tsi_test_fixture_create();
- fake_tsi_test_fixture *fake_fixture =
- (fake_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = fake_tsi_test_fixture_create();
+ fake_tsi_test_fixture* fake_fixture =
+ (fake_tsi_test_fixture*)fixture;
tsi_test_frame_protector_config_set_buffer_size(
fake_fixture->base.config, odd_sizes[ind1], odd_sizes[ind2],
odd_sizes[ind3], odd_sizes[ind4], odd_sizes[ind5]);
@@ -135,7 +136,7 @@ void fake_tsi_test_do_round_trip_odd_buffer_size() {
}
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
grpc_init();
fake_tsi_test_do_handshake_tiny_handshake_buffer();
diff --git a/test/core/tsi/ssl_transport_security_test.c b/test/core/tsi/ssl_transport_security_test.cc
index 2399b054b1..8939c0434b 100644
--- a/test/core/tsi/ssl_transport_security_test.c
+++ b/test/core/tsi/ssl_transport_security_test.cc
@@ -52,8 +52,8 @@ typedef enum AlpnMode {
typedef struct ssl_alpn_lib {
AlpnMode alpn_mode;
- char **server_alpn_protocols;
- char **client_alpn_protocols;
+ char** server_alpn_protocols;
+ char** client_alpn_protocols;
uint16_t num_server_alpn_protocols;
uint16_t num_client_alpn_protocols;
} ssl_alpn_lib;
@@ -61,9 +61,9 @@ typedef struct ssl_alpn_lib {
typedef struct ssl_key_cert_lib {
bool use_bad_server_cert;
bool use_bad_client_cert;
- char *root_cert;
- tsi_ssl_pem_key_cert_pair *server_pem_key_cert_pairs;
- tsi_ssl_pem_key_cert_pair *bad_server_pem_key_cert_pairs;
+ char* root_cert;
+ tsi_ssl_pem_key_cert_pair* server_pem_key_cert_pairs;
+ tsi_ssl_pem_key_cert_pair* bad_server_pem_key_cert_pairs;
tsi_ssl_pem_key_cert_pair client_pem_key_cert_pair;
tsi_ssl_pem_key_cert_pair bad_client_pem_key_cert_pair;
uint16_t server_num_key_cert_pairs;
@@ -72,29 +72,29 @@ typedef struct ssl_key_cert_lib {
typedef struct ssl_tsi_test_fixture {
tsi_test_fixture base;
- ssl_key_cert_lib *key_cert_lib;
- ssl_alpn_lib *alpn_lib;
+ ssl_key_cert_lib* key_cert_lib;
+ ssl_alpn_lib* alpn_lib;
bool force_client_auth;
- char *server_name_indication;
- tsi_ssl_server_handshaker_factory *server_handshaker_factory;
- tsi_ssl_client_handshaker_factory *client_handshaker_factory;
+ char* server_name_indication;
+ tsi_ssl_server_handshaker_factory* server_handshaker_factory;
+ tsi_ssl_client_handshaker_factory* client_handshaker_factory;
} ssl_tsi_test_fixture;
-static void ssl_test_setup_handshakers(tsi_test_fixture *fixture) {
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
- GPR_ASSERT(ssl_fixture != NULL);
- GPR_ASSERT(ssl_fixture->key_cert_lib != NULL);
- GPR_ASSERT(ssl_fixture->alpn_lib != NULL);
- ssl_key_cert_lib *key_cert_lib = ssl_fixture->key_cert_lib;
- ssl_alpn_lib *alpn_lib = ssl_fixture->alpn_lib;
+static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) {
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
+ GPR_ASSERT(ssl_fixture != nullptr);
+ GPR_ASSERT(ssl_fixture->key_cert_lib != nullptr);
+ GPR_ASSERT(ssl_fixture->alpn_lib != nullptr);
+ ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib;
+ ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib;
/* Create client handshaker factory. */
- tsi_ssl_pem_key_cert_pair *client_key_cert_pair = NULL;
+ tsi_ssl_pem_key_cert_pair* client_key_cert_pair = nullptr;
if (ssl_fixture->force_client_auth) {
client_key_cert_pair = key_cert_lib->use_bad_client_cert
? &key_cert_lib->bad_client_pem_key_cert_pair
: &key_cert_lib->client_pem_key_cert_pair;
}
- char **client_alpn_protocols = NULL;
+ char** client_alpn_protocols = nullptr;
uint16_t num_client_alpn_protocols = 0;
if (alpn_lib->alpn_mode == ALPN_CLIENT_NO_SERVER ||
alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK ||
@@ -103,12 +103,11 @@ static void ssl_test_setup_handshakers(tsi_test_fixture *fixture) {
num_client_alpn_protocols = alpn_lib->num_client_alpn_protocols;
}
GPR_ASSERT(tsi_create_ssl_client_handshaker_factory(
- client_key_cert_pair, key_cert_lib->root_cert, NULL,
- (const char **)client_alpn_protocols,
- num_client_alpn_protocols,
+ client_key_cert_pair, key_cert_lib->root_cert, nullptr,
+ (const char**)client_alpn_protocols, num_client_alpn_protocols,
&ssl_fixture->client_handshaker_factory) == TSI_OK);
/* Create server handshaker factory. */
- char **server_alpn_protocols = NULL;
+ char** server_alpn_protocols = nullptr;
uint16_t num_server_alpn_protocols = 0;
if (alpn_lib->alpn_mode == ALPN_SERVER_NO_CLIENT ||
alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK ||
@@ -126,19 +125,19 @@ static void ssl_test_setup_handshakers(tsi_test_fixture *fixture) {
key_cert_lib->use_bad_server_cert
? key_cert_lib->bad_server_num_key_cert_pairs
: key_cert_lib->server_num_key_cert_pairs,
- key_cert_lib->root_cert, ssl_fixture->force_client_auth, NULL,
- (const char **)server_alpn_protocols,
+ key_cert_lib->root_cert, ssl_fixture->force_client_auth,
+ nullptr, (const char**)server_alpn_protocols,
num_server_alpn_protocols,
&ssl_fixture->server_handshaker_factory) == TSI_OK);
/* Create server and client handshakers. */
- tsi_handshaker *client_handshaker = NULL;
+ tsi_handshaker* client_handshaker = nullptr;
GPR_ASSERT(tsi_ssl_client_handshaker_factory_create_handshaker(
ssl_fixture->client_handshaker_factory,
ssl_fixture->server_name_indication,
&client_handshaker) == TSI_OK);
ssl_fixture->base.client_handshaker =
tsi_create_adapter_handshaker(client_handshaker);
- tsi_handshaker *server_handshaker = NULL;
+ tsi_handshaker* server_handshaker = nullptr;
GPR_ASSERT(tsi_ssl_server_handshaker_factory_create_handshaker(
ssl_fixture->server_handshaker_factory, &server_handshaker) ==
TSI_OK);
@@ -146,45 +145,45 @@ static void ssl_test_setup_handshakers(tsi_test_fixture *fixture) {
tsi_create_adapter_handshaker(server_handshaker);
}
-static void check_alpn(ssl_tsi_test_fixture *ssl_fixture,
- const tsi_peer *peer) {
- GPR_ASSERT(ssl_fixture != NULL);
- GPR_ASSERT(ssl_fixture->alpn_lib != NULL);
- ssl_alpn_lib *alpn_lib = ssl_fixture->alpn_lib;
- const tsi_peer_property *alpn_property =
+static void check_alpn(ssl_tsi_test_fixture* ssl_fixture,
+ const tsi_peer* peer) {
+ GPR_ASSERT(ssl_fixture != nullptr);
+ GPR_ASSERT(ssl_fixture->alpn_lib != nullptr);
+ ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib;
+ const tsi_peer_property* alpn_property =
tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL);
if (alpn_lib->alpn_mode != ALPN_CLIENT_SERVER_OK) {
- GPR_ASSERT(alpn_property == NULL);
+ GPR_ASSERT(alpn_property == nullptr);
} else {
- GPR_ASSERT(alpn_property != NULL);
- const char *expected_match = "baz";
+ GPR_ASSERT(alpn_property != nullptr);
+ const char* expected_match = "baz";
GPR_ASSERT(memcmp(alpn_property->value.data, expected_match,
alpn_property->value.length) == 0);
}
}
-static const tsi_peer_property *
-check_basic_authenticated_peer_and_get_common_name(const tsi_peer *peer) {
- const tsi_peer_property *cert_type_property =
+static const tsi_peer_property*
+check_basic_authenticated_peer_and_get_common_name(const tsi_peer* peer) {
+ const tsi_peer_property* cert_type_property =
tsi_peer_get_property_by_name(peer, TSI_CERTIFICATE_TYPE_PEER_PROPERTY);
- GPR_ASSERT(cert_type_property != NULL);
+ GPR_ASSERT(cert_type_property != nullptr);
GPR_ASSERT(memcmp(cert_type_property->value.data, TSI_X509_CERTIFICATE_TYPE,
cert_type_property->value.length) == 0);
- const tsi_peer_property *property = tsi_peer_get_property_by_name(
+ const tsi_peer_property* property = tsi_peer_get_property_by_name(
peer, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY);
- GPR_ASSERT(property != NULL);
+ GPR_ASSERT(property != nullptr);
return property;
}
-void check_server0_peer(tsi_peer *peer) {
- const tsi_peer_property *property =
+void check_server0_peer(tsi_peer* peer) {
+ const tsi_peer_property* property =
check_basic_authenticated_peer_and_get_common_name(peer);
- const char *expected_match = "*.test.google.com.au";
+ const char* expected_match = "*.test.google.com.au";
GPR_ASSERT(memcmp(property->value.data, expected_match,
property->value.length) == 0);
GPR_ASSERT(tsi_peer_get_property_by_name(
peer, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) ==
- NULL);
+ nullptr);
GPR_ASSERT(tsi_ssl_peer_matches_name(peer, "foo.test.google.com.au") == 1);
GPR_ASSERT(tsi_ssl_peer_matches_name(peer, "bar.test.google.com.au") == 1);
GPR_ASSERT(tsi_ssl_peer_matches_name(peer, "bar.test.google.blah") == 0);
@@ -194,9 +193,9 @@ void check_server0_peer(tsi_peer *peer) {
tsi_peer_destruct(peer);
}
-static bool check_subject_alt_name(tsi_peer *peer, const char *name) {
+static bool check_subject_alt_name(tsi_peer* peer, const char* name) {
for (size_t i = 0; i < peer->property_count; i++) {
- const tsi_peer_property *prop = &peer->properties[i];
+ const tsi_peer_property* prop = &peer->properties[i];
if (strcmp(prop->name, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) ==
0) {
if (memcmp(prop->value.data, name, prop->value.length) == 0) {
@@ -207,10 +206,10 @@ static bool check_subject_alt_name(tsi_peer *peer, const char *name) {
return false;
}
-void check_server1_peer(tsi_peer *peer) {
- const tsi_peer_property *property =
+void check_server1_peer(tsi_peer* peer) {
+ const tsi_peer_property* property =
check_basic_authenticated_peer_and_get_common_name(peer);
- const char *expected_match = "*.test.google.com";
+ const char* expected_match = "*.test.google.com";
GPR_ASSERT(memcmp(property->value.data, expected_match,
property->value.length) == 0);
GPR_ASSERT(check_subject_alt_name(peer, "*.test.google.fr") == 1);
@@ -226,29 +225,29 @@ void check_server1_peer(tsi_peer *peer) {
tsi_peer_destruct(peer);
}
-static void check_client_peer(ssl_tsi_test_fixture *ssl_fixture,
- tsi_peer *peer) {
- GPR_ASSERT(ssl_fixture != NULL);
- GPR_ASSERT(ssl_fixture->alpn_lib != NULL);
- ssl_alpn_lib *alpn_lib = ssl_fixture->alpn_lib;
+static void check_client_peer(ssl_tsi_test_fixture* ssl_fixture,
+ tsi_peer* peer) {
+ GPR_ASSERT(ssl_fixture != nullptr);
+ GPR_ASSERT(ssl_fixture->alpn_lib != nullptr);
+ ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib;
if (!ssl_fixture->force_client_auth) {
GPR_ASSERT(peer->property_count ==
(alpn_lib->alpn_mode == ALPN_CLIENT_SERVER_OK ? 1 : 0));
} else {
- const tsi_peer_property *property =
+ const tsi_peer_property* property =
check_basic_authenticated_peer_and_get_common_name(peer);
- const char *expected_match = "testclient";
+ const char* expected_match = "testclient";
GPR_ASSERT(memcmp(property->value.data, expected_match,
property->value.length) == 0);
}
tsi_peer_destruct(peer);
}
-static void ssl_test_check_handshaker_peers(tsi_test_fixture *fixture) {
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
- GPR_ASSERT(ssl_fixture != NULL);
- GPR_ASSERT(ssl_fixture->key_cert_lib != NULL);
- ssl_key_cert_lib *key_cert_lib = ssl_fixture->key_cert_lib;
+static void ssl_test_check_handshaker_peers(tsi_test_fixture* fixture) {
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
+ GPR_ASSERT(ssl_fixture != nullptr);
+ GPR_ASSERT(ssl_fixture->key_cert_lib != nullptr);
+ ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib;
tsi_peer peer;
bool expect_success =
!(key_cert_lib->use_bad_server_cert ||
@@ -258,13 +257,13 @@ static void ssl_test_check_handshaker_peers(tsi_test_fixture *fixture) {
ssl_fixture->base.client_result, &peer) == TSI_OK);
check_alpn(ssl_fixture, &peer);
- if (ssl_fixture->server_name_indication != NULL) {
+ if (ssl_fixture->server_name_indication != nullptr) {
check_server1_peer(&peer);
} else {
check_server0_peer(&peer);
}
} else {
- GPR_ASSERT(ssl_fixture->base.client_result == NULL);
+ GPR_ASSERT(ssl_fixture->base.client_result == nullptr);
}
if (expect_success) {
GPR_ASSERT(tsi_handshaker_result_extract_peer(
@@ -272,22 +271,22 @@ static void ssl_test_check_handshaker_peers(tsi_test_fixture *fixture) {
check_alpn(ssl_fixture, &peer);
check_client_peer(ssl_fixture, &peer);
} else {
- GPR_ASSERT(ssl_fixture->base.server_result == NULL);
+ GPR_ASSERT(ssl_fixture->base.server_result == nullptr);
}
}
static void ssl_test_pem_key_cert_pair_destroy(tsi_ssl_pem_key_cert_pair kp) {
- gpr_free((void *)kp.private_key);
- gpr_free((void *)kp.cert_chain);
+ gpr_free((void*)kp.private_key);
+ gpr_free((void*)kp.cert_chain);
}
-static void ssl_test_destruct(tsi_test_fixture *fixture) {
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
- if (ssl_fixture == NULL) {
+static void ssl_test_destruct(tsi_test_fixture* fixture) {
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
+ if (ssl_fixture == nullptr) {
return;
}
/* Destroy ssl_alpn_lib. */
- ssl_alpn_lib *alpn_lib = ssl_fixture->alpn_lib;
+ ssl_alpn_lib* alpn_lib = ssl_fixture->alpn_lib;
for (size_t i = 0; i < alpn_lib->num_server_alpn_protocols; i++) {
gpr_free(alpn_lib->server_alpn_protocols[i]);
}
@@ -298,7 +297,7 @@ static void ssl_test_destruct(tsi_test_fixture *fixture) {
gpr_free(alpn_lib->client_alpn_protocols);
gpr_free(alpn_lib);
/* Destroy ssl_key_cert_lib. */
- ssl_key_cert_lib *key_cert_lib = ssl_fixture->key_cert_lib;
+ ssl_key_cert_lib* key_cert_lib = ssl_fixture->key_cert_lib;
for (size_t i = 0; i < key_cert_lib->server_num_key_cert_pairs; i++) {
ssl_test_pem_key_cert_pair_destroy(
key_cert_lib->server_pem_key_cert_pairs[i]);
@@ -325,26 +324,28 @@ static const struct tsi_test_fixture_vtable vtable = {
ssl_test_setup_handshakers, ssl_test_check_handshaker_peers,
ssl_test_destruct};
-static char *load_file(const char *dir_path, const char *file_name) {
- char *file_path =
- gpr_zalloc(sizeof(char) * (strlen(dir_path) + strlen(file_name) + 1));
+static char* load_file(const char* dir_path, const char* file_name) {
+ char* file_path = static_cast<char*>(
+ gpr_zalloc(sizeof(char) * (strlen(dir_path) + strlen(file_name) + 1)));
memcpy(file_path, dir_path, strlen(dir_path));
memcpy(file_path + strlen(dir_path), file_name, strlen(file_name));
grpc_slice slice;
GPR_ASSERT(grpc_load_file(file_path, 1, &slice) == GRPC_ERROR_NONE);
- char *data = grpc_slice_to_c_string(slice);
+ char* data = grpc_slice_to_c_string(slice);
grpc_slice_unref(slice);
gpr_free(file_path);
return data;
}
-static tsi_test_fixture *ssl_tsi_test_fixture_create() {
- ssl_tsi_test_fixture *ssl_fixture = gpr_zalloc(sizeof(*ssl_fixture));
+static tsi_test_fixture* ssl_tsi_test_fixture_create() {
+ ssl_tsi_test_fixture* ssl_fixture =
+ static_cast<ssl_tsi_test_fixture*>(gpr_zalloc(sizeof(*ssl_fixture)));
tsi_test_fixture_init(&ssl_fixture->base);
ssl_fixture->base.test_unused_bytes = false;
ssl_fixture->base.vtable = &vtable;
/* Create ssl_key_cert_lib. */
- ssl_key_cert_lib *key_cert_lib = gpr_zalloc(sizeof(*key_cert_lib));
+ ssl_key_cert_lib* key_cert_lib =
+ static_cast<ssl_key_cert_lib*>(gpr_zalloc(sizeof(*key_cert_lib)));
key_cert_lib->use_bad_server_cert = false;
key_cert_lib->use_bad_client_cert = false;
key_cert_lib->server_num_key_cert_pairs =
@@ -352,11 +353,13 @@ static tsi_test_fixture *ssl_tsi_test_fixture_create() {
key_cert_lib->bad_server_num_key_cert_pairs =
SSL_TSI_TEST_BAD_SERVER_KEY_CERT_PAIRS_NUM;
key_cert_lib->server_pem_key_cert_pairs =
- gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) *
- key_cert_lib->server_num_key_cert_pairs);
+ static_cast<tsi_ssl_pem_key_cert_pair*>(
+ gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) *
+ key_cert_lib->server_num_key_cert_pairs));
key_cert_lib->bad_server_pem_key_cert_pairs =
- gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) *
- key_cert_lib->bad_server_num_key_cert_pairs);
+ static_cast<tsi_ssl_pem_key_cert_pair*>(
+ gpr_malloc(sizeof(tsi_ssl_pem_key_cert_pair) *
+ key_cert_lib->bad_server_num_key_cert_pairs));
key_cert_lib->server_pem_key_cert_pairs[0].private_key =
load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "server0.key");
key_cert_lib->server_pem_key_cert_pairs[0].cert_chain =
@@ -380,11 +383,12 @@ static tsi_test_fixture *ssl_tsi_test_fixture_create() {
key_cert_lib->root_cert = load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "ca.pem");
ssl_fixture->key_cert_lib = key_cert_lib;
/* Create ssl_alpn_lib. */
- ssl_alpn_lib *alpn_lib = gpr_zalloc(sizeof(*alpn_lib));
+ ssl_alpn_lib* alpn_lib =
+ static_cast<ssl_alpn_lib*>(gpr_zalloc(sizeof(*alpn_lib)));
alpn_lib->server_alpn_protocols =
- gpr_zalloc(sizeof(char *) * SSL_TSI_TEST_ALPN_NUM);
+ static_cast<char**>(gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM));
alpn_lib->client_alpn_protocols =
- gpr_zalloc(sizeof(char *) * SSL_TSI_TEST_ALPN_NUM);
+ static_cast<char**>(gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM));
alpn_lib->server_alpn_protocols[0] = gpr_strdup(SSL_TSI_TEST_ALPN1);
alpn_lib->server_alpn_protocols[1] = gpr_strdup(SSL_TSI_TEST_ALPN3);
alpn_lib->client_alpn_protocols[0] = gpr_strdup(SSL_TSI_TEST_ALPN2);
@@ -394,34 +398,34 @@ static tsi_test_fixture *ssl_tsi_test_fixture_create() {
alpn_lib->alpn_mode = NO_ALPN;
ssl_fixture->alpn_lib = alpn_lib;
ssl_fixture->base.vtable = &vtable;
- ssl_fixture->server_name_indication = NULL;
+ ssl_fixture->server_name_indication = nullptr;
ssl_fixture->force_client_auth = false;
return &ssl_fixture->base;
}
void ssl_tsi_test_do_handshake_tiny_handshake_buffer() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
fixture->handshake_buffer_size = TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake_small_handshake_buffer() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
fixture->handshake_buffer_size = TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake_with_client_authentication() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
ssl_fixture->force_client_auth = true;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
@@ -429,33 +433,35 @@ void ssl_tsi_test_do_handshake_with_client_authentication() {
void ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain() {
/* server1 cert contains "waterzooi.test.google.be" in SAN. */
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
- ssl_fixture->server_name_indication = "waterzooi.test.google.be";
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
+ ssl_fixture->server_name_indication =
+ const_cast<char*>("waterzooi.test.google.be");
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain() {
/* server1 cert contains "*.test.google.fr" in SAN. */
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
- ssl_fixture->server_name_indication = "juju.test.google.fr";
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
+ ssl_fixture->server_name_indication =
+ const_cast<char*>("juju.test.google.fr");
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake_with_bad_server_cert() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
ssl_fixture->key_cert_lib->use_bad_server_cert = true;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake_with_bad_client_cert() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
ssl_fixture->key_cert_lib->use_bad_client_cert = true;
ssl_fixture->force_client_auth = true;
tsi_test_do_handshake(fixture);
@@ -463,40 +469,40 @@ void ssl_tsi_test_do_handshake_with_bad_client_cert() {
}
void ssl_tsi_test_do_handshake_alpn_client_no_server() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_NO_SERVER;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake_alpn_server_no_client() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
ssl_fixture->alpn_lib->alpn_mode = ALPN_SERVER_NO_CLIENT;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake_alpn_client_server_mismatch() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_SERVER_MISMATCH;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_handshake_alpn_client_server_ok() {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
ssl_fixture->alpn_lib->alpn_mode = ALPN_CLIENT_SERVER_OK;
tsi_test_do_handshake(fixture);
tsi_test_fixture_destroy(fixture);
}
void ssl_tsi_test_do_round_trip_for_all_configs() {
- unsigned int *bit_array =
- gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS);
+ unsigned int* bit_array = static_cast<unsigned int*>(
+ gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS));
const unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1);
for (unsigned int val = 0; val < TSI_TEST_NUM_OF_COMBINATIONS; val++) {
unsigned int v = val;
@@ -504,8 +510,8 @@ void ssl_tsi_test_do_round_trip_for_all_configs() {
bit_array[ind] = (v & mask) ? 1 : 0;
v <<= 1;
}
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
tsi_test_frame_protector_config_destroy(ssl_fixture->base.config);
ssl_fixture->base.config = tsi_test_frame_protector_config_create(
bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4],
@@ -524,8 +530,8 @@ void ssl_tsi_test_do_round_trip_odd_buffer_size() {
for (size_t ind3 = 0; ind3 < size; ind3++) {
for (size_t ind4 = 0; ind4 < size; ind4++) {
for (size_t ind5 = 0; ind5 < size; ind5++) {
- tsi_test_fixture *fixture = ssl_tsi_test_fixture_create();
- ssl_tsi_test_fixture *ssl_fixture = (ssl_tsi_test_fixture *)fixture;
+ tsi_test_fixture* fixture = ssl_tsi_test_fixture_create();
+ ssl_tsi_test_fixture* ssl_fixture = (ssl_tsi_test_fixture*)fixture;
tsi_test_frame_protector_config_set_buffer_size(
ssl_fixture->base.config, odd_sizes[ind1], odd_sizes[ind2],
odd_sizes[ind3], odd_sizes[ind4], odd_sizes[ind5]);
@@ -538,14 +544,14 @@ void ssl_tsi_test_do_round_trip_odd_buffer_size() {
}
}
-static const tsi_ssl_handshaker_factory_vtable *original_vtable;
+static const tsi_ssl_handshaker_factory_vtable* original_vtable;
static bool handshaker_factory_destructor_called;
static void ssl_tsi_test_handshaker_factory_destructor(
- tsi_ssl_handshaker_factory *factory) {
- GPR_ASSERT(factory != NULL);
+ tsi_ssl_handshaker_factory* factory) {
+ GPR_ASSERT(factory != nullptr);
handshaker_factory_destructor_called = true;
- if (original_vtable != NULL && original_vtable->destroy != NULL) {
+ if (original_vtable != nullptr && original_vtable->destroy != nullptr) {
original_vtable->destroy(factory);
}
}
@@ -555,20 +561,20 @@ static tsi_ssl_handshaker_factory_vtable test_handshaker_factory_vtable = {
void test_tsi_ssl_client_handshaker_factory_refcounting() {
int i;
- const char *cert_chain =
+ const char* cert_chain =
load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "client.pem");
- tsi_ssl_client_handshaker_factory *client_handshaker_factory;
+ tsi_ssl_client_handshaker_factory* client_handshaker_factory;
GPR_ASSERT(tsi_create_ssl_client_handshaker_factory(
- NULL, cert_chain, NULL, NULL, 0, &client_handshaker_factory) ==
- TSI_OK);
+ nullptr, cert_chain, nullptr, nullptr, 0,
+ &client_handshaker_factory) == TSI_OK);
handshaker_factory_destructor_called = false;
original_vtable = tsi_ssl_handshaker_factory_swap_vtable(
- (tsi_ssl_handshaker_factory *)client_handshaker_factory,
+ (tsi_ssl_handshaker_factory*)client_handshaker_factory,
&test_handshaker_factory_vtable);
- tsi_handshaker *handshaker[3];
+ tsi_handshaker* handshaker[3];
for (i = 0; i < 3; ++i) {
GPR_ASSERT(tsi_ssl_client_handshaker_factory_create_handshaker(
@@ -588,14 +594,14 @@ void test_tsi_ssl_client_handshaker_factory_refcounting() {
tsi_handshaker_destroy(handshaker[2]);
GPR_ASSERT(handshaker_factory_destructor_called);
- gpr_free((void *)cert_chain);
+ gpr_free((void*)cert_chain);
}
void test_tsi_ssl_server_handshaker_factory_refcounting() {
int i;
- tsi_ssl_server_handshaker_factory *server_handshaker_factory;
- tsi_handshaker *handshaker[3];
- const char *cert_chain =
+ tsi_ssl_server_handshaker_factory* server_handshaker_factory;
+ tsi_handshaker* handshaker[3];
+ const char* cert_chain =
load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "server0.pem");
tsi_ssl_pem_key_cert_pair cert_pair;
@@ -604,12 +610,12 @@ void test_tsi_ssl_server_handshaker_factory_refcounting() {
load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "server0.key");
GPR_ASSERT(tsi_create_ssl_server_handshaker_factory(
- &cert_pair, 1, cert_chain, 0, NULL, NULL, 0,
+ &cert_pair, 1, cert_chain, 0, nullptr, nullptr, 0,
&server_handshaker_factory) == TSI_OK);
handshaker_factory_destructor_called = false;
original_vtable = tsi_ssl_handshaker_factory_swap_vtable(
- (tsi_ssl_handshaker_factory *)server_handshaker_factory,
+ (tsi_ssl_handshaker_factory*)server_handshaker_factory,
&test_handshaker_factory_vtable);
for (i = 0; i < 3; ++i) {
@@ -635,12 +641,12 @@ void test_tsi_ssl_server_handshaker_factory_refcounting() {
/* Attempting to create a handshaker factory with invalid parameters should fail
* but not crash. */
void test_tsi_ssl_client_handshaker_factory_bad_params() {
- const char *cert_chain = "This is not a valid PEM file.";
+ const char* cert_chain = "This is not a valid PEM file.";
- tsi_ssl_client_handshaker_factory *client_handshaker_factory;
+ tsi_ssl_client_handshaker_factory* client_handshaker_factory;
GPR_ASSERT(tsi_create_ssl_client_handshaker_factory(
- NULL, cert_chain, NULL, NULL, 0, &client_handshaker_factory) ==
- TSI_INVALID_ARGUMENT);
+ nullptr, cert_chain, nullptr, nullptr, 0,
+ &client_handshaker_factory) == TSI_INVALID_ARGUMENT);
tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory);
}
@@ -650,7 +656,7 @@ void ssl_tsi_test_handshaker_factory_internals() {
test_tsi_ssl_client_handshaker_factory_bad_params();
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
grpc_init();
ssl_tsi_test_do_handshake_tiny_handshake_buffer();
diff --git a/test/core/tsi/transport_security_test.c b/test/core/tsi/transport_security_test.cc
index 27932a8169..c788ad96ad 100644
--- a/test/core/tsi/transport_security_test.c
+++ b/test/core/tsi/transport_security_test.cc
@@ -37,46 +37,46 @@ typedef struct {
int expected;
/* Host name to match. */
- const char *host_name;
+ const char* host_name;
/* Common name (CN). */
- const char *common_name;
+ const char* common_name;
/* Comma separated list of certificate names to match against. Any occurrence
of '#' will be replaced with a null character before processing. */
- const char *dns_names;
+ const char* dns_names;
/* Comma separated list of IP SANs to match aggainst */
- const char *ip_names;
+ const char* ip_names;
} cert_name_test_entry;
/* Largely inspired from:
chromium/src/net/cert/x509_certificate_unittest.cc.
TODO(jboeuf) uncomment test cases as we fix tsi_ssl_peer_matches_name. */
const cert_name_test_entry cert_name_test_entries[] = {
- {1, "foo.com", "foo.com", NULL, NULL},
- {1, "f", "f", NULL, NULL},
- {0, "h", "i", NULL, NULL},
- {1, "bar.foo.com", "*.foo.com", NULL, NULL},
+ {1, "foo.com", "foo.com", nullptr, nullptr},
+ {1, "f", "f", nullptr, nullptr},
+ {0, "h", "i", nullptr, nullptr},
+ {1, "bar.foo.com", "*.foo.com", nullptr, nullptr},
{1, "www.test.fr", "common.name",
- "*.test.com,*.test.co.uk,*.test.de,*.test.fr", NULL},
+ "*.test.com,*.test.co.uk,*.test.de,*.test.fr", nullptr},
/*
{1, "wwW.tESt.fr", "common.name", ",*.*,*.test.de,*.test.FR,www"},
*/
- {0, "f.uk", ".uk", NULL, NULL},
- {0, "w.bar.foo.com", "?.bar.foo.com", NULL, NULL},
- {0, "www.foo.com", "(www|ftp).foo.com", NULL, NULL},
- {0, "www.foo.com", "www.foo.com#", NULL, NULL}, /* # = null char. */
- {0, "www.foo.com", "", "www.foo.com#*.foo.com,#,#", NULL},
- {0, "www.house.example", "ww.house.example", NULL, NULL},
- {0, "test.org", "", "www.test.org,*.test.org,*.org", NULL},
- {0, "w.bar.foo.com", "w*.bar.foo.com", NULL, NULL},
- {0, "www.bar.foo.com", "ww*ww.bar.foo.com", NULL, NULL},
- {0, "wwww.bar.foo.com", "ww*ww.bar.foo.com", NULL, NULL},
- {0, "wwww.bar.foo.com", "w*w.bar.foo.com", NULL, NULL},
- {0, "wwww.bar.foo.com", "w*w.bar.foo.c0m", NULL, NULL},
- {0, "WALLY.bar.foo.com", "wa*.bar.foo.com", NULL, NULL},
- {0, "wally.bar.foo.com", "*Ly.bar.foo.com", NULL, NULL},
+ {0, "f.uk", ".uk", nullptr, nullptr},
+ {0, "w.bar.foo.com", "?.bar.foo.com", nullptr, nullptr},
+ {0, "www.foo.com", "(www|ftp).foo.com", nullptr, nullptr},
+ {0, "www.foo.com", "www.foo.com#", nullptr, nullptr}, /* # = null char. */
+ {0, "www.foo.com", "", "www.foo.com#*.foo.com,#,#", nullptr},
+ {0, "www.house.example", "ww.house.example", nullptr, nullptr},
+ {0, "test.org", "", "www.test.org,*.test.org,*.org", nullptr},
+ {0, "w.bar.foo.com", "w*.bar.foo.com", nullptr, nullptr},
+ {0, "www.bar.foo.com", "ww*ww.bar.foo.com", nullptr, nullptr},
+ {0, "wwww.bar.foo.com", "ww*ww.bar.foo.com", nullptr, nullptr},
+ {0, "wwww.bar.foo.com", "w*w.bar.foo.com", nullptr, nullptr},
+ {0, "wwww.bar.foo.com", "w*w.bar.foo.c0m", nullptr, nullptr},
+ {0, "WALLY.bar.foo.com", "wa*.bar.foo.com", nullptr, nullptr},
+ {0, "wally.bar.foo.com", "*Ly.bar.foo.com", nullptr, nullptr},
/*
{1, "ww%57.foo.com", "", "www.foo.com"},
{1, "www&.foo.com", "www%26.foo.com", NULL},
@@ -84,134 +84,138 @@ const cert_name_test_entry cert_name_test_entries[] = {
/* Common name must not be used if subject alternative name was provided. */
{0, "www.test.co.jp", "www.test.co.jp",
- "*.test.de,*.jp,www.test.co.uk,www.*.co.jp", NULL},
+ "*.test.de,*.jp,www.test.co.uk,www.*.co.jp", nullptr},
{0, "www.bar.foo.com", "www.bar.foo.com",
- "*.foo.com,*.*.foo.com,*.*.bar.foo.com,*..bar.foo.com,", NULL},
+ "*.foo.com,*.*.foo.com,*.*.bar.foo.com,*..bar.foo.com,", nullptr},
/* IDN tests */
- {1, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br", NULL, NULL},
- {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL, NULL},
+ {1, "xn--poema-9qae5a.com.br", "xn--poema-9qae5a.com.br", nullptr, nullptr},
+ {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", nullptr,
+ nullptr},
{0, "xn--poema-9qae5a.com.br", "",
"*.xn--poema-9qae5a.com.br,"
"xn--poema-*.com.br,"
"xn--*-9qae5a.com.br,"
"*--poema-9qae5a.com.br",
- NULL},
+ nullptr},
/* The following are adapted from the examples quoted from
http://tools.ietf.org/html/rfc6125#section-6.4.3
(e.g., *.example.com would match foo.example.com but
not bar.foo.example.com or example.com). */
- {1, "foo.example.com", "*.example.com", NULL, NULL},
- {0, "bar.foo.example.com", "*.example.com", NULL, NULL},
- {0, "example.com", "*.example.com", NULL, NULL},
+ {1, "foo.example.com", "*.example.com", nullptr, nullptr},
+ {0, "bar.foo.example.com", "*.example.com", nullptr, nullptr},
+ {0, "example.com", "*.example.com", nullptr, nullptr},
/* Partial wildcards are disallowed, though RFC 2818 rules allow them.
That is, forms such as baz*.example.net, *baz.example.net, and
b*z.example.net should NOT match domains. Instead, the wildcard must
always be the left-most label, and only a single label. */
- {0, "baz1.example.net", "baz*.example.net", NULL, NULL},
- {0, "foobaz.example.net", "*baz.example.net", NULL, NULL},
- {0, "buzz.example.net", "b*z.example.net", NULL, NULL},
- {0, "www.test.example.net", "www.*.example.net", NULL, NULL},
+ {0, "baz1.example.net", "baz*.example.net", nullptr, nullptr},
+ {0, "foobaz.example.net", "*baz.example.net", nullptr, nullptr},
+ {0, "buzz.example.net", "b*z.example.net", nullptr, nullptr},
+ {0, "www.test.example.net", "www.*.example.net", nullptr, nullptr},
/* Wildcards should not be valid for public registry controlled domains,
and unknown/unrecognized domains, at least three domain components must
be present. */
- {1, "www.test.example", "*.test.example", NULL, NULL},
- {1, "test.example.co.uk", "*.example.co.uk", NULL, NULL},
- {0, "test.example", "*.example", NULL, NULL},
+ {1, "www.test.example", "*.test.example", nullptr, nullptr},
+ {1, "test.example.co.uk", "*.example.co.uk", nullptr, nullptr},
+ {0, "test.example", "*.example", nullptr, nullptr},
/*
{0, "example.co.uk", "*.co.uk", NULL},
*/
- {0, "foo.com", "*.com", NULL, NULL},
- {0, "foo.us", "*.us", NULL, NULL},
- {0, "foo", "*", NULL, NULL},
+ {0, "foo.com", "*.com", nullptr, nullptr},
+ {0, "foo.us", "*.us", nullptr, nullptr},
+ {0, "foo", "*", nullptr, nullptr},
/* IDN variants of wildcards and registry controlled domains. */
- {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", NULL, NULL},
- {1, "test.example.xn--mgbaam7a8h", "*.example.xn--mgbaam7a8h", NULL, NULL},
+ {1, "www.xn--poema-9qae5a.com.br", "*.xn--poema-9qae5a.com.br", nullptr,
+ nullptr},
+ {1, "test.example.xn--mgbaam7a8h", "*.example.xn--mgbaam7a8h", nullptr,
+ nullptr},
/*
{0, "xn--poema-9qae5a.com.br", "*.com.br", NULL},
*/
- {0, "example.xn--mgbaam7a8h", "*.xn--mgbaam7a8h", NULL, NULL},
+ {0, "example.xn--mgbaam7a8h", "*.xn--mgbaam7a8h", nullptr, nullptr},
/* Wildcards should be permissible for 'private' registry controlled
domains. */
- {1, "www.appspot.com", "*.appspot.com", NULL, NULL},
- {1, "foo.s3.amazonaws.com", "*.s3.amazonaws.com", NULL, NULL},
+ {1, "www.appspot.com", "*.appspot.com", nullptr, nullptr},
+ {1, "foo.s3.amazonaws.com", "*.s3.amazonaws.com", nullptr, nullptr},
/* Multiple wildcards are not valid. */
- {0, "foo.example.com", "*.*.com", NULL, NULL},
- {0, "foo.bar.example.com", "*.bar.*.com", NULL, NULL},
+ {0, "foo.example.com", "*.*.com", nullptr, nullptr},
+ {0, "foo.bar.example.com", "*.bar.*.com", nullptr, nullptr},
/* Absolute vs relative DNS name tests. Although not explicitly specified
in RFC 6125, absolute reference names (those ending in a .) should
match either absolute or relative presented names. */
- {1, "foo.com", "foo.com.", NULL, NULL},
- {1, "foo.com.", "foo.com", NULL, NULL},
- {1, "foo.com.", "foo.com.", NULL, NULL},
- {1, "f", "f.", NULL, NULL},
- {1, "f.", "f", NULL, NULL},
- {1, "f.", "f.", NULL, NULL},
- {1, "www-3.bar.foo.com", "*.bar.foo.com.", NULL, NULL},
- {1, "www-3.bar.foo.com.", "*.bar.foo.com", NULL, NULL},
- {1, "www-3.bar.foo.com.", "*.bar.foo.com.", NULL, NULL},
- {0, ".", ".", NULL, NULL},
- {0, "example.com", "*.com.", NULL, NULL},
- {0, "example.com.", "*.com", NULL, NULL},
- {0, "example.com.", "*.com.", NULL, NULL},
- {0, "foo.", "*.", NULL, NULL},
- {0, "foo", "*.", NULL, NULL},
+ {1, "foo.com", "foo.com.", nullptr, nullptr},
+ {1, "foo.com.", "foo.com", nullptr, nullptr},
+ {1, "foo.com.", "foo.com.", nullptr, nullptr},
+ {1, "f", "f.", nullptr, nullptr},
+ {1, "f.", "f", nullptr, nullptr},
+ {1, "f.", "f.", nullptr, nullptr},
+ {1, "www-3.bar.foo.com", "*.bar.foo.com.", nullptr, nullptr},
+ {1, "www-3.bar.foo.com.", "*.bar.foo.com", nullptr, nullptr},
+ {1, "www-3.bar.foo.com.", "*.bar.foo.com.", nullptr, nullptr},
+ {0, ".", ".", nullptr, nullptr},
+ {0, "example.com", "*.com.", nullptr, nullptr},
+ {0, "example.com.", "*.com", nullptr, nullptr},
+ {0, "example.com.", "*.com.", nullptr, nullptr},
+ {0, "foo.", "*.", nullptr, nullptr},
+ {0, "foo", "*.", nullptr, nullptr},
/*
{0, "foo.co.uk", "*.co.uk.", NULL},
{0, "foo.co.uk.", "*.co.uk.", NULL},
*/
/* An empty CN is OK. */
- {1, "test.foo.com", "", "test.foo.com", NULL},
+ {1, "test.foo.com", "", "test.foo.com", nullptr},
/* An IP should not be used for the CN. */
- {0, "173.194.195.139", "173.194.195.139", NULL, NULL},
+ {0, "173.194.195.139", "173.194.195.139", nullptr, nullptr},
/* An IP can be used if the SAN IP is present */
- {1, "173.194.195.139", "foo.example.com", NULL, "173.194.195.139"},
- {0, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8"},
- {0, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8,8.8.4.4"},
- {1, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8,173.194.195.139"},
- {0, "173.194.195.139", "foo.example.com", NULL, "173.194.195.13"},
- {0, "2001:db8:a0b:12f0::1", "foo.example.com", NULL, "173.194.195.13"},
- {1, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
+ {1, "173.194.195.139", "foo.example.com", nullptr, "173.194.195.139"},
+ {0, "173.194.195.139", "foo.example.com", nullptr, "8.8.8.8"},
+ {0, "173.194.195.139", "foo.example.com", nullptr, "8.8.8.8,8.8.4.4"},
+ {1, "173.194.195.139", "foo.example.com", nullptr,
+ "8.8.8.8,173.194.195.139"},
+ {0, "173.194.195.139", "foo.example.com", nullptr, "173.194.195.13"},
+ {0, "2001:db8:a0b:12f0::1", "foo.example.com", nullptr, "173.194.195.13"},
+ {1, "2001:db8:a0b:12f0::1", "foo.example.com", nullptr,
"2001:db8:a0b:12f0::1"},
- {0, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
+ {0, "2001:db8:a0b:12f0::1", "foo.example.com", nullptr,
"2001:db8:a0b:12f0::2"},
- {1, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
+ {1, "2001:db8:a0b:12f0::1", "foo.example.com", nullptr,
"2001:db8:a0b:12f0::2,2001:db8:a0b:12f0::1,8.8.8.8"},
};
typedef struct name_list {
- const char *name;
- struct name_list *next;
+ const char* name;
+ struct name_list* next;
} name_list;
typedef struct {
size_t name_count;
- char *buffer;
- name_list *names;
+ char* buffer;
+ name_list* names;
} parsed_names;
-name_list *name_list_add(const char *n) {
- name_list *result = gpr_malloc(sizeof(name_list));
+name_list* name_list_add(const char* n) {
+ name_list* result = static_cast<name_list*>(gpr_malloc(sizeof(name_list)));
result->name = n;
- result->next = NULL;
+ result->next = nullptr;
return result;
}
-static parsed_names parse_names(const char *names_str) {
+static parsed_names parse_names(const char* names_str) {
parsed_names result;
- name_list *current_nl;
+ name_list* current_nl;
size_t i;
memset(&result, 0, sizeof(parsed_names));
- if (names_str == 0) return result;
+ if (names_str == nullptr) return result;
result.name_count = 1;
result.buffer = gpr_strdup(names_str);
result.names = name_list_add(result.buffer);
@@ -228,18 +232,18 @@ static parsed_names parse_names(const char *names_str) {
return result;
}
-static void destruct_parsed_names(parsed_names *pdn) {
- name_list *nl = pdn->names;
- if (pdn->buffer != NULL) gpr_free(pdn->buffer);
- while (nl != NULL) {
- name_list *to_be_free = nl;
+static void destruct_parsed_names(parsed_names* pdn) {
+ name_list* nl = pdn->names;
+ if (pdn->buffer != nullptr) gpr_free(pdn->buffer);
+ while (nl != nullptr) {
+ name_list* to_be_free = nl;
nl = nl->next;
gpr_free(to_be_free);
}
}
-static char *processed_name(const char *name) {
- char *result = gpr_strdup(name);
+static char* processed_name(const char* name) {
+ char* result = gpr_strdup(name);
size_t i;
for (i = 0; i < strlen(result); i++) {
if (result[i] == '#') {
@@ -250,10 +254,10 @@ static char *processed_name(const char *name) {
}
static tsi_peer peer_from_cert_name_test_entry(
- const cert_name_test_entry *entry) {
+ const cert_name_test_entry* entry) {
size_t i;
tsi_peer peer;
- name_list *nl;
+ name_list* nl;
parsed_names dns_entries = parse_names(entry->dns_names);
parsed_names ip_entries = parse_names(entry->ip_names);
nl = dns_entries.names;
@@ -264,8 +268,8 @@ static tsi_peer peer_from_cert_name_test_entry(
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, entry->common_name,
&peer.properties[0]) == TSI_OK);
i = 1;
- while (nl != NULL) {
- char *processed = processed_name(nl->name);
+ while (nl != nullptr) {
+ char* processed = processed_name(nl->name);
GPR_ASSERT(tsi_construct_string_peer_property(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, processed,
strlen(nl->name), &peer.properties[i++]) == TSI_OK);
@@ -274,8 +278,8 @@ static tsi_peer peer_from_cert_name_test_entry(
}
nl = ip_entries.names;
- while (nl != NULL) {
- char *processed = processed_name(nl->name);
+ while (nl != nullptr) {
+ char* processed = processed_name(nl->name);
GPR_ASSERT(tsi_construct_string_peer_property(
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, processed,
strlen(nl->name), &peer.properties[i++]) == TSI_OK);
@@ -287,26 +291,26 @@ static tsi_peer peer_from_cert_name_test_entry(
return peer;
}
-char *cert_name_test_entry_to_string(const cert_name_test_entry *entry) {
- char *s;
+char* cert_name_test_entry_to_string(const cert_name_test_entry* entry) {
+ char* s;
gpr_asprintf(&s,
"{ success = %s, host_name = %s, common_name = %s, dns_names = "
"%s, ip_names = %s}",
entry->expected ? "true" : "false", entry->host_name,
entry->common_name,
- entry->dns_names != NULL ? entry->dns_names : "",
- entry->ip_names != NULL ? entry->ip_names : "");
+ entry->dns_names != nullptr ? entry->dns_names : "",
+ entry->ip_names != nullptr ? entry->ip_names : "");
return s;
}
static void test_peer_matches_name(void) {
size_t i = 0;
for (i = 0; i < GPR_ARRAY_SIZE(cert_name_test_entries); i++) {
- const cert_name_test_entry *entry = &cert_name_test_entries[i];
+ const cert_name_test_entry* entry = &cert_name_test_entries[i];
tsi_peer peer = peer_from_cert_name_test_entry(entry);
int result = tsi_ssl_peer_matches_name(&peer, entry->host_name);
if (result != entry->expected) {
- char *entry_str = cert_name_test_entry_to_string(entry);
+ char* entry_str = cert_name_test_entry_to_string(entry);
gpr_log(GPR_ERROR, "%s", entry_str);
gpr_free(entry_str);
GPR_ASSERT(0); /* Unexpected result. */
@@ -317,7 +321,7 @@ static void test_peer_matches_name(void) {
typedef struct {
tsi_result res;
- const char *str;
+ const char* str;
} tsi_result_string_pair;
static void test_result_strings(void) {
@@ -344,38 +348,39 @@ static void test_result_strings(void) {
}
static void test_protector_invalid_args(void) {
- GPR_ASSERT(tsi_frame_protector_protect(NULL, NULL, NULL, NULL, NULL) ==
- TSI_INVALID_ARGUMENT);
- GPR_ASSERT(tsi_frame_protector_protect_flush(NULL, NULL, NULL, NULL) ==
- TSI_INVALID_ARGUMENT);
- GPR_ASSERT(tsi_frame_protector_unprotect(NULL, NULL, NULL, NULL, NULL) ==
- TSI_INVALID_ARGUMENT);
+ GPR_ASSERT(tsi_frame_protector_protect(nullptr, nullptr, nullptr, nullptr,
+ nullptr) == TSI_INVALID_ARGUMENT);
+ GPR_ASSERT(tsi_frame_protector_protect_flush(
+ nullptr, nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT);
+ GPR_ASSERT(tsi_frame_protector_unprotect(nullptr, nullptr, nullptr, nullptr,
+ nullptr) == TSI_INVALID_ARGUMENT);
}
static void test_handshaker_invalid_args(void) {
- GPR_ASSERT(tsi_handshaker_get_result(NULL) == TSI_INVALID_ARGUMENT);
- GPR_ASSERT(tsi_handshaker_extract_peer(NULL, NULL) == TSI_INVALID_ARGUMENT);
- GPR_ASSERT(tsi_handshaker_create_frame_protector(NULL, NULL, NULL) ==
- TSI_INVALID_ARGUMENT);
- GPR_ASSERT(tsi_handshaker_process_bytes_from_peer(NULL, NULL, NULL) ==
- TSI_INVALID_ARGUMENT);
- GPR_ASSERT(tsi_handshaker_get_bytes_to_send_to_peer(NULL, NULL, NULL) ==
+ GPR_ASSERT(tsi_handshaker_get_result(nullptr) == TSI_INVALID_ARGUMENT);
+ GPR_ASSERT(tsi_handshaker_extract_peer(nullptr, nullptr) ==
TSI_INVALID_ARGUMENT);
- GPR_ASSERT(tsi_handshaker_next(NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL) ==
+ GPR_ASSERT(tsi_handshaker_create_frame_protector(nullptr, nullptr, nullptr) ==
TSI_INVALID_ARGUMENT);
+ GPR_ASSERT(tsi_handshaker_process_bytes_from_peer(
+ nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT);
+ GPR_ASSERT(tsi_handshaker_get_bytes_to_send_to_peer(
+ nullptr, nullptr, nullptr) == TSI_INVALID_ARGUMENT);
+ GPR_ASSERT(tsi_handshaker_next(nullptr, nullptr, 0, nullptr, nullptr, nullptr,
+ nullptr, nullptr) == TSI_INVALID_ARGUMENT);
}
static void test_handshaker_invalid_state(void) {
- tsi_handshaker *h = tsi_create_fake_handshaker(0);
+ tsi_handshaker* h = tsi_create_fake_handshaker(0);
tsi_peer peer;
- tsi_frame_protector *p;
+ tsi_frame_protector* p;
GPR_ASSERT(tsi_handshaker_extract_peer(h, &peer) == TSI_FAILED_PRECONDITION);
- GPR_ASSERT(tsi_handshaker_create_frame_protector(h, NULL, &p) ==
+ GPR_ASSERT(tsi_handshaker_create_frame_protector(h, nullptr, &p) ==
TSI_FAILED_PRECONDITION);
tsi_handshaker_destroy(h);
}
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
grpc_test_init(argc, argv);
test_peer_matches_name();
test_result_strings();
diff --git a/test/core/tsi/transport_security_test_lib.c b/test/core/tsi/transport_security_test_lib.cc
index 329b2371bf..3537366de9 100644
--- a/test/core/tsi/transport_security_test_lib.c
+++ b/test/core/tsi/transport_security_test_lib.cc
@@ -27,14 +27,14 @@
#include "src/core/lib/security/transport/tsi_error.h"
#include "test/core/tsi/transport_security_test_lib.h"
-static void notification_signal(tsi_test_fixture *fixture) {
+static void notification_signal(tsi_test_fixture* fixture) {
gpr_mu_lock(&fixture->mu);
fixture->notified = true;
gpr_cv_signal(&fixture->cv);
gpr_mu_unlock(&fixture->mu);
}
-static void notification_wait(tsi_test_fixture *fixture) {
+static void notification_wait(tsi_test_fixture* fixture) {
gpr_mu_lock(&fixture->mu);
while (!fixture->notified) {
gpr_cv_wait(&fixture->cv, &fixture->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
@@ -44,51 +44,53 @@ static void notification_wait(tsi_test_fixture *fixture) {
}
typedef struct handshaker_args {
- tsi_test_fixture *fixture;
- unsigned char *handshake_buffer;
+ tsi_test_fixture* fixture;
+ unsigned char* handshake_buffer;
size_t handshake_buffer_size;
bool is_client;
bool transferred_data;
bool appended_unused_bytes;
- grpc_error *error;
+ grpc_error* error;
} handshaker_args;
-static handshaker_args *handshaker_args_create(tsi_test_fixture *fixture,
+static handshaker_args* handshaker_args_create(tsi_test_fixture* fixture,
bool is_client) {
- GPR_ASSERT(fixture != NULL);
- GPR_ASSERT(fixture->config != NULL);
- handshaker_args *args = gpr_zalloc(sizeof(*args));
+ GPR_ASSERT(fixture != nullptr);
+ GPR_ASSERT(fixture->config != nullptr);
+ handshaker_args* args =
+ static_cast<handshaker_args*>(gpr_zalloc(sizeof(*args)));
args->fixture = fixture;
args->handshake_buffer_size = fixture->handshake_buffer_size;
- args->handshake_buffer = gpr_zalloc(args->handshake_buffer_size);
+ args->handshake_buffer =
+ static_cast<unsigned char*>(gpr_zalloc(args->handshake_buffer_size));
args->is_client = is_client;
args->error = GRPC_ERROR_NONE;
return args;
}
-static void handshaker_args_destroy(handshaker_args *args) {
+static void handshaker_args_destroy(handshaker_args* args) {
gpr_free(args->handshake_buffer);
GRPC_ERROR_UNREF(args->error);
gpr_free(args);
}
-static void do_handshaker_next(handshaker_args *args);
+static void do_handshaker_next(handshaker_args* args);
-static void setup_handshakers(tsi_test_fixture *fixture) {
- GPR_ASSERT(fixture != NULL);
- GPR_ASSERT(fixture->vtable != NULL);
- GPR_ASSERT(fixture->vtable->setup_handshakers != NULL);
+static void setup_handshakers(tsi_test_fixture* fixture) {
+ GPR_ASSERT(fixture != nullptr);
+ GPR_ASSERT(fixture->vtable != nullptr);
+ GPR_ASSERT(fixture->vtable->setup_handshakers != nullptr);
fixture->vtable->setup_handshakers(fixture);
}
-static void check_unused_bytes(tsi_test_fixture *fixture) {
- tsi_handshaker_result *result_with_unused_bytes =
+static void check_unused_bytes(tsi_test_fixture* fixture) {
+ tsi_handshaker_result* result_with_unused_bytes =
fixture->has_client_finished_first ? fixture->server_result
: fixture->client_result;
- tsi_handshaker_result *result_without_unused_bytes =
+ tsi_handshaker_result* result_without_unused_bytes =
fixture->has_client_finished_first ? fixture->client_result
: fixture->server_result;
- const unsigned char *bytes = NULL;
+ const unsigned char* bytes = nullptr;
size_t bytes_size = 0;
GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(
result_with_unused_bytes, &bytes, &bytes_size) == TSI_OK);
@@ -97,18 +99,19 @@ static void check_unused_bytes(tsi_test_fixture *fixture) {
GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(
result_without_unused_bytes, &bytes, &bytes_size) == TSI_OK);
GPR_ASSERT(bytes_size == 0);
- GPR_ASSERT(bytes == NULL);
+ GPR_ASSERT(bytes == nullptr);
}
-static void check_handshake_results(tsi_test_fixture *fixture) {
- GPR_ASSERT(fixture != NULL);
- GPR_ASSERT(fixture->vtable != NULL);
- GPR_ASSERT(fixture->vtable->check_handshaker_peers != NULL);
+static void check_handshake_results(tsi_test_fixture* fixture) {
+ GPR_ASSERT(fixture != nullptr);
+ GPR_ASSERT(fixture->vtable != nullptr);
+ GPR_ASSERT(fixture->vtable->check_handshaker_peers != nullptr);
/* Check handshaker peers. */
fixture->vtable->check_handshaker_peers(fixture);
/* Check unused bytes. */
if (fixture->test_unused_bytes) {
- if (fixture->server_result != NULL && fixture->client_result != NULL) {
+ if (fixture->server_result != nullptr &&
+ fixture->client_result != nullptr) {
check_unused_bytes(fixture);
}
fixture->bytes_written_to_server_channel = 0;
@@ -118,52 +121,53 @@ static void check_handshake_results(tsi_test_fixture *fixture) {
}
}
-static void send_bytes_to_peer(tsi_test_fixture *fixture,
- const unsigned char *buf, size_t buf_size,
+static void send_bytes_to_peer(tsi_test_fixture* fixture,
+ const unsigned char* buf, size_t buf_size,
bool is_client) {
- GPR_ASSERT(fixture != NULL);
- GPR_ASSERT(buf != NULL);
- uint8_t *channel =
+ GPR_ASSERT(fixture != nullptr);
+ GPR_ASSERT(buf != nullptr);
+ uint8_t* channel =
is_client ? fixture->server_channel : fixture->client_channel;
- GPR_ASSERT(channel != NULL);
- size_t *bytes_written = is_client ? &fixture->bytes_written_to_server_channel
+ GPR_ASSERT(channel != nullptr);
+ size_t* bytes_written = is_client ? &fixture->bytes_written_to_server_channel
: &fixture->bytes_written_to_client_channel;
- GPR_ASSERT(bytes_written != NULL);
+ GPR_ASSERT(bytes_written != nullptr);
GPR_ASSERT(*bytes_written + buf_size <= TSI_TEST_DEFAULT_CHANNEL_SIZE);
/* Write data to channel. */
memcpy(channel + *bytes_written, buf, buf_size);
*bytes_written += buf_size;
}
-static void maybe_append_unused_bytes(handshaker_args *args) {
- GPR_ASSERT(args != NULL);
- GPR_ASSERT(args->fixture != NULL);
- tsi_test_fixture *fixture = args->fixture;
+static void maybe_append_unused_bytes(handshaker_args* args) {
+ GPR_ASSERT(args != nullptr);
+ GPR_ASSERT(args->fixture != nullptr);
+ tsi_test_fixture* fixture = args->fixture;
if (fixture->test_unused_bytes && !args->appended_unused_bytes) {
args->appended_unused_bytes = true;
- send_bytes_to_peer(fixture, (const unsigned char *)TSI_TEST_UNUSED_BYTES,
+ send_bytes_to_peer(fixture, (const unsigned char*)TSI_TEST_UNUSED_BYTES,
strlen(TSI_TEST_UNUSED_BYTES), args->is_client);
- if (fixture->client_result != NULL && fixture->server_result == NULL) {
+ if (fixture->client_result != nullptr &&
+ fixture->server_result == nullptr) {
fixture->has_client_finished_first = true;
}
}
}
-static void receive_bytes_from_peer(tsi_test_fixture *fixture,
- unsigned char **buf, size_t *buf_size,
+static void receive_bytes_from_peer(tsi_test_fixture* fixture,
+ unsigned char** buf, size_t* buf_size,
bool is_client) {
- GPR_ASSERT(fixture != NULL);
- GPR_ASSERT(*buf != NULL);
- GPR_ASSERT(buf_size != NULL);
- uint8_t *channel =
+ GPR_ASSERT(fixture != nullptr);
+ GPR_ASSERT(*buf != nullptr);
+ GPR_ASSERT(buf_size != nullptr);
+ uint8_t* channel =
is_client ? fixture->client_channel : fixture->server_channel;
- GPR_ASSERT(channel != NULL);
- size_t *bytes_read = is_client ? &fixture->bytes_read_from_client_channel
+ GPR_ASSERT(channel != nullptr);
+ size_t* bytes_read = is_client ? &fixture->bytes_read_from_client_channel
: &fixture->bytes_read_from_server_channel;
- size_t *bytes_written = is_client ? &fixture->bytes_written_to_client_channel
+ size_t* bytes_written = is_client ? &fixture->bytes_written_to_client_channel
: &fixture->bytes_written_to_server_channel;
- GPR_ASSERT(bytes_read != NULL);
- GPR_ASSERT(bytes_written != NULL);
+ GPR_ASSERT(bytes_read != nullptr);
+ GPR_ASSERT(bytes_written != nullptr);
size_t to_read = *buf_size < *bytes_written - *bytes_read
? *buf_size
: *bytes_written - *bytes_read;
@@ -173,21 +177,22 @@ static void receive_bytes_from_peer(tsi_test_fixture *fixture,
*bytes_read += to_read;
}
-static void send_message_to_peer(tsi_test_fixture *fixture,
- tsi_frame_protector *protector,
+static void send_message_to_peer(tsi_test_fixture* fixture,
+ tsi_frame_protector* protector,
bool is_client) {
/* Initialization. */
- GPR_ASSERT(fixture != NULL);
- GPR_ASSERT(fixture->config != NULL);
- GPR_ASSERT(protector != NULL);
- tsi_test_frame_protector_config *config = fixture->config;
- unsigned char *protected_buffer = gpr_zalloc(config->protected_buffer_size);
+ GPR_ASSERT(fixture != nullptr);
+ GPR_ASSERT(fixture->config != nullptr);
+ GPR_ASSERT(protector != nullptr);
+ tsi_test_frame_protector_config* config = fixture->config;
+ unsigned char* protected_buffer =
+ static_cast<unsigned char*>(gpr_zalloc(config->protected_buffer_size));
size_t message_size =
is_client ? config->client_message_size : config->server_message_size;
- uint8_t *message =
+ uint8_t* message =
is_client ? config->client_message : config->server_message;
- GPR_ASSERT(message != NULL);
- const unsigned char *message_bytes = (const unsigned char *)message;
+ GPR_ASSERT(message != nullptr);
+ const unsigned char* message_bytes = (const unsigned char*)message;
tsi_result result = TSI_OK;
/* Do protect and send protected data to peer. */
while (message_size > 0 && result == TSI_OK) {
@@ -222,25 +227,26 @@ static void send_message_to_peer(tsi_test_fixture *fixture,
gpr_free(protected_buffer);
}
-static void receive_message_from_peer(tsi_test_fixture *fixture,
- tsi_frame_protector *protector,
- unsigned char *message,
- size_t *bytes_received, bool is_client) {
+static void receive_message_from_peer(tsi_test_fixture* fixture,
+ tsi_frame_protector* protector,
+ unsigned char* message,
+ size_t* bytes_received, bool is_client) {
/* Initialization. */
- GPR_ASSERT(fixture != NULL);
- GPR_ASSERT(protector != NULL);
- GPR_ASSERT(message != NULL);
- GPR_ASSERT(bytes_received != NULL);
- GPR_ASSERT(fixture->config != NULL);
- tsi_test_frame_protector_config *config = fixture->config;
+ GPR_ASSERT(fixture != nullptr);
+ GPR_ASSERT(protector != nullptr);
+ GPR_ASSERT(message != nullptr);
+ GPR_ASSERT(bytes_received != nullptr);
+ GPR_ASSERT(fixture->config != nullptr);
+ tsi_test_frame_protector_config* config = fixture->config;
size_t read_offset = 0;
size_t message_offset = 0;
size_t read_from_peer_size = 0;
tsi_result result = TSI_OK;
bool done = false;
- unsigned char *read_buffer = gpr_zalloc(config->read_buffer_allocated_size);
- unsigned char *message_buffer =
- gpr_zalloc(config->message_buffer_allocated_size);
+ unsigned char* read_buffer = static_cast<unsigned char*>(
+ gpr_zalloc(config->read_buffer_allocated_size));
+ unsigned char* message_buffer = static_cast<unsigned char*>(
+ gpr_zalloc(config->message_buffer_allocated_size));
/* Do unprotect on data received from peer. */
while (!done && result == TSI_OK) {
/* Receive data from peer. */
@@ -278,15 +284,15 @@ static void receive_message_from_peer(tsi_test_fixture *fixture,
gpr_free(message_buffer);
}
-grpc_error *on_handshake_next_done(tsi_result result, void *user_data,
- const unsigned char *bytes_to_send,
+grpc_error* on_handshake_next_done(tsi_result result, void* user_data,
+ const unsigned char* bytes_to_send,
size_t bytes_to_send_size,
- tsi_handshaker_result *handshaker_result) {
- handshaker_args *args = (handshaker_args *)user_data;
- GPR_ASSERT(args != NULL);
- GPR_ASSERT(args->fixture != NULL);
- tsi_test_fixture *fixture = args->fixture;
- grpc_error *error = GRPC_ERROR_NONE;
+ tsi_handshaker_result* handshaker_result) {
+ handshaker_args* args = (handshaker_args*)user_data;
+ GPR_ASSERT(args != nullptr);
+ GPR_ASSERT(args->fixture != nullptr);
+ tsi_test_fixture* fixture = args->fixture;
+ grpc_error* error = GRPC_ERROR_NONE;
/* Read more data if we need to. */
if (result == TSI_INCOMPLETE_DATA) {
GPR_ASSERT(bytes_to_send_size == 0);
@@ -299,10 +305,10 @@ grpc_error *on_handshake_next_done(tsi_result result, void *user_data,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake failed"), result);
}
/* Update handshaker result. */
- if (handshaker_result != NULL) {
- tsi_handshaker_result **result_to_write =
+ if (handshaker_result != nullptr) {
+ tsi_handshaker_result** result_to_write =
args->is_client ? &fixture->client_result : &fixture->server_result;
- GPR_ASSERT(*result_to_write == NULL);
+ GPR_ASSERT(*result_to_write == nullptr);
*result_to_write = handshaker_result;
}
/* Send data to peer, if needed. */
@@ -311,7 +317,7 @@ grpc_error *on_handshake_next_done(tsi_result result, void *user_data,
args->is_client);
args->transferred_data = true;
}
- if (handshaker_result != NULL) {
+ if (handshaker_result != nullptr) {
maybe_append_unused_bytes(args);
}
notification_signal(fixture);
@@ -319,65 +325,68 @@ grpc_error *on_handshake_next_done(tsi_result result, void *user_data,
}
static void on_handshake_next_done_wrapper(
- tsi_result result, void *user_data, const unsigned char *bytes_to_send,
- size_t bytes_to_send_size, tsi_handshaker_result *handshaker_result) {
- handshaker_args *args = (handshaker_args *)user_data;
+ tsi_result result, void* user_data, const unsigned char* bytes_to_send,
+ size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result) {
+ handshaker_args* args = (handshaker_args*)user_data;
args->error = on_handshake_next_done(result, user_data, bytes_to_send,
bytes_to_send_size, handshaker_result);
}
-static bool is_handshake_finished_properly(handshaker_args *args) {
- GPR_ASSERT(args != NULL);
- GPR_ASSERT(args->fixture != NULL);
- tsi_test_fixture *fixture = args->fixture;
- if ((args->is_client && fixture->client_result != NULL) ||
- (!args->is_client && fixture->server_result != NULL)) {
+static bool is_handshake_finished_properly(handshaker_args* args) {
+ GPR_ASSERT(args != nullptr);
+ GPR_ASSERT(args->fixture != nullptr);
+ tsi_test_fixture* fixture = args->fixture;
+ if ((args->is_client && fixture->client_result != nullptr) ||
+ (!args->is_client && fixture->server_result != nullptr)) {
return true;
}
return false;
}
-static void do_handshaker_next(handshaker_args *args) {
+static void do_handshaker_next(handshaker_args* args) {
/* Initialization. */
- GPR_ASSERT(args != NULL);
- GPR_ASSERT(args->fixture != NULL);
- tsi_test_fixture *fixture = args->fixture;
- tsi_handshaker *handshaker =
+ GPR_ASSERT(args != nullptr);
+ GPR_ASSERT(args->fixture != nullptr);
+ tsi_test_fixture* fixture = args->fixture;
+ tsi_handshaker* handshaker =
args->is_client ? fixture->client_handshaker : fixture->server_handshaker;
if (is_handshake_finished_properly(args)) {
return;
}
- tsi_handshaker_result *handshaker_result = NULL;
- unsigned char *bytes_to_send = NULL;
+ tsi_handshaker_result* handshaker_result = nullptr;
+ unsigned char* bytes_to_send = nullptr;
size_t bytes_to_send_size = 0;
+ tsi_result result = TSI_OK;
/* Receive data from peer, if available. */
- size_t buf_size = args->handshake_buffer_size;
- receive_bytes_from_peer(args->fixture, &args->handshake_buffer, &buf_size,
- args->is_client);
- if (buf_size > 0) {
- args->transferred_data = true;
- }
- /* Peform handshaker next. */
- tsi_result result = tsi_handshaker_next(
- handshaker, args->handshake_buffer, buf_size,
- (const unsigned char **)&bytes_to_send, &bytes_to_send_size,
- &handshaker_result, &on_handshake_next_done_wrapper, args);
- if (result != TSI_ASYNC) {
- args->error = on_handshake_next_done(result, args, bytes_to_send,
- bytes_to_send_size, handshaker_result);
- if (args->error != GRPC_ERROR_NONE) {
- return;
+ do {
+ size_t buf_size = args->handshake_buffer_size;
+ receive_bytes_from_peer(args->fixture, &args->handshake_buffer, &buf_size,
+ args->is_client);
+ if (buf_size > 0) {
+ args->transferred_data = true;
}
- }
+ /* Peform handshaker next. */
+ result = tsi_handshaker_next(handshaker, args->handshake_buffer, buf_size,
+ (const unsigned char**)&bytes_to_send,
+ &bytes_to_send_size, &handshaker_result,
+ &on_handshake_next_done_wrapper, args);
+ if (result != TSI_ASYNC) {
+ args->error = on_handshake_next_done(
+ result, args, bytes_to_send, bytes_to_send_size, handshaker_result);
+ if (args->error != GRPC_ERROR_NONE) {
+ return;
+ }
+ }
+ } while (result == TSI_INCOMPLETE_DATA);
notification_wait(fixture);
}
-void tsi_test_do_handshake(tsi_test_fixture *fixture) {
+void tsi_test_do_handshake(tsi_test_fixture* fixture) {
/* Initializaiton. */
setup_handshakers(fixture);
- handshaker_args *client_args =
+ handshaker_args* client_args =
handshaker_args_create(fixture, true /* is_client */);
- handshaker_args *server_args =
+ handshaker_args* server_args =
handshaker_args_create(fixture, false /* is_client */);
/* Do handshake. */
do {
@@ -392,7 +401,8 @@ void tsi_test_do_handshake(tsi_test_fixture *fixture) {
break;
}
GPR_ASSERT(client_args->transferred_data || server_args->transferred_data);
- } while (fixture->client_result == NULL || fixture->server_result == NULL);
+ } while (fixture->client_result == nullptr ||
+ fixture->server_result == nullptr);
/* Verify handshake results. */
check_handshake_results(fixture);
/* Cleanup. */
@@ -400,13 +410,13 @@ void tsi_test_do_handshake(tsi_test_fixture *fixture) {
handshaker_args_destroy(server_args);
}
-void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
+void tsi_test_do_round_trip(tsi_test_fixture* fixture) {
/* Initialization. */
- GPR_ASSERT(fixture != NULL);
- GPR_ASSERT(fixture->config != NULL);
- tsi_test_frame_protector_config *config = fixture->config;
- tsi_frame_protector *client_frame_protector = NULL;
- tsi_frame_protector *server_frame_protector = NULL;
+ GPR_ASSERT(fixture != nullptr);
+ GPR_ASSERT(fixture->config != nullptr);
+ tsi_test_frame_protector_config* config = fixture->config;
+ tsi_frame_protector* client_frame_protector = nullptr;
+ tsi_frame_protector* server_frame_protector = nullptr;
/* Perform handshake. */
tsi_test_do_handshake(fixture);
/* Create frame protectors.*/
@@ -415,7 +425,7 @@ void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
GPR_ASSERT(tsi_handshaker_result_create_frame_protector(
fixture->client_result,
client_max_output_protected_frame_size == 0
- ? NULL
+ ? nullptr
: &client_max_output_protected_frame_size,
&client_frame_protector) == TSI_OK);
size_t server_max_output_protected_frame_size =
@@ -423,13 +433,13 @@ void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
GPR_ASSERT(tsi_handshaker_result_create_frame_protector(
fixture->server_result,
server_max_output_protected_frame_size == 0
- ? NULL
+ ? nullptr
: &server_max_output_protected_frame_size,
&server_frame_protector) == TSI_OK);
/* Client sends a message to server. */
send_message_to_peer(fixture, client_frame_protector, true /* is_client */);
- unsigned char *server_received_message =
- gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE);
+ unsigned char* server_received_message =
+ static_cast<unsigned char*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
size_t server_received_message_size = 0;
receive_message_from_peer(
fixture, server_frame_protector, server_received_message,
@@ -439,8 +449,8 @@ void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
server_received_message_size) == 0);
/* Server sends a message to client. */
send_message_to_peer(fixture, server_frame_protector, false /* is_client */);
- unsigned char *client_received_message =
- gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE);
+ unsigned char* client_received_message =
+ static_cast<unsigned char*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
size_t client_received_message_size = 0;
receive_message_from_peer(
fixture, client_frame_protector, client_received_message,
@@ -455,17 +465,18 @@ void tsi_test_do_round_trip(tsi_test_fixture *fixture) {
gpr_free(client_received_message);
}
-static unsigned char *generate_random_message(size_t size) {
+static unsigned char* generate_random_message(size_t size) {
size_t i;
unsigned char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890";
- unsigned char *output = gpr_zalloc(sizeof(unsigned char) * size);
+ unsigned char* output =
+ static_cast<unsigned char*>(gpr_zalloc(sizeof(unsigned char) * size));
for (i = 0; i < size - 1; ++i) {
output[i] = chars[rand() % (int)(sizeof(chars) - 1)];
}
return output;
}
-tsi_test_frame_protector_config *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,
@@ -473,7 +484,9 @@ tsi_test_frame_protector_config *tsi_test_frame_protector_config_create(
bool use_default_client_max_output_protected_frame_size,
bool use_default_server_max_output_protected_frame_size,
bool use_default_handshake_buffer_size) {
- tsi_test_frame_protector_config *config = gpr_zalloc(sizeof(*config));
+ tsi_test_frame_protector_config* config =
+ static_cast<tsi_test_frame_protector_config*>(
+ gpr_zalloc(sizeof(*config)));
/* Set the value for read_buffer_allocated_size. */
config->read_buffer_allocated_size =
use_default_read_buffer_allocated_size
@@ -522,11 +535,11 @@ tsi_test_frame_protector_config *tsi_test_frame_protector_config_create(
}
void tsi_test_frame_protector_config_set_buffer_size(
- tsi_test_frame_protector_config *config, size_t read_buffer_allocated_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) {
- GPR_ASSERT(config != NULL);
+ GPR_ASSERT(config != nullptr);
config->read_buffer_allocated_size = read_buffer_allocated_size;
config->message_buffer_allocated_size = message_buffer_allocated_size;
config->protected_buffer_size = protected_buffer_size;
@@ -537,19 +550,21 @@ void tsi_test_frame_protector_config_set_buffer_size(
}
void tsi_test_frame_protector_config_destroy(
- tsi_test_frame_protector_config *config) {
- GPR_ASSERT(config != NULL);
+ tsi_test_frame_protector_config* config) {
+ GPR_ASSERT(config != nullptr);
gpr_free(config->client_message);
gpr_free(config->server_message);
gpr_free(config);
}
-void tsi_test_fixture_init(tsi_test_fixture *fixture) {
+void tsi_test_fixture_init(tsi_test_fixture* fixture) {
fixture->config = tsi_test_frame_protector_config_create(
true, true, true, true, true, true, true, true);
fixture->handshake_buffer_size = TSI_TEST_DEFAULT_BUFFER_SIZE;
- fixture->client_channel = gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE);
- fixture->server_channel = gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE);
+ fixture->client_channel =
+ static_cast<uint8_t*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
+ fixture->server_channel =
+ static_cast<uint8_t*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
fixture->bytes_written_to_client_channel = 0;
fixture->bytes_written_to_server_channel = 0;
fixture->bytes_read_from_client_channel = 0;
@@ -561,8 +576,8 @@ void tsi_test_fixture_init(tsi_test_fixture *fixture) {
fixture->notified = false;
}
-void tsi_test_fixture_destroy(tsi_test_fixture *fixture) {
- GPR_ASSERT(fixture != NULL);
+void tsi_test_fixture_destroy(tsi_test_fixture* fixture) {
+ GPR_ASSERT(fixture != nullptr);
tsi_test_frame_protector_config_destroy(fixture->config);
tsi_handshaker_destroy(fixture->client_handshaker);
tsi_handshaker_destroy(fixture->server_handshaker);
@@ -570,8 +585,8 @@ void tsi_test_fixture_destroy(tsi_test_fixture *fixture) {
tsi_handshaker_result_destroy(fixture->server_result);
gpr_free(fixture->client_channel);
gpr_free(fixture->server_channel);
- GPR_ASSERT(fixture->vtable != NULL);
- GPR_ASSERT(fixture->vtable->destruct != NULL);
+ GPR_ASSERT(fixture->vtable != nullptr);
+ GPR_ASSERT(fixture->vtable->destruct != nullptr);
fixture->vtable->destruct(fixture);
gpr_mu_destroy(&fixture->mu);
gpr_cv_destroy(&fixture->cv);
diff --git a/test/core/tsi/transport_security_test_lib.h b/test/core/tsi/transport_security_test_lib.h
index ed8ff856df..9b07448cc5 100644
--- a/test/core/tsi/transport_security_test_lib.h
+++ b/test/core/tsi/transport_security_test_lib.h
@@ -21,9 +21,7 @@
#include "src/core/tsi/transport_security_interface.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <grpc/support/sync.h>
#define TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE 32
#define TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE 128
@@ -57,29 +55,29 @@ typedef struct tsi_test_frame_protector_config tsi_test_frame_protector_config;
/* V-table for tsi_test_fixture operations that are implemented differently in
different TSI implementations. */
typedef struct tsi_test_fixture_vtable {
- void (*setup_handshakers)(tsi_test_fixture *fixture);
- void (*check_handshaker_peers)(tsi_test_fixture *fixture);
- void (*destruct)(tsi_test_fixture *fixture);
+ void (*setup_handshakers)(tsi_test_fixture* fixture);
+ void (*check_handshaker_peers)(tsi_test_fixture* fixture);
+ void (*destruct)(tsi_test_fixture* fixture);
} tsi_test_fixture_vtable;
struct tsi_test_fixture {
- const tsi_test_fixture_vtable *vtable;
+ const tsi_test_fixture_vtable* vtable;
/* client/server TSI handshaker used to perform TSI handshakes, and will get
instantiated during the call to setup_handshakers. */
- tsi_handshaker *client_handshaker;
- tsi_handshaker *server_handshaker;
+ tsi_handshaker* client_handshaker;
+ tsi_handshaker* server_handshaker;
/* client/server TSI handshaker results used to store the result of TSI
handshake. If the handshake fails, the result will store NULL upon
finishing the handshake. */
- tsi_handshaker_result *client_result;
- tsi_handshaker_result *server_result;
+ tsi_handshaker_result* client_result;
+ tsi_handshaker_result* server_result;
/* size of buffer used to store data received from the peer. */
size_t handshake_buffer_size;
/* simulated channels between client and server. If the server (client)
wants to send data to the client (server), he will write data to
client_channel (server_channel), which will be read by client (server). */
- uint8_t *client_channel;
- uint8_t *server_channel;
+ uint8_t* client_channel;
+ uint8_t* server_channel;
/* size of data written to the client/server channel. */
size_t bytes_written_to_client_channel;
size_t bytes_written_to_server_channel;
@@ -87,7 +85,7 @@ struct tsi_test_fixture {
size_t bytes_read_from_client_channel;
size_t bytes_read_from_server_channel;
/* tsi_test_frame_protector_config instance */
- tsi_test_frame_protector_config *config;
+ tsi_test_frame_protector_config* config;
/* a flag indicating if client has finished TSI handshake first (i.e., before
server).
The flag should be referred if and only if TSI handshake finishes
@@ -119,8 +117,8 @@ struct tsi_test_frame_protector_config {
size_t client_max_output_protected_frame_size;
size_t server_max_output_protected_frame_size;
/* pointer that points to client/server message to be protected. */
- uint8_t *client_message;
- uint8_t *server_message;
+ uint8_t* client_message;
+ uint8_t* server_message;
/* size of client/server message. */
size_t client_message_size;
size_t server_message_size;
@@ -131,7 +129,7 @@ struct tsi_test_frame_protector_config {
corresponding parameter with a default value or not. If it's false, it will
be set with a specific value which is usually much smaller than the default.
Both values are defined with #define directive. */
-tsi_test_frame_protector_config *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,
@@ -143,38 +141,34 @@ tsi_test_frame_protector_config *tsi_test_frame_protector_config_create(
/* This method sets different buffer and frame sizes of a
tsi_test_frame_protector_config instance with user provided values. */
void tsi_test_frame_protector_config_set_buffer_size(
- tsi_test_frame_protector_config *config, size_t read_buffer_allocated_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);
/* This method destroys a tsi_test_frame_protector_config instance. */
void tsi_test_frame_protector_config_destroy(
- tsi_test_frame_protector_config *config);
+ tsi_test_frame_protector_config* config);
/* This method initializes members of tsi_test_fixture instance.
Note that the struct instance should be allocated before making
this call. */
-void tsi_test_fixture_init(tsi_test_fixture *fixture);
+void tsi_test_fixture_init(tsi_test_fixture* fixture);
/* This method destroys a tsi_test_fixture instance. Note that the
fixture intance must be dynamically allocated and will be freed by
this function. */
-void tsi_test_fixture_destroy(tsi_test_fixture *fixture);
+void tsi_test_fixture_destroy(tsi_test_fixture* fixture);
/* This method performs a full TSI handshake between a client and a server.
Note that the test library will implement the new TSI handshaker API to
perform handshakes. */
-void tsi_test_do_handshake(tsi_test_fixture *fixture);
+void tsi_test_do_handshake(tsi_test_fixture* fixture);
/* This method performs a round trip test between the client and the server.
That is, the client sends a protected message to a server who receives the
message, and unprotects it. The same operation is triggered again with
the client and server switching its role. */
-void tsi_test_do_round_trip(tsi_test_fixture *fixture);
-
-#ifdef __cplusplus
-}
-#endif
+void tsi_test_do_round_trip(tsi_test_fixture* fixture);
#endif // GRPC_TEST_CORE_TSI_TRANSPORT_SECURITY_TEST_LIB_H_