[cpp-xmltooling] 01/02: CPPXT-136 More tests for bad data....
Rod Widdowson
rdw at steadingsoftware.com
Wed Aug 8 11:53:32 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=47ce39fe32576533eb296311d5cc68f4abd2e197
commit 47ce39fe32576533eb296311d5cc68f4abd2e197
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Aug 8 16:10:29 2018 +0100
CPPXT-136 More tests for bad data....
https://issues.shibboleth.net/jira/browse/CPPXT-136
This time the exponent, which allows encryption
---
xmltoolingtest/BadKeyKeyInfoTest.h | 43 +++++++++++++++++++++++++++----------
xmltoolingtest/data/RSABadExp.xml | 11 ++++++++++
xmltoolingtest/data/RSABadExp64.xml | 11 ++++++++++
3 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/xmltoolingtest/BadKeyKeyInfoTest.h b/xmltoolingtest/BadKeyKeyInfoTest.h
index 9bc335a..08b9860 100644
--- a/xmltoolingtest/BadKeyKeyInfoTest.h
+++ b/xmltoolingtest/BadKeyKeyInfoTest.h
@@ -24,6 +24,7 @@
#include <xmltooling/security/KeyInfoResolver.h>
#include <xmltooling/security/Credential.h>
+#include <xmltooling/encryption/Decrypter.h>
#include <xmltooling/encryption/Encrypter.h>
#include <xmltooling/encryption/Encryption.h>
#include <xmltooling/signature/KeyInfo.h>
@@ -62,13 +63,15 @@ public:
}
private:
- void RSATest(const char* file, ParserPool& parser = XMLToolingConfig::getConfig().getValidatingParser()) {
+ void RSATest(const char* file, bool fails, ParserPool& parser = XMLToolingConfig::getConfig().getValidatingParser()) {
string path=data_path + file;
ifstream fs(path.c_str());
// Non validating parser!
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)));
@@ -95,14 +98,23 @@ private:
Encrypter::KeyEncryptionParams xsecKep(*xsecCred.get());
Encrypter::KeyEncryptionParams toolingKep(*toolingCred.get());
//
- TSM_ASSERT_THROWS("Bad RSA key throws an assert", encrypter.encryptElement(doc->getDocumentElement(), ep, &xsecKep), EncryptionException);
- /* string xsecBuffer, toolingBuffer;
- XMLHelper::serialize(xsecEncData->marshall(), xsecBuffer);
- XMLHelper::serialize(toolingEncData->marshall(), toolingBuffer);
- */
- // TSM_ASSERT_EQUALS("Encrytped Data differs", xsecBuffer, toolingBuffer);
-
- TSM_ASSERT_THROWS("Bad RSA key throws an assert", encrypter.encryptElement(doc->getDocumentElement(), ep, &toolingKep), EncryptionException);
+ if (fails) {
+ TSM_ASSERT_THROWS("Bad RSA key throws an assert", encrypter.encryptElement(doc->getDocumentElement(), ep, &xsecKep), EncryptionException);
+ TSM_ASSERT_THROWS("Bad RSA key throws an assert", encrypter.encryptElement(doc->getDocumentElement(), ep, &toolingKep), EncryptionException);
+ }
+ else {
+ scoped_ptr<EncryptedData> toolingEncData(encrypter.encryptElement(doc->getDocumentElement(), ep, &toolingKep));
+ scoped_ptr<EncryptedData> xsecEncData(encrypter.encryptElement(doc->getDocumentElement(), ep, &xsecKep));
+
+ string xsecBuffer, toolingBuffer;
+ XMLHelper::serialize(xsecEncData->marshall(), xsecBuffer);
+ XMLHelper::serialize(toolingEncData->marshall(), toolingBuffer);
+ const char* cx= xsecBuffer.c_str();
+ const char* ct= toolingBuffer.c_str();
+
+ // The decrypted data is completely different. hmm.
+ // TSM_ASSERT_EQUALS("Encrytped Data differs", cx, ct);
+ }
}
@@ -110,13 +122,22 @@ public:
void testRSABadMod()
{
- RSATest("RSABadMod.xml", XMLToolingConfig::getConfig().getParser());
+ RSATest("RSABadMod.xml", true, XMLToolingConfig::getConfig().getParser());
}
void testRSABadMod64()
{
- RSATest("RSABadMod64.xml");
+ RSATest("RSABadMod64.xml", true);
+ }
+
+ void testRSABadExp()
+ {
+ RSATest("RSABadExp.xml", false, XMLToolingConfig::getConfig().getParser());
}
+ void testRSABadExp64()
+ {
+ RSATest("RSABadExp64.xml", false);
+ }
};
diff --git a/xmltoolingtest/data/RSABadExp.xml b/xmltoolingtest/data/RSABadExp.xml
new file mode 100644
index 0000000..3ab3c3a
--- /dev/null
+++ b/xmltoolingtest/data/RSABadExp.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>Nibble A Happy Warthog</ds:Exponent>
+ </ds:RSAKeyValue>
+ </ds:KeyValue>
+</ds:KeyInfo>
diff --git a/xmltoolingtest/data/RSABadExp64.xml b/xmltoolingtest/data/RSABadExp64.xml
new file mode 100644
index 0000000..bb33b46
--- /dev/null
+++ b/xmltoolingtest/data/RSABadExp64.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>TmliYmxlQUhhcHB5V2FydGhvZw==</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