File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed
Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change 1- // spell-checker: ignore ssleof aesccm aesgcm getblocking setblocking ENDTLS
1+ // spell-checker: ignore ssleof aesccm aesgcm getblocking setblocking ENDTLS TLSEXT
22
33//! Pure Rust SSL/TLS implementation using rustls
44//!
@@ -2652,7 +2652,31 @@ mod _ssl {
26522652 } ;
26532653 let initial_context: PyObjectRef = self . context . read ( ) . clone ( ) . into ( ) ;
26542654
2655- let result = callback. call ( ( ssl_sock, server_name_py, initial_context) , vm) ?;
2655+ // catches exceptions from the callback and reports them as unraisable
2656+ let result = match callback. call ( ( ssl_sock, server_name_py, initial_context) , vm) {
2657+ Ok ( result) => result,
2658+ Err ( exc) => {
2659+ vm. run_unraisable (
2660+ exc,
2661+ Some ( "in ssl servername callback" . to_owned ( ) ) ,
2662+ callback. clone ( ) ,
2663+ ) ;
2664+ // Return SSL error like SSL_TLSEXT_ERR_ALERT_FATAL
2665+ let ssl_exc: PyBaseExceptionRef = vm
2666+ . new_os_subtype_error (
2667+ PySSLError :: class ( & vm. ctx ) . to_owned ( ) ,
2668+ None ,
2669+ "SNI callback raised exception" ,
2670+ )
2671+ . upcast ( ) ;
2672+ let _ = ssl_exc. as_object ( ) . set_attr (
2673+ "reason" ,
2674+ vm. ctx . new_str ( "TLSV1_ALERT_INTERNAL_ERROR" ) ,
2675+ vm,
2676+ ) ;
2677+ return Err ( ssl_exc) ;
2678+ }
2679+ } ;
26562680
26572681 // Check return value type (must be None or integer)
26582682 if !vm. is_none ( & result) {
You can’t perform that action at this time.
0 commit comments