-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtls_type.go
249 lines (220 loc) · 6.21 KB
/
tls_type.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
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
package tcpip
import (
"crypto/x509"
)
const (
ContentTypeHandShake = 0x16
ContentTypeAlert = 0x15
ContentTypeApplicationData = 0x17
HandshakeTypeClientHello = 0x01
HandshakeTypeServerHello = 0x02
HandshakeTypeNewSessionTicket = 0x04
HandshakeTypeEncryptedExtensions = 0x08
HandshakeTypeClientKeyExchange = 0x10 //=16
HandshakeTypeCertificate = 0x0b //=11
HandshakeTypeServerKeyExchange = 0x0c
HandshakeTypeCertificateRequest = 0x0d
HandshakeTypeServerHelloDone = 0x0e
HandshakeTypeCertificateVerify = 0x0f
HandshakeTypeChangeCipherSpec = 0x14 //=20
HandshakeTypeFinished = 0x14
CurveIDx25519 = 0x1D
// 4.4.3. Certificate Verify
str0x20x64 = "20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020"
)
var TLS1_2 = []byte{0x03, 0x03}
var TLS1_3 = []byte{0x03, 0x04}
// 固定のラベル
var MasterSecretLable = []byte(`master secret`)
var KeyLable = []byte(`key expansion`)
var CLientFinishedLabel = []byte(`client finished`)
var ServerFinishedLabel = []byte(`server finished`)
// TLS1.3
var DerivedLabel = []byte(`derived`)
var ClienthsTraffic = []byte(`c hs traffic`)
var ClientapTraffic = []byte(`c ap traffic`)
var ServerhsTraffic = []byte(`s hs traffic`)
var ServerapTraffic = []byte(`s ap traffic`)
var FinishedLabel = []byte(`finished`)
// 4.4.3. Certificate Verify
//var str0x20x64 = []byte(`20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020`)
var serverCertificateContextString = []byte(`TLS 1.3, server CertificateVerify`)
// https://www.ipa.go.jp/security/rfc/RFC5246-AAJA.html
type TLSRecordHeader struct {
ContentType []byte
ProtocolVersion []byte
Length []byte
}
type ClientHello struct {
HandshakeType []byte
Length []byte
Version []byte
Random []byte
SessionIDLength []byte
SessionID []byte
CipherSuitesLength []byte
CipherSuites []byte
CompressionLength []byte
CompressionMethod []byte
ExtensionLength []byte
Extensions []byte
}
type ServerHello struct {
HandshakeType []byte
Length []byte
Version []byte
Random []byte
SessionIDLength []byte
SessionID []byte
CipherSuites []byte
CompressionMethod []byte
ExtensionLength []byte
TLSExtensions []TLSExtensions
}
type TLSExtensions struct {
Type []byte
Length []byte
Value interface{}
}
type ServerCertificate struct {
HandshakeType []byte
Length []byte
CertificatesRequestContextLength []byte
CertificatesLength []byte
Certificates []*x509.Certificate
}
// https://tex2e.github.io/rfc-translater/html/rfc8422.html
type ServerKeyExchange struct {
HandshakeType []byte
Length []byte
ECDiffieHellmanServerParams ECDiffieHellmanParam
}
type CertificateRequest struct {
HandshakeType []byte
Length []byte
CertificateTypesCount []byte
CertificateTypes []byte
SignatureHashAlgorithmsLength []byte
SignatureHashAlgorithms []byte
}
type ClientCertificate struct {
HandshakeType []byte
Length []byte
CertificatesLength []byte
CertificateLength []byte
Certificate []byte
}
// https://qiita.com/n-i-e/items/41673fd16d7bd1189a29
type ClientKeyExchange struct {
HandshakeType []byte
Length []byte
// RSA
EncryptedPreMasterSecretLength []byte
EncryptedPreMasterSecret []byte
// ECDHE
PubkeyLength []byte
Pubkey []byte
}
type CertificateVerify struct {
HandshakeType []byte
Length []byte
SignatureHashAlgorithms []byte
SignatureLength []byte
Signature []byte
}
type ServerHelloDone struct {
HandshakeType []byte
Length []byte
}
// https://www.ipa.go.jp/security/rfc/RFC5246-07JA.html#0743
type ECDiffieHellmanParam struct {
CurveType []byte
NamedCurve []byte
PubkeyLength []byte
Pubkey []byte
SignatureAlgorithm []byte
SignatureLength []byte
Signature []byte
}
type TLSProtocol struct {
RHeader TLSRecordHeader
HandshakeProtocol interface{}
}
type TCPandServerHello struct {
ACKFromClient TCPIP
TLSProcotocol []TLSProtocol
TLSProcotocolBytes []byte
ClientHelloRandom []byte
}
type MasterSecretInfo struct {
MasterSecret []byte
PreMasterSecret []byte
ServerRandom []byte
ClientRandom []byte
}
type KeyBlock struct {
ClientWriteKey []byte
ServerWriteKey []byte
ClientWriteIV []byte
ServerWriteIV []byte
}
type TLSInfo struct {
State int
Version []byte
MasterSecretInfo MasterSecretInfo
KeyBlock KeyBlock
KeyBlockTLS13 KeyBlockTLS13
Handshakemessages []byte
ServerHandshakeSeq int
ServerAppSeq int
ClientSequenceNum int
ClientHandshakeSeq int
ClientAppSeq int
ECDHEKeys ECDHEKeys
}
type ECDHEKeys struct {
PrivateKey []byte
PublicKey []byte
SharedKey []byte
}
type KeyBlockTLS13 struct {
handshakeSecret []byte
clientHandshakeSecret []byte
clientHandshakeKey []byte
clientHandshakeIV []byte
ClientFinishedKey []byte
serverHandshakeSecret []byte
serverHandshakeKey []byte
serverHandshakeIV []byte
ServerFinishedKey []byte
masterSecret []byte
clientAppSecret []byte
clientAppKey []byte
clientAppIV []byte
serverAppSecret []byte
serverAppKey []byte
serverAppIV []byte
}
type EncryptedExtensions struct {
HandshakeType []byte
Length []byte
ExtensionLength []byte
TLSExtensions []TLSExtensions
}
type FinishedMessage struct {
HandshakeType []byte
Length []byte
VerifyData []byte
}
type SessionTicket struct {
HandshakeType []byte
Length []byte
TicketLifeTime []byte
TicketAgeAdd []byte
TicketNonceLength []byte
TicketNonce []byte
TicketLength []byte
Ticket []byte
TicketExtensionLength []byte
TicketExtensions []byte
}