-
Notifications
You must be signed in to change notification settings - Fork 0
/
quic_clienthello.go
48 lines (39 loc) · 1.13 KB
/
quic_clienthello.go
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
package clienthellod
import (
"bytes"
)
// QUICClientHello represents a QUIC ClientHello.
type QUICClientHello struct {
ClientHello
}
// ParseQUICClientHello parses a QUIC ClientHello from a QUIC Initial Packet.
func ParseQUICClientHello(p []byte) (*QUICClientHello, error) {
// patch TLS record header to make it a valid TLS record
record := make([]byte, 5+len(p))
record[0] = 0x16 // TLS handshake
record[1] = 0x00 // Dummy TLS version MSB - 00
record[2] = 0x00 // Dummy TLS version LSB - 00
record[3] = byte(len(p) >> 8)
record[4] = byte(len(p))
copy(record[5:], p)
// parse TLS record
r := bytes.NewReader(record)
ch, err := ReadClientHello(r)
if err != nil {
return nil, err
}
if err = ch.ParseClientHello(); err != nil {
return nil, err
}
if ch.qtp == nil {
return nil, ErrNotQUICInitialPacket
}
if ch.qtp.ParseError() != nil {
return nil, ch.qtp.ParseError()
}
return &QUICClientHello{ClientHello: *ch}, nil
}
// Raw returns the raw bytes of the QUIC ClientHello.
func (qch *QUICClientHello) Raw() []byte {
return qch.ClientHello.Raw()[5:] // strip TLS record header which is added by ParseQUICClientHello
}