From 76968b3584ac4a67d8c5ad38211c65695980ccc1 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 28 Jun 2024 17:46:37 +0200 Subject: [PATCH] add niklas suggestions --- client/transport/Cargo.toml | 2 +- client/transport/src/ws/mod.rs | 22 ++++++--------- client/ws-client/Cargo.toml | 4 +-- client/ws-client/src/lib.rs | 49 ++++------------------------------ jsonrpsee/Cargo.toml | 2 +- 5 files changed, 17 insertions(+), 62 deletions(-) diff --git a/client/transport/Cargo.toml b/client/transport/Cargo.toml index adda7b122b..8201788353 100644 --- a/client/transport/Cargo.toml +++ b/client/transport/Cargo.toml @@ -44,7 +44,7 @@ futures-channel = { version = "0.3.14", default-features = false, optional = tru [features] tls = ["rustls", "tokio-rustls", "rustls-pki-types"] tls-rustls-platform-verifier = ["tls", "rustls-platform-verifier"] -default = ["tls-rustls-platform-verifier"] +default = [] ws = [ "base64", diff --git a/client/transport/src/ws/mod.rs b/client/transport/src/ws/mod.rs index 959cae420d..01ba8f3dac 100644 --- a/client/transport/src/ws/mod.rs +++ b/client/transport/src/ws/mod.rs @@ -61,7 +61,6 @@ pub type CustomCertStore = rustls::ClientConfig; #[cfg(feature = "tls")] #[derive(Debug, Clone)] pub enum CertificateStore { - #[cfg(feature = "tls-rustls-platform-verifier")] /// Native. Native, /// Custom certificate store. @@ -102,9 +101,9 @@ pub struct WsTransportClientBuilder { } impl Default for WsTransportClientBuilder { - #[cfg(feature = "tls-rustls-platform-verifier")] fn default() -> Self { Self { + #[cfg(feature = "tls")] certificate_store: CertificateStore::Native, max_request_size: TEN_MB_SIZE_BYTES, max_response_size: TEN_MB_SIZE_BYTES, @@ -114,18 +113,6 @@ impl Default for WsTransportClientBuilder { tcp_no_delay: true, } } - - #[cfg(not(feature = "tls"))] - fn default() -> Self { - Self { - max_request_size: TEN_MB_SIZE_BYTES, - max_response_size: TEN_MB_SIZE_BYTES, - connection_timeout: Duration::from_secs(10), - headers: http::HeaderMap::new(), - max_redirections: 5, - tcp_no_delay: true, - } - } } impl WsTransportClientBuilder { @@ -629,6 +616,13 @@ fn build_tls_config(cert_store: &CertificateStore) -> Result rustls_platform_verifier::tls_config(), + #[cfg(not(feature = "tls-rustls-platform-verifier"))] + CertificateStore::Native => { + return Err(WsHandshakeError::CertificateStore(io::Error::new( + io::ErrorKind::Other, + "Native certificate store not supported, either call `Builder::with_custom_cert_store` or enable the `tls-rustls-platform-verifier` feature.", + ))) + } CertificateStore::Custom(cfg) => cfg.clone(), }; diff --git a/client/ws-client/Cargo.toml b/client/ws-client/Cargo.toml index 064d4bb724..4a4641b15e 100644 --- a/client/ws-client/Cargo.toml +++ b/client/ws-client/Cargo.toml @@ -16,7 +16,7 @@ publish = true [dependencies] http = "1" jsonrpsee-types = { workspace = true } -jsonrpsee-client-transport = { workspace = true, features = ["ws"], default-features = false } +jsonrpsee-client-transport = { workspace = true, features = ["ws"] } jsonrpsee-core = { workspace = true, features = ["async-client"] } url = "2.4.0" @@ -30,7 +30,7 @@ rustls = { version = "0.23.7", default-features = false, features = ["logging", [features] tls = ["jsonrpsee-client-transport/tls"] -tls-rustls-platform-verifier = ["jsonrpsee-client-transport/tls-rustls-platform-verifier"] +tls-rustls-platform-verifier = ["jsonrpsee-client-transport/tls-rustls-platform-verifier", "tls"] default = ["tls-rustls-platform-verifier"] [package.metadata.docs.rs] diff --git a/client/ws-client/src/lib.rs b/client/ws-client/src/lib.rs index 2fbe4bb624..03495101be 100644 --- a/client/ws-client/src/lib.rs +++ b/client/ws-client/src/lib.rs @@ -53,7 +53,7 @@ use url::Url; #[cfg(feature = "tls")] pub use jsonrpsee_client_transport::ws::CustomCertStore; -#[cfg(any(feature = "tls", feature = "tls-rustls-platform-verifier"))] +#[cfg(feature = "tls")] use jsonrpsee_client_transport::ws::CertificateStore; /// Builder for [`WsClient`]. @@ -83,7 +83,7 @@ use jsonrpsee_client_transport::ws::CertificateStore; /// ``` #[derive(Clone, Debug)] pub struct WsClientBuilder { - #[cfg(any(feature = "tls", feature = "tls-rustls-platform-verifier"))] + #[cfg(feature = "tls")] certificate_store: CertificateStore, max_request_size: u32, max_response_size: u32, @@ -100,9 +100,9 @@ pub struct WsClientBuilder { } impl Default for WsClientBuilder { - #[cfg(feature = "tls-rustls-platform-verifier")] fn default() -> Self { Self { + #[cfg(feature = "tls")] certificate_store: CertificateStore::Native, max_request_size: TEN_MB_SIZE_BYTES, max_response_size: TEN_MB_SIZE_BYTES, @@ -118,53 +118,14 @@ impl Default for WsClientBuilder { tcp_no_delay: true, } } - - #[cfg(not(any(feature = "tls", feature = "tls-rustls-platform-verifier")))] - fn default() -> Self { - Self { - max_request_size: TEN_MB_SIZE_BYTES, - max_response_size: TEN_MB_SIZE_BYTES, - request_timeout: Duration::from_secs(60), - connection_timeout: Duration::from_secs(10), - ping_config: None, - headers: HeaderMap::new(), - max_concurrent_requests: 256, - max_buffer_capacity_per_subscription: 1024, - max_redirections: 5, - id_kind: IdKind::Number, - max_log_length: 4096, - tcp_no_delay: true, - } - } } impl WsClientBuilder { /// Create a new WebSocket client builder. - #[cfg(any(not(feature = "tls"), feature = "tls-rustls-platform-verifier"))] pub fn new() -> WsClientBuilder { WsClientBuilder::default() } - /// Create a new WebSocket client builder. - #[cfg(feature = "tls")] - pub fn new(cfg: CustomCertStore) -> WsClientBuilder { - WsClientBuilder { - certificate_store: CertificateStore::Custom(cfg), - max_request_size: TEN_MB_SIZE_BYTES, - max_response_size: TEN_MB_SIZE_BYTES, - request_timeout: Duration::from_secs(60), - connection_timeout: Duration::from_secs(10), - ping_config: None, - headers: HeaderMap::new(), - max_concurrent_requests: 256, - max_buffer_capacity_per_subscription: 1024, - max_redirections: 5, - id_kind: IdKind::Number, - max_log_length: 4096, - tcp_no_delay: true, - } - } - /// Force to use a custom certificate store. /// /// # Optional @@ -359,7 +320,7 @@ impl WsClientBuilder { T: AsyncRead + AsyncWrite + Unpin + MaybeSend + 'static, { let transport_builder = WsTransportClientBuilder { - #[cfg(any(feature = "tls", feature = "tls-rustls-platform-verifier"))] + #[cfg(feature = "tls")] certificate_store: self.certificate_store.clone(), connection_timeout: self.connection_timeout, headers: self.headers.clone(), @@ -385,7 +346,7 @@ impl WsClientBuilder { /// Panics if being called outside of `tokio` runtime context. pub async fn build(self, url: impl AsRef) -> Result { let transport_builder = WsTransportClientBuilder { - #[cfg(any(feature = "tls", feature = "tls-rustls-platform-verifier"))] + #[cfg(feature = "tls")] certificate_store: self.certificate_store.clone(), connection_timeout: self.connection_timeout, headers: self.headers.clone(), diff --git a/jsonrpsee/Cargo.toml b/jsonrpsee/Cargo.toml index 448fe0f58f..5211011d3d 100644 --- a/jsonrpsee/Cargo.toml +++ b/jsonrpsee/Cargo.toml @@ -28,7 +28,7 @@ tracing = { version = "0.1.34", optional = true } tokio = { version = "1.23.1", optional = true } [features] -client-ws-transport-tls = ["jsonrpsee-client-transport/ws", "jsonrpsee-client-transport/tls"] +client-ws-transport-tls = ["jsonrpsee-client-transport/ws", "jsonrpsee-client-transport/tls-rustls-platform-verifier"] client-ws-transport-no-tls = ["jsonrpsee-client-transport/ws"] client-web-transport = ["jsonrpsee-client-transport/web"] async-client = ["jsonrpsee-core/async-client"]