Properly handle DST transitions in cron jobs (fixes #2366)

This commit is contained in:
mdecimus
2025-11-02 16:10:55 +01:00
parent 3d20a82354
commit c088110da1
4 changed files with 246 additions and 255 deletions

463
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,25 +4,26 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use aes_gcm_siv::{
AeadInPlace, Aes256GcmSiv, KeyInit, Nonce,
aead::{Aead, generic_array::GenericArray},
};
use aes_gcm_siv::{AeadInPlace, Aes256GcmSiv, KeyInit, Nonce, aead::Aead};
use store::blake3;
pub struct SymmetricEncrypt {
aes: Aes256GcmSiv,
}
//TODO: Remove allow deprecated when aes-gcm is updated
#[allow(deprecated)]
impl SymmetricEncrypt {
pub const ENCRYPT_TAG_LEN: usize = 16;
pub const NONCE_LEN: usize = 12;
pub fn new(key: &[u8], context: &str) -> Self {
SymmetricEncrypt {
aes: Aes256GcmSiv::new(&GenericArray::clone_from_slice(
&blake3::derive_key(context, key)[..],
)),
aes: Aes256GcmSiv::new(
&sha1::digest::generic_array::GenericArray::clone_from_slice(
&blake3::derive_key(context, key)[..],
),
),
}
}

View File

@@ -3,7 +3,6 @@
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use aes_gcm::{Aes128Gcm, Nonce, aead::Aead};
use hkdf::Hkdf;
use p256::{
@@ -11,7 +10,7 @@ use p256::{
ecdh::EphemeralSecret,
elliptic_curve::{rand_core::OsRng, sec1::ToEncodedPoint},
};
use sha2::{Sha256, digest::generic_array::GenericArray};
use sha2::Sha256;
use store::rand::Rng;
/*
@@ -158,10 +157,14 @@ fn hkdf_sha256(salt: &[u8], secret: &[u8], info: &[u8], len: usize) -> Result<Ve
Ok(okm)
}
// TODO: Remove allow deprecated when aes-gcm 0.10 is updated
#[allow(deprecated)]
fn aes_gcm_128_encrypt(key: &[u8], nonce: &[u8], data: &[u8]) -> Result<Vec<u8>, String> {
<Aes128Gcm as aes_gcm::KeyInit>::new(&GenericArray::clone_from_slice(key))
.encrypt(Nonce::from_slice(nonce), data)
.map_err(|e| e.to_string())
<Aes128Gcm as aes_gcm::KeyInit>::new(
&sha2::digest::generic_array::GenericArray::clone_from_slice(key),
)
.encrypt(Nonce::from_slice(nonce), data)
.map_err(|e| e.to_string())
}
fn generate_info(

View File

@@ -59,7 +59,15 @@ impl SimpleCron {
}
};
(next - now).to_std().unwrap()
(next - now).to_std().unwrap_or_else(|_| self.as_duration())
}
pub fn as_duration(&self) -> Duration {
match self {
SimpleCron::Day { .. } => Duration::from_secs(24 * 60 * 60),
SimpleCron::Week { .. } => Duration::from_secs(7 * 24 * 60 * 60),
SimpleCron::Hour { .. } => Duration::from_secs(60 * 60),
}
}
}