@@ -109,10 +109,12 @@ void baseSSLCom<L4Proto>::init(baseHostCX* owner) {
109
109
template <class L4Proto >
110
110
std::string baseSSLCom<L4Proto>::to_string(int verbosity) const {
111
111
mp::stringstream ss;
112
+
112
113
ss << " SSLCom[" << ( is_server () ? " server] <-" : " client] ->" );
113
114
ss << " sni:" << get_sni () << " alpn: " << sslcom_alpn_;
114
115
115
116
if (opt.bypass ) ss << " bypassed" ;
117
+ if (opt.no_fallback_bypass ) ss << " no_fallback_bypass" ;
116
118
117
119
return ss.str ().c_str ();
118
120
}
@@ -1748,7 +1750,15 @@ void baseSSLCom<L4Proto>::init_server() {
1748
1750
_dia (" SSLCom::init_server: using custom context 0x%x" , sslcom_ctx);
1749
1751
}
1750
1752
else if (not sslcom_ctx) {
1751
- sslcom_ctx = factory ()->default_tls_server_cx ();
1753
+
1754
+ if (not opt.cert .mitm_cert_searched_only ) {
1755
+ sslcom_ctx = factory ()->default_tls_server_cx ();
1756
+ }
1757
+ else {
1758
+ _dia (" using default tls context is prohibited" );
1759
+ error (baseCom::ERROR_UNSPEC);
1760
+ return ;
1761
+ }
1752
1762
}
1753
1763
1754
1764
@@ -2014,6 +2024,9 @@ void baseSSLCom<L4Proto>::accept_socket (int sockfd) {
2014
2024
counters.prof_accept_bypass_cnt ++;
2015
2025
return ;
2016
2026
}
2027
+ if (not sslcom_ssl) {
2028
+ return ;
2029
+ }
2017
2030
2018
2031
2019
2032
if (l4_proto () == SOCK_DGRAM) {
@@ -2147,6 +2160,12 @@ int baseSSLCom<L4Proto>::handshake_server() {
2147
2160
}
2148
2161
2149
2162
ERR_clear_error ();
2163
+ if (not sslcom_ssl) {
2164
+ _dia (" SSLCom::handshake: socket not upgraded, failing" );
2165
+ error (ERROR_UNSPEC);
2166
+ return -1 ;
2167
+ }
2168
+
2150
2169
sslcom_ret = SSL_accept (sslcom_ssl);
2151
2170
2152
2171
if (sslcom_ret == 1 ) {
@@ -2329,15 +2348,23 @@ ret_handshake baseSSLCom<L4Proto>::handshake() {
2329
2348
op_code = handshake_server ();
2330
2349
}
2331
2350
2332
- int err = SSL_get_error (sslcom_ssl, op_code);
2333
- unsigned long err2 = ERR_get_error ();
2334
2351
2335
- _dia (" SSLCom::handshake: %s on socket %d: r=%d, err=%d, err2=%d" , op_descr, socket (), op_code, err, err2);
2352
+
2353
+ _dia (" SSLCom::handshake: %s on socket %d: r=%d" , op_descr, socket (), op_code);
2336
2354
2337
2355
// general error handling code - both accept and connect yield the same errors
2338
2356
if (op_code < 0 ) {
2357
+
2358
+ if (error ()) {
2359
+ return ret_handshake::FATAL;
2360
+ }
2361
+
2362
+ int err = SSL_get_error (sslcom_ssl, op_code);
2363
+ unsigned long err2 = ERR_get_error ();
2339
2364
// potentially OK if non-blocking socket
2340
2365
2366
+ _dia (" SSLCom::handshake: %s on socket %d: ret=%d, err=%d, err2=%d" , op_descr, socket (), op_code, err, err2);
2367
+
2341
2368
if (err == SSL_ERROR_WANT_READ) {
2342
2369
_dia (" SSLCom::handshake: SSL_%s[%d]: pending on want_read" , op_descr , socket ());
2343
2370
@@ -2390,15 +2417,19 @@ ret_handshake baseSSLCom<L4Proto>::handshake() {
2390
2417
else {
2391
2418
// any other error < 0 is considered as BAD thing.
2392
2419
2393
- _dia (" SSLCom::handshake: SSL_%s: error: %d: %d" ,op_descr , err, err2);
2420
+ _dia (" SSLCom::handshake: SSL_%s: ret=0, err=%d, err2= %d" , op_descr , err, err2);
2394
2421
handshake_dia_error2 (op_code, err, err2);
2395
2422
sslcom_waiting = true ;
2396
2423
return ret_handshake::ERROR;
2397
2424
}
2398
2425
2399
2426
} else if (op_code == 0 ) {
2427
+
2428
+ int err = SSL_get_error (sslcom_ssl, op_code);
2429
+ unsigned long err2 = ERR_get_error ();
2430
+
2400
2431
// positively handshake error signalled by SSL_connect or SSL_accept
2401
- _dia (" SSLCom::handshake: SSL_%s: error: %d: %d" ,op_descr , err, err2);
2432
+ _dia (" SSLCom::handshake: SSL_%s: ret=0, err=%d, err2= %d" , op_descr , err, err2);
2402
2433
handshake_dia_error2 (op_code, err, err2);
2403
2434
2404
2435
// shutdown OK, but connection failed
@@ -2407,12 +2438,18 @@ ret_handshake baseSSLCom<L4Proto>::handshake() {
2407
2438
}
2408
2439
else if (op_code == 2 ) {
2409
2440
2410
- // our internal signalling for bypass
2411
- opt.bypass = true ;
2412
- verify_reset (verify_status_t ::VRF_OK);
2413
- _dia (" SSLCom::handshake: bypassed." );
2441
+ if (opt.no_fallback_bypass ) {
2442
+ error (ERROR_UNSPEC);
2443
+ return ret_handshake::FATAL;
2444
+ }
2445
+ else {
2446
+ // our internal signalling for bypass
2447
+ opt.bypass = true ;
2448
+ verify_reset (verify_status_t ::VRF_OK);
2449
+ _dia (" SSLCom::handshake: bypassed." );
2414
2450
2415
- return ret_handshake::AGAIN;
2451
+ return ret_handshake::AGAIN;
2452
+ }
2416
2453
}
2417
2454
2418
2455
@@ -2676,11 +2713,18 @@ bool baseSSLCom<L4Proto>::waiting_peer_hello() {
2676
2713
_dia (" SSLCom::waiting_peer_hello: analysis failed" );
2677
2714
_dia (" SSLCom::waiting_peer_hello: failed ClientHello data:\r\n %s" ,
2678
2715
hex_dump (sslcom_peer_hello_buffer.data (),sslcom_peer_hello_buffer.size (), 4 , 0 , true ).c_str ());
2679
-
2680
- if (bypass_me_and_peer ()) {
2681
- _inf (" bypassing non-TLS connection" );
2682
- log .event (INF, " [%s] cannot read ClientHello: bypassed" , peer_scom->to_string (iINF).c_str ());
2683
- return false ;
2716
+
2717
+ if (not opt.no_fallback_bypass ) {
2718
+ _inf (" fallback bypass disabled!" );
2719
+ log .event (INF, " [%s] cannot read ClientHello: bypass disabled" ,
2720
+ peer_scom->to_string (iINF).c_str ());
2721
+
2722
+ if (bypass_me_and_peer ()) {
2723
+ _inf (" bypassing non-TLS connection" );
2724
+ log .event (INF, " [%s] cannot read ClientHello: bypassed" ,
2725
+ peer_scom->to_string (iINF).c_str ());
2726
+ return false ;
2727
+ }
2684
2728
}
2685
2729
2686
2730
error_flag_ = ERROR_UNSPEC; // peer nullptr or its com() is not SSLCom
0 commit comments