Go to the documentation of this file.
32 #include <arpa/inet.h>
33 #include <sys/socket.h>
47 #include "absl/strings/match.h"
48 #include "absl/strings/string_view.h"
65 #define TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND 16384
66 #define TSI_SSL_MAX_PROTECTED_FRAME_SIZE_LOWER_BOUND 1024
67 #define TSI_SSL_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE 1024
72 #ifndef TSI_OPENSSL_ALPN_SUPPORT
73 #define TSI_OPENSSL_ALPN_SUPPORT 1
78 #define TSI_SSL_MAX_PROTECTION_OVERHEAD 100
144 #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
148 #if OPENSSL_VERSION_NUMBER < 0x10100000
168 #if OPENSSL_VERSION_NUMBER >= 0x10100000
175 #if OPENSSL_VERSION_NUMBER < 0x10100000
181 for (
int i = 0;
i < num_locks;
i++) {
200 return "SSL_ERROR_NONE";
202 return "SSL_ERROR_ZERO_RETURN";
204 return "SSL_ERROR_WANT_READ";
206 return "SSL_ERROR_WANT_WRITE";
208 return "SSL_ERROR_WANT_CONNECT";
210 return "SSL_ERROR_WANT_ACCEPT";
212 return "SSL_ERROR_WANT_X509_LOOKUP";
214 return "SSL_ERROR_SYSCALL";
216 return "SSL_ERROR_SSL";
218 return "Unknown error";
246 size_t dot_count = 0;
248 for (
size_t i = 0;
i <
name.size(); ++
i) {
249 if (
name[
i] ==
':') {
254 if (num_size > 3)
return 0;
256 }
else if (
name[
i] ==
'.') {
257 if (dot_count > 3 || num_size == 0)
return 0;
264 if (dot_count < 3 || num_size == 0)
return 0;
271 int common_name_index = -1;
275 int utf8_returned_size = 0;
276 if (subject_name ==
nullptr) {
282 if (common_name_index == -1) {
283 gpr_log(
GPR_INFO,
"Could not get common name of subject from certificate.");
287 if (common_name_entry ==
nullptr) {
292 if (common_name_asn1 ==
nullptr) {
294 "Could not get common name entry asn1 from certificate.");
298 if (utf8_returned_size < 0) {
302 *utf8_size =
static_cast<size_t>(utf8_returned_size);
309 unsigned char* common_name;
310 size_t common_name_size;
315 common_name =
nullptr;
316 common_name_size = 0;
323 common_name ==
nullptr ?
"" :
reinterpret_cast<const char*
>(common_name),
324 common_name_size, property);
333 if (subject_name ==
nullptr) {
374 tsi_peer* peer, GENERAL_NAMES* subject_alt_names,
375 size_t subject_alt_name_count,
int* current_insert_index) {
379 for (
i = 0;
i < subject_alt_name_count;
i++) {
385 unsigned char*
name =
nullptr;
406 reinterpret_cast<const char*
>(
name),
static_cast<size_t>(name_size),
407 &peer->
properties[(*current_insert_index)++]);
413 property_name.c_str(),
reinterpret_cast<const char*
>(
name),
414 static_cast<size_t>(name_size),
415 &peer->
properties[(*current_insert_index)++]);
418 char ntop_buf[INET6_ADDRSTRLEN];
431 ntop_buf, INET6_ADDRSTRLEN);
432 if (
name ==
nullptr) {
440 &peer->
properties[(*current_insert_index)++]);
444 &peer->
properties[(*current_insert_index)++]);
448 &peer->
properties[(*current_insert_index)++]);
459 GENERAL_NAMES* subject_alt_names =
static_cast<GENERAL_NAMES*
>(
461 int subject_alt_name_count =
462 (subject_alt_names !=
nullptr)
463 ?
static_cast<int>(sk_GENERAL_NAME_num(subject_alt_names))
465 size_t property_count;
468 property_count = (include_certificate_type ?
static_cast<size_t>(1) : 0) +
470 static_cast<size_t>(subject_alt_name_count);
471 for (
int i = 0;
i < subject_alt_name_count;
i++) {
487 int current_insert_index = 0;
489 if (include_certificate_type) {
497 cert, &peer->
properties[current_insert_index++]);
501 cert, &peer->
properties[current_insert_index++]);
508 if (subject_alt_name_count != 0) {
510 peer, subject_alt_names,
static_cast<size_t>(subject_alt_name_count),
511 ¤t_insert_index);
516 if (subject_alt_names !=
nullptr) {
537 size_t* unprotected_bytes_size) {
538 GPR_ASSERT(*unprotected_bytes_size <= INT_MAX);
540 int read_from_ssl =
SSL_read(ssl, unprotected_bytes,
541 static_cast<int>(*unprotected_bytes_size));
542 if (read_from_ssl <= 0) {
544 switch (read_from_ssl) {
547 *unprotected_bytes_size = 0;
552 "Peer tried to renegotiate SSL connection. This is unsupported.");
564 *unprotected_bytes_size =
static_cast<size_t>(read_from_ssl);
570 size_t unprotected_bytes_size) {
571 GPR_ASSERT(unprotected_bytes_size <= INT_MAX);
573 int ssl_write_result =
SSL_write(ssl, unprotected_bytes,
574 static_cast<int>(unprotected_bytes_size));
575 if (ssl_write_result < 0) {
579 "Peer tried to renegotiate SSL connection. This is unsupported.");
592 const char* pem_cert_chain,
593 size_t pem_cert_chain_size) {
595 X509* certificate =
nullptr;
598 pem =
BIO_new_mem_buf(pem_cert_chain,
static_cast<int>(pem_cert_chain_size));
604 if (certificate ==
nullptr) {
613 X509* certificate_authority =
615 if (certificate_authority ==
nullptr) {
631 if (certificate !=
nullptr)
X509_free(certificate);
636 #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
639 size_t pem_key_size) {
647 char* engine_end = (
char*)strchr(engine_start,
':');
648 if (engine_end ==
nullptr) {
652 char*
key_id = engine_end + 1;
653 int engine_name_length = engine_end - engine_start;
654 if (engine_name_length == 0) {
661 ENGINE_load_dynamic();
663 if (engine ==
nullptr) {
666 engine = ENGINE_by_id(
"dynamic");
667 if (engine ==
nullptr) {
672 if (!ENGINE_ctrl_cmd_string(engine,
"ID",
engine_name, 0) ||
673 !ENGINE_ctrl_cmd_string(engine,
"DIR_LOAD",
"2", 0) ||
674 !ENGINE_ctrl_cmd_string(engine,
"DIR_ADD",
".", 0) ||
675 !ENGINE_ctrl_cmd_string(engine,
"LIST_ADD",
"1", 0) ||
676 !ENGINE_ctrl_cmd_string(engine,
"LOAD", NULL, 0)) {
682 if (!ENGINE_set_default(engine, ENGINE_METHOD_ALL)) {
687 if (!ENGINE_init(engine)) {
713 size_t pem_key_size) {
739 size_t pem_key_size) {
741 #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
754 const char* pem_roots,
755 size_t pem_roots_size,
758 size_t num_roots = 0;
766 if (root_names !=
nullptr) {
773 if (
root ==
nullptr) {
777 if (root_names !=
nullptr) {
779 if (root_name ==
nullptr) {
785 if (root_name ==
nullptr) {
805 if (num_roots == 0) {
812 if (root_names !=
nullptr) {
814 *root_names =
nullptr;
823 const char* pem_roots,
824 size_t pem_roots_size,
838 const char* cipher_list) {
840 if (key_cert_pair !=
nullptr) {
858 if ((cipher_list !=
nullptr) &&
878 const char* pem_cert,
tsi_peer* peer) {
880 X509* cert =
nullptr;
886 if (cert ==
nullptr) {
899 const char** alpn_protocols,
uint16_t num_alpn_protocols,
900 unsigned char** protocol_name_list,
size_t* protocol_name_list_length) {
902 unsigned char* current;
903 *protocol_name_list =
nullptr;
904 *protocol_name_list_length = 0;
906 for (
i = 0;
i < num_alpn_protocols;
i++) {
908 alpn_protocols[
i] ==
nullptr ? 0 : strlen(alpn_protocols[
i]);
911 static_cast<int>(
length));
914 *protocol_name_list_length +=
length + 1;
916 *protocol_name_list =
917 static_cast<unsigned char*
>(
gpr_malloc(*protocol_name_list_length));
919 current = *protocol_name_list;
920 for (
i = 0;
i < num_alpn_protocols;
i++) {
921 size_t length = strlen(alpn_protocols[
i]);
927 if ((current < *protocol_name_list) ||
928 (
static_cast<uintptr_t>(current - *protocol_name_list) !=
929 *protocol_name_list_length)) {
949 if (ssl_context ==
nullptr) {
951 "Invalid nullptr argument to |tsi_set_min_and_max_tls_versions|.");
954 #if OPENSSL_VERSION_NUMBER >= 0x10100000
959 switch (min_tls_version) {
963 #if defined(TLS1_3_VERSION)
977 switch (max_tls_version) {
982 #if defined(TLS1_3_VERSION)
1001 const char* pem_roots) {
1002 if (pem_roots ==
nullptr) {
1008 if (root_store ==
nullptr) {
1013 if (root_store->
store ==
nullptr) {
1019 strlen(pem_roots),
nullptr);
1030 if (
self ==
nullptr)
return;
1055 const unsigned char* unprotected_bytes,
1056 size_t* unprotected_bytes_size,
1057 unsigned char* protected_output_frames,
1058 size_t* protected_output_frames_size) {
1067 if (pending_in_ssl > 0) {
1068 *unprotected_bytes_size = 0;
1069 GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
1071 static_cast<int>(*protected_output_frames_size));
1072 if (read_from_ssl < 0) {
1074 "Could not read from BIO even though some data is pending");
1077 *protected_output_frames_size =
static_cast<size_t>(read_from_ssl);
1083 if (available > *unprotected_bytes_size) {
1086 *unprotected_bytes_size);
1088 *protected_output_frames_size = 0;
1097 GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
1099 static_cast<int>(*protected_output_frames_size));
1100 if (read_from_ssl < 0) {
1104 *protected_output_frames_size =
static_cast<size_t>(read_from_ssl);
1105 *unprotected_bytes_size = available;
1112 size_t* protected_output_frames_size,
size_t* still_pending_size) {
1116 int read_from_ssl = 0;
1127 *still_pending_size =
static_cast<size_t>(
pending);
1128 if (*still_pending_size == 0)
return TSI_OK;
1130 GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
1132 static_cast<int>(*protected_output_frames_size));
1133 if (read_from_ssl <= 0) {
1137 *protected_output_frames_size =
static_cast<size_t>(read_from_ssl);
1140 *still_pending_size =
static_cast<size_t>(
pending);
1146 size_t* protected_frames_bytes_size,
unsigned char* unprotected_bytes,
1147 size_t* unprotected_bytes_size) {
1149 int written_into_ssl = 0;
1150 size_t output_bytes_size = *unprotected_bytes_size;
1151 size_t output_bytes_offset = 0;
1158 if (*unprotected_bytes_size == output_bytes_size) {
1160 *protected_frames_bytes_size = 0;
1163 output_bytes_offset = *unprotected_bytes_size;
1164 unprotected_bytes += output_bytes_offset;
1165 *unprotected_bytes_size = output_bytes_size - output_bytes_offset;
1168 GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX);
1170 static_cast<int>(*protected_frames_bytes_size));
1171 if (written_into_ssl < 0) {
1176 *protected_frames_bytes_size =
static_cast<size_t>(written_into_ssl);
1182 *unprotected_bytes_size += output_bytes_offset;
1207 if (factory ==
nullptr)
return;
1219 if (factory ==
nullptr)
return nullptr;
1226 if (factory ==
nullptr)
return;
1249 const auto peer_chain_len =
sk_X509_num(peer_chain);
1250 for (
auto i = decltype(peer_chain_len){0};
i < peer_chain_len;
i++) {
1273 const unsigned char* alpn_selected =
nullptr;
1274 unsigned int alpn_selected_len;
1278 if (peer_cert !=
nullptr) {
1283 #if TSI_OPENSSL_ALPN_SUPPORT
1286 if (alpn_selected ==
nullptr) {
1289 &alpn_selected_len);
1297 if (alpn_selected !=
nullptr) new_property_count++;
1298 if (peer_chain !=
nullptr) new_property_count++;
1300 gpr_zalloc(
sizeof(*new_properties) * new_property_count));
1307 if (peer_chain !=
nullptr) {
1312 if (alpn_selected !=
nullptr) {
1315 reinterpret_cast<const char*
>(alpn_selected), alpn_selected_len,
1347 size_t actual_max_output_protected_frame_size =
1356 if (max_output_protected_frame_size !=
nullptr) {
1357 if (*max_output_protected_frame_size >
1359 *max_output_protected_frame_size =
1361 }
else if (*max_output_protected_frame_size <
1363 *max_output_protected_frame_size =
1366 actual_max_output_protected_frame_size = *max_output_protected_frame_size;
1372 if (protector_impl->
buffer ==
nullptr) {
1374 "Could not allocated buffer for tsi_ssl_frame_protector.");
1380 protector_impl->
ssl = impl->
ssl;
1381 impl->
ssl =
nullptr;
1385 *protector = &protector_impl->
base;
1391 size_t* bytes_size) {
1420 if (handshaker ==
nullptr || handshaker_result ==
nullptr ||
1421 (unused_bytes_size > 0 && unused_bytes ==
nullptr)) {
1425 grpc_core::Zalloc<tsi_ssl_handshaker_result>();
1429 handshaker->
ssl =
nullptr;
1433 result->unused_bytes = unused_bytes;
1434 result->unused_bytes_size = unused_bytes_size;
1435 *handshaker_result = &
result->base;
1443 int bytes_read_from_ssl = 0;
1444 if (
bytes ==
nullptr || bytes_size ==
nullptr || *bytes_size > INT_MAX) {
1448 bytes_read_from_ssl =
1450 if (bytes_read_from_ssl < 0) {
1459 *bytes_size =
static_cast<size_t>(bytes_read_from_ssl);
1480 switch (ssl_result) {
1506 int bytes_written_into_ssl_size = 0;
1507 if (
bytes ==
nullptr || bytes_size ==
nullptr || *bytes_size > INT_MAX) {
1511 bytes_written_into_ssl_size =
1513 if (bytes_written_into_ssl_size < 0) {
1518 *bytes_size =
static_cast<size_t>(bytes_written_into_ssl_size);
1534 unsigned char** bytes_remaining,
1535 size_t* bytes_remaining_size) {
1536 if (impl ==
nullptr || bytes_remaining ==
nullptr ||
1537 bytes_remaining_size ==
nullptr) {
1544 if (bytes_in_ssl == 0)
return TSI_OK;
1547 static_cast<int>(bytes_in_ssl));
1552 "Failed to read the expected number of bytes from SSL object.");
1554 *bytes_remaining =
nullptr;
1557 *bytes_remaining_size =
static_cast<size_t>(
bytes_read);
1587 size_t received_bytes_size,
const unsigned char** bytes_to_send,
1591 if ((received_bytes_size > 0 && received_bytes ==
nullptr) ||
1592 bytes_to_send ==
nullptr || bytes_to_send_size ==
nullptr ||
1593 handshaker_result ==
nullptr) {
1599 size_t bytes_consumed = received_bytes_size;
1601 if (received_bytes_size > 0) {
1618 *handshaker_result =
nullptr;
1624 unsigned char* unused_bytes =
nullptr;
1625 size_t unused_bytes_size = 0;
1628 if (unused_bytes_size > received_bytes_size) {
1638 self->handshaker_result_created =
true;
1664 if (session !=
nullptr) {
1671 const char* server_name_indication,
1672 size_t network_bio_buf_size,
1673 size_t ssl_bio_buf_size,
1677 BIO* network_io =
nullptr;
1678 BIO* ssl_io =
nullptr;
1680 *handshaker =
nullptr;
1681 if (
ctx ==
nullptr) {
1685 if (ssl ==
nullptr) {
1691 ssl_bio_buf_size)) {
1700 if (server_name_indication !=
nullptr) {
1703 server_name_indication);
1720 "Unexpected error received from first SSL_do_handshake call: %s",
1730 impl = grpc_core::Zalloc<tsi_ssl_handshaker>();
1740 *handshaker = &impl->
base;
1745 unsigned char* outlen,
1746 const unsigned char* client_list,
1747 size_t client_list_len,
1748 const unsigned char* server_list,
1749 size_t server_list_len) {
1750 const unsigned char* client_current = client_list;
1751 while (
static_cast<unsigned int>(client_current - client_list) <
1753 unsigned char client_current_len = *(client_current++);
1754 const unsigned char* server_current = server_list;
1755 while ((server_current >= server_list) &&
1756 static_cast<uintptr_t>(server_current - server_list) <
1758 unsigned char server_current_len = *(server_current++);
1759 if ((client_current_len == server_current_len) &&
1760 !memcmp(client_current, server_current, server_current_len)) {
1761 *
out = server_current;
1762 *outlen = server_current_len;
1765 server_current += server_current_len;
1767 client_current += client_current_len;
1776 const char* server_name_indication,
size_t network_bio_buf_size,
1779 factory->
ssl_context, 1, server_name_indication, network_bio_buf_size,
1780 ssl_bio_buf_size, &factory->
base, handshaker);
1785 if (factory ==
nullptr)
return;
1791 if (factory ==
nullptr)
return;
1795 if (
self->alpn_protocol_list !=
nullptr)
gpr_free(
self->alpn_protocol_list);
1796 self->session_cache.reset();
1797 self->key_logger.reset();
1802 SSL* ,
unsigned char**
out,
unsigned char* outlen,
1803 const unsigned char*
in,
unsigned int inlen,
void*
arg) {
1820 network_bio_buf_size, ssl_bio_buf_size,
1821 &factory->
base, handshaker);
1826 if (factory ==
nullptr)
return;
1832 if (factory ==
nullptr)
return;
1836 for (
i = 0;
i <
self->ssl_context_count;
i++) {
1837 if (
self->ssl_contexts[
i] !=
nullptr) {
1843 if (
self->ssl_context_x509_subject_names !=
nullptr) {
1846 if (
self->alpn_protocol_list !=
nullptr)
gpr_free(
self->alpn_protocol_list);
1847 self->key_logger.reset();
1853 if (entry.
empty())
return 0;
1856 if (
name.back() ==
'.') {
1857 name.remove_suffix(1);
1859 if (entry.
back() ==
'.') {
1861 if (entry.
empty())
return 0;
1867 if (entry.
front() !=
'*')
return 0;
1870 if (entry.
size() < 3 || entry[1] !=
'.') {
1874 size_t name_subdomain_pos =
name.find(
'.');
1876 if (name_subdomain_pos >=
name.size() - 2)
return 0;
1878 name.substr(name_subdomain_pos + 1);
1880 size_t dot = name_subdomain.
find(
'.');
1886 if (name_subdomain.
back() ==
'.') {
1899 if (servername ==
nullptr || strlen(servername) == 0) {
1914 #if TSI_OPENSSL_ALPN_SUPPORT
1916 SSL* ,
const unsigned char**
out,
unsigned char* outlen,
1917 const unsigned char*
in,
unsigned int inlen,
void*
arg) {
1927 SSL* ,
const unsigned char**
out,
unsigned int* outlen,
void*
arg) {
1945 if (ssl_context ==
nullptr) {
1962 template <
typename T>
1967 T* factory =
static_cast<T*
>(
arg);
1968 factory->key_logger->LogSessionKeys(ssl_context, info);
1978 "Certificate verification failed to get CRL files. Ignoring error.");
1981 if (cert_error != 0) {
1995 const char** alpn_protocols,
uint16_t num_alpn_protocols,
1998 options.pem_key_cert_pair = pem_key_cert_pair;
2001 options.alpn_protocols = alpn_protocols;
2002 options.num_alpn_protocols = num_alpn_protocols;
2010 SSL_CTX* ssl_context =
nullptr;
2018 if (
options->pem_root_certs ==
nullptr &&
options->root_store ==
nullptr) {
2022 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2027 if (ssl_context ==
nullptr) {
2034 ssl_context,
options->min_tls_version,
options->max_tls_version);
2042 if (
options->session_cache !=
nullptr) {
2052 #if OPENSSL_VERSION_NUMBER >= 0x10101000 && !defined(LIBRESSL_VERSION_NUMBER)
2053 if (
options->key_logger !=
nullptr) {
2059 ssl_keylogging_callback<tsi_ssl_client_handshaker_factory>);
2063 if (
options->session_cache !=
nullptr ||
options->key_logger !=
nullptr) {
2073 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2075 if (
options->root_store !=
nullptr) {
2080 if (OPENSSL_VERSION_NUMBER < 0x10100000 || options->root_store ==
nullptr) {
2082 ssl_context,
options->pem_root_certs, strlen(
options->pem_root_certs),
2090 if (
options->num_alpn_protocols != 0) {
2099 #if TSI_OPENSSL_ALPN_SUPPORT
2117 if (
options->skip_server_certificate_verification) {
2123 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2124 if (
options->crl_directory !=
nullptr &&
2125 strcmp(
options->crl_directory,
"") != 0) {
2150 size_t num_key_cert_pairs,
const char* pem_client_root_certs,
2152 const char** alpn_protocols,
uint16_t num_alpn_protocols,
2155 pem_key_cert_pairs, num_key_cert_pairs, pem_client_root_certs,
2158 cipher_suites, alpn_protocols, num_alpn_protocols, factory);
2163 size_t num_key_cert_pairs,
const char* pem_client_root_certs,
2168 options.pem_key_cert_pairs = pem_key_cert_pairs;
2169 options.num_key_cert_pairs = num_key_cert_pairs;
2170 options.pem_client_root_certs = pem_client_root_certs;
2171 options.client_certificate_request = client_certificate_request;
2173 options.alpn_protocols = alpn_protocols;
2174 options.num_alpn_protocols = num_alpn_protocols;
2190 if (
options->num_key_cert_pairs == 0 ||
2191 options->pem_key_cert_pairs ==
nullptr) {
2211 if (
options->num_alpn_protocols > 0) {
2221 if (
options->key_logger !=
nullptr) {
2225 for (
i = 0;
i <
options->num_key_cert_pairs;
i++) {
2227 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2255 if (set_sid_ctx_result == 0) {
2261 if (
options->session_ticket_key !=
nullptr) {
2264 const_cast<char*
>(
options->session_ticket_key),
2265 options->session_ticket_key_size) == 0) {
2272 if (
options->pem_client_root_certs !=
nullptr) {
2276 strlen(
options->pem_client_root_certs), &root_names);
2283 switch (
options->client_certificate_request) {
2306 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2307 if (
options->crl_directory !=
nullptr &&
2308 strcmp(
options->crl_directory,
"") != 0) {
2325 options->pem_key_cert_pairs[
i].cert_chain,
2333 #if TSI_OPENSSL_ALPN_SUPPORT
2341 #if OPENSSL_VERSION_NUMBER >= 0x10101000 && !defined(LIBRESSL_VERSION_NUMBER)
2343 if (
options->key_logger !=
nullptr) {
2351 ssl_keylogging_callback<tsi_ssl_server_handshaker_factory>);
2370 size_t san_count = 0;
2377 if (property->name ==
nullptr)
continue;
2378 if (strcmp(property->name,
2385 }
else if (like_ip &&
name == entry) {
2389 }
else if (strcmp(property->name,
2391 cn_property = property;
2396 if (san_count == 0 && cn_property !=
nullptr && !like_ip) {
2415 factory->
vtable = new_vtable;
#define SSL_CB_HANDSHAKE_START
const char * tsi_security_level_to_string(tsi_security_level security_level)
#define X509_NAME_print_ex
static tsi_result ssl_handshaker_process_bytes_from_peer(tsi_ssl_handshaker *impl, const unsigned char *bytes, size_t *bytes_size)
grpc_core::RefCountedPtr< TlsSessionKeyLogger > key_logger
static tsi_result build_alpn_protocol_name_list(const char **alpn_protocols, uint16_t num_alpn_protocols, unsigned char **protocol_name_list, size_t *protocol_name_list_length)
@ TSI_DONT_REQUEST_CLIENT_CERTIFICATE
#define TSI_X509_CERTIFICATE_TYPE
tsi_ssl_handshaker_factory base
static void openssl_locking_cb(int mode, int type, const char *file, int line) GRPC_UNUSED
static void ssl_handshaker_destroy(tsi_handshaker *self)
const tsi_handshaker_vtable * vtable
#define SSL_CTX_set_tlsext_servername_callback
#define SSL_CTX_set_verify
#define EC_KEY_new_by_curve_name
GPRAPI void gpr_mu_unlock(gpr_mu *mu)
tsi_result tsi_create_ssl_server_handshaker_factory_with_options(const tsi_ssl_server_handshaker_options *options, tsi_ssl_server_handshaker_factory **factory)
#define X509_get_subject_name
tsi_ssl_handshaker_factory_destructor destroy
#define SSL_is_init_finished
#define SSL_CTX_set_ex_data
tsi_peer_property * properties
tsi_result tsi_create_ssl_client_handshaker_factory(const tsi_ssl_pem_key_cert_pair *pem_key_cert_pair, const char *pem_root_certs, const char *cipher_suites, const char **alpn_protocols, uint16_t num_alpn_protocols, tsi_ssl_client_handshaker_factory **factory)
#define PEM_read_bio_X509_AUX
GPRAPI void gpr_refn(gpr_refcount *r, int n)
static tsi_result peer_property_from_x509_subject(X509 *cert, tsi_peer_property *property)
struct tsi_peer_property::@48 value
SslSessionPtr Get(const char *key)
#define NID_X9_62_prime256v1
#define X509_STORE_up_ref
ABSL_INTERNAL_STRING_VIEW_CXX14_CONSTEXPR void remove_suffix(size_type n)
#define SSL_CTX_set_options
tsi_result tsi_create_ssl_client_handshaker_factory_with_options(const tsi_ssl_client_handshaker_options *options, tsi_ssl_client_handshaker_factory **factory)
grpc_core::TraceFlag tsi_tracing_enabled(false, "tsi")
#define TSI_SSL_ALPN_SELECTED_PROTOCOL
#define SSL_CB_HANDSHAKE_DONE
static char * pem_root_certs
#define TSI_X509_SUBJECT_PEER_PROPERTY
#define SSL_get0_alpn_selected
#define X509_V_FLAG_CRL_CHECK
#define SSL_set_accept_state
#define X509_STORE_set_verify_cb
#define TSI_X509_IP_PEER_PROPERTY
#define X509_V_FLAG_PARTIAL_CHAIN
#define SSL_CTX_get_ex_data
static int verify_cb(int ok, X509_STORE_CTX *ctx)
size_type find(string_view s, size_type pos=0) const noexcept
#define X509_R_CERT_ALREADY_IN_HASH_TABLE
ASN1_IA5STRING * uniformResourceIdentifier
#define TSI_SECURITY_LEVEL_PEER_PROPERTY
tsi_result tsi_create_ssl_server_handshaker_factory(const tsi_ssl_pem_key_cert_pair *pem_key_cert_pairs, size_t num_key_cert_pairs, const char *pem_client_root_certs, int force_client_auth, const char *cipher_suites, const char **alpn_protocols, uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory **factory)
static tsi_result ssl_handshaker_result_extract_peer(const tsi_handshaker_result *self, tsi_peer *peer)
#define TSI_SIZE_AS_SIZE(x)
#define SSL_ERROR_WANT_READ
static tsi_result ssl_handshaker_result_get_unused_bytes(const tsi_handshaker_result *self, const unsigned char **bytes, size_t *bytes_size)
void tsi_ssl_client_handshaker_factory_unref(tsi_ssl_client_handshaker_factory *factory)
#define SSL_CTX_set_client_CA_list
static int ssl_server_handshaker_factory_servername_callback(SSL *ssl, int *, void *arg)
static tsi_ssl_handshaker_factory * tsi_ssl_handshaker_factory_ref(tsi_ssl_handshaker_factory *factory)
GPRAPI void gpr_free(void *ptr)
void tsi_ssl_session_cache_unref(tsi_ssl_session_cache *cache)
size_t alpn_protocol_list_length
#define SSL_TLSEXT_ERR_OK
#define SSL_CTX_sess_set_new_cb
static tsi_result ssl_ctx_use_private_key(SSL_CTX *context, const char *pem_key, size_t pem_key_size)
#define CRYPTO_get_locking_callback
#define SSL_CTX_set_session_cache_mode
GPRAPI void * gpr_malloc(size_t size)
@ TSI_FRAME_PROTECTOR_NORMAL
@ TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
static void tsi_ssl_handshaker_factory_unref(tsi_ssl_handshaker_factory *factory)
constexpr const_reference back() const
#define SSL_CTX_add_extra_chain_cert
static int g_ssl_ctx_ex_factory_index
static const char * cipher_suites
@ TSI_FAILED_PRECONDITION
tsi_result tsi_ssl_get_cert_chain_contents(STACK_OF(X509) *peer_chain, tsi_peer_property *property)
#define SSL_load_error_strings
unsigned char * outgoing_bytes_buffer
static void ssl_info_callback(const SSL *ssl, int where, int ret)
#define X509_NAME_get_index_by_NID
#define GRPC_TRACE_FLAG_ENABLED(f)
#define T(upbtypeconst, upbtype, ctype, default_value)
static tsi_result ssl_handshaker_next(tsi_handshaker *self, const unsigned char *received_bytes, size_t received_bytes_size, const unsigned char **bytes_to_send, size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result, tsi_handshaker_on_next_done_cb, void *)
EVP_PKEY * PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
#define SSL_ERROR_WANT_ACCEPT
@ TSI_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY
static tsi_result peer_property_from_x509_common_name(X509 *cert, tsi_peer_property *property)
#define SSL_CTX_set_max_proto_version
static const char * ssl_error_string(int error)
static tsi_result ssl_handshaker_result_create_frame_protector(const tsi_handshaker_result *self, size_t *max_output_protected_frame_size, tsi_frame_protector **protector)
static void tsi_ssl_handshaker_factory_destroy(tsi_ssl_handshaker_factory *factory)
GPRAPI void gpr_once_init(gpr_once *once, void(*init_function)(void))
#define TSI_X509_URI_PEER_PROPERTY
GPRAPI void * gpr_zalloc(size_t size)
#define OpenSSL_add_all_algorithms
ASN1_OCTET_STRING * iPAddress
#define TSI_X509_DNS_PEER_PROPERTY
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger TlsSessionKeyLogger
static void tsi_ssl_server_handshaker_factory_destroy(tsi_ssl_handshaker_factory *factory)
const tsi_ssl_handshaker_factory_vtable * tsi_ssl_handshaker_factory_swap_vtable(tsi_ssl_handshaker_factory *factory, tsi_ssl_handshaker_factory_vtable *new_vtable)
#define X509_VERIFY_PARAM_set_flags
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static const char engine_name[]
#define sk_X509_NAME_pop_free
constexpr const_reference front() const
#define PEM_read_bio_X509
#define SSL_OP_SINGLE_ECDH_USE
GPRAPI gpr_thd_id gpr_thd_currentid(void)
#define X509_STORE_load_locations
#define ERR_GET_REASON(packed_error)
void tsi_ssl_session_cache_ref(tsi_ssl_session_cache *cache)
tsi_client_certificate_request_type
const tsi_ssl_handshaker_factory_vtable * vtable
GPRAPI void * gpr_realloc(void *p, size_t size)
static tsi_result ssl_protector_unprotect(tsi_frame_protector *self, const unsigned char *protected_frames_bytes, size_t *protected_frames_bytes_size, unsigned char *unprotected_bytes, size_t *unprotected_bytes_size)
std::unique_ptr< SSL_SESSION, SslSessionDeleter > SslSessionPtr
constexpr size_type size() const noexcept
static tsi_result do_ssl_write(SSL *ssl, unsigned char *unprotected_bytes, size_t unprotected_bytes_size)
static void tsi_ssl_client_handshaker_factory_destroy(tsi_ssl_handshaker_factory *factory)
int tsi_ssl_peer_matches_name(const tsi_peer *peer, absl::string_view name)
def c_str(s, encoding='ascii')
#define SSL_get_peer_cert_chain
RefCountedPtr< grpc_tls_certificate_provider > root
#define X509_NAME_get_entry
size_t alpn_protocol_list_length
#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
GPRAPI void gpr_mu_init(gpr_mu *mu)
static tsi_result add_pem_certificate(X509 *cert, tsi_peer_property *property)
#define SSL_CTX_set_next_protos_advertised_cb
tsi_ssl_handshaker_factory * factory_ref
static unsigned long openssl_thread_id_cb(void) GRPC_UNUSED
const CBS size_t uint32_t key_id
#define SSL_session_reused
#define X509_STORE_add_cert
void(* tsi_handshaker_on_next_done_cb)(tsi_result status, void *user_data, const unsigned char *bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result *handshaker_result)
static void log_ssl_error_stack(void)
static const char kSslEnginePrefix[]
#define ERR_GET_LIB(packed_error)
#define CRYPTO_set_id_callback
ASN1_IA5STRING * rfc822Name
ABSL_NAMESPACE_BEGIN bool EqualsIgnoreCase(absl::string_view piece1, absl::string_view piece2) noexcept
#define X509_NAME_ENTRY_get_data
#define SSL_TLSEXT_ERR_NOACK
static const tsi_handshaker_result_vtable handshaker_result_vtable
static const unsigned char kSslSessionIdContext[]
#define PEM_write_bio_X509
static void tsi_ssl_handshaker_factory_init(tsi_ssl_handshaker_factory *factory)
#define X509_V_FLAG_TRUSTED_FIRST
#define SSL_CTX_set_keylog_callback
static tsi_ssl_handshaker_factory_vtable client_handshaker_factory_vtable
GPRAPI void gpr_mu_lock(gpr_mu *mu)
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)
#define SSL_set_tlsext_host_name
#define SSL_get0_next_proto_negotiated
static int NullVerifyCallback(int, X509_STORE_CTX *)
static tsi_result populate_ssl_context(SSL_CTX *context, const tsi_ssl_pem_key_cert_pair *key_cert_pair, const char *cipher_list)
_W64 unsigned int uintptr_t
static int select_protocol_list(const unsigned char **out, unsigned char *outlen, const unsigned char *client_list, size_t client_list_len, const unsigned char *server_list, size_t server_list_len)
static tsi_result add_subject_alt_names_properties_to_peer(tsi_peer *peer, GENERAL_NAMES *subject_alt_names, size_t subject_alt_name_count, int *current_insert_index)
static tsi_result do_ssl_read(SSL *ssl, unsigned char *unprotected_bytes, size_t *unprotected_bytes_size)
#define ERR_error_string_n
#define SSL_SESS_CACHE_CLIENT
tsi_peer * ssl_context_x509_subject_names
#define TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND
#define SSL_CTX_get_ex_new_index
tsi_handshaker_result base
#define SSL_CTX_set_tlsext_servername_arg
unsigned char * alpn_protocol_list
static tsi_result create_tsi_ssl_handshaker(SSL_CTX *ctx, int is_client, const char *server_name_indication, size_t network_bio_buf_size, size_t ssl_bio_buf_size, tsi_ssl_handshaker_factory *factory, tsi_handshaker **handshaker)
static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_ssl_handshaker *impl, unsigned char *bytes, size_t *bytes_size)
tsi_ssl_handshaker_factory base
static int looks_like_ip_address(absl::string_view name)
size_t outgoing_bytes_buffer_size
#define SSL_set_info_callback
@ TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY
#define SSL_ERROR_WANT_WRITE
static grpc_slice details
static gpr_once g_init_openssl_once
static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX *context, const char *pem_cert_chain, size_t pem_cert_chain_size)
#define GENERAL_NAME_free
#define SSL_CTX_set_cipher_list
static const tsi_handshaker_vtable handshaker_vtable
#define ASN1_STRING_to_UTF8
#define TSI_SSL_SESSION_REUSED_PEER_PROPERTY
#define GPR_ARRAY_SIZE(array)
void Put(const char *key, SslSessionPtr session)
@ TSI_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY
void tsi_ssl_server_handshaker_factory_unref(tsi_ssl_server_handshaker_factory *factory)
static int server_handshaker_factory_npn_advertised_callback(SSL *, const unsigned char **out, unsigned int *outlen, void *arg)
union GENERAL_NAME_st::@370 d
#define SSL_CTX_set_tmp_ecdh
static int server_handshaker_factory_new_session_callback(SSL *ssl, SSL_SESSION *session)
struct tsi_ssl_session_cache tsi_ssl_session_cache
ABSL_INTERNAL_STRING_VIEW_CXX14_CONSTEXPR void remove_prefix(size_type n)
#define SSL_CTX_set_cert_store
static tsi_result ssl_handshaker_get_result(tsi_ssl_handshaker *impl)
const char * tsi_result_to_string(tsi_result result)
#define SSL_ERROR_ZERO_RETURN
#define X509_STORE_get0_param
#define TSI_SSL_MAX_PROTECTION_OVERHEAD
static void init_openssl(void)
UniquePtr< SSL_SESSION > ret
static tsi_result ssl_get_x509_common_name(X509 *cert, unsigned char **utf8, size_t *utf8_size)
static tsi_result ssl_protector_protect_flush(tsi_frame_protector *self, unsigned char *protected_output_frames, size_t *protected_output_frames_size, size_t *still_pending_size)
#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT
tsi_result tsi_ssl_extract_x509_subject_names_from_pem_cert(const char *pem_cert, tsi_peer *peer)
static int does_entry_match_name(absl::string_view entry, absl::string_view name)
unsigned char * unused_bytes
#define X509_STORE_set_flags
#define SSL_ERROR_WANT_CONNECT
static tsi_result ssl_protector_protect(tsi_frame_protector *self, const unsigned char *unprotected_bytes, size_t *unprotected_bytes_size, unsigned char *protected_output_frames, size_t *protected_output_frames_size)
#define TSI_SSL_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE
const tsi_frame_protector_vtable * vtable
#define TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY
#define sk_X509_NAME_push
#define TSI_SSL_MAX_PROTECTED_FRAME_SIZE_LOWER_BOUND
static const tsi_frame_protector_vtable frame_protector_vtable
static void ssl_protector_destroy(tsi_frame_protector *self)
#define NID_subject_alt_name
static tsi_result ssl_ctx_use_engine_private_key(SSL_CTX *context, const char *pem_key, size_t pem_key_size)
#define SSL_CTX_use_certificate
#define sk_X509_NAME_new_null
tsi_result tsi_create_ssl_server_handshaker_factory_ex(const tsi_ssl_pem_key_cert_pair *pem_key_cert_pairs, size_t num_key_cert_pairs, const char *pem_client_root_certs, tsi_client_certificate_request_type client_certificate_request, const char *cipher_suites, const char **alpn_protocols, uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory **factory)
static tsi_result ssl_ctx_load_verification_certs(SSL_CTX *context, const char *pem_roots, size_t pem_roots_size, STACK_OF(X509_NAME) **root_name)
static tsi_result x509_store_load_certs(X509_STORE *cert_store, const char *pem_roots, size_t pem_roots_size, STACK_OF(X509_NAME) **root_names)
#define SSL_CTX_set_session_id_context
OPENSSL_EXPORT X509_NAME * X509_NAME_dup(X509_NAME *xn)
static tsi_result ssl_handshaker_write_output_buffer(tsi_handshaker *self, size_t *bytes_written)
#define SSL_CTX_set_alpn_protos
static int server_handshaker_factory_alpn_callback(SSL *, const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
static tsi_result peer_from_x509(X509 *cert, int include_certificate_type, tsi_peer *peer)
static tsi_result ssl_bytes_remaining(tsi_ssl_handshaker *impl, unsigned char **bytes_remaining, size_t *bytes_remaining_size)
#define SSL_CTX_use_PrivateKey
grpc_core::RefCountedPtr< TlsSessionKeyLogger > key_logger
static size_t bytes_written
static tsi_ssl_handshaker_factory_vtable handshaker_factory_vtable
constexpr bool empty() const noexcept
#define X509_STORE_CTX_get_error
@ TSI_PRIVACY_AND_INTEGRITY
#define SSL_CTX_check_private_key
grpc::ClientContext context
static tsi_result tsi_set_min_and_max_tls_versions(SSL_CTX *ssl_context, tsi_tls_version min_tls_version, tsi_tls_version max_tls_version)
static tsi_result ssl_ctx_use_pem_private_key(SSL_CTX *context, const char *pem_key, size_t pem_key_size)
#define SSL_ERROR_WANT_X509_LOOKUP
#define CRYPTO_set_locking_callback
#define SSL_CTX_set_next_proto_select_cb
#define SSL_set_connect_state
static gpr_mu * g_openssl_mutexes
GPRAPI void gpr_ref_init(gpr_refcount *r, int n)
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)
#define TSI_CERTIFICATE_TYPE_PEER_PROPERTY
GPRAPI int gpr_unref(gpr_refcount *r)
static constexpr size_type npos
#define SSL_CTX_set_min_proto_version
static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker *impl)
#define SSL_get_servername
static void ssl_log_where_info(const SSL *ssl, int where, int flag, const char *msg)
#define SSL_get_peer_certificate
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
internal::RefMatcher< T & > Ref(T &x)
static tsi_result ssl_handshaker_result_get_frame_protector_type(const tsi_handshaker_result *, tsi_frame_protector_type *frame_protector_type)
#define TSI_X509_PEM_CERT_CHAIN_PROPERTY
#define SSL_state_string_long
static int client_handshaker_factory_npn_callback(SSL *, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
static grpc_core::RefCountedPtr< SslSessionLRUCache > Create(size_t capacity)
Create new LRU cache with the given capacity.
static void ssl_keylogging_callback(const SSL *ssl, const char *info)
#define TSI_X509_EMAIL_PEER_PROPERTY
#define SSL_CTX_set_alpn_select_cb
#define TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY
void tsi_peer_destruct(tsi_peer *self)
#define TLSEXT_NAMETYPE_host_name
static tsi_result ssl_handshaker_result_create(tsi_ssl_handshaker *handshaker, unsigned char *unused_bytes, size_t unused_bytes_size, tsi_handshaker_result **handshaker_result)
unsigned char * alpn_protocol_list
#define X509_V_ERR_UNABLE_TO_GET_CRL
tsi_result tsi_construct_string_peer_property(const char *name, const char *value, size_t value_length, tsi_peer_property *property)
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)
#define SSL_CTX_get_cert_store
static void tsi_ssl_handshaker_resume_session(SSL *ssl, tsi::SslSessionLRUCache *session_cache)
#define SSL_CTX_set_tlsext_ticket_keys
static tsi_ssl_handshaker_factory_vtable server_handshaker_factory_vtable
tsi_result tsi_construct_string_peer_property_from_cstring(const char *name, const char *value, tsi_peer_property *property)
grpc_core::RefCountedPtr< tsi::SslSessionLRUCache > session_cache
tsi_result tsi_construct_peer(size_t property_count, tsi_peer *peer)
static void ssl_handshaker_result_destroy(tsi_handshaker_result *self)
@ TSI_HANDSHAKE_IN_PROGRESS
tsi_ssl_session_cache * tsi_ssl_session_cache_create_lru(size_t capacity)
#define SSL_ERROR_SYSCALL
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:16