chore: update dependencies

This commit is contained in:
zhom
2026-07-08 01:18:48 +04:00
parent 23859333c6
commit 0b3857b361
12 changed files with 1440 additions and 1348 deletions
+7 -3
View File
@@ -1,10 +1,11 @@
use aes_gcm::{
aead::{Aead, AeadCore, KeyInit, OsRng},
aead::{Aead, KeyInit},
Aes256Gcm, Key, Nonce,
};
use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
use chrono::Utc;
use lazy_static::lazy_static;
use rand::RngExt;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
@@ -261,7 +262,9 @@ impl CloudAuthManager {
}
let vault_password = Self::get_vault_password();
let salt = SaltString::generate(&mut OsRng);
let salt_bytes: [u8; 16] = rand::rng().random();
let salt =
SaltString::encode_b64(&salt_bytes).map_err(|e| format!("Failed to encode salt: {e}"))?;
let argon2 = Argon2::default();
let password_hash = argon2
.hash_password(vault_password.as_bytes(), &salt)
@@ -273,7 +276,8 @@ impl CloudAuthManager {
.map_err(|_| "Invalid key length".to_string())?;
let key = Key::<Aes256Gcm>::from(key_bytes);
let cipher = Aes256Gcm::new(&key);
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
let nonce_bytes: [u8; 12] = rand::rng().random();
let nonce = Nonce::from(nonce_bytes);
let ciphertext = cipher
.encrypt(&nonce, data.as_bytes())
.map_err(|e| format!("Encryption failed: {e}"))?;
+17 -7
View File
@@ -3,10 +3,11 @@ use std::fs::{self, create_dir_all};
use std::path::PathBuf;
use aes_gcm::{
aead::{Aead, AeadCore, KeyInit, OsRng},
aead::{Aead, KeyInit},
Aes256Gcm, Key, Nonce,
};
use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
use rand::RngExt;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct TableSortingSettings {
@@ -224,7 +225,9 @@ impl SettingsManager {
let vault_password = Self::get_vault_password();
// Generate a random salt for Argon2
let salt = SaltString::generate(&mut OsRng);
let salt_bytes: [u8; 16] = rand::rng().random();
let salt =
SaltString::encode_b64(&salt_bytes).map_err(|e| format!("Failed to encode salt: {e}"))?;
// Use Argon2 to derive a 32-byte key from the vault password
let argon2 = Argon2::default();
@@ -242,7 +245,8 @@ impl SettingsManager {
let cipher = Aes256Gcm::new(&key);
// Generate a random nonce
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
let nonce_bytes: [u8; 12] = rand::rng().random();
let nonce = Nonce::from(nonce_bytes);
// Encrypt the token
let ciphertext = cipher
@@ -408,7 +412,9 @@ impl SettingsManager {
}
let vault_password = Self::get_vault_password();
let salt = SaltString::generate(&mut OsRng);
let salt_bytes: [u8; 16] = rand::rng().random();
let salt =
SaltString::encode_b64(&salt_bytes).map_err(|e| format!("Failed to encode salt: {e}"))?;
let argon2 = Argon2::default();
let password_hash = argon2
.hash_password(vault_password.as_bytes(), &salt)
@@ -420,7 +426,8 @@ impl SettingsManager {
.map_err(|_| "Invalid key length")?;
let key = Key::<Aes256Gcm>::from(key_bytes);
let cipher = Aes256Gcm::new(&key);
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
let nonce_bytes: [u8; 12] = rand::rng().random();
let nonce = Nonce::from(nonce_bytes);
let ciphertext = cipher
.encrypt(&nonce, token.as_bytes())
.map_err(|e| format!("Encryption failed: {e}"))?;
@@ -548,7 +555,9 @@ impl SettingsManager {
}
let vault_password = Self::get_vault_password();
let salt = SaltString::generate(&mut OsRng);
let salt_bytes: [u8; 16] = rand::rng().random();
let salt =
SaltString::encode_b64(&salt_bytes).map_err(|e| format!("Failed to encode salt: {e}"))?;
let argon2 = Argon2::default();
let password_hash = argon2
.hash_password(vault_password.as_bytes(), &salt)
@@ -560,7 +569,8 @@ impl SettingsManager {
.map_err(|_| "Invalid key length")?;
let key = Key::<Aes256Gcm>::from(key_bytes);
let cipher = Aes256Gcm::new(&key);
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
let nonce_bytes: [u8; 12] = rand::rng().random();
let nonce = Nonce::from(nonce_bytes);
let ciphertext = cipher
.encrypt(&nonce, token.as_bytes())
.map_err(|e| format!("Encryption failed: {e}"))?;
+10 -7
View File
@@ -1,9 +1,10 @@
use aes_gcm::{
aead::{Aead, AeadCore, KeyInit, OsRng},
aead::{Aead, KeyInit},
Aes256Gcm, Key,
};
use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
use rand::RngExt;
use std::collections::HashMap;
use std::sync::Mutex;
@@ -55,7 +56,9 @@ pub fn store_e2e_password(password: &str) -> Result<(), String> {
}
let vault_password = get_vault_password();
let salt = SaltString::generate(&mut OsRng);
let salt_bytes: [u8; 16] = rand::rng().random();
let salt =
SaltString::encode_b64(&salt_bytes).map_err(|e| format!("Failed to encode salt: {e}"))?;
let argon2 = Argon2::default();
let password_hash = argon2
.hash_password(vault_password.as_bytes(), &salt)
@@ -68,7 +71,8 @@ pub fn store_e2e_password(password: &str) -> Result<(), String> {
.map_err(|_| "Invalid key length")?;
let key = Key::<Aes256Gcm>::from(key_bytes);
let cipher = Aes256Gcm::new(&key);
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
let nonce_bytes: [u8; 12] = rand::rng().random();
let nonce = aes_gcm::Nonce::from(nonce_bytes);
let ciphertext = cipher
.encrypt(&nonce, password.as_bytes())
@@ -230,9 +234,7 @@ pub fn derive_profile_key(user_password: &str, profile_salt: &str) -> Result<[u8
/// Generate a random 16-byte salt, base64-encoded
pub fn generate_salt() -> String {
let mut salt = [0u8; 16];
use aes_gcm::aead::rand_core::RngCore;
OsRng.fill_bytes(&mut salt);
let salt: [u8; 16] = rand::rng().random();
BASE64.encode(salt)
}
@@ -240,7 +242,8 @@ pub fn generate_salt() -> String {
pub fn encrypt_bytes(key: &[u8; 32], plaintext: &[u8]) -> Result<Vec<u8>, String> {
let aes_key = Key::<Aes256Gcm>::from(*key);
let cipher = Aes256Gcm::new(&aes_key);
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
let nonce_bytes: [u8; 12] = rand::rng().random();
let nonce = aes_gcm::Nonce::from(nonce_bytes);
let ciphertext = cipher
.encrypt(&nonce, plaintext)
+5 -8
View File
@@ -194,10 +194,10 @@ impl VpnStorage {
.map_err(|e| VpnError::Encryption(format!("Failed to create cipher: {e}")))?;
let nonce_bytes: [u8; 12] = rand::rng().random();
let nonce = Nonce::from_slice(&nonce_bytes);
let nonce = Nonce::from(nonce_bytes);
let ciphertext = cipher
.encrypt(nonce, data.as_bytes())
.encrypt(&nonce, data.as_bytes())
.map_err(|e| VpnError::Encryption(format!("Encryption failed: {e}")))?;
Ok((
@@ -218,14 +218,11 @@ impl VpnStorage {
let nonce_bytes = base64::Engine::decode(&base64::engine::general_purpose::STANDARD, nonce_str)
.map_err(|e| VpnError::Encryption(format!("Failed to decode nonce: {e}")))?;
if nonce_bytes.len() != 12 {
return Err(VpnError::Encryption("Invalid nonce length".to_string()));
}
let nonce = Nonce::from_slice(&nonce_bytes);
let nonce = Nonce::try_from(nonce_bytes.as_slice())
.map_err(|_| VpnError::Encryption("Invalid nonce length".to_string()))?;
let plaintext = cipher
.decrypt(nonce, ciphertext.as_ref())
.decrypt(&nonce, ciphertext.as_ref())
.map_err(|e| VpnError::Encryption(format!("Decryption failed: {e}")))?;
String::from_utf8(plaintext)