-
Notifications
You must be signed in to change notification settings - Fork 0
/
cms_test.go
357 lines (335 loc) · 15.9 KB
/
cms_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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package pkcs7_test
import (
"encoding/pem"
"github.com/ddulesov/pkcs7"
"testing"
"time"
)
var testSignedData = []byte{116, 101, 115, 116, 32, 115, 116, 114, 105, 110, 103, 10}
const testAlienCA = `-----BEGIN CERTIFICATE-----
MIIBmzCCAUigAwIBAgIJAM7hOrq5ksiJMAoGBiqFAwICAwUAMCcxEjAQBgNVBAMM
CWxvY2FsaG9zdDERMA8GA1UECwwIZ29zdDIwMDEwHhcNMTkwODIzMTEzMjA3WhcN
MjkwODIwMTEzMjA3WjAnMRIwEAYDVQQDDAlsb2NhbGhvc3QxETAPBgNVBAsMCGdv
c3QyMDAxMGMwHAYGKoUDAgITMBIGByqFAwICIwEGByqFAwICHgEDQwAEQLIVXDhT
Q1ruBfsFgZa3494vsLyRP80yZupl8/gaKh5n3WLBMxCAuCNY+Y9NW5w9KH3A9sYk
Upt4sT2ce+rvCG2jUzBRMB0GA1UdDgQWBBRhtnT2MGTJwoVMKNjuzPUm+9q7XzAf
BgNVHSMEGDAWgBRhtnT2MGTJwoVMKNjuzPUm+9q7XzAPBgNVHRMBAf8EBTADAQH/
MAoGBiqFAwICAwUAA0EA3DNrRU2ZVb0YRs6yHPbg/ZCcRL17jDXT85tMHiS1VlzQ
Ztnn0Sz/f9hwXMHgT3q+93IpDN4HifEKAhJzS2XITA==
-----END CERTIFICATE-----`
var testSet = []struct {
Name string
Cms string
Ca string
Content []byte
NotBefore time.Time
NotAfter time.Time
}{
{
"GOST-34.10-2001",
`-----BEGIN CMS-----
MIIC7QYJKoZIhvcNAQcCoIIC3jCCAtoCAQExDDAKBgYqhQMCAgkFADAbBgkqhkiG
9w0BBwGgDgQMdGVzdCBzdHJpbmcKoIIBozCCAZ8wggFMAgkAjONak/cOJM0wCgYG
KoUDAgIDBQAwJzESMBAGA1UEAwwJbG9jYWxob3N0MREwDwYDVQQLDAhnb3N0MjAw
MTAeFw0xOTA4MjMxNjA5NDFaFw0yMDA4MjIxNjA5NDFaMIGEMQswCQYDVQQGEwJS
VTEPMA0GA1UECAwGTW9zY293MQ8wDQYDVQQHDAZNb3Njb3cxGDAWBgNVBAoMD0ds
b2JhbCBTZWN1cml0eTEWMBQGA1UECwwNSVQgRGVwYXJ0bWVudDEhMB8GA1UEAwwY
ZG1pdHJ5LmR1bGVzb3ZAZ21haWwuY29tMGMwHAYGKoUDAgITMBIGByqFAwICIwEG
ByqFAwICHgEDQwAEQIDZWQ3quOWQ0GkbeqIEke7qRaMw+gqi8CA6ijX643O34nGS
d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gKg==
-----END CERTIFICATE-----`,
testSignedData,
time.Date(2019, time.August, 23, 0, 0, 0, 0, time.UTC),
time.Date(2019, time.August, 25, 0, 0, 0, 0, time.UTC),
},
{
"GOST-34.10.2012_256",
`-----BEGIN CMS-----
MIIDAwYJKoZIhvcNAQcCoIIC9DCCAvACAQExDjAMBggqhQMHAQECAgUAMBsGCSqG
SIb3DQEHAaAOBAx0ZXN0IHN0cmluZwqgggGuMIIBqjCCAVUCCQCPVPoTAC1IMTAM
BggqhQMHAQEDAgUAMCsxEjAQBgNVBAMMCWxvY2FsaG9zdDEVMBMGA1UECwwMZ29z
dDIwMTJfMjU2MB4XDTE5MDgyMzE2MDk0MVoXDTIwMDgyMjE2MDk0MVowgYQxCzAJ
BgNVBAYTAlJVMQ8wDQYDVQQIDAZNb3Njb3cxDzANBgNVBAcMBk1vc2NvdzEYMBYG
A1UECgwPR2xvYmFsIFNlY3VyaXR5MRYwFAYDVQQLDA1JVCBEZXBhcnRtZW50MSEw
HwYDVQQDDBhkbWl0cnkuZHVsZXNvdkBnbWFpbC5jb20wZjAfBggqhQMHAQEBATAT
BgcqhQMCAiMBBggqhQMHAQECAgNDAARADVqw5zN6+PKhGDJR2r4PM9G9QAr3wwH9
dWhqT58dMI1HuG2LB0TnCrtpogPXZrNfxXNJ86i4RlXlFUZkiXTDfzAMBggqhQMH
AQEDAgUAA0EAbJwXF9ujVWDCs3qw8OhNG0c9wdsg32BiNfvcQjzczGYPqaQC6/NQ
jiEBmBNGLm9gR7opv2KmPzCS8I5IxxyteTGCAQowggEGAgEBMDgwKzESMBAGA1UE
AwwJbG9jYWxob3N0MRUwEwYDVQQLDAxnb3N0MjAxMl8yNTYCCQCPVPoTAC1IMTAM
BggqhQMHAQECAgUAoGkwGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG
9w0BCQUxDxcNMTkwODIzMTYwOTQxWjAvBgkqhkiG9w0BCQQxIgQgzFZibgJ3QZcx
1IGWV2vdbzGaEA/l7WMTS7DX9DjBQ9kwDAYIKoUDBwEBAQEFAARA4vUnMZRmswBZ
qxBpslgRCq3aqDU48yYoJqfREqTYVnwuKjUQYqkG9ppjX+waZwe3wYmNY6Aha5UC
PRtQCk0PCw==
-----END CMS-----`,
`-----BEGIN CERTIFICATE-----
MIIBqjCCAVWgAwIBAgIJALhaVkBotxkpMAwGCCqFAwcBAQMCBQAwKzESMBAGA1UE
AwwJbG9jYWxob3N0MRUwEwYDVQQLDAxnb3N0MjAxMl8yNTYwHhcNMTkwODIzMTYw
OTQxWhcNMjkwODIwMTYwOTQxWjArMRIwEAYDVQQDDAlsb2NhbGhvc3QxFTATBgNV
BAsMDGdvc3QyMDEyXzI1NjBmMB8GCCqFAwcBAQEBMBMGByqFAwICIwEGCCqFAwcB
AQICA0MABEDloAV7YmyN1ieVTzdrgO0/vZo7qZ/Yi7BgSX8ie5iql9UiqBdNuVdy
NfKskmlVf2W2m5ql43P6edVCidp9MzqEo1MwUTAdBgNVHQ4EFgQUmNW0C21fXYF7
Rj7lVBqgGXOZXWowHwYDVR0jBBgwFoAUmNW0C21fXYF7Rj7lVBqgGXOZXWowDwYD
VR0TAQH/BAUwAwEB/zAMBggqhQMHAQEDAgUAA0EAFMYn4pIAS3I27xiBYd/iKTzJ
RHwBB8sDLv+8s0YHw02fvI1Z6Plk3CKbYq5MUu6mDtyHcwsOaPwCRupZ6RYDxg==
-----END CERTIFICATE-----`,
testSignedData,
time.Date(2019, time.August, 23, 0, 0, 0, 0, time.UTC),
time.Date(2019, time.August, 25, 0, 0, 0, 0, time.UTC),
},
{
"GOST-34.10-2012_512",
`-----BEGIN CMS-----
MIID6wYJKoZIhvcNAQcCoIID3DCCA9gCAQExDjAMBggqhQMHAQECAwUAMBsGCSqG
SIb3DQEHAaAOBAx0ZXN0IHN0cmluZwqgggI0MIICMDCCAZoCCQCoX2T1W0KqdjAM
BggqhQMHAQEDAwUAMCsxEjAQBgNVBAMMCWxvY2FsaG9zdDEVMBMGA1UECwwM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fxX49mxMGX0nrNIWwCrHfgDeyoFThWeQYu4lfaQ1VXV
FBEdCajOW5v6iDIVoB8DnoPGXBVvgAiz5g9cgxAgxifKNdXn3QDM4rCshezZYvI=
-----END CMS-----`,
`-----BEGIN CERTIFICATE-----
MIICMDCCAZqgAwIBAgIJAJodEe1eXuYCMAwGCCqFAwcBAQMDBQAwKzESMBAGA1UE
AwwJbG9jYWxob3N0MRUwEwYDVQQLDAxnb3N0MjAxMl81MTIwHhcNMTkwODIzMTYw
OTQxWhcNMjkwODIwMTYwOTQxWjArMRIwEAYDVQQDDAlsb2NhbGhvc3QxFTATBgNV
BAsMDGdvc3QyMDEyXzUxMjCBqjAhBggqhQMHAQEBAjAVBgkqhQMHAQIBAgEGCCqF
AwcBAQIDA4GEAASBgN/+MLwqs48KGsDHgwEqKAIgNL5iCUpDdO4/1834+2t2MSt/
ijZ9Zel62+jJDrf7jQvqoCFMdqLU1FKH4J6hZuZmbRUedGuHCnpahQyFiEf1NINU
QvfVyoAyoV8mOhi2pNAqurcCo56SORJFHVTj5CrVHAdbisVOpp6vOjpk90sTo1Mw
UTAdBgNVHQ4EFgQUJ5/g4/Np4NxZekN/uyOIDCDkAcowHwYDVR0jBBgwFoAUJ5/g
4/Np4NxZekN/uyOIDCDkAcowDwYDVR0TAQH/BAUwAwEB/zAMBggqhQMHAQEDAwUA
A4GBACOtQAoi2L9DXu0+VZA/QD/lC4kxFXT3ZwKODWozkRkdz2AOb+BHjMLBn9fI
2nGx8ZVEw51RnR9Li4kskCILlfl9yXmPW/GTG5ydrL5dTi8AjJ/xQSd9AWG7VB7g
24TKgtSBGjr3+tDJyp9jyhotj4x8vNkY54zFfPvYM+WfLf9g
-----END CERTIFICATE-----`,
testSignedData,
time.Date(2019, time.August, 23, 0, 0, 0, 0, time.UTC),
time.Date(2019, time.August, 25, 0, 0, 0, 0, time.UTC),
},
{
"RSA256",
`-----BEGIN CMS-----
MIIFNAYJKoZIhvcNAQcCoIIFJTCCBSECAQExDTALBgl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1Lk4VmEThJtwRSLUZyc6IXqLgn/TihR87WLZnbxGPVWfN+dsZTIVzrxABmCRxV8z
wcOn8oZW5a+iQKHU+U0wQeoV15Bg2UBMRJZyoyLbfZenglSgv9Nn60I9unmkEeoL
24zaGB0EST/5ulHlM0lwQLhph2gAm00DPyS6A3MnSz8ipMbfrJNWEVL/HUde9jXy
a6AstMFuKkpehbtyQz/FN1Th0S9Dq8N6sa6JzTNVb8abJHN0pFfi1aBhyh4HEYDj
AgMBAAGjUzBRMB0GA1UdDgQWBBSv7I0DjH2bE+64rQ2VDPRnJEM7uTAfBgNVHSME
GDAWgBSv7I0DjH2bE+64rQ2VDPRnJEM7uTAPBgNVHRMBAf8EBTADAQH/MA0GCSqG
SIb3DQEBCwUAA4IBAQA/lS8bvY3AF/h5Z2yfuLS09vpl0pR50JQPu8FK1JVcDo9W
sVpLjC3n6LKfspfUOAKh1b6lqm+NkqRNF0bPGE8/lEZXwff8yCZTX7HpKkI+0Y1e
6sp8rCnOfYLlrkecOro9QAgckDxV7JOiQFupD0eap7BXkFCHEf4BjxcEHTGswwSa
UZC7jN+AEHVRmx/yLu5o3KT5fuwKRNwSz0+AGU2YAZN3+JZACK+8WomOkwPNtdIj
pN1uuzjBh7PO/mUAKvrBmU66fi+CkyJfDQClpN++QS353TDbQEaeNbDYcS1/wqXD
GyCULCtJlKqqS3vie07YnuCg2yhhSyUV18beveSX
-----END CERTIFICATE-----`,
testSignedData,
time.Date(2019, time.August, 23, 0, 0, 0, 0, time.UTC),
time.Date(2019, time.August, 25, 0, 0, 0, 0, time.UTC),
},
{
"RSA512",
`-----BEGIN CMS-----
MIIGVQYJKoZIhvcNAQcCoIIGRjCCBkICAQExDTALBglghkgBZQMEAgMwGwYJKoZI
hvcNAQcBoA4EDHRlc3Qgc3RyaW5nCqCCBCcwggQjMIICCwIJAOFQtPQCC4cBMA0G
CSqGSIb3DQEBDQUAMCIxEjAQBgNVBAMMCWxvY2FsaG9zdDEMMAoGA1UECwwDNTEy
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
QDEdqcagCF2XtKJpSyWNtGUC2l08Ccl62dKKTOJ2Urt5uMAkhBiQZdTJzUSDOz8X
uz3jFlB9OfedgtNbN1XCIwG/KOevIddxw+ME6iREn8Ozdhmi9Fk2BoQqJTVfy/Zv
Wt6JmxUtI3qB789D58Ea6yfsK9cagrJjjKT3sH/6nQBojFSlwTMUGBPgvF0CPg8k
ovCtxlko/qItwoc+zTMlT4jABYIrCzXFVMSIGTXXTYeFVsqdQsWoisSGk1ygZvsG
LKg4lHAmWyJRVUy3Hek8g2AEacBCrKdFKZb1FI9iKkbXgBBzKv2i0gvJQfS8UqpC
x3/hQO2nZ0XStoX9PePKh9LD2TS0DAWUXulAk+ej1tyjoYQMFcfQILK0Z1J7MbC3
XhHPesHpJI9plCM5qABEsR2mRgFlE9JN5Vs1gIJdSor/9dybkBtTAvhZ1ASC5xkv
vqx8LfNL8ilSfUi7ZF1T9RnfdrXt+QxgECk3Q2vCW44dkhzdq4BVp6B4yD7HS7F7
cJhI5btdMjkivQVT8bpyB9wRahFmwFakOc5ViNP4W24xbommAV5D3zhP2FAn9qyB
V4kqNcM94/N7hlXsKvw=
-----END CERTIFICATE-----`,
testSignedData,
time.Date(2019, time.August, 23, 0, 0, 0, 0, time.UTC),
time.Date(2019, time.August, 25, 0, 0, 0, 0, time.UTC),
},
}
func Pem2Der(t *testing.T, pemData string, pemType string) []byte {
ber, _ := pem.Decode([]byte(pemData))
if ber == nil || ber.Type != pemType {
t.Fatal("not PEM encoded")
}
return ber.Bytes
}
func TestCMS(t *testing.T) {
caAlien, err := pkcs7.ParseCertificate(Pem2Der(t, testAlienCA, "CERTIFICATE"))
if err != nil {
t.FailNow()
}
var calist []*pkcs7.Certificate
for _, item := range testSet {
ca, err := pkcs7.ParseCertificate(Pem2Der(t, item.Ca, "CERTIFICATE"))
if err != nil {
t.FailNow()
}
calist = append(calist, ca)
cms, err := pkcs7.ParseCMS(Pem2Der(t, item.Cms, "CMS"))
if err != nil {
t.FailNow()
}
t.Run(item.Name, func(t *testing.T) {
err = cms.VerifyCertificates([]*pkcs7.Certificate{ca})
if err != nil {
t.FailNow()
}
err = cms.Verify(item.Content, item.NotBefore, item.NotAfter)
if err != nil {
t.FailNow()
}
})
//errors
t.Run(item.Name+"_CertificateError", func(t *testing.T) {
err = cms.VerifyCertificates([]*pkcs7.Certificate{caAlien})
if err != pkcs7.ErrSignature {
t.FailNow()
}
})
t.Run(item.Name+"_SigningTimeError", func(t *testing.T) {
err = cms.Verify(item.Content, item.NotAfter, item.NotAfter)
if err != pkcs7.ErrSigningTime {
t.FailNow()
}
})
t.Run(item.Name+"_ContentError", func(t *testing.T) {
err = cms.Verify([]byte{10}, item.NotBefore, item.NotAfter)
if err != pkcs7.ErrSignature {
t.FailNow()
}
})
}
for _, item := range testSet {
t.Run(item.Name+"_ValidateCAList", func(t *testing.T) {
cms, err := pkcs7.ParseCMS(Pem2Der(t, item.Cms, "CMS"))
if err != nil {
t.FailNow()
}
err = cms.VerifyCertificates(calist)
if err != nil {
t.FailNow()
}
})
}
}