Go to the documentation of this file.
42 #define SSL_TSI_TEST_ALPN1 "foo"
43 #define SSL_TSI_TEST_ALPN2 "toto"
44 #define SSL_TSI_TEST_ALPN3 "baz"
45 #define SSL_TSI_TEST_ALPN_NUM 2
46 #define SSL_TSI_TEST_SERVER_KEY_CERT_PAIRS_NUM 2
47 #define SSL_TSI_TEST_BAD_SERVER_KEY_CERT_PAIRS_NUM 1
48 #define SSL_TSI_TEST_CREDENTIALS_DIR "src/core/tsi/test_creds/"
49 #define SSL_TSI_TEST_WRONG_SNI "test.google.cn"
53 #if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_IS_BORINGSSL)
200 const char* expected_match =
"baz";
210 const char* expected_match =
"TSI_PRIVACY_AND_INTEGRITY";
245 const char* expected_match =
"*.test.google.com.au";
246 GPR_ASSERT(memcmp(property->value.data, expected_match,
247 property->value.length) == 0);
264 const char* property_value) {
267 if (strcmp(prop->
name, property_name) == 0) {
268 if (strlen(property_value) == prop->
value.
length &&
280 const char* expected_match =
"*.test.google.com";
281 GPR_ASSERT(memcmp(property->value.data, expected_match,
282 property->value.length) == 0);
285 "*.test.google.fr") == 1);
288 "waterzooi.test.google.be") == 1);
311 const char* expected_match =
"testclient";
312 GPR_ASSERT(memcmp(property->value.data, expected_match,
313 property->value.length) == 0);
334 bool expect_server_success =
337 #if OPENSSL_VERSION_NUMBER >= 0x10100000
339 ? expect_server_success
342 bool expect_client_success = expect_server_success;
344 if (expect_client_success) {
362 if (expect_server_success) {
382 if (ssl_fixture ==
nullptr) {
429 static char*
load_file(
const char* dir_path,
const char* file_name) {
430 char* file_path =
static_cast<char*
>(
431 gpr_zalloc(
sizeof(
char) * (strlen(dir_path) + strlen(file_name) + 1)));
432 memcpy(file_path, dir_path, strlen(dir_path));
433 memcpy(file_path + strlen(dir_path), file_name, strlen(file_name));
490 ssl_alpn_lib* alpn_lib = grpc_core::Zalloc<ssl_alpn_lib>();
511 return &ssl_fixture->
base;
520 fixture->test_unused_bytes =
false;
551 gpr_log(
GPR_INFO,
"ssl_tsi_test_do_handshake_with_client_authentication");
563 "ssl_tsi_test_do_handshake_with_client_authentication_and_root_store");
575 "ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain");
581 const_cast<char*
>(
"waterzooi.test.google.be");
589 "ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain");
595 const_cast<char*
>(
"juju.test.google.fr");
602 "ssl_tsi_test_do_handshake_with_wrong_server_name_indication");
676 unsigned int* bit_array =
static_cast<unsigned int*
>(
680 unsigned int v = val;
682 bit_array[
ind] = (
v & mask) ? 1 : 0;
690 bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4],
691 bit_array[5], bit_array[6]);
710 #if defined(GPR_ARCH_32) || defined(__APPLE__)
719 const size_t odd_sizes[] = {1025, 2051, 4103, 8207, 16409};
720 size_t size =
sizeof(odd_sizes) /
sizeof(
size_t);
729 for (
size_t ind1 = 0; ind1 <
size; ind1++) {
730 for (
size_t ind2 = 0; ind2 <
size; ind2++) {
731 for (
size_t ind3 = 0; ind3 <
size; ind3++) {
732 for (
size_t ind4 = 0; ind4 <
size; ind4++) {
733 for (
size_t ind5 = 0; ind5 <
size; ind5++) {
738 ssl_fixture->
base.
config, odd_sizes[ind1], odd_sizes[ind2],
739 odd_sizes[ind3], odd_sizes[ind4], odd_sizes[ind5]);
753 auto do_handshake = [&session_ticket_key,
754 &session_cache](
bool session_reused) {
759 const_cast<char*
>(
"waterzooi.test.google.be");
768 memset(session_ticket_key,
'a',
sizeof(session_ticket_key));
773 memset(session_ticket_key,
'b',
sizeof(session_ticket_key));
776 memset(session_ticket_key,
'c',
sizeof(session_ticket_key));
802 options.pem_root_certs = cert_chain;
814 for (
i = 0;
i < 3; ++
i) {
816 client_handshaker_factory,
"google.com", 0, 0,
839 const char* cert_chain =
847 options.pem_key_cert_pairs = &cert_pair;
848 options.num_key_cert_pairs = 1;
849 options.pem_client_root_certs = cert_chain;
859 for (
i = 0;
i < 3; ++
i) {
861 server_handshaker_factory, 0, 0, &handshaker[
i]) ==
TSI_OK);
882 const char* cert_chain =
"This is not a valid PEM file.";
886 options.pem_root_certs = cert_chain;
902 char* dup_root_cert =
static_cast<char*
>(
903 gpr_zalloc(
sizeof(
char) * (strlen(root_cert) * 2 + 1)));
904 memcpy(dup_root_cert, root_cert, strlen(root_cert));
905 memcpy(dup_root_cert + strlen(root_cert), root_cert, strlen(root_cert));
924 size_t expected_property_count = 22;
927 const char* expected_subject =
"CN=xpigors,OU=Google,L=SF,ST=CA,C=US";
931 GPR_ASSERT(memcmp(property->value.data, expected_subject,
932 property->value.length) == 0);
934 const char* expected_cn =
"xpigors";
939 memcmp(property->value.data, expected_cn, property->value.length) == 0);
943 GPR_ASSERT(memcmp(property->value.data, cert, property->value.length) == 0);
947 "foo.test.domain.com") == 1);
950 "bar.test.domain.com") == 1);
952 "foo.test.domain.com") == 1);
954 "bar.test.domain.com") == 1);
959 "spiffe://foo.com/bar/baz") == 1);
962 "https://foo.test.domain.com/test") == 1);
965 "https://bar.test.domain.com/test") == 1);
967 "spiffe://foo.com/bar/baz") == 1);
969 "https://foo.test.domain.com/test") == 1);
971 "https://bar.test.domain.com/test") == 1);
975 "foo@test.domain.com") == 1);
978 "bar@test.domain.com") == 1);
980 "foo@test.domain.com") == 1);
982 "bar@test.domain.com") == 1);
986 "192.168.7.1") == 1);
996 "other types of SAN") == 1);
1006 char* chain =
static_cast<char*
>(
1007 gpr_zalloc(
sizeof(
char) * (strlen(cert) + strlen(ca) + 1)));
1008 memcpy(chain, cert, strlen(cert));
1009 memcpy(chain + strlen(cert), ca, strlen(ca));
1017 for (
size_t i = 0;
i < sk_X509_INFO_num(certInfos);
i++) {
1018 X509_INFO* certInfo = sk_X509_INFO_value(certInfos,
i);
1019 if (certInfo->
x509 !=
nullptr) {
1021 #if OPENSSL_VERSION_NUMBER >= 0x10100000
1047 #if OPENSSL_VERSION_NUMBER >= 0x10100000
1059 const size_t number_tls_versions = 2;
1062 for (
size_t i = 0;
i < number_tls_versions;
i++) {
1077 #ifdef OPENSSL_IS_BORINGSSL
tsi_ssl_pem_key_cert_pair * bad_server_pem_key_cert_pairs
GPRAPI void grpc_slice_unref(grpc_slice s)
@ TSI_DONT_REQUEST_CLIENT_CERTIFICATE
#define TSI_X509_CERTIFICATE_TYPE
tsi_ssl_client_handshaker_factory * client_handshaker_factory
void tsi_peer_property_destruct(tsi_peer_property *property)
uint16_t num_client_alpn_protocols
const char * pem_root_certs
uint16_t bad_server_num_key_cert_pairs
#define EC_KEY_new_by_curve_name
tsi_result tsi_create_ssl_server_handshaker_factory_with_options(const tsi_ssl_server_handshaker_options *options, tsi_ssl_server_handshaker_factory **factory)
tsi_ssl_handshaker_factory_destructor destroy
tsi_handshaker * server_handshaker
void ssl_tsi_test_extract_cert_chain()
tsi_handshaker_result * client_result
tsi_peer_property * properties
#define SSL_TSI_TEST_ALPN3
#define SSL_TSI_TEST_ALPN2
struct tsi_peer_property::@48 value
grpc_error_handle grpc_load_file(const char *filename, int add_null_terminator, grpc_slice *output)
void ssl_tsi_test_do_handshake_with_bad_server_cert()
tsi_result tsi_create_ssl_client_handshaker_factory_with_options(const tsi_ssl_client_handshaker_options *options, tsi_ssl_client_handshaker_factory **factory)
struct ssl_key_cert_lib ssl_key_cert_lib
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)
return memset(p, 0, total)
void test_tsi_ssl_client_handshaker_factory_refcounting()
uint16_t num_server_alpn_protocols
#define TSI_TEST_NUM_OF_ARGUMENTS
void ssl_tsi_test_do_handshake_small_handshake_buffer()
#define TSI_SSL_ALPN_SELECTED_PROTOCOL
#define TSI_X509_SUBJECT_PEER_PROPERTY
#define TSI_X509_IP_PEER_PROPERTY
void tsi_handshaker_destroy(tsi_handshaker *self)
void ssl_tsi_test_handshaker_factory_internals()
#define SSL_TSI_TEST_WRONG_SNI
#define TSI_SECURITY_LEVEL_PEER_PROPERTY
tsi_ssl_session_cache * session_cache
void tsi_ssl_client_handshaker_factory_unref(tsi_ssl_client_handshaker_factory *factory)
void ssl_tsi_test_duplicate_root_certificates()
static const tsi_peer_property * check_basic_authenticated_peer_and_get_common_name(const tsi_peer *peer)
tsi_ssl_server_handshaker_factory * server_handshaker_factory
void ssl_tsi_test_do_round_trip_for_all_configs()
GPRAPI void gpr_free(void *ptr)
void tsi_ssl_session_cache_unref(tsi_ssl_session_cache *cache)
void tsi_test_frame_protector_config_destroy(tsi_test_frame_protector_config *config)
void tsi_test_fixture_init(tsi_test_fixture *fixture)
GPRAPI void * gpr_malloc(size_t size)
void tsi_test_fixture_destroy(tsi_test_fixture *fixture)
@ TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
struct ssl_alpn_lib ssl_alpn_lib
const char ** client_alpn_protocols
void ssl_tsi_test_do_handshake_alpn_client_server_ok()
const tsi_ssl_pem_key_cert_pair * pem_key_cert_pair
tsi_result tsi_ssl_get_cert_chain_contents(STACK_OF(X509) *peer_chain, tsi_peer_property *property)
void test_tsi_ssl_server_handshaker_factory_refcounting()
tsi_ssl_pem_key_cert_pair bad_client_pem_key_cert_pair
void ssl_tsi_test_do_handshake_with_bad_client_cert()
static tsi_test_fixture * ssl_tsi_test_fixture_create()
tsi_tls_version max_tls_version
const char ** alpn_protocols
void test_tsi_ssl_client_handshaker_factory_bad_params()
static void ssl_tsi_test_handshaker_factory_destructor(tsi_ssl_handshaker_factory *factory)
void ssl_tsi_test_do_handshake_with_server_name_indication_wild_star_domain()
#define TSI_X509_URI_PEER_PROPERTY
GPRAPI void * gpr_zalloc(size_t size)
static const struct tsi_test_fixture_vtable vtable
CRYPTO_refcount_t references
const size_t kSessionTicketEncryptionKeySize
@ ALPN_CLIENT_SERVER_MISMATCH
void ssl_tsi_test_do_handshake_alpn_server_no_client()
size_t num_alpn_protocols
#define TSI_X509_DNS_PEER_PROPERTY
const tsi_ssl_handshaker_factory_vtable * tsi_ssl_handshaker_factory_swap_vtable(tsi_ssl_handshaker_factory *factory, tsi_ssl_handshaker_factory_vtable *new_vtable)
int main(int argc, char **argv)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE
static tsi_tls_version test_tls_version
#define SSL_TSI_TEST_SERVER_KEY_CERT_PAIRS_NUM
static char * load_file(const char *dir_path, const char *file_name)
static void ssl_test_pem_key_cert_pair_destroy(tsi_ssl_pem_key_cert_pair kp)
void ssl_tsi_test_do_handshake_with_wrong_server_name_indication()
void tsi_ssl_session_cache_ref(tsi_ssl_session_cache *cache)
#define SSL_TSI_TEST_BAD_SERVER_KEY_CERT_PAIRS_NUM
static const char fixture[]
int tsi_ssl_peer_matches_name(const tsi_peer *peer, absl::string_view name)
static void check_client_peer(ssl_tsi_test_fixture *ssl_fixture, tsi_peer *peer)
ssl_key_cert_lib * key_cert_lib
void tsi_test_do_round_trip(tsi_test_fixture *fixture)
#define TSI_X509_PEM_CERT_PROPERTY
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
void ssl_tsi_test_do_handshake_with_server_name_indication_exact_domain()
tsi_ssl_root_certs_store * root_store
#define PEM_X509_INFO_read_bio
static const tsi_ssl_handshaker_factory_vtable * original_vtable
void check_server1_peer(tsi_peer *peer)
tsi_test_frame_protector_config * config
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)
OPENSSL_EXPORT int X509_up_ref(X509 *x509)
char * server_name_indication
tsi_ssl_pem_key_cert_pair * server_pem_key_cert_pairs
tsi_result tsi_ssl_server_handshaker_factory_create_handshaker(tsi_ssl_server_handshaker_factory *factory, size_t network_bio_buf_size, size_t ssl_bio_buf_size, tsi_handshaker **handshaker)
void ssl_tsi_test_do_handshake_alpn_client_server_mismatch()
const tsi_peer_property * tsi_peer_get_property_by_name(const tsi_peer *peer, const char *name)
void ssl_tsi_test_do_handshake_with_client_authentication_and_root_store()
static void ssl_test_check_handshaker_peers(tsi_test_fixture *fixture)
#define TSI_TEST_DEFAULT_BUFFER_SIZE
tsi_ssl_session_cache * session_cache
const tsi_test_fixture_vtable * vtable
static bool check_property(tsi_peer *peer, const char *property_name, const char *property_value)
void tsi_test_do_handshake(tsi_test_fixture *fixture)
void check_server0_peer(tsi_peer *peer)
#define SSL_TSI_TEST_ALPN1
tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result *self, tsi_peer *peer)
const char * session_ticket_key
#define TSI_TEST_NUM_OF_COMBINATIONS
static void ssl_test_destruct(tsi_test_fixture *fixture)
#define TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE
GPRAPI char * grpc_slice_to_c_string(grpc_slice s)
def server_options(multi_method_implementation=None, request_deserializers=None, response_serializers=None, thread_pool=None, thread_pool_size=None, default_timeout=None, maximum_timeout=None)
static void check_alpn(ssl_tsi_test_fixture *ssl_fixture, const tsi_peer *peer)
static bool is_slow_build()
uint16_t server_num_key_cert_pairs
#define TSI_SSL_SESSION_REUSED_PEER_PROPERTY
void tsi_ssl_server_handshaker_factory_unref(tsi_ssl_server_handshaker_factory *factory)
struct tsi_ssl_session_cache tsi_ssl_session_cache
void ssl_tsi_test_do_round_trip_odd_buffer_size()
tsi_result tsi_ssl_extract_x509_subject_names_from_pem_cert(const char *pem_cert, tsi_peer *peer)
static void ssl_test_setup_handshakers(tsi_test_fixture *fixture)
size_t session_ticket_key_size
void ssl_tsi_test_do_handshake_tiny_handshake_buffer()
static tsi_ssl_handshaker_factory_vtable test_handshaker_factory_vtable
#define TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY
void ssl_tsi_test_do_handshake()
static void check_session_reusage(ssl_tsi_test_fixture *ssl_fixture, tsi_peer *peer)
void ssl_tsi_test_do_handshake_with_root_store()
struct ssl_tsi_test_fixture ssl_tsi_test_fixture
GPRAPI char * gpr_strdup(const char *src)
void ssl_tsi_test_do_handshake_alpn_client_no_server()
tsi_handshaker_result * server_result
tsi_ssl_root_certs_store * tsi_ssl_root_certs_store_create(const char *pem_roots)
void tsi_ssl_root_certs_store_destroy(tsi_ssl_root_certs_store *self)
tsi_handshaker * client_handshaker
#define TSI_CERTIFICATE_TYPE_PEER_PROPERTY
GRPCAPI void grpc_init(void)
void ssl_tsi_test_do_handshake_with_client_authentication()
tsi_tls_version min_tls_version
#define SSL_TSI_TEST_ALPN_NUM
size_t network_bio_buf_size
#define SSL_TSI_TEST_CREDENTIALS_DIR
void ssl_tsi_test_do_handshake_with_custom_bio_pair()
static bool handshaker_factory_destructor_called
#define TSI_X509_EMAIL_PEER_PROPERTY
#define TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY
void tsi_peer_destruct(tsi_peer *self)
GRPCAPI void grpc_shutdown(void)
const char ** server_alpn_protocols
void ssl_tsi_test_do_round_trip_with_error_on_stack()
tsi_result tsi_ssl_client_handshaker_factory_create_handshaker(tsi_ssl_client_handshaker_factory *factory, const char *server_name_indication, size_t network_bio_buf_size, size_t ssl_bio_buf_size, tsi_handshaker **handshaker)
void ssl_tsi_test_do_handshake_session_cache()
static void check_security_level(const tsi_peer *peer)
tsi_ssl_pem_key_cert_pair client_pem_key_cert_pair
tsi_ssl_session_cache * tsi_ssl_session_cache_create_lru(size_t capacity)
void ssl_tsi_test_extract_x509_subject_names()
const tsi_ssl_root_certs_store * root_store
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:16