From 57f988d4fdc41d707c0a8fdd375008bde73f0a3f Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Tue, 20 Jul 2010 16:26:29 +0000 Subject: [PATCH] Route signature debugging to log. --- config_win32.h | 1 + configure.ac | 7 +++++ xmltooling/XMLToolingConfig.cpp | 66 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/config_win32.h b/config_win32.h index fad778f..4663076 100644 --- a/config_win32.h +++ b/config_win32.h @@ -130,6 +130,7 @@ # define XMLTOOLING_XMLSEC_MULTIPLECRL 1 # define XMLTOOLING_XMLSEC_SIGALGORITHM 1 # define XMLTOOLING_XMLSEC_ECC 1 +# define XMLTOOLING_XMLSEC_DEBUGLOGGING 1 # endif #endif diff --git a/configure.ac b/configure.ac index 4c7fd07..62e4adf 100644 --- a/configure.ac +++ b/configure.ac @@ -335,6 +335,13 @@ int i = 0; [AC_DEFINE([XMLTOOLING_XMLSEC_ECC], [1], [Define to 1 if XML-Security-C includes ECC support.])], [AC_MSG_RESULT([no])]) + AC_MSG_CHECKING([whether XML-Security-C includes debug logging support]) + AC_TRY_COMPILE([#include ], + [XSECPlatformUtils::SetReferenceLoggingSink(NULL)], + [AC_MSG_RESULT([yes])] + [AC_DEFINE([XMLTOOLING_XMLSEC_DEBUGLOGGING], [1], [Define to 1 if XML-Security-C includes debug logging support.])], + [AC_MSG_RESULT([no])]) + # restore master libs LIBS="$save_LIBS" diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index be6d53a..36294be 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -61,15 +61,17 @@ #ifndef XMLTOOLING_NO_XMLSEC # include # include +# include # include +# include #endif using namespace soap11; using namespace xmltooling::logging; using namespace xmltooling; +using namespace xercesc; using namespace std; -using xercesc::XMLPlatformUtils; DECL_XMLTOOLING_EXCEPTION_FACTORY(XMLParserException,xmltooling); DECL_XMLTOOLING_EXCEPTION_FACTORY(XMLObjectException,xmltooling); @@ -89,7 +91,7 @@ using namespace xmlsignature; DECL_XMLTOOLING_EXCEPTION_FACTORY(EncryptionException,xmlencryption); #endif -namespace xmltooling { +namespace { static XMLToolingInternalConfig g_config; #ifndef XMLTOOLING_NO_XMLSEC static vector g_openssl_locks; @@ -108,6 +110,63 @@ namespace xmltooling { return (unsigned long)(pthread_self()); } # endif + +# ifdef XMLTOOLING_XMLSEC_DEBUGLOGGING + class TXFMOutputLog : public TXFMBase { + TXFMOutputLog(); + public: + TXFMOutputLog(DOMDocument* doc) : TXFMBase(doc), m_log(Category::getInstance(XMLTOOLING_LOGCAT".Signature.Debugger")) { + input = nullptr; + } + ~TXFMOutputLog() { + m_log.debug("----- END SIGNATURE DEBUG -----"); + } + + void setInput(TXFMBase *newInput) { + input = newInput; + if (newInput->getOutputType() != TXFMBase::BYTE_STREAM) + throw XSECException(XSECException::TransformInputOutputFail, "OutputLog transform requires BYTE_STREAM input"); + keepComments = input->getCommentsStatus(); + m_log.debug("----- BEGIN SIGNATURE DEBUG -----"); + } + + TXFMBase::ioType getInputType() { + return TXFMBase::BYTE_STREAM; + } + TXFMBase::ioType getOutputType() { + return TXFMBase::BYTE_STREAM; + } + TXFMBase::nodeType getNodeType() { + return TXFMBase::DOM_NODE_NONE; + } + + unsigned int readBytes(XMLByte * const toFill, const unsigned int maxToFill) { + unsigned int sz = input->readBytes(toFill, maxToFill); + m_log.debug(string(reinterpret_cast(toFill), sz)); + return sz; + } + + DOMDocument* getDocument() { + return nullptr; + } + DOMNode* getFragmentNode() { + return nullptr; + } + const XMLCh* getFragmentId() { + return nullptr; + } + + private: + Category& m_log; + }; + + TXFMBase* TXFMOutputLogFactory(DOMDocument* doc) { + if (Category::getInstance(XMLTOOLING_LOGCAT".Signature.Debugger").isDebugEnabled()) + return new TXFMOutputLog(doc); + return nullptr; + } +# endif + #endif #ifdef WIN32 @@ -296,6 +355,9 @@ bool XMLToolingInternalConfig::init() #ifndef XMLTOOLING_NO_XMLSEC XSECPlatformUtils::Initialise(); +# ifdef XMLTOOLING_XMLSEC_DEBUGLOGGING + XSECPlatformUtils::SetReferenceLoggingSink(TXFMOutputLogFactory); +# endif m_xsecProvider=new XSECProvider(); log.debug("XML-Security %s initialization complete", XSEC_FULLVERSIONDOT); #endif -- 2.1.4