Fix TLS refactors for MySQL

This commit is contained in:
Ryan Leckey
2020-03-11 01:54:33 -07:00
parent a9c3d9f44c
commit d6ce866c4b
2 changed files with 11 additions and 4 deletions

View File

@@ -22,9 +22,9 @@ use crate::url::Url;
use std::ops::Range;
// Size before a packet is split
const MAX_PACKET_SIZE: u32 = 1024;
pub(super) const MAX_PACKET_SIZE: u32 = 1024;
const COLLATE_UTF8MB4_UNICODE_CI: u8 = 224;
pub(super) const COLLATE_UTF8MB4_UNICODE_CI: u8 = 224;
/// An asynchronous connection to a [MySql] database.
///

View File

@@ -26,6 +26,13 @@ pub(super) async fn upgrade_if_needed(stream: &mut MySqlStream, url: &Url) -> cr
}
}
#[cfg(feature = "tls")]
None => {
if let Err(error) = try_upgrade(stream, &url, ca_file.as_deref(), true).await {
// TLS upgrade failed; fall back to a normal connection
}
}
#[cfg(feature = "tls")]
Some(mode @ "REQUIRED") | Some(mode @ "VERIFY_CA") | Some(mode @ "VERIFY_IDENTITY")
if !supports_tls =>
@@ -104,8 +111,8 @@ async fn try_upgrade(
stream
.send(
SslRequest {
client_collation: COLLATE_UTF8MB4_UNICODE_CI,
max_packet_size: MAX_PACKET_SIZE,
client_collation: super::connection::COLLATE_UTF8MB4_UNICODE_CI,
max_packet_size: super::connection::MAX_PACKET_SIZE,
},
false,
)