X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fbinding%2Fimpl%2FMessageFlowRule.cpp;h=1c61ba235f8d31d76836d4c9350a7eacc62eb210;hb=932cfaae2176c2eba1a9938dc420591a9551a7f3;hp=9db7c4ebdd7f53af6222f8eca72a7a39b7a5054c;hpb=a30857e2c0f4bcd1817aa2939ffdc0856e93a533;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/binding/impl/MessageFlowRule.cpp b/saml/binding/impl/MessageFlowRule.cpp index 9db7c4e..1c61ba2 100644 --- a/saml/binding/impl/MessageFlowRule.cpp +++ b/saml/binding/impl/MessageFlowRule.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2006 Internet2 + * Copyright 2001-2007 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +22,11 @@ #include "internal.h" #include "exceptions.h" -#include "RootObject.h" #include "binding/MessageFlowRule.h" -#include "util/SAMLConstants.h" -#include -#include #include +#include +#include using namespace opensaml; using namespace xmltooling; @@ -58,60 +56,43 @@ MessageFlowRule::MessageFlowRule(const DOMElement* e) } } -pair MessageFlowRule::evaluate( - const GenericRequest& request, - const XMLObject& message, - const saml2md::MetadataProvider* metadataProvider, - const QName* role, - const TrustEngine* trustEngine - ) const -{ - Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.MessageFlow"); - log.debug("evaluating message flow policy"); - - try { - const XMLCh* ns = message.getElementQName().getNamespaceURI(); - if (ns && (XMLString::equals(ns, samlconstants::SAML20P_NS) || XMLString::equals(ns, samlconstants::SAML1P_NS))) { - const RootObject& obj = dynamic_cast(message); - check(obj.getID(), obj.getIssueInstantEpoch()); - } - else { - log.debug("ignoring unrecognized message type"); - } - } - catch (bad_cast&) { - log.warn("caught a bad_cast while extracting issuer"); - } - return pair(NULL,NULL); -} - -void MessageFlowRule::check(const XMLCh* id, time_t issueInstant) const +void MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const { Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.MessageFlow"); log.debug("evaluating message flow policy (replay checking %s, expiration %lu)", m_checkReplay ? "on" : "off", m_expires); - - time_t skew = XMLToolingConfig::getConfig().clock_skew_secs; + time_t now = time(NULL); - if (issueInstant > now + skew) { - log.errorStream() << "rejected not-yet-valid message, timestamp (" << issueInstant << - "), newest allowed (" << now + skew << ")" << CategoryStream::ENDLINE; - throw BindingException("Message rejected, was issued in the future."); + time_t skew = XMLToolingConfig::getConfig().clock_skew_secs; + time_t issueInstant = policy.getIssueInstant(); + if (issueInstant == 0) { + log.info("unknown message timestamp, assuming current time for replay checking"); + issueInstant = now; } - else if (issueInstant < now - skew - m_expires) { - log.errorStream() << "rejected expired message, timestamp (" << issueInstant << - "), oldest allowed (" << (now - skew - m_expires) << ")" << CategoryStream::ENDLINE; - throw BindingException("Message expired, was issued too long ago."); + else { + if (issueInstant > now + skew) { + log.errorStream() << "rejected not-yet-valid message, timestamp (" << issueInstant << + "), newest allowed (" << now + skew << ")" << CategoryStream::ENDLINE; + throw BindingException("Message rejected, was issued in the future."); + } + else if (issueInstant < now - skew - m_expires) { + log.errorStream() << "rejected expired message, timestamp (" << issueInstant << + "), oldest allowed (" << (now - skew - m_expires) << ")" << CategoryStream::ENDLINE; + throw BindingException("Message expired, was issued too long ago."); + } } // Check replay. if (m_checkReplay) { + const XMLCh* id = policy.getMessageID(); + if (!id || !*id) { + log.info("unknown message ID, no replay check possible"); + return; + } ReplayCache* replayCache = XMLToolingConfig::getConfig().getReplayCache(); if (!replayCache) - throw BindingException("No ReplayCache instance available."); - else if (!id) - throw BindingException("Message did not contain an identifier."); - auto_ptr_char temp(id); - if (!replayCache->check("SAML", temp.get(), issueInstant + skew + m_expires)) { + throw BindingException("Message rejected, no ReplayCache instance available."); + auto_ptr_char temp(id); + if (!replayCache->check("MessageFlow", temp.get(), issueInstant + skew + m_expires)) { log.error("replay detected of message ID (%s)", temp.get()); throw BindingException("Rejecting replayed message ID ($1).", params(1,temp.get())); }