Skip to content

Commit

Permalink
default disable ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Feb 8, 2022
1 parent 170df9a commit 291c298
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 31 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [

[package]
name = "cdbc"
version = "0.1.12"
version = "0.1.13"
edition = "2021"
authors = ["[email protected]"]
description = "Rust Coroutine Database Driver Connectivity"
Expand All @@ -18,7 +18,8 @@ license = "Apache-2.0"

[features]
default = []
_tls-native-tls = []

#native-tls

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
Expand All @@ -32,6 +33,6 @@ log = { version = "0.4.8", default-features = false }
crossbeam-queue = "0.3.1"
either = {version = "1.5.3",features = ["serde"]}
bstr = { version = "0.2.14", default-features = false, features = ["std"] }
native-tls = {version ="0.2"}
native-tls = {version ="0.2",optional = true}
ahash = "0.7.2"
serde_json = { version = "1.0.51", features = ["raw_value"]}
27 changes: 14 additions & 13 deletions cdbc-mysql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "cdbc-mysql"
version = "0.1.12"
version = "0.1.13"
edition = "2021"
authors = ["[email protected]"]
description = "Rust Coroutine Database Driver Connectivity"
repository = "https://github.com/co-rs/cdbc"
license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["offline","time"]
default = ["cdbc","offline", "time"]
offline = ["serde", "either/serde"]
_tls-native-tls = []

Expand All @@ -25,29 +25,30 @@ bigdecimal = ["bigdecimal_", "num-bigint"]
decimal = ["rust_decimal", "num-bigint"]
json = ["serde", "serde_json"]

native-tls = ["cdbc/native-tls"]

[dependencies]
cdbc = { version = "0.1.12", path = "../"}
cdbc = { version = "0.1.13", path = "../", optional = true }

cogo = "0.1"
hashlink = "0.7.0"
thiserror = "1.0.30"
bytes = '1.0.0'
memchr = "2.3.4"
serde={version = "1.0.130" ,optional = true}
serde = { version = "1.0.130", optional = true }
log = { version = "0.4.8", default-features = false }

either = "1.5.3"
bstr = { version = "0.2.14", default-features = false, features = ["std"] }
native-tls = {version ="0.2"}
generic-array = {version ="^0.14.4",features = ["serde"]}
rand = {version = "0.8.4",features = ["std","serde"]}
rsa = {version = "0.5.0",features = ["std","serde","serde_crate"]}
sha-1 = {version = "0.9.0", default-features = false}
sha2 = {version = "0.9.0", default-features = false}
base64 = {version="0.13.0",features = ["std"]}
digest = {version = "0.9.0"}
generic-array = { version = "^0.14.4", features = ["serde"] }
rand = { version = "0.8.4", features = ["std", "serde"] }
rsa = { version = "0.5.0", features = ["std", "serde", "serde_crate"] }
sha-1 = { version = "0.9.0", default-features = false }
sha2 = { version = "0.9.0", default-features = false }
base64 = { version = "0.13.0", features = ["std"] }
digest = { version = "0.9.0" }
smallvec = "1.7.0"
byteorder = { version = "1.3.4", features = ["std"] }
byteorder = { version = "1.3.4", features = ["std"] }
ahash = "0.7.2"
percent-encoding = "2.1.0"
url = { version = "2.1.1" }
Expand Down
4 changes: 4 additions & 0 deletions cdbc-mysql/src/connection/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ fn upgrade(stream: &mut MySqlStream, options: &MySqlConnectOptions) -> Result<bo
);
let accept_invalid_host_names = !matches!(options.ssl_mode, MySqlSslMode::VerifyIdentity);

if !cfg!(feature = "native-tls") {
return Result::Err(Error::from("must enable native-tls!"));
}
#[cfg(feature = "native-tls")]
stream
.upgrade(
&options.host,
Expand Down
5 changes: 2 additions & 3 deletions cdbc-pg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cdbc-pg"
version = "0.1.12"
version = "0.1.13"
edition = "2021"
authors = ["[email protected]"]
description = "Rust Coroutine Database Driver Connectivity"
Expand Down Expand Up @@ -42,7 +42,7 @@ json = ["serde", "serde_json"]
offline = ["json"]

[dependencies]
cdbc = { version = "0.1.12", path = "../"}
cdbc = { version = "0.1.13", path = "../"}

atoi = "0.4.0"
smallvec = "1.4.0"
Expand All @@ -56,7 +56,6 @@ log = { version = "0.4.8", default-features = false }

serde_json = { version = "1.0.51", features = ["raw_value"], optional = true }

native-tls = {version ="0.2"}
either = "1.5.3"
md-5 = { version = "0.9.0", default-features = false, optional = true }
sha2 = { version = "0.9.0", default-features = false, optional = true }
Expand Down
7 changes: 5 additions & 2 deletions cdbc-pg/src/connection/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ fn upgrade(stream: &mut PgStream, options: &PgConnectOptions) -> Result<bool, Er
);
let accept_invalid_hostnames = !matches!(options.ssl_mode, PgSslMode::VerifyFull);

stream
.upgrade(
if !cfg!(feature = "native-tls") {
return cdbc::Result::Err(Error::from("must enable native-tls!"));
}
#[cfg(feature = "native-tls")]
stream.upgrade(
&options.host,
accept_invalid_certs,
accept_invalid_hostnames,
Expand Down
5 changes: 2 additions & 3 deletions cdbc-sqlite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cdbc-sqlite"
version = "0.1.12"
version = "0.1.13"
edition = "2021"
authors = ["[email protected]"]
description = "Rust Coroutine Database Driver Connectivity"
Expand All @@ -10,7 +10,6 @@ license = "Apache-2.0"
[features]
default = ["sqlite","offline"]
offline = []
_tls-native-tls = []
json= ["serde","serde_json"]

sqlite = ["libsqlite3-sys","json"]
Expand All @@ -23,7 +22,7 @@ all-types = [
[dependencies]

cogo = "0.1"
cdbc = { version = "0.1.12", path = "../"}
cdbc = { version = "0.1.13", path = "../"}
serde={version = "1.0.130" ,features = ["derive", "rc"],optional = true}
serde_json = { version = "1.0.51", features = ["raw_value"], optional = true }
log = { version = "0.4.8", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::result::Result as StdResult;
use std::sync::mpsc::{RecvError, SendError};
use std::sync::PoisonError;
use cogo::std::sync::channel;
use native_tls::HandshakeError;
use crate::database::Database;
use crate::type_info::TypeInfo;
use crate::types::Type;
Expand Down
24 changes: 18 additions & 6 deletions src/net/tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::task::{Context, Poll};

use crate::error::Error;
use std::mem::replace;
use native_tls::HandshakeError;
use crate::decode::Decode;
use crate::encode::Encode;
use crate::net::socket::IsTLS;
Expand Down Expand Up @@ -57,16 +56,19 @@ impl std::fmt::Display for CertificateInput {
}


#[cfg(feature = "native-tls")]
pub struct TlsStream<S>{
pub inner:native_tls::TlsStream<S>
}
#[cfg(feature = "native-tls")]
impl <S>Deref for TlsStream<S>{
type Target = native_tls::TlsStream<S>;

fn deref(&self) -> &Self::Target {
&self.inner
}
}
#[cfg(feature = "native-tls")]
impl <S>DerefMut for TlsStream<S>{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
Expand All @@ -80,6 +82,7 @@ where
S: std::io::Read + std::io::Write,
{
Raw(S),
#[cfg(feature = "native-tls")]
Tls(TlsStream<S>),
Upgrading,
}
Expand All @@ -89,6 +92,7 @@ impl<S> MaybeTlsStream<S>
where
S: std::io::Read + std::io::Write + std::fmt::Debug + Send +Sync + 'static,
{
#[cfg(feature = "native-tls")]
pub fn upgrade(
&mut self,
host: &str,
Expand Down Expand Up @@ -135,11 +139,17 @@ where
impl <S>IsTLS for MaybeTlsStream<S> where S:Write+Read{
#[inline]
fn is_tls(&self) -> bool {
matches!(self, Self::Tls(_))
if !cfg!(feature = "native-tls") {
return false;
}else{
#[cfg(feature = "native-tls")]
return matches!(self, Self::Tls(_));
}
return false;
}
}

// #[cfg(feature = "_tls-native-tls")]
#[cfg(feature = "native-tls")]
fn configure_tls_connector(
accept_invalid_certs: bool,
accept_invalid_hostnames: bool,
Expand Down Expand Up @@ -185,6 +195,7 @@ where
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
match &mut *self {
MaybeTlsStream::Raw(s) => s.read(buf),
#[cfg(feature = "native-tls")]
MaybeTlsStream::Tls(s) => s.read(buf),
MaybeTlsStream::Upgrading => Err(io::ErrorKind::ConnectionAborted.into()),
}
Expand All @@ -198,15 +209,16 @@ where
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
match self {
MaybeTlsStream::Raw(s) => s.write( buf),
#[cfg(feature = "native-tls")]
MaybeTlsStream::Tls(s) => s.write( buf),

MaybeTlsStream::Upgrading => Err(io::ErrorKind::ConnectionAborted.into()),
}
}

fn flush(&mut self) -> std::io::Result<()> {
match self {
MaybeTlsStream::Raw(s) => s.flush(),
#[cfg(feature = "native-tls")]
MaybeTlsStream::Tls(s) => s.flush(),

MaybeTlsStream::Upgrading => Err(io::ErrorKind::ConnectionAborted.into()),
Expand All @@ -224,7 +236,7 @@ where
fn deref(&self) -> &Self::Target {
match self {
MaybeTlsStream::Raw(s) => s,

#[cfg(feature = "native-tls")]
MaybeTlsStream::Tls(s) => s.get_ref(),

MaybeTlsStream::Upgrading => {
Expand All @@ -241,7 +253,7 @@ where
fn deref_mut(&mut self) -> &mut Self::Target {
match self {
MaybeTlsStream::Raw(s) => s,

#[cfg(feature = "native-tls")]
MaybeTlsStream::Tls(s) => s.get_mut(),

MaybeTlsStream::Upgrading => {
Expand Down

0 comments on commit 291c298

Please sign in to comment.