aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-11-21 21:37:45 -0500
committerJack Lloyd <[email protected]>2016-11-23 08:31:08 -0500
commitab0172b9babc0f5552f35a7dbd27076deba48c18 (patch)
treed9e77e2306748132a7d730236d7207a09258dbcc /src/tests
parent54ea7886c6099a2fde17b4c1261c6e2f2b9469f1 (diff)
Add some simple OCSP tests
Nothing much but better than nothing. Also add a useful arg check to OCSP::Request constructor.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/data/ocsp/gmail.pem27
-rw-r--r--src/tests/data/ocsp/google_g2.pem24
-rw-r--r--src/tests/data/ocsp/resp1.derbin0 -> 1595 bytes
-rw-r--r--src/tests/data/ocsp/resp2.derbin0 -> 463 bytes
-rw-r--r--src/tests/data/ocsp/resp3.derbin0 -> 472 bytes
-rw-r--r--src/tests/test_ocsp.cpp115
6 files changed, 166 insertions, 0 deletions
diff --git a/src/tests/data/ocsp/gmail.pem b/src/tests/data/ocsp/gmail.pem
new file mode 100644
index 000000000..f96928a64
--- /dev/null
+++ b/src/tests/data/ocsp/gmail.pem
@@ -0,0 +1,27 @@
+-----BEGIN CERTIFICATE-----
+MIIEnTCCA4WgAwIBAgIIQkg+DF+RYMYwDQYJKoZIhvcNAQELBQAwSTELMAkGA1UE
+BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
+cm5ldCBBdXRob3JpdHkgRzIwHhcNMTYxMTEwMTUzMDAwWhcNMTcwMjAyMTUzMDAw
+WjBjMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
+TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzESMBAGA1UEAwwJZ21h
+aWwuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuw15ghutT7Ne
+eTd1u+TXCoyDK0/Xw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fegz/De39rtbCPunC9VQtlMDas4FIOjQrSTIz
+tV/xNJMR9ka57B4YLfzoTHq7w7zw+fqeebpyKa4MqOzK9kgrfASYe1YpWEy0SBBT
+4zfVLXqyr5eDeaJJjpRJEcSopc0nIN9qBCLc2K7GI54v
+-----END CERTIFICATE-----
diff --git a/src/tests/data/ocsp/google_g2.pem b/src/tests/data/ocsp/google_g2.pem
new file mode 100644
index 000000000..b663266fc
--- /dev/null
+++ b/src/tests/data/ocsp/google_g2.pem
@@ -0,0 +1,24 @@
+-----BEGIN CERTIFICATE-----
+MIID8DCCAtigAwIBAgIDAjqSMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNVBAYTAlVT
+MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
+YWwgQ0EwHhcNMTUwNDAxMDAwMDAwWhcNMTcxMjMxMjM1OTU5WjBJMQswCQYDVQQG
+EwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzElMCMGA1UEAxMcR29vZ2xlIEludGVy
+bmV0IEF1dGhvcml0eSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
+AJwqBHdc2FCROgajguDYUEi8iT/xGXAaiEZ+4I/F8YnOIe5a/mENtzJEiaB0C1NP
+VaTOgmKV7utZX8bhBYASxF6UP7xbSDj0U/ck5vuR6RXEz/RTDfRK/J9U3n2+oGtv
+h8DQUB8oMANA2ghzUWx//zo8pzcGjr1LEQTrfSTe5vn8MXH7lNVg8y5Kr0LSy+rE
+ahqyzFPdFUuLH8gZYR/Nnag+YyuENWllhMgZxUYi+FOVvuOAShDGKuy6lyARxzmZ
+EASg8GF6lSWMTlJ14rbtCMoU/M4iarNOz0YDl5cDfsCx3nuvRTPPuj5xt970JSXC
+DTWJnZ37DhF5iR43xa+OcmkCAwEAAaOB5zCB5DAfBgNVHSMEGDAWgBTAephojYn7
+qwVkDBF9qn1luMrMTjAdBgNVHQ4EFgQUSt0GFhu89mi1dvWBtrtiGrpagS8wDgYD
+VR0PAQH/BAQDAgEGMC4GCCsGAQUFBwEBBCIwIDAeBggrBgEFBQcwAYYSaHR0cDov
+L2cuc3ltY2QuY29tMBIGA1UdEwEB/wQIMAYBAf8CAQAwNQYDVR0fBC4wLDAqoCig
+JoYkaHR0cDovL2cuc3ltY2IuY29tL2NybHMvZ3RnbG9iYWwuY3JsMBcGA1UdIAQQ
+MA4wDAYKKwYBBAHWeQIFATANBgkqhkiG9w0BAQsFAAOCAQEACE4Ep4B/EBZDXgKt
+10KA9LCO0q6z6xF9kIQYfeeQFftJf6iZBZG7esnWPDcYCZq2x5IgBzUzCeQoY3IN
+tOAynIeYxBt2iWfBUFiwE6oTGhsypb7qEZVMSGNJ6ZldIDfM/ippURaVS6neSYLA
+EHD0LPPsvCQk0E6spdleHm2SwaesSDWB+eXknGVpzYekQVA/LlelkVESWA6MCaGs
+eqQSpSfzmhCXfVUDBvdmWF9fZOGrXW2lOUh1mEwpWjqN0yvKnFUEv/TmFNWArCbt
+F4mmk2xcpMy48GaOZON9muIAs0nH5Aqq3VuDx3CQRk6+0NtZlmwu9RY23nHMAcIS
+wSHGFg==
+-----END CERTIFICATE-----
diff --git a/src/tests/data/ocsp/resp1.der b/src/tests/data/ocsp/resp1.der
new file mode 100644
index 000000000..dd5420378
--- /dev/null
+++ b/src/tests/data/ocsp/resp1.der
Binary files differ
diff --git a/src/tests/data/ocsp/resp2.der b/src/tests/data/ocsp/resp2.der
new file mode 100644
index 000000000..ea993bf5d
--- /dev/null
+++ b/src/tests/data/ocsp/resp2.der
Binary files differ
diff --git a/src/tests/data/ocsp/resp3.der b/src/tests/data/ocsp/resp3.der
new file mode 100644
index 000000000..416678cae
--- /dev/null
+++ b/src/tests/data/ocsp/resp3.der
Binary files differ
diff --git a/src/tests/test_ocsp.cpp b/src/tests/test_ocsp.cpp
new file mode 100644
index 000000000..39bc9e77a
--- /dev/null
+++ b/src/tests/test_ocsp.cpp
@@ -0,0 +1,115 @@
+/*
+* (C) 2016 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include "tests.h"
+
+#if defined(BOTAN_HAS_OCSP)
+ #include <botan/ocsp.h>
+ #include <sstream>
+#endif
+
+namespace Botan_Tests {
+
+#if defined(BOTAN_HAS_OCSP)
+
+class OCSP_Tests : public Test
+ {
+ private:
+ std::vector<byte> slurp_data_file(const std::string& path)
+ {
+ const std::string fsname = Test::data_file(path);
+ std::ifstream file(fsname.c_str());
+ if(!file.good())
+ throw Test_Error("Error reading from " + fsname);
+
+ std::vector<byte> contents;
+
+ while(file.good())
+ {
+ std::vector<byte> buf(4096);
+ file.read(reinterpret_cast<char*>(buf.data()), buf.size());
+ size_t got = file.gcount();
+
+ if(got == 0 && file.eof())
+ break;
+
+ contents.insert(contents.end(), buf.data(), buf.data() + got);
+ }
+
+ return contents;
+ }
+
+ Test::Result test_response_parsing()
+ {
+ Test::Result result("OCSP response parsing");
+
+ // Simple parsing tests
+ const std::vector<std::string> ocsp_input_paths = {
+ "ocsp/resp1.der",
+ "ocsp/resp2.der",
+ "ocsp/resp3.der"
+ };
+
+ for(std::string ocsp_input_path : ocsp_input_paths)
+ {
+ try
+ {
+ Botan::OCSP::Response resp(slurp_data_file(ocsp_input_path));
+ result.test_success("Parsed input " + ocsp_input_path);
+ }
+ catch(Botan::Exception& e)
+ {
+ result.test_failure("Parsing failed", e.what());
+ }
+ }
+
+ return result;
+ }
+
+ Test::Result test_request_encoding()
+ {
+ Test::Result result("OCSP encoding");
+
+ const Botan::X509_Certificate end_entity(Test::data_file("ocsp/gmail.pem"));
+ const Botan::X509_Certificate issuer(Test::data_file("ocsp/google_g2.pem"));
+
+ try
+ {
+ const Botan::OCSP::Request bogus(end_entity, issuer);
+ result.test_failure("Bad arguments (swapped end entity, issuer) accepted");
+ }
+ catch(Botan::Invalid_Argument&)
+ {
+ result.test_success("Bad arguments rejected");
+ }
+
+ const Botan::OCSP::Request req(issuer, end_entity);
+ const std::string expected_request = "ME4wTKADAgEAMEUwQzBBMAkGBSsOAwIaBQAEFPLgavmFih2NcJtJGSN6qbUaKH5kBBRK3QYWG7z2aLV29YG2u2IaulqBLwIIQkg+DF+RYMY=";
+
+ result.test_eq("Encoded OCSP request",
+ req.base64_encode(),
+ expected_request);
+
+ return result;
+ }
+
+ public:
+ std::vector<Test::Result> run() override
+ {
+ std::vector<Test::Result> results;
+
+ results.push_back(test_request_encoding());
+ results.push_back(test_response_parsing());
+
+ return results;
+ }
+ };
+
+BOTAN_REGISTER_TEST("ocsp", OCSP_Tests);
+
+#endif
+
+}