Skip to content

Commit b9b5516

Browse files
committed
debug
1 parent 703f9d8 commit b9b5516

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

mysql/src/lib.rs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ pub struct AsyncMysqlIntermediary<B, S: AsyncRead + Unpin, W> {
471471
session_autocommit: bool,
472472
}
473473

474+
fn packet_preview(bytes: &[u8]) -> (usize, String) {
475+
let preview_len = bytes.len().min(128);
476+
let preview = bytes[..preview_len]
477+
.iter()
478+
.map(|b| format!("{:02X}", b))
479+
.collect::<Vec<_>>()
480+
.join(" ");
481+
(preview_len, preview)
482+
}
483+
474484
impl<B, R, W> AsyncMysqlIntermediary<B, R, W>
475485
where
476486
W: AsyncWrite + Send + Unpin,
@@ -542,11 +552,18 @@ where
542552
// connection_id (4 bytes)
543553
writer.write_all(&shim.connect_id().to_le_bytes())?;
544554

545-
let server_capabilities = CapabilityFlags::CLIENT_PROTOCOL_41
555+
let mut server_capabilities = CapabilityFlags::CLIENT_LONG_PASSWORD
556+
| CapabilityFlags::CLIENT_LONG_FLAG
557+
| CapabilityFlags::CLIENT_CONNECT_WITH_DB
558+
| CapabilityFlags::CLIENT_PROTOCOL_41
559+
| CapabilityFlags::CLIENT_TRANSACTIONS
546560
| CapabilityFlags::CLIENT_SECURE_CONNECTION
561+
| CapabilityFlags::CLIENT_MULTI_STATEMENTS
562+
| CapabilityFlags::CLIENT_MULTI_RESULTS
563+
| CapabilityFlags::CLIENT_PS_MULTI_RESULTS
547564
| CapabilityFlags::CLIENT_PLUGIN_AUTH
548565
| CapabilityFlags::CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA
549-
| CapabilityFlags::CLIENT_CONNECT_WITH_DB
566+
| CapabilityFlags::CLIENT_CONNECT_ATTRS
550567
| CapabilityFlags::CLIENT_SESSION_TRACK
551568
| CapabilityFlags::CLIENT_DEPRECATE_EOF;
552569

@@ -567,7 +584,7 @@ where
567584
writer.write_all(&server_capabilities_vec[..2])?; // The lower 2 bytes of the Capabilities Flags, 0x42
568585
// self.writer.write_all(&[0x00, 0x42])?;
569586
writer.write_all(&[0x21])?; // UTF8_GENERAL_CI
570-
writer.write_all(&[0x00, 0x00])?; // status_flags
587+
writer.write_all(&StatusFlags::SERVER_STATUS_AUTOCOMMIT.bits().to_le_bytes())?; // status_flags
571588
writer.write_all(&server_capabilities_vec[2..4])?; // The upper 2 bytes of the Capabilities Flags
572589

573590
if default_auth_plugin.is_empty() {
@@ -596,15 +613,18 @@ where
596613
)
597614
})?;
598615

616+
let (preview_len, preview) = packet_preview(&handshake_packet);
617+
warn!(
618+
"opensrv:mysql received initial handshake packet len={}, first_bytes({}): {}",
619+
handshake_packet.len(),
620+
preview_len,
621+
preview
622+
);
623+
599624
let handshake = match commands::client_handshake(&handshake_packet, false) {
600625
Ok((_, handshake)) => handshake,
601626
Err(e) => {
602-
let preview_len = handshake_packet.len().min(128);
603-
let preview = handshake_packet[..preview_len]
604-
.iter()
605-
.map(|b| format!("{:02X}", b))
606-
.collect::<Vec<_>>()
607-
.join(" ");
627+
let (preview_len, preview) = packet_preview(&handshake_packet);
608628

609629
error!(
610630
"opensrv:mysql failed to parse initial handshake: err={:?}, packet_len={}, first_bytes({}): {}",
@@ -644,7 +664,7 @@ where
644664
}
645665
};
646666

647-
info!(
667+
warn!(
648668
"opensrv:mysql initial handshake parsed: username={:?}, auth_plugin={}, db_present={}, client_flags=0x{:X}, tls_requested={}",
649669
handshake
650670
.username
@@ -670,7 +690,7 @@ where
670690

671691
#[cfg(feature = "tls")]
672692
if handshake.capabilities.contains(CapabilityFlags::CLIENT_SSL) {
673-
info!(
693+
warn!(
674694
"opensrv:mysql client requested TLS; deferring handshake completion user={:?}",
675695
handshake
676696
.username
@@ -699,15 +719,18 @@ where
699719
})?;
700720
seq = _seq;
701721

722+
let (preview_len, preview) = packet_preview(&hs_packet);
723+
warn!(
724+
"opensrv:mysql received TLS handshake packet len={}, first_bytes({}): {}",
725+
hs_packet.len(),
726+
preview_len,
727+
preview
728+
);
729+
702730
handshake = match commands::client_handshake(&hs_packet, true) {
703731
Ok((_, handshake)) => handshake,
704732
Err(e) => {
705-
let preview_len = hs_packet.len().min(128);
706-
let preview = hs_packet[..preview_len]
707-
.iter()
708-
.map(|b| format!("{:02X}", b))
709-
.collect::<Vec<_>>()
710-
.join(" ");
733+
let (preview_len, preview) = packet_preview(&hs_packet);
711734

712735
error!(
713736
"opensrv:mysql failed to parse TLS handshake: err={:?}, packet_len={}, first_bytes({}): {}",
@@ -747,7 +770,7 @@ where
747770
}
748771
};
749772

750-
info!(
773+
warn!(
751774
"opensrv:mysql TLS handshake parsed: username={:?}, auth_plugin={}, db_present={}, client_flags=0x{:X}",
752775
handshake
753776
.username

0 commit comments

Comments
 (0)