Skip to content

Commit b0422cb

Browse files
committed
more fix
1 parent 2a17ca0 commit b0422cb

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

Lib/test/test_ssl.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,6 @@ def test_refcycle(self):
586586
del ss
587587
self.assertEqual(wr(), None)
588588

589-
@unittest.expectedFailure # TODO: RUSTPYTHON
590589
def test_wrapped_unconnected(self):
591590
# Methods on an unconnected SSLSocket propagate the original
592591
# OSError raise by the underlying socket object.
@@ -1670,7 +1669,6 @@ def test_context_client_server(self):
16701669
self.assertFalse(ctx.check_hostname)
16711670
self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
16721671

1673-
@unittest.expectedFailure # TODO: RUSTPYTHON
16741672
def test_context_custom_class(self):
16751673
class MySSLSocket(ssl.SSLSocket):
16761674
pass
@@ -1687,7 +1685,6 @@ class MySSLObject(ssl.SSLObject):
16871685
obj = ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(), server_side=True)
16881686
self.assertIsInstance(obj, MySSLObject)
16891687

1690-
@unittest.expectedFailure # TODO: RUSTPYTHON
16911688
def test_num_tickest(self):
16921689
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
16931690
self.assertEqual(ctx.num_tickets, 2)
@@ -1896,7 +1893,6 @@ def setUp(self):
18961893
self.enterContext(server)
18971894
self.server_addr = (HOST, server.port)
18981895

1899-
@unittest.expectedFailure # TODO: RUSTPYTHON
19001896
def test_connect(self):
19011897
with test_wrap_socket(socket.socket(socket.AF_INET),
19021898
cert_reqs=ssl.CERT_NONE) as s:
@@ -1963,7 +1959,6 @@ def test_non_blocking_connect_ex(self):
19631959
# SSL established
19641960
self.assertTrue(s.getpeercert())
19651961

1966-
@unittest.expectedFailure # TODO: RUSTPYTHON
19671962
def test_connect_with_context(self):
19681963
# Same as test_connect, but with a separately created context
19691964
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
@@ -2090,7 +2085,6 @@ def test_non_blocking_handshake(self):
20902085
def test_get_server_certificate(self):
20912086
_test_get_server_certificate(self, *self.server_addr, cert=SIGNING_CA)
20922087

2093-
@unittest.expectedFailure # TODO: RUSTPYTHON
20942088
def test_get_server_certificate_sni(self):
20952089
host, port = self.server_addr
20962090
server_names = []
@@ -2117,7 +2111,6 @@ def test_get_server_certificate_fail(self):
21172111
# independent test method
21182112
_test_get_server_certificate_fail(self, *self.server_addr)
21192113

2120-
@unittest.expectedFailure # TODO: RUSTPYTHON
21212114
def test_get_server_certificate_timeout(self):
21222115
def servername_cb(ssl_sock, server_name, initial_context):
21232116
time.sleep(0.2)
@@ -2153,7 +2146,6 @@ def test_get_ca_certs_capath(self):
21532146
self.assertTrue(cert)
21542147
self.assertEqual(len(ctx.get_ca_certs()), 1)
21552148

2156-
@unittest.expectedFailure # TODO: RUSTPYTHON
21572149
def test_context_setget(self):
21582150
# Check that the context of a connected socket can be replaced.
21592151
ctx1 = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
@@ -3038,7 +3030,6 @@ def test_crl_check(self):
30383030
cert = s.getpeercert()
30393031
self.assertTrue(cert, "Can't get peer certificate.")
30403032

3041-
@unittest.expectedFailure # TODO: RUSTPYTHON
30423033
def test_check_hostname(self):
30433034
if support.verbose:
30443035
sys.stdout.write("\n")
@@ -3179,7 +3170,6 @@ def test_dual_rsa_ecc(self):
31793170
cipher = s.cipher()[0].split('-')
31803171
self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA'))
31813172

3182-
@unittest.expectedFailure # TODO: RUSTPYTHON
31833173
def test_check_hostname_idn(self, warnings_filters=True):
31843174
if support.verbose:
31853175
sys.stdout.write("\n")
@@ -3367,7 +3357,6 @@ def connector():
33673357
finally:
33683358
t.join()
33693359

3370-
@unittest.expectedFailure # TODO: RUSTPYTHON
33713360
def test_ssl_cert_verify_error(self):
33723361
if support.verbose:
33733362
sys.stdout.write("\n")
@@ -3474,7 +3463,6 @@ def test_protocol_tlsv1_1(self):
34743463
try_protocol_combo(ssl.PROTOCOL_TLSv1_2, ssl.PROTOCOL_TLSv1_1, False)
34753464

34763465
@requires_tls_version('TLSv1_2')
3477-
@unittest.expectedFailure # TODO: RUSTPYTHON
34783466
def test_protocol_tlsv1_2(self):
34793467
"""Connecting to a TLSv1.2 server with various client options.
34803468
Testing against older TLS versions."""
@@ -3921,7 +3909,6 @@ def test_do_handshake_enotconn(self):
39213909
sock.do_handshake()
39223910
self.assertEqual(cm.exception.errno, errno.ENOTCONN)
39233911

3924-
@unittest.expectedFailure # TODO: RUSTPYTHON
39253912
def test_no_shared_ciphers(self):
39263913
client_context, server_context, hostname = testing_context()
39273914
# OpenSSL enables all TLS 1.3 ciphers, enforce TLS 1.2 for test
@@ -4153,7 +4140,6 @@ def test_no_legacy_server_connect(self):
41534140
chatty=True, connectionchatty=True,
41544141
sni_name=hostname)
41554142

4156-
@unittest.expectedFailure # TODO: RUSTPYTHON
41574143
def test_dh_params(self):
41584144
# Check we can get a connection with ephemeral finite-field
41594145
# Diffie-Hellman (if supported).
@@ -4752,7 +4738,6 @@ def test_pha_optional(self):
47524738
s.write(b'HASCERT')
47534739
self.assertEqual(s.recv(1024), b'TRUE\n')
47544740

4755-
@unittest.expectedFailure # TODO: RUSTPYTHON
47564741
def test_pha_optional_nocert(self):
47574742
if support.verbose:
47584743
sys.stdout.write("\n")
@@ -4775,7 +4760,6 @@ def test_pha_optional_nocert(self):
47754760
s.write(b'HASCERT')
47764761
self.assertEqual(s.recv(1024), b'FALSE\n')
47774762

4778-
@unittest.expectedFailure # TODO: RUSTPYTHON
47794763
def test_pha_no_pha_client(self):
47804764
client_context, server_context, hostname = testing_context()
47814765
server_context.post_handshake_auth = True
@@ -4792,7 +4776,6 @@ def test_pha_no_pha_client(self):
47924776
s.write(b'PHA')
47934777
self.assertIn(b'extension not received', s.recv(1024))
47944778

4795-
@unittest.expectedFailure # TODO: RUSTPYTHON
47964779
def test_pha_no_pha_server(self):
47974780
# server doesn't have PHA enabled, cert is requested in handshake
47984781
client_context, server_context, hostname = testing_context()
@@ -4813,7 +4796,6 @@ def test_pha_no_pha_server(self):
48134796
s.write(b'HASCERT')
48144797
self.assertEqual(s.recv(1024), b'TRUE\n')
48154798

4816-
@unittest.expectedFailure # TODO: RUSTPYTHON
48174799
def test_pha_not_tls13(self):
48184800
# TLS 1.2
48194801
client_context, server_context, hostname = testing_context()

stdlib/src/ssl.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,6 @@ mod _ssl {
12581258
Ok(dict.into())
12591259
}
12601260

1261-
// CPython: cpython/Modules/_ssl.c:4502-4539
12621261
#[pymethod]
12631262
fn session_stats(&self, vm: &VirtualMachine) -> PyResult {
12641263
let ctx = self.ctx();
@@ -1505,7 +1504,7 @@ mod _ssl {
15051504
}
15061505
}
15071506

1508-
// Configure post-handshake authentication (PHA) - CPython: bpo-37428
1507+
// Configure post-handshake authentication (PHA)
15091508
#[cfg(ossl111)]
15101509
if *zelf.post_handshake_auth.lock() {
15111510
unsafe {
@@ -1644,7 +1643,7 @@ mod _ssl {
16441643
sys::SSL_set_bio(ssl.as_ptr(), inbio_ptr, outbio_ptr);
16451644
}
16461645

1647-
// Configure post-handshake authentication (PHA) - CPython: bpo-37428
1646+
// Configure post-handshake authentication (PHA)
16481647
#[cfg(ossl111)]
16491648
if *zelf.post_handshake_auth.lock() {
16501649
unsafe {
@@ -3002,6 +3001,33 @@ mod _ssl {
30023001
) -> PyBaseExceptionRef {
30033002
match err.errors().last() {
30043003
Some(e) => {
3004+
// Check if this is a system library error (file not found, etc.)
3005+
// CPython: Modules/_ssl.c:667-670, 697-701
3006+
let lib = sys::ERR_GET_LIB(e.code());
3007+
let library_str = e.library().unwrap_or("");
3008+
3009+
// Check both lib code and library string for system errors
3010+
if lib == sys::ERR_LIB_SYS || library_str == "SSL routines" {
3011+
let reason = sys::ERR_GET_REASON(e.code());
3012+
let reason_str = e.reason().unwrap_or("");
3013+
3014+
// Check if it's a system lib error by reason string
3015+
if reason_str == "system lib" || lib == sys::ERR_LIB_SYS {
3016+
// errno 2 = ENOENT = FileNotFoundError
3017+
let exc_type = if reason == 2 {
3018+
vm.ctx.exceptions.file_not_found_error.to_owned()
3019+
} else {
3020+
vm.ctx.exceptions.os_error.to_owned()
3021+
};
3022+
let exc = vm.new_exception(exc_type, vec![vm.ctx.new_int(reason).into()]);
3023+
// Set errno attribute explicitly
3024+
let _ = exc
3025+
.as_object()
3026+
.set_attr("errno", vm.ctx.new_int(reason), vm);
3027+
return exc;
3028+
}
3029+
}
3030+
30053031
let caller = std::panic::Location::caller();
30063032
let (file, line) = (caller.file(), caller.line());
30073033
let file = file

0 commit comments

Comments
 (0)