From 49a264ba3fac2330f4a1ecb6f9ad8dc7d286b998 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Fri, 20 Aug 2021 10:01:23 -0400 Subject: [PATCH] move incorrect passkey error --- Cargo.lock | 13 ------------- Cargo.toml | 1 - src/accountmanager.rs | 5 +++++ src/encryption.rs | 7 +------ src/main.rs | 4 +--- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d741aa..dc5c2dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -808,18 +808,6 @@ version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" -[[package]] -name = "memoize" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb49e4361c7534fd1fd1d4a1da51b1bb4b254c5ebc519fc4e5dce578fd69f5d9" -dependencies = [ - "lazy_static 1.4.0", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "mime" version = "0.3.16" @@ -1863,7 +1851,6 @@ dependencies = [ "hmac-sha1", "lazy_static 1.4.0", "log", - "memoize", "proptest", "rand 0.8.4", "regex", diff --git a/Cargo.toml b/Cargo.toml index d85bacd..12672c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ ring = "0.16.20" aes = "0.7.4" block-modes = "0.8.1" thiserror = "1.0.26" -memoize = "0.1.9" [dev-dependencies] tempdir = "0.3" diff --git a/src/accountmanager.rs b/src/accountmanager.rs index 160b971..cb9fb1e 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -97,6 +97,9 @@ impl Manifest { let plaintext = crate::encryption::LegacySdaCompatible::decrypt( passkey, params, ciphertext, )?; + if plaintext[0] != '{' as u8 && plaintext[plaintext.len() - 1] != '}' as u8 { + return Err(ManifestAccountLoadError::IncorrectPasskey); + } let s = std::str::from_utf8(&plaintext).unwrap(); account = serde_json::from_str(&s)?; } @@ -195,6 +198,8 @@ impl Manifest { pub enum ManifestAccountLoadError { #[error("Manifest accounts are encrypted, but no passkey was provided.")] MissingPasskey, + #[error("Incorrect passkey provided.")] + IncorrectPasskey, #[error("Failed to decrypt account. {self:?}")] DecryptionFailed(#[from] crate::encryption::EntryEncryptionError), #[error("Failed to deserialize the account.")] diff --git a/src/encryption.rs b/src/encryption.rs index 07fbdfc..a1a74cc 100644 --- a/src/encryption.rs +++ b/src/encryption.rs @@ -131,9 +131,6 @@ impl EntryEncryptor for LegacySdaCompatible { let mut buffer = vec![0xffu8; 16 * size]; buffer[..decoded.len()].copy_from_slice(&decoded); let mut decrypted = cipher.decrypt(&mut buffer)?; - if decrypted[0] != '{' as u8 && decrypted[decrypted.len() - 1] != '}' as u8 { - return Err(EntryEncryptionError::IncorrectPasskey); - } let unpadded = Pkcs7::unpad(&mut decrypted)?; return Ok(unpadded.to_vec()); } @@ -141,8 +138,6 @@ impl EntryEncryptor for LegacySdaCompatible { #[derive(Debug, Error)] pub enum EntryEncryptionError { - #[error("Incorrect passkey provided.")] - IncorrectPasskey, #[error(transparent)] Unknown(#[from] anyhow::Error), } @@ -208,7 +203,7 @@ mod tests { fn test_ensure_encryption_symmetric() -> anyhow::Result<()> { let passkey = "password"; let params = EntryEncryptionParams::generate(); - let orig = "{{tactical glizzy}}".as_bytes().to_vec(); + let orig = "tactical glizzy".as_bytes().to_vec(); let encrypted = LegacySdaCompatible::encrypt(&passkey.clone().into(), ¶ms, orig.clone()).unwrap(); let result = LegacySdaCompatible::decrypt(&passkey.into(), ¶ms, encrypted).unwrap(); diff --git a/src/main.rs b/src/main.rs index d6856bb..5311a42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -193,9 +193,7 @@ fn main() { Ok(_) => break, Err( accountmanager::ManifestAccountLoadError::MissingPasskey - | accountmanager::ManifestAccountLoadError::DecryptionFailed( - encryption::EntryEncryptionError::IncorrectPasskey, - ), + | accountmanager::ManifestAccountLoadError::IncorrectPasskey, ) => { if passkey.is_some() { error!("Incorrect passkey");