From 3bfb55ece2f70fc9b1969a2ec9c55f7a00358b90 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Tue, 11 Oct 2022 23:31:21 +0200 Subject: Refactor base_conversion. Fix hmac byte bug. Moved the basis conversion into a submodule, to ease the upcoming rewrite. Add a couple of new integration tests. Fix a bug caused by misreading the PasswordMaker Pro HMAC code. --- tests/password_generation.rs | 99 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/password_generation.rs b/tests/password_generation.rs index 45c6afa..a8618a2 100644 --- a/tests/password_generation.rs +++ b/tests/password_generation.rs @@ -1,4 +1,4 @@ -use passwordmaker_rs::{PasswordMaker, Hasher, HasherList, HashAlgorithm}; +use passwordmaker_rs::{PasswordMaker, Hasher, HasherList, HashAlgorithm, LeetLevel}; use digest::Digest; use md4; use md5; @@ -73,4 +73,101 @@ fn default_settings() { ).unwrap(); let result = pwm.generate(".abcdefghij".to_owned(), "1".to_owned()).unwrap(); assert_eq!(result, "J3>'1F\"/"); +} + +#[test] +fn v06_compatibility_leading_zeros() { + let pwm = Pwm::new( + HashAlgorithm::Md5Version06, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "whatevr", + "", + "", + 8, + "", + "" + ).unwrap(); + let result = pwm.generate("01".to_owned(), "a".to_owned()).unwrap(); + assert_eq!(result, "00d2a735"); +} + +#[test] +fn regular_md5_no_leading_zeros() { + let pwm = Pwm::new( + HashAlgorithm::Md5, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "0123456789abcdef", + "", + "", + 8, + "", + "" + ).unwrap(); + let result = pwm.generate("01".to_owned(), "a".to_owned()).unwrap(); + assert_eq!(result, "d2a73551"); +} + +/// Tests compatibility with an edge case in the l33t generation of PasswordMaker Pro JavaScript Edition: Word-Final-Sigma. +#[test] +fn word_final_sigma_post_leet() { + let pwm = Pwm::new( + HashAlgorithm::Md4, + passwordmaker_rs::UseLeetWhenGenerating::After { level: LeetLevel::One }, + "ΣΔΠΖ", + "", + "", + 64, + "", + "" + ).unwrap(); + let result = pwm.generate("123456".to_owned(), "password".to_owned()).unwrap(); + assert_eq!(result, "ζδζσσπσζδδσδπζδδδπσπζπζδδζζππσζσσζδπδσζπζππδσπσζζπσζσδπζσζπδσςπδ"); //mind the lunate sigma at character position 61. +} + +#[test] +fn hmac_with_upper_bytes() { + let pwm = Pwm::new( + HashAlgorithm::HmacRipemd160, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./", + "", + "", + 41, + "", + "" + ).unwrap(); + let result = pwm.generate("€äß".to_owned(), "password".to_owned()).unwrap(); + assert_eq!(result, "CX'!aI7J+\\.x?:ua'vtaj~c_PBbfATer1tstX_n<}"); +} + +#[test] +fn v06_yeet_bytes() { + let pwm = Pwm::new( + HashAlgorithm::Md5Version06, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "notused", + "", + "", + 47, + "", + "" + ).unwrap(); + let result = pwm.generate("€äß".to_owned(), "password".to_owned()).unwrap(); + assert_eq!(result, "ea552be82dc75c12e6e9d9f30e643e63eeba34536077ce3"); +} + +#[test] +fn v06_yeet_bytes_hmac() { + let pwm = Pwm::new( + HashAlgorithm::HmacMd5Version06, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "notused", + "", + "", + 47, + "", + "" + ).unwrap(); + let result = pwm.generate("€äß".to_owned(), "password".to_owned()).unwrap(); + assert_eq!(result, "28e1392052364d34c7e42e2711ccdd62c67a0a30dbf568a"); } \ No newline at end of file -- cgit v1.2.3