Skip to content

Commit 6911a8f

Browse files
committed
Correct distrustAfter check
1 parent 5e1e522 commit 6911a8f

File tree

2 files changed

+241
-1
lines changed

2 files changed

+241
-1
lines changed

certs/convert_mozilla_certdata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func OutputTrustedCerts(objects []*Object) (parsedCerts CertList) {
272272
log.Fatalf("Unable to parse distrust after value '%s' for certificate on line %d, error %s", distrustAfter.value, cert.startingLine, err)
273273
}
274274

275-
if t.After(time.Now()) {
275+
if time.Now().After(t) {
276276
// This certificate is now distrusted.
277277
continue
278278
}
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
// Copyright 2022 Cory Benfield
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package certs
15+
16+
import (
17+
"strings"
18+
"testing"
19+
)
20+
21+
func TestDecodeDistrustAfterCert(t *testing.T) {
22+
testStr := `This Source Code
23+
24+
BEGINDATA
25+
CKA_CLASS CK_OBJECT_CLASS CKO_NSS_BUILTIN_ROOT_LIST
26+
CKA_TOKEN CK_BBOOL CK_TRUE
27+
CKA_PRIVATE CK_BBOOL CK_FALSE
28+
CKA_MODIFIABLE CK_BBOOL CK_FALSE
29+
CKA_LABEL UTF8 "Mozilla Builtin Roots"
30+
31+
#
32+
# Certificate "EC-ACC"
33+
#
34+
# Issuer: CN=EC-ACC,OU=Jerarquia Entitats de Certificacio Catalanes,OU=Vegeu https://www.catcert.net/verarrel (c)03,OU=Serveis Publics de Certificacio,O=Agencia Catalana de Certificacio (NIF Q-0801176-I),C=ES
35+
# Serial Number:ee:2b:3d:eb:d4:21:de:14:a8:62:ac:04:f3:dd:c4:01
36+
# Subject: CN=EC-ACC,OU=Jerarquia Entitats de Certificacio Catalanes,OU=Vegeu https://www.catcert.net/verarrel (c)03,OU=Serveis Publics de Certificacio,O=Agencia Catalana de Certificacio (NIF Q-0801176-I),C=ES
37+
# Not Valid Before: Tue Jan 07 23:00:00 2003
38+
# Not Valid After : Tue Jan 07 22:59:59 2031
39+
# Fingerprint (SHA-256): 88:49:7F:01:60:2F:31:54:24:6A:E2:8C:4D:5A:EF:10:F1:D8:7E:BB:76:62:6F:4A:E0:B7:F9:5B:A7:96:87:99
40+
# Fingerprint (SHA1): 28:90:3A:63:5B:52:80:FA:E6:77:4C:0B:6D:A7:D6:BA:A6:4A:F2:E8
41+
CKA_CLASS CK_OBJECT_CLASS CKO_CERTIFICATE
42+
CKA_TOKEN CK_BBOOL CK_TRUE
43+
CKA_PRIVATE CK_BBOOL CK_FALSE
44+
CKA_MODIFIABLE CK_BBOOL CK_FALSE
45+
CKA_LABEL UTF8 "EC-ACC"
46+
CKA_CERTIFICATE_TYPE CK_CERTIFICATE_TYPE CKC_X_509
47+
CKA_SUBJECT MULTILINE_OCTAL
48+
\060\201\363\061\013\060\011\006\003\125\004\006\023\002\105\123
49+
\061\073\060\071\006\003\125\004\012\023\062\101\147\145\156\143
50+
\151\141\040\103\141\164\141\154\141\156\141\040\144\145\040\103
51+
\145\162\164\151\146\151\143\141\143\151\157\040\050\116\111\106
52+
\040\121\055\060\070\060\061\061\067\066\055\111\051\061\050\060
53+
\046\006\003\125\004\013\023\037\123\145\162\166\145\151\163\040
54+
\120\165\142\154\151\143\163\040\144\145\040\103\145\162\164\151
55+
\146\151\143\141\143\151\157\061\065\060\063\006\003\125\004\013
56+
\023\054\126\145\147\145\165\040\150\164\164\160\163\072\057\057
57+
\167\167\167\056\143\141\164\143\145\162\164\056\156\145\164\057
58+
\166\145\162\141\162\162\145\154\040\050\143\051\060\063\061\065
59+
\060\063\006\003\125\004\013\023\054\112\145\162\141\162\161\165
60+
\151\141\040\105\156\164\151\164\141\164\163\040\144\145\040\103
61+
\145\162\164\151\146\151\143\141\143\151\157\040\103\141\164\141
62+
\154\141\156\145\163\061\017\060\015\006\003\125\004\003\023\006
63+
\105\103\055\101\103\103
64+
END
65+
CKA_ID UTF8 "0"
66+
CKA_ISSUER MULTILINE_OCTAL
67+
\060\201\363\061\013\060\011\006\003\125\004\006\023\002\105\123
68+
\061\073\060\071\006\003\125\004\012\023\062\101\147\145\156\143
69+
\151\141\040\103\141\164\141\154\141\156\141\040\144\145\040\103
70+
\145\162\164\151\146\151\143\141\143\151\157\040\050\116\111\106
71+
\040\121\055\060\070\060\061\061\067\066\055\111\051\061\050\060
72+
\046\006\003\125\004\013\023\037\123\145\162\166\145\151\163\040
73+
\120\165\142\154\151\143\163\040\144\145\040\103\145\162\164\151
74+
\146\151\143\141\143\151\157\061\065\060\063\006\003\125\004\013
75+
\023\054\126\145\147\145\165\040\150\164\164\160\163\072\057\057
76+
\167\167\167\056\143\141\164\143\145\162\164\056\156\145\164\057
77+
\166\145\162\141\162\162\145\154\040\050\143\051\060\063\061\065
78+
\060\063\006\003\125\004\013\023\054\112\145\162\141\162\161\165
79+
\151\141\040\105\156\164\151\164\141\164\163\040\144\145\040\103
80+
\145\162\164\151\146\151\143\141\143\151\157\040\103\141\164\141
81+
\154\141\156\145\163\061\017\060\015\006\003\125\004\003\023\006
82+
\105\103\055\101\103\103
83+
END
84+
CKA_SERIAL_NUMBER MULTILINE_OCTAL
85+
\002\020\356\053\075\353\324\041\336\024\250\142\254\004\363\335
86+
\304\001
87+
END
88+
CKA_VALUE MULTILINE_OCTAL
89+
\060\202\005\126\060\202\004\076\240\003\002\001\002\002\020\356
90+
\053\075\353\324\041\336\024\250\142\254\004\363\335\304\001\060
91+
\015\006\011\052\206\110\206\367\015\001\001\005\005\000\060\201
92+
\363\061\013\060\011\006\003\125\004\006\023\002\105\123\061\073
93+
\060\071\006\003\125\004\012\023\062\101\147\145\156\143\151\141
94+
\040\103\141\164\141\154\141\156\141\040\144\145\040\103\145\162
95+
\164\151\146\151\143\141\143\151\157\040\050\116\111\106\040\121
96+
\055\060\070\060\061\061\067\066\055\111\051\061\050\060\046\006
97+
\003\125\004\013\023\037\123\145\162\166\145\151\163\040\120\165
98+
\142\154\151\143\163\040\144\145\040\103\145\162\164\151\146\151
99+
\143\141\143\151\157\061\065\060\063\006\003\125\004\013\023\054
100+
\126\145\147\145\165\040\150\164\164\160\163\072\057\057\167\167
101+
\167\056\143\141\164\143\145\162\164\056\156\145\164\057\166\145
102+
\162\141\162\162\145\154\040\050\143\051\060\063\061\065\060\063
103+
\006\003\125\004\013\023\054\112\145\162\141\162\161\165\151\141
104+
\040\105\156\164\151\164\141\164\163\040\144\145\040\103\145\162
105+
\164\151\146\151\143\141\143\151\157\040\103\141\164\141\154\141
106+
\156\145\163\061\017\060\015\006\003\125\004\003\023\006\105\103
107+
\055\101\103\103\060\036\027\015\060\063\060\061\060\067\062\063
108+
\060\060\060\060\132\027\015\063\061\060\061\060\067\062\062\065
109+
\071\065\071\132\060\201\363\061\013\060\011\006\003\125\004\006
110+
\023\002\105\123\061\073\060\071\006\003\125\004\012\023\062\101
111+
\147\145\156\143\151\141\040\103\141\164\141\154\141\156\141\040
112+
\144\145\040\103\145\162\164\151\146\151\143\141\143\151\157\040
113+
\050\116\111\106\040\121\055\060\070\060\061\061\067\066\055\111
114+
\051\061\050\060\046\006\003\125\004\013\023\037\123\145\162\166
115+
\145\151\163\040\120\165\142\154\151\143\163\040\144\145\040\103
116+
\145\162\164\151\146\151\143\141\143\151\157\061\065\060\063\006
117+
\003\125\004\013\023\054\126\145\147\145\165\040\150\164\164\160
118+
\163\072\057\057\167\167\167\056\143\141\164\143\145\162\164\056
119+
\156\145\164\057\166\145\162\141\162\162\145\154\040\050\143\051
120+
\060\063\061\065\060\063\006\003\125\004\013\023\054\112\145\162
121+
\141\162\161\165\151\141\040\105\156\164\151\164\141\164\163\040
122+
\144\145\040\103\145\162\164\151\146\151\143\141\143\151\157\040
123+
\103\141\164\141\154\141\156\145\163\061\017\060\015\006\003\125
124+
\004\003\023\006\105\103\055\101\103\103\060\202\001\042\060\015
125+
\006\011\052\206\110\206\367\015\001\001\001\005\000\003\202\001
126+
\017\000\060\202\001\012\002\202\001\001\000\263\042\307\117\342
127+
\227\102\225\210\107\203\100\366\035\027\363\203\163\044\036\121
128+
\363\230\212\303\222\270\377\100\220\005\160\207\140\311\000\251
129+
\265\224\145\031\042\025\027\302\103\154\146\104\232\015\004\076
130+
\071\157\245\113\172\252\143\267\212\104\235\331\143\221\204\146
131+
\340\050\017\272\102\343\156\216\367\024\047\223\151\356\221\016
132+
\243\137\016\261\353\146\242\162\117\022\023\206\145\172\076\333
133+
\117\007\364\247\011\140\332\072\102\231\307\262\177\263\026\225
134+
\034\307\371\064\265\224\205\325\231\136\240\110\240\176\347\027
135+
\145\270\242\165\270\036\363\345\102\175\257\355\363\212\110\144
136+
\135\202\024\223\330\300\344\377\263\120\162\362\166\366\263\135
137+
\102\120\171\320\224\076\153\014\000\276\330\153\016\116\052\354
138+
\076\322\314\202\242\030\145\063\023\167\236\232\135\032\023\330
139+
\303\333\075\310\227\172\356\160\355\247\346\174\333\161\317\055
140+
\224\142\337\155\326\365\070\276\077\245\205\012\031\270\250\330
141+
\011\165\102\160\304\352\357\313\016\310\064\250\022\042\230\014
142+
\270\023\224\266\113\354\360\320\220\347\047\002\003\001\000\001
143+
\243\201\343\060\201\340\060\035\006\003\125\035\021\004\026\060
144+
\024\201\022\145\143\137\141\143\143\100\143\141\164\143\145\162
145+
\164\056\156\145\164\060\017\006\003\125\035\023\001\001\377\004
146+
\005\060\003\001\001\377\060\016\006\003\125\035\017\001\001\377
147+
\004\004\003\002\001\006\060\035\006\003\125\035\016\004\026\004
148+
\024\240\303\213\104\252\067\245\105\277\227\200\132\321\361\170
149+
\242\233\351\135\215\060\177\006\003\125\035\040\004\170\060\166
150+
\060\164\006\013\053\006\001\004\001\365\170\001\003\001\012\060
151+
\145\060\054\006\010\053\006\001\005\005\007\002\001\026\040\150
152+
\164\164\160\163\072\057\057\167\167\167\056\143\141\164\143\145
153+
\162\164\056\156\145\164\057\166\145\162\141\162\162\145\154\060
154+
\065\006\010\053\006\001\005\005\007\002\002\060\051\032\047\126
155+
\145\147\145\165\040\150\164\164\160\163\072\057\057\167\167\167
156+
\056\143\141\164\143\145\162\164\056\156\145\164\057\166\145\162
157+
\141\162\162\145\154\040\060\015\006\011\052\206\110\206\367\015
158+
\001\001\005\005\000\003\202\001\001\000\240\110\133\202\001\366
159+
\115\110\270\071\125\065\234\200\172\123\231\325\132\377\261\161
160+
\073\314\071\011\224\136\326\332\357\276\001\133\135\323\036\330
161+
\375\175\117\315\240\101\340\064\223\277\313\342\206\234\067\222
162+
\220\126\034\334\353\051\005\345\304\236\307\065\337\212\014\315
163+
\305\041\103\351\252\210\345\065\300\031\102\143\132\002\136\244
164+
\110\030\072\205\157\334\235\274\077\235\234\301\207\270\172\141
165+
\010\351\167\013\177\160\253\172\335\331\227\054\144\036\205\277
166+
\274\164\226\241\303\172\022\354\014\032\156\203\014\074\350\162
167+
\106\237\373\110\325\136\227\346\261\241\370\344\357\106\045\224
168+
\234\211\333\151\070\276\354\134\016\126\307\145\121\345\120\210
169+
\210\277\102\325\053\075\345\371\272\236\056\263\312\364\163\222
170+
\002\013\276\114\146\353\040\376\271\313\265\231\177\346\266\023
171+
\372\312\113\115\331\356\123\106\006\073\306\116\255\223\132\201
172+
\176\154\052\113\152\005\105\214\362\041\244\061\220\207\154\145
173+
\234\235\245\140\225\072\122\177\365\321\253\010\156\363\356\133
174+
\371\210\075\176\270\157\156\003\344\102
175+
END
176+
CKA_NSS_MOZILLA_CA_POLICY CK_BBOOL CK_TRUE
177+
# For Server Distrust After: Sat Dec 28 00:00:00 2019
178+
CKA_NSS_SERVER_DISTRUST_AFTER MULTILINE_OCTAL
179+
\061\071\061\062\062\070\060\060\060\060\060\060\132
180+
END
181+
# For Email Distrust After: Wed Aug 31 00:00:00 2022
182+
CKA_NSS_EMAIL_DISTRUST_AFTER MULTILINE_OCTAL
183+
\062\062\060\070\063\061\060\060\060\060\060\060\132
184+
END
185+
186+
# Trust for "EC-ACC"
187+
# Issuer: CN=EC-ACC,OU=Jerarquia Entitats de Certificacio Catalanes,OU=Vegeu https://www.catcert.net/verarrel (c)03,OU=Serveis Publics de Certificacio,O=Agencia Catalana de Certificacio (NIF Q-0801176-I),C=ES
188+
# Serial Number:ee:2b:3d:eb:d4:21:de:14:a8:62:ac:04:f3:dd:c4:01
189+
# Subject: CN=EC-ACC,OU=Jerarquia Entitats de Certificacio Catalanes,OU=Vegeu https://www.catcert.net/verarrel (c)03,OU=Serveis Publics de Certificacio,O=Agencia Catalana de Certificacio (NIF Q-0801176-I),C=ES
190+
# Not Valid Before: Tue Jan 07 23:00:00 2003
191+
# Not Valid After : Tue Jan 07 22:59:59 2031
192+
# Fingerprint (SHA-256): 88:49:7F:01:60:2F:31:54:24:6A:E2:8C:4D:5A:EF:10:F1:D8:7E:BB:76:62:6F:4A:E0:B7:F9:5B:A7:96:87:99
193+
# Fingerprint (SHA1): 28:90:3A:63:5B:52:80:FA:E6:77:4C:0B:6D:A7:D6:BA:A6:4A:F2:E8
194+
CKA_CLASS CK_OBJECT_CLASS CKO_NSS_TRUST
195+
CKA_TOKEN CK_BBOOL CK_TRUE
196+
CKA_PRIVATE CK_BBOOL CK_FALSE
197+
CKA_MODIFIABLE CK_BBOOL CK_FALSE
198+
CKA_LABEL UTF8 "EC-ACC"
199+
CKA_CERT_SHA1_HASH MULTILINE_OCTAL
200+
\050\220\072\143\133\122\200\372\346\167\114\013\155\247\326\272
201+
\246\112\362\350
202+
END
203+
CKA_CERT_MD5_HASH MULTILINE_OCTAL
204+
\353\365\235\051\015\141\371\102\037\174\302\272\155\343\025\011
205+
END
206+
CKA_ISSUER MULTILINE_OCTAL
207+
\060\201\363\061\013\060\011\006\003\125\004\006\023\002\105\123
208+
\061\073\060\071\006\003\125\004\012\023\062\101\147\145\156\143
209+
\151\141\040\103\141\164\141\154\141\156\141\040\144\145\040\103
210+
\145\162\164\151\146\151\143\141\143\151\157\040\050\116\111\106
211+
\040\121\055\060\070\060\061\061\067\066\055\111\051\061\050\060
212+
\046\006\003\125\004\013\023\037\123\145\162\166\145\151\163\040
213+
\120\165\142\154\151\143\163\040\144\145\040\103\145\162\164\151
214+
\146\151\143\141\143\151\157\061\065\060\063\006\003\125\004\013
215+
\023\054\126\145\147\145\165\040\150\164\164\160\163\072\057\057
216+
\167\167\167\056\143\141\164\143\145\162\164\056\156\145\164\057
217+
\166\145\162\141\162\162\145\154\040\050\143\051\060\063\061\065
218+
\060\063\006\003\125\004\013\023\054\112\145\162\141\162\161\165
219+
\151\141\040\105\156\164\151\164\141\164\163\040\144\145\040\103
220+
\145\162\164\151\146\151\143\141\143\151\157\040\103\141\164\141
221+
\154\141\156\145\163\061\017\060\015\006\003\125\004\003\023\006
222+
\105\103\055\101\103\103
223+
END
224+
CKA_SERIAL_NUMBER MULTILINE_OCTAL
225+
\002\020\356\053\075\353\324\041\336\024\250\142\254\004\363\335
226+
\304\001
227+
END
228+
CKA_TRUST_SERVER_AUTH CK_TRUST CKT_NSS_TRUSTED_DELEGATOR
229+
CKA_TRUST_EMAIL_PROTECTION CK_TRUST CKT_NSS_MUST_VERIFY_TRUST
230+
CKA_TRUST_CODE_SIGNING CK_TRUST CKT_NSS_MUST_VERIFY_TRUST
231+
CKA_TRUST_STEP_UP_APPROVED CK_BBOOL CK_FALSE
232+
`
233+
reader := strings.NewReader(testStr)
234+
_, _, objects := ParseInput(reader)
235+
certs := OutputTrustedCerts(objects)
236+
if len(certs) != 0 {
237+
t.Errorf("Unexpected cert count: %v", len(certs))
238+
}
239+
240+
}

0 commit comments

Comments
 (0)