From c4ade92756797024a82f34ca7496ddadfd4a837b Mon Sep 17 00:00:00 2001 From: Friedrich Altheide <11352905+FriedrichAltheide@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:27:54 +0200 Subject: [PATCH] bump apns2 to upstream --- Cargo.lock | 164 +++++++++++++++++---------------------- Cargo.toml | 2 +- fpush-apns/src/config.rs | 20 +++++ fpush-apns/src/push.rs | 17 ++-- 4 files changed, 100 insertions(+), 103 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6429945..a85119f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,18 +4,25 @@ version = 3 [[package]] name = "a2" -version = "0.7.0" -source = "git+https://github.com/monal-im/apns2.git?branch=faltheide/sync#73ebf5a2c2b417d8901847e45a46d54b9003ff3d" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f279fc8b1f1a64138f0f4b9cda9be488ae35bc2f8556c7ffe60730f1c07d005a" dependencies = [ "base64 0.21.7", "erased-serde", - "http 0.2.12", - "hyper 0.14.30", - "hyper-alpn", + "http 1.1.0", + "http-body-util", + "hyper 1.4.1", + "hyper-rustls 0.26.0", + "hyper-util", "openssl", + "parking_lot", + "rustls 0.22.4", + "rustls-pemfile 2.1.3", "serde", "serde_json", "thiserror", + "tokio", ] [[package]] @@ -123,6 +130,12 @@ dependencies = [ "syn", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.3.0" @@ -804,6 +817,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "h2" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http 1.1.0", + "indexmap 2.3.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -992,7 +1024,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", + "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", "httparse", @@ -1015,6 +1047,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", + "h2 0.4.5", "http 1.1.0", "http-body 1.0.1", "httparse", @@ -1025,21 +1058,6 @@ dependencies = [ "want", ] -[[package]] -name = "hyper-alpn" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bafa0c8f13da51d474d0c0933c7abe8c50e5f8c7ad72ea34ba998104d9190760" -dependencies = [ - "hyper 0.14.30", - "log", - "rustls 0.20.9", - "rustls-pemfile 1.0.4", - "tokio", - "tokio-rustls 0.23.4", - "webpki-roots", -] - [[package]] name = "hyper-rustls" version = "0.24.2" @@ -1073,6 +1091,24 @@ dependencies = [ "tokio-rustls 0.25.0", ] +[[package]] +name = "hyper-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" +dependencies = [ + "futures-util", + "http 1.1.0", + "hyper 1.4.1", + "hyper-util", + "rustls 0.22.4", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.25.0", + "tower-service", + "webpki-roots", +] + [[package]] name = "hyper-util" version = "0.1.7" @@ -1796,21 +1832,6 @@ dependencies = [ "quick-error", ] -[[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 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi", -] - [[package]] name = "ring" version = "0.17.8" @@ -1821,8 +1842,8 @@ dependencies = [ "cfg-if", "getrandom", "libc", - "spin 0.9.8", - "untrusted 0.9.0", + "spin", + "untrusted", "windows-sys 0.52.0", ] @@ -1832,18 +1853,6 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustls" -version = "0.20.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" -dependencies = [ - "log", - "ring 0.16.20", - "sct", - "webpki", -] - [[package]] name = "rustls" version = "0.21.12" @@ -1851,7 +1860,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.17.8", + "ring", "rustls-webpki 0.101.7", "sct", ] @@ -1863,7 +1872,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" dependencies = [ "log", - "ring 0.17.8", + "ring", "rustls-pki-types", "rustls-webpki 0.102.6", "subtle", @@ -1926,8 +1935,8 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -1936,9 +1945,9 @@ version = "0.102.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" dependencies = [ - "ring 0.17.8", + "ring", "rustls-pki-types", - "untrusted 0.9.0", + "untrusted", ] [[package]] @@ -2020,8 +2029,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -2203,12 +2212,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -2385,17 +2388,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-rustls" -version = "0.23.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" -dependencies = [ - "rustls 0.20.9", - "tokio", - "webpki", -] - [[package]] name = "tokio-rustls" version = "0.24.1" @@ -2564,12 +2556,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "untrusted" version = "0.9.0" @@ -2742,23 +2728,13 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" -dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", -] - [[package]] name = "webpki-roots" -version = "0.22.6" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" dependencies = [ - "webpki", + "rustls-pki-types", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3ab627a..01097b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ google-fcm1 = { version = "5.0.2" } hyper-rustls = { version = "0.24", features = ["http2"] } hyper = { version = "0.14", features = ["client", "http2"] } -a2 = { git = "https://github.com/monal-im/apns2.git", branch = "faltheide/sync" } +a2 = { version = "0.10" } async-trait = { version = "^0.1" } diff --git a/fpush-apns/src/config.rs b/fpush-apns/src/config.rs index 635780a..053ec4e 100644 --- a/fpush-apns/src/config.rs +++ b/fpush-apns/src/config.rs @@ -11,6 +11,10 @@ pub struct AppleApnsConfig { additional_data: Option>, #[serde(default = "ApnsEndpoint::production")] environment: ApnsEndpoint, + #[serde(default = "AppleApnsConfig::default_pool_timeout")] + pool_idle_timeout: u64, + #[serde(default = "AppleApnsConfig::default_request_timeout")] + request_timeout: u64, } impl AppleApnsConfig { @@ -36,6 +40,22 @@ impl AppleApnsConfig { pub fn additional_data(&self) -> &Option> { &self.additional_data } + + pub fn pool_idle_timeout(&self) -> u64 { + self.pool_idle_timeout + } + + pub fn request_timeout(&self) -> u64 { + self.request_timeout + } + + pub fn default_pool_timeout() -> u64 { + 600 + } + + pub fn default_request_timeout() -> u64 { + 5 + } } #[derive(Debug, Deserialize)] diff --git a/fpush-apns/src/push.rs b/fpush-apns/src/push.rs index 7c131ea..5c47b4c 100644 --- a/fpush-apns/src/push.rs +++ b/fpush-apns/src/push.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use std::time::SystemTime; use a2::{ - Client, DefaultNotificationBuilder, NotificationBuilder, NotificationOptions, Priority, - PushType, + request::payload::PayloadLike, Client, ClientConfig, DefaultNotificationBuilder, + NotificationBuilder, NotificationOptions, Priority, PushType, }; use fpush_traits::push::{PushError, PushResult, PushTrait}; @@ -29,11 +29,12 @@ impl FpushApns { pub fn init(apns_config: &AppleApnsConfig) -> PushResult { let mut certificate = FpushApns::open_cert(apns_config.cert_file_path())?; - match Client::certificate( - &mut certificate, - apns_config.cert_password(), - apns_config.endpoint(), - ) { + + let mut client_config = ClientConfig::new(apns_config.endpoint()); + client_config.pool_idle_timeout_secs = Some(apns_config.pool_idle_timeout()); + client_config.request_timeout_secs = Some(apns_config.request_timeout()); + + match Client::certificate(&mut certificate, apns_config.cert_password(), client_config) { Ok(apns_conn) => { let wrapped_conn = Self { apns: apns_conn, @@ -71,7 +72,7 @@ impl PushTrait for FpushApns { apns_expiration: Some( SystemTime::now().elapsed().unwrap().as_secs() + 4 * 7 * 24 * 3600, ), - apns_push_type: PushType::Alert, + apns_push_type: Some(PushType::Alert), ..Default::default() }, );