Files
sabia/crates/sabia-core/tests/crack_roundtrip.rs
T
Lucas RayanandClaude Sonnet 5 55e19a8e5b
CI / Format and clippy (push) Successful in 1m13s
CI / Dependency audit (push) Successful in 13s
CI / Tests (Linux) (push) Successful in 1m35s
Release / Create release (push) Successful in 7s
CI / Check desktop app (Linux) (push) Successful in 3m19s
Release / CLI (linux-aarch64) (push) Successful in 1m3s
Release / CLI (linux-x86_64) (push) Successful in 1m28s
Release / Desktop app (linux-aarch64) (push) Successful in 7m16s
Release / Desktop app (linux-x86_64) (push) Successful in 10m17s
Release / Desktop app (windows) (push) Successful in 4m54s
chore(i18n): finish translating code comments and scripts to English
Completes the English-only standardization for code, comments, scripts
and CI templates (UI/CLI-facing strings stay bilingual pt-BR/en,
untouched). Covers the remaining crates/, apps/gui/ui/ and
apps/gui/src-tauri/ comments, .gitea/ workflow and template comments,
.githooks/ hooks, and the scripts/ source comments for the files
already renamed in a prior commit (check.sh, generate-logo.py,
install-hooks.sh).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VAyr8d7HuAdUGB6aA5xmDD
2026-10-30 20:44:39 -03:00

81 lines
3.2 KiB
Rust

//! Integration test: synthetic handshake -> `CrackTarget` -> `verify()` and
//! dictionary cracking across both EAPOL 4-way and PMKID modes.
//!
mod common;
use sabia_core::crack::{compute_mic, compute_pmkid, compute_ptk, derive_pmk, CrackTarget};
const BSSID: &str = "00:11:22:33:44:55";
const STATION: &str = "66:77:88:99:aa:bb";
#[test]
fn eapol_4way_roundtrip_verifies_password() {
let (m1, m2) = common::handshake_frames("MinhaRede", "senha-correta", 2, false);
let hs = common::synthetic_handshake("MinhaRede", BSSID, STATION, &m1, &m2);
let target = CrackTarget::from_handshake(&hs).expect("alvo EAPOL válido");
assert_eq!(target.method(), "EAPOL/CCMP");
assert!(target.verify("senha-correta"));
assert!(!target.verify("senha-errada"));
}
#[test]
fn pmkid_roundtrip_verifies_password() {
let (m1, _m2) = common::handshake_frames("MinhaRede", "senha-correta", 2, true);
let hs = common::synthetic_handshake("MinhaRede", BSSID, STATION, &m1, &[]);
let target = CrackTarget::from_handshake(&hs).expect("alvo PMKID válido");
assert_eq!(target.method(), "PMKID");
assert!(target.verify("senha-correta"));
assert!(!target.verify("senha-errada"));
}
#[test]
fn tkip_keyversion_roundtrip_verifies_password() {
let (m1, m2) = common::handshake_frames("RedeAntiga", "outra-senha", 1, false);
let hs = common::synthetic_handshake("RedeAntiga", BSSID, STATION, &m1, &m2);
let target = CrackTarget::from_handshake(&hs).expect("alvo EAPOL/TKIP válido");
assert_eq!(target.method(), "EAPOL/TKIP");
assert!(target.verify("outra-senha"));
assert!(!target.verify("senha-errada"));
}
#[test]
fn incomplete_handshake_without_pmkid_or_msg2_has_no_target() {
let (m1, _m2) = common::handshake_frames("MinhaRede", "senha-correta", 2, false);
// Without message 2 or a PMKID, the handshake is not yet crackable.
let hs = common::synthetic_handshake("MinhaRede", BSSID, STATION, &m1, &[]);
assert!(CrackTarget::from_handshake(&hs).is_none());
}
#[test]
fn derive_pmk_compute_ptk_and_mic_are_consistent() {
let ssid = "VetorDireto";
let password = "senha-direta";
let anonce = [0xaa; 32];
let snonce = [0xbb; 32];
let pmk = derive_pmk(password, ssid);
let ptk = compute_ptk(&pmk, &common::ap(), &common::sta(), &anonce, &snonce);
// Compute the MIC over a message 2 frame with its MIC field zeroed.
let mut m2 = common::key_frame(2, 2, snonce, &[]);
let mic = compute_mic(2, &ptk[..16], &m2, sabia_core::eapol::MIC_OFFSET).expect("mic");
m2[sabia_core::eapol::MIC_OFFSET..sabia_core::eapol::MIC_OFFSET + 16].copy_from_slice(&mic);
// Recomputing the MIC over the already-signed frame must yield the same digest
// (`compute_mic` zeroes the MIC slice before hashing).
let mic_again = compute_mic(2, &ptk[..16], &m2, sabia_core::eapol::MIC_OFFSET).expect("mic");
assert_eq!(mic, mic_again);
// Direct PMKID computation is deterministic and verifies via `CrackTarget::Pmkid`.
let pmkid = compute_pmkid(&pmk, &common::ap(), &common::sta());
assert_eq!(
pmkid,
compute_pmkid(&pmk, &common::ap(), &common::sta()),
"PMKID deve ser determinístico"
);
}