Multi-line svn commit, see body.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / impl / InlineKeyResolver.cpp
index 122aff3..126a6ea 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include "internal.h"
+#include "logging.h"
 #include "security/BasicX509Credential.h"
 #include "security/KeyInfoCredentialContext.h"
 #include "security/KeyInfoResolver.h"
@@ -31,7 +32,6 @@
 #include "util/XMLConstants.h"
 #include "validation/ValidatorSuite.h"
 
-#include <log4cpp/Category.hh>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xsec/dsig/DSIGKeyInfoX509.hpp>
 #include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
@@ -42,8 +42,8 @@
 #include <xsec/framework/XSECException.hpp>
 
 using namespace xmlsignature;
+using namespace xmltooling::logging;
 using namespace xmltooling;
-using namespace log4cpp;
 using namespace std;
 
 namespace xmltooling {
@@ -65,8 +65,33 @@ namespace xmltooling {
             return NULL;
         }
 
-        const KeyInfo* getKeyInfo(bool compact=false) const {
-            return m_credctx->getKeyInfo();
+        KeyInfo* getKeyInfo(bool compact=false) const {
+            KeyInfo* ret = m_credctx->getKeyInfo() ? m_credctx->getKeyInfo()->cloneKeyInfo() : NULL;
+            if (ret) {
+                ret->setId(NULL);
+                ret->getRetrievalMethods().clear();
+                if (compact) {
+                    ret->getKeyValues().clear();
+                    ret->getSPKIDatas().clear();
+                    ret->getPGPDatas().clear();
+                    ret->getUnknownXMLObjects().clear();
+                    VectorOf(X509Data) x509Datas=ret->getX509Datas();
+                    for (VectorOf(X509Data)::size_type pos = 0; pos < x509Datas.size();) {
+                        x509Datas[pos]->getX509Certificates().clear();
+                        x509Datas[pos]->getX509CRLs().clear();
+                        x509Datas[pos]->getUnknownXMLObjects().clear();
+                        if (x509Datas[pos]->hasChildren())
+                            ++pos;
+                        else
+                            x509Datas.erase(x509Datas.begin() + pos);
+                    }
+                }
+            }
+            if (!ret->hasChildren()) {
+                delete ret;
+                ret = NULL;
+            }
+            return ret;
         }
         
         const CredentialContext* getCredentialContext() const {
@@ -162,7 +187,7 @@ void InlineCredential::resolve(const KeyInfo* keyInfo, int types)
 
 bool InlineCredential::resolveKey(const KeyInfo* keyInfo)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver");
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:KeyValue
     const vector<KeyValue*>& keyValues = keyInfo->getKeyValues();
@@ -245,7 +270,7 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo)
 
 bool InlineCredential::resolveCerts(const KeyInfo* keyInfo)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver");
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:X509Data
     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
@@ -309,7 +334,7 @@ bool InlineCredential::resolveCerts(const KeyInfo* keyInfo)
 
 bool InlineCredential::resolveCRL(const KeyInfo* keyInfo)
 {
-    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver");
+    Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
 
     // Check for ds:X509Data
     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
@@ -382,10 +407,10 @@ void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types)
         }
         catch(XSECException& e) {
             auto_ptr_char temp(e.getMsg());
-            Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver").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").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());
         }
     }
 
@@ -418,10 +443,10 @@ void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types)
                     }
                     catch(XSECException& e) {
                         auto_ptr_char temp(e.getMsg());
-                        Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver").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").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());
                     }
                 }
             }