ssl_transport_security.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
22 
23 #include <limits.h>
24 #include <string.h>
25 
26 /* TODO(jboeuf): refactor inet_ntop into a portability header. */
27 /* Note: for whomever reads this and tries to refactor this, this
28  can't be in grpc, it has to be in gpr. */
29 #ifdef GPR_WINDOWS
30 #include <ws2tcpip.h>
31 #else
32 #include <arpa/inet.h>
33 #include <sys/socket.h>
34 #endif
35 
36 #include <string>
37 
38 #include <openssl/bio.h>
39 #include <openssl/crypto.h> /* For OPENSSL_free */
40 #include <openssl/engine.h>
41 #include <openssl/err.h>
42 #include <openssl/ssl.h>
43 #include <openssl/tls1.h>
44 #include <openssl/x509.h>
45 #include <openssl/x509v3.h>
46 
47 #include "absl/strings/match.h"
48 #include "absl/strings/string_view.h"
49 
50 #include <grpc/grpc_security.h>
51 #include <grpc/support/alloc.h>
52 #include <grpc/support/log.h>
54 #include <grpc/support/sync.h>
55 #include <grpc/support/thd_id.h>
56 
60 #include "src/core/tsi/ssl_types.h"
62 
63 /* --- Constants. ---*/
64 
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
68 
69 /* Putting a macro like this and littering the source file with #if is really
70  bad practice.
71  TODO(jboeuf): refactor all the #if / #endif in a separate module. */
72 #ifndef TSI_OPENSSL_ALPN_SUPPORT
73 #define TSI_OPENSSL_ALPN_SUPPORT 1
74 #endif
75 
76 /* TODO(jboeuf): I have not found a way to get this number dynamically from the
77  SSL structure. This is what we would ultimately want though... */
78 #define TSI_SSL_MAX_PROTECTION_OVERHEAD 100
79 
81 
82 /* --- Structure definitions. ---*/
83 
86 };
87 
91 };
92 
96  unsigned char* alpn_protocol_list;
100 };
101 
103  /* Several contexts to support SNI.
104  The tsi_peer array contains the subject names of the server certificates
105  associated with the contexts at the same index. */
110  unsigned char* alpn_protocol_list;
113 };
114 
120  unsigned char* outgoing_bytes_buffer;
123 };
128  unsigned char* unused_bytes;
130 };
135  unsigned char* buffer;
136  size_t buffer_size;
138 };
139 /* --- Library Initialization. ---*/
140 
143 static const unsigned char kSslSessionIdContext[] = {'g', 'r', 'p', 'c'};
144 #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
145 static const char kSslEnginePrefix[] = "engine:";
146 #endif
147 
148 #if OPENSSL_VERSION_NUMBER < 0x10100000
149 static gpr_mu* g_openssl_mutexes = nullptr;
150 static void openssl_locking_cb(int mode, int type, const char* file,
151  int line) GRPC_UNUSED;
152 static unsigned long openssl_thread_id_cb(void) GRPC_UNUSED;
153 
154 static void openssl_locking_cb(int mode, int type, const char* file, int line) {
155  if (mode & CRYPTO_LOCK) {
157  } else {
159  }
160 }
161 
162 static unsigned long openssl_thread_id_cb(void) {
163  return static_cast<unsigned long>(gpr_thd_currentid());
164 }
165 #endif
166 
167 static void init_openssl(void) {
168 #if OPENSSL_VERSION_NUMBER >= 0x10100000
169  OPENSSL_init_ssl(0, nullptr);
170 #else
174 #endif
175 #if OPENSSL_VERSION_NUMBER < 0x10100000
177  int num_locks = CRYPTO_num_locks();
178  GPR_ASSERT(num_locks > 0);
179  g_openssl_mutexes = static_cast<gpr_mu*>(
180  gpr_malloc(static_cast<size_t>(num_locks) * sizeof(gpr_mu)));
181  for (int i = 0; i < num_locks; i++) {
183  }
186  } else {
187  gpr_log(GPR_INFO, "OpenSSL callback has already been set.");
188  }
189 #endif
191  SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
193 }
194 
195 /* --- Ssl utils. ---*/
196 
197 static const char* ssl_error_string(int error) {
198  switch (error) {
199  case SSL_ERROR_NONE:
200  return "SSL_ERROR_NONE";
202  return "SSL_ERROR_ZERO_RETURN";
203  case SSL_ERROR_WANT_READ:
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";
213  case SSL_ERROR_SYSCALL:
214  return "SSL_ERROR_SYSCALL";
215  case SSL_ERROR_SSL:
216  return "SSL_ERROR_SSL";
217  default:
218  return "Unknown error";
219  }
220 }
221 
222 /* TODO(jboeuf): Remove when we are past the debugging phase with this code. */
223 static void ssl_log_where_info(const SSL* ssl, int where, int flag,
224  const char* msg) {
226  gpr_log(GPR_INFO, "%20.20s - %30.30s - %5.10s", msg,
228  }
229 }
230 
231 /* Used for debugging. TODO(jboeuf): Remove when code is mature enough. */
232 static void ssl_info_callback(const SSL* ssl, int where, int ret) {
233  if (ret == 0) {
234  gpr_log(GPR_ERROR, "ssl_info_callback: error occurred.\n");
235  return;
236  }
237 
238  ssl_log_where_info(ssl, where, SSL_CB_LOOP, "LOOP");
239  ssl_log_where_info(ssl, where, SSL_CB_HANDSHAKE_START, "HANDSHAKE START");
240  ssl_log_where_info(ssl, where, SSL_CB_HANDSHAKE_DONE, "HANDSHAKE DONE");
241 }
242 
243 /* Returns 1 if name looks like an IP address, 0 otherwise.
244  This is a very rough heuristic, and only handles IPv6 in hexadecimal form. */
246  size_t dot_count = 0;
247  size_t num_size = 0;
248  for (size_t i = 0; i < name.size(); ++i) {
249  if (name[i] == ':') {
250  /* IPv6 Address in hexadecimal form, : is not allowed in DNS names. */
251  return 1;
252  }
253  if (name[i] >= '0' && name[i] <= '9') {
254  if (num_size > 3) return 0;
255  num_size++;
256  } else if (name[i] == '.') {
257  if (dot_count > 3 || num_size == 0) return 0;
258  dot_count++;
259  num_size = 0;
260  } else {
261  return 0;
262  }
263  }
264  if (dot_count < 3 || num_size == 0) return 0;
265  return 1;
266 }
267 
268 /* Gets the subject CN from an X509 cert. */
269 static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8,
270  size_t* utf8_size) {
271  int common_name_index = -1;
272  X509_NAME_ENTRY* common_name_entry = nullptr;
273  ASN1_STRING* common_name_asn1 = nullptr;
274  X509_NAME* subject_name = X509_get_subject_name(cert);
275  int utf8_returned_size = 0;
276  if (subject_name == nullptr) {
277  gpr_log(GPR_INFO, "Could not get subject name from certificate.");
278  return TSI_NOT_FOUND;
279  }
280  common_name_index =
281  X509_NAME_get_index_by_NID(subject_name, NID_commonName, -1);
282  if (common_name_index == -1) {
283  gpr_log(GPR_INFO, "Could not get common name of subject from certificate.");
284  return TSI_NOT_FOUND;
285  }
286  common_name_entry = X509_NAME_get_entry(subject_name, common_name_index);
287  if (common_name_entry == nullptr) {
288  gpr_log(GPR_ERROR, "Could not get common name entry from certificate.");
289  return TSI_INTERNAL_ERROR;
290  }
291  common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry);
292  if (common_name_asn1 == nullptr) {
294  "Could not get common name entry asn1 from certificate.");
295  return TSI_INTERNAL_ERROR;
296  }
297  utf8_returned_size = ASN1_STRING_to_UTF8(utf8, common_name_asn1);
298  if (utf8_returned_size < 0) {
299  gpr_log(GPR_ERROR, "Could not extract utf8 from asn1 string.");
300  return TSI_OUT_OF_RESOURCES;
301  }
302  *utf8_size = static_cast<size_t>(utf8_returned_size);
303  return TSI_OK;
304 }
305 
306 /* Gets the subject CN of an X509 cert as a tsi_peer_property. */
308  X509* cert, tsi_peer_property* property) {
309  unsigned char* common_name;
310  size_t common_name_size;
312  ssl_get_x509_common_name(cert, &common_name, &common_name_size);
313  if (result != TSI_OK) {
314  if (result == TSI_NOT_FOUND) {
315  common_name = nullptr;
316  common_name_size = 0;
317  } else {
318  return result;
319  }
320  }
323  common_name == nullptr ? "" : reinterpret_cast<const char*>(common_name),
324  common_name_size, property);
325  OPENSSL_free(common_name);
326  return result;
327 }
328 
329 /* Gets the subject of an X509 cert as a tsi_peer_property. */
331  tsi_peer_property* property) {
332  X509_NAME* subject_name = X509_get_subject_name(cert);
333  if (subject_name == nullptr) {
334  gpr_log(GPR_INFO, "Could not get subject name from certificate.");
335  return TSI_NOT_FOUND;
336  }
337  BIO* bio = BIO_new(BIO_s_mem());
338  X509_NAME_print_ex(bio, subject_name, 0, XN_FLAG_RFC2253);
339  char* contents;
340  long len = BIO_get_mem_data(bio, &contents);
341  if (len < 0) {
342  gpr_log(GPR_ERROR, "Could not get subject entry from certificate.");
343  BIO_free(bio);
344  return TSI_INTERNAL_ERROR;
345  }
347  TSI_X509_SUBJECT_PEER_PROPERTY, contents, static_cast<size_t>(len),
348  property);
349  BIO_free(bio);
350  return result;
351 }
352 
353 /* Gets the X509 cert in PEM format as a tsi_peer_property. */
355  BIO* bio = BIO_new(BIO_s_mem());
356  if (!PEM_write_bio_X509(bio, cert)) {
357  BIO_free(bio);
358  return TSI_INTERNAL_ERROR;
359  }
360  char* contents;
361  long len = BIO_get_mem_data(bio, &contents);
362  if (len <= 0) {
363  BIO_free(bio);
364  return TSI_INTERNAL_ERROR;
365  }
367  TSI_X509_PEM_CERT_PROPERTY, contents, static_cast<size_t>(len), property);
368  BIO_free(bio);
369  return result;
370 }
371 
372 /* Gets the subject SANs from an X509 cert as a tsi_peer_property. */
374  tsi_peer* peer, GENERAL_NAMES* subject_alt_names,
375  size_t subject_alt_name_count, int* current_insert_index) {
376  size_t i;
378 
379  for (i = 0; i < subject_alt_name_count; i++) {
380  GENERAL_NAME* subject_alt_name =
381  sk_GENERAL_NAME_value(subject_alt_names, TSI_SIZE_AS_SIZE(i));
382  if (subject_alt_name->type == GEN_DNS ||
383  subject_alt_name->type == GEN_EMAIL ||
384  subject_alt_name->type == GEN_URI) {
385  unsigned char* name = nullptr;
386  int name_size;
387  std::string property_name;
388  if (subject_alt_name->type == GEN_DNS) {
389  name_size = ASN1_STRING_to_UTF8(&name, subject_alt_name->d.dNSName);
390  property_name = TSI_X509_DNS_PEER_PROPERTY;
391  } else if (subject_alt_name->type == GEN_EMAIL) {
392  name_size = ASN1_STRING_to_UTF8(&name, subject_alt_name->d.rfc822Name);
393  property_name = TSI_X509_EMAIL_PEER_PROPERTY;
394  } else {
395  name_size = ASN1_STRING_to_UTF8(
396  &name, subject_alt_name->d.uniformResourceIdentifier);
397  property_name = TSI_X509_URI_PEER_PROPERTY;
398  }
399  if (name_size < 0) {
400  gpr_log(GPR_ERROR, "Could not get utf8 from asn1 string.");
402  break;
403  }
406  reinterpret_cast<const char*>(name), static_cast<size_t>(name_size),
407  &peer->properties[(*current_insert_index)++]);
408  if (result != TSI_OK) {
410  break;
411  }
413  property_name.c_str(), reinterpret_cast<const char*>(name),
414  static_cast<size_t>(name_size),
415  &peer->properties[(*current_insert_index)++]);
417  } else if (subject_alt_name->type == GEN_IPADD) {
418  char ntop_buf[INET6_ADDRSTRLEN];
419  int af;
420 
421  if (subject_alt_name->d.iPAddress->length == 4) {
422  af = AF_INET;
423  } else if (subject_alt_name->d.iPAddress->length == 16) {
424  af = AF_INET6;
425  } else {
426  gpr_log(GPR_ERROR, "SAN IP Address contained invalid IP");
428  break;
429  }
430  const char* name = inet_ntop(af, subject_alt_name->d.iPAddress->data,
431  ntop_buf, INET6_ADDRSTRLEN);
432  if (name == nullptr) {
433  gpr_log(GPR_ERROR, "Could not get IP string from asn1 octet.");
435  break;
436  }
437 
440  &peer->properties[(*current_insert_index)++]);
441  if (result != TSI_OK) break;
444  &peer->properties[(*current_insert_index)++]);
445  } else {
448  &peer->properties[(*current_insert_index)++]);
449  }
450  if (result != TSI_OK) break;
451  }
452  return result;
453 }
454 
455 /* Gets information about the peer's X509 cert as a tsi_peer object. */
456 static tsi_result peer_from_x509(X509* cert, int include_certificate_type,
457  tsi_peer* peer) {
458  /* TODO(jboeuf): Maybe add more properties. */
459  GENERAL_NAMES* subject_alt_names = static_cast<GENERAL_NAMES*>(
460  X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr));
461  int subject_alt_name_count =
462  (subject_alt_names != nullptr)
463  ? static_cast<int>(sk_GENERAL_NAME_num(subject_alt_names))
464  : 0;
465  size_t property_count;
467  GPR_ASSERT(subject_alt_name_count >= 0);
468  property_count = (include_certificate_type ? static_cast<size_t>(1) : 0) +
469  3 /* subject, common name, certificate */ +
470  static_cast<size_t>(subject_alt_name_count);
471  for (int i = 0; i < subject_alt_name_count; i++) {
472  GENERAL_NAME* subject_alt_name =
473  sk_GENERAL_NAME_value(subject_alt_names, TSI_SIZE_AS_SIZE(i));
474  // TODO(zhenlian): Clean up tsi_peer to avoid duplicate entries.
475  // URI, DNS, email and ip address SAN fields are plumbed to tsi_peer, in
476  // addition to all SAN fields (results in duplicate values). This code
477  // snippet updates property_count accordingly.
478  if (subject_alt_name->type == GEN_URI ||
479  subject_alt_name->type == GEN_DNS ||
480  subject_alt_name->type == GEN_EMAIL ||
481  subject_alt_name->type == GEN_IPADD) {
482  property_count += 1;
483  }
484  }
485  result = tsi_construct_peer(property_count, peer);
486  if (result != TSI_OK) return result;
487  int current_insert_index = 0;
488  do {
489  if (include_certificate_type) {
492  &peer->properties[current_insert_index++]);
493  if (result != TSI_OK) break;
494  }
495 
497  cert, &peer->properties[current_insert_index++]);
498  if (result != TSI_OK) break;
499 
501  cert, &peer->properties[current_insert_index++]);
502  if (result != TSI_OK) break;
503 
504  result =
505  add_pem_certificate(cert, &peer->properties[current_insert_index++]);
506  if (result != TSI_OK) break;
507 
508  if (subject_alt_name_count != 0) {
510  peer, subject_alt_names, static_cast<size_t>(subject_alt_name_count),
511  &current_insert_index);
512  if (result != TSI_OK) break;
513  }
514  } while (false);
515 
516  if (subject_alt_names != nullptr) {
517  sk_GENERAL_NAME_pop_free(subject_alt_names, GENERAL_NAME_free);
518  }
519  if (result != TSI_OK) tsi_peer_destruct(peer);
520 
521  GPR_ASSERT((int)peer->property_count == current_insert_index);
522  return result;
523 }
524 
525 /* Logs the SSL error stack. */
526 static void log_ssl_error_stack(void) {
527  unsigned long err;
528  while ((err = ERR_get_error()) != 0) {
529  char details[256];
530  ERR_error_string_n(static_cast<uint32_t>(err), details, sizeof(details));
531  gpr_log(GPR_ERROR, "%s", details);
532  }
533 }
534 
535 /* Performs an SSL_read and handle errors. */
536 static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes,
537  size_t* unprotected_bytes_size) {
538  GPR_ASSERT(*unprotected_bytes_size <= INT_MAX);
539  ERR_clear_error();
540  int read_from_ssl = SSL_read(ssl, unprotected_bytes,
541  static_cast<int>(*unprotected_bytes_size));
542  if (read_from_ssl <= 0) {
543  read_from_ssl = SSL_get_error(ssl, read_from_ssl);
544  switch (read_from_ssl) {
545  case SSL_ERROR_ZERO_RETURN: /* Received a close_notify alert. */
546  case SSL_ERROR_WANT_READ: /* We need more data to finish the frame. */
547  *unprotected_bytes_size = 0;
548  return TSI_OK;
550  gpr_log(
551  GPR_ERROR,
552  "Peer tried to renegotiate SSL connection. This is unsupported.");
553  return TSI_UNIMPLEMENTED;
554  case SSL_ERROR_SSL:
555  gpr_log(GPR_ERROR, "Corruption detected.");
557  return TSI_DATA_CORRUPTED;
558  default:
559  gpr_log(GPR_ERROR, "SSL_read failed with error %s.",
560  ssl_error_string(read_from_ssl));
561  return TSI_PROTOCOL_FAILURE;
562  }
563  }
564  *unprotected_bytes_size = static_cast<size_t>(read_from_ssl);
565  return TSI_OK;
566 }
567 
568 /* Performs an SSL_write and handle errors. */
569 static tsi_result do_ssl_write(SSL* ssl, unsigned char* unprotected_bytes,
570  size_t unprotected_bytes_size) {
571  GPR_ASSERT(unprotected_bytes_size <= INT_MAX);
572  ERR_clear_error();
573  int ssl_write_result = SSL_write(ssl, unprotected_bytes,
574  static_cast<int>(unprotected_bytes_size));
575  if (ssl_write_result < 0) {
576  ssl_write_result = SSL_get_error(ssl, ssl_write_result);
577  if (ssl_write_result == SSL_ERROR_WANT_READ) {
579  "Peer tried to renegotiate SSL connection. This is unsupported.");
580  return TSI_UNIMPLEMENTED;
581  } else {
582  gpr_log(GPR_ERROR, "SSL_write failed with error %s.",
583  ssl_error_string(ssl_write_result));
584  return TSI_INTERNAL_ERROR;
585  }
586  }
587  return TSI_OK;
588 }
589 
590 /* Loads an in-memory PEM certificate chain into the SSL context. */
592  const char* pem_cert_chain,
593  size_t pem_cert_chain_size) {
595  X509* certificate = nullptr;
596  BIO* pem;
597  GPR_ASSERT(pem_cert_chain_size <= INT_MAX);
598  pem = BIO_new_mem_buf(pem_cert_chain, static_cast<int>(pem_cert_chain_size));
599  if (pem == nullptr) return TSI_OUT_OF_RESOURCES;
600 
601  do {
602  certificate =
603  PEM_read_bio_X509_AUX(pem, nullptr, nullptr, const_cast<char*>(""));
604  if (certificate == nullptr) {
606  break;
607  }
608  if (!SSL_CTX_use_certificate(context, certificate)) {
610  break;
611  }
612  while (true) {
613  X509* certificate_authority =
614  PEM_read_bio_X509(pem, nullptr, nullptr, const_cast<char*>(""));
615  if (certificate_authority == nullptr) {
616  ERR_clear_error();
617  break; /* Done reading. */
618  }
619  if (!SSL_CTX_add_extra_chain_cert(context, certificate_authority)) {
620  X509_free(certificate_authority);
622  break;
623  }
624  /* We don't need to free certificate_authority as its ownership has been
625  transferred to the context. That is not the case for certificate
626  though.
627  */
628  }
629  } while (false);
630 
631  if (certificate != nullptr) X509_free(certificate);
632  BIO_free(pem);
633  return result;
634 }
635 
636 #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
638  const char* pem_key,
639  size_t pem_key_size) {
641  EVP_PKEY* private_key = nullptr;
642  ENGINE* engine = nullptr;
643  char* engine_name = nullptr;
644  // Parse key which is in following format engine:<engine_id>:<key_id>
645  do {
646  char* engine_start = (char*)pem_key + strlen(kSslEnginePrefix);
647  char* engine_end = (char*)strchr(engine_start, ':');
648  if (engine_end == nullptr) {
650  break;
651  }
652  char* key_id = engine_end + 1;
653  int engine_name_length = engine_end - engine_start;
654  if (engine_name_length == 0) {
656  break;
657  }
658  engine_name = static_cast<char*>(gpr_zalloc(engine_name_length + 1));
659  memcpy(engine_name, engine_start, engine_name_length);
660  gpr_log(GPR_DEBUG, "ENGINE key: %s", engine_name);
661  ENGINE_load_dynamic();
662  engine = ENGINE_by_id(engine_name);
663  if (engine == nullptr) {
664  // If not available at ENGINE_DIR, use dynamic to load from
665  // current working directory.
666  engine = ENGINE_by_id("dynamic");
667  if (engine == nullptr) {
668  gpr_log(GPR_ERROR, "Cannot load dynamic engine");
670  break;
671  }
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)) {
677  gpr_log(GPR_ERROR, "Cannot find engine");
679  break;
680  }
681  }
682  if (!ENGINE_set_default(engine, ENGINE_METHOD_ALL)) {
683  gpr_log(GPR_ERROR, "ENGINE_set_default with ENGINE_METHOD_ALL failed");
685  break;
686  }
687  if (!ENGINE_init(engine)) {
688  gpr_log(GPR_ERROR, "ENGINE_init failed");
690  break;
691  }
692  private_key = ENGINE_load_private_key(engine, key_id, 0, 0);
693  if (private_key == nullptr) {
694  gpr_log(GPR_ERROR, "ENGINE_load_private_key failed");
696  break;
697  }
699  gpr_log(GPR_ERROR, "SSL_CTX_use_PrivateKey failed");
701  break;
702  }
703  } while (0);
704  if (engine != nullptr) ENGINE_free(engine);
705  if (private_key != nullptr) EVP_PKEY_free(private_key);
706  if (engine_name != nullptr) gpr_free(engine_name);
707  return result;
708 }
709 #endif /* !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE) */
710 
712  const char* pem_key,
713  size_t pem_key_size) {
715  EVP_PKEY* private_key = nullptr;
716  BIO* pem;
717  GPR_ASSERT(pem_key_size <= INT_MAX);
718  pem = BIO_new_mem_buf(pem_key, static_cast<int>(pem_key_size));
719  if (pem == nullptr) return TSI_OUT_OF_RESOURCES;
720  do {
721  private_key =
722  PEM_read_bio_PrivateKey(pem, nullptr, nullptr, const_cast<char*>(""));
723  if (private_key == nullptr) {
725  break;
726  }
729  break;
730  }
731  } while (false);
732  if (private_key != nullptr) EVP_PKEY_free(private_key);
733  BIO_free(pem);
734  return result;
735 }
736 
737 /* Loads an in-memory PEM private key into the SSL context. */
738 static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key,
739  size_t pem_key_size) {
740 // BoringSSL does not have ENGINE support
741 #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
742  if (strncmp(pem_key, kSslEnginePrefix, strlen(kSslEnginePrefix)) == 0) {
743  return ssl_ctx_use_engine_private_key(context, pem_key, pem_key_size);
744  } else
745 #endif /* !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE) */
746  {
747  return ssl_ctx_use_pem_private_key(context, pem_key, pem_key_size);
748  }
749 }
750 
751 /* Loads in-memory PEM verification certs into the SSL context and optionally
752  returns the verification cert names (root_names can be NULL). */
754  const char* pem_roots,
755  size_t pem_roots_size,
756  STACK_OF(X509_NAME) * *root_names) {
758  size_t num_roots = 0;
759  X509* root = nullptr;
760  X509_NAME* root_name = nullptr;
761  BIO* pem;
762  GPR_ASSERT(pem_roots_size <= INT_MAX);
763  pem = BIO_new_mem_buf(pem_roots, static_cast<int>(pem_roots_size));
764  if (cert_store == nullptr) return TSI_INVALID_ARGUMENT;
765  if (pem == nullptr) return TSI_OUT_OF_RESOURCES;
766  if (root_names != nullptr) {
767  *root_names = sk_X509_NAME_new_null();
768  if (*root_names == nullptr) return TSI_OUT_OF_RESOURCES;
769  }
770 
771  while (true) {
772  root = PEM_read_bio_X509_AUX(pem, nullptr, nullptr, const_cast<char*>(""));
773  if (root == nullptr) {
774  ERR_clear_error();
775  break; /* We're at the end of stream. */
776  }
777  if (root_names != nullptr) {
778  root_name = X509_get_subject_name(root);
779  if (root_name == nullptr) {
780  gpr_log(GPR_ERROR, "Could not get name from root certificate.");
782  break;
783  }
784  root_name = X509_NAME_dup(root_name);
785  if (root_name == nullptr) {
787  break;
788  }
789  sk_X509_NAME_push(*root_names, root_name);
790  root_name = nullptr;
791  }
792  ERR_clear_error();
793  if (!X509_STORE_add_cert(cert_store, root)) {
794  unsigned long error = ERR_get_error();
795  if (ERR_GET_LIB(error) != ERR_LIB_X509 ||
797  gpr_log(GPR_ERROR, "Could not add root certificate to ssl context.");
799  break;
800  }
801  }
802  X509_free(root);
803  num_roots++;
804  }
805  if (num_roots == 0) {
806  gpr_log(GPR_ERROR, "Could not load any root certificate.");
808  }
809 
810  if (result != TSI_OK) {
811  if (root != nullptr) X509_free(root);
812  if (root_names != nullptr) {
814  *root_names = nullptr;
815  if (root_name != nullptr) X509_NAME_free(root_name);
816  }
817  }
818  BIO_free(pem);
819  return result;
820 }
821 
823  const char* pem_roots,
824  size_t pem_roots_size,
826  *root_name) {
828  X509_STORE_set_flags(cert_store,
830  return x509_store_load_certs(cert_store, pem_roots, pem_roots_size,
831  root_name);
832 }
833 
834 /* Populates the SSL context with a private key and a cert chain, and sets the
835  cipher list and the ephemeral ECDH key. */
837  SSL_CTX* context, const tsi_ssl_pem_key_cert_pair* key_cert_pair,
838  const char* cipher_list) {
840  if (key_cert_pair != nullptr) {
841  if (key_cert_pair->cert_chain != nullptr) {
843  strlen(key_cert_pair->cert_chain));
844  if (result != TSI_OK) {
845  gpr_log(GPR_ERROR, "Invalid cert chain file.");
846  return result;
847  }
848  }
849  if (key_cert_pair->private_key != nullptr) {
851  strlen(key_cert_pair->private_key));
853  gpr_log(GPR_ERROR, "Invalid private key.");
855  }
856  }
857  }
858  if ((cipher_list != nullptr) &&
859  !SSL_CTX_set_cipher_list(context, cipher_list)) {
860  gpr_log(GPR_ERROR, "Invalid cipher list: %s.", cipher_list);
861  return TSI_INVALID_ARGUMENT;
862  }
863  {
865  if (!SSL_CTX_set_tmp_ecdh(context, ecdh)) {
866  gpr_log(GPR_ERROR, "Could not set ephemeral ECDH key.");
867  EC_KEY_free(ecdh);
868  return TSI_INTERNAL_ERROR;
869  }
871  EC_KEY_free(ecdh);
872  }
873  return TSI_OK;
874 }
875 
876 /* Extracts the CN and the SANs from an X509 cert as a peer object. */
878  const char* pem_cert, tsi_peer* peer) {
880  X509* cert = nullptr;
881  BIO* pem;
882  pem = BIO_new_mem_buf(pem_cert, static_cast<int>(strlen(pem_cert)));
883  if (pem == nullptr) return TSI_OUT_OF_RESOURCES;
884 
885  cert = PEM_read_bio_X509(pem, nullptr, nullptr, const_cast<char*>(""));
886  if (cert == nullptr) {
887  gpr_log(GPR_ERROR, "Invalid certificate");
889  } else {
890  result = peer_from_x509(cert, 0, peer);
891  }
892  if (cert != nullptr) X509_free(cert);
893  BIO_free(pem);
894  return result;
895 }
896 
897 /* Builds the alpn protocol name list according to rfc 7301. */
899  const char** alpn_protocols, uint16_t num_alpn_protocols,
900  unsigned char** protocol_name_list, size_t* protocol_name_list_length) {
901  uint16_t i;
902  unsigned char* current;
903  *protocol_name_list = nullptr;
904  *protocol_name_list_length = 0;
905  if (num_alpn_protocols == 0) return TSI_INVALID_ARGUMENT;
906  for (i = 0; i < num_alpn_protocols; i++) {
907  size_t length =
908  alpn_protocols[i] == nullptr ? 0 : strlen(alpn_protocols[i]);
909  if (length == 0 || length > 255) {
910  gpr_log(GPR_ERROR, "Invalid protocol name length: %d.",
911  static_cast<int>(length));
912  return TSI_INVALID_ARGUMENT;
913  }
914  *protocol_name_list_length += length + 1;
915  }
916  *protocol_name_list =
917  static_cast<unsigned char*>(gpr_malloc(*protocol_name_list_length));
918  if (*protocol_name_list == nullptr) return TSI_OUT_OF_RESOURCES;
919  current = *protocol_name_list;
920  for (i = 0; i < num_alpn_protocols; i++) {
921  size_t length = strlen(alpn_protocols[i]);
922  *(current++) = static_cast<uint8_t>(length); /* max checked above. */
923  memcpy(current, alpn_protocols[i], length);
924  current += length;
925  }
926  /* Safety check. */
927  if ((current < *protocol_name_list) ||
928  (static_cast<uintptr_t>(current - *protocol_name_list) !=
929  *protocol_name_list_length)) {
930  return TSI_INTERNAL_ERROR;
931  }
932  return TSI_OK;
933 }
934 
935 // The verification callback is used for clients that don't really care about
936 // the server's certificate, but we need to pull it anyway, in case a higher
937 // layer wants to look at it. In this case the verification may fail, but
938 // we don't really care.
939 static int NullVerifyCallback(int /*preverify_ok*/, X509_STORE_CTX* /*ctx*/) {
940  return 1;
941 }
942 
943 // Sets the min and max TLS version of |ssl_context| to |min_tls_version| and
944 // |max_tls_version|, respectively. Calling this method is a no-op when using
945 // OpenSSL versions < 1.1.
947  SSL_CTX* ssl_context, tsi_tls_version min_tls_version,
948  tsi_tls_version max_tls_version) {
949  if (ssl_context == nullptr) {
951  "Invalid nullptr argument to |tsi_set_min_and_max_tls_versions|.");
952  return TSI_INVALID_ARGUMENT;
953  }
954 #if OPENSSL_VERSION_NUMBER >= 0x10100000
955  // Set the min TLS version of the SSL context if using OpenSSL version
956  // >= 1.1.0. This OpenSSL version is required because the
957  // |SSL_CTX_set_min_proto_version| and |SSL_CTX_set_max_proto_version| APIs
958  // only exist in this version range.
959  switch (min_tls_version) {
962  break;
963 #if defined(TLS1_3_VERSION)
964  // If the library does not support TLS 1.3 and the caller requests a minimum
965  // of TLS 1.3, then return an error because the caller's request cannot be
966  // satisfied.
969  break;
970 #endif
971  default:
972  gpr_log(GPR_INFO, "TLS version is not supported.");
974  }
975 
976  // Set the max TLS version of the SSL context.
977  switch (max_tls_version) {
980  break;
982 #if defined(TLS1_3_VERSION)
984 #else
985  // If the library does not support TLS 1.3, then set the max TLS version
986  // to TLS 1.2 instead.
988 #endif
989  break;
990  default:
991  gpr_log(GPR_INFO, "TLS version is not supported.");
993  }
994 #endif
995  return TSI_OK;
996 }
997 
998 /* --- tsi_ssl_root_certs_store methods implementation. ---*/
999 
1001  const char* pem_roots) {
1002  if (pem_roots == nullptr) {
1003  gpr_log(GPR_ERROR, "The root certificates are empty.");
1004  return nullptr;
1005  }
1006  tsi_ssl_root_certs_store* root_store = static_cast<tsi_ssl_root_certs_store*>(
1008  if (root_store == nullptr) {
1009  gpr_log(GPR_ERROR, "Could not allocate buffer for ssl_root_certs_store.");
1010  return nullptr;
1011  }
1012  root_store->store = X509_STORE_new();
1013  if (root_store->store == nullptr) {
1014  gpr_log(GPR_ERROR, "Could not allocate buffer for X509_STORE.");
1015  gpr_free(root_store);
1016  return nullptr;
1017  }
1018  tsi_result result = x509_store_load_certs(root_store->store, pem_roots,
1019  strlen(pem_roots), nullptr);
1020  if (result != TSI_OK) {
1021  gpr_log(GPR_ERROR, "Could not load root certificates.");
1022  X509_STORE_free(root_store->store);
1023  gpr_free(root_store);
1024  return nullptr;
1025  }
1026  return root_store;
1027 }
1028 
1030  if (self == nullptr) return;
1031  X509_STORE_free(self->store);
1032  gpr_free(self);
1033 }
1034 
1035 /* --- tsi_ssl_session_cache methods implementation. ---*/
1036 
1038  /* Pointer will be dereferenced by unref call. */
1039  return reinterpret_cast<tsi_ssl_session_cache*>(
1041 }
1042 
1044  /* Pointer will be dereferenced by unref call. */
1045  reinterpret_cast<tsi::SslSessionLRUCache*>(cache)->Ref().release();
1046 }
1047 
1049  reinterpret_cast<tsi::SslSessionLRUCache*>(cache)->Unref();
1050 }
1051 
1052 /* --- tsi_frame_protector methods implementation. ---*/
1053 
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) {
1059  tsi_ssl_frame_protector* impl =
1060  reinterpret_cast<tsi_ssl_frame_protector*>(self);
1061  int read_from_ssl;
1062  size_t available;
1064 
1065  /* First see if we have some pending data in the SSL BIO. */
1066  int pending_in_ssl = static_cast<int>(BIO_pending(impl->network_io));
1067  if (pending_in_ssl > 0) {
1068  *unprotected_bytes_size = 0;
1069  GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
1070  read_from_ssl = BIO_read(impl->network_io, protected_output_frames,
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");
1075  return TSI_INTERNAL_ERROR;
1076  }
1077  *protected_output_frames_size = static_cast<size_t>(read_from_ssl);
1078  return TSI_OK;
1079  }
1080 
1081  /* Now see if we can send a complete frame. */
1082  available = impl->buffer_size - impl->buffer_offset;
1083  if (available > *unprotected_bytes_size) {
1084  /* If we cannot, just copy the data in our internal buffer. */
1085  memcpy(impl->buffer + impl->buffer_offset, unprotected_bytes,
1086  *unprotected_bytes_size);
1087  impl->buffer_offset += *unprotected_bytes_size;
1088  *protected_output_frames_size = 0;
1089  return TSI_OK;
1090  }
1091 
1092  /* If we can, prepare the buffer, send it to SSL_write and read. */
1093  memcpy(impl->buffer + impl->buffer_offset, unprotected_bytes, available);
1094  result = do_ssl_write(impl->ssl, impl->buffer, impl->buffer_size);
1095  if (result != TSI_OK) return result;
1096 
1097  GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
1098  read_from_ssl = BIO_read(impl->network_io, protected_output_frames,
1099  static_cast<int>(*protected_output_frames_size));
1100  if (read_from_ssl < 0) {
1101  gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write.");
1102  return TSI_INTERNAL_ERROR;
1103  }
1104  *protected_output_frames_size = static_cast<size_t>(read_from_ssl);
1105  *unprotected_bytes_size = available;
1106  impl->buffer_offset = 0;
1107  return TSI_OK;
1108 }
1109 
1111  tsi_frame_protector* self, unsigned char* protected_output_frames,
1112  size_t* protected_output_frames_size, size_t* still_pending_size) {
1114  tsi_ssl_frame_protector* impl =
1115  reinterpret_cast<tsi_ssl_frame_protector*>(self);
1116  int read_from_ssl = 0;
1117  int pending;
1118 
1119  if (impl->buffer_offset != 0) {
1120  result = do_ssl_write(impl->ssl, impl->buffer, impl->buffer_offset);
1121  if (result != TSI_OK) return result;
1122  impl->buffer_offset = 0;
1123  }
1124 
1125  pending = static_cast<int>(BIO_pending(impl->network_io));
1126  GPR_ASSERT(pending >= 0);
1127  *still_pending_size = static_cast<size_t>(pending);
1128  if (*still_pending_size == 0) return TSI_OK;
1129 
1130  GPR_ASSERT(*protected_output_frames_size <= INT_MAX);
1131  read_from_ssl = BIO_read(impl->network_io, protected_output_frames,
1132  static_cast<int>(*protected_output_frames_size));
1133  if (read_from_ssl <= 0) {
1134  gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write.");
1135  return TSI_INTERNAL_ERROR;
1136  }
1137  *protected_output_frames_size = static_cast<size_t>(read_from_ssl);
1138  pending = static_cast<int>(BIO_pending(impl->network_io));
1139  GPR_ASSERT(pending >= 0);
1140  *still_pending_size = static_cast<size_t>(pending);
1141  return TSI_OK;
1142 }
1143 
1145  tsi_frame_protector* self, const unsigned char* protected_frames_bytes,
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;
1152  tsi_ssl_frame_protector* impl =
1153  reinterpret_cast<tsi_ssl_frame_protector*>(self);
1154 
1155  /* First, try to read remaining data from ssl. */
1156  result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size);
1157  if (result != TSI_OK) return result;
1158  if (*unprotected_bytes_size == output_bytes_size) {
1159  /* We have read everything we could and cannot process any more input. */
1160  *protected_frames_bytes_size = 0;
1161  return TSI_OK;
1162  }
1163  output_bytes_offset = *unprotected_bytes_size;
1164  unprotected_bytes += output_bytes_offset;
1165  *unprotected_bytes_size = output_bytes_size - output_bytes_offset;
1166 
1167  /* Then, try to write some data to ssl. */
1168  GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX);
1169  written_into_ssl = BIO_write(impl->network_io, protected_frames_bytes,
1170  static_cast<int>(*protected_frames_bytes_size));
1171  if (written_into_ssl < 0) {
1172  gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d",
1173  written_into_ssl);
1174  return TSI_INTERNAL_ERROR;
1175  }
1176  *protected_frames_bytes_size = static_cast<size_t>(written_into_ssl);
1177 
1178  /* Now try to read some data again. */
1179  result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size);
1180  if (result == TSI_OK) {
1181  /* Don't forget to output the total number of bytes read. */
1182  *unprotected_bytes_size += output_bytes_offset;
1183  }
1184  return result;
1185 }
1186 
1188  tsi_ssl_frame_protector* impl =
1189  reinterpret_cast<tsi_ssl_frame_protector*>(self);
1190  if (impl->buffer != nullptr) gpr_free(impl->buffer);
1191  if (impl->ssl != nullptr) SSL_free(impl->ssl);
1192  if (impl->network_io != nullptr) BIO_free(impl->network_io);
1193  gpr_free(self);
1194 }
1195 
1201 };
1202 
1203 /* --- tsi_server_handshaker_factory methods implementation. --- */
1204 
1206  tsi_ssl_handshaker_factory* factory) {
1207  if (factory == nullptr) return;
1208 
1209  if (factory->vtable != nullptr && factory->vtable->destroy != nullptr) {
1210  factory->vtable->destroy(factory);
1211  }
1212  /* Note, we don't free(self) here because this object is always directly
1213  * embedded in another object. If tsi_ssl_handshaker_factory_init allocates
1214  * any memory, it should be free'd here. */
1215 }
1216 
1218  tsi_ssl_handshaker_factory* factory) {
1219  if (factory == nullptr) return nullptr;
1220  gpr_refn(&factory->refcount, 1);
1221  return factory;
1222 }
1223 
1225  tsi_ssl_handshaker_factory* factory) {
1226  if (factory == nullptr) return;
1227 
1228  if (gpr_unref(&factory->refcount)) {
1230  }
1231 }
1232 
1234 
1235 /* Initializes a tsi_ssl_handshaker_factory object. Caller is responsible for
1236  * allocating memory for the factory. */
1238  tsi_ssl_handshaker_factory* factory) {
1239  GPR_ASSERT(factory != nullptr);
1240 
1241  factory->vtable = &handshaker_factory_vtable;
1242  gpr_ref_init(&factory->refcount, 1);
1243 }
1244 
1245 /* Gets the X509 cert chain in PEM format as a tsi_peer_property. */
1247  tsi_peer_property* property) {
1248  BIO* bio = BIO_new(BIO_s_mem());
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++) {
1251  if (!PEM_write_bio_X509(bio, sk_X509_value(peer_chain, i))) {
1252  BIO_free(bio);
1253  return TSI_INTERNAL_ERROR;
1254  }
1255  }
1256  char* contents;
1257  long len = BIO_get_mem_data(bio, &contents);
1258  if (len <= 0) {
1259  BIO_free(bio);
1260  return TSI_INTERNAL_ERROR;
1261  }
1263  TSI_X509_PEM_CERT_CHAIN_PROPERTY, contents, static_cast<size_t>(len),
1264  property);
1265  BIO_free(bio);
1266  return result;
1267 }
1268 
1269 /* --- tsi_handshaker_result methods implementation. ---*/
1271  const tsi_handshaker_result* self, tsi_peer* peer) {
1273  const unsigned char* alpn_selected = nullptr;
1274  unsigned int alpn_selected_len;
1275  const tsi_ssl_handshaker_result* impl =
1276  reinterpret_cast<const tsi_ssl_handshaker_result*>(self);
1277  X509* peer_cert = SSL_get_peer_certificate(impl->ssl);
1278  if (peer_cert != nullptr) {
1279  result = peer_from_x509(peer_cert, 1, peer);
1280  X509_free(peer_cert);
1281  if (result != TSI_OK) return result;
1282  }
1283 #if TSI_OPENSSL_ALPN_SUPPORT
1284  SSL_get0_alpn_selected(impl->ssl, &alpn_selected, &alpn_selected_len);
1285 #endif /* TSI_OPENSSL_ALPN_SUPPORT */
1286  if (alpn_selected == nullptr) {
1287  /* Try npn. */
1288  SSL_get0_next_proto_negotiated(impl->ssl, &alpn_selected,
1289  &alpn_selected_len);
1290  }
1291  // When called on the client side, the stack also contains the
1292  // peer's certificate; When called on the server side,
1293  // the peer's certificate is not present in the stack
1294  STACK_OF(X509)* peer_chain = SSL_get_peer_cert_chain(impl->ssl);
1295  // 1 is for session reused property.
1296  size_t new_property_count = peer->property_count + 3;
1297  if (alpn_selected != nullptr) new_property_count++;
1298  if (peer_chain != nullptr) new_property_count++;
1299  tsi_peer_property* new_properties = static_cast<tsi_peer_property*>(
1300  gpr_zalloc(sizeof(*new_properties) * new_property_count));
1301  for (size_t i = 0; i < peer->property_count; i++) {
1302  new_properties[i] = peer->properties[i];
1303  }
1304  if (peer->properties != nullptr) gpr_free(peer->properties);
1305  peer->properties = new_properties;
1306  // Add peer chain if available
1307  if (peer_chain != nullptr) {
1309  peer_chain, &peer->properties[peer->property_count]);
1310  if (result == TSI_OK) peer->property_count++;
1311  }
1312  if (alpn_selected != nullptr) {
1315  reinterpret_cast<const char*>(alpn_selected), alpn_selected_len,
1316  &peer->properties[peer->property_count]);
1317  if (result != TSI_OK) return result;
1318  peer->property_count++;
1319  }
1320  // Add security_level peer property.
1324  &peer->properties[peer->property_count]);
1325  if (result != TSI_OK) return result;
1326  peer->property_count++;
1327 
1328  const char* session_reused = SSL_session_reused(impl->ssl) ? "true" : "false";
1330  TSI_SSL_SESSION_REUSED_PEER_PROPERTY, session_reused,
1331  &peer->properties[peer->property_count]);
1332  if (result != TSI_OK) return result;
1333  peer->property_count++;
1334  return result;
1335 }
1336 
1338  const tsi_handshaker_result* /*self*/,
1339  tsi_frame_protector_type* frame_protector_type) {
1340  *frame_protector_type = TSI_FRAME_PROTECTOR_NORMAL;
1341  return TSI_OK;
1342 }
1343 
1345  const tsi_handshaker_result* self, size_t* max_output_protected_frame_size,
1346  tsi_frame_protector** protector) {
1347  size_t actual_max_output_protected_frame_size =
1350  reinterpret_cast<tsi_ssl_handshaker_result*>(
1351  const_cast<tsi_handshaker_result*>(self));
1352  tsi_ssl_frame_protector* protector_impl =
1353  static_cast<tsi_ssl_frame_protector*>(
1354  gpr_zalloc(sizeof(*protector_impl)));
1355 
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 =
1365  }
1366  actual_max_output_protected_frame_size = *max_output_protected_frame_size;
1367  }
1368  protector_impl->buffer_size =
1369  actual_max_output_protected_frame_size - TSI_SSL_MAX_PROTECTION_OVERHEAD;
1370  protector_impl->buffer =
1371  static_cast<unsigned char*>(gpr_malloc(protector_impl->buffer_size));
1372  if (protector_impl->buffer == nullptr) {
1374  "Could not allocated buffer for tsi_ssl_frame_protector.");
1375  gpr_free(protector_impl);
1376  return TSI_INTERNAL_ERROR;
1377  }
1378 
1379  /* Transfer ownership of ssl and network_io to the frame protector. */
1380  protector_impl->ssl = impl->ssl;
1381  impl->ssl = nullptr;
1382  protector_impl->network_io = impl->network_io;
1383  impl->network_io = nullptr;
1384  protector_impl->base.vtable = &frame_protector_vtable;
1385  *protector = &protector_impl->base;
1386  return TSI_OK;
1387 }
1388 
1390  const tsi_handshaker_result* self, const unsigned char** bytes,
1391  size_t* bytes_size) {
1392  const tsi_ssl_handshaker_result* impl =
1393  reinterpret_cast<const tsi_ssl_handshaker_result*>(self);
1394  *bytes_size = impl->unused_bytes_size;
1395  *bytes = impl->unused_bytes;
1396  return TSI_OK;
1397 }
1398 
1401  reinterpret_cast<tsi_ssl_handshaker_result*>(self);
1402  SSL_free(impl->ssl);
1403  BIO_free(impl->network_io);
1404  gpr_free(impl->unused_bytes);
1405  gpr_free(impl);
1406 }
1407 
1411  nullptr, /* create_zero_copy_grpc_protector */
1415 };
1416 
1418  tsi_ssl_handshaker* handshaker, unsigned char* unused_bytes,
1419  size_t unused_bytes_size, tsi_handshaker_result** handshaker_result) {
1420  if (handshaker == nullptr || handshaker_result == nullptr ||
1421  (unused_bytes_size > 0 && unused_bytes == nullptr)) {
1422  return TSI_INVALID_ARGUMENT;
1423  }
1425  grpc_core::Zalloc<tsi_ssl_handshaker_result>();
1426  result->base.vtable = &handshaker_result_vtable;
1427  /* Transfer ownership of ssl and network_io to the handshaker result. */
1428  result->ssl = handshaker->ssl;
1429  handshaker->ssl = nullptr;
1430  result->network_io = handshaker->network_io;
1431  handshaker->network_io = nullptr;
1432  /* Transfer ownership of |unused_bytes| to the handshaker result. */
1433  result->unused_bytes = unused_bytes;
1434  result->unused_bytes_size = unused_bytes_size;
1435  *handshaker_result = &result->base;
1436  return TSI_OK;
1437 }
1438 
1439 /* --- tsi_handshaker methods implementation. ---*/
1440 
1442  tsi_ssl_handshaker* impl, unsigned char* bytes, size_t* bytes_size) {
1443  int bytes_read_from_ssl = 0;
1444  if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) {
1445  return TSI_INVALID_ARGUMENT;
1446  }
1447  GPR_ASSERT(*bytes_size <= INT_MAX);
1448  bytes_read_from_ssl =
1449  BIO_read(impl->network_io, bytes, static_cast<int>(*bytes_size));
1450  if (bytes_read_from_ssl < 0) {
1451  *bytes_size = 0;
1452  if (!BIO_should_retry(impl->network_io)) {
1453  impl->result = TSI_INTERNAL_ERROR;
1454  return impl->result;
1455  } else {
1456  return TSI_OK;
1457  }
1458  }
1459  *bytes_size = static_cast<size_t>(bytes_read_from_ssl);
1460  return BIO_pending(impl->network_io) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA;
1461 }
1462 
1464  if ((impl->result == TSI_HANDSHAKE_IN_PROGRESS) &&
1465  SSL_is_init_finished(impl->ssl)) {
1466  impl->result = TSI_OK;
1467  }
1468  return impl->result;
1469 }
1470 
1473  impl->result = TSI_OK;
1474  return impl->result;
1475  } else {
1476  ERR_clear_error();
1477  /* Get ready to get some bytes from SSL. */
1478  int ssl_result = SSL_do_handshake(impl->ssl);
1479  ssl_result = SSL_get_error(impl->ssl, ssl_result);
1480  switch (ssl_result) {
1481  case SSL_ERROR_WANT_READ:
1482  if (BIO_pending(impl->network_io) == 0) {
1483  /* We need more data. */
1484  return TSI_INCOMPLETE_DATA;
1485  } else {
1486  return TSI_OK;
1487  }
1488  case SSL_ERROR_NONE:
1489  return TSI_OK;
1490  case SSL_ERROR_WANT_WRITE:
1491  return TSI_DRAIN_BUFFER;
1492  default: {
1493  char err_str[256];
1494  ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
1495  gpr_log(GPR_ERROR, "Handshake failed with fatal error %s: %s.",
1496  ssl_error_string(ssl_result), err_str);
1497  impl->result = TSI_PROTOCOL_FAILURE;
1498  return impl->result;
1499  }
1500  }
1501  }
1502 }
1503 
1505  tsi_ssl_handshaker* impl, const unsigned char* bytes, size_t* bytes_size) {
1506  int bytes_written_into_ssl_size = 0;
1507  if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) {
1508  return TSI_INVALID_ARGUMENT;
1509  }
1510  GPR_ASSERT(*bytes_size <= INT_MAX);
1511  bytes_written_into_ssl_size =
1512  BIO_write(impl->network_io, bytes, static_cast<int>(*bytes_size));
1513  if (bytes_written_into_ssl_size < 0) {
1514  gpr_log(GPR_ERROR, "Could not write to memory BIO.");
1515  impl->result = TSI_INTERNAL_ERROR;
1516  return impl->result;
1517  }
1518  *bytes_size = static_cast<size_t>(bytes_written_into_ssl_size);
1519  return ssl_handshaker_do_handshake(impl);
1520 }
1521 
1523  tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self);
1524  SSL_free(impl->ssl);
1525  BIO_free(impl->network_io);
1528  gpr_free(impl);
1529 }
1530 
1531 // Removes the bytes remaining in |impl->SSL|'s read BIO and writes them to
1532 // |bytes_remaining|.
1534  unsigned char** bytes_remaining,
1535  size_t* bytes_remaining_size) {
1536  if (impl == nullptr || bytes_remaining == nullptr ||
1537  bytes_remaining_size == nullptr) {
1538  return TSI_INVALID_ARGUMENT;
1539  }
1540  // Atempt to read all of the bytes in SSL's read BIO. These bytes should
1541  // contain application data records that were appended to a handshake record
1542  // containing the ClientFinished or ServerFinished message.
1543  size_t bytes_in_ssl = BIO_pending(SSL_get_rbio(impl->ssl));
1544  if (bytes_in_ssl == 0) return TSI_OK;
1545  *bytes_remaining = static_cast<uint8_t*>(gpr_malloc(bytes_in_ssl));
1546  int bytes_read = BIO_read(SSL_get_rbio(impl->ssl), *bytes_remaining,
1547  static_cast<int>(bytes_in_ssl));
1548  // If an unexpected number of bytes were read, return an error status and free
1549  // all of the bytes that were read.
1550  if (bytes_read < 0 || static_cast<size_t>(bytes_read) != bytes_in_ssl) {
1552  "Failed to read the expected number of bytes from SSL object.");
1553  gpr_free(*bytes_remaining);
1554  *bytes_remaining = nullptr;
1555  return TSI_INTERNAL_ERROR;
1556  }
1557  *bytes_remaining_size = static_cast<size_t>(bytes_read);
1558  return TSI_OK;
1559 }
1560 
1561 // Write handshake data received from SSL to an unbound output buffer.
1562 // By doing that, we drain SSL bio buffer used to hold handshake data.
1563 // This API needs to be repeatedly called until all handshake data are
1564 // received from SSL.
1566  size_t* bytes_written) {
1567  tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self);
1569  size_t offset = *bytes_written;
1570  do {
1571  size_t to_send_size = impl->outgoing_bytes_buffer_size - offset;
1573  impl, impl->outgoing_bytes_buffer + offset, &to_send_size);
1574  offset += to_send_size;
1575  if (status == TSI_INCOMPLETE_DATA) {
1576  impl->outgoing_bytes_buffer_size *= 2;
1577  impl->outgoing_bytes_buffer = static_cast<unsigned char*>(gpr_realloc(
1579  }
1580  } while (status == TSI_INCOMPLETE_DATA);
1581  *bytes_written = offset;
1582  return status;
1583 }
1584 
1586  tsi_handshaker* self, const unsigned char* received_bytes,
1587  size_t received_bytes_size, const unsigned char** bytes_to_send,
1588  size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result,
1589  tsi_handshaker_on_next_done_cb /*cb*/, void* /*user_data*/) {
1590  /* Input sanity check. */
1591  if ((received_bytes_size > 0 && received_bytes == nullptr) ||
1592  bytes_to_send == nullptr || bytes_to_send_size == nullptr ||
1593  handshaker_result == nullptr) {
1594  return TSI_INVALID_ARGUMENT;
1595  }
1596  /* If there are received bytes, process them first. */
1597  tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self);
1599  size_t bytes_consumed = received_bytes_size;
1600  size_t bytes_written = 0;
1601  if (received_bytes_size > 0) {
1602  status = ssl_handshaker_process_bytes_from_peer(impl, received_bytes,
1603  &bytes_consumed);
1604  while (status == TSI_DRAIN_BUFFER) {
1606  if (status != TSI_OK) return status;
1608  }
1609  }
1610  if (status != TSI_OK) return status;
1611  /* Get bytes to send to the peer, if available. */
1613  if (status != TSI_OK) return status;
1614  *bytes_to_send = impl->outgoing_bytes_buffer;
1615  *bytes_to_send_size = bytes_written;
1616  /* If handshake completes, create tsi_handshaker_result. */
1618  *handshaker_result = nullptr;
1619  } else {
1620  // Any bytes that remain in |impl->ssl|'s read BIO after the handshake is
1621  // complete must be extracted and set to the unused bytes of the handshaker
1622  // result. This indicates to the gRPC stack that there are bytes from the
1623  // peer that must be processed.
1624  unsigned char* unused_bytes = nullptr;
1625  size_t unused_bytes_size = 0;
1626  status = ssl_bytes_remaining(impl, &unused_bytes, &unused_bytes_size);
1627  if (status != TSI_OK) return status;
1628  if (unused_bytes_size > received_bytes_size) {
1629  gpr_log(GPR_ERROR, "More unused bytes than received bytes.");
1630  gpr_free(unused_bytes);
1631  return TSI_INTERNAL_ERROR;
1632  }
1633  status = ssl_handshaker_result_create(impl, unused_bytes, unused_bytes_size,
1634  handshaker_result);
1635  if (status == TSI_OK) {
1636  /* Indicates that the handshake has completed and that a handshaker_result
1637  * has been created. */
1638  self->handshaker_result_created = true;
1639  }
1640  }
1641  return status;
1642 }
1643 
1645  nullptr, /* get_bytes_to_send_to_peer -- deprecated */
1646  nullptr, /* process_bytes_from_peer -- deprecated */
1647  nullptr, /* get_result -- deprecated */
1648  nullptr, /* extract_peer -- deprecated */
1649  nullptr, /* create_frame_protector -- deprecated */
1652  nullptr, /* shutdown */
1653 };
1654 
1655 /* --- tsi_ssl_handshaker_factory common methods. --- */
1656 
1658  SSL* ssl, tsi::SslSessionLRUCache* session_cache) {
1660  if (server_name == nullptr) {
1661  return;
1662  }
1663  tsi::SslSessionPtr session = session_cache->Get(server_name);
1664  if (session != nullptr) {
1665  // SSL_set_session internally increments reference counter.
1666  SSL_set_session(ssl, session.get());
1667  }
1668 }
1669 
1671  const char* server_name_indication,
1672  size_t network_bio_buf_size,
1673  size_t ssl_bio_buf_size,
1674  tsi_ssl_handshaker_factory* factory,
1675  tsi_handshaker** handshaker) {
1676  SSL* ssl = SSL_new(ctx);
1677  BIO* network_io = nullptr;
1678  BIO* ssl_io = nullptr;
1679  tsi_ssl_handshaker* impl = nullptr;
1680  *handshaker = nullptr;
1681  if (ctx == nullptr) {
1682  gpr_log(GPR_ERROR, "SSL Context is null. Should never happen.");
1683  return TSI_INTERNAL_ERROR;
1684  }
1685  if (ssl == nullptr) {
1686  return TSI_OUT_OF_RESOURCES;
1687  }
1689 
1690  if (!BIO_new_bio_pair(&network_io, network_bio_buf_size, &ssl_io,
1691  ssl_bio_buf_size)) {
1692  gpr_log(GPR_ERROR, "BIO_new_bio_pair failed.");
1693  SSL_free(ssl);
1694  return TSI_OUT_OF_RESOURCES;
1695  }
1696  SSL_set_bio(ssl, ssl_io, ssl_io);
1697  if (is_client) {
1698  int ssl_result;
1699  SSL_set_connect_state(ssl);
1700  if (server_name_indication != nullptr) {
1701  if (!SSL_set_tlsext_host_name(ssl, server_name_indication)) {
1702  gpr_log(GPR_ERROR, "Invalid server name indication %s.",
1703  server_name_indication);
1704  SSL_free(ssl);
1705  BIO_free(network_io);
1706  return TSI_INTERNAL_ERROR;
1707  }
1708  }
1709  tsi_ssl_client_handshaker_factory* client_factory =
1710  reinterpret_cast<tsi_ssl_client_handshaker_factory*>(factory);
1711  if (client_factory->session_cache != nullptr) {
1713  client_factory->session_cache.get());
1714  }
1715  ERR_clear_error();
1716  ssl_result = SSL_do_handshake(ssl);
1717  ssl_result = SSL_get_error(ssl, ssl_result);
1718  if (ssl_result != SSL_ERROR_WANT_READ) {
1720  "Unexpected error received from first SSL_do_handshake call: %s",
1721  ssl_error_string(ssl_result));
1722  SSL_free(ssl);
1723  BIO_free(network_io);
1724  return TSI_INTERNAL_ERROR;
1725  }
1726  } else {
1727  SSL_set_accept_state(ssl);
1728  }
1729 
1730  impl = grpc_core::Zalloc<tsi_ssl_handshaker>();
1731  impl->ssl = ssl;
1732  impl->network_io = network_io;
1736  impl->outgoing_bytes_buffer =
1737  static_cast<unsigned char*>(gpr_zalloc(impl->outgoing_bytes_buffer_size));
1738  impl->base.vtable = &handshaker_vtable;
1740  *handshaker = &impl->base;
1741  return TSI_OK;
1742 }
1743 
1744 static int select_protocol_list(const unsigned char** out,
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) <
1752  client_list_len) {
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) <
1757  server_list_len) {
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;
1763  return SSL_TLSEXT_ERR_OK;
1764  }
1765  server_current += server_current_len;
1766  }
1767  client_current += client_current_len;
1768  }
1769  return SSL_TLSEXT_ERR_NOACK;
1770 }
1771 
1772 /* --- tsi_ssl_client_handshaker_factory methods implementation. --- */
1773 
1776  const char* server_name_indication, size_t network_bio_buf_size,
1777  size_t ssl_bio_buf_size, tsi_handshaker** handshaker) {
1779  factory->ssl_context, 1, server_name_indication, network_bio_buf_size,
1780  ssl_bio_buf_size, &factory->base, handshaker);
1781 }
1782 
1785  if (factory == nullptr) return;
1787 }
1788 
1790  tsi_ssl_handshaker_factory* factory) {
1791  if (factory == nullptr) return;
1793  reinterpret_cast<tsi_ssl_client_handshaker_factory*>(factory);
1794  if (self->ssl_context != nullptr) SSL_CTX_free(self->ssl_context);
1795  if (self->alpn_protocol_list != nullptr) gpr_free(self->alpn_protocol_list);
1796  self->session_cache.reset();
1797  self->key_logger.reset();
1798  gpr_free(self);
1799 }
1800 
1802  SSL* /*ssl*/, unsigned char** out, unsigned char* outlen,
1803  const unsigned char* in, unsigned int inlen, void* arg) {
1805  static_cast<tsi_ssl_client_handshaker_factory*>(arg);
1806  return select_protocol_list(const_cast<const unsigned char**>(out), outlen,
1807  factory->alpn_protocol_list,
1808  factory->alpn_protocol_list_length, in, inlen);
1809 }
1810 
1811 /* --- tsi_ssl_server_handshaker_factory methods implementation. --- */
1812 
1814  tsi_ssl_server_handshaker_factory* factory, size_t network_bio_buf_size,
1815  size_t ssl_bio_buf_size, tsi_handshaker** handshaker) {
1816  if (factory->ssl_context_count == 0) return TSI_INVALID_ARGUMENT;
1817  /* Create the handshaker with the first context. We will switch if needed
1818  because of SNI in ssl_server_handshaker_factory_servername_callback. */
1819  return create_tsi_ssl_handshaker(factory->ssl_contexts[0], 0, nullptr,
1820  network_bio_buf_size, ssl_bio_buf_size,
1821  &factory->base, handshaker);
1822 }
1823 
1826  if (factory == nullptr) return;
1828 }
1829 
1831  tsi_ssl_handshaker_factory* factory) {
1832  if (factory == nullptr) return;
1834  reinterpret_cast<tsi_ssl_server_handshaker_factory*>(factory);
1835  size_t i;
1836  for (i = 0; i < self->ssl_context_count; i++) {
1837  if (self->ssl_contexts[i] != nullptr) {
1838  SSL_CTX_free(self->ssl_contexts[i]);
1839  tsi_peer_destruct(&self->ssl_context_x509_subject_names[i]);
1840  }
1841  }
1842  if (self->ssl_contexts != nullptr) gpr_free(self->ssl_contexts);
1843  if (self->ssl_context_x509_subject_names != nullptr) {
1844  gpr_free(self->ssl_context_x509_subject_names);
1845  }
1846  if (self->alpn_protocol_list != nullptr) gpr_free(self->alpn_protocol_list);
1847  self->key_logger.reset();
1848  gpr_free(self);
1849 }
1850 
1853  if (entry.empty()) return 0;
1854 
1855  /* Take care of '.' terminations. */
1856  if (name.back() == '.') {
1857  name.remove_suffix(1);
1858  }
1859  if (entry.back() == '.') {
1860  entry.remove_suffix(1);
1861  if (entry.empty()) return 0;
1862  }
1863 
1864  if (absl::EqualsIgnoreCase(name, entry)) {
1865  return 1; /* Perfect match. */
1866  }
1867  if (entry.front() != '*') return 0;
1868 
1869  /* Wildchar subdomain matching. */
1870  if (entry.size() < 3 || entry[1] != '.') { /* At least *.x */
1871  gpr_log(GPR_ERROR, "Invalid wildchar entry.");
1872  return 0;
1873  }
1874  size_t name_subdomain_pos = name.find('.');
1875  if (name_subdomain_pos == absl::string_view::npos) return 0;
1876  if (name_subdomain_pos >= name.size() - 2) return 0;
1877  absl::string_view name_subdomain =
1878  name.substr(name_subdomain_pos + 1); /* Starts after the dot. */
1879  entry.remove_prefix(2); /* Remove *. */
1880  size_t dot = name_subdomain.find('.');
1881  if (dot == absl::string_view::npos || dot == name_subdomain.size() - 1) {
1882  gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s",
1883  std::string(name_subdomain).c_str());
1884  return 0;
1885  }
1886  if (name_subdomain.back() == '.') {
1887  name_subdomain.remove_suffix(1);
1888  }
1889  return !entry.empty() && absl::EqualsIgnoreCase(name_subdomain, entry);
1890 }
1891 
1893  int* /*ap*/,
1894  void* arg) {
1896  static_cast<tsi_ssl_server_handshaker_factory*>(arg);
1897  size_t i = 0;
1898  const char* servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
1899  if (servername == nullptr || strlen(servername) == 0) {
1900  return SSL_TLSEXT_ERR_NOACK;
1901  }
1902 
1903  for (i = 0; i < impl->ssl_context_count; i++) {
1905  servername)) {
1906  SSL_set_SSL_CTX(ssl, impl->ssl_contexts[i]);
1907  return SSL_TLSEXT_ERR_OK;
1908  }
1909  }
1910  gpr_log(GPR_ERROR, "No match found for server name: %s.", servername);
1911  return SSL_TLSEXT_ERR_NOACK;
1912 }
1913 
1914 #if TSI_OPENSSL_ALPN_SUPPORT
1916  SSL* /*ssl*/, const unsigned char** out, unsigned char* outlen,
1917  const unsigned char* in, unsigned int inlen, void* arg) {
1919  static_cast<tsi_ssl_server_handshaker_factory*>(arg);
1920  return select_protocol_list(out, outlen, in, inlen,
1921  factory->alpn_protocol_list,
1922  factory->alpn_protocol_list_length);
1923 }
1924 #endif /* TSI_OPENSSL_ALPN_SUPPORT */
1925 
1927  SSL* /*ssl*/, const unsigned char** out, unsigned int* outlen, void* arg) {
1929  static_cast<tsi_ssl_server_handshaker_factory*>(arg);
1930  *out = factory->alpn_protocol_list;
1931  GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX);
1932  *outlen = static_cast<unsigned int>(factory->alpn_protocol_list_length);
1933  return SSL_TLSEXT_ERR_OK;
1934 }
1935 
1943  SSL* ssl, SSL_SESSION* session) {
1944  SSL_CTX* ssl_context = SSL_get_SSL_CTX(ssl);
1945  if (ssl_context == nullptr) {
1946  return 0;
1947  }
1948  void* arg = SSL_CTX_get_ex_data(ssl_context, g_ssl_ctx_ex_factory_index);
1950  static_cast<tsi_ssl_client_handshaker_factory*>(arg);
1952  if (server_name == nullptr) {
1953  return 0;
1954  }
1955  factory->session_cache->Put(server_name, tsi::SslSessionPtr(session));
1956  // Return 1 to indicate transferred ownership over the given session.
1957  return 1;
1958 }
1959 
1962 template <typename T>
1963 static void ssl_keylogging_callback(const SSL* ssl, const char* info) {
1964  SSL_CTX* ssl_context = SSL_get_SSL_CTX(ssl);
1965  GPR_ASSERT(ssl_context != nullptr);
1966  void* arg = SSL_CTX_get_ex_data(ssl_context, g_ssl_ctx_ex_factory_index);
1967  T* factory = static_cast<T*>(arg);
1968  factory->key_logger->LogSessionKeys(ssl_context, info);
1969 }
1970 
1971 // This callback is invoked when the CRL has been verified and will soft-fail
1972 // errors in verification depending on certain error types.
1973 static int verify_cb(int ok, X509_STORE_CTX* ctx) {
1974  int cert_error = X509_STORE_CTX_get_error(ctx);
1975  if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL) {
1976  gpr_log(
1977  GPR_INFO,
1978  "Certificate verification failed to get CRL files. Ignoring error.");
1979  return 1;
1980  }
1981  if (cert_error != 0) {
1982  gpr_log(GPR_ERROR, "Certificate verify failed with code %d", cert_error);
1983  }
1984  return ok;
1985 }
1986 
1987 /* --- tsi_ssl_handshaker_factory constructors. --- */
1988 
1991 
1993  const tsi_ssl_pem_key_cert_pair* pem_key_cert_pair,
1994  const char* pem_root_certs, const char* cipher_suites,
1995  const char** alpn_protocols, uint16_t num_alpn_protocols,
1998  options.pem_key_cert_pair = pem_key_cert_pair;
1999  options.pem_root_certs = pem_root_certs;
2000  options.cipher_suites = cipher_suites;
2001  options.alpn_protocols = alpn_protocols;
2002  options.num_alpn_protocols = num_alpn_protocols;
2004  factory);
2005 }
2006 
2010  SSL_CTX* ssl_context = nullptr;
2011  tsi_ssl_client_handshaker_factory* impl = nullptr;
2013 
2015 
2016  if (factory == nullptr) return TSI_INVALID_ARGUMENT;
2017  *factory = nullptr;
2018  if (options->pem_root_certs == nullptr && options->root_store == nullptr) {
2019  return TSI_INVALID_ARGUMENT;
2020  }
2021 
2022 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2023  ssl_context = SSL_CTX_new(TLS_method());
2024 #else
2025  ssl_context = SSL_CTX_new(TLSv1_2_method());
2026 #endif
2027  if (ssl_context == nullptr) {
2029  gpr_log(GPR_ERROR, "Could not create ssl context.");
2030  return TSI_INVALID_ARGUMENT;
2031  }
2032 
2034  ssl_context, options->min_tls_version, options->max_tls_version);
2035  if (result != TSI_OK) return result;
2036 
2037  impl = static_cast<tsi_ssl_client_handshaker_factory*>(
2038  gpr_zalloc(sizeof(*impl)));
2041  impl->ssl_context = ssl_context;
2042  if (options->session_cache != nullptr) {
2043  // Unref is called manually on factory destruction.
2044  impl->session_cache =
2045  reinterpret_cast<tsi::SslSessionLRUCache*>(options->session_cache)
2046  ->Ref();
2047  SSL_CTX_sess_set_new_cb(ssl_context,
2050  }
2051 
2052 #if OPENSSL_VERSION_NUMBER >= 0x10101000 && !defined(LIBRESSL_VERSION_NUMBER)
2053  if (options->key_logger != nullptr) {
2054  impl->key_logger = options->key_logger->Ref();
2055  // SSL_CTX_set_keylog_callback is set here to register callback
2056  // when ssl/tls handshakes complete.
2058  ssl_context,
2059  ssl_keylogging_callback<tsi_ssl_client_handshaker_factory>);
2060  }
2061 #endif
2062 
2063  if (options->session_cache != nullptr || options->key_logger != nullptr) {
2064  // Need to set factory at g_ssl_ctx_ex_factory_index
2065  SSL_CTX_set_ex_data(ssl_context, g_ssl_ctx_ex_factory_index, impl);
2066  }
2067 
2068  do {
2069  result = populate_ssl_context(ssl_context, options->pem_key_cert_pair,
2070  options->cipher_suites);
2071  if (result != TSI_OK) break;
2072 
2073 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2074  // X509_STORE_up_ref is only available since OpenSSL 1.1.
2075  if (options->root_store != nullptr) {
2076  X509_STORE_up_ref(options->root_store->store);
2077  SSL_CTX_set_cert_store(ssl_context, options->root_store->store);
2078  }
2079 #endif
2080  if (OPENSSL_VERSION_NUMBER < 0x10100000 || options->root_store == nullptr) {
2082  ssl_context, options->pem_root_certs, strlen(options->pem_root_certs),
2083  nullptr);
2084  if (result != TSI_OK) {
2085  gpr_log(GPR_ERROR, "Cannot load server root certificates.");
2086  break;
2087  }
2088  }
2089 
2090  if (options->num_alpn_protocols != 0) {
2092  options->alpn_protocols, options->num_alpn_protocols,
2094  if (result != TSI_OK) {
2095  gpr_log(GPR_ERROR, "Building alpn list failed with error %s.",
2097  break;
2098  }
2099 #if TSI_OPENSSL_ALPN_SUPPORT
2100  GPR_ASSERT(impl->alpn_protocol_list_length < UINT_MAX);
2102  ssl_context, impl->alpn_protocol_list,
2103  static_cast<unsigned int>(impl->alpn_protocol_list_length))) {
2104  gpr_log(GPR_ERROR, "Could not set alpn protocol list to context.");
2106  break;
2107  }
2108 #endif /* TSI_OPENSSL_ALPN_SUPPORT */
2110  ssl_context, client_handshaker_factory_npn_callback, impl);
2111  }
2112  } while (false);
2113  if (result != TSI_OK) {
2115  return result;
2116  }
2117  if (options->skip_server_certificate_verification) {
2119  } else {
2120  SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER, nullptr);
2121  }
2122 
2123 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2124  if (options->crl_directory != nullptr &&
2125  strcmp(options->crl_directory, "") != 0) {
2126  gpr_log(GPR_INFO, "enabling client CRL checking with path: %s",
2127  options->crl_directory);
2128  X509_STORE* cert_store = SSL_CTX_get_cert_store(ssl_context);
2129  X509_STORE_set_verify_cb(cert_store, verify_cb);
2130  if (!X509_STORE_load_locations(cert_store, nullptr,
2131  options->crl_directory)) {
2132  gpr_log(GPR_ERROR, "Failed to load CRL File from directory.");
2133  } else {
2134  X509_VERIFY_PARAM* param = X509_STORE_get0_param(cert_store);
2136  gpr_log(GPR_INFO, "enabled client side CRL checking.");
2137  }
2138  }
2139 #endif
2140 
2141  *factory = impl;
2142  return TSI_OK;
2143 }
2144 
2147 
2149  const tsi_ssl_pem_key_cert_pair* pem_key_cert_pairs,
2150  size_t num_key_cert_pairs, const char* pem_client_root_certs,
2151  int force_client_auth, const char* cipher_suites,
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);
2159 }
2160 
2162  const tsi_ssl_pem_key_cert_pair* pem_key_cert_pairs,
2163  size_t num_key_cert_pairs, const char* pem_client_root_certs,
2164  tsi_client_certificate_request_type client_certificate_request,
2165  const char* cipher_suites, const char** alpn_protocols,
2166  uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory** factory) {
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;
2172  options.cipher_suites = cipher_suites;
2173  options.alpn_protocols = alpn_protocols;
2174  options.num_alpn_protocols = num_alpn_protocols;
2176  factory);
2177 }
2178 
2182  tsi_ssl_server_handshaker_factory* impl = nullptr;
2184  size_t i = 0;
2185 
2187 
2188  if (factory == nullptr) return TSI_INVALID_ARGUMENT;
2189  *factory = nullptr;
2190  if (options->num_key_cert_pairs == 0 ||
2191  options->pem_key_cert_pairs == nullptr) {
2192  return TSI_INVALID_ARGUMENT;
2193  }
2194 
2195  impl = static_cast<tsi_ssl_server_handshaker_factory*>(
2196  gpr_zalloc(sizeof(*impl)));
2199 
2200  impl->ssl_contexts = static_cast<SSL_CTX**>(
2201  gpr_zalloc(options->num_key_cert_pairs * sizeof(SSL_CTX*)));
2202  impl->ssl_context_x509_subject_names = static_cast<tsi_peer*>(
2203  gpr_zalloc(options->num_key_cert_pairs * sizeof(tsi_peer)));
2204  if (impl->ssl_contexts == nullptr ||
2205  impl->ssl_context_x509_subject_names == nullptr) {
2207  return TSI_OUT_OF_RESOURCES;
2208  }
2209  impl->ssl_context_count = options->num_key_cert_pairs;
2210 
2211  if (options->num_alpn_protocols > 0) {
2213  options->alpn_protocols, options->num_alpn_protocols,
2215  if (result != TSI_OK) {
2217  return result;
2218  }
2219  }
2220 
2221  if (options->key_logger != nullptr) {
2222  impl->key_logger = options->key_logger->Ref();
2223  }
2224 
2225  for (i = 0; i < options->num_key_cert_pairs; i++) {
2226  do {
2227 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2228  impl->ssl_contexts[i] = SSL_CTX_new(TLS_method());
2229 #else
2231 #endif
2232  if (impl->ssl_contexts[i] == nullptr) {
2234  gpr_log(GPR_ERROR, "Could not create ssl context.");
2236  break;
2237  }
2238 
2240  options->min_tls_version,
2241  options->max_tls_version);
2242  if (result != TSI_OK) return result;
2243 
2245  &options->pem_key_cert_pairs[i],
2246  options->cipher_suites);
2247  if (result != TSI_OK) break;
2248 
2249  // TODO(elessar): Provide ability to disable session ticket keys.
2250 
2251  // Allow client cache sessions (it's needed for OpenSSL only).
2252  int set_sid_ctx_result = SSL_CTX_set_session_id_context(
2255  if (set_sid_ctx_result == 0) {
2256  gpr_log(GPR_ERROR, "Failed to set session id context.");
2258  break;
2259  }
2260 
2261  if (options->session_ticket_key != nullptr) {
2263  impl->ssl_contexts[i],
2264  const_cast<char*>(options->session_ticket_key),
2265  options->session_ticket_key_size) == 0) {
2266  gpr_log(GPR_ERROR, "Invalid STEK size.");
2268  break;
2269  }
2270  }
2271 
2272  if (options->pem_client_root_certs != nullptr) {
2273  STACK_OF(X509_NAME)* root_names = nullptr;
2275  impl->ssl_contexts[i], options->pem_client_root_certs,
2276  strlen(options->pem_client_root_certs), &root_names);
2277  if (result != TSI_OK) {
2278  gpr_log(GPR_ERROR, "Invalid verification certs.");
2279  break;
2280  }
2281  SSL_CTX_set_client_CA_list(impl->ssl_contexts[i], root_names);
2282  }
2283  switch (options->client_certificate_request) {
2286  break;
2290  break;
2293  break;
2298  break;
2302  nullptr);
2303  break;
2304  }
2305 
2306 #if OPENSSL_VERSION_NUMBER >= 0x10100000
2307  if (options->crl_directory != nullptr &&
2308  strcmp(options->crl_directory, "") != 0) {
2309  gpr_log(GPR_INFO, "enabling server CRL checking with path %s",
2310  options->crl_directory);
2311  X509_STORE* cert_store = SSL_CTX_get_cert_store(impl->ssl_contexts[i]);
2312  X509_STORE_set_verify_cb(cert_store, verify_cb);
2313  if (!X509_STORE_load_locations(cert_store, nullptr,
2314  options->crl_directory)) {
2315  gpr_log(GPR_ERROR, "Failed to load CRL File from directory.");
2316  } else {
2317  X509_VERIFY_PARAM* param = X509_STORE_get0_param(cert_store);
2319  gpr_log(GPR_INFO, "enabled server CRL checking.");
2320  }
2321  }
2322 #endif
2323 
2325  options->pem_key_cert_pairs[i].cert_chain,
2327  if (result != TSI_OK) break;
2328 
2330  impl->ssl_contexts[i],
2333 #if TSI_OPENSSL_ALPN_SUPPORT
2336 #endif /* TSI_OPENSSL_ALPN_SUPPORT */
2338  impl->ssl_contexts[i],
2340 
2341 #if OPENSSL_VERSION_NUMBER >= 0x10101000 && !defined(LIBRESSL_VERSION_NUMBER)
2342  /* Register factory at index */
2343  if (options->key_logger != nullptr) {
2344  // Need to set factory at g_ssl_ctx_ex_factory_index
2346  impl);
2347  // SSL_CTX_set_keylog_callback is set here to register callback
2348  // when ssl/tls handshakes complete.
2350  impl->ssl_contexts[i],
2351  ssl_keylogging_callback<tsi_ssl_server_handshaker_factory>);
2352  }
2353 #endif
2354  } while (false);
2355 
2356  if (result != TSI_OK) {
2358  return result;
2359  }
2360  }
2361 
2362  *factory = impl;
2363  return TSI_OK;
2364 }
2365 
2366 /* --- tsi_ssl utils. --- */
2367 
2369  size_t i = 0;
2370  size_t san_count = 0;
2371  const tsi_peer_property* cn_property = nullptr;
2372  int like_ip = looks_like_ip_address(name);
2373 
2374  /* Check the SAN first. */
2375  for (i = 0; i < peer->property_count; i++) {
2376  const tsi_peer_property* property = &peer->properties[i];
2377  if (property->name == nullptr) continue;
2378  if (strcmp(property->name,
2380  san_count++;
2381 
2382  absl::string_view entry(property->value.data, property->value.length);
2383  if (!like_ip && does_entry_match_name(entry, name)) {
2384  return 1;
2385  } else if (like_ip && name == entry) {
2386  /* IP Addresses are exact matches only. */
2387  return 1;
2388  }
2389  } else if (strcmp(property->name,
2391  cn_property = property;
2392  }
2393  }
2394 
2395  /* If there's no SAN, try the CN, but only if its not like an IP Address */
2396  if (san_count == 0 && cn_property != nullptr && !like_ip) {
2398  cn_property->value.length),
2399  name)) {
2400  return 1;
2401  }
2402  }
2403 
2404  return 0; /* Not found. */
2405 }
2406 
2407 /* --- Testing support. --- */
2409  tsi_ssl_handshaker_factory* factory,
2410  tsi_ssl_handshaker_factory_vtable* new_vtable) {
2411  GPR_ASSERT(factory != nullptr);
2412  GPR_ASSERT(factory->vtable != nullptr);
2413 
2414  const tsi_ssl_handshaker_factory_vtable* orig_vtable = factory->vtable;
2415  factory->vtable = new_vtable;
2416  return orig_vtable;
2417 }
SSL_CB_HANDSHAKE_START
#define SSL_CB_HANDSHAKE_START
Definition: ssl.h:4291
XN_FLAG_RFC2253
#define XN_FLAG_RFC2253
Definition: x509.h:236
tsi_security_level_to_string
const char * tsi_security_level_to_string(tsi_security_level security_level)
Definition: transport_security.cc:70
X509_NAME_print_ex
#define X509_NAME_print_ex
Definition: boringssl_prefix_symbols.h:2394
ssl_handshaker_process_bytes_from_peer
static tsi_result ssl_handshaker_process_bytes_from_peer(tsi_ssl_handshaker *impl, const unsigned char *bytes, size_t *bytes_size)
Definition: ssl_transport_security.cc:1504
tsi_ssl_server_handshaker_factory::key_logger
grpc_core::RefCountedPtr< TlsSessionKeyLogger > key_logger
Definition: ssl_transport_security.cc:112
build_alpn_protocol_name_list
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)
Definition: ssl_transport_security.cc:898
TSI_DONT_REQUEST_CLIENT_CERTIFICATE
@ TSI_DONT_REQUEST_CLIENT_CERTIFICATE
Definition: transport_security_interface.h:62
TSI_X509_CERTIFICATE_TYPE
#define TSI_X509_CERTIFICATE_TYPE
Definition: ssl_transport_security.h:34
tsi_ssl_client_handshaker_factory::base
tsi_ssl_handshaker_factory base
Definition: ssl_transport_security.cc:94
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
openssl_locking_cb
static void openssl_locking_cb(int mode, int type, const char *file, int line) GRPC_UNUSED
Definition: ssl_transport_security.cc:154
flag
uint32_t flag
Definition: ssl_versions.cc:162
tsi_ssl_server_handshaker_factory::ssl_contexts
SSL_CTX ** ssl_contexts
Definition: ssl_transport_security.cc:107
GPR_INFO
#define GPR_INFO
Definition: include/grpc/impl/codegen/log.h:56
X509_STORE_new
#define X509_STORE_new
Definition: boringssl_prefix_symbols.h:2545
ssl_handshaker_destroy
static void ssl_handshaker_destroy(tsi_handshaker *self)
Definition: ssl_transport_security.cc:1522
tsi_handshaker::vtable
const tsi_handshaker_vtable * vtable
Definition: transport_security.h:85
tsi_ssl_handshaker_result::network_io
BIO * network_io
Definition: ssl_transport_security.cc:127
SSL_CTX_set_tlsext_servername_callback
#define SSL_CTX_set_tlsext_servername_callback
Definition: boringssl_prefix_symbols.h:206
SSL_CTX_set_verify
#define SSL_CTX_set_verify
Definition: boringssl_prefix_symbols.h:218
GENERAL_NAME_st::type
int type
Definition: x509v3.h:184
EC_KEY_new_by_curve_name
#define EC_KEY_new_by_curve_name
Definition: boringssl_prefix_symbols.h:1356
gpr_mu_unlock
GPRAPI void gpr_mu_unlock(gpr_mu *mu)
tsi_create_ssl_server_handshaker_factory_with_options
tsi_result tsi_create_ssl_server_handshaker_factory_with_options(const tsi_ssl_server_handshaker_options *options, tsi_ssl_server_handshaker_factory **factory)
Definition: ssl_transport_security.cc:2179
X509_get_subject_name
#define X509_get_subject_name
Definition: boringssl_prefix_symbols.h:2672
tsi_ssl_handshaker_factory_vtable::destroy
tsi_ssl_handshaker_factory_destructor destroy
Definition: ssl_transport_security.h:389
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
SSL_is_init_finished
#define SSL_is_init_finished
Definition: boringssl_prefix_symbols.h:403
GEN_IPADD
#define GEN_IPADD
Definition: x509v3.h:181
SSL_CTX_set_ex_data
#define SSL_CTX_set_ex_data
Definition: boringssl_prefix_symbols.h:167
log.h
tsi_peer::properties
tsi_peer_property * properties
Definition: transport_security_interface.h:239
tsi_create_ssl_client_handshaker_factory
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)
Definition: ssl_transport_security.cc:1992
PEM_read_bio_X509_AUX
#define PEM_read_bio_X509_AUX
Definition: boringssl_prefix_symbols.h:1956
ERR_LIB_X509
@ ERR_LIB_X509
Definition: err.h:302
gpr_refn
GPRAPI void gpr_refn(gpr_refcount *r, int n)
Definition: sync.cc:99
peer_property_from_x509_subject
static tsi_result peer_property_from_x509_subject(X509 *cert, tsi_peer_property *property)
Definition: ssl_transport_security.cc:330
tsi_peer_property::value
struct tsi_peer_property::@48 value
GENERAL_NAME_st
Definition: x509v3.h:173
tsi::SslSessionLRUCache::Get
SslSessionPtr Get(const char *key)
Definition: ssl_session_cache.cc:117
AF_INET6
#define AF_INET6
Definition: ares_setup.h:208
ctx
Definition: benchmark-async.c:30
tsi_ssl_handshaker_result
Definition: ssl_transport_security.cc:124
TSI_TLS1_3
@ TSI_TLS1_3
Definition: transport_security_interface.h:91
NID_X9_62_prime256v1
#define NID_X9_62_prime256v1
Definition: nid.h:1914
X509_STORE_up_ref
#define X509_STORE_up_ref
Definition: boringssl_prefix_symbols.h:2563
absl::string_view::remove_suffix
ABSL_INTERNAL_STRING_VIEW_CXX14_CONSTEXPR void remove_suffix(size_type n)
Definition: abseil-cpp/absl/strings/string_view.h:354
SSL_CTX_set_options
#define SSL_CTX_set_options
Definition: boringssl_prefix_symbols.h:182
tsi_create_ssl_client_handshaker_factory_with_options
tsi_result tsi_create_ssl_client_handshaker_factory_with_options(const tsi_ssl_client_handshaker_options *options, tsi_ssl_client_handshaker_factory **factory)
Definition: ssl_transport_security.cc:2007
tsi_ssl_root_certs_store::store
X509_STORE * store
Definition: ssl_transport_security.cc:85
tsi_handshaker_vtable
Definition: transport_security.h:57
bio_st
Definition: bio.h:822
tsi_tracing_enabled
grpc_core::TraceFlag tsi_tracing_enabled(false, "tsi")
gpr_once
pthread_once_t gpr_once
Definition: impl/codegen/sync_posix.h:50
grpc_core::RefCountedPtr::get
T * get() const
Definition: ref_counted_ptr.h:146
TSI_SSL_ALPN_SELECTED_PROTOCOL
#define TSI_SSL_ALPN_SELECTED_PROTOCOL
Definition: ssl_transport_security.h:44
SSL_CB_HANDSHAKE_DONE
#define SSL_CB_HANDSHAKE_DONE
Definition: ssl.h:4292
pem_root_certs
static char * pem_root_certs
Definition: rb_channel_credentials.c:38
tsi_handshaker
Definition: transport_security.h:84
tsi::SslSessionLRUCache
Definition: ssl_session_cache.h:47
TSI_X509_SUBJECT_PEER_PROPERTY
#define TSI_X509_SUBJECT_PEER_PROPERTY
Definition: ssl_transport_security.h:37
SSL_get0_alpn_selected
#define SSL_get0_alpn_selected
Definition: boringssl_prefix_symbols.h:310
X509_V_FLAG_CRL_CHECK
#define X509_V_FLAG_CRL_CHECK
Definition: x509.h:2007
SSL_set_accept_state
#define SSL_set_accept_state
Definition: boringssl_prefix_symbols.h:450
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
X509_STORE_set_verify_cb
#define X509_STORE_set_verify_cb
Definition: boringssl_prefix_symbols.h:2562
tsi_ssl_pem_key_cert_pair
Definition: ssl_transport_security.h:101
TSI_X509_IP_PEER_PROPERTY
#define TSI_X509_IP_PEER_PROPERTY
Definition: ssl_transport_security.h:48
capacity
uint16_t capacity
Definition: protobuf/src/google/protobuf/descriptor.cc:948
X509_V_FLAG_PARTIAL_CHAIN
#define X509_V_FLAG_PARTIAL_CHAIN
Definition: x509.h:2042
SSL_CTX_get_ex_data
#define SSL_CTX_get_ex_data
Definition: boringssl_prefix_symbols.h:95
tls1.h
TSI_INTERNAL_ERROR
@ TSI_INTERNAL_ERROR
Definition: transport_security_interface.h:39
verify_cb
static int verify_cb(int ok, X509_STORE_CTX *ctx)
Definition: ssl_transport_security.cc:1973
absl::string_view::find
size_type find(string_view s, size_type pos=0) const noexcept
Definition: abseil-cpp/absl/strings/string_view.cc:81
X509_R_CERT_ALREADY_IN_HASH_TABLE
#define X509_R_CERT_ALREADY_IN_HASH_TABLE
Definition: x509.h:2382
GENERAL_NAME_st::uniformResourceIdentifier
ASN1_IA5STRING * uniformResourceIdentifier
Definition: x509v3.h:193
TSI_SECURITY_LEVEL_PEER_PROPERTY
#define TSI_SECURITY_LEVEL_PEER_PROPERTY
Definition: transport_security_interface.h:226
tsi_create_ssl_server_handshaker_factory
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)
Definition: ssl_transport_security.cc:2148
ssl_handshaker_result_extract_peer
static tsi_result ssl_handshaker_result_extract_peer(const tsi_handshaker_result *self, tsi_peer *peer)
Definition: ssl_transport_security.cc:1270
TSI_SIZE_AS_SIZE
#define TSI_SIZE_AS_SIZE(x)
Definition: ssl_types.h:39
SSL_ERROR_WANT_READ
#define SSL_ERROR_WANT_READ
Definition: ssl.h:494
SSL_set_session
#define SSL_set_session
Definition: boringssl_prefix_symbols.h:491
SSL_ERROR_SSL
#define SSL_ERROR_SSL
Definition: ssl.h:485
SSL_VERIFY_NONE
#define SSL_VERIFY_NONE
Definition: ssl.h:2373
ssl_handshaker_result_get_unused_bytes
static tsi_result ssl_handshaker_result_get_unused_bytes(const tsi_handshaker_result *self, const unsigned char **bytes, size_t *bytes_size)
Definition: ssl_transport_security.cc:1389
bio.h
tsi_ssl_client_handshaker_factory_unref
void tsi_ssl_client_handshaker_factory_unref(tsi_ssl_client_handshaker_factory *factory)
Definition: ssl_transport_security.cc:1783
tsi_peer_property::length
size_t length
Definition: transport_security_interface.h:234
SSL_CTX_set_client_CA_list
#define SSL_CTX_set_client_CA_list
Definition: boringssl_prefix_symbols.h:158
string.h
options
double_dict options[]
Definition: capstone_test.c:55
sk_X509_num
#define sk_X509_num
Definition: boringssl_prefix_symbols.h:587
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
tsi_ssl_client_handshaker_factory
Definition: ssl_transport_security.cc:93
ssl_server_handshaker_factory_servername_callback
static int ssl_server_handshaker_factory_servername_callback(SSL *ssl, int *, void *arg)
Definition: ssl_transport_security.cc:1892
tsi_ssl_handshaker_factory_ref
static tsi_ssl_handshaker_factory * tsi_ssl_handshaker_factory_ref(tsi_ssl_handshaker_factory *factory)
Definition: ssl_transport_security.cc:1217
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
tsi_ssl_session_cache_unref
void tsi_ssl_session_cache_unref(tsi_ssl_session_cache *cache)
Definition: ssl_transport_security.cc:1048
tsi_ssl_server_handshaker_factory::alpn_protocol_list_length
size_t alpn_protocol_list_length
Definition: ssl_transport_security.cc:111
useful.h
SSL_TLSEXT_ERR_OK
#define SSL_TLSEXT_ERR_OK
Definition: ssl.h:2755
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
tsi_ssl_frame_protector
Definition: ssl_transport_security.cc:131
SSL_CTX_sess_set_new_cb
#define SSL_CTX_sess_set_new_cb
Definition: boringssl_prefix_symbols.h:134
ssl_ctx_use_private_key
static tsi_result ssl_ctx_use_private_key(SSL_CTX *context, const char *pem_key, size_t pem_key_size)
Definition: ssl_transport_security.cc:738
error_ref_leak.err
err
Definition: error_ref_leak.py:35
SSL_ERROR_NONE
#define SSL_ERROR_NONE
Definition: ssl.h:481
CRYPTO_get_locking_callback
#define CRYPTO_get_locking_callback
Definition: boringssl_prefix_symbols.h:1168
SSL_CTX_set_session_cache_mode
#define SSL_CTX_set_session_cache_mode
Definition: boringssl_prefix_symbols.h:195
x509v3.h
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
SSL_set_bio
#define SSL_set_bio
Definition: boringssl_prefix_symbols.h:452
gpr_malloc
GPRAPI void * gpr_malloc(size_t size)
Definition: alloc.cc:29
TSI_FRAME_PROTECTOR_NORMAL
@ TSI_FRAME_PROTECTOR_NORMAL
Definition: transport_security_interface.h:73
status
absl::Status status
Definition: rls.cc:251
TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
@ TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
Definition: transport_security_interface.h:66
SSL_do_handshake
#define SSL_do_handshake
Definition: boringssl_prefix_symbols.h:297
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
GPR_ONCE_INIT
#define GPR_ONCE_INIT
Definition: impl/codegen/sync_posix.h:52
setup.name
name
Definition: setup.py:542
tsi_ssl_pem_key_cert_pair::cert_chain
const char * cert_chain
Definition: ssl_transport_security.h:108
tsi_ssl_handshaker_factory_unref
static void tsi_ssl_handshaker_factory_unref(tsi_ssl_handshaker_factory *factory)
Definition: ssl_transport_security.cc:1224
thd_id.h
BIO_write
#define BIO_write
Definition: boringssl_prefix_symbols.h:870
absl::string_view::back
constexpr const_reference back() const
Definition: abseil-cpp/absl/strings/string_view.h:325
ssl_types.h
SSL_CTX_add_extra_chain_cert
#define SSL_CTX_add_extra_chain_cert
Definition: boringssl_prefix_symbols.h:72
g_ssl_ctx_ex_factory_index
static int g_ssl_ctx_ex_factory_index
Definition: ssl_transport_security.cc:142
cipher_suites
static const char * cipher_suites
Definition: ssl_utils.cc:78
TSI_FAILED_PRECONDITION
@ TSI_FAILED_PRECONDITION
Definition: transport_security_interface.h:37
tsi_ssl_get_cert_chain_contents
tsi_result tsi_ssl_get_cert_chain_contents(STACK_OF(X509) *peer_chain, tsi_peer_property *property)
Definition: ssl_transport_security.cc:1246
grpc_security.h
ssl_transport_security.h
SSL_load_error_strings
#define SSL_load_error_strings
Definition: boringssl_prefix_symbols.h:409
BIO_read
#define BIO_read
Definition: boringssl_prefix_symbols.h:831
tsi_ssl_handshaker::outgoing_bytes_buffer
unsigned char * outgoing_bytes_buffer
Definition: ssl_transport_security.cc:120
TLSv1_2_method
#define TLSv1_2_method
Definition: boringssl_prefix_symbols.h:545
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
ssl_info_callback
static void ssl_info_callback(const SSL *ssl, int where, int ret)
Definition: ssl_transport_security.cc:232
X509_NAME_get_index_by_NID
#define X509_NAME_get_index_by_NID
Definition: boringssl_prefix_symbols.h:2384
ssl_ctx_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3404
GRPC_TRACE_FLAG_ENABLED
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: debug/trace.h:114
GENERAL_NAME_st::dNSName
ASN1_IA5STRING * dNSName
Definition: x509v3.h:189
grpc_core::pending
P< T > pending()
Definition: try_join_test.cc:50
X509_NAME_free
#define X509_NAME_free
Definition: boringssl_prefix_symbols.h:2381
T
#define T(upbtypeconst, upbtype, ctype, default_value)
asn1_string_st::data
unsigned char * data
Definition: asn1.h:546
gpr_refcount
Definition: impl/codegen/sync_generic.h:39
ERR_get_error
#define ERR_get_error
Definition: boringssl_prefix_symbols.h:1419
ssl_handshaker_next
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 *)
Definition: ssl_transport_security.cc:1585
PEM_read_bio_PrivateKey
EVP_PKEY * PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
Definition: pem_pkey.c:71
tsi_ssl_client_handshaker_factory::ssl_context
SSL_CTX * ssl_context
Definition: ssl_transport_security.cc:95
SSL_ERROR_WANT_ACCEPT
#define SSL_ERROR_WANT_ACCEPT
Definition: ssl.h:530
TSI_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY
@ TSI_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY
Definition: transport_security_interface.h:63
peer_property_from_x509_common_name
static tsi_result peer_property_from_x509_common_name(X509 *cert, tsi_peer_property *property)
Definition: ssl_transport_security.cc:307
SSL_CTX_set_max_proto_version
#define SSL_CTX_set_max_proto_version
Definition: boringssl_prefix_symbols.h:173
ssl_error_string
static const char * ssl_error_string(int error)
Definition: ssl_transport_security.cc:197
tsi_ssl_server_handshaker_options
Definition: ssl_transport_security.h:279
ssl_handshaker_result_create_frame_protector
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)
Definition: ssl_transport_security.cc:1344
tsi_ssl_handshaker_factory_destroy
static void tsi_ssl_handshaker_factory_destroy(tsi_ssl_handshaker_factory *factory)
Definition: ssl_transport_security.cc:1205
gpr_once_init
GPRAPI void gpr_once_init(gpr_once *once, void(*init_function)(void))
TSI_X509_URI_PEER_PROPERTY
#define TSI_X509_URI_PEER_PROPERTY
Definition: ssl_transport_security.h:46
gpr_zalloc
GPRAPI void * gpr_zalloc(size_t size)
Definition: alloc.cc:40
X509_free
#define X509_free
Definition: boringssl_prefix_symbols.h:2632
ssl_key_logging.h
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
OpenSSL_add_all_algorithms
#define OpenSSL_add_all_algorithms
Definition: boringssl_prefix_symbols.h:1903
GENERAL_NAME_st::iPAddress
ASN1_OCTET_STRING * iPAddress
Definition: x509v3.h:194
TSI_X509_DNS_PEER_PROPERTY
#define TSI_X509_DNS_PEER_PROPERTY
Definition: ssl_transport_security.h:45
TSI_OK
@ TSI_OK
Definition: transport_security_interface.h:32
TlsSessionKeyLogger
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger TlsSessionKeyLogger
Definition: ssl_transport_security.cc:80
tsi_ssl_server_handshaker_factory_destroy
static void tsi_ssl_server_handshaker_factory_destroy(tsi_ssl_handshaker_factory *factory)
Definition: ssl_transport_security.cc:1830
string_util.h
tsi_ssl_handshaker_factory_swap_vtable
const tsi_ssl_handshaker_factory_vtable * tsi_ssl_handshaker_factory_swap_vtable(tsi_ssl_handshaker_factory *factory, tsi_ssl_handshaker_factory_vtable *new_vtable)
Definition: ssl_transport_security.cc:2408
BIO_new_mem_buf
#define BIO_new_mem_buf
Definition: boringssl_prefix_symbols.h:820
X509_VERIFY_PARAM_set_flags
#define X509_VERIFY_PARAM_set_flags
Definition: boringssl_prefix_symbols.h:2599
SSL_CTX_free
#define SSL_CTX_free
Definition: boringssl_prefix_symbols.h:84
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
engine_name
static const char engine_name[]
Definition: engine_passthrough.cc:35
SSL_set_SSL_CTX
#define SSL_set_SSL_CTX
Definition: boringssl_prefix_symbols.h:449
sk_X509_NAME_pop_free
#define sk_X509_NAME_pop_free
Definition: boringssl_prefix_symbols.h:581
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
absl::string_view::front
constexpr const_reference front() const
Definition: abseil-cpp/absl/strings/string_view.h:318
GEN_EMAIL
#define GEN_EMAIL
Definition: x509v3.h:175
X509_VERIFY_PARAM_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:217
GEN_DNS
#define GEN_DNS
Definition: x509v3.h:176
BIO_new_bio_pair
#define BIO_new_bio_pair
Definition: boringssl_prefix_symbols.h:815
tsi_ssl_frame_protector::buffer_offset
size_t buffer_offset
Definition: ssl_transport_security.cc:137
PEM_read_bio_X509
#define PEM_read_bio_X509
Definition: boringssl_prefix_symbols.h:1955
SSL_OP_SINGLE_ECDH_USE
#define SSL_OP_SINGLE_ECDH_USE
Definition: ssl.h:4776
SSL_get_error
#define SSL_get_error
Definition: boringssl_prefix_symbols.h:340
gpr_thd_currentid
GPRAPI gpr_thd_id gpr_thd_currentid(void)
NID_commonName
#define NID_commonName
Definition: nid.h:148
X509_STORE_load_locations
#define X509_STORE_load_locations
Definition: boringssl_prefix_symbols.h:2544
ERR_GET_REASON
#define ERR_GET_REASON(packed_error)
Definition: err.h:171
evp_pkey_st
Definition: evp.h:1046
tsi_ssl_session_cache_ref
void tsi_ssl_session_cache_ref(tsi_ssl_session_cache *cache)
Definition: ssl_transport_security.cc:1043
SSL_CTX_new
#define SSL_CTX_new
Definition: boringssl_prefix_symbols.h:115
tsi_frame_protector_type
tsi_frame_protector_type
Definition: transport_security_interface.h:69
grpc_core::RefCountedPtr< tsi::SslSessionLRUCache >
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
tsi_client_certificate_request_type
tsi_client_certificate_request_type
Definition: transport_security_interface.h:60
tsi_ssl_handshaker_factory::vtable
const tsi_ssl_handshaker_factory_vtable * vtable
Definition: ssl_transport_security.cc:89
gpr_realloc
GPRAPI void * gpr_realloc(void *p, size_t size)
Definition: alloc.cc:56
ssl_protector_unprotect
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)
Definition: ssl_transport_security.cc:1144
STACK_OF
#define STACK_OF(type)
Definition: stack.h:125
tsi::SslSessionPtr
std::unique_ptr< SSL_SESSION, SslSessionDeleter > SslSessionPtr
Definition: ssl_session.h:46
absl::string_view::size
constexpr size_type size() const noexcept
Definition: abseil-cpp/absl/strings/string_view.h:277
do_ssl_write
static tsi_result do_ssl_write(SSL *ssl, unsigned char *unprotected_bytes, size_t unprotected_bytes_size)
Definition: ssl_transport_security.cc:569
asn1_string_st::length
int length
Definition: asn1.h:544
tsi_ssl_client_handshaker_factory_destroy
static void tsi_ssl_client_handshaker_factory_destroy(tsi_ssl_handshaker_factory *factory)
Definition: ssl_transport_security.cc:1789
tsi_ssl_peer_matches_name
int tsi_ssl_peer_matches_name(const tsi_peer *peer, absl::string_view name)
Definition: ssl_transport_security.cc:2368
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
SSL_get_peer_cert_chain
#define SSL_get_peer_cert_chain
Definition: boringssl_prefix_symbols.h:355
root
RefCountedPtr< grpc_tls_certificate_provider > root
Definition: xds_server_config_fetcher.cc:223
ssl_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3698
X509_NAME_get_entry
#define X509_NAME_get_entry
Definition: boringssl_prefix_symbols.h:2383
tsi_ssl_client_handshaker_factory::alpn_protocol_list_length
size_t alpn_protocol_list_length
Definition: ssl_transport_security.cc:97
TSI_TLS1_2
@ TSI_TLS1_2
Definition: transport_security_interface.h:90
BIO_s_mem
#define BIO_s_mem
Definition: boringssl_prefix_symbols.h:839
TSI_X509_PEM_CERT_PROPERTY
#define TSI_X509_PEM_CERT_PROPERTY
Definition: ssl_transport_security.h:42
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
gpr_mu_init
GPRAPI void gpr_mu_init(gpr_mu *mu)
add_pem_certificate
static tsi_result add_pem_certificate(X509 *cert, tsi_peer_property *property)
Definition: ssl_transport_security.cc:354
SSL_CTX_set_next_protos_advertised_cb
#define SSL_CTX_set_next_protos_advertised_cb
Definition: boringssl_prefix_symbols.h:180
tsi_ssl_server_handshaker_factory::ssl_context_count
size_t ssl_context_count
Definition: ssl_transport_security.cc:109
tsi_ssl_handshaker::factory_ref
tsi_ssl_handshaker_factory * factory_ref
Definition: ssl_transport_security.cc:122
openssl_thread_id_cb
static unsigned long openssl_thread_id_cb(void) GRPC_UNUSED
Definition: ssl_transport_security.cc:162
key_id
const CBS size_t uint32_t key_id
Definition: third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h:107
tsi_ssl_frame_protector::ssl
SSL * ssl
Definition: ssl_transport_security.cc:133
GRPC_UNUSED
#define GRPC_UNUSED
Definition: impl/codegen/port_platform.h:606
SSL_session_reused
#define SSL_session_reused
Definition: boringssl_prefix_symbols.h:433
X509_STORE_add_cert
#define X509_STORE_add_cert
Definition: boringssl_prefix_symbols.h:2524
BIO_should_retry
#define BIO_should_retry
Definition: boringssl_prefix_symbols.h:861
SSL_get_rbio
#define SSL_get_rbio
Definition: boringssl_prefix_symbols.h:366
bytes_read
static size_t bytes_read
Definition: test-ipc-heavy-traffic-deadlock-bug.c:47
tsi_tls_version
tsi_tls_version
Definition: transport_security_interface.h:89
tsi_handshaker_on_next_done_cb
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)
Definition: transport_security_interface.h:462
log_ssl_error_stack
static void log_ssl_error_stack(void)
Definition: ssl_transport_security.cc:526
EVP_PKEY_free
#define EVP_PKEY_free
Definition: boringssl_prefix_symbols.h:1625
kSslEnginePrefix
static const char kSslEnginePrefix[]
Definition: ssl_transport_security.cc:145
ERR_GET_LIB
#define ERR_GET_LIB(packed_error)
Definition: err.h:166
CRYPTO_set_id_callback
#define CRYPTO_set_id_callback
Definition: boringssl_prefix_symbols.h:1197
GENERAL_NAME_st::rfc822Name
ASN1_IA5STRING * rfc822Name
Definition: x509v3.h:188
tsi_result
tsi_result
Definition: transport_security_interface.h:31
tsi_ssl_handshaker::result
tsi_result result
Definition: ssl_transport_security.cc:119
absl::EqualsIgnoreCase
ABSL_NAMESPACE_BEGIN bool EqualsIgnoreCase(absl::string_view piece1, absl::string_view piece2) noexcept
Definition: abseil-cpp/absl/strings/match.cc:22
X509_NAME_ENTRY_get_data
#define X509_NAME_ENTRY_get_data
Definition: boringssl_prefix_symbols.h:2364
SSL_TLSEXT_ERR_NOACK
#define SSL_TLSEXT_ERR_NOACK
Definition: ssl.h:2758
handshaker_result_vtable
static const tsi_handshaker_result_vtable handshaker_result_vtable
Definition: ssl_transport_security.cc:1408
tsi_ssl_frame_protector::buffer
unsigned char * buffer
Definition: ssl_transport_security.cc:135
ssl_session_cache.h
err.h
kSslSessionIdContext
static const unsigned char kSslSessionIdContext[]
Definition: ssl_transport_security.cc:143
PEM_write_bio_X509
#define PEM_write_bio_X509
Definition: boringssl_prefix_symbols.h:1998
crypto.h
tsi_ssl_handshaker_factory_init
static void tsi_ssl_handshaker_factory_init(tsi_ssl_handshaker_factory *factory)
Definition: ssl_transport_security.cc:1237
X509_V_FLAG_TRUSTED_FIRST
#define X509_V_FLAG_TRUSTED_FIRST
Definition: x509.h:2033
arg
Definition: cmdline.cc:40
x509_store_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:270
SSL_CTX_set_keylog_callback
#define SSL_CTX_set_keylog_callback
Definition: boringssl_prefix_symbols.h:171
client_handshaker_factory_vtable
static tsi_ssl_handshaker_factory_vtable client_handshaker_factory_vtable
Definition: ssl_transport_security.cc:1989
tsi_ssl_handshaker_result::ssl
SSL * ssl
Definition: ssl_transport_security.cc:126
SSL_VERIFY_PEER
#define SSL_VERIFY_PEER
Definition: ssl.h:2379
gpr_mu_lock
GPRAPI void gpr_mu_lock(gpr_mu *mu)
tsi_peer_property::data
char * data
Definition: transport_security_interface.h:233
tsi_ssl_server_handshaker_factory_create_handshaker
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)
Definition: ssl_transport_security.cc:1813
SSL_set_tlsext_host_name
#define SSL_set_tlsext_host_name
Definition: boringssl_prefix_symbols.h:501
SSL_get0_next_proto_negotiated
#define SSL_get0_next_proto_negotiated
Definition: boringssl_prefix_symbols.h:315
ENGINE_free
#define ENGINE_free
Definition: boringssl_prefix_symbols.h:1402
tsi_ssl_frame_protector::network_io
BIO * network_io
Definition: ssl_transport_security.cc:134
NullVerifyCallback
static int NullVerifyCallback(int, X509_STORE_CTX *)
Definition: ssl_transport_security.cc:939
tsi_ssl_handshaker::ssl
SSL * ssl
Definition: ssl_transport_security.cc:117
TSI_DRAIN_BUFFER
@ TSI_DRAIN_BUFFER
Definition: transport_security_interface.h:48
populate_ssl_context
static tsi_result populate_ssl_context(SSL_CTX *context, const tsi_ssl_pem_key_cert_pair *key_cert_pair, const char *cipher_list)
Definition: ssl_transport_security.cc:836
BIO_new
#define BIO_new
Definition: boringssl_prefix_symbols.h:814
uintptr_t
_W64 unsigned int uintptr_t
Definition: stdint-msvc2008.h:119
select_protocol_list
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)
Definition: ssl_transport_security.cc:1744
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
add_subject_alt_names_properties_to_peer
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)
Definition: ssl_transport_security.cc:373
do_ssl_read
static tsi_result do_ssl_read(SSL *ssl, unsigned char *unprotected_bytes, size_t *unprotected_bytes_size)
Definition: ssl_transport_security.cc:536
ERR_error_string_n
#define ERR_error_string_n
Definition: boringssl_prefix_symbols.h:1416
SSL_SESS_CACHE_CLIENT
#define SSL_SESS_CACHE_CLIENT
Definition: ssl.h:1937
tsi_ssl_server_handshaker_factory::ssl_context_x509_subject_names
tsi_peer * ssl_context_x509_subject_names
Definition: ssl_transport_security.cc:108
TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND
#define TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND
Definition: ssl_transport_security.cc:65
tsi_ssl_frame_protector::base
tsi_frame_protector base
Definition: ssl_transport_security.cc:132
SSL_CTX_get_ex_new_index
#define SSL_CTX_get_ex_new_index
Definition: boringssl_prefix_symbols.h:96
tsi_ssl_handshaker_result::base
tsi_handshaker_result base
Definition: ssl_transport_security.cc:125
SSL_CTX_set_tlsext_servername_arg
#define SSL_CTX_set_tlsext_servername_arg
Definition: boringssl_prefix_symbols.h:205
TSI_UNIMPLEMENTED
@ TSI_UNIMPLEMENTED
Definition: transport_security_interface.h:38
EC_KEY_free
#define EC_KEY_free
Definition: boringssl_prefix_symbols.h:1341
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
X509_name_entry_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:88
tsi_ssl_server_handshaker_factory::alpn_protocol_list
unsigned char * alpn_protocol_list
Definition: ssl_transport_security.cc:110
create_tsi_ssl_handshaker
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)
Definition: ssl_transport_security.cc:1670
ssl_handshaker_get_bytes_to_send_to_peer
static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_ssl_handshaker *impl, unsigned char *bytes, size_t *bytes_size)
Definition: ssl_transport_security.cc:1441
tsi_ssl_handshaker_factory::refcount
gpr_refcount refcount
Definition: ssl_transport_security.cc:90
ssl.h
tsi_ssl_server_handshaker_factory::base
tsi_ssl_handshaker_factory base
Definition: ssl_transport_security.cc:106
looks_like_ip_address
static int looks_like_ip_address(absl::string_view name)
Definition: ssl_transport_security.cc:245
tsi_ssl_handshaker::outgoing_bytes_buffer_size
size_t outgoing_bytes_buffer_size
Definition: ssl_transport_security.cc:121
tsi_ssl_handshaker_factory_vtable
Definition: ssl_transport_security.h:388
ec_key_st
Definition: third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h:723
SSL_set_info_callback
#define SSL_set_info_callback
Definition: boringssl_prefix_symbols.h:465
tsi_peer_property
Definition: transport_security_interface.h:230
TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY
@ TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY
Definition: transport_security_interface.h:65
SSL_ERROR_WANT_WRITE
#define SSL_ERROR_WANT_WRITE
Definition: ssl.h:499
details
static grpc_slice details
Definition: test/core/fling/client.cc:46
g_init_openssl_once
static gpr_once g_init_openssl_once
Definition: ssl_transport_security.cc:141
OPENSSL_init_ssl
#define OPENSSL_init_ssl
Definition: boringssl_prefix_symbols.h:38
ssl_ctx_use_certificate_chain
static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX *context, const char *pem_cert_chain, size_t pem_cert_chain_size)
Definition: ssl_transport_security.cc:591
tsi_ssl_server_handshaker_factory
Definition: ssl_transport_security.cc:102
GENERAL_NAME_free
#define GENERAL_NAME_free
Definition: boringssl_prefix_symbols.h:1769
SSL_CTX_set_cipher_list
#define SSL_CTX_set_cipher_list
Definition: boringssl_prefix_symbols.h:157
SSL_free
#define SSL_free
Definition: boringssl_prefix_symbols.h:308
tsi_ssl_pem_key_cert_pair::private_key
const char * private_key
Definition: ssl_transport_security.h:104
BIO_free
#define BIO_free
Definition: boringssl_prefix_symbols.h:787
SSL_state_string
#define SSL_state_string
Definition: boringssl_prefix_symbols.h:517
TLS1_3_VERSION
#define TLS1_3_VERSION
Definition: ssl.h:653
ssl_session_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3787
handshaker_vtable
static const tsi_handshaker_vtable handshaker_vtable
Definition: ssl_transport_security.cc:1644
TSI_DATA_CORRUPTED
@ TSI_DATA_CORRUPTED
Definition: transport_security_interface.h:40
ASN1_STRING_to_UTF8
#define ASN1_STRING_to_UTF8
Definition: boringssl_prefix_symbols.h:693
TSI_SSL_SESSION_REUSED_PEER_PROPERTY
#define TSI_SSL_SESSION_REUSED_PEER_PROPERTY
Definition: ssl_transport_security.h:41
tsi_peer
Definition: transport_security_interface.h:238
contents
string_view contents
Definition: elf.cc:597
TLS1_2_VERSION
#define TLS1_2_VERSION
Definition: ssl.h:652
GPR_ARRAY_SIZE
#define GPR_ARRAY_SIZE(array)
Definition: useful.h:129
transport_security.h
tsi_frame_protector_vtable
Definition: transport_security.h:34
TLS_method
#define TLS_method
Definition: boringssl_prefix_symbols.h:538
tsi::SslSessionLRUCache::Put
void Put(const char *key, SslSessionPtr session)
Definition: ssl_session_cache.cc:95
TSI_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY
@ TSI_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY
Definition: transport_security_interface.h:64
TSI_INCOMPLETE_DATA
@ TSI_INCOMPLETE_DATA
Definition: transport_security_interface.h:36
tsi_ssl_server_handshaker_factory_unref
void tsi_ssl_server_handshaker_factory_unref(tsi_ssl_server_handshaker_factory *factory)
Definition: ssl_transport_security.cc:1824
server_handshaker_factory_npn_advertised_callback
static int server_handshaker_factory_npn_advertised_callback(SSL *, const unsigned char **out, unsigned int *outlen, void *arg)
Definition: ssl_transport_security.cc:1926
x509_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:139
GENERAL_NAME_st::d
union GENERAL_NAME_st::@370 d
bytes
uint8 bytes[10]
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:153
SSL_CTX_set_tmp_ecdh
#define SSL_CTX_set_tmp_ecdh
Definition: boringssl_prefix_symbols.h:214
server_handshaker_factory_new_session_callback
static int server_handshaker_factory_new_session_callback(SSL *ssl, SSL_SESSION *session)
Definition: ssl_transport_security.cc:1942
tsi_ssl_session_cache
struct tsi_ssl_session_cache tsi_ssl_session_cache
Definition: ssl_transport_security.h:68
gpr_mu
pthread_mutex_t gpr_mu
Definition: impl/codegen/sync_posix.h:47
CRYPTO_num_locks
#define CRYPTO_num_locks
Definition: boringssl_prefix_symbols.h:1180
absl::string_view::remove_prefix
ABSL_INTERNAL_STRING_VIEW_CXX14_CONSTEXPR void remove_prefix(size_type n)
Definition: abseil-cpp/absl/strings/string_view.h:344
SSL_CTX_set_cert_store
#define SSL_CTX_set_cert_store
Definition: boringssl_prefix_symbols.h:154
CRYPTO_LOCK
#define CRYPTO_LOCK
Definition: thread.h:112
tsi_ssl_root_certs_store
Definition: ssl_transport_security.cc:84
ssl_handshaker_get_result
static tsi_result ssl_handshaker_get_result(tsi_ssl_handshaker *impl)
Definition: ssl_transport_security.cc:1463
tsi_result_to_string
const char * tsi_result_to_string(tsi_result result)
Definition: transport_security.cc:35
SSL_ERROR_ZERO_RETURN
#define SSL_ERROR_ZERO_RETURN
Definition: ssl.h:518
X509_STORE_get0_param
#define X509_STORE_get0_param
Definition: boringssl_prefix_symbols.h:2529
TSI_SSL_MAX_PROTECTION_OVERHEAD
#define TSI_SSL_MAX_PROTECTION_OVERHEAD
Definition: ssl_transport_security.cc:78
init_openssl
static void init_openssl(void)
Definition: ssl_transport_security.cc:167
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
ssl_get_x509_common_name
static tsi_result ssl_get_x509_common_name(X509 *cert, unsigned char **utf8, size_t *utf8_size)
Definition: ssl_transport_security.cc:269
alloc.h
ssl_protector_protect_flush
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)
Definition: ssl_transport_security.cc:1110
private_key
Definition: hrss.c:1885
sk_X509_value
#define sk_X509_value
Definition: boringssl_prefix_symbols.h:590
SSL_VERIFY_FAIL_IF_NO_PEER_CERT
#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT
Definition: ssl.h:2384
tsi_ssl_handshaker
Definition: ssl_transport_security.cc:115
tsi_ssl_extract_x509_subject_names_from_pem_cert
tsi_result tsi_ssl_extract_x509_subject_names_from_pem_cert(const char *pem_cert, tsi_peer *peer)
Definition: ssl_transport_security.cc:877
does_entry_match_name
static int does_entry_match_name(absl::string_view entry, absl::string_view name)
Definition: ssl_transport_security.cc:1851
tsi_ssl_handshaker_result::unused_bytes
unsigned char * unused_bytes
Definition: ssl_transport_security.cc:128
X509_STORE_set_flags
#define X509_STORE_set_flags
Definition: boringssl_prefix_symbols.h:2554
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger
Definition: ssl_key_logging.h:46
SSL_ERROR_WANT_CONNECT
#define SSL_ERROR_WANT_CONNECT
Definition: ssl.h:523
ssl_protector_protect
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)
Definition: ssl_transport_security.cc:1054
TSI_SSL_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE
#define TSI_SSL_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE
Definition: ssl_transport_security.cc:67
regen-readme.line
line
Definition: regen-readme.py:30
BIO_get_mem_data
#define BIO_get_mem_data
Definition: boringssl_prefix_symbols.h:793
TSI_INVALID_ARGUMENT
@ TSI_INVALID_ARGUMENT
Definition: transport_security_interface.h:34
tsi_frame_protector::vtable
const tsi_frame_protector_vtable * vtable
Definition: transport_security.h:52
ok
bool ok
Definition: async_end2end_test.cc:197
arg
struct arg arg
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY
#define TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY
Definition: ssl_transport_security.h:38
sk_X509_NAME_push
#define sk_X509_NAME_push
Definition: boringssl_prefix_symbols.h:582
ERR_clear_error
#define ERR_clear_error
Definition: boringssl_prefix_symbols.h:1413
TSI_SSL_MAX_PROTECTED_FRAME_SIZE_LOWER_BOUND
#define TSI_SSL_MAX_PROTECTED_FRAME_SIZE_LOWER_BOUND
Definition: ssl_transport_security.cc:66
TSI_OUT_OF_RESOURCES
@ TSI_OUT_OF_RESOURCES
Definition: transport_security_interface.h:44
GEN_URI
#define GEN_URI
Definition: x509v3.h:180
frame_protector_vtable
static const tsi_frame_protector_vtable frame_protector_vtable
Definition: ssl_transport_security.cc:1196
ssl_protector_destroy
static void ssl_protector_destroy(tsi_frame_protector *self)
Definition: ssl_transport_security.cc:1187
tsi_ssl_handshaker_result::unused_bytes_size
size_t unused_bytes_size
Definition: ssl_transport_security.cc:129
NID_subject_alt_name
#define NID_subject_alt_name
Definition: nid.h:474
ssl_ctx_use_engine_private_key
static tsi_result ssl_ctx_use_engine_private_key(SSL_CTX *context, const char *pem_key, size_t pem_key_size)
Definition: ssl_transport_security.cc:637
SSL_CTX_use_certificate
#define SSL_CTX_use_certificate
Definition: boringssl_prefix_symbols.h:228
sk_X509_NAME_new_null
#define sk_X509_NAME_new_null
Definition: boringssl_prefix_symbols.h:580
tsi_create_ssl_server_handshaker_factory_ex
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)
Definition: ssl_transport_security.cc:2161
ssl_ctx_load_verification_certs
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)
Definition: ssl_transport_security.cc:822
X509_get_ext_d2i
#define X509_get_ext_d2i
Definition: boringssl_prefix_symbols.h:2661
x509_store_load_certs
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)
Definition: ssl_transport_security.cc:753
SSL_CTX_set_session_id_context
#define SSL_CTX_set_session_id_context
Definition: boringssl_prefix_symbols.h:196
TSI_PROTOCOL_FAILURE
@ TSI_PROTOCOL_FAILURE
Definition: transport_security_interface.h:42
X509_NAME_dup
OPENSSL_EXPORT X509_NAME * X509_NAME_dup(X509_NAME *xn)
ssl_handshaker_write_output_buffer
static tsi_result ssl_handshaker_write_output_buffer(tsi_handshaker *self, size_t *bytes_written)
Definition: ssl_transport_security.cc:1565
SSL_CTX_set_alpn_protos
#define SSL_CTX_set_alpn_protos
Definition: boringssl_prefix_symbols.h:151
tsi_handshaker_result
Definition: transport_security.h:121
server_handshaker_factory_alpn_callback
static int server_handshaker_factory_alpn_callback(SSL *, const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
Definition: ssl_transport_security.cc:1915
peer_from_x509
static tsi_result peer_from_x509(X509 *cert, int include_certificate_type, tsi_peer *peer)
Definition: ssl_transport_security.cc:456
ssl_bytes_remaining
static tsi_result ssl_bytes_remaining(tsi_ssl_handshaker *impl, unsigned char **bytes_remaining, size_t *bytes_remaining_size)
Definition: ssl_transport_security.cc:1533
engine.h
SSL_new
#define SSL_new
Definition: boringssl_prefix_symbols.h:414
SSL_CTX_use_PrivateKey
#define SSL_CTX_use_PrivateKey
Definition: boringssl_prefix_symbols.h:222
engine_st
Definition: engine.c:29
tsi_ssl_client_handshaker_factory::key_logger
grpc_core::RefCountedPtr< TlsSessionKeyLogger > key_logger
Definition: ssl_transport_security.cc:99
GPR_DEBUG
#define GPR_DEBUG
Definition: include/grpc/impl/codegen/log.h:55
bytes_written
static size_t bytes_written
Definition: test-ipc-heavy-traffic-deadlock-bug.c:46
handshaker_factory_vtable
static tsi_ssl_handshaker_factory_vtable handshaker_factory_vtable
Definition: ssl_transport_security.cc:1233
tsi_ssl_frame_protector::buffer_size
size_t buffer_size
Definition: ssl_transport_security.cc:136
tsi_ssl_client_handshaker_options
Definition: ssl_transport_security.h:137
absl::string_view::empty
constexpr bool empty() const noexcept
Definition: abseil-cpp/absl/strings/string_view.h:292
X509_STORE_CTX_get_error
#define X509_STORE_CTX_get_error
Definition: boringssl_prefix_symbols.h:2501
TSI_PRIVACY_AND_INTEGRITY
@ TSI_PRIVACY_AND_INTEGRITY
Definition: transport_security_interface.h:56
SSL_CTX_check_private_key
#define SSL_CTX_check_private_key
Definition: boringssl_prefix_symbols.h:74
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
SSL_get_SSL_CTX
#define SSL_get_SSL_CTX
Definition: boringssl_prefix_symbols.h:326
tsi_ssl_handshaker::base
tsi_handshaker base
Definition: ssl_transport_security.cc:116
tsi_set_min_and_max_tls_versions
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)
Definition: ssl_transport_security.cc:946
ssl_ctx_use_pem_private_key
static tsi_result ssl_ctx_use_pem_private_key(SSL_CTX *context, const char *pem_key, size_t pem_key_size)
Definition: ssl_transport_security.cc:711
SSL_ERROR_WANT_X509_LOOKUP
#define SSL_ERROR_WANT_X509_LOOKUP
Definition: ssl.h:507
CRYPTO_set_locking_callback
#define CRYPTO_set_locking_callback
Definition: boringssl_prefix_symbols.h:1198
SSL_CTX_set_next_proto_select_cb
#define SSL_CTX_set_next_proto_select_cb
Definition: boringssl_prefix_symbols.h:179
SSL_set_connect_state
#define SSL_set_connect_state
Definition: boringssl_prefix_symbols.h:457
g_openssl_mutexes
static gpr_mu * g_openssl_mutexes
Definition: ssl_transport_security.cc:149
gpr_ref_init
GPRAPI void gpr_ref_init(gpr_refcount *r, int n)
Definition: sync.cc:86
tsi_frame_protector
Definition: transport_security.h:51
SSL_write
#define SSL_write
Definition: boringssl_prefix_symbols.h:533
tsi_ssl_root_certs_store_create
tsi_ssl_root_certs_store * tsi_ssl_root_certs_store_create(const char *pem_roots)
Definition: ssl_transport_security.cc:1000
SSL_library_init
#define SSL_library_init
Definition: boringssl_prefix_symbols.h:407
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
tsi_ssl_root_certs_store_destroy
void tsi_ssl_root_certs_store_destroy(tsi_ssl_root_certs_store *self)
Definition: ssl_transport_security.cc:1029
TSI_CERTIFICATE_TYPE_PEER_PROPERTY
#define TSI_CERTIFICATE_TYPE_PEER_PROPERTY
Definition: transport_security_interface.h:223
gpr_unref
GPRAPI int gpr_unref(gpr_refcount *r)
Definition: sync.cc:103
absl::string_view::npos
static constexpr size_type npos
Definition: abseil-cpp/absl/strings/string_view.h:182
SSL_CTX_set_min_proto_version
#define SSL_CTX_set_min_proto_version
Definition: boringssl_prefix_symbols.h:175
tsi_handshaker_result_vtable
Definition: transport_security.h:100
ssl_handshaker_do_handshake
static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker *impl)
Definition: ssl_transport_security.cc:1471
SSL_get_servername
#define SSL_get_servername
Definition: boringssl_prefix_symbols.h:374
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
ssl_log_where_info
static void ssl_log_where_info(const SSL *ssl, int where, int flag, const char *msg)
Definition: ssl_transport_security.cc:223
SSL_get_peer_certificate
#define SSL_get_peer_certificate
Definition: boringssl_prefix_symbols.h:356
self
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:543
testing::Ref
internal::RefMatcher< T & > Ref(T &x)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8628
ssl_handshaker_result_get_frame_protector_type
static tsi_result ssl_handshaker_result_get_frame_protector_type(const tsi_handshaker_result *, tsi_frame_protector_type *frame_protector_type)
Definition: ssl_transport_security.cc:1337
TSI_X509_PEM_CERT_CHAIN_PROPERTY
#define TSI_X509_PEM_CERT_CHAIN_PROPERTY
Definition: ssl_transport_security.h:43
SSL_state_string_long
#define SSL_state_string_long
Definition: boringssl_prefix_symbols.h:518
client_handshaker_factory_npn_callback
static int client_handshaker_factory_npn_callback(SSL *, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
Definition: ssl_transport_security.cc:1801
tsi::SslSessionLRUCache::Create
static grpc_core::RefCountedPtr< SslSessionLRUCache > Create(size_t capacity)
Create new LRU cache with the given capacity.
Definition: ssl_session_cache.h:50
X509_STORE_free
#define X509_STORE_free
Definition: boringssl_prefix_symbols.h:2527
BIO_pending
#define BIO_pending
Definition: boringssl_prefix_symbols.h:825
OPENSSL_free
#define OPENSSL_free
Definition: boringssl_prefix_symbols.h:1869
sync.h
tsi_ssl_handshaker::network_io
BIO * network_io
Definition: ssl_transport_security.cc:118
ssl_keylogging_callback
static void ssl_keylogging_callback(const SSL *ssl, const char *info)
Definition: ssl_transport_security.cc:1963
tsi_ssl_handshaker_factory
Definition: ssl_transport_security.cc:88
TSI_X509_EMAIL_PEER_PROPERTY
#define TSI_X509_EMAIL_PEER_PROPERTY
Definition: ssl_transport_security.h:47
SSL_CTX_set_alpn_select_cb
#define SSL_CTX_set_alpn_select_cb
Definition: boringssl_prefix_symbols.h:152
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY
#define TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY
Definition: ssl_transport_security.h:39
tsi_peer_destruct
void tsi_peer_destruct(tsi_peer *self)
Definition: transport_security.cc:320
SSL_CB_LOOP
#define SSL_CB_LOOP
Definition: ssl.h:4280
TLSEXT_NAMETYPE_host_name
#define TLSEXT_NAMETYPE_host_name
Definition: ssl.h:2721
ssl_handshaker_result_create
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)
Definition: ssl_transport_security.cc:1417
X509_name_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:95
x509_store_ctx_st
Definition: third_party/boringssl-with-bazel/src/crypto/x509/internal.h:312
tsi_ssl_client_handshaker_factory::alpn_protocol_list
unsigned char * alpn_protocol_list
Definition: ssl_transport_security.cc:96
X509_V_ERR_UNABLE_TO_GET_CRL
#define X509_V_ERR_UNABLE_TO_GET_CRL
Definition: x509.h:1922
tsi_construct_string_peer_property
tsi_result tsi_construct_string_peer_property(const char *name, const char *value, size_t value_length, tsi_peer_property *property)
Definition: transport_security.cc:346
tsi_ssl_client_handshaker_factory_create_handshaker
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)
Definition: ssl_transport_security.cc:1774
asn1_string_st
Definition: asn1.h:543
SSL_CTX_get_cert_store
#define SSL_CTX_get_cert_store
Definition: boringssl_prefix_symbols.h:90
tsi_ssl_handshaker_resume_session
static void tsi_ssl_handshaker_resume_session(SSL *ssl, tsi::SslSessionLRUCache *session_cache)
Definition: ssl_transport_security.cc:1657
SSL_read
#define SSL_read
Definition: boringssl_prefix_symbols.h:424
SSL_CTX_set_tlsext_ticket_keys
#define SSL_CTX_set_tlsext_ticket_keys
Definition: boringssl_prefix_symbols.h:210
server_handshaker_factory_vtable
static tsi_ssl_handshaker_factory_vtable server_handshaker_factory_vtable
Definition: ssl_transport_security.cc:2145
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
tsi_construct_string_peer_property_from_cstring
tsi_result tsi_construct_string_peer_property_from_cstring(const char *name, const char *value, tsi_peer_property *property)
Definition: transport_security.cc:340
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
tsi_ssl_client_handshaker_factory::session_cache
grpc_core::RefCountedPtr< tsi::SslSessionLRUCache > session_cache
Definition: ssl_transport_security.cc:98
tsi_construct_peer
tsi_result tsi_construct_peer(size_t property_count, tsi_peer *peer)
Definition: transport_security.cc:359
tsi_peer::property_count
size_t property_count
Definition: transport_security_interface.h:240
TSI_NOT_FOUND
@ TSI_NOT_FOUND
Definition: transport_security_interface.h:41
ssl_handshaker_result_destroy
static void ssl_handshaker_result_destroy(tsi_handshaker_result *self)
Definition: ssl_transport_security.cc:1399
run_interop_tests.server_name
server_name
Definition: run_interop_tests.py:1510
TSI_HANDSHAKE_IN_PROGRESS
@ TSI_HANDSHAKE_IN_PROGRESS
Definition: transport_security_interface.h:43
tsi_ssl_session_cache_create_lru
tsi_ssl_session_cache * tsi_ssl_session_cache_create_lru(size_t capacity)
Definition: ssl_transport_security.cc:1037
x509.h
port_platform.h
SSL_ERROR_SYSCALL
#define SSL_ERROR_SYSCALL
Definition: ssl.h:514


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