forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
corpus.go
147 lines (137 loc) · 4.32 KB
/
corpus.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
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
package main
import (
"bytes"
"log"
"math/rand"
"github.com/btwiuse/quic/fuzzing/header"
"github.com/btwiuse/quic/fuzzing/internal/helper"
"github.com/btwiuse/quic/internal/protocol"
"github.com/btwiuse/quic/internal/wire"
)
const version = protocol.VersionTLS
func getRandomData(l int) []byte {
b := make([]byte, l)
rand.Read(b)
return b
}
func getVNP(src, dest protocol.ArbitraryLenConnectionID, numVersions int) []byte {
versions := make([]protocol.VersionNumber, numVersions)
for i := 0; i < numVersions; i++ {
versions[i] = protocol.VersionNumber(rand.Uint32())
}
return wire.ComposeVersionNegotiation(src, dest, versions)
}
func main() {
headers := []wire.Header{
{ // Initial without token
IsLongHeader: true,
SrcConnectionID: protocol.ParseConnectionID(getRandomData(3)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Initial without token, with zero-length src conn id
IsLongHeader: true,
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Initial with Token
IsLongHeader: true,
SrcConnectionID: protocol.ParseConnectionID(getRandomData(10)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(19)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
Token: getRandomData(25),
},
{ // Handshake packet
IsLongHeader: true,
SrcConnectionID: protocol.ParseConnectionID(getRandomData(5)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(10)),
Type: protocol.PacketTypeHandshake,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Handshake packet, with zero-length src conn id
IsLongHeader: true,
DestConnectionID: protocol.ParseConnectionID(getRandomData(12)),
Type: protocol.PacketTypeHandshake,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // 0-RTT packet
IsLongHeader: true,
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
Type: protocol.PacketType0RTT,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Retry Packet, with empty orig dest conn id
IsLongHeader: true,
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
Type: protocol.PacketTypeRetry,
Token: getRandomData(1000),
Version: version,
},
{ // Short-Header
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
},
}
for _, h := range headers {
extHdr := &wire.ExtendedHeader{
Header: h,
PacketNumberLen: protocol.PacketNumberLen(rand.Intn(4) + 1),
PacketNumber: protocol.PacketNumber(rand.Uint64()),
}
b := &bytes.Buffer{}
if err := extHdr.Write(b, version); err != nil {
log.Fatal(err)
}
if h.Type == protocol.PacketTypeRetry {
b.Write([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
}
if h.Length > 0 {
b.Write(make([]byte, h.Length))
}
if err := helper.WriteCorpusFileWithPrefix("corpus", b.Bytes(), header.PrefixLen); err != nil {
log.Fatal(err)
}
}
vnps := [][]byte{
getVNP(
protocol.ArbitraryLenConnectionID(getRandomData(8)),
protocol.ArbitraryLenConnectionID(getRandomData(10)),
4,
),
getVNP(
protocol.ArbitraryLenConnectionID(getRandomData(10)),
protocol.ArbitraryLenConnectionID(getRandomData(5)),
0,
),
getVNP(
protocol.ArbitraryLenConnectionID(getRandomData(3)),
protocol.ArbitraryLenConnectionID(getRandomData(19)),
100,
),
getVNP(
protocol.ArbitraryLenConnectionID(getRandomData(3)),
nil,
20,
),
getVNP(
nil,
protocol.ArbitraryLenConnectionID(getRandomData(10)),
5,
),
}
for _, vnp := range vnps {
if err := helper.WriteCorpusFileWithPrefix("corpus", vnp, header.PrefixLen); err != nil {
log.Fatal(err)
}
}
}