Skip to content

Commit 2d3ef86

Browse files
fix SSL callback (#6688)
* fix SSL callback * Auto-format: cargo fmt --all --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 6fe0598 commit 2d3ef86

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

crates/stdlib/src/ssl.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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) {

0 commit comments

Comments
 (0)