SSPCPP-616 - clean up concatenated string literals
[shibboleth/cpp-xmltooling.git] / xmltooling / security / impl / InlineKeyResolver.cpp
index f437ac4..a4baf85 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  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.
- * You may obtain a copy of the License at
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
@@ -25,6 +29,8 @@
 #include "security/BasicX509Credential.h"
 #include "security/KeyInfoCredentialContext.h"
 #include "security/KeyInfoResolver.h"
+#include "security/SecurityHelper.h"
+#include "security/XSECCryptoX509CRL.h"
 #include "signature/KeyInfo.h"
 #include "signature/Signature.h"
 #include "util/NDC.h"
 #include "util/XMLConstants.h"
 #include "validation/ValidatorSuite.h"
 
+#include <boost/iterator/indirect_iterator.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xsec/dsig/DSIGKeyInfoX509.hpp>
 #include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
-#include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>
-#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
-#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp>
+#include <xsec/enc/XSECCryptoX509.hpp>
+#include <xsec/enc/XSECCryptoKeyRSA.hpp>
+#include <xsec/enc/XSECCryptoKeyDSA.hpp>
+#ifdef XMLTOOLING_XMLSEC_ECC
+# include <xsec/enc/XSECCryptoKeyEC.hpp>
+#endif
 #include <xsec/enc/XSECCryptoException.hpp>
 #include <xsec/framework/XSECException.hpp>
 
@@ -45,6 +55,7 @@ using namespace xmlsignature;
 using namespace xmltooling::logging;
 using namespace xmltooling;
 using namespace xercesc;
+using namespace boost;
 using namespace std;
 
 namespace xmltooling {
@@ -52,27 +63,24 @@ namespace xmltooling {
     class XMLTOOL_DLLLOCAL InlineCredential : public BasicX509Credential
     {
     public:
-        InlineCredential(const KeyInfo* keyInfo=NULL) : BasicX509Credential(keyInfo!=NULL), m_credctx(new KeyInfoCredentialContext(keyInfo)) {
-        }
-        InlineCredential(DSIGKeyInfoList* keyInfo) : BasicX509Credential(false), m_credctx(new KeyInfoCredentialContext(keyInfo)) {
-        }
-        InlineCredential(KeyInfoCredentialContext* context) : BasicX509Credential(context->getKeyInfo()!=NULL), m_credctx(NULL) {
-        }
-        virtual ~InlineCredential() {
-            delete m_credctx;
-        }
+        InlineCredential(const KeyInfo* keyInfo=nullptr) : BasicX509Credential(keyInfo!=nullptr), m_credctx(new KeyInfoCredentialContext(keyInfo)) {}
+        InlineCredential(DSIGKeyInfoList* keyInfo) : BasicX509Credential(false), m_credctx(new KeyInfoCredentialContext(keyInfo)) {}
+        InlineCredential(KeyInfoCredentialContext* context) : BasicX509Credential(context->getKeyInfo()!=nullptr) {}
+        virtual ~InlineCredential() {}
 
         XSECCryptoKey* getPrivateKey() const {
-            return NULL;
+            return nullptr;
         }
 
         KeyInfo* getKeyInfo(bool compact=false) const {
-            KeyInfo* ret = m_credctx->getKeyInfo() ? m_credctx->getKeyInfo()->cloneKeyInfo() : NULL;
+            KeyInfo* ret = m_credctx->getKeyInfo() ? m_credctx->getKeyInfo()->cloneKeyInfo() : nullptr;
             if (ret) {
-                ret->setId(NULL);
+                ret->setId(nullptr);
                 ret->getRetrievalMethods().clear();
+                ret->getKeyInfoReferences().clear();
                 if (compact) {
                     ret->getKeyValues().clear();
+                    ret->getDEREncodedKeyValues().clear();
                     ret->getSPKIDatas().clear();
                     ret->getPGPDatas().clear();
                     ret->getUnknownXMLObjects().clear();
@@ -80,6 +88,7 @@ namespace xmltooling {
                     for (VectorOf(X509Data)::size_type pos = 0; pos < x509Datas.size();) {
                         x509Datas[pos]->getX509Certificates().clear();
                         x509Datas[pos]->getX509CRLs().clear();
+                        x509Datas[pos]->getOCSPResponses().clear();
                         x509Datas[pos]->getUnknownXMLObjects().clear();
                         if (x509Datas[pos]->hasChildren())
                             ++pos;
@@ -90,83 +99,98 @@ namespace xmltooling {
             }
             if (!ret->hasChildren()) {
                 delete ret;
-                ret = NULL;
+                ret = nullptr;
             }
             return ret;
         }
         
         const CredentialContext* getCredentalContext() const {
-            return m_credctx;
+            return m_credctx.get();
         }
 
         void setCredentialContext(KeyInfoCredentialContext* context) {
-            m_credctx = context;
+            m_credctx.reset(context);
         }
 
-        void resolve(const KeyInfo* keyInfo, int types=0);
-        void resolve(DSIGKeyInfoList* keyInfo, int types=0);
+        void resolve(const KeyInfo* keyInfo, int types=0, bool followRefs=false);
+        void resolve(DSIGKeyInfoList* keyInfo, int types=0, bool followRefs=false);
+
+        bool isEmpty() const {
+            return (!m_key && m_xseccerts.empty() && m_crls.empty() &&
+                m_keyNames.empty() && m_serial.empty() && m_issuerName.empty());
+        }
 
     private:
-        bool resolveCerts(const KeyInfo* keyInfo);
-        bool resolveKey(const KeyInfo* keyInfo);
-        bool resolveCRLs(const KeyInfo* keyInfo);
+        bool resolveCerts(const KeyInfo* keyInfo, bool followRefs=false);
+        bool resolveKey(const KeyInfo* keyInfo, bool followRefs=false);
+        bool resolveCRLs(const KeyInfo* keyInfo, bool followRefs=false);
 
-        KeyInfoCredentialContext* m_credctx;
+        auto_ptr<KeyInfoCredentialContext> m_credctx;
     };
 
+    static const XMLCh keyInfoReferences[] = UNICODE_LITERAL_17(k,e,y,I,n,f,o,R,e,f,e,r,e,n,c,e,s);
+
     class XMLTOOL_DLLLOCAL InlineKeyResolver : public KeyInfoResolver
     {
     public:
-        InlineKeyResolver() {}
+        InlineKeyResolver(const DOMElement* e)
+            : m_followRefs(XMLHelper::getAttrBool(e, false, keyInfoReferences)) {
+        }
+
         virtual ~InlineKeyResolver() {}
 
         Credential* resolve(const KeyInfo* keyInfo, int types=0) const {
             if (!keyInfo)
-                return NULL;
+                return nullptr;
             if (types == 0)
                 types = Credential::RESOLVE_KEYS|X509Credential::RESOLVE_CERTS|X509Credential::RESOLVE_CRLS;
             auto_ptr<InlineCredential> credential(new InlineCredential(keyInfo));
-            credential->resolve(keyInfo, types);
-            return credential.release();
+            credential->resolve(keyInfo, types, m_followRefs);
+            return credential->isEmpty() ? nullptr : credential.release();
         }
         Credential* resolve(DSIGKeyInfoList* keyInfo, int types=0) const {
             if (!keyInfo)
-                return NULL;
+                return nullptr;
             if (types == 0)
                 types = Credential::RESOLVE_KEYS|X509Credential::RESOLVE_CERTS|X509Credential::RESOLVE_CRLS;
             auto_ptr<InlineCredential> credential(new InlineCredential(keyInfo));
-            credential->resolve(keyInfo, types);
-            return credential.release();
+            credential->resolve(keyInfo, types, m_followRefs);
+            return credential->isEmpty() ? nullptr : credential.release();
         }
         Credential* resolve(KeyInfoCredentialContext* context, int types=0) const {
             if (!context)
-                return NULL;
+                return nullptr;
             if (types == 0)
                 types = Credential::RESOLVE_KEYS|X509Credential::RESOLVE_CERTS|X509Credential::RESOLVE_CRLS;
             auto_ptr<InlineCredential> credential(new InlineCredential(context));
             if (context->getKeyInfo())
-                credential->resolve(context->getKeyInfo(), types);
+                credential->resolve(context->getKeyInfo(), types, m_followRefs);
             else if (context->getNativeKeyInfo())
-                credential->resolve(context->getNativeKeyInfo(), types);
-            credential->setCredentialContext(context);
+                credential->resolve(context->getNativeKeyInfo(), types, m_followRefs);
+            if (credential->isEmpty())
+                return nullptr;
+            credential->setCredentialContext(context);  // transfers ownership to credential
             return credential.release();
         }
+
+    private:
+        bool m_followRefs;
     };
 
     KeyInfoResolver* XMLTOOL_DLLLOCAL InlineKeyInfoResolverFactory(const DOMElement* const & e)
     {
-        return new InlineKeyResolver();
+        return new InlineKeyResolver(e);
     }
 };
 
-void InlineCredential::resolve(const KeyInfo* keyInfo, int types)
+void InlineCredential::resolve(const KeyInfo* keyInfo, int types, bool followRefs)
 {
 #ifdef _DEBUG
     NDC ndc("resolve");
 #endif
 
     if (types & X509Credential::RESOLVE_CERTS)
-        resolveCerts(keyInfo);
+        resolveCerts(keyInfo, followRefs);
     
     if (types & Credential::RESOLVE_KEYS) {
         if (types & X509Credential::RESOLVE_CERTS) {
@@ -174,24 +198,25 @@ void InlineCredential::resolve(const KeyInfo* keyInfo, int types)
             if (!m_xseccerts.empty())
                 m_key = m_xseccerts.front()->clonePublicKey();
             else
-                resolveKey(keyInfo);
+                resolveKey(keyInfo, followRefs);
         }
         // Otherwise try directly for a key and then go for certs if none is found.
-        else if (!resolveKey(keyInfo) && resolveCerts(keyInfo)) {
+        else if (!resolveKey(keyInfo, followRefs) && resolveCerts(keyInfo, followRefs)) {
             m_key = m_xseccerts.front()->clonePublicKey();
         }
     }
 
     if (types & X509Credential::RESOLVE_CRLS)
-        resolveCRLs(keyInfo);
+        resolveCRLs(keyInfo, followRefs);
 
     const XMLCh* n;
     char* kn;
     const vector<KeyName*>& knames=keyInfo->getKeyNames();
-    for (vector<KeyName*>::const_iterator kn_i=knames.begin(); kn_i!=knames.end(); ++kn_i) {
-        n=(*kn_i)->getName();
+    for (indirect_iterator<vector<KeyName*>::const_iterator> kn_i = make_indirect_iterator(knames.begin());
+            kn_i != make_indirect_iterator(knames.end()); ++kn_i) {
+        n = kn_i->getName();
         if (n && *n) {
-            kn=toUTF8(n);
+            kn = toUTF8(n);
             m_keyNames.insert(kn);
             delete[] kn;
         }
@@ -228,16 +253,17 @@ void InlineCredential::resolve(const KeyInfo* keyInfo, int types)
     }
 }
 
-bool InlineCredential::resolveKey(const KeyInfo* keyInfo)
+bool InlineCredential::resolveKey(const KeyInfo* keyInfo, bool followRefs)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT ".KeyInfoResolver." INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:KeyValue
     const vector<KeyValue*>& keyValues = keyInfo->getKeyValues();
-    for (vector<KeyValue*>::const_iterator i=keyValues.begin(); i!=keyValues.end(); ++i) {
+    for (indirect_iterator<vector<KeyValue*>::const_iterator> i = make_indirect_iterator(keyValues.begin());
+            i != make_indirect_iterator(keyValues.end()); ++i) {
         try {
-            SchemaValidators.validate(*i);    // see if it's a "valid" key
-            RSAKeyValue* rsakv = (*i)->getRSAKeyValue();
+            SchemaValidators.validate(*(i.base()));    // see if it's a "valid" key
+            RSAKeyValue* rsakv = i->getRSAKeyValue();
             if (rsakv) {
                 log.debug("resolving ds:RSAKeyValue");
                 auto_ptr_char mod(rsakv->getModulus()->getValue());
@@ -248,7 +274,7 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo)
                 m_key = rsa.release();
                 return true;
             }
-            DSAKeyValue* dsakv = (*i)->getDSAKeyValue();
+            DSAKeyValue* dsakv = i->getDSAKeyValue();
             if (dsakv) {
                 log.debug("resolving ds:DSAKeyValue");
                 auto_ptr<XSECCryptoKeyDSA> dsa(XSECPlatformUtils::g_cryptoProvider->keyDSA());
@@ -269,6 +295,20 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo)
                 m_key = dsa.release();
                 return true;
             }
+#ifdef XMLTOOLING_XMLSEC_ECC
+            ECKeyValue* eckv = i->getECKeyValue();
+            if (eckv && eckv->getNamedCurve() && eckv->getPublicKey()) {
+                log.warn("resolving ds11:ECKeyValue");
+                auto_ptr<XSECCryptoKeyEC> ec(XSECPlatformUtils::g_cryptoProvider->keyEC());
+                auto_ptr_char uri(eckv->getNamedCurve()->getURI());
+                auto_ptr_char val(eckv->getPublicKey()->getValue());
+                if (uri.get() && val.get()) {
+                    ec->loadPublicKeyBase64(uri.get(), val.get(), XMLString::stringLen(val.get()));
+                    m_key = ec.release();
+                    return true;
+                }
+            }
+#endif
         }
         catch (ValidationException& ex) {
             log.warn("skipping invalid ds:KeyValue (%s)", ex.what());
@@ -282,20 +322,60 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo)
         }
     }
 
+    // Check for ds11:DEREncodedKeyValue
+    const vector<DEREncodedKeyValue*>& derValues = keyInfo->getDEREncodedKeyValues();
+    for (indirect_iterator<vector<DEREncodedKeyValue*>::const_iterator> j = make_indirect_iterator(derValues.begin());
+            j != make_indirect_iterator(derValues.end()); ++j) {
+        log.debug("resolving ds11:DEREncodedKeyValue");
+        m_key = SecurityHelper::fromDEREncoding(j->getValue());
+        if (m_key)
+            return true;
+        log.warn("failed to resolve ds11:DEREncodedKeyValue");
+    }
+
+
+    if (followRefs) {
+        // Check for KeyInfoReference.
+        const XMLCh* fragID=nullptr;
+        const XMLObject* treeRoot=nullptr;
+        const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
+        for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+                ref != make_indirect_iterator(refs.end()); ++ref) {
+            fragID = ref->getURI();
+            if (!fragID || *fragID != chPound || !*(fragID+1)) {
+                log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
+                continue;
+            }
+            if (!treeRoot) {
+                treeRoot = keyInfo;
+                while (treeRoot->getParent())
+                    treeRoot = treeRoot->getParent();
+            }
+            keyInfo = dynamic_cast<const KeyInfo*>(XMLHelper::getXMLObjectById(*treeRoot, fragID+1));
+            if (!keyInfo) {
+                log.warn("skipping ds11:KeyInfoReference, local reference did not resolve to a ds:KeyInfo");
+                continue;
+            }
+            if (resolveKey(keyInfo, false))
+                return true;
+        }
+    }
+
     return false;
 }
 
-bool InlineCredential::resolveCerts(const KeyInfo* keyInfo)
+bool InlineCredential::resolveCerts(const KeyInfo* keyInfo, bool followRefs)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT ".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:X509Data
     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
-    for (vector<X509Data*>::const_iterator j=x509Datas.begin(); m_xseccerts.empty() && j!=x509Datas.end(); ++j) {
+    for (vector<X509Data*>::const_iterator j = x509Datas.begin(); m_xseccerts.empty() && j != x509Datas.end(); ++j) {
         const vector<X509Certificate*> x509Certs=const_cast<const X509Data*>(*j)->getX509Certificates();
-        for (vector<X509Certificate*>::const_iterator k=x509Certs.begin(); k!=x509Certs.end(); ++k) {
+        for (indirect_iterator<vector<X509Certificate*>::const_iterator> k = make_indirect_iterator(x509Certs.begin());
+                k != make_indirect_iterator(x509Certs.end()); ++k) {
             try {
-                auto_ptr_char x((*k)->getValue());
+                auto_ptr_char x(k->getValue());
                 if (!x.get()) {
                     log.warn("skipping empty ds:X509Certificate");
                 }
@@ -315,22 +395,51 @@ bool InlineCredential::resolveCerts(const KeyInfo* keyInfo)
             }
         }
     }
+
+    if (followRefs && m_xseccerts.empty()) {
+        // Check for KeyInfoReference.
+        const XMLCh* fragID=NULL;
+        const XMLObject* treeRoot=NULL;
+        const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
+        for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+                ref != make_indirect_iterator(refs.end()); ++ref) {
+            fragID = ref->getURI();
+            if (!fragID || *fragID != chPound || !*(fragID+1)) {
+                log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
+                continue;
+            }
+            if (!treeRoot) {
+                treeRoot = keyInfo;
+                while (treeRoot->getParent())
+                    treeRoot = treeRoot->getParent();
+            }
+            keyInfo = dynamic_cast<const KeyInfo*>(XMLHelper::getXMLObjectById(*treeRoot, fragID+1));
+            if (!keyInfo) {
+                log.warn("skipping ds11:KeyInfoReference, local reference did not resolve to a ds:KeyInfo");
+                continue;
+            }
+            if (resolveCerts(keyInfo, false))
+                return true;
+        }
+        return false;
+    }
     
     log.debug("resolved %d certificate(s)", m_xseccerts.size());
     return !m_xseccerts.empty();
 }
 
-bool InlineCredential::resolveCRLs(const KeyInfo* keyInfo)
+bool InlineCredential::resolveCRLs(const KeyInfo* keyInfo, bool followRefs)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT ".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:X509Data
     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
     for (vector<X509Data*>::const_iterator j=x509Datas.begin(); j!=x509Datas.end(); ++j) {
         const vector<X509CRL*> x509CRLs=const_cast<const X509Data*>(*j)->getX509CRLs();
-        for (vector<X509CRL*>::const_iterator k=x509CRLs.begin(); k!=x509CRLs.end(); ++k) {
+        for (indirect_iterator<vector<X509CRL*>::const_iterator> k = make_indirect_iterator(x509CRLs.begin());
+                k != make_indirect_iterator(x509CRLs.end()); ++k) {
             try {
-                auto_ptr_char x((*k)->getValue());
+                auto_ptr_char x(k->getValue());
                 if (!x.get()) {
                     log.warn("skipping empty ds:X509CRL");
                 }
@@ -351,11 +460,39 @@ bool InlineCredential::resolveCRLs(const KeyInfo* keyInfo)
         }
     }
 
+    if (followRefs && m_crls.empty()) {
+        // Check for KeyInfoReference.
+        const XMLCh* fragID=NULL;
+        const XMLObject* treeRoot=NULL;
+        const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
+        for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+                ref != make_indirect_iterator(refs.end()); ++ref) {
+            fragID = ref->getURI();
+            if (!fragID || *fragID != chPound || !*(fragID+1)) {
+                log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
+                continue;
+            }
+            if (!treeRoot) {
+                treeRoot = keyInfo;
+                while (treeRoot->getParent())
+                    treeRoot = treeRoot->getParent();
+            }
+            keyInfo = dynamic_cast<const KeyInfo*>(XMLHelper::getXMLObjectById(*treeRoot, fragID+1));
+            if (!keyInfo) {
+                log.warn("skipping ds11:KeyInfoReference, local reference did not resolve to a ds:KeyInfo");
+                continue;
+            }
+            if (resolveCRLs(keyInfo, false))
+                return true;
+        }
+        return false;
+    }
+
     log.debug("resolved %d CRL(s)", m_crls.size());
     return !m_crls.empty();
 }
 
-void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types)
+void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types, bool followRefs)
 {
 #ifdef _DEBUG
     NDC ndc("resolve");
@@ -369,10 +506,10 @@ void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types)
         }
         catch(XSECException& e) {
             auto_ptr_char temp(e.getMsg());
-            Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading certificate: %s", temp.get());
+            Category::getInstance(XMLTOOLING_LOGCAT ".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading certificate: %s", temp.get());
         }
         catch(XSECCryptoException& e) {
-            Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading certificate: %s", e.getMsg());
+            Category::getInstance(XMLTOOLING_LOGCAT ".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading certificate: %s", e.getMsg());
         }
     }
 
@@ -393,14 +530,33 @@ void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types)
     }
 
     if (types & X509Credential::RESOLVE_CRLS) {
-        DOMNode* x509Node;
-        DOMElement* crlElement;
         for (DSIGKeyInfoList::size_type i=0; i<sz; ++i) {
             if (keyInfo->item(i)->getKeyInfoType()==DSIGKeyInfo::KEYINFO_X509) {
+#ifdef XMLTOOLING_XMLSEC_MULTIPLECRL
+                DSIGKeyInfoX509* x509 = static_cast<DSIGKeyInfoX509*>(keyInfo->item(i));
+                int count = x509->getX509CRLListSize();
+                for (int j=0; j<count; ++j) {
+                    auto_ptr_char buf(x509->getX509CRLItem(j));
+                    if (buf.get()) {
+                        try {
+                            auto_ptr<XSECCryptoX509CRL> crlobj(XMLToolingConfig::getConfig().X509CRL());
+                            crlobj->loadX509CRLBase64Bin(buf.get(), strlen(buf.get()));
+                            m_crls.push_back(crlobj.release());
+                        }
+                        catch(XSECException& e) {
+                            auto_ptr_char temp(e.getMsg());
+                            Category::getInstance(XMLTOOLING_LOGCAT ".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", temp.get());
+                        }
+                        catch(XSECCryptoException& e) {
+                            Category::getInstance(XMLTOOLING_LOGCAT ".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", e.getMsg());
+                        }
+                    }
+                }
+#else
                 // The current xmlsec API is limited to one CRL per KeyInfo.
                 // For now, I'm going to process the DOM directly.
-                x509Node = keyInfo->item(i)->getKeyInfoDOMNode();
-                crlElement = x509Node ? XMLHelper::getFirstChildElement(x509Node, xmlconstants::XMLSIG_NS, X509CRL::LOCAL_NAME) : NULL;
+                DOMNode* x509Node = keyInfo->item(i)->getKeyInfoDOMNode();
+                DOMElement* crlElement = x509Node ? XMLHelper::getFirstChildElement(x509Node, xmlconstants::XMLSIG_NS, X509CRL::LOCAL_NAME) : nullptr;
                 while (crlElement) {
                     if (crlElement->hasChildNodes()) {
                         auto_ptr_char buf(crlElement->getFirstChild()->getNodeValue());
@@ -412,15 +568,16 @@ void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types)
                             }
                             catch(XSECException& e) {
                                 auto_ptr_char temp(e.getMsg());
-                                Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", temp.get());
+                                Category::getInstance(XMLTOOLING_LOGCAT ".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", temp.get());
                             }
                             catch(XSECCryptoException& e) {
-                                Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", e.getMsg());
+                                Category::getInstance(XMLTOOLING_LOGCAT ".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", e.getMsg());
                             }
                         }
                     }
                     crlElement = XMLHelper::getNextSiblingElement(crlElement, xmlconstants::XMLSIG_NS, X509CRL::LOCAL_NAME);
                 }
+#endif
             }
         }
     }