[cpp-xmltooling] 01/03: CPPXT-136 Test bad/missing DEREncodedKeyValue

Rod Widdowson rdw at steadingsoftware.com
Wed Oct 24 11:08:05 EDT 2018


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository cpp-xmltooling.

View the commit online:
http://git.shibboleth.net/view/?p=cpp-xmltooling.git;a=commit;h=6776816ab62b15895c44756cf3fc8db68affa413

commit 6776816ab62b15895c44756cf3fc8db68affa413
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Oct 15 15:24:00 2018 +0100

    CPPXT-136 Test bad/missing DEREncodedKeyValue
    
    https://issues.shibboleth.net/jira/browse/CPPXT-136
---
 xmltoolingtest/BadKeyInfoTest.h       | 44 +++++++++++++++++++++++++++++++++++
 xmltoolingtest/data/DERValueBad.xml   |  3 +++
 xmltoolingtest/data/DERValueBad64.xml |  3 +++
 xmltoolingtest/data/DERValueNull.xml  |  3 +++
 4 files changed, 53 insertions(+)

diff --git a/xmltoolingtest/BadKeyInfoTest.h b/xmltoolingtest/BadKeyInfoTest.h
index bae3141..2d3b881 100644
--- a/xmltoolingtest/BadKeyInfoTest.h
+++ b/xmltoolingtest/BadKeyInfoTest.h
@@ -319,6 +319,35 @@ private:
     }
 #endif
 
+    void DERTest(const char* file, bool xsecLoadThrows)
+    {
+
+	string path = data_path + file;
+	ifstream fs(path.c_str());
+	ParserPool& parser = XMLToolingConfig::getConfig().getParser();
+	DOMDocument* doc = parser.parse(fs);
+
+	TS_ASSERT(doc != nullptr);
+
+	const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
+	TS_ASSERT(b != nullptr);
+	const scoped_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));
+	TS_ASSERT(kiObject.get() != nullptr);
+
+	const scoped_ptr<const XSECEnv> env(new XSECEnv(doc));
+	const scoped_ptr<DSIGKeyInfoList> xencKey(new DSIGKeyInfoList(env.get()));
+	if (xsecLoadThrows) {
+	    TSM_ASSERT_THROWS("Bad EC key throws during load", xencKey->loadListFromXML(doc->getDocumentElement()), XSECException);
+	}
+	else {
+	    xencKey->loadListFromXML(doc->getDocumentElement());
+	    const scoped_ptr<X509Credential> xsecCred(dynamic_cast<X509Credential*>(m_resolver->resolve(xencKey.get())));
+	    TSM_ASSERT("XsecCred was non null", xsecCred.get() == nullptr)
+	}
+	const scoped_ptr<X509Credential> toolingCred(dynamic_cast<X509Credential*>(m_resolver->resolve(kiObject.get())));
+	TSM_ASSERT("ToolCred was non null", toolingCred.get() == nullptr)
+    }
+
 public:
     void testRSABadMod()
     {
@@ -612,4 +641,19 @@ public:
     }
 
 #endif
+
+    void testDERBad()
+    {
+	DERTest("DERValueBad.xml", false);
+    }
+
+    void testDERBad64()
+    {
+	DERTest("DERValueBad64.xml", false);
+    }
+
+    void testDERNull()
+    {
+	DERTest("DERValueNull.xml", true);
+    }
 };
diff --git a/xmltoolingtest/data/DERValueBad.xml b/xmltoolingtest/data/DERValueBad.xml
new file mode 100644
index 0000000..4991e8d
--- /dev/null
+++ b/xmltoolingtest/data/DERValueBad.xml
@@ -0,0 +1,3 @@
+<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ds11="http://www.w3.org/2009/xmldsig11#">
+  <ds11:DEREncodedKeyValue>INVALID</ds11:DEREncodedKeyValue>
+</ds:KeyInfo>
diff --git a/xmltoolingtest/data/DERValueBad64.xml b/xmltoolingtest/data/DERValueBad64.xml
new file mode 100644
index 0000000..49f9241
--- /dev/null
+++ b/xmltoolingtest/data/DERValueBad64.xml
@@ -0,0 +1,3 @@
+<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ds11="http://www.w3.org/2009/xmldsig11#">
+  <ds11:DEREncodedKeyValue>RG1FUW9vK1lBVk5UVUdva2N5MWtpMDFXZ01mVEJzdlBxWWpSRHpjbUY3cDRvSjhuZVZDbjBCOTkwanY5Vzh2OGdwdnhyK3c1WnBRa0p5Ym5nSkZBanc9PQ==</ds11:DEREncodedKeyValue>
+</ds:KeyInfo>
diff --git a/xmltoolingtest/data/DERValueNull.xml b/xmltoolingtest/data/DERValueNull.xml
new file mode 100644
index 0000000..58f7495
--- /dev/null
+++ b/xmltoolingtest/data/DERValueNull.xml
@@ -0,0 +1,3 @@
+<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ds11="http://www.w3.org/2009/xmldsig11#">
+  <ds11:DEREncodedKeyValue/>
+</ds:KeyInfo>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list