-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
134 lines (107 loc) · 3.59 KB
/
client_test.go
File metadata and controls
134 lines (107 loc) · 3.59 KB
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
package toyls
import (
"testing"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type ToySuite struct{}
var _ = Suite(&ToySuite{})
func (s *ToySuite) TestDeserializeClientHello(c *C) {
helloBody := []byte{
//client_version
0x03, 0x03, //ProtocolVersion
//random (Random)
0x00, 0x00, 0x00, 0x00, //gmt_unix_time
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, //random_bytes
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
//session_id (SessionID)
0x0A, //length
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //SessionID
//cipher_suites
0x00, 0x02, // length
0x00, 0x2f, // CipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA
//compression_methods
0x01, //length
0x00, //NULL
}
msg, err := deserializeClientHello(helloBody)
expected := &clientHelloBody{
clientVersion: protocolVersion{0x03, 0x03},
random: random{
0,
[28]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07},
},
sessionID: []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09},
cipherSuites: []cipherSuite{cipherSuite{0x00, 0x2f}},
compressionMethods: []byte{0x00},
}
c.Assert(err, IsNil)
c.Assert(msg, DeepEquals, expected)
}
func (s *ToySuite) TestDeserializeFailsWhenClientHelloCiphersOutOfRange(c *C) {
helloBody := []byte{
//client_version
0x03, 0x03, //ProtocolVersion
//random (Random)
0x00, 0x00, 0x00, 0x00, //gmt_unix_time
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, //random_bytes
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
//session_id (SessionID)
0x0A, //length
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //SessionID
//cipher_suites
0xff, 0xff, // length
0x00, 0x2f, // CipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA
//compression_methods
0x01, //length
0x00, //NULL
}
msg, err := deserializeClientHello(helloBody)
expected := &clientHelloBody{}
c.Assert(err, NotNil)
c.Assert(msg, DeepEquals, expected)
}
func (s *ToySuite) TestSerializeClientHello(c *C) {
helloBytes := &clientHelloBody{
clientVersion: protocolVersion{0x03, 0x03},
random: random{
1,
[28]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07},
},
sessionID: []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09},
cipherSuites: []cipherSuite{cipherSuite{0x00, 0x2f}},
compressionMethods: []byte{0x00},
}
msg, err := serializeClientHello(helloBytes)
expected := []byte{
//client_version
0x03, 0x03, //ProtocolVersion
//random (Random)
0x00, 0x00, 0x00, 0x01, //gmt_unix_time
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, //random_bytes
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
//session_id (SessionID)
0x0A, //length
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //SessionID
//cipher_suites
0x00, 0x02, // length
0x00, 0x2f, // CipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA
//compression_methods
0x01, //length
0x00, //NULL
}
c.Assert(err, IsNil)
c.Assert(msg, DeepEquals, expected)
}