Replace custom code with CredentialResolver.
authorScott Cantor <cantor.2@osu.edu>
Wed, 26 Jul 2006 03:05:48 +0000 (03:05 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 26 Jul 2006 03:05:48 +0000 (03:05 +0000)
xmltoolingtest/EncryptionTest.h
xmltoolingtest/SignatureTest.h
xmltoolingtest/xmltoolingtest.vcproj

index 154f8d0..3f88890 100644 (file)
 \r
 #include <xmltooling/encryption/Decrypter.h>\r
 #include <xmltooling/encryption/Encrypter.h>\r
+#include <xmltooling/signature/CredentialResolver.h>\r
 \r
 #include <fstream>\r
-#include <openssl/pem.h>\r
 #include <xercesc/util/XMLUniDefs.hpp>\r
 #include <xsec/dsig/DSIGReference.hpp>\r
-#include <xsec/enc/XSECKeyInfoResolverDefault.hpp>\r
-#include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>\r
-#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>\r
-#include <xsec/enc/XSECCryptoException.hpp>\r
-#include <xsec/framework/XSECException.hpp>\r
 \r
 using namespace xmlencryption;\r
 \r
@@ -42,53 +37,34 @@ public:
 };\r
 \r
 class EncryptionTest : public CxxTest::TestSuite {\r
-    XSECCryptoKey* m_key;\r
-    vector<XSECCryptoX509*> m_certs;\r
+    CredentialResolver* m_resolver;\r
 public:\r
     void setUp() {\r
-        string keypath=data_path + "key.pem";\r
-        BIO* in=BIO_new(BIO_s_file_internal());\r
-        if (in && BIO_read_filename(in,keypath.c_str())>0) {\r
-            EVP_PKEY* pkey=PEM_read_bio_PrivateKey(in, NULL, NULL, NULL);\r
-            if (pkey) {\r
-                m_key=new OpenSSLCryptoKeyRSA(pkey);\r
-                EVP_PKEY_free(pkey);\r
-            }\r
-        }\r
-        if (in) BIO_free(in);\r
-        TS_ASSERT(m_key!=NULL);\r
-\r
-        string certpath=data_path + "cert.pem";\r
-        in=BIO_new(BIO_s_file_internal());\r
-        if (in && BIO_read_filename(in,certpath.c_str())>0) {\r
-            X509* x=NULL;\r
-            while (x=PEM_read_bio_X509(in,NULL,NULL,NULL)) {\r
-                m_certs.push_back(new OpenSSLCryptoX509(x));\r
-                X509_free(x);\r
-            }\r
-        }\r
-        if (in) BIO_free(in);\r
-        TS_ASSERT(m_certs.size()>0);\r
-        \r
+        m_resolver=NULL;\r
+        string config = data_path + "FilesystemCredentialResolver.xml";\r
+        ifstream in(config.c_str());\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
+        XercesJanitor<DOMDocument> janitor(doc);\r
+        m_resolver = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(\r
+            FILESYSTEM_CREDENTIAL_RESOLVER,doc->getDocumentElement()\r
+            );\r
     }\r
 \r
     void tearDown() {\r
-        delete m_key;\r
-        for_each(m_certs.begin(),m_certs.end(),xmltooling::cleanup<XSECCryptoX509>());\r
+        delete m_resolver;\r
     }\r
 \r
-    void testBasic() {\r
-        TS_TRACE("testBasic");\r
-\r
+    void testEncryption() {\r
         string path=data_path + "ComplexXMLObject.xml";\r
         ifstream fs(path.c_str());\r
         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         try {\r
+            Locker locker(m_resolver);\r
             Encrypter encrypter;\r
             Encrypter::EncryptionParams ep;\r
-            Encrypter::KeyEncryptionParams kep(DSIGConstants::s_unicodeStrURIRSA_1_5,m_key->clone());\r
+            Encrypter::KeyEncryptionParams kep(DSIGConstants::s_unicodeStrURIRSA_1_5,m_resolver->getKey());\r
             auto_ptr<EncryptedData> encData(encrypter.encryptElement(doc->getDocumentElement(),ep,&kep));\r
 \r
             string buf;\r
@@ -99,7 +75,7 @@ public:
                 dynamic_cast<EncryptedData*>(XMLObjectBuilder::buildOneFromElement(doc2->getDocumentElement(),true))\r
                 );\r
 \r
-            Decrypter decrypter(new KeyResolver(m_key->clone()));\r
+            Decrypter decrypter(new KeyResolver(m_resolver->getKey()));\r
             DOMDocumentFragment* frag = decrypter.decryptData(encData2.get());\r
             XMLHelper::serialize(static_cast<DOMElement*>(frag->getFirstChild()), buf);\r
             //TS_TRACE(buf.c_str());\r
index d52c0a2..8f3ec2c 100644 (file)
 \r
 #include "XMLObjectBaseTestCase.h"\r
 \r
+#include <xmltooling/signature/CredentialResolver.h>\r
 #include <xmltooling/signature/SignatureValidator.h>\r
 \r
 #include <fstream>\r
-#include <openssl/pem.h>\r
 #include <xercesc/util/XMLUniDefs.hpp>\r
 #include <xsec/dsig/DSIGReference.hpp>\r
-#include <xsec/enc/XSECKeyInfoResolverDefault.hpp>\r
-#include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>\r
-#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>\r
-#include <xsec/enc/XSECCryptoException.hpp>\r
-#include <xsec/framework/XSECException.hpp>\r
 \r
 class TestContext : public ContentReference\r
 {\r
@@ -82,38 +77,22 @@ public:
 };\r
 \r
 class SignatureTest : public CxxTest::TestSuite {\r
-    XSECCryptoKey* m_key;\r
-    vector<XSECCryptoX509*> m_certs;\r
+    CredentialResolver* m_resolver;\r
 public:\r
     void setUp() {\r
+        m_resolver=NULL;\r
         QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);\r
         QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);\r
         XMLObjectBuilder::registerBuilder(qname, new SimpleXMLObjectBuilder());\r
         XMLObjectBuilder::registerBuilder(qtype, new SimpleXMLObjectBuilder());\r
-        string keypath=data_path + "key.pem";\r
-        BIO* in=BIO_new(BIO_s_file_internal());\r
-        if (in && BIO_read_filename(in,keypath.c_str())>0) {\r
-            EVP_PKEY* pkey=PEM_read_bio_PrivateKey(in, NULL, NULL, NULL);\r
-            if (pkey) {\r
-                m_key=new OpenSSLCryptoKeyRSA(pkey);\r
-                EVP_PKEY_free(pkey);\r
-            }\r
-        }\r
-        if (in) BIO_free(in);\r
-        TS_ASSERT(m_key!=NULL);\r
 \r
-        string certpath=data_path + "cert.pem";\r
-        in=BIO_new(BIO_s_file_internal());\r
-        if (in && BIO_read_filename(in,certpath.c_str())>0) {\r
-            X509* x=NULL;\r
-            while (x=PEM_read_bio_X509(in,NULL,NULL,NULL)) {\r
-                m_certs.push_back(new OpenSSLCryptoX509(x));\r
-                X509_free(x);\r
-            }\r
-        }\r
-        if (in) BIO_free(in);\r
-        TS_ASSERT(m_certs.size()>0);\r
-        \r
+        string config = data_path + "FilesystemCredentialResolver.xml";\r
+        ifstream in(config.c_str());\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
+        XercesJanitor<DOMDocument> janitor(doc);\r
+        m_resolver = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(\r
+            FILESYSTEM_CREDENTIAL_RESOLVER,doc->getDocumentElement()\r
+            );\r
     }\r
 \r
     void tearDown() {\r
@@ -121,13 +100,10 @@ public:
         QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);\r
         XMLObjectBuilder::deregisterBuilder(qname);\r
         XMLObjectBuilder::deregisterBuilder(qtype);\r
-        delete m_key;\r
-        for_each(m_certs.begin(),m_certs.end(),xmltooling::cleanup<XSECCryptoX509>());\r
+        delete m_resolver;\r
     }\r
 \r
     void testSignature() {\r
-        TS_TRACE("testSignature");\r
-\r
         QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);\r
         const SimpleXMLObjectBuilder* b=dynamic_cast<const SimpleXMLObjectBuilder*>(XMLObjectBuilder::getBuilder(qname));\r
         TS_ASSERT(b!=NULL);\r
@@ -148,13 +124,15 @@ public:
         Signature* sig=SignatureBuilder::buildSignature();\r
         sxObject->setSignature(sig);\r
         sig->setContentReference(new TestContext(&chNull));\r
-        sig->setSigningKey(m_key->clone());\r
+\r
+        Locker locker(m_resolver);\r
+        sig->setSigningKey(m_resolver->getKey());\r
         \r
         // Build KeyInfo.\r
         KeyInfo* keyInfo=KeyInfoBuilder::buildKeyInfo();\r
         X509Data* x509Data=X509DataBuilder::buildX509Data();\r
         keyInfo->getX509Datas().push_back(x509Data);\r
-        for_each(m_certs.begin(),m_certs.end(),bind1st(_addcert(),x509Data));\r
+        for_each(m_resolver->getCertificates().begin(),m_resolver->getCertificates().end(),bind1st(_addcert(),x509Data));\r
         sig->setKeyInfo(keyInfo);\r
         \r
         // Signing context for the whole document.\r
@@ -179,7 +157,7 @@ public:
         TS_ASSERT(sxObject2->getSignature()!=NULL);\r
         \r
         try {\r
-            TestValidator tv(&chNull,m_key->clone());\r
+            TestValidator tv(&chNull,m_resolver->getKey());\r
             tv.validate(sxObject2->getSignature());\r
         }\r
         catch (XMLToolingException& e) {\r
index 4502fe7..3bf88f1 100644 (file)
@@ -62,7 +62,7 @@
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               AdditionalDependencies="xerces-c_2D.lib xsec_1D.lib libeay32_0_9_8D.lib"\r
+                               AdditionalDependencies="xerces-c_2D.lib xsec_1D.lib"\r
                                LinkIncremental="2"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="1"\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               AdditionalDependencies="xerces-c_2.lib xsec_1.lib libeay32_0_9_8.lib"\r
+                               AdditionalDependencies="xerces-c_2.lib xsec_1.lib"\r
                                LinkIncremental="1"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="1"\r
                                        >\r
                                        <Tool\r
                                                Name="VCCustomBuildTool"\r
-                                               CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputName)&quot;.cpp &quot;$(InputPath)&quot;"\r
+                                               CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputName)&quot;.cpp &quot;$(InputPath)&quot;&#x0D;&#x0A;"\r
                                                Outputs="&quot;$(InputName)&quot;.cpp"\r
                                        />\r
                                </FileConfiguration>\r
                                        >\r
                                        <Tool\r
                                                Name="VCCustomBuildTool"\r
-                                               CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputName)&quot;.cpp &quot;$(InputPath)&quot;"\r
+                                               CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputName)&quot;.cpp &quot;$(InputPath)&quot;&#x0D;&#x0A;"\r
                                                Outputs="&quot;$(InputName)&quot;.cpp"\r
                                        />\r
                                </FileConfiguration>\r