X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Fsignature%2Fimpl%2FXMLSecSignatureImpl.cpp;h=dec07c1bf651daeaa059bd383be4d48aadfede24;hb=83de10b45721b7882182aaa8a6df0c729db8fc01;hp=57ab8bce0a0b2a4cebf2c211d48c744036cb1372;hpb=5a4c9204dc299319e9ca7c18f44918a82892045a;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp index 57ab8bc..dec07c1 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp @@ -1,5 +1,5 @@ /* -* Copyright 2001-2007 Internet2 +* Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,15 +22,16 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" #include "impl/UnknownElement.h" #include "security/Credential.h" +#include "signature/ContentReference.h" #include "signature/KeyInfo.h" #include "signature/Signature.h" #include "util/NDC.h" #include "util/XMLConstants.h" #include "util/XMLHelper.h" -#include #include #include #include @@ -45,18 +46,19 @@ #include using namespace xmlsignature; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; +using namespace xercesc; using namespace std; using xmlconstants::XMLSIG_NS; using xmlconstants::XMLSIG_PREFIX; +namespace xmlsignature { + #if defined (_MSC_VER) #pragma warning( push ) #pragma warning( disable : 4250 4251 ) #endif - -namespace xmlsignature { class XMLTOOL_DLLLOCAL XMLSecSignatureImpl : public UnknownElementImpl, public virtual Signature { @@ -89,12 +91,15 @@ namespace xmlsignature { } const XMLCh* getSignatureAlgorithm() const { if (!m_sm && m_signature) { +#ifdef XMLTOOLING_XMLSEC_SIGALGORITHM + m_sm = XMLString::replicate(m_signature->getAlgorithmURI()); +#else safeBuffer sURI; - if (signatureHashMethod2URI(sURI, m_signature->getSignatureMethod(), m_signature->getHashMethod()) == false) - return NULL; - m_sm = XMLString::replicate(sURI.sbStrToXMLCh()); + if (signatureHashMethod2URI(sURI, m_signature->getSignatureMethod(), m_signature->getHashMethod())) + m_sm = XMLString::replicate(sURI.sbStrToXMLCh()); +#endif } - return m_sm ? m_sm : DSIGConstants::s_unicodeStrURIRSA_SHA1; + return m_sm; } KeyInfo* getKeyInfo() const { return m_keyInfo; } @@ -127,12 +132,27 @@ namespace xmlsignature { mutable KeyInfo* m_keyInfo; ContentReference* m_reference; }; - -}; #if defined (_MSC_VER) #pragma warning( pop ) #endif +}; + +ContentReference::ContentReference() +{ +} + +ContentReference::~ContentReference() +{ +} + +Signature::Signature() +{ +} + +Signature::~Signature() +{ +} XMLSecSignatureImpl::~XMLSecSignatureImpl() { @@ -259,7 +279,10 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMDocument* document, const vectornewSignature(); temp->setDSIGNSPrefix(XMLSIG_PREFIX); - cachedDOM=temp->createBlankSignature(document, getCanonicalizationMethod(), getSignatureAlgorithm()); + const XMLCh* alg = getSignatureAlgorithm(); + if (!alg) + alg = DSIGConstants::s_unicodeStrURIRSA_SHA1; + cachedDOM=temp->createBlankSignature(document, getCanonicalizationMethod(), alg); m_signature = temp; } else { @@ -306,9 +329,7 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMDocument* document, const vectorgetKeyInfo(); - if (fromcred) - m_keyInfo = fromcred->cloneKeyInfo(); + m_keyInfo = credential->getKeyInfo(); } if (m_keyInfo && (!m_signature->getKeyInfoList() || m_signature->getKeyInfoList()->isEmpty())) { m_keyInfo->marshall(cachedDOM); @@ -358,7 +379,10 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMElement* parentElement, const vecto log.debug("creating empty Signature element"); DSIGSignature* temp=XMLToolingInternalConfig::getInternalConfig().m_xsecProvider->newSignature(); temp->setDSIGNSPrefix(XMLSIG_PREFIX); - cachedDOM=temp->createBlankSignature(parentElement->getOwnerDocument(), getCanonicalizationMethod(), getSignatureAlgorithm()); + const XMLCh* alg = getSignatureAlgorithm(); + if (!alg) + alg = DSIGConstants::s_unicodeStrURIRSA_SHA1; + cachedDOM=temp->createBlankSignature(parentElement->getOwnerDocument(), getCanonicalizationMethod(), alg); m_signature = temp; } else { @@ -391,9 +415,7 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMElement* parentElement, const vecto if (credential) { delete m_keyInfo; m_keyInfo = NULL; - const KeyInfo* fromcred = credential->getKeyInfo(); - if (fromcred) - m_keyInfo = fromcred->cloneKeyInfo(); + m_keyInfo = credential->getKeyInfo(); } if (m_keyInfo && (!m_signature->getKeyInfoList() || m_signature->getKeyInfoList()->isEmpty())) { m_keyInfo->marshall(cachedDOM); @@ -436,7 +458,7 @@ Signature* XMLObject* #endif SignatureBuilder::buildObject( - const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType ) const { if (!XMLString::equals(nsURI,XMLSIG_NS) || !XMLString::equals(localName,Signature::LOCAL_NAME)) @@ -454,6 +476,20 @@ SignatureBuilder::buildObject() const return new XMLSecSignatureImpl(); } +Signature* SignatureBuilder::buildSignature() { + const SignatureBuilder* b = dynamic_cast( + XMLObjectBuilder::getBuilder(xmltooling::QName(xmlconstants::XMLSIG_NS,Signature::LOCAL_NAME)) + ); + if (b) { +#ifdef HAVE_COVARIANT_RETURNS + return b->buildObject(); +#else + return dynamic_cast(b->buildObject()); +#endif + } + throw XMLObjectException("Unable to obtain typed builder for Signature."); +} + const XMLCh Signature::LOCAL_NAME[] = UNICODE_LITERAL_9(S,i,g,n,a,t,u,r,e); // Raw signature methods.