diff --git a/Cargo.toml b/Cargo.toml index b693a4b..210f9ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,9 @@ name = "signal-decrypt-backup-rust" version = "0.1.0" edition = "2021" +description = "Get all the data from your Signal backup." +repository = "https://git.duskflower.dev/duskflower/signal-decrypt-backup-rust" +license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/Readme.md b/Readme.md index 7a28a38..1280359 100644 --- a/Readme.md +++ b/Readme.md @@ -1,9 +1,9 @@ # signal-decrypt-backup-rust A port of [https://github.com/mossblaser/signal_for_android_decryption](signal_for_android_decryption) in Rust. -This port was done for speed improvements and easier integration with wasm. +This port was done for speed improvements and easier integration with wasm. It was almost completely done by an AI. -The wasm version is available at [https://git.duskflower.dev/duskflower/signal-decrypt-backup-wasm](duskflower/signal-decrypt-backup-wasm) +The wasm version, which works quite differently but is based on this one, is available at [https://git.duskflower.dev/duskflower/signal-decrypt-backup-wasm](duskflower/signal-decrypt-backup-wasm) ## Build `cargo build` diff --git a/src/main.rs b/src/main.rs index b563ea9..941bc35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,6 +114,7 @@ fn parameter_to_native_type( Ok(None) } } + fn decrypt_frame( backup_file: &mut R, hmac_key: &[u8], @@ -139,11 +140,19 @@ fn decrypt_frame( Some(1) => { let mut encrypted_length = [0u8; 4]; backup_file.read_exact(&mut encrypted_length)?; + + println!("encrypted length bytes: {:02x?}", encrypted_length); + Mac::update(&mut hmac, &encrypted_length); let mut decrypted_length = encrypted_length; ctr.apply_keystream(&mut decrypted_length); - u32::from_be_bytes(decrypted_length) + + println!("decrypted length bytes: {:02x?}", decrypted_length); + + let len = u32::from_be_bytes(decrypted_length); + println!("length: {}", len); + len } Some(v) => { return Err(io::Error::new( @@ -170,10 +179,20 @@ fn decrypt_frame( Mac::update(&mut hmac, ciphertext_buf); let our_mac = hmac.finalize().into_bytes(); + println!( + "Their MAC: {:02x?}, Our MAC: {:02x?}", + their_mac, + &our_mac[..10] + ); + if their_mac != our_mac[..10] { return Err(io::Error::new( io::ErrorKind::InvalidData, - "MAC verification failed", + format!( + "MAC verification failed. Their MAC: {:02x?}, Our MAC: {:02x?}", + their_mac, + &our_mac[..10] + ), )); } @@ -219,12 +238,17 @@ fn decrypt_frame_payload( let mut their_mac = [0u8; 10]; backup_file.read_exact(&mut their_mac)?; + let our_mac = hmac.finalize().into_bytes(); if &their_mac != &our_mac[..10] { return Err(io::Error::new( io::ErrorKind::InvalidData, - "Bad MAC found. Passphrase may be incorrect or file corrupted or incompatible.", + format!( + "payload: MAC verification failed. Their MAC: {:02x?}, Our MAC: {:02x?}", + their_mac, + &our_mac[..10] + ), )); } @@ -241,6 +265,7 @@ where { let mut backup_file = BufReader::with_capacity(32 * 1024, backup_file); let total_size = backup_file.seek(SeekFrom::End(0))?; + // reset the reader backup_file.seek(SeekFrom::Start(0))?; let mut last_percentage = 0;