X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltoolingtest%2FSignatureTest.h;h=c50b86f6453d135d718e8ec2836132009e9e3dff;hb=a21d1f24fc3fb85928b014b69c0e6916dcb66955;hp=458fa7ee59e37115f96948fa644f949ff8ef7932;hpb=c390bc9abfd5ef673577b2da3104c3f36fb1c18d;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltoolingtest/SignatureTest.h b/xmltoolingtest/SignatureTest.h index 458fa7e..c50b86f 100644 --- a/xmltoolingtest/SignatureTest.h +++ b/xmltoolingtest/SignatureTest.h @@ -16,17 +16,12 @@ #include "XMLObjectBaseTestCase.h" +#include #include #include -#include #include #include -#include -#include -#include -#include -#include class TestContext : public ContentReference { @@ -52,12 +47,8 @@ class TestValidator : public SignatureValidator { XMLCh* m_uri; - TestValidator(const TestValidator& src) : SignatureValidator(src) { - m_uri=XMLString::replicate(src.m_uri); - } - public: - TestValidator(const XMLCh* uri, XSECCryptoKey* key) : SignatureValidator(new KeyResolver(key)) { + TestValidator(const XMLCh* uri) : SignatureValidator(XMLToolingConfig::getConfig().KeyResolverManager.newPlugin(INLINE_KEY_RESOLVER,NULL)) { m_uri=XMLString::replicate(uri); } @@ -65,10 +56,6 @@ public: XMLString::release(&m_uri); } - TestValidator* clone() const { - return new TestValidator(*this); - } - void validate(const Signature* sigObj) const { DSIGSignature* sig=sigObj->getXMLSignature(); if (!sig) @@ -90,38 +77,22 @@ public: }; class SignatureTest : public CxxTest::TestSuite { - XSECCryptoKey* m_key; - vector m_certs; + CredentialResolver* m_resolver; public: void setUp() { + m_resolver=NULL; QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME); QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME); XMLObjectBuilder::registerBuilder(qname, new SimpleXMLObjectBuilder()); XMLObjectBuilder::registerBuilder(qtype, new SimpleXMLObjectBuilder()); - string keypath=data_path + "key.pem"; - BIO* in=BIO_new(BIO_s_file_internal()); - if (in && BIO_read_filename(in,keypath.c_str())>0) { - EVP_PKEY* pkey=PEM_read_bio_PrivateKey(in, NULL, NULL, NULL); - if (pkey) { - m_key=new OpenSSLCryptoKeyRSA(pkey); - EVP_PKEY_free(pkey); - } - } - if (in) BIO_free(in); - TS_ASSERT(m_key!=NULL); - string certpath=data_path + "cert.pem"; - in=BIO_new(BIO_s_file_internal()); - if (in && BIO_read_filename(in,certpath.c_str())>0) { - X509* x=NULL; - while (x=PEM_read_bio_X509(in,NULL,NULL,NULL)) { - m_certs.push_back(new OpenSSLCryptoX509(x)); - X509_free(x); - } - } - if (in) BIO_free(in); - TS_ASSERT(m_certs.size()>0); - + string config = data_path + "FilesystemCredentialResolver.xml"; + ifstream in(config.c_str()); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in); + XercesJanitor janitor(doc); + m_resolver = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin( + FILESYSTEM_CREDENTIAL_RESOLVER,doc->getDocumentElement() + ); } void tearDown() { @@ -129,13 +100,10 @@ public: QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME); XMLObjectBuilder::deregisterBuilder(qname); XMLObjectBuilder::deregisterBuilder(qtype); - delete m_key; - for_each(m_certs.begin(),m_certs.end(),xmltooling::cleanup()); + delete m_resolver; } void testSignature() { - TS_TRACE("testSignature"); - QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME); const SimpleXMLObjectBuilder* b=dynamic_cast(XMLObjectBuilder::getBuilder(qname)); TS_ASSERT(b!=NULL); @@ -156,13 +124,15 @@ public: Signature* sig=SignatureBuilder::buildSignature(); sxObject->setSignature(sig); sig->setContentReference(new TestContext(&chNull)); - sig->setSigningKey(m_key->clone()); + + Locker locker(m_resolver); + sig->setSigningKey(m_resolver->getKey()); // Build KeyInfo. KeyInfo* keyInfo=KeyInfoBuilder::buildKeyInfo(); X509Data* x509Data=X509DataBuilder::buildX509Data(); keyInfo->getX509Datas().push_back(x509Data); - for_each(m_certs.begin(),m_certs.end(),bind1st(_addcert(),x509Data)); + for_each(m_resolver->getCertificates().begin(),m_resolver->getCertificates().end(),bind1st(_addcert(),x509Data)); sig->setKeyInfo(keyInfo); // Signing context for the whole document. @@ -185,10 +155,10 @@ public: auto_ptr sxObject2(dynamic_cast(b->buildFromDocument(doc))); TS_ASSERT(sxObject2.get()!=NULL); TS_ASSERT(sxObject2->getSignature()!=NULL); - sxObject2->getSignature()->registerValidator(new TestValidator(&chNull,m_key->clone())); try { - sxObject2->getSignature()->validate(false); + TestValidator tv(&chNull); + tv.validate(sxObject2->getSignature()); } catch (XMLToolingException& e) { TS_TRACE(e.what());