From 37406faa3275a7553acc27f2a77917d372680146 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 17 Jul 2024 18:44:09 +0200 Subject: [PATCH] Automatically regenerate CRLs at regular interval --- central_backend/Cargo.lock | 115 +++++++++++++++++++++++++++++++++++- central_backend/Cargo.toml | 4 +- central_backend/src/main.rs | 11 +++- 3 files changed, 125 insertions(+), 5 deletions(-) diff --git a/central_backend/Cargo.lock b/central_backend/Cargo.lock index f523954..af6b20c 100644 --- a/central_backend/Cargo.lock +++ b/central_backend/Cargo.lock @@ -386,6 +386,21 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.14" @@ -603,6 +618,8 @@ dependencies = [ "serde", "serde_json", "thiserror", + "tokio", + "tokio_schedule", "uuid", ] @@ -612,6 +629,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.5", +] + [[package]] name = "cipher" version = "0.4.4" @@ -1064,6 +1095,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "hkdf" version = "0.12.4" @@ -1218,6 +1255,29 @@ dependencies = [ "tracing", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -1425,6 +1485,25 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.36.0" @@ -2093,21 +2172,34 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.0" +version = "1.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "eb2caba9f80616f438e09748d5acda951967e1ea58508ef53d9c6402485a46df" dependencies = [ "backtrace", "bytes", "libc", "mio", + "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", + "tokio-macros", "windows-sys 0.48.0", ] +[[package]] +name = "tokio-macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" @@ -2154,6 +2246,16 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio_schedule" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c291c554da3518d6ef69c76ea35aabc78f736185a16b6017f6d1c224dac2e0" +dependencies = [ + "chrono", + "tokio", +] + [[package]] name = "tower" version = "0.4.13" @@ -2380,6 +2482,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/central_backend/Cargo.toml b/central_backend/Cargo.toml index 68a4928..d8e0fcd 100644 --- a/central_backend/Cargo.toml +++ b/central_backend/Cargo.toml @@ -29,4 +29,6 @@ actix-remote-ip = "0.1.0" futures-util = "0.3.30" uuid = { version = "1.9.1", features = ["v4", "serde"] } semver = { version = "1.0.23", features = ["serde"] } -lazy-regex = "3.1.0" \ No newline at end of file +lazy-regex = "3.1.0" +tokio = { version = "1.38.1", features = ["full"] } +tokio_schedule = "0.3.2" \ No newline at end of file diff --git a/central_backend/src/main.rs b/central_backend/src/main.rs index efd33af..3f40d90 100644 --- a/central_backend/src/main.rs +++ b/central_backend/src/main.rs @@ -5,6 +5,7 @@ use central_backend::energy::energy_actor::EnergyActor; use central_backend::server::servers; use central_backend::utils::files_utils::create_directory_if_missing; use futures::future; +use tokio_schedule::{every, Job}; #[actix_web::main] async fn main() -> std::io::Result<()> { @@ -23,9 +24,15 @@ async fn main() -> std::io::Result<()> { pki::initialize_devices_ca().expect("Failed to initialize devices CA!"); pki::initialize_server_ca().expect("Failed to initialize server certificate!"); + // Initialize CRL pki::refresh_crls().expect("Failed to initialize Root CA!"); - - // TODO : schedule CRL auto renewal + let refresh_crl = every(1).hour().perform(|| async { + log::info!("Periodic refresh of CRLs..."); + if let Err(e) = pki::refresh_crls() { + log::error!("Failed to perform auto refresh of CRLs! {e}"); + } + }); + tokio::spawn(refresh_crl); // Initialize energy actor let actor = EnergyActor::new()