-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
corpus.go
146 lines (134 loc) · 4.34 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
package main
import (
"log"
"golang.org/x/exp/rand"
"github.com/quic-go/quic-go/fuzzing/header"
"github.com/quic-go/quic-go/fuzzing/internal/helper"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/wire"
)
const version = protocol.Version1
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.Version, numVersions)
for i := 0; i < numVersions; i++ {
versions[i] = protocol.Version(rand.Uint32())
}
return wire.ComposeVersionNegotiation(src, dest, versions)
}
func main() {
headers := []wire.Header{
{ // Initial without token
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
DestConnectionID: protocol.ParseConnectionID(getRandomData(8)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // Initial with Token
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
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
DestConnectionID: protocol.ParseConnectionID(getRandomData(12)),
Type: protocol.PacketTypeHandshake,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
{ // 0-RTT packet
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
SrcConnectionID: protocol.ParseConnectionID(getRandomData(8)),
DestConnectionID: protocol.ParseConnectionID(getRandomData(9)),
Type: protocol.PacketTypeRetry,
Token: getRandomData(1000),
Version: version,
},
}
for _, h := range headers {
extHdr := &wire.ExtendedHeader{
Header: h,
PacketNumberLen: protocol.PacketNumberLen(rand.Intn(4) + 1),
PacketNumber: protocol.PacketNumber(rand.Uint64()),
}
b, err := extHdr.Append(nil, version)
if err != nil {
log.Fatal(err)
}
if h.Type == protocol.PacketTypeRetry {
b = append(b, []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}...)
}
if h.Length > 0 {
b = append(b, make([]byte, h.Length)...)
}
if err := helper.WriteCorpusFileWithPrefix("corpus", b, header.PrefixLen); err != nil {
log.Fatal(err)
}
}
// short header
b, err := wire.AppendShortHeader(nil, protocol.ParseConnectionID(getRandomData(8)), 1337, protocol.PacketNumberLen2, protocol.KeyPhaseOne)
if err != nil {
log.Fatal(err)
}
if err := helper.WriteCorpusFileWithPrefix("corpus", b, 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)
}
}
}