[cpp-xmltooling] 02/02: CPPXT-136 Null values in keys

Rod Widdowson rdw at steadingsoftware.com
Wed Aug 8 11:53:33 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=2e139dd8f3a70a31d844e02c6d864726f287c423

commit 2e139dd8f3a70a31d844e02c6d864726f287c423
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Aug 8 16:53:22 2018 +0100

    CPPXT-136 Null values in keys
---
 xmltoolingtest/BadKeyKeyInfoTest.h  | 29 +++++++++++++++++++++++++----
 xmltoolingtest/data/RSANullBoth.xml | 11 +++++++++++
 xmltoolingtest/data/RSANullExp.xml  | 11 +++++++++++
 xmltoolingtest/data/RSANullMod.xml  | 11 +++++++++++
 4 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/xmltoolingtest/BadKeyKeyInfoTest.h b/xmltoolingtest/BadKeyKeyInfoTest.h
index 08b9860..7515678 100644
--- a/xmltoolingtest/BadKeyKeyInfoTest.h
+++ b/xmltoolingtest/BadKeyKeyInfoTest.h
@@ -63,7 +63,7 @@ public:
     }
 
 private:
-    void RSATest(const char* file, bool fails, ParserPool& parser = XMLToolingConfig::getConfig().getValidatingParser()) {
+    void RSATest(const char* file, bool fails, ParserPool& parser = XMLToolingConfig::getConfig().getValidatingParser(), bool nullKeys=false) {
 
         string path=data_path + file;
         ifstream fs(path.c_str());
@@ -80,16 +80,23 @@ private:
         const scoped_ptr<Credential> toolingCred(dynamic_cast<Credential*>(m_resolver->resolve(kiObject.get())));
         TSM_ASSERT("Unable to resolve KeyInfo into Credential.", toolingCred.get()!=nullptr);
         TSM_ASSERT("Expected null Private Key", toolingCred->getPrivateKey()==nullptr);
-        TSM_ASSERT("Expected non-null Public Key", toolingCred->getPublicKey()!=nullptr);
-        TSM_ASSERT_EQUALS("Expected RSA key", toolingCred->getPublicKey()->getKeyType(), XSECCryptoKey::KEY_RSA_PUBLIC);
-
         const scoped_ptr<const XSECEnv> env(new XSECEnv(doc));
         const scoped_ptr<DSIGKeyInfoList> xencKey(new DSIGKeyInfoList(env.get()));
+        if (nullKeys) {
+            TSM_ASSERT_EQUALS("Expected null Public Key", toolingCred->getPublicKey(), nullptr);
+            TSM_ASSERT_THROWS("Lack of data should make xsec throw", xencKey->loadListFromXML(doc->getDocumentElement()), XSECException);
+            return;
+        }
         xencKey->loadListFromXML(doc->getDocumentElement());
 
         const scoped_ptr<Credential> xsecCred(dynamic_cast<Credential*>(m_resolver->resolve(xencKey.get())));
         TSM_ASSERT("Unable to resolve DSIGKeyInfoList into Credential.", xsecCred.get() != nullptr);
         TSM_ASSERT("Expected null Private Key", xsecCred->getPrivateKey() == nullptr);
+
+
+        TSM_ASSERT("Expected non-null Public Key", toolingCred->getPublicKey()!=nullptr);
+        TSM_ASSERT_EQUALS("Expected RSA key", toolingCred->getPublicKey()->getKeyType(), XSECCryptoKey::KEY_RSA_PUBLIC);
+
         TSM_ASSERT("Expected non-null Public Key", xsecCred->getPublicKey() != nullptr);
         TSM_ASSERT_EQUALS("Expected RSA key", xsecCred->getPublicKey()->getKeyType(), XSECCryptoKey::KEY_RSA_PUBLIC);
 
@@ -140,4 +147,18 @@ public:
         RSATest("RSABadExp64.xml", false);
     }
 
+    void testRSANullMod()
+    {
+        RSATest("RSANullMod.xml", true, XMLToolingConfig::getConfig().getParser(), true);
+    }
+
+    void testRSANullExp()
+    {
+        RSATest("RSANullExp.xml", true, XMLToolingConfig::getConfig().getParser(), true);
+    }
+
+    void testRSANullBoth()
+    {
+        RSATest("RSANullBoth.xml", true, XMLToolingConfig::getConfig().getParser(), true);
+    }
 };
diff --git a/xmltoolingtest/data/RSANullBoth.xml b/xmltoolingtest/data/RSANullBoth.xml
new file mode 100644
index 0000000..f06dbc7
--- /dev/null
+++ b/xmltoolingtest/data/RSANullBoth.xml
@@ -0,0 +1,11 @@
+<ds:KeyInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.w3.org/2000/09/xmldsig# ../../schemas/xmldsig-core-schema.xsd"
+ xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
+    <ds:KeyName>Public Key for CN=xmldap.org, OU=Domain Control Validated, O=xmldap.org</ds:KeyName>
+    <ds:KeyValue>
+        <ds:RSAKeyValue>
+            <ds:Modulus/>
+            <ds:Exponent/>
+        </ds:RSAKeyValue>
+    </ds:KeyValue>
+</ds:KeyInfo>
diff --git a/xmltoolingtest/data/RSANullExp.xml b/xmltoolingtest/data/RSANullExp.xml
new file mode 100644
index 0000000..b791063
--- /dev/null
+++ b/xmltoolingtest/data/RSANullExp.xml
@@ -0,0 +1,11 @@
+<ds:KeyInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.w3.org/2000/09/xmldsig# ../../schemas/xmldsig-core-schema.xsd"
+ xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
+    <ds:KeyName>Public Key for CN=xmldap.org, OU=Domain Control Validated, O=xmldap.org</ds:KeyName>
+    <ds:KeyValue>
+        <ds:RSAKeyValue>
+            <ds:Modulus>ANCxWwHKKOzwCtsbZUhhzQjXcyKHA7zrl8UqoCyu7haKzrEmI7udl7B6L+zxgnmVRz4zsw1PJsVYUt9zG6ABC+P7Xtx46Tk/h5gO6hWL4XBzFUuKwsMRZ0RB0sAv6iQtz6TCyH47OBSJSN24h7e/viUQ0ZtKYsJo/r8BHrnoiJk1</ds:Modulus>
+            <ds:Exponent/>
+        </ds:RSAKeyValue>
+    </ds:KeyValue>
+</ds:KeyInfo>
diff --git a/xmltoolingtest/data/RSANullMod.xml b/xmltoolingtest/data/RSANullMod.xml
new file mode 100644
index 0000000..576848e
--- /dev/null
+++ b/xmltoolingtest/data/RSANullMod.xml
@@ -0,0 +1,11 @@
+<ds:KeyInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.w3.org/2000/09/xmldsig# ../../schemas/xmldsig-core-schema.xsd"
+ xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
+    <ds:KeyName>Public Key for CN=xmldap.org, OU=Domain Control Validated, O=xmldap.org</ds:KeyName>
+    <ds:KeyValue>
+        <ds:RSAKeyValue>
+            <ds:Modulus/>
+            <ds:Exponent>AQAB</ds:Exponent>
+        </ds:RSAKeyValue>
+    </ds:KeyValue>
+</ds:KeyInfo>

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


More information about the commits mailing list