• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 11844561993

14 Nov 2024 07:58PM UTC coverage: 91.178% (+0.1%) from 91.072%
11844561993

Pull #4435

github

web-flow
Merge 81dcb29da into e430f157a
Pull Request #4435: Test duration values ​​are now presented in seconds with six digits of precision. Tests without time measurements have been edited.

91856 of 100744 relevant lines covered (91.18%)

9311006.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.59
/src/tests/test_ocsp.cpp
1
/*
2
* (C) 2016 Jack Lloyd
3
* (C) 2022 René Meusel, Rohde & Schwarz Cybersecurity
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "tests.h"
9

10
#if defined(BOTAN_HAS_OCSP)
11
   #include <botan/certstor.h>
12
   #include <botan/ocsp.h>
13
   #include <botan/x509path.h>
14
   #include <botan/internal/calendar.h>
15
   #include <fstream>
16
#endif
17

18
namespace Botan_Tests {
19

20
#if defined(BOTAN_HAS_OCSP) && defined(BOTAN_HAS_RSA) && defined(BOTAN_HAS_EMSA_PKCS1) && \
21
   defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
22

23
class OCSP_Tests final : public Test {
×
24
   private:
25
      static Botan::X509_Certificate load_test_X509_cert(const std::string& path) {
23✔
26
         return Botan::X509_Certificate(Test::data_file(path));
46✔
27
      }
28

29
      static Botan::OCSP::Response load_test_OCSP_resp(const std::string& path) {
9✔
30
         return Botan::OCSP::Response(Test::read_binary_data_file(path));
27✔
31
      }
32

33
      static Test::Result test_response_parsing() {
1✔
34
         Test::Result result("OCSP response parsing");
1✔
35
         result.start_timer();
1✔
36

37
         // Simple parsing tests
38
         const std::vector<std::string> ocsp_input_paths = {
1✔
39
            "x509/ocsp/resp1.der", "x509/ocsp/resp2.der", "x509/ocsp/resp3.der"};
1✔
40

41
         for(const std::string& ocsp_input_path : ocsp_input_paths) {
4✔
42
            try {
3✔
43
               Botan::OCSP::Response resp(Test::read_binary_data_file(ocsp_input_path));
6✔
44
               result.confirm("parsing was successful", resp.status() == Botan::OCSP::Response_Status_Code::Successful);
6✔
45
               result.test_success("Parsed input " + ocsp_input_path);
3✔
46
            } catch(Botan::Exception& e) {
3✔
47
               result.test_failure("Parsing failed", e.what());
×
48
            }
×
49
         }
50

51
         Botan::OCSP::Response resp(
1✔
52
            Test::read_binary_data_file("x509/ocsp/patrickschmidt_ocsp_try_later_wrong_sig.der"));
3✔
53
         result.confirm("parsing exposes correct status code",
2✔
54
                        resp.status() == Botan::OCSP::Response_Status_Code::Try_Later);
1✔
55

56
         result.end_timer();
1✔
57
         return result;
1✔
58
      }
1✔
59

60
      static Test::Result test_response_certificate_access() {
1✔
61
         Test::Result result("OCSP response certificate access");
1✔
62
         result.start_timer();
1✔
63

64
         try {
1✔
65
            Botan::OCSP::Response resp1(Test::read_binary_data_file("x509/ocsp/resp1.der"));
3✔
66
            const auto& certs1 = resp1.certificates();
1✔
67
            if(result.test_eq("Expected count of certificates", certs1.size(), 1)) {
1✔
68
               const auto& cert = certs1.front();
1✔
69
               const Botan::X509_DN expected_dn(
1✔
70
                  {std::make_pair("X520.CommonName", "Symantec Class 3 EV SSL CA - G3 OCSP Responder")});
3✔
71
               const bool matches = cert.subject_dn() == expected_dn;
1✔
72
               result.test_eq("CN matches expected", matches, true);
1✔
73
            }
1✔
74

75
            Botan::OCSP::Response resp2(Test::read_binary_data_file("x509/ocsp/resp2.der"));
3✔
76
            const auto& certs2 = resp2.certificates();
1✔
77
            result.test_eq("Expect no certificates", certs2.size(), 0);
1✔
78
         } catch(Botan::Exception& e) {
1✔
79
            result.test_failure("Parsing failed", e.what());
×
80
         }
×
81

82
         result.end_timer();
1✔
83
         return result;
1✔
84
      }
1✔
85

86
      static Test::Result test_request_encoding() {
1✔
87
         Test::Result result("OCSP request encoding");
1✔
88
         result.start_timer();
1✔
89

90
         const Botan::X509_Certificate end_entity(Test::data_file("x509/ocsp/gmail.pem"));
2✔
91
         const Botan::X509_Certificate issuer(Test::data_file("x509/ocsp/google_g2.pem"));
2✔
92

93
         try {
1✔
94
            const Botan::OCSP::Request bogus(end_entity, issuer);
1✔
95
            result.test_failure("Bad arguments (swapped end entity, issuer) accepted");
×
96
         } catch(Botan::Invalid_Argument&) {
1✔
97
            result.test_success("Bad arguments rejected");
1✔
98
         }
1✔
99

100
         const std::string expected_request =
1✔
101
            "ME4wTKADAgEAMEUwQzBBMAkGBSsOAwIaBQAEFPLgavmFih2NcJtJGSN6qbUaKH5kBBRK3QYWG7z2aLV29YG2u2IaulqBLwIIQkg+DF+RYMY=";
1✔
102

103
         const Botan::OCSP::Request req1(issuer, end_entity);
1✔
104
         result.test_eq("Encoded OCSP request", req1.base64_encode(), expected_request);
2✔
105

106
         const Botan::OCSP::Request req2(issuer, BigInt::from_bytes(end_entity.serial_number()));
1✔
107
         result.test_eq("Encoded OCSP request", req2.base64_encode(), expected_request);
2✔
108

109
         result.end_timer();
1✔
110
         return result;
2✔
111
      }
2✔
112

113
      static Test::Result test_response_find_signing_certificate() {
1✔
114
         Test::Result result("OCSP response finding signature certificates");
1✔
115
         result.start_timer();
1✔
116

117
         const std::optional<Botan::X509_Certificate> nullopt_cert;
1✔
118

119
         // OCSP response is signed by the issuing CA itself
120
         auto randombit_ocsp = load_test_OCSP_resp("x509/ocsp/randombit_ocsp.der");
1✔
121
         auto randombit_ca = load_test_X509_cert("x509/ocsp/letsencrypt.pem");
1✔
122

123
         // OCSP response is signed by an authorized responder certificate
124
         // issued by the issuing CA and embedded in the response
125
         auto bdr_ocsp = load_test_OCSP_resp("x509/ocsp/bdr-ocsp-resp.der");
1✔
126
         auto bdr_responder = load_test_X509_cert("x509/ocsp/bdr-ocsp-responder.pem");
1✔
127
         auto bdr_ca = load_test_X509_cert("x509/ocsp/bdr-int.pem");
1✔
128

129
         // Dummy OCSP response is not signed at all
130
         auto dummy_ocsp = Botan::OCSP::Response(Botan::Certificate_Status_Code::OCSP_SERVER_NOT_AVAILABLE);
1✔
131

132
         // OCSP response is signed by 3rd party responder certificate that is
133
         // not included in the OCSP response itself
134
         // See `src/scripts/randombit_ocsp_forger.sh` for a helper script to recreate those.
135
         auto randombit_alt_resp_ocsp = load_test_OCSP_resp("x509/ocsp/randombit_ocsp_forged_valid_nocerts.der");
1✔
136
         auto randombit_alt_resp_cert = load_test_X509_cert("x509/ocsp/randombit_ocsp_forged_responder.pem");
1✔
137

138
         result.test_is_eq("Dummy has no signing certificate",
2✔
139
                           dummy_ocsp.find_signing_certificate(Botan::X509_Certificate()),
2✔
140
                           nullopt_cert);
141

142
         result.test_is_eq("CA is returned as signing certificate",
3✔
143
                           randombit_ocsp.find_signing_certificate(randombit_ca),
1✔
144
                           std::optional(randombit_ca));
1✔
145
         result.test_is_eq("No signer certificate is returned when signer couldn't be determined",
2✔
146
                           randombit_ocsp.find_signing_certificate(bdr_ca),
1✔
147
                           nullopt_cert);
148

149
         result.test_is_eq("Delegated responder certificate is returned for further validation",
3✔
150
                           bdr_ocsp.find_signing_certificate(bdr_ca),
1✔
151
                           std::optional(bdr_responder));
1✔
152

153
         result.test_is_eq("Delegated responder without stapled certs does not find signer without user-provided certs",
2✔
154
                           randombit_alt_resp_ocsp.find_signing_certificate(randombit_ca),
1✔
155
                           nullopt_cert);
156
         auto trusted_responders = std::make_unique<Botan::Certificate_Store_In_Memory>(randombit_alt_resp_cert);
1✔
157
         result.test_is_eq("Delegated responder returns user-provided cert",
3✔
158
                           randombit_alt_resp_ocsp.find_signing_certificate(randombit_ca, trusted_responders.get()),
2✔
159
                           std::optional(randombit_alt_resp_cert));
1✔
160

161
         result.end_timer();
1✔
162
         return result;
2✔
163
      }
1✔
164

165
      static Test::Result test_response_verification_with_next_update_without_max_age() {
1✔
166
         Test::Result result("OCSP request check with next_update w/o max_age");
1✔
167
         result.start_timer();
1✔
168

169
         auto ee = load_test_X509_cert("x509/ocsp/randombit.pem");
1✔
170
         auto ca = load_test_X509_cert("x509/ocsp/letsencrypt.pem");
1✔
171
         auto trust_root = load_test_X509_cert("x509/ocsp/geotrust.pem");
1✔
172

173
         const std::vector<Botan::X509_Certificate> cert_path = {ee, ca, trust_root};
4✔
174

175
         auto ocsp = load_test_OCSP_resp("x509/ocsp/randombit_ocsp.der");
1✔
176

177
         Botan::Certificate_Store_In_Memory certstore;
1✔
178
         certstore.add_certificate(trust_root);
1✔
179

180
         auto check_ocsp = [&](const std::chrono::system_clock::time_point valid_time,
5✔
181
                               const Botan::Certificate_Status_Code expected) {
182
            const auto ocsp_status = Botan::PKIX::check_ocsp(
8✔
183
               cert_path, {ocsp}, {&certstore}, valid_time, Botan::Path_Validation_Restrictions());
16✔
184

185
            return result.test_eq("Expected size of ocsp_status", ocsp_status.size(), 1) &&
8✔
186
                   result.test_eq("Expected size of ocsp_status[0]", ocsp_status[0].size(), 1) &&
12✔
187
                   result.confirm(std::string("Status: '") + Botan::to_string(expected) + "'",
28✔
188
                                  ocsp_status[0].contains(expected));
12✔
189
         };
8✔
190

191
         check_ocsp(Botan::calendar_point(2016, 11, 11, 12, 30, 0).to_std_timepoint(),
1✔
192
                    Botan::Certificate_Status_Code::OCSP_NOT_YET_VALID);
193
         check_ocsp(Botan::calendar_point(2016, 11, 18, 12, 30, 0).to_std_timepoint(),
1✔
194
                    Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD);
195
         check_ocsp(Botan::calendar_point(2016, 11, 20, 8, 30, 0).to_std_timepoint(),
1✔
196
                    Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD);
197
         check_ocsp(Botan::calendar_point(2016, 11, 28, 8, 30, 0).to_std_timepoint(),
1✔
198
                    Botan::Certificate_Status_Code::OCSP_HAS_EXPIRED);
199

200
         result.end_timer();
1✔
201
         return result;
1✔
202
      }
2✔
203

204
      static Test::Result test_response_verification_with_next_update_with_max_age() {
1✔
205
         Test::Result result("OCSP request check with next_update with max_age");
1✔
206
         result.start_timer();
1✔
207

208
         auto ee = load_test_X509_cert("x509/ocsp/randombit.pem");
1✔
209
         auto ca = load_test_X509_cert("x509/ocsp/letsencrypt.pem");
1✔
210
         auto trust_root = load_test_X509_cert("x509/ocsp/geotrust.pem");
1✔
211

212
         const std::vector<Botan::X509_Certificate> cert_path = {ee, ca, trust_root};
4✔
213

214
         auto ocsp = load_test_OCSP_resp("x509/ocsp/randombit_ocsp.der");
1✔
215

216
         Botan::Certificate_Store_In_Memory certstore;
1✔
217
         certstore.add_certificate(trust_root);
1✔
218

219
         // Some arbitrary time within the validity period of the test certs
220
         const auto max_age = std::chrono::minutes(59);
1✔
221

222
         auto check_ocsp = [&](const std::chrono::system_clock::time_point valid_time,
5✔
223
                               const Botan::Certificate_Status_Code expected) {
224
            Botan::Path_Validation_Restrictions pvr(false, 110, false, max_age);
4✔
225
            const auto ocsp_status = Botan::PKIX::check_ocsp(cert_path, {ocsp}, {&certstore}, valid_time, pvr);
12✔
226

227
            return result.test_eq("Expected size of ocsp_status", ocsp_status.size(), 1) &&
8✔
228
                   result.test_eq("Expected size of ocsp_status[0]", ocsp_status[0].size(), 1) &&
12✔
229
                   result.confirm(std::string("Status: '") + Botan::to_string(expected) + "'",
28✔
230
                                  ocsp_status[0].contains(expected));
12✔
231
         };
8✔
232

233
         check_ocsp(Botan::calendar_point(2016, 11, 11, 12, 30, 0).to_std_timepoint(),
1✔
234
                    Botan::Certificate_Status_Code::OCSP_NOT_YET_VALID);
235
         check_ocsp(Botan::calendar_point(2016, 11, 18, 12, 30, 0).to_std_timepoint(),
1✔
236
                    Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD);
237
         check_ocsp(Botan::calendar_point(2016, 11, 20, 8, 30, 0).to_std_timepoint(),
1✔
238
                    Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD);
239
         check_ocsp(Botan::calendar_point(2016, 11, 28, 8, 30, 0).to_std_timepoint(),
1✔
240
                    Botan::Certificate_Status_Code::OCSP_HAS_EXPIRED);
241

242
         result.end_timer();
1✔
243
         return result;
1✔
244
      }
2✔
245

246
      static Test::Result test_response_verification_without_next_update_with_max_age() {
1✔
247
         Test::Result result("OCSP request check w/o next_update with max_age");
1✔
248
         result.start_timer();
1✔
249

250
         auto ee = load_test_X509_cert("x509/ocsp/patrickschmidt.pem");
1✔
251
         auto ca = load_test_X509_cert("x509/ocsp/bdrive_encryption.pem");
1✔
252
         auto trust_root = load_test_X509_cert("x509/ocsp/bdrive_root.pem");
1✔
253

254
         const std::vector<Botan::X509_Certificate> cert_path = {ee, ca, trust_root};
4✔
255

256
         auto ocsp = load_test_OCSP_resp("x509/ocsp/patrickschmidt_ocsp.der");
1✔
257

258
         Botan::Certificate_Store_In_Memory certstore;
1✔
259
         certstore.add_certificate(trust_root);
1✔
260

261
         // Some arbitrary time within the validity period of the test certs
262
         const auto max_age = std::chrono::minutes(59);
1✔
263

264
         auto check_ocsp = [&](const std::chrono::system_clock::time_point valid_time,
4✔
265
                               const Botan::Certificate_Status_Code expected) {
266
            Botan::Path_Validation_Restrictions pvr(false, 110, false, max_age);
3✔
267
            const auto ocsp_status = Botan::PKIX::check_ocsp(cert_path, {ocsp}, {&certstore}, valid_time, pvr);
9✔
268

269
            return result.test_eq("Expected size of ocsp_status", ocsp_status.size(), 1) &&
6✔
270
                   result.test_eq("Expected size of ocsp_status[0]", ocsp_status[0].size(), 1) &&
9✔
271
                   result.confirm(std::string("Status: '") + Botan::to_string(expected) + "'",
21✔
272
                                  ocsp_status[0].contains(expected));
9✔
273
         };
6✔
274

275
         check_ocsp(Botan::calendar_point(2019, 5, 28, 7, 0, 0).to_std_timepoint(),
1✔
276
                    Botan::Certificate_Status_Code::OCSP_NOT_YET_VALID);
277
         check_ocsp(Botan::calendar_point(2019, 5, 28, 7, 30, 0).to_std_timepoint(),
1✔
278
                    Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD);
279
         check_ocsp(Botan::calendar_point(2019, 5, 28, 8, 0, 0).to_std_timepoint(),
1✔
280
                    Botan::Certificate_Status_Code::OCSP_IS_TOO_OLD);
281

282
         result.end_timer();
1✔
283
         return result;
1✔
284
      }
2✔
285

286
      static Test::Result test_response_verification_without_next_update_without_max_age() {
1✔
287
         Test::Result result("OCSP request check w/o next_update w/o max_age");
1✔
288
         result.start_timer();
1✔
289

290
         auto ee = load_test_X509_cert("x509/ocsp/patrickschmidt.pem");
1✔
291
         auto ca = load_test_X509_cert("x509/ocsp/bdrive_encryption.pem");
1✔
292
         auto trust_root = load_test_X509_cert("x509/ocsp/bdrive_root.pem");
1✔
293

294
         const std::vector<Botan::X509_Certificate> cert_path = {ee, ca, trust_root};
4✔
295

296
         auto ocsp = load_test_OCSP_resp("x509/ocsp/patrickschmidt_ocsp.der");
1✔
297

298
         Botan::Certificate_Store_In_Memory certstore;
1✔
299
         certstore.add_certificate(trust_root);
1✔
300

301
         auto check_ocsp = [&](const std::chrono::system_clock::time_point valid_time,
4✔
302
                               const Botan::Certificate_Status_Code expected) {
303
            const auto ocsp_status = Botan::PKIX::check_ocsp(
6✔
304
               cert_path, {ocsp}, {&certstore}, valid_time, Botan::Path_Validation_Restrictions());
12✔
305

306
            return result.test_eq("Expected size of ocsp_status", ocsp_status.size(), 1) &&
6✔
307
                   result.test_eq("Expected size of ocsp_status[0]", ocsp_status[0].size(), 1) &&
9✔
308
                   result.confirm(std::string("Status: '") + Botan::to_string(expected) + "'",
21✔
309
                                  ocsp_status[0].contains(expected));
9✔
310
         };
6✔
311

312
         check_ocsp(Botan::calendar_point(2019, 5, 28, 7, 0, 0).to_std_timepoint(),
1✔
313
                    Botan::Certificate_Status_Code::OCSP_NOT_YET_VALID);
314
         check_ocsp(Botan::calendar_point(2019, 5, 28, 7, 30, 0).to_std_timepoint(),
1✔
315
                    Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD);
316
         check_ocsp(Botan::calendar_point(2019, 5, 28, 8, 0, 0).to_std_timepoint(),
1✔
317
                    Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD);
318

319
         result.end_timer();
1✔
320
         return result;
1✔
321
      }
2✔
322

323
      static Test::Result test_response_verification_softfail() {
1✔
324
         Test::Result result("OCSP request softfail check");
1✔
325
         result.start_timer();
1✔
326

327
         auto ee = load_test_X509_cert("x509/ocsp/randombit.pem");
1✔
328
         auto ca = load_test_X509_cert("x509/ocsp/letsencrypt.pem");
1✔
329
         auto trust_root = load_test_X509_cert("x509/ocsp/geotrust.pem");
1✔
330

331
         const std::vector<Botan::X509_Certificate> cert_path = {ee, ca, trust_root};
4✔
332

333
         Botan::OCSP::Response ocsp(Botan::Certificate_Status_Code::OCSP_NO_REVOCATION_URL);
1✔
334

335
         Botan::Certificate_Store_In_Memory certstore;
1✔
336
         certstore.add_certificate(trust_root);
1✔
337

338
         // Some arbitrary time within the validity period of the test certs
339
         const auto valid_time = Botan::calendar_point(2016, 11, 20, 8, 30, 0).to_std_timepoint();
1✔
340
         const auto ocsp_status =
1✔
341
            Botan::PKIX::check_ocsp(cert_path, {ocsp}, {&certstore}, valid_time, Botan::Path_Validation_Restrictions());
4✔
342

343
         if(result.test_eq("Expected size of ocsp_status", ocsp_status.size(), 1)) {
1✔
344
            if(result.test_eq("Expected size of ocsp_status[0]", ocsp_status[0].size(), 1)) {
1✔
345
               result.test_gt(
3✔
346
                  "Status warning", ocsp_status[0].count(Botan::Certificate_Status_Code::OCSP_NO_REVOCATION_URL), 0);
1✔
347
            }
348
         }
349

350
         result.end_timer();
1✔
351
         return result;
1✔
352
      }
3✔
353

354
   #if defined(BOTAN_HAS_ONLINE_REVOCATION_CHECKS)
355
      static Test::Result test_online_request() {
1✔
356
         Test::Result result("OCSP online check");
1✔
357
         result.start_timer();
1✔
358

359
         auto cert = load_test_X509_cert("x509/ocsp/digicert-ecdsa-int.pem");
1✔
360
         auto trust_root = load_test_X509_cert("x509/ocsp/digicert-root.pem");
1✔
361

362
         const std::vector<Botan::X509_Certificate> cert_path = {cert, trust_root};
3✔
363

364
         Botan::Certificate_Store_In_Memory certstore;
1✔
365
         certstore.add_certificate(trust_root);
1✔
366

367
         const auto ocsp_timeout = std::chrono::milliseconds(3000);
1✔
368
         const auto now = std::chrono::system_clock::now();
1✔
369
         auto ocsp_status = Botan::PKIX::check_ocsp_online(
1✔
370
            cert_path, {&certstore}, now, ocsp_timeout, Botan::Path_Validation_Restrictions());
2✔
371

372
         if(result.test_eq("Expected size of ocsp_status", ocsp_status.size(), 1)) {
1✔
373
            if(result.test_eq("Expected size of ocsp_status[0]", ocsp_status[0].size(), 1)) {
1✔
374
               const bool status_good = ocsp_status[0].contains(Botan::Certificate_Status_Code::OCSP_RESPONSE_GOOD);
1✔
375
               const bool server_not_found =
1✔
376
                  ocsp_status[0].contains(Botan::Certificate_Status_Code::OCSP_SERVER_NOT_AVAILABLE);
1✔
377
               result.confirm("Expected status", status_good || server_not_found);
2✔
378
            }
379
         }
380

381
         result.end_timer();
1✔
382
         return result;
1✔
383
      }
2✔
384
   #endif
385

386
      static Test::Result test_response_verification_with_additionally_trusted_responder() {
1✔
387
         Test::Result result("OCSP response with user-defined (additional) responder certificate");
1✔
388
         result.start_timer();
1✔
389

390
         // OCSP response is signed by 3rd party responder certificate that is
391
         // not included in the OCSP response itself
392
         // See `src/scripts/randombit_ocsp_forger.sh` for a helper script to recreate those.
393
         auto ocsp = load_test_OCSP_resp("x509/ocsp/randombit_ocsp_forged_valid_nocerts.der");
1✔
394
         auto responder = load_test_X509_cert("x509/ocsp/randombit_ocsp_forged_responder.pem");
1✔
395
         auto ca = load_test_X509_cert("x509/ocsp/letsencrypt.pem");
1✔
396

397
         std::optional<Botan::X509_Certificate> nullopt_cert;
1✔
398

399
         Botan::Certificate_Store_In_Memory trusted_responders;
1✔
400

401
         // without providing the 3rd party responder certificate no issuer will be found
402
         result.test_is_eq("cannot find signing certificate without trusted responders",
2✔
403
                           ocsp.find_signing_certificate(ca),
1✔
404
                           nullopt_cert);
405
         result.test_is_eq("cannot find signing certificate without additional help",
2✔
406
                           ocsp.find_signing_certificate(ca, &trusted_responders),
1✔
407
                           nullopt_cert);
408

409
         // add the 3rd party responder certificate to the list of trusted OCSP responder certs
410
         // to find the issuer certificate of this response
411
         trusted_responders.add_certificate(responder);
1✔
412
         result.test_is_eq("the responder certificate is returned when it is trusted",
3✔
413
                           ocsp.find_signing_certificate(ca, &trusted_responders),
1✔
414
                           std::optional(responder));
1✔
415

416
         result.test_is_eq("the responder's signature checks out",
1✔
417
                           ocsp.verify_signature(responder),
1✔
418
                           Botan::Certificate_Status_Code::OCSP_SIGNATURE_OK);
1✔
419

420
         result.end_timer();
1✔
421
         return result;
1✔
422
      }
1✔
423

424
      static Test::Result test_responder_cert_with_nocheck_extension() {
1✔
425
         Test::Result result("BDr's OCSP response contains certificate featuring NoCheck extension");
1✔
426
         result.start_timer();
1✔
427

428
         auto ocsp = load_test_OCSP_resp("x509/ocsp/bdr-ocsp-resp.der");
1✔
429
         const bool contains_cert_with_nocheck =
1✔
430
            std::find_if(ocsp.certificates().cbegin(), ocsp.certificates().cend(), [](const auto& cert) {
1✔
431
               return cert.v3_extensions().extension_set(Botan::OID::from_string("PKIX.OCSP.NoCheck"));
1✔
432
            }) != ocsp.certificates().end();
1✔
433

434
         result.confirm("Contains NoCheck extension", contains_cert_with_nocheck);
2✔
435

436
         result.end_timer();
1✔
437
         return result;
1✔
438
      }
1✔
439

440
   public:
441
      std::vector<Test::Result> run() override {
1✔
442
         std::vector<Test::Result> results;
1✔
443

444
         results.push_back(test_request_encoding());
2✔
445
         results.push_back(test_response_parsing());
2✔
446
         results.push_back(test_response_certificate_access());
2✔
447
         results.push_back(test_response_find_signing_certificate());
2✔
448
         results.push_back(test_response_verification_with_next_update_without_max_age());
2✔
449
         results.push_back(test_response_verification_with_next_update_with_max_age());
2✔
450
         results.push_back(test_response_verification_without_next_update_with_max_age());
2✔
451
         results.push_back(test_response_verification_without_next_update_without_max_age());
2✔
452
         results.push_back(test_response_verification_softfail());
2✔
453
         results.push_back(test_response_verification_with_additionally_trusted_responder());
2✔
454
         results.push_back(test_responder_cert_with_nocheck_extension());
2✔
455

456
   #if defined(BOTAN_HAS_ONLINE_REVOCATION_CHECKS)
457
         if(Test::options().run_online_tests()) {
1✔
458
            results.push_back(test_online_request());
2✔
459
         }
460
   #endif
461

462
         return results;
1✔
463
      }
×
464
};
465

466
BOTAN_REGISTER_TEST("x509", "ocsp", OCSP_Tests);
467

468
#endif
469

470
}  // namespace Botan_Tests
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc