Skip to content

Commit f12a547

Browse files
committed
Fix SSL test_preauth_data_to_tls_server
1 parent aae6bf5 commit f12a547

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/stdlib/src/ssl/compat.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ pub(super) enum SslError {
391391
ZeroReturn,
392392
/// Unexpected EOF without close_notify (protocol violation)
393393
Eof,
394+
/// Non-TLS data received before handshake completed
395+
PreauthData,
394396
/// Certificate verification error
395397
CertVerification(rustls::CertificateError),
396398
/// I/O error
@@ -562,6 +564,15 @@ impl SslError {
562564
.upcast(),
563565
SslError::ZeroReturn => create_ssl_zero_return_error(vm).upcast(),
564566
SslError::Eof => create_ssl_eof_error(vm).upcast(),
567+
SslError::PreauthData => {
568+
// Non-TLS data received before handshake
569+
Self::create_ssl_error_with_reason(
570+
vm,
571+
None,
572+
"before TLS handshake with data",
573+
"before TLS handshake with data",
574+
)
575+
}
565576
SslError::CertVerification(cert_err) => {
566577
// Use the proper cert verification error creator
567578
create_ssl_cert_verification_error(vm, &cert_err).expect("unlikely to happen")
@@ -1245,6 +1256,12 @@ pub(super) fn ssl_do_handshake(
12451256
}
12461257
}
12471258

1259+
// InvalidMessage during handshake means non-TLS data was received
1260+
// before the handshake completed (e.g., HTTP request to TLS server)
1261+
if matches!(e, rustls::Error::InvalidMessage(_)) {
1262+
return Err(SslError::PreauthData);
1263+
}
1264+
12481265
// Certificate verification errors are already handled by from_rustls
12491266

12501267
return Err(SslError::from_rustls(e));

0 commit comments

Comments
 (0)