From fbaf9608d961e3205f396b565d019ed727a930c5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 30 Jul 2023 17:42:14 +0100 Subject: [PATCH] Use native rust tls - no openssl --- .github/workflows/release.yml | 12 +- Cargo.lock | 244 +++++++++++----------- Cargo.toml | 2 +- src/authenticator/access_token_fetcher.rs | 2 +- src/authenticator/mod.rs | 2 +- src/client/mod.rs | 4 +- src/sync/mod.rs | 4 +- 7 files changed, 133 insertions(+), 137 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 65c2adb..9adbbe2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,13 +25,19 @@ jobs: os: ubuntu-latest artifact_name: target/release/strava-rs asset_name: strava-rs-linux + - name: windows + os: windows-latest + artifact_name: target/release/strava-rs.exe + asset_name: strava-rs-windows + - name: macos + os: macos-latest + artifact_name: target/release/strava-rs + asset_name: strava-rs-macos steps: - uses: actions/checkout@v3 - - name: Install deps - run: sudo apt-get update && sudo apt-get install -y openssl-dev - name: Build - run: env OPENSSL_LIB_DIR=/usr/local/lib/ OPENSSL_INCLUDE_DIR=/usr/local/include OPENSSL_STATIC=yes cargo build --release --locked + run: cargo build --release --locked - name: Rename run: mv ${{ matrix.artifact_name }} ${{ matrix.asset_name }} diff --git a/Cargo.lock b/Cargo.lock index 103d6ee..a4727aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,6 +96,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + [[package]] name = "bitflags" version = "1.3.2" @@ -366,36 +372,12 @@ dependencies = [ "libc", ] -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.0" @@ -611,16 +593,19 @@ dependencies = [ ] [[package]] -name = "hyper-tls" -version = "0.5.0" +name = "hyper-rustls" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" dependencies = [ - "bytes", + "futures-util", + "http", "hyper", - "native-tls", + "log", + "rustls", + "rustls-native-certs", "tokio", - "tokio-native-tls", + "tokio-rustls", ] [[package]] @@ -682,15 +667,6 @@ version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c785eefb63ebd0e33416dfcb8d6da0bf27ce752843a45632a67bf10d4d4b5c4" -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "io-lifetimes" version = "1.0.11" @@ -729,12 +705,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.146" @@ -819,24 +789,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "num-traits" version = "0.2.15" @@ -882,50 +834,12 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "openssl" -version = "0.10.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -1085,6 +999,21 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + [[package]] name = "rustix" version = "0.37.20" @@ -1099,6 +1028,49 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustls" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79ea77c539259495ce8ca47f53e66ae0330a8819f67e23ac96ca02f50e7b7d36" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +dependencies = [ + "base64", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513722fd73ad80a71f72b61009ea1b584bcfa1483ca93949c8f290298837fa59" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.12" @@ -1113,11 +1085,11 @@ checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" [[package]] name = "schannel" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys 0.42.0", + "windows-sys 0.48.0", ] [[package]] @@ -1135,11 +1107,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "security-framework" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -1150,9 +1132,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" dependencies = [ "core-foundation-sys", "libc", @@ -1253,6 +1235,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "strava-rs" version = "0.1.0" @@ -1270,7 +1258,7 @@ dependencies = [ "geo-types", "geoutils", "hyper", - "hyper-tls", + "hyper-rustls", "libsqlite3-sys", "log", "open", @@ -1324,20 +1312,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" -dependencies = [ - "autocfg", - "cfg-if", - "fastrand", - "redox_syscall 0.3.5", - "rustix", - "windows-sys 0.48.0", -] - [[package]] name = "termcolor" version = "1.2.0" @@ -1453,12 +1427,12 @@ dependencies = [ ] [[package]] -name = "tokio-native-tls" -version = "0.3.1" +name = "tokio-rustls" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "native-tls", + "rustls", "tokio", ] @@ -1594,6 +1568,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "2.4.0" @@ -1692,6 +1672,16 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 5331071..b6faadf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ libsqlite3-sys = { version = ">=0.17.2, <0.27.0", features = ["bundled_bindings" env_logger = "0.10.0" futures-util = "0.3.25" hyper = { version = "0.14.23", features = ["client", "full"] } -hyper-tls = "0.5.0" log = "0.4.17" open = "3.2.0" serde = { version = "1.0.152", features = ["derive"] } @@ -33,3 +32,4 @@ diesel_migrations = { version = "2.1.0", features = ["sqlite"] } tui = { package = "ratatui", version = "0.22.0", features = ["all-widgets"]} tui-input = "0.7.1" confy = "0.5.1" +hyper-rustls = "0.24.1" diff --git a/src/authenticator/access_token_fetcher.rs b/src/authenticator/access_token_fetcher.rs index 7045f4c..6a36f48 100644 --- a/src/authenticator/access_token_fetcher.rs +++ b/src/authenticator/access_token_fetcher.rs @@ -1,5 +1,5 @@ use hyper::{client::HttpConnector, Body, Client, Request, Response}; -use hyper_tls::HttpsConnector; +use hyper_rustls::HttpsConnector; use super::AuthResponse; diff --git a/src/authenticator/mod.rs b/src/authenticator/mod.rs index 415c7ab..49dcd73 100644 --- a/src/authenticator/mod.rs +++ b/src/authenticator/mod.rs @@ -3,7 +3,7 @@ mod auth_code_fetcher; mod token_store; use std::time::{SystemTime, UNIX_EPOCH}; -use hyper_tls::HttpsConnector; +use hyper_rustls::HttpsConnector; use serde::{Deserialize, Serialize}; use hyper::{client::HttpConnector, Client}; diff --git a/src/client/mod.rs b/src/client/mod.rs index 0d80258..e934659 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -4,14 +4,14 @@ use std::{fmt::Display}; use chrono::{DateTime, NaiveDateTime, Utc}; use hyper::{client::HttpConnector, Body, Client, Method, Request, Response}; -use hyper_tls::HttpsConnector; +use hyper_rustls::{HttpsConnectorBuilder, HttpsConnector}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_json::Value; use crate::event::{logger::Logger}; pub fn new_strava_client(config: StravaConfig, logger: Logger) -> StravaClient { - let connector = HttpsConnector::new(); + let connector = HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build(); let client = Client::builder().build(connector); StravaClient { diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 332f9e0..b09d0b9 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -1,7 +1,7 @@ use diesel::{r2d2::{ConnectionManager, Pool}, SqliteConnection}; use hyper::Client; -use hyper_tls::HttpsConnector; +use hyper_rustls::HttpsConnectorBuilder; use tokio::{task, sync::mpsc::Receiver}; use crate::{authenticator::Authenticator, event::{input::EventSender, logger::Logger}, client::{StravaConfig, new_strava_client}}; @@ -21,7 +21,7 @@ pub async fn spawn_sync( logger: Logger, mut sync_receiver: Receiver, ) -> task::JoinHandle<()> { - let connector = HttpsConnector::new(); + let connector = HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build(); let mut sync_conn = pool.get().unwrap(); let event_sender = event_sender;