| 1044 | } |
| 1045 | |
| 1046 | int |
| 1047 | SSLNetVConnection::sslStartHandShake(int event, int &err) |
| 1048 | { |
| 1049 | if (TSSystemState::is_ssl_handshaking_stopped()) { |
| 1050 | Dbg(dbg_ctl_ssl, "Stopping handshake due to server shutting down."); |
| 1051 | return EVENT_ERROR; |
| 1052 | } |
| 1053 | if (this->get_tls_handshake_begin_time() == 0) { |
| 1054 | this->_record_tls_handshake_begin_time(); |
| 1055 | // net_activity will not be triggered until after the handshake |
| 1056 | set_inactivity_timeout(HRTIME_SECONDS(SSLConfigParams::ssl_handshake_timeout_in)); |
| 1057 | } |
| 1058 | SSLConfig::scoped_config params; |
| 1059 | switch (event) { |
| 1060 | case SSL_EVENT_SERVER: |
| 1061 | if (this->ssl == nullptr) { |
| 1062 | SSLCertificateConfig::scoped_config lookup; |
| 1063 | IpEndpoint dst; |
| 1064 | int namelen = sizeof(dst); |
| 1065 | if (0 != safe_getsockname(this->get_socket(), &dst.sa, &namelen)) { |
| 1066 | Dbg(dbg_ctl_ssl, "Failed to get dest ip, errno = [%d]", errno); |
| 1067 | return EVENT_ERROR; |
| 1068 | } |
| 1069 | SSLCertContext *cc = lookup->find(dst); |
| 1070 | if (dbg_ctl_ssl.on()) { |
| 1071 | IpEndpoint src; |
| 1072 | ip_port_text_buffer ipb1, ipb2; |
| 1073 | int ip_len = sizeof(src); |
| 1074 | |
| 1075 | if (0 != safe_getpeername(this->get_socket(), &src.sa, &ip_len)) { |
| 1076 | DbgPrint(dbg_ctl_ssl, "Failed to get src ip, errno = [%d]", errno); |
| 1077 | return EVENT_ERROR; |
| 1078 | } |
| 1079 | ats_ip_nptop(&dst, ipb1, sizeof(ipb1)); |
| 1080 | ats_ip_nptop(&src, ipb2, sizeof(ipb2)); |
| 1081 | DbgPrint(dbg_ctl_ssl, "IP context is %p for [%s] -> [%s], default context %p", cc, ipb2, ipb1, lookup->defaultContext()); |
| 1082 | } |
| 1083 | |
| 1084 | // Escape if this is marked to be a tunnel. |
| 1085 | // No data has been read at this point, so we can go |
| 1086 | // directly into blind tunnel mode |
| 1087 | |
| 1088 | if (cc && SSLCertContextOption::OPT_TUNNEL == cc->opt) { |
| 1089 | if (this->is_transparent) { |
| 1090 | this->attributes = HttpProxyPort::TRANSPORT_BLIND_TUNNEL; |
| 1091 | sslHandshakeStatus = SSLHandshakeStatus::SSL_HANDSHAKE_DONE; |
| 1092 | SSL_free(this->ssl); |
| 1093 | this->ssl = nullptr; |
| 1094 | return EVENT_DONE; |
| 1095 | } else { |
| 1096 | hookOpRequested = SslVConnOp::SSL_HOOK_OP_TUNNEL; |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | // Attach the default SSL_CTX to this SSL session. The default context is never going to be able |
| 1101 | // to negotiate a SSL session, but it's enough to trampoline us into the SNI callback where we |
| 1102 | // can select the right server certificate. |
| 1103 | this->_make_ssl_connection(lookup->defaultContext()); |
nothing calls this directly
no test coverage detected