Skip to content

Commit c404c6a

Browse files
committed
fix _wrap_socket
1 parent c3dad1d commit c404c6a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

stdlib/src/ssl.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,20 @@ mod _ssl {
884884
args: WrapSocketArgs,
885885
vm: &VirtualMachine,
886886
) -> PyResult<PySslSocket> {
887+
// validate socket type and context protocol
888+
if !args.server_side && zelf.protocol == SslVersion::TlsServer {
889+
return Err(vm.new_exception_msg(
890+
ssl_error(vm),
891+
"Cannot create a client socket with a PROTOCOL_TLS_SERVER context".to_owned(),
892+
));
893+
}
894+
if args.server_side && zelf.protocol == SslVersion::TlsClient {
895+
return Err(vm.new_exception_msg(
896+
ssl_error(vm),
897+
"Cannot create a server socket with a PROTOCOL_TLS_CLIENT context".to_owned(),
898+
));
899+
}
900+
887901
let mut ssl = ssl::Ssl::new(&zelf.ctx()).map_err(|e| convert_openssl_error(vm, e))?;
888902

889903
let socket_type = if args.server_side {

0 commit comments

Comments
 (0)