AtlatestRepositorysigil-quic

sigil-quic / tree / scriptshandshake-spy.sgl

1;;; Test-only observation of actual returned buffers, without secret copies.
2;;; Import only from an instrumented remote handshake, never from the schedule.
3(define-library (sigil quic tests handshake spy)
4 (import (sigil crypto)
5 (sigil quic tls schedule)
6 (sigil quic tls transcript))
7 (export handshake-spy-reset! handshake-spy-fail! handshake-spy-inputs
8 handshake-spy-shares handshake-spy-public
9 handshake-spy-shared handshake-spy-early handshake-spy-handshake
10 handshake-spy-transcript handshake-spy-derive handshake-spy-master)
11 (begin
12 (define captured '())
13 (define generated '())
14 (define failure #f)
16 (define (handshake-spy-reset!)
17 (set! captured '())
18 (set! generated '())
19 (set! failure #f))
21 (define (handshake-spy-fail! stage)
22 (set! failure stage))
24 (define (handshake-spy-inputs)
25 captured)
27 (define (handshake-spy-shares)
28 generated)
30 (define (observation kind bytes)
31 (vector kind bytes
32 (let loop ((i 0))
33 (and (< i (bytevector-length bytes))
34 (or (not (= (bytevector-u8-ref bytes i) 0))
35 (loop (+ i 1)))))))
37 (define (observe! kind bytes)
38 (when (bytevector? bytes)
39 (set! captured (cons (observation kind bytes) captured)))
40 bytes)
42 (define (checkpoint! stage)
43 (when (eq? failure stage)
44 (error "QL7 injected handshake failure" stage)))
46 (define (handshake-spy-public private)
47 (set! generated (cons (observation 'key-private private) generated))
48 (checkpoint! 'key-generation-before)
49 (let ((public (x25519-public-key private)))
50 (checkpoint! 'key-generation-after)
51 (if (eq? failure 'key-generation-null) #f public)))
53 (define (handshake-spy-shared private peer)
54 (observe! 'private private)
55 (observe! 'shared (x25519-shared-secret private peer)))
57 (define (handshake-spy-early psk)
58 (checkpoint! 'early)
59 (observe! 'early (early-secret psk)))
61 (define (handshake-spy-handshake early shared)
62 (checkpoint! 'handshake)
63 (observe! 'handshake (handshake-secret early shared)))
65 (define (handshake-spy-transcript transcript)
66 (checkpoint! 'transcript)
67 (tls-transcript-hash transcript))
69 (define (handshake-spy-derive secret label hash)
70 (let ((kind (if (string=? label "c hs traffic") 'client-traffic 'server-traffic)))
71 (checkpoint! kind)
72 (observe! kind (derive-secret secret label hash))))
74 (define (handshake-spy-master secret)
75 (checkpoint! 'master)
76 (observe! 'master (master-secret secret)))))