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

Update deps: tungstenite, tokio-rustls etc. #122

Merged
merged 3 commits into from
Dec 7, 2023
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
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tokio-rustls-native-certs = ["__rustls-tls", "rustls-native-certs"]
tokio-openssl = ["tokio-runtime", "real-tokio-openssl", "openssl"]
verbose-logging = []

__rustls-tls = ["tokio-runtime", "real-tokio-rustls", "tungstenite/__rustls-tls"]
__rustls-tls = ["tokio-runtime", "real-tokio-rustls", "rustls-pki-types", "tungstenite/__rustls-tls"]

[package.metadata.docs.rs]
features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"]
Expand All @@ -41,7 +41,7 @@ futures-io = { version = "0.3", default-features = false, features = ["std"] }
pin-project-lite = "0.2"

[dependencies.tungstenite]
version = "0.20"
version = "0.21"
default-features = false

[dependencies.async-std]
Expand Down Expand Up @@ -84,16 +84,20 @@ package = "tokio-native-tls"

[dependencies.real-tokio-rustls]
optional = true
version = "0.24"
version = "0.25"
package = "tokio-rustls"

[dependencies.rustls-pki-types]
optional = true
version = "1.0.1"

[dependencies.rustls-native-certs]
optional = true
version = "0.6"
version = "0.7"

[dependencies.webpki-roots]
optional = true
version = "0.25"
version = "0.26"

[dependencies.gio]
optional = true
Expand Down
24 changes: 6 additions & 18 deletions src/tokio/rustls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use real_tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};
use real_tokio_rustls::rustls::{ClientConfig, RootCertStore};
use real_tokio_rustls::{client::TlsStream, TlsConnector};
use rustls_pki_types::ServerName;

use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::error::TlsError;
Expand Down Expand Up @@ -48,11 +49,9 @@ where
#[cfg(feature = "tokio-rustls-native-certs")]
{
let native_certs = rustls_native_certs::load_native_certs()?;
let der_certs: Vec<Vec<u8>> =
native_certs.into_iter().map(|cert| cert.0).collect();
let total_number = der_certs.len();
let total_number = native_certs.len();
let (number_added, number_ignored) =
root_store.add_parsable_certificates(&der_certs);
root_store.add_parsable_certificates(native_certs);
log::debug!("Added {number_added}/{total_number} native root certificates (ignored {number_ignored})");
}
#[cfg(all(
Expand All @@ -61,26 +60,15 @@ where
not(feature = "tokio-rustls-manual-roots")
))]
{
use real_tokio_rustls::rustls::OwnedTrustAnchor;

root_store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().map(
|ta| {
OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
},
));
root_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
}
TlsConnector::from(std::sync::Arc::new(
ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_store)
sdroege marked this conversation as resolved.
Show resolved Hide resolved
.with_no_client_auth(),
))
};
let domain = ServerName::try_from(domain.as_str())
let domain = ServerName::try_from(domain)
.map_err(|_| Error::Tls(TlsError::InvalidDnsName))?;
connector.connect(domain, socket).await?
};
Expand Down
Loading