skyauth 0.1.0

High-assurance, formally verified OAuth 2.1 and RFC 9449 DPoP authentication engine for the AT Protocol (Bluesky)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
//! Bounded Model Checking Proof Harnesses with Mandatory Anti-Vacuity Gates.
//!
//! This module contains symbolic model checking proof harnesses verified with the Kani
//! Rust Model Checker (`cargo kani`).
//!
//! ## Anti-Vacuity Invariant (Zero Vacuous Proofs)
//!
//! A critical vulnerability in formal model checking is *vacuous proofs* — where overly
//! restrictive assumptions (`kani::assume()`) or dead code paths cause the model checker
//! to report success simply because no execution trace reaches the verification assertion.
//!
//! To prevent vacuous proofs, **every single harness in this module enforces mandatory
//! reachability conditions via `kani::cover!()` and [`AntiVacuityCoverage`]**.
//!
//! The harnesses verify:
//! 1. [`proof_single_use_state_consumption`]: Atomic single-use state transition invariant.
//! 2. [`proof_ssrf_restricted_ip_rejection`]: Absolute non-bypassability of SSRF boundary filters.
//! 3. [`proof_pkce_s256_verifier_bounds`]: Length and character domain bounds for PKCE S256.
//! 4. [`proof_constant_time_eq_soundness`]: Bitwise equality correctness of `constant_time_eq`.
//! 5. [`proof_dpop_htu_normalization_invariants`]: Target URI normalization invariants per RFC 9449.

use std::collections::HashSet;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::sync::atomic::{AtomicUsize, Ordering};

use crate::crypto::constant_time_eq;
use crate::dpop::normalize_htu;
use crate::pkce::{derive_s256_challenge, validate_verifier};
use crate::ssrf::{is_restricted_ip, is_restricted_ipv4, is_restricted_ipv6, SsrfFilter};
use crate::verification::verus_contracts::{
    ConstantTimeEqSpec, DPoPHtuFormalSpec, OAuthStateTransitionModel, PkceFormalSpec,
    SsrfFormalSpec,
};

/// Thread-safe coverage tracker ensuring all formal reachability branches are hit.
#[derive(Debug, Default)]
pub struct AntiVacuityCoverage {
    hit_points: std::sync::RwLock<HashSet<String>>,
    total_assertions: AtomicUsize,
}

impl AntiVacuityCoverage {
    /// Creates a new coverage tracker.
    #[must_use]
    pub fn new() -> Self {
        Self {
            hit_points: std::sync::RwLock::new(HashSet::new()),
            total_assertions: AtomicUsize::new(0),
        }
    }

    /// Records that a specific reachability condition was satisfied.
    pub fn cover(&self, tag: &str, condition: bool) {
        if condition {
            if let Ok(mut guard) = self.hit_points.write() {
                guard.insert(tag.to_string());
            }
        }
        self.total_assertions.fetch_add(1, Ordering::Relaxed);
    }

    /// Asserts that all required cover points were actively triggered during proof execution.
    ///
    /// # Panics
    /// Panics if any required cover tag was not reached, indicating a vacuous proof.
    #[allow(clippy::panic)]
    pub fn assert_all_covered(&self, required_tags: &[&str]) {
        let guard = match self.hit_points.read() {
            Ok(g) => g,
            Err(poisoned) => poisoned.into_inner(),
        };
        for tag in required_tags {
            assert!(
                guard.contains(*tag),
                "ANTI-VACUITY VIOLATION: Required cover point '{tag}' was never reached! Proof is vacuous."
            );
        }
    }

    /// Returns the number of distinct cover points triggered.
    #[must_use]
    pub fn covered_count(&self) -> usize {
        let guard = match self.hit_points.read() {
            Ok(g) => g,
            Err(poisoned) => poisoned.into_inner(),
        };
        guard.len()
    }
}

/// Global anti-vacuity recorder instance.
static GLOBAL_COVERAGE: std::sync::OnceLock<AntiVacuityCoverage> = std::sync::OnceLock::new();

/// Returns the global coverage instance.
#[must_use]
pub fn global_coverage() -> &'static AntiVacuityCoverage {
    GLOBAL_COVERAGE.get_or_init(AntiVacuityCoverage::new)
}

/// Helper macro for recording anti-vacuity reachability under both Kani and standard execution.
#[macro_export]
macro_rules! anti_vacuity_cover {
    ($tag:expr, $cond:expr) => {
        let cond_val = $cond;
        $crate::verification::kani_harnesses::global_coverage().cover($tag, cond_val);
        #[cfg(kani)]
        kani::cover!(cond_val, $tag);
    };
}

/// # Proof 1: Atomic Single-Use State Consumption Invariant
///
/// **Theorem**: An OAuth authorization state token can be consumed from `Pending` to `Consumed`
/// at most once across all possible thread executions, and once `Consumed`, all subsequent
/// `take_state` invocations deterministically return `None`.
///
/// **Anti-Vacuity Cover Points**:
/// - `state_inserted`: State successfully inserted into store.
/// - `first_take_success`: First `take_state` call returns `Some(entry)`.
/// - `second_take_rejected`: Second `take_state` call returns `None`.
/// - `expired_state_rejected`: State past TTL returns `None` and transitions to `Expired`.
/// - `uninitialized_state_rejected`: Non-existent state returns `None`.
/// - `concurrent_race_single_winner`: Exactly 1 of $N$ concurrent racers succeeds.
#[cfg_attr(kani, kani::proof)]
#[cfg_attr(kani, kani::unwind(10))]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
pub fn proof_single_use_state_consumption() {
    let mut model = OAuthStateTransitionModel::new();
    let state_token = "symbolic_state_token_123";
    let client_id = "https://app.example.com/client-metadata.json";
    let ttl_ticks = 100u64;

    // 1. Initial State: Uninitialized
    let initial_take = model.take_state(state_token, 0);
    assert!(initial_take.is_none());
    anti_vacuity_cover!("uninitialized_state_rejected", initial_take.is_none());

    // 2. State Insertion
    let inserted = model.insert(state_token, client_id, ttl_ticks, 10);
    assert!(inserted);
    anti_vacuity_cover!("state_inserted", inserted);
    assert!(model.verify_global_store_invariants());

    // 3. First Take (Active TTL): MUST succeed
    let first_take = model.take_state(state_token, 20);
    assert!(first_take.is_some());
    if let Some(entry) = &first_take {
        assert_eq!(entry.state_id, state_token);
        assert_eq!(entry.client_id, client_id);
    }
    anti_vacuity_cover!("first_take_success", first_take.is_some());
    assert!(model.verify_single_use_invariant(state_token));

    // 4. Second Take: MUST fail (Single-Use Guarantee)
    let second_take = model.take_state(state_token, 25);
    assert!(second_take.is_none());
    anti_vacuity_cover!("second_take_rejected", second_take.is_none());
    assert!(model.verify_single_use_invariant(state_token));

    // 5. Subsequent Take: MUST still fail
    let third_take = model.take_state(state_token, 30);
    assert!(third_take.is_none());
    assert!(model.verify_single_use_invariant(state_token));

    // 6. Expired State Behavior
    let expired_token = "symbolic_expired_state";
    let exp_inserted = model.insert(expired_token, client_id, 50, 0);
    assert!(exp_inserted);
    // Take at tick 60 (elapsed 60 >= 50 TTL)
    let exp_take = model.take_state(expired_token, 60);
    assert!(exp_take.is_none());
    anti_vacuity_cover!("expired_state_rejected", exp_take.is_none());

    // 7. Concurrent Race Simulation (50 racers)
    let race_token = "symbolic_race_state";
    assert!(model.insert(race_token, client_id, 100, 0));
    let (winners, losers) = model.simulate_concurrent_consumption_race(race_token, 50, 10);
    assert_eq!(winners, 1);
    assert_eq!(losers, 49);
    anti_vacuity_cover!(
        "concurrent_race_single_winner",
        winners == 1 && losers == 49
    );
    assert!(model.verify_single_use_invariant(race_token));
    assert!(model.verify_global_store_invariants());
}

/// # Proof 2: SSRF Restricted IP Rejection Non-Bypassability
///
/// **Theorem**: No IP address in any restricted space (RFC 1918 private, loopback, link-local,
/// cloud metadata `169.254.169.254`, CGNAT, ULA, or mapped IPv4) can pass SSRF filters when
/// `allow_insecure_localhost` is false.
///
/// **Anti-Vacuity Cover Points**:
/// - `rfc1918_10_blocked`: 10.0.0.0/8 rejected.
/// - `rfc1918_172_blocked`: 172.16.0.0/12 rejected.
/// - `rfc1918_192_blocked`: 192.168.0.0/16 rejected.
/// - `cloud_metadata_169_254_blocked`: 169.254.169.254 metadata rejected.
/// - `loopback_127_blocked`: 127.0.0.1 loopback rejected.
/// - `cgnat_100_64_blocked`: 100.64.0.1 CGNAT rejected.
/// - `ipv6_ula_fc00_blocked`: fc00::/7 ULA rejected.
/// - `ipv6_link_local_fe80_blocked`: fe80::/10 link-local rejected.
/// - `ipv4_mapped_ipv6_blocked`: ::ffff:10.0.0.1 mapped private rejected.
/// - `public_ip_allowed`: Valid public IP passes filter.
#[cfg_attr(kani, kani::proof)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
pub fn proof_ssrf_restricted_ip_rejection() {
    let filter = SsrfFilter::new(false);

    // 1. RFC 1918: 10.0.0.0/8
    let ip_10 = Ipv4Addr::new(10, 254, 1, 2);
    assert!(is_restricted_ip(IpAddr::V4(ip_10)));
    assert!(is_restricted_ipv4(&ip_10));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv4(&ip_10));
    assert!(filter.validate_ip(IpAddr::V4(ip_10)).is_err());
    anti_vacuity_cover!("rfc1918_10_blocked", is_restricted_ipv4(&ip_10));

    // 2. RFC 1918: 172.16.0.0/12
    let ip_172 = Ipv4Addr::new(172, 31, 255, 254);
    assert!(is_restricted_ip(IpAddr::V4(ip_172)));
    assert!(is_restricted_ipv4(&ip_172));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv4(&ip_172));
    assert!(filter.validate_ip(IpAddr::V4(ip_172)).is_err());
    anti_vacuity_cover!("rfc1918_172_blocked", is_restricted_ipv4(&ip_172));

    // 3. RFC 1918: 192.168.0.0/16
    let ip_192 = Ipv4Addr::new(192, 168, 100, 1);
    assert!(is_restricted_ip(IpAddr::V4(ip_192)));
    assert!(is_restricted_ipv4(&ip_192));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv4(&ip_192));
    assert!(filter.validate_ip(IpAddr::V4(ip_192)).is_err());
    anti_vacuity_cover!("rfc1918_192_blocked", is_restricted_ipv4(&ip_192));

    // 4. Cloud Metadata: 169.254.169.254
    let ip_meta = Ipv4Addr::new(169, 254, 169, 254);
    assert!(is_restricted_ip(IpAddr::V4(ip_meta)));
    assert!(is_restricted_ipv4(&ip_meta));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv4(&ip_meta));
    assert!(filter.validate_ip(IpAddr::V4(ip_meta)).is_err());
    anti_vacuity_cover!(
        "cloud_metadata_169_254_blocked",
        is_restricted_ipv4(&ip_meta)
    );

    // 5. Loopback: 127.0.0.1
    let ip_loop = Ipv4Addr::new(127, 0, 0, 1);
    assert!(is_restricted_ip(IpAddr::V4(ip_loop)));
    assert!(is_restricted_ipv4(&ip_loop));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv4(&ip_loop));
    assert!(filter.validate_ip(IpAddr::V4(ip_loop)).is_err());
    anti_vacuity_cover!("loopback_127_blocked", is_restricted_ipv4(&ip_loop));

    // 6. CGNAT: 100.64.0.1
    let ip_cgnat = Ipv4Addr::new(100, 64, 0, 1);
    assert!(is_restricted_ip(IpAddr::V4(ip_cgnat)));
    assert!(is_restricted_ipv4(&ip_cgnat));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv4(&ip_cgnat));
    assert!(filter.validate_ip(IpAddr::V4(ip_cgnat)).is_err());
    anti_vacuity_cover!("cgnat_100_64_blocked", is_restricted_ipv4(&ip_cgnat));

    // 7. IPv6 ULA: fc00::/7
    let ip_ula = Ipv6Addr::new(0xfc00, 0, 0, 0, 0, 0, 0, 1);
    assert!(is_restricted_ip(IpAddr::V6(ip_ula)));
    assert!(is_restricted_ipv6(&ip_ula));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv6(&ip_ula));
    assert!(filter.validate_ip(IpAddr::V6(ip_ula)).is_err());
    anti_vacuity_cover!("ipv6_ula_fc00_blocked", is_restricted_ipv6(&ip_ula));

    // 8. IPv6 Link-Local: fe80::/10
    let ip_fe80 = Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 1);
    assert!(is_restricted_ip(IpAddr::V6(ip_fe80)));
    assert!(is_restricted_ipv6(&ip_fe80));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv6(&ip_fe80));
    assert!(filter.validate_ip(IpAddr::V6(ip_fe80)).is_err());
    anti_vacuity_cover!("ipv6_link_local_fe80_blocked", is_restricted_ipv6(&ip_fe80));

    // 9. IPv4-mapped IPv6: ::ffff:10.0.0.1
    let mapped_priv = Ipv4Addr::new(10, 0, 0, 1).to_ipv6_mapped();
    assert!(is_restricted_ip(IpAddr::V6(mapped_priv)));
    assert!(is_restricted_ipv6(&mapped_priv));
    assert!(SsrfFormalSpec::spec_is_restricted_ipv6(&mapped_priv));
    assert!(filter.validate_ip(IpAddr::V6(mapped_priv)).is_err());
    anti_vacuity_cover!("ipv4_mapped_ipv6_blocked", is_restricted_ipv6(&mapped_priv));

    // 10. Public IP: 8.8.8.8 (MUST be allowed)
    let ip_pub = Ipv4Addr::new(8, 8, 8, 8);
    assert!(!is_restricted_ip(IpAddr::V4(ip_pub)));
    assert!(!is_restricted_ipv4(&ip_pub));
    assert!(!SsrfFormalSpec::spec_is_restricted_ipv4(&ip_pub));
    assert!(filter.validate_ip(IpAddr::V4(ip_pub)).is_ok());
    anti_vacuity_cover!("public_ip_allowed", !is_restricted_ipv4(&ip_pub));
}

/// # Proof 3: PKCE S256 Verifier Bounds & Character Domain
///
/// **Theorem**: A code verifier is accepted by `validate_verifier` if and only if its length
/// is in $[43, 128]$ and all characters belong to `[A-Za-z0-9-._~]`. Furthermore, S256 challenge
/// derivation strictly outputs a 43-character string.
///
/// **Anti-Vacuity Cover Points**:
/// - `valid_min_length_43_verifier`: Valid 43-char verifier accepted.
/// - `valid_max_length_128_verifier`: Valid 128-char verifier accepted.
/// - `valid_mid_length_verifier`: Valid 64-char verifier accepted.
/// - `invalid_short_length_rejected`: 42-char verifier rejected.
/// - `invalid_long_length_rejected`: 129-char verifier rejected.
/// - `invalid_character_rejected`: Verifier with illegal char (e.g. space, `+`) rejected.
/// - `challenge_length_is_43`: S256 challenge length is strictly 43.
#[cfg_attr(kani, kani::proof)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
pub fn proof_pkce_s256_verifier_bounds() {
    // 1. Min boundary: exactly 43 chars
    let min_verifier = "a".repeat(43);
    assert!(validate_verifier(&min_verifier).is_ok());
    assert!(PkceFormalSpec::spec_validate_verifier(
        min_verifier.as_bytes()
    ));
    let ch_min = derive_s256_challenge(&min_verifier);
    assert_eq!(ch_min.len(), 43);
    anti_vacuity_cover!(
        "valid_min_length_43_verifier",
        validate_verifier(&min_verifier).is_ok()
    );

    // 2. Max boundary: exactly 128 chars
    let max_verifier = "z".repeat(128);
    assert!(validate_verifier(&max_verifier).is_ok());
    assert!(PkceFormalSpec::spec_validate_verifier(
        max_verifier.as_bytes()
    ));
    let ch_max = derive_s256_challenge(&max_verifier);
    assert_eq!(ch_max.len(), 43);
    anti_vacuity_cover!(
        "valid_max_length_128_verifier",
        validate_verifier(&max_verifier).is_ok()
    );

    // 3. Mid length: 64 chars with unreserved symbols `-._~`
    let mid_verifier = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk.test~example-pkce-1234567";
    let mid_verifier = &mid_verifier[..64];
    assert!(validate_verifier(mid_verifier).is_ok());
    assert!(PkceFormalSpec::spec_validate_verifier(
        mid_verifier.as_bytes()
    ));
    anti_vacuity_cover!(
        "valid_mid_length_verifier",
        validate_verifier(mid_verifier).is_ok()
    );

    // 4. Invalid short: 42 chars
    let short_verifier = "a".repeat(42);
    assert!(validate_verifier(&short_verifier).is_err());
    assert!(!PkceFormalSpec::spec_validate_verifier(
        short_verifier.as_bytes()
    ));
    anti_vacuity_cover!(
        "invalid_short_length_rejected",
        validate_verifier(&short_verifier).is_err()
    );

    // 5. Invalid long: 129 chars
    let long_verifier = "a".repeat(129);
    assert!(validate_verifier(&long_verifier).is_err());
    assert!(!PkceFormalSpec::spec_validate_verifier(
        long_verifier.as_bytes()
    ));
    anti_vacuity_cover!(
        "invalid_long_length_rejected",
        validate_verifier(&long_verifier).is_err()
    );

    // 6. Invalid characters
    let illegal_space = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEj k";
    assert!(validate_verifier(illegal_space).is_err());
    assert!(!PkceFormalSpec::spec_validate_verifier(
        illegal_space.as_bytes()
    ));
    let illegal_plus = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEj+k";
    assert!(validate_verifier(illegal_plus).is_err());
    anti_vacuity_cover!(
        "invalid_character_rejected",
        validate_verifier(illegal_space).is_err()
    );

    // 7. Challenge length invariant
    anti_vacuity_cover!(
        "challenge_length_is_43",
        ch_min.len() == 43 && ch_max.len() == 43
    );
}

/// # Proof 4: Constant-Time Slice Equality Soundness
///
/// **Theorem**: `constant_time_eq(a, b)` returns `true` if and only if slices `a` and `b`
/// have identical lengths and identical byte contents at all indices.
///
/// **Anti-Vacuity Cover Points**:
/// - `equal_non_empty_slices_true`: Equal slices return `true`.
/// - `differing_first_byte_false`: Slices differing at index 0 return `false`.
/// - `differing_last_byte_false`: Slices differing at final index return `false`.
/// - `differing_middle_byte_false`: Slices differing at middle index return `false`.
/// - `mismatched_length_false`: Different length slices return `false`.
/// - `empty_slices_true`: Empty slices return `true`.
#[cfg_attr(kani, kani::proof)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
pub fn proof_constant_time_eq_soundness() {
    let s1 = b"cryptographic_secret_token_1234";
    let s2 = b"cryptographic_secret_token_1234";

    // 1. Equal slices
    assert!(constant_time_eq(s1, s2));
    assert!(ConstantTimeEqSpec::verify_soundness(s1, s2));
    anti_vacuity_cover!("equal_non_empty_slices_true", constant_time_eq(s1, s2));

    // 2. Differing first byte
    let mut diff_first = *s1;
    diff_first[0] ^= 0x01;
    assert!(!constant_time_eq(s1, &diff_first));
    assert!(ConstantTimeEqSpec::verify_soundness(s1, &diff_first));
    anti_vacuity_cover!(
        "differing_first_byte_false",
        !constant_time_eq(s1, &diff_first)
    );

    // 3. Differing last byte
    let mut diff_last = *s1;
    diff_last[s1.len() - 1] ^= 0x01;
    assert!(!constant_time_eq(s1, &diff_last));
    assert!(ConstantTimeEqSpec::verify_soundness(s1, &diff_last));
    anti_vacuity_cover!(
        "differing_last_byte_false",
        !constant_time_eq(s1, &diff_last)
    );

    // 4. Differing middle byte
    let mut diff_mid = *s1;
    diff_mid[s1.len() / 2] ^= 0x01;
    assert!(!constant_time_eq(s1, &diff_mid));
    assert!(ConstantTimeEqSpec::verify_soundness(s1, &diff_mid));
    anti_vacuity_cover!(
        "differing_middle_byte_false",
        !constant_time_eq(s1, &diff_mid)
    );

    // 5. Mismatched length
    let short = &s1[..16];
    assert!(!constant_time_eq(s1, short));
    assert!(ConstantTimeEqSpec::verify_soundness(s1, short));
    anti_vacuity_cover!("mismatched_length_false", !constant_time_eq(s1, short));

    // 6. Empty slices
    assert!(constant_time_eq(b"", b""));
    assert!(ConstantTimeEqSpec::verify_soundness(b"", b""));
    anti_vacuity_cover!("empty_slices_true", constant_time_eq(b"", b""));
}

/// # Proof 5: DPoP Target URI (`htu`) Normalization Invariants
///
/// **Theorem**: `normalize_htu(uri)` strictly strips query strings and fragments, lowercases
/// scheme and host, omits default ports (`http:80`, `https:443`), and preserves custom ports
/// and path casing per RFC 9449 § 4.2.
///
/// **Anti-Vacuity Cover Points**:
/// - `query_stripped_success`: Query string `?foo=bar` is stripped.
/// - `fragment_stripped_success`: Fragment `#section` is stripped.
/// - `port_443_stripped_success`: Default HTTPS port 443 is omitted.
/// - `port_80_stripped_success`: Default HTTP port 80 is omitted.
/// - `custom_port_preserved_success`: Custom port 8443 is preserved.
/// - `uppercase_host_lowercased_success`: Uppercase host `EXAMPLE.COM` is lowercased.
/// - `invalid_scheme_rejected`: Non-http(s) scheme (e.g. `ftp://`) is rejected.
#[cfg_attr(kani, kani::proof)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
pub fn proof_dpop_htu_normalization_invariants() {
    // 1. Query stripping
    if let Ok(res_query) = normalize_htu("https://example.com/oauth/token?grant_type=code") {
        assert_eq!(res_query, "https://example.com/oauth/token");
        assert!(DPoPHtuFormalSpec::spec_has_no_query(&res_query));
        anti_vacuity_cover!(
            "query_stripped_success",
            DPoPHtuFormalSpec::spec_has_no_query(&res_query)
        );
    }

    // 2. Fragment stripping
    if let Ok(res_frag) = normalize_htu("https://example.com/oauth/token#frag") {
        assert_eq!(res_frag, "https://example.com/oauth/token");
        assert!(DPoPHtuFormalSpec::spec_has_no_fragment(&res_frag));
        anti_vacuity_cover!(
            "fragment_stripped_success",
            DPoPHtuFormalSpec::spec_has_no_fragment(&res_frag)
        );
    }

    // 3. Port 443 stripping
    if let Ok(res_443) = normalize_htu("https://example.com:443/oauth/token") {
        assert_eq!(res_443, "https://example.com/oauth/token");
        assert!(DPoPHtuFormalSpec::spec_no_default_ports(&res_443));
        anti_vacuity_cover!(
            "port_443_stripped_success",
            DPoPHtuFormalSpec::spec_no_default_ports(&res_443)
        );
    }

    // 4. Port 80 stripping
    if let Ok(res_80) = normalize_htu("http://example.com:80/oauth/token") {
        assert_eq!(res_80, "http://example.com/oauth/token");
        assert!(DPoPHtuFormalSpec::spec_no_default_ports(&res_80));
        anti_vacuity_cover!(
            "port_80_stripped_success",
            DPoPHtuFormalSpec::spec_no_default_ports(&res_80)
        );
    }

    // 5. Custom port preservation
    if let Ok(res_custom) = normalize_htu("https://example.com:8443/oauth/token") {
        assert_eq!(res_custom, "https://example.com:8443/oauth/token");
        anti_vacuity_cover!(
            "custom_port_preserved_success",
            res_custom.contains(":8443")
        );
    }

    // 6. Uppercase host lowercasing
    if let Ok(res_case) = normalize_htu("https://AUTH.EXAMPLE.COM/Token/Path") {
        assert_eq!(res_case, "https://auth.example.com/Token/Path");
        assert!(DPoPHtuFormalSpec::spec_valid_scheme(&res_case));
        anti_vacuity_cover!(
            "uppercase_host_lowercased_success",
            res_case.starts_with("https://auth.example.com")
        );
    }

    // 7. Invalid scheme rejection
    let res_ftp = normalize_htu("ftp://example.com/token");
    assert!(res_ftp.is_err());
    anti_vacuity_cover!("invalid_scheme_rejected", res_ftp.is_err());
}