X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fbinding%2Fimpl%2FXMLSigningRule.cpp;h=029f14c681e3e4e01f6856623a9ce273fa6ece1c;hb=694b587ec84095f2d7c0987724956673fe7eb2b5;hp=552cef88a12e453febfac70e7f4c908361a9f467;hpb=a22a5e16b79b7a40e139b75ebe8d95a9a6aed51c;p=shibboleth%2Fopensaml2.git diff --git a/saml/binding/impl/XMLSigningRule.cpp b/saml/binding/impl/XMLSigningRule.cpp index 552cef8..029f14c 100644 --- a/saml/binding/impl/XMLSigningRule.cpp +++ b/saml/binding/impl/XMLSigningRule.cpp @@ -26,10 +26,8 @@ #include "saml2/core/Assertions.h" #include "saml2/metadata/Metadata.h" #include "saml2/metadata/MetadataProvider.h" -#include "security/TrustEngine.h" +#include "signature/SignatureProfileValidator.h" -#include -#include #include using namespace opensaml::saml2md; @@ -45,73 +43,42 @@ namespace opensaml { } }; -pair XMLSigningRule::evaluate( - const GenericRequest& request, - const XMLObject& message, - const MetadataProvider* metadataProvider, - const QName* role, - const opensaml::TrustEngine* trustEngine, - const MessageExtractor& extractor - ) const +void XMLSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const { Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.XMLSigning"); log.debug("evaluating message signing policy"); - pair ret = pair(NULL,NULL); + if (!policy.getIssuerMetadata()) { + log.debug("ignoring message, no issuer metadata supplied"); + return; + } + else if (!policy.getTrustEngine()) { + log.debug("ignoring message, no TrustEngine supplied"); + return; + } - if (!metadataProvider || !role || !trustEngine) { - log.debug("ignoring message, no metadata or trust information supplied"); - return ret; + const SignableObject* signable = dynamic_cast(&message); + if (!signable || !signable->getSignature()) { + log.debug("ignoring unsigned or unrecognized message"); + return; } + log.debug("validating signature profile"); try { - const RootObject& root = dynamic_cast(message); - if (!root.getSignature()) { - log.debug("ignoring unsigned message"); - return ret; - } - - log.debug("extracting issuer from message"); - pair issuerInfo = extractor.getIssuerAndProtocol(message); - - auto_ptr issuer(issuerInfo.first); - if (!issuerInfo.first || !issuerInfo.second || - (issuer->getFormat() && !XMLString::equals(issuer->getFormat(), saml2::NameIDType::ENTITY))) { - log.warn("issuer identity not estabished, or was not an entityID"); - return ret; - } - - log.debug("searching metadata for message issuer..."); - const EntityDescriptor* entity = metadataProvider->getEntityDescriptor(issuer->getName()); - if (!entity) { - auto_ptr_char temp(issuer->getName()); - log.warn("no metadata found, can't establish identity of issuer (%s)", temp.get()); - return ret; - } - - log.debug("matched message issuer against metadata, searching for applicable role..."); - const RoleDescriptor* roledesc=entity->getRoleDescriptor(*role, issuerInfo.second); - if (!roledesc) { - log.warn("unable to find compatible role (%s) in metadata", role->toString().c_str()); - return ret; - } - - if (!trustEngine->validate(*(root.getSignature()), *roledesc, metadataProvider->getKeyResolver())) { - log.error("unable to verify signature on message with supplied trust engine"); - return ret; - } - - if (log.isDebugEnabled()) { - auto_ptr_char iname(entity->getEntityID()); - log.debug("message from (%s), signature verified", iname.get()); - } - - ret.first = issuer.release(); - ret.second = roledesc; + SignatureProfileValidator sigval; + sigval.validate(signable->getSignature()); + } + catch (ValidationException& ve) { + log.error("signature profile failed to validate: %s", ve.what()); + return; } - catch (bad_cast&) { - // Just trap it. - log.warn("caught a bad_cast while extracting issuer"); + + if (!policy.getTrustEngine()->validate( + *(signable->getSignature()), *(policy.getIssuerMetadata()), policy.getMetadataProvider()->getKeyResolver() + )) { + log.error("unable to verify message signature with supplied trust engine"); + return; } - return ret; + + log.debug("signature verified against message issuer"); }