From 8f6a1d83450737c69a6c54fe0ad186b79ee3f6b2 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sun, 15 Aug 2021 13:41:11 -0400 Subject: [PATCH] add encryption key tests to verify compatibility --- src/accountmanager.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/accountmanager.rs b/src/accountmanager.rs index bf1e819..9eb53ab 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -192,7 +192,7 @@ fn get_encryption_key(passkey: &String, salt: &String) -> anyhow::Result<[u8; KE let salt_bytes = base64::decode(salt)?; let mut full_key: [u8; KEY_SIZE_BYTES] = [0u8; KEY_SIZE_BYTES]; pbkdf2::derive( - pbkdf2::PBKDF2_HMAC_SHA256, + pbkdf2::PBKDF2_HMAC_SHA1, std::num::NonZeroU32::new(PBKDF2_ITERATIONS).unwrap(), &salt_bytes, password_bytes, @@ -341,3 +341,26 @@ mod tests { ); } } + +#[cfg(test)] +mod encryption_tests { + use super::*; + + /// This test ensures compatibility with SteamDesktopAuthenticator and with previous versions of steamguard-cli + #[test] + fn test_encryption_key() { + assert_eq!( + get_encryption_key(&"password".into(), &"GMhL0N2hqXg=".into()).unwrap(), + base64::decode("KtiRa4/OxW83MlB6URf+Z8rAGj7CBY+pDlwD/NuVo6Y=") + .unwrap() + .as_slice() + ); + + assert_eq!( + get_encryption_key(&"password".into(), &"wTzTE9A6aN8=".into()).unwrap(), + base64::decode("Dqpej/3DqEat0roJaHmu3luYgDzRCUmzX94n4fqvWj8=") + .unwrap() + .as_slice() + ); + } +}