aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_x509_dn.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-04-04 15:45:42 -0400
committerJack Lloyd <[email protected]>2017-04-04 15:45:42 -0400
commit92f3ff5e27f6736d8a498e0d3144255c4ba37c8d (patch)
treec61436699e5afb8de2e8c3b7874c2040ec195263 /src/tests/test_x509_dn.cpp
parentd4c3f6a3409ce0ad6520c13813310f6cb523fe6f (diff)
Fix X509 DN comparisons
CVE-2017-2801
Diffstat (limited to 'src/tests/test_x509_dn.cpp')
-rw-r--r--src/tests/test_x509_dn.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tests/test_x509_dn.cpp b/src/tests/test_x509_dn.cpp
new file mode 100644
index 000000000..3a2fdf7d0
--- /dev/null
+++ b/src/tests/test_x509_dn.cpp
@@ -0,0 +1,56 @@
+/*
+* (C) 2017 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include "tests.h"
+
+#if defined(BOTAN_HAS_ASN1)
+ #include <botan/x509_dn.h>
+ #include <botan/ber_dec.h>
+#endif
+
+namespace Botan_Tests {
+
+#if defined(BOTAN_HAS_ASN1)
+class X509_DN_Comparisons_Tests : public Text_Based_Test
+ {
+ public:
+ X509_DN_Comparisons_Tests() :
+ Text_Based_Test("x509_dn.vec", "DN1,DN2")
+ {}
+
+ Test::Result run_one_test(const std::string& type, const VarMap& vars) override
+ {
+ const std::vector<uint8_t> dn_bits1 = get_req_bin(vars, "DN1");
+ const std::vector<uint8_t> dn_bits2 = get_req_bin(vars, "DN2");
+ const bool dn_same = (type == "Equal");
+
+ Test::Result result("X509_DN comparisons");
+ try
+ {
+ Botan::X509_DN dn1;
+ Botan::BER_Decoder bd1(dn_bits1);
+ dn1.decode_from(bd1);
+
+ Botan::X509_DN dn2;
+ Botan::BER_Decoder bd2(dn_bits2);
+ dn2.decode_from(bd2);
+
+ const bool compared_same = (dn1 == dn2);
+ result.test_eq("Comparison matches expected", dn_same, compared_same);
+ }
+ catch(Botan::Exception& e)
+ {
+ result.test_failure(e.what());
+ }
+
+ return result;
+ }
+ };
+
+BOTAN_REGISTER_TEST("x509_dn_cmp", X509_DN_Comparisons_Tests);
+#endif
+
+}