Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove server side dependent of crypto provider. #1007

Merged
merged 3 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ci-check-web = "hack check --package xitca-web --each-feature --no-dev-deps"
ci-check-client-exclude-io-uring = "hack check --package xitca-client --each-feature --no-dev-deps --exclude-features=io-uring"
ci-check-client = "hack check --package xitca-client --each-feature --no-dev-deps"

ci-check-other-exclude-io-uring = "hack check --workspace --exclude xitca-http --exclude xitca-client --exclude xitca-web --feature-powerset --exclude-features=io-uring,tokio-uring,runtime-uring,rustls-uring"
ci-check-other-exclude-io-uring = "hack check --workspace --exclude xitca-http --exclude xitca-client --exclude xitca-web --feature-powerset --exclude-features=io-uring,tokio-uring,runtime-uring,rustls-uring,rustls-uring-no-crypto"
ci-check-other = "hack check --workspace --exclude xitca-http --exclude xitca-client --exclude xitca-web --feature-powerset"

ci-test-exclude-io-uring = "hack test --workspace --feature-powerset --exclude-features=io-uring --no-fail-fast -- --nocapture"
Expand Down
9 changes: 4 additions & 5 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ version = "0.1.0"
edition = "2021"

[features]
# default feature includes http/1 clear text client.
# default feature includes http/1 clear text client
default = ["http1"]
# http/1 clear text client
# http/1 clear text client
http1 = ["httparse", "xitca-http/http1"]
# http/2 client(tls enabled by default. see `dangerous` feature for clear text http/2)
http2 = ["h2", "itoa", "xitca-http/http2"]
# htt/3 client(tls always enabled with rustls)
# http/3 client(tls always enabled with rustls)
http3 = ["h3", "h3-quinn", "quinn/tls-rustls", "itoa", "async-stream", "rustls_0dot21", "webpki_roots_0dot25"]
# openssl as http/1 and http/2 tls handler.
openssl = ["xitca-tls/openssl"]
Expand All @@ -24,7 +24,6 @@ compress = ["http-encoding"]
json = ["serde", "serde_json"]
# websocket support
websocket = ["http-ws"]

# feature for testing niche client side usage and correctness of server implemenation:
# - http/2 clear text over plain tcp connection
# - http/3 connection to server with self signed certificates.
Expand Down Expand Up @@ -57,7 +56,7 @@ async-stream = { version = "0.3", optional = true }
itoa = { version = "1", optional = true }

# tls shared
xitca-tls = { version = "0.2.2", optional = true }
xitca-tls = { version = "0.2.3", optional = true }

# rustls, http3 and dangerous features shared
webpki-roots = { version = "0.26", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
timeout::TimeoutConfig,
tls::{
connector::{self, Connector},
stream::TlsStream,
TlsStream,
},
};

Expand Down
4 changes: 2 additions & 2 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
connect::Connect,
connection::{ConnectionExclusive, ConnectionKey, ConnectionShared},
date::DateTimeService,
error::{Error, TimeoutError},
error::{Error, ResolveError, TimeoutError},
http::{self, uri, Method, Version},
http_tunnel::HttpTunnelRequest,
pool,
Expand Down Expand Up @@ -316,7 +316,7 @@ impl Client {
async fn make_tcp_inner(&self, connect: &Connect<'_>) -> Result<TcpStream, Error> {
let mut iter = connect.addrs();

let mut addr = iter.next().ok_or(Error::Resolve)?;
let mut addr = iter.next().ok_or_else(|| ResolveError::new(connect.hostname()))?;

// try to connect with all addresses resolved by dns resolver.
// return the last error when all are fail to be connected.
Expand Down
2 changes: 1 addition & 1 deletion client/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use xitca_io::{
#[cfg(unix)]
use xitca_io::net::UnixStream;

use crate::{tls::stream::TlsStream, uri::Uri};
use super::{tls::TlsStream, uri::Uri};

#[cfg(feature = "http1")]
/// A convince type alias for typing connection without interacting with pool.
Expand Down
46 changes: 42 additions & 4 deletions client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ pub enum Error {
Io(io::Error),
Std(Box<dyn error::Error + Send + Sync>),
InvalidUri(InvalidUri),
Resolve,
Timeout(TimeoutError),
TlsNotEnabled,
#[cfg(feature = "http1")]
H1(crate::h1::Error),
#[cfg(feature = "http2")]
Expand Down Expand Up @@ -95,9 +92,48 @@ pub enum TimeoutError {
Response,
}

impl fmt::Display for TimeoutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Resolve => f.write_str("dns look up timeout"),
Self::Connect => f.write_str("socket connect timeout"),
Self::TlsHandshake => f.write_str("tls handshake timeout"),
Self::Request => f.write_str("request sending timeout"),
Self::Response => f.write_str("response receiving timeout"),
}
}
}

impl error::Error for TimeoutError {}

impl From<TimeoutError> for Error {
fn from(e: TimeoutError) -> Self {
Self::Timeout(e)
Self::Std(Box::new(e))
}
}

#[derive(Debug)]
pub struct ResolveError {
domain: String,
}

impl ResolveError {
pub(crate) fn new(domain: impl Into<String>) -> Self {
Self { domain: domain.into() }
}
}

impl fmt::Display for ResolveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "domain: {} can't be resolved to socket address", self.domain)
}
}

impl error::Error for ResolveError {}

impl From<ResolveError> for Error {
fn from(e: ResolveError) -> Self {
Self::Std(Box::new(e))
}
}

Expand Down Expand Up @@ -222,6 +258,7 @@ pub enum FeatureError {
Http1NotEnabled,
Http2NotEnabled,
Http3NotEnabled,
TlsNotEnabled,
}

impl fmt::Display for FeatureError {
Expand All @@ -230,6 +267,7 @@ impl fmt::Display for FeatureError {
Self::Http1NotEnabled => f.write_str("http1")?,
Self::Http2NotEnabled => f.write_str("http2")?,
Self::Http3NotEnabled => f.write_str("http3")?,
Self::TlsNotEnabled => f.write_str("openssl or rustls")?,
};
f.write_str(" crate feature is not enabled")
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub use self::request::RequestBuilder;
pub use self::response::Response;
pub use self::service::{HttpService, Service, ServiceRequest};
pub use self::timeout::TimeoutConfig;
pub use self::tls::{connector::Connector, stream::TlsStream};
pub use self::tls::{connector::Connector, TlsStream};

// re-export http crate.
pub use xitca_http::http;
Expand Down
10 changes: 9 additions & 1 deletion client/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,15 @@ pub(crate) fn base_service() -> HttpService {
{
_spawner.spawned(conn.into());
} else {
version = Version::HTTP_2;
#[cfg(feature = "http2")]
{
version = Version::HTTP_2;
}

#[cfg(not(feature = "http2"))]
{
version = Version::HTTP_11;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/tls/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
service::{Service, ServiceDyn},
};

use super::stream::TlsStream;
use super::TlsStream;

/// Connector for tls connections.
///
Expand All @@ -23,7 +23,7 @@ pub(crate) fn nop() -> Connector {
async fn call(&self, (_, _io): (&'n str, TlsStream)) -> Result<Self::Response, Self::Error> {
#[cfg(not(feature = "dangerous"))]
{
Err(Error::TlsNotEnabled)
Err(crate::error::FeatureError::TlsNotEnabled.into())
}

#[cfg(feature = "dangerous")]
Expand Down
3 changes: 2 additions & 1 deletion client/src/tls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub(crate) mod connector;
pub(crate) mod stream;

pub type TlsStream = Box<dyn xitca_io::io::AsyncIoDyn + Send + Sync>;
8 changes: 6 additions & 2 deletions http/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# unreleased 0.4.1
## Fix
- fix panic when using `rustls/ring` feature together with `xitca-http/rustls`
- fix panic when using `rustls/ring` feature together with `xitca-http/rustls-uring`

## Change
- update `xitca-io` to `0.2.1`.
- update `xitca-tls` to `0.2.2`.
- update `xitca-io` to `0.2.1`
- update `xitca-tls` to `0.2.3`

# 0.4.0
## Add
Expand Down
6 changes: 3 additions & 3 deletions http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ http3 = ["xitca-io/http3", "futures-util/alloc", "h3", "h3-quinn", "runtime"]
# openssl as server side tls.
openssl = ["xitca-tls/openssl", "runtime"]
# rustls as server side tls.
rustls = ["xitca-tls/rustls", "runtime"]
rustls = ["xitca-tls/rustls-no-crypto", "runtime"]
# rustls as server side tls.
rustls-uring = ["rustls", "xitca-tls/rustls-uring", "xitca-io/runtime-uring"]
rustls-uring = ["rustls", "xitca-tls/rustls-uring-no-crypto", "xitca-io/runtime-uring"]
# rustls as server side tls.
native-tls = ["dep:native-tls", "runtime"]
# async runtime feature.
Expand All @@ -48,7 +48,7 @@ tracing = { version = "0.1.40", default-features = false }
native-tls = { version = "0.2.7", features = ["alpn"], optional = true }

# tls support shared
xitca-tls = { version = "0.2.2", optional = true }
xitca-tls = { version = "0.2.3", optional = true }

# http/1 support
httparse = { version = "1.8", optional = true }
Expand Down
5 changes: 5 additions & 0 deletions tls/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# unreleased

# 0.2.3
## Add
- `rustls-no-crypto` feature
- `rustls-uring-no-crypto` feature

# 0.2.2
## Add
- `rustls-ring-crypto` feature
Expand Down
13 changes: 10 additions & 3 deletions tls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xitca-tls"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
license = "Apache-2.0"
description = "tls utility for xitca"
Expand All @@ -11,12 +11,19 @@ readme= "README.md"

[features]
openssl = ["dep:openssl"]
# rustls with no default crypto provider
rustls-no-crypto = ["rustls_crate"]
# rustls with aws-lc as crypto provider (default provider from `rustls` crate)
rustls = ["rustls_crate/aws-lc-rs"]
# rustls with ring as crypto provider
rustls-ring-crypto = ["rustls_crate/ring"]
rustls-uring = ["rustls_crate/default", "xitca-io/runtime-uring"]
# rustls with no crypto provider for xitca-io io-uring traits
rustls-uring-no-crypto = ["rustls_crate", "xitca-io/runtime-uring"]
# rustls with aws-lc as crypto provider for xitca-io io-uring trait (default provider from `rustls` crate)
rustls-uring = ["rustls_crate/aws-lc-rs", "xitca-io/runtime-uring"]

[dependencies]
xitca-io = { version = "0.2.1", features = ["runtime"] }

rustls_crate = { package = "rustls", version = "0.23", default-features = false, features = ["logging", "std", "tls12"], optional = true }
openssl = { version = "0.10", optional = true }
rustls_crate = { package = "rustls", version = "0.23", default-features = false, features = ["logging", "std", "tls12"], optional = true }
4 changes: 2 additions & 2 deletions tls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "openssl")]
pub mod openssl;
#[cfg(any(feature = "rustls", feature = "rustls-ring-crypto"))]
#[cfg(any(feature = "rustls", feature = "rustls-ring-crypto", feature = "rustls-no-crypto"))]
pub mod rustls;
#[cfg(feature = "rustls-uring")]
#[cfg(any(feature = "rustls-uring", feature = "rustls-uring-no-crypto"))]
pub mod rustls_uring;
7 changes: 6 additions & 1 deletion web/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# unreleased
# unreleased 0.4.1
## Fix
- fix panic when using `rustls/ring` feature together with `xitca-web/rustls`

## Change
- remove direct dependent on `openssl` and `rustls` crates

# 0.4.0
## Add
Expand Down
10 changes: 5 additions & 5 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xitca-web"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
license = "Apache-2.0"
description = "an async web framework"
Expand All @@ -22,7 +22,7 @@ io-uring = ["__server", "xitca-server/io-uring"]

# tls transport layer
openssl = ["__server", "xitca-http/openssl", "xitca-tls/openssl"]
rustls = ["__server", "xitca-http/rustls", "xitca-tls/rustls"]
rustls = ["__server", "xitca-http/rustls", "xitca-tls/rustls-no-crypto"]

# params type extractor
params = ["serde"]
Expand Down Expand Up @@ -76,9 +76,9 @@ serde = ["dep:serde"]
__server = ["xitca-http/runtime", "xitca-server"]

[dependencies]
xitca-http = { version = "0.4.0", features = ["router"], default-features = false }
xitca-http = { version = "0.4.1", features = ["router"], default-features = false }
xitca-service = { version = "0.1", features = ["alloc", "std"] }
xitca-unsafe-collection = "0.1"
xitca-unsafe-collection = "0.1.1"

futures-core = "0.3"
pin-project-lite = "0.2.9"
Expand All @@ -88,7 +88,7 @@ tokio = { version = "1", features = ["rt", "sync"] }
xitca-server = { version = "0.2", optional = true }

# tls
xitca-tls = { version = "0.2.2", optional = true }
xitca-tls = { version = "0.2.3", optional = true }

# (de)serialization shared.
serde = { version = "1", optional = true }
Expand Down
Loading