-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsecurity_test.go
212 lines (203 loc) · 5.11 KB
/
security_test.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
package ntlmssp
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSignKey(t *testing.T) {
tables := []struct {
exportedSessionKey, constant, want []byte
}{
{
bytes.Repeat([]byte{0x55}, 16),
clientSigning,
[]byte{
0x47, 0x88, 0xdc, 0x86, 0x1b, 0x47, 0x82, 0xf3,
0x5d, 0x43, 0xfd, 0x98, 0xfe, 0x1a, 0x2d, 0x39,
},
},
}
for _, table := range tables {
got := signKey(table.exportedSessionKey, table.constant)
assert.Equal(t, table.want, got)
}
}
func TestSealKey(t *testing.T) {
tables := []struct {
flags uint32
exportedSessionKey, constant []byte
exchangeKey func(uint32, []byte) ([]byte, error)
want []byte
}{
// No flags
{
0,
bytes.Repeat([]byte{0x55}, 16),
clientSealing,
nil,
bytes.Repeat([]byte{0x55}, 16),
},
// NTLMv1 56-bit
{
0x80000080,
bytes.Repeat([]byte{0x55}, 16),
clientSealing,
nil,
[]byte{
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xa0,
},
},
// NTLMv1 40-bit
{
0x80,
bytes.Repeat([]byte{0x55}, 16),
clientSealing,
nil,
[]byte{
0x55, 0x55, 0x55, 0x55, 0x55, 0xe5, 0x38, 0xb0,
},
},
// NTLMv2 128-bit
{
0x20080000,
bytes.Repeat([]byte{0x55}, 16),
clientSealing,
nil,
[]byte{
0x59, 0xf6, 0x00, 0x97, 0x3c, 0xc4, 0x96, 0x0a,
0x25, 0x48, 0x0a, 0x7c, 0x19, 0x6e, 0x4c, 0x58,
},
},
// NTLMv2 56-bit
{
0x80080000,
[]byte{
0xd8, 0x72, 0x62, 0xb0, 0xcd, 0xe4, 0xb1, 0xcb,
0x74, 0x99, 0xbe, 0xcc, 0xcd, 0xf1, 0x07, 0x84,
},
clientSealing,
func(flags uint32, sessionBaseKey []byte) ([]byte, error) {
return ntlmV1ExchangeKey(flags, sessionBaseKey, []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, zeroPad(bytes.Repeat([]byte{0xaa}, 8), 24), zeroPad(bytes.Repeat([]byte{0xaa}, 8), 16))
},
[]byte{
0x04, 0xdd, 0x7f, 0x01, 0x4d, 0x85, 0x04, 0xd2,
0x65, 0xa2, 0x5c, 0xc8, 0x6a, 0x3a, 0x7c, 0x06,
},
},
// NTLMv2 40-bit
{
0x80000,
[]byte{
0xd8, 0x72, 0x62, 0xb0, 0xcd, 0xe4, 0xb1, 0xcb,
0x74, 0x99, 0xbe, 0xcc, 0xcd, 0xf1, 0x07, 0x84,
},
clientSealing,
func(flags uint32, sessionBaseKey []byte) ([]byte, error) {
return ntlmV1ExchangeKey(flags, sessionBaseKey, []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, zeroPad(bytes.Repeat([]byte{0xaa}, 8), 24), zeroPad(bytes.Repeat([]byte{0xaa}, 8), 16))
},
[]byte{
0x26, 0xb2, 0xc1, 0xe7, 0x7b, 0xe4, 0x53, 0x3d,
0x55, 0x5a, 0x22, 0x0a, 0x0f, 0xde, 0xb9, 0x6c,
},
},
}
for _, table := range tables {
var exportedSessionKey []byte
if table.exchangeKey != nil {
var err error
exportedSessionKey, err = table.exchangeKey(table.flags, table.exportedSessionKey)
assert.Nil(t, err)
} else {
exportedSessionKey = table.exportedSessionKey
}
got := sealKey(table.flags, exportedSessionKey, table.constant)
assert.Equal(t, table.want, got)
}
}
func TestSecuritySession(t *testing.T) {
tables := []struct {
flags uint32
exportedSessionKey []byte
message []byte
seal, signature []byte
err error
}{
{
0xe2028233,
bytes.Repeat([]byte{0x55}, 16),
[]byte{
0x50, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x69, 0x00,
0x6e, 0x00, 0x74, 0x00, 0x65, 0x00, 0x78, 0x00,
0x74, 0x00,
},
[]byte{
0x56, 0xfe, 0x04, 0xd8, 0x61, 0xf9, 0x31, 0x9a,
0xf0, 0xd7, 0x23, 0x8a, 0x2e, 0x3b, 0x4d, 0x45,
0x7f, 0xb8,
},
[]byte{
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x09, 0xdc, 0xd1, 0xdf, 0x2e, 0x45, 0x9d, 0x36,
},
nil,
},
{
0x820a8233,
[]byte{
0xeb, 0x93, 0x42, 0x9a, 0x8b, 0xd9, 0x52, 0xf8,
0xb8, 0x9c, 0x55, 0xb8, 0x7f, 0x47, 0x5e, 0xdc,
},
[]byte{
0x50, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x69, 0x00,
0x6e, 0x00, 0x74, 0x00, 0x65, 0x00, 0x78, 0x00,
0x74, 0x00,
},
[]byte{
0xa0, 0x23, 0x72, 0xf6, 0x53, 0x02, 0x73, 0xf3,
0xaa, 0x1e, 0xb9, 0x01, 0x90, 0xce, 0x52, 0x00,
0xc9, 0x9d,
},
[]byte{
0x01, 0x00, 0x00, 0x00, 0xff, 0x2a, 0xeb, 0x52,
0xf6, 0x81, 0x79, 0x3a, 0x00, 0x00, 0x00, 0x00,
},
nil,
},
{
0xe28a8234,
bytes.Repeat([]byte{0x55}, 16),
[]byte{
0x50, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x69, 0x00,
0x6e, 0x00, 0x74, 0x00, 0x65, 0x00, 0x78, 0x00,
0x74, 0x00,
},
[]byte{
0x54, 0xe5, 0x01, 0x65, 0xbf, 0x19, 0x36, 0xdc,
0x99, 0x60, 0x20, 0xc1, 0x81, 0x1b, 0x0f, 0x06,
0xfb, 0x5f,
},
[]byte{
0x01, 0x00, 0x00, 0x00, 0x7f, 0xb3, 0x8e, 0xc5,
0xc5, 0x5d, 0x49, 0x76, 0x00, 0x00, 0x00, 0x00,
},
nil,
},
}
for _, table := range tables {
c, err := newSecuritySession(table.flags, table.exportedSessionKey, sourceClient)
assert.Nil(t, err)
s, err := newSecuritySession(table.flags, table.exportedSessionKey, sourceServer)
assert.Nil(t, err)
seal, signature, err := c.Wrap(table.message)
assert.Equal(t, table.err, err)
if err == nil {
assert.Equal(t, table.seal, seal)
assert.Equal(t, table.signature, signature)
}
message, err := s.Unwrap(seal, signature)
assert.Equal(t, table.err, err)
if err == nil {
assert.Equal(t, table.message, message)
}
}
}