@@ -54,6 +54,24 @@ static std::shared_ptr<X509> MakeCert(const char* issuer, EVP_PKEY* signer, cons
54
54
return std::shared_ptr<X509>(cert, X509_free);
55
55
}
56
56
57
+ static void ShortValidity (ASN1_TIME* notBefore, ASN1_TIME* notAfter)
58
+ {
59
+ BOOST_REQUIRE (X509_gmtime_adj (notBefore, -60 ));
60
+ BOOST_REQUIRE (X509_gmtime_adj (notAfter, 60 ));
61
+ }
62
+
63
+ static void ExpiredRecently (ASN1_TIME* notBefore, ASN1_TIME* notAfter)
64
+ {
65
+ BOOST_REQUIRE (X509_gmtime_adj (notBefore, -120 ));
66
+ BOOST_REQUIRE (X509_gmtime_adj (notAfter, -60 ));
67
+ }
68
+
69
+ static void NotYetValid (ASN1_TIME* notBefore, ASN1_TIME* notAfter)
70
+ {
71
+ BOOST_REQUIRE (X509_gmtime_adj (notBefore, 60 ));
72
+ BOOST_REQUIRE (X509_gmtime_adj (notAfter, 120 ));
73
+ }
74
+
57
75
static const long l_2016 = 1480000000 ; // Thu Nov 24 15:06:40 UTC 2016
58
76
static const long l_2017 = 1490000000 ; // Mon Mar 20 08:53:20 UTC 2017
59
77
@@ -132,4 +150,81 @@ BOOST_AUTO_TEST_CASE(iscertuptodate_old)
132
150
})));
133
151
}
134
152
153
+ BOOST_AUTO_TEST_CASE (verifycertificate_ok)
154
+ {
155
+ auto caKey (GenKeypair ());
156
+
157
+ BOOST_CHECK (VerifyCertificate (
158
+ MakeCert (" Icinga CA" , caKey, " Icinga CA" , caKey, ShortValidity),
159
+ MakeCert (" Icinga CA" , caKey, " example.com" , GenKeypair (), ShortValidity),
160
+ String ()
161
+ ));
162
+ }
163
+
164
+ BOOST_AUTO_TEST_CASE (verifycertificate_leafexpired)
165
+ {
166
+ auto caKey (GenKeypair ());
167
+
168
+ BOOST_CHECK_THROW (VerifyCertificate (
169
+ MakeCert (" Icinga CA" , caKey, " Icinga CA" , caKey, ShortValidity),
170
+ MakeCert (" Icinga CA" , caKey, " example.com" , GenKeypair (), ExpiredRecently),
171
+ String ()
172
+ ), openssl_error);
173
+ }
174
+
175
+ BOOST_AUTO_TEST_CASE (verifycertificate_caexpired)
176
+ {
177
+ auto caKey (GenKeypair ());
178
+
179
+ BOOST_CHECK_THROW (VerifyCertificate (
180
+ MakeCert (" Icinga CA" , caKey, " Icinga CA" , caKey, ExpiredRecently),
181
+ MakeCert (" Icinga CA" , caKey, " example.com" , GenKeypair (), ShortValidity),
182
+ String ()
183
+ ), openssl_error);
184
+ }
185
+
186
+ BOOST_AUTO_TEST_CASE (verifycertificate_leafnotyetvalid)
187
+ {
188
+ auto caKey (GenKeypair ());
189
+
190
+ BOOST_CHECK_THROW (VerifyCertificate (
191
+ MakeCert (" Icinga CA" , caKey, " Icinga CA" , caKey, ShortValidity),
192
+ MakeCert (" Icinga CA" , caKey, " example.com" , GenKeypair (), NotYetValid),
193
+ String ()
194
+ ), openssl_error);
195
+ }
196
+
197
+ BOOST_AUTO_TEST_CASE (verifycertificate_canotyetvalid)
198
+ {
199
+ auto caKey (GenKeypair ());
200
+
201
+ BOOST_CHECK_THROW (VerifyCertificate (
202
+ MakeCert (" Icinga CA" , caKey, " Icinga CA" , caKey, NotYetValid),
203
+ MakeCert (" Icinga CA" , caKey, " example.com" , GenKeypair (), ShortValidity),
204
+ String ()
205
+ ), openssl_error);
206
+ }
207
+
208
+ BOOST_AUTO_TEST_CASE (verifycertificate_issuermismatch)
209
+ {
210
+ auto caKey (GenKeypair ());
211
+
212
+ BOOST_CHECK_THROW (VerifyCertificate (
213
+ MakeCert (" Icinga CA" , caKey, " Icinga CA" , caKey, ShortValidity),
214
+ MakeCert (" Icigna CA" , caKey, " example.com" , GenKeypair (), ShortValidity),
215
+ String ()
216
+ ), openssl_error);
217
+ }
218
+
219
+ BOOST_AUTO_TEST_CASE (verifycertificate_sigmismatch)
220
+ {
221
+ auto caKey (GenKeypair ());
222
+
223
+ BOOST_CHECK_THROW (VerifyCertificate (
224
+ MakeCert (" Icinga CA" , caKey, " Icinga CA" , caKey, ShortValidity),
225
+ MakeCert (" Icinga CA" , GenKeypair (), " example.com" , GenKeypair (), ShortValidity),
226
+ String ()
227
+ ), openssl_error);
228
+ }
229
+
135
230
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments