guise 0.1.2

Canonical browser fingerprint bundles, human-behavior timing, and TLS profile re-exports for the Santh fleet
Documentation
//! Probe classifiers: map a probed JSON value to a `ProbeOutcome`.

use super::ProbeOutcome;
use crate::fingerprint::user_agent_facts;

pub(super) fn classify_must_be_undefined(v: &serde_json::Value) -> ProbeOutcome {
    if matches!(v, serde_json::Value::Null) {
        ProbeOutcome::Pass
    } else {
        ProbeOutcome::Critical(format!("expected undefined / null, got {v}"))
    }
}

/// `navigator.webdriver` is genuine on a real browser: the property is PRESENT
/// with value `false` (it only becomes `true` under automation). Hiding it to
/// `undefined`/`null` is itself a tell — a real, un-automated browser reports
/// `false`. So `false` (and, leniently, `null`) pass; `true` is the
/// automation-revealing Critical.
pub(super) fn classify_webdriver_ok(v: &serde_json::Value) -> ProbeOutcome {
    match v {
        serde_json::Value::Bool(false) | serde_json::Value::Null => ProbeOutcome::Pass,
        serde_json::Value::Bool(true) => {
            ProbeOutcome::Critical("navigator.webdriver === true — automation leak".to_string())
        }
        other => ProbeOutcome::Drift(format!("expected false, got {other}")),
    }
}

pub(super) fn classify_must_be_true(v: &serde_json::Value) -> ProbeOutcome {
    if v.as_bool() == Some(true) {
        ProbeOutcome::Pass
    } else {
        ProbeOutcome::Critical(format!("expected true, got {v}"))
    }
}

pub(super) fn classify_must_be_nonzero_int(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_u64().or(v.as_i64().map(|i| i as u64)) {
        Some(n) if n > 0 => ProbeOutcome::Pass,
        Some(0) => ProbeOutcome::Critical("expected nonzero count, got 0".to_string()),
        _ => ProbeOutcome::Drift(format!("expected integer, got {v}")),
    }
}

pub(super) fn classify_must_be_nonempty_string(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_str() {
        Some(s) if !s.is_empty() => ProbeOutcome::Pass,
        Some(_) => ProbeOutcome::Critical("expected nonempty string, got empty".to_string()),
        _ => ProbeOutcome::Drift(format!("expected string, got {v}")),
    }
}

pub(super) fn classify_must_be_empty_string(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_str() {
        Some("") => ProbeOutcome::Pass,
        Some(s) => ProbeOutcome::Critical(format!("expected empty string (Firefox vendor), got {s:?}")),
        _ => ProbeOutcome::Drift(format!("expected string, got {v}")),
    }
}

pub(super) fn classify_must_be_firefox_ua(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_str() {
        Some(ua) => {
            let facts = user_agent_facts(ua);
            if facts.headless {
                ProbeOutcome::Critical(format!("UA leaks a headless token: {ua}"))
            } else if matches!(facts.browser, crate::fingerprint::UserAgentBrowser::Firefox)
                && ua.contains("Gecko/")
            {
                ProbeOutcome::Pass
            } else {
                ProbeOutcome::Critical(format!("expected a Gecko/Firefox UA, got {ua}"))
            }
        }
        None => ProbeOutcome::Drift(format!("UA not a string: {v}")),
    }
}

pub(super) fn classify_must_be_chromium_ua(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_str() {
        Some(ua) => {
            let facts = user_agent_facts(ua);
            if facts.headless {
                ProbeOutcome::Critical(format!("UA leaks HeadlessChrome: {ua}"))
            } else if facts.chromium_major_version.is_some() {
                ProbeOutcome::Pass
            } else {
                ProbeOutcome::Drift(format!("non-Chromium UA: {ua}"))
            }
        }
        None => ProbeOutcome::Drift(format!("UA not a string: {v}")),
    }
}

pub(super) fn classify_must_not_contain_swiftshader(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_str() {
        Some(s) if s.to_lowercase().contains("swiftshader") => {
            ProbeOutcome::Critical(format!("renderer leaks SwiftShader: {s}"))
        }
        Some(s) if !s.is_empty() => ProbeOutcome::Pass,
        _ => ProbeOutcome::Drift(format!("expected non-empty renderer, got {v}")),
    }
}

pub(super) fn classify_must_be_at_least_4_int(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_u64() {
        Some(n) if n >= 4 => ProbeOutcome::Pass,
        Some(n) => ProbeOutcome::Drift(format!("expected >=4, got {n}")),
        _ => ProbeOutcome::Drift(format!("not an integer: {v}")),
    }
}

pub(super) fn classify_in_range(v: &serde_json::Value, min: u64, max: u64) -> ProbeOutcome {
    match v.as_u64() {
        Some(n) if (min..=max).contains(&n) => ProbeOutcome::Pass,
        Some(n) => ProbeOutcome::Drift(format!("expected [{min}, {max}], got {n}")),
        _ => ProbeOutcome::Drift(format!("not an integer: {v}")),
    }
}

pub(super) fn classify_hardware_concurrency(v: &serde_json::Value) -> ProbeOutcome {
    classify_in_range(v, 2, 16)
}
pub(super) fn classify_device_memory(v: &serde_json::Value) -> ProbeOutcome {
    classify_in_range(v, 1, 64)
}
pub(super) fn classify_color_depth(v: &serde_json::Value) -> ProbeOutcome {
    classify_in_range(v, 24, 30)
}
pub(super) fn classify_screen_size(v: &serde_json::Value) -> ProbeOutcome {
    classify_in_range(v, 390, 5120)
}
pub(super) fn classify_dpr(v: &serde_json::Value) -> ProbeOutcome {
    classify_in_range(v, 1, 5)
}
pub(super) fn classify_history(v: &serde_json::Value) -> ProbeOutcome {
    classify_in_range(v, 1, 100)
}

/// Canvas/audio fingerprint *randomization* is an optional per-session defense
/// strategy, NOT a property of a real browser. A genuine browser returns
/// DETERMINISTIC canvas/audio across reads (constant within a session), and
/// per-call randomization is itself a tell — fingerprinters (CreepJS) flag an
/// "unstable" canvas. So `true` (noise applied) passes, but `false` (a stable,
/// real-browser-like surface) is an informational Drift, never an
/// automation-revealing Critical. A real, un-automated Firefox returns `false`
/// here; flagging that Critical would be a false positive.
pub(super) fn classify_session_noise(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_bool() {
        Some(true) => ProbeOutcome::Pass,
        Some(false) => ProbeOutcome::Drift(
            "stable canvas/audio (real-browser-like); per-read randomization not applied".to_string(),
        ),
        _ => ProbeOutcome::Drift(format!("expected boolean, got {v}")),
    }
}

pub(super) fn classify_must_be_native_code(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_str() {
        Some(s) if s.contains("[native code]") => ProbeOutcome::Pass,
        Some(s) => ProbeOutcome::Critical(format!("toString leaks wrapper source: {s}")),
        _ => ProbeOutcome::Drift(format!("not a string: {v}")),
    }
}

// Array-length helpers (dead-code-tolerated until referenced).
#[allow(dead_code)]
pub(super) fn classify_array_at_least_2(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_array() {
        Some(arr) if arr.len() >= 2 => ProbeOutcome::Pass,
        Some(arr) => ProbeOutcome::Critical(format!("array length {} < 2", arr.len())),
        _ => ProbeOutcome::Drift(format!("not an array: {v}")),
    }
}

#[allow(dead_code)]
pub(super) fn classify_array_at_least_4(v: &serde_json::Value) -> ProbeOutcome {
    match v.as_array() {
        Some(arr) if arr.len() >= 4 => ProbeOutcome::Pass,
        Some(arr) => ProbeOutcome::Critical(format!("array length {} < 4", arr.len())),
        _ => ProbeOutcome::Drift(format!("not an array: {v}")),
    }
}