489 {
491 if (in_handshake_) {
492 FATAL(
"Connect called twice on the same _SecureFilter.");
493 }
494
495 int status;
497 BIO* ssl_side;
498 status = BIO_new_bio_pair(&ssl_side, kInternalBIOSize, &socket_side_,
499 kInternalBIOSize);
501 ssl_);
502
503 ASSERT(context !=
nullptr);
504 ASSERT(context->context() !=
nullptr);
505 ssl_ = SSL_new(context->context());
506 SSL_set_bio(ssl_, ssl_side, ssl_side);
507 SSL_set_mode(ssl_, SSL_MODE_AUTO_RETRY);
509
510 if (context->allow_tls_renegotiation()) {
511 SSL_set_renegotiate_mode(ssl_, ssl_renegotiate_freely);
512 }
513 context->RegisterCallbacks(ssl_);
515
517 context->GetTrustEvaluateHandler();
518 if (trust_evaluate_handler != nullptr) {
520 "SSLCertContextTrustEvaluate", trust_evaluate_handler,
521 false);
522 }
523 if (is_server_) {
524 int certificate_mode =
525 request_client_certificate ? SSL_VERIFY_PEER : SSL_VERIFY_NONE;
526 if (require_client_certificate) {
527 certificate_mode |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
528 }
529 SSL_set_verify(ssl_, certificate_mode, nullptr);
530 } else {
532 status = SSL_set_tlsext_host_name(ssl_,
hostname);
534 "Set SNI host name", ssl_);
535
536
537 X509_VERIFY_PARAM* certificate_checking_parameters = SSL_get0_param(ssl_);
539 X509_VERIFY_PARAM_set_flags(
540 certificate_checking_parameters,
541 X509_V_FLAG_PARTIAL_CHAIN | X509_V_FLAG_TRUSTED_FIRST);
542 X509_VERIFY_PARAM_set_hostflags(certificate_checking_parameters, 0);
543
544
545
547 status = X509_VERIFY_PARAM_set1_ip_asc(certificate_checking_parameters,
548 hostname_);
549 } else {
550 status = X509_VERIFY_PARAM_set1_host(certificate_checking_parameters,
551 hostname_, strlen(hostname_));
552 }
554 status, "TlsException", "Set hostname for certificate checking", ssl_);
555 }
556
557 if (is_server_) {
558 status = SSL_accept(ssl_);
561 }
562 if (status != 1) {
563
564 error = SSL_get_error(ssl_, status);
567 }
568 }
569 } else {
570 status = SSL_connect(ssl_);
573 }
574 if (status != 1) {
575
576 error = SSL_get_error(ssl_, status);
579 }
580 }
581 }
582
583
584
586}
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
static void SetAlpnProtocolList(Dart_Handle protocols_handle, SSL *ssl, SSLCertContext *context, bool is_server)
int Handshake(Dart_Port reply_port)
static int ssl_cert_context_index
static int filter_ssl_index
static void CheckStatusSSL(int status, const char *type, const char *message, const SSL *ssl)
static bool IsValidAddress(const char *address)
const uint8_t uint32_t uint32_t GError ** error
const bool SSL_LOG_STATUS
void(* TrustEvaluateHandlerFunc)(Dart_Port dest_port_id, Dart_CObject *message)
DART_EXPORT Dart_Port Dart_NewNativePort(const char *name, Dart_NativeMessageHandler handler, bool handle_concurrently)