[cpp-xmltooling] branch master updated: SSPCPP-775 - Client-side session storage
Scott Cantor
cantor.2 at osu.edu
Fri Feb 2 17:38:39 EST 2018
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository cpp-xmltooling.
View the commit online:
http://git.shibboleth.net/view/?p=cpp-xmltooling.git;a=commit;h=74ad070ce199ad65b87698c9c04c370475616a19
The following commit(s) were added to refs/heads/master by this push:
new 74ad070 SSPCPP-775 - Client-side session storage
74ad070 is described below
commit 74ad070ce199ad65b87698c9c04c370475616a19
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Fri Feb 2 17:37:40 2018 -0500
SSPCPP-775 - Client-side session storage
https://issues.shibboleth.net/jira/browse/SSPCPP-775
Skeletal DataSealer, migrated zlib dependency down.
---
Projects/vc15/xmltooling/xmltooling-lite.vcxproj | 10 +-
.../xmltooling/xmltooling-lite.vcxproj.filters | 6 --
Projects/vc15/xmltooling/xmltooling.vcxproj | 12 ++-
.../vc15/xmltooling/xmltooling.vcxproj.filters | 12 +--
configure.ac | 24 +++++
xmltooling/Makefile.am | 2 +
xmltooling/XMLToolingConfig.cpp | 92 +++++++---------
xmltooling/XMLToolingConfig.h | 31 +++++-
xmltooling/internal.h | 6 +-
xmltooling/util/DataSealer.cpp | 112 ++++++++++++++++++++
xmltooling/util/DataSealer.h | 79 ++++++++++++++
xmltooling/util/XMLHelper.cpp | 116 ++++++++++++++++++++-
xmltooling/util/XMLHelper.h | 24 ++++-
13 files changed, 440 insertions(+), 86 deletions(-)
diff --git a/Projects/vc15/xmltooling/xmltooling-lite.vcxproj b/Projects/vc15/xmltooling/xmltooling-lite.vcxproj
index e9a71fa..497173f 100644
--- a/Projects/vc15/xmltooling/xmltooling-lite.vcxproj
+++ b/Projects/vc15/xmltooling/xmltooling-lite.vcxproj
@@ -112,7 +112,7 @@
<PreprocessorDefinitions>_DEBUG;XMLTOOLING_LITE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
- <AdditionalDependencies>wsock32.lib;log4shib1D.lib;xerces-c_3D.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;log4shib1D.lib;zlib1D.lib;xerces-c_3D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
@@ -143,7 +143,7 @@
<PreprocessorDefinitions>_DEBUG;XMLTOOLING_LITE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
- <AdditionalDependencies>wsock32.lib;log4shib1D.lib;xerces-c_3D.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;log4shib1D.lib;zlib1D.lib;xerces-c_3D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<DataExecutionPrevention>
@@ -166,7 +166,7 @@
<PreprocessorDefinitions>XMLTOOLING_LITE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
- <AdditionalDependencies>wsock32.lib;log4shib1.lib;xerces-c_3.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;log4shib1.lib;zlib1.lib;xerces-c_3.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
@@ -196,7 +196,7 @@
<PreprocessorDefinitions>XMLTOOLING_LITE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
- <AdditionalDependencies>wsock32.lib;log4shib1.lib;xerces-c_3.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;log4shib1.lib;zlib1.lib;xerces-c_3.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
@@ -298,4 +298,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/Projects/vc15/xmltooling/xmltooling-lite.vcxproj.filters b/Projects/vc15/xmltooling/xmltooling-lite.vcxproj.filters
index 8ff8ad2..6b7e866 100644
--- a/Projects/vc15/xmltooling/xmltooling-lite.vcxproj.filters
+++ b/Projects/vc15/xmltooling/xmltooling-lite.vcxproj.filters
@@ -84,9 +84,6 @@
<ClCompile Include="..\..\..\XMLTooling\XMLToolingConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\XMLTooling\util\DateTime.cpp">
- <Filter>Source Files\util</Filter>
- </ClCompile>
<ClCompile Include="..\..\..\XMLTooling\util\NDC.cpp">
<Filter>Source Files\util</Filter>
</ClCompile>
@@ -221,9 +218,6 @@
<ClInclude Include="..\..\..\XMLTooling\XMLToolingConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\XMLTooling\util\DateTime.h">
- <Filter>Header Files\util</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\XMLTooling\util\NDC.h">
<Filter>Header Files\util</Filter>
</ClInclude>
diff --git a/Projects/vc15/xmltooling/xmltooling.vcxproj b/Projects/vc15/xmltooling/xmltooling.vcxproj
index 4677c3c..612963f 100644
--- a/Projects/vc15/xmltooling/xmltooling.vcxproj
+++ b/Projects/vc15/xmltooling/xmltooling.vcxproj
@@ -116,7 +116,7 @@
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
- <AdditionalDependencies>wsock32.lib;log4shib1D.lib;xerces-c_3D.lib;xsec_2D.lib;$(SSLLibD);$(LibCurlLibD);%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;log4shib1D.lib;zlib1D.lib;xerces-c_3D.lib;xsec_2D.lib;$(SSLLibD);$(LibCurlLibD);%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<DataExecutionPrevention>
@@ -145,7 +145,7 @@
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
- <AdditionalDependencies>wsock32.lib;log4shib1D.lib;xerces-c_3D.lib;xsec_2D.lib;$(SSLLibD);$(LibCurlLibD);%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;log4shib1D.lib;zlib1D.lib;xerces-c_3D.lib;xsec_2D.lib;$(SSLLibD);$(LibCurlLibD);%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<DataExecutionPrevention>
@@ -164,7 +164,7 @@
<DisableSpecificWarnings>4275</DisableSpecificWarnings>
</ClCompile>
<Link>
- <AdditionalDependencies>wsock32.lib;log4shib1.lib;xerces-c_3.lib;xsec_2.lib;$(SSLLib);$(LibCurlLib);%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;log4shib1.lib;zlib1.lib;xerces-c_3.lib;xsec_2.lib;$(SSLLib);$(LibCurlLib);%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
@@ -188,7 +188,7 @@
<DisableSpecificWarnings>4275</DisableSpecificWarnings>
</ClCompile>
<Link>
- <AdditionalDependencies>wsock32.lib;log4shib1.lib;xerces-c_3.lib;xsec_2.lib;$(SSLLib);$(LibCurlLib);%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wsock32.lib;log4shib1.lib;zlib1.lib;xerces-c_3.lib;xsec_2.lib;$(SSLLib);$(LibCurlLib);%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
@@ -212,6 +212,7 @@
<ClCompile Include="..\..\..\XMLTooling\security\impl\PKIXPathValidator.cpp" />
<ClCompile Include="..\..\..\XMLTooling\unicode.cpp" />
<ClCompile Include="..\..\..\XMLTooling\util\CloneInputStream.cpp" />
+ <ClCompile Include="..\..\..\xmltooling\util\DataSealer.cpp" />
<ClCompile Include="..\..\..\XMLTooling\version.cpp" />
<ClCompile Include="..\..\..\XMLTooling\XMLObjectBuilder.cpp" />
<ClCompile Include="..\..\..\XMLTooling\XMLToolingConfig.cpp" />
@@ -290,6 +291,7 @@
<ClInclude Include="..\..\..\XMLTooling\security\PKIXPathValidatorParams.h" />
<ClInclude Include="..\..\..\XMLTooling\unicode.h" />
<ClInclude Include="..\..\..\XMLTooling\util\CloneInputStream.h" />
+ <ClInclude Include="..\..\..\xmltooling\util\DataSealer.h" />
<ClInclude Include="..\..\..\XMLTooling\version.h" />
<ClInclude Include="..\..\..\XMLTooling\XMLObject.h" />
<ClInclude Include="..\..\..\XMLTooling\XMLObjectBuilder.h" />
@@ -360,4 +362,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/Projects/vc15/xmltooling/xmltooling.vcxproj.filters b/Projects/vc15/xmltooling/xmltooling.vcxproj.filters
index 53a6400..6a8112f 100644
--- a/Projects/vc15/xmltooling/xmltooling.vcxproj.filters
+++ b/Projects/vc15/xmltooling/xmltooling.vcxproj.filters
@@ -114,9 +114,6 @@
<ClCompile Include="..\..\..\XMLTooling\util\CurlURLInputStream.cpp">
<Filter>Source Files\util</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\XMLTooling\util\DateTime.cpp">
- <Filter>Source Files\util</Filter>
- </ClCompile>
<ClCompile Include="..\..\..\XMLTooling\util\NDC.cpp">
<Filter>Source Files\util</Filter>
</ClCompile>
@@ -276,6 +273,9 @@
<ClCompile Include="..\..\..\xmltooling\security\impl\OpenSSLSecurityHelper.cpp">
<Filter>Source Files\security\impl</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\xmltooling\util\DataSealer.cpp">
+ <Filter>Source Files\util</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\XMLTooling\AbstractAttributeExtensibleXMLObject.h">
@@ -350,9 +350,6 @@
<ClInclude Include="..\..\..\XMLTooling\util\CurlURLInputStream.h">
<Filter>Header Files\util</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\XMLTooling\util\DateTime.h">
- <Filter>Header Files\util</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\XMLTooling\util\NDC.h">
<Filter>Header Files\util</Filter>
</ClInclude>
@@ -527,6 +524,9 @@
<ClInclude Include="..\..\..\XMLTooling\util\CloneInputStream.h">
<Filter>Header Files\util</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\xmltooling\util\DataSealer.h">
+ <Filter>Header Files\util</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\..\XMLTooling\xmltooling.rc">
diff --git a/configure.ac b/configure.ac
index 307347b..7c2aec1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -324,6 +324,30 @@ int i = 0;
# restore master libs
LIBS="$save_LIBS"
+ # zlib settings
+ AC_ARG_WITH(zlib,
+ AS_HELP_STRING([--with-zlib=PATH],[where zlib is installed]),
+ [
+ if test -d "$withval" ; then
+ CPPFLAGS="${CPPFLAGS} -I$withval/include"
+ XMLSEC_LIBS="-L$withval/lib -lz $XMLSEC_LIBS"
+ fi
+ ]
+ )
+
+ # save and append master libs
+ save_LIBS="$LIBS"
+ LIBS="$XMLSEC_LIBS $LIBS"
+
+ AC_CHECK_HEADER([zlib.h],,AC_MSG_ERROR([unable to find zlib header files]))
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[#include <zlib.h>]],
+ [[zlibVersion()]])],,
+ [AC_MSG_ERROR([unable to link with zlib])])
+
+ # restore master libs
+ LIBS="$save_LIBS"
+
AC_SUBST(XMLSEC_LIBS)
else
AC_MSG_WARN([xmlsec disabled, building without signature/encryption support])
diff --git a/xmltooling/Makefile.am b/xmltooling/Makefile.am
index 120d87e..d0a9fda 100644
--- a/xmltooling/Makefile.am
+++ b/xmltooling/Makefile.am
@@ -108,6 +108,7 @@ soapinclude_HEADERS = \
utilinclude_HEADERS = \
util/CloneInputStream.h \
util/CurlURLInputStream.h \
+ util/DataSealer.h \
util/NDC.h \
util/ParserPool.h \
util/PathResolver.h \
@@ -161,6 +162,7 @@ xmlsec_sources = \
signature/impl/XMLSecSignatureImpl.cpp \
soap/impl/CURLSOAPTransport.cpp \
util/CurlURLInputStream.cpp \
+ util/DataSealer.cpp \
util/ReplayCache.cpp \
util/StorageService.cpp
diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp
index 421700f..a224bc4 100644
--- a/xmltooling/XMLToolingConfig.cpp
+++ b/xmltooling/XMLToolingConfig.cpp
@@ -41,6 +41,7 @@
#include "signature/Signature.h"
#include "soap/SOAP.h"
#include "soap/SOAPTransport.h"
+#include "util/DataSealer.h"
#include "util/NDC.h"
#include "util/PathResolver.h"
#include "util/ReplayCache.h"
@@ -210,13 +211,7 @@ XMLToolingInternalConfig& XMLToolingInternalConfig::getInternalConfig()
return g_config;
}
-#ifndef XMLTOOLING_NO_XMLSEC
-XMLToolingConfig::XMLToolingConfig()
- : m_keyInfoResolver(nullptr), m_replayCache(nullptr), m_pathResolver(nullptr), m_templateEngine(nullptr), m_urlEncoder(nullptr), clock_skew_secs(180)
-#else
-XMLToolingConfig::XMLToolingConfig()
- : m_pathResolver(nullptr), m_templateEngine(nullptr), m_urlEncoder(nullptr), clock_skew_secs(180)
-#endif
+XMLToolingConfig::XMLToolingConfig() : clock_skew_secs(180)
{
}
@@ -227,65 +222,66 @@ XMLToolingConfig::~XMLToolingConfig()
#ifndef XMLTOOLING_LITE
const KeyInfoResolver* XMLToolingConfig::getKeyInfoResolver() const
{
- return m_keyInfoResolver;
+ return m_keyInfoResolver.get();
}
ReplayCache* XMLToolingConfig::getReplayCache() const
{
- return m_replayCache;
+ return m_replayCache.get();
+}
+
+const DataSealer* XMLToolingConfig::getDataSealer() const
+{
+ return m_dataSealer.get();
}
void XMLToolingConfig::setKeyInfoResolver(xmltooling::KeyInfoResolver *keyInfoResolver)
{
- delete m_keyInfoResolver;
- m_keyInfoResolver = keyInfoResolver;
+ m_keyInfoResolver.reset(keyInfoResolver);
}
void XMLToolingConfig::setReplayCache(ReplayCache* replayCache)
{
- delete m_replayCache;
- m_replayCache = replayCache;
+ m_replayCache.reset(replayCache);
+}
+
+void XMLToolingConfig::setDataSealer(DataSealer* dataSealer)
+{
+ m_dataSealer.reset(dataSealer);
}
#endif
PathResolver* XMLToolingConfig::getPathResolver() const
{
- return m_pathResolver;
+ return m_pathResolver.get();
}
TemplateEngine* XMLToolingConfig::getTemplateEngine() const
{
- return m_templateEngine;
+ return m_templateEngine.get();
}
const URLEncoder* XMLToolingConfig::getURLEncoder() const
{
- return m_urlEncoder;
+ return m_urlEncoder.get();
}
void XMLToolingConfig::setPathResolver(PathResolver* pathResolver)
{
- delete m_pathResolver;
- m_pathResolver = pathResolver;
+ m_pathResolver.reset(pathResolver);
}
void XMLToolingConfig::setTemplateEngine(TemplateEngine* templateEngine)
{
- delete m_templateEngine;
- m_templateEngine = templateEngine;
+ m_templateEngine.reset(templateEngine);
}
void XMLToolingConfig::setURLEncoder(URLEncoder* urlEncoder)
{
- delete m_urlEncoder;
- m_urlEncoder = urlEncoder;
+ m_urlEncoder.reset(urlEncoder);
}
-XMLToolingInternalConfig::XMLToolingInternalConfig() :
-#ifndef XMLTOOLING_NO_XMLSEC
- m_xsecProvider(nullptr),
-#endif
- m_initCount(0), m_lock(Mutex::create()), m_parserPool(nullptr), m_validatingPool(nullptr)
+XMLToolingInternalConfig::XMLToolingInternalConfig() : m_initCount(0), m_lock(Mutex::create())
{
}
@@ -344,7 +340,7 @@ bool XMLToolingInternalConfig::log_config(const char* config)
}
else {
string path(config);
- PropertyConfigurator::configure(m_pathResolver ? m_pathResolver->resolve(path, PathResolver::XMLTOOLING_CFG_FILE) : path);
+ PropertyConfigurator::configure(m_pathResolver.get() ? m_pathResolver->resolve(path, PathResolver::XMLTOOLING_CFG_FILE) : path);
}
#ifndef XMLTOOLING_NO_XMLSEC
@@ -410,15 +406,15 @@ bool XMLToolingInternalConfig::init()
#ifndef XMLTOOLING_NO_XMLSEC
XSECPlatformUtils::Initialise();
XSECPlatformUtils::SetReferenceLoggingSink(TXFMOutputLogFactory);
- m_xsecProvider = new XSECProvider();
+ m_xsecProvider.reset(new XSECProvider());
log.debug("XML-Security %s initialization complete", XSEC_FULLVERSIONDOT);
#endif
- m_parserPool = new ParserPool();
- m_validatingPool = new ParserPool(true,true);
+ m_parserPool.reset(new ParserPool());
+ m_validatingPool.reset(new ParserPool(true,true));
- m_pathResolver = new PathResolver();
- m_urlEncoder = new URLEncoder();
+ m_pathResolver.reset(new PathResolver());
+ m_urlEncoder.reset(new URLEncoder());
// Load catalogs from deprecated path setting.
if (!catalog_path.empty())
@@ -450,7 +446,7 @@ bool XMLToolingInternalConfig::init()
registerPathValidators();
registerTrustEngines();
registerXMLAlgorithms();
- m_keyInfoResolver = KeyInfoResolverManager.newPlugin(INLINE_KEYINFO_RESOLVER,nullptr);
+ m_keyInfoResolver.reset(KeyInfoResolverManager.newPlugin(INLINE_KEYINFO_RESOLVER,nullptr));
#endif
#ifndef XMLTOOLING_LITE
@@ -527,21 +523,14 @@ void XMLToolingInternalConfig::term()
KeyInfoResolverManager.deregisterFactories();
m_algorithmMap.clear();
- delete m_keyInfoResolver;
- m_keyInfoResolver = nullptr;
-
- delete m_replayCache;
- m_replayCache = nullptr;
+ m_keyInfoResolver.reset();
+ m_replayCache.reset();
+ m_dataSealer.reset();
#endif
- delete m_pathResolver;
- m_pathResolver = nullptr;
-
- delete m_templateEngine;
- m_templateEngine = nullptr;
-
- delete m_urlEncoder;
- m_urlEncoder = nullptr;
+ m_pathResolver.reset();
+ m_templateEngine.reset();
+ m_urlEncoder.reset();
for (vector<void*>::reverse_iterator i=m_libhandles.rbegin(); i!=m_libhandles.rend(); i++) {
#if defined(WIN32)
@@ -560,17 +549,14 @@ void XMLToolingInternalConfig::term()
}
m_libhandles.clear();
- delete m_parserPool;
- m_parserPool=nullptr;
- delete m_validatingPool;
- m_validatingPool=nullptr;
+ m_parserPool.reset();
+ m_validatingPool.reset();
for_each(m_namedLocks.begin(), m_namedLocks.end(), cleanup_pair<string,Mutex>());
m_namedLocks.clear();
#ifndef XMLTOOLING_NO_XMLSEC
- delete m_xsecProvider;
- m_xsecProvider=nullptr;
+ m_xsecProvider.reset();
XSECPlatformUtils::Terminate();
#endif
diff --git a/xmltooling/XMLToolingConfig.h b/xmltooling/XMLToolingConfig.h
index 93e9e51..b5b52e9 100644
--- a/xmltooling/XMLToolingConfig.h
+++ b/xmltooling/XMLToolingConfig.h
@@ -31,6 +31,7 @@
#include <xmltooling/PluginManager.h>
#include <xmltooling/soap/SOAPTransport.h>
+#include <memory>
#include <string>
#include <xercesc/dom/DOM.hpp>
@@ -52,6 +53,7 @@ namespace xmltooling {
#endif
#ifndef XMLTOOLING_NO_XMLSEC
class XMLTOOL_API CredentialResolver;
+ class XMLTOOL_API DataSealer;
class XMLTOOL_API KeyInfoResolver;
class XMLTOOL_API PathValidator;
class XMLTOOL_API TrustEngine;
@@ -73,20 +75,23 @@ namespace xmltooling {
#ifndef XMLTOOLING_NO_XMLSEC
/** Global KeyInfoResolver instance. */
- KeyInfoResolver* m_keyInfoResolver;
+ std::auto_ptr<KeyInfoResolver> m_keyInfoResolver;
/** Global ReplayCache instance. */
- ReplayCache* m_replayCache;
+ std::auto_ptr<ReplayCache> m_replayCache;
+
+ /* Global DataSealer instance. */
+ std::auto_ptr<DataSealer> m_dataSealer;
#endif
/** Global PathResolver instance. */
- PathResolver* m_pathResolver;
+ std::auto_ptr<PathResolver> m_pathResolver;
/** Global TemplateEngine instance. */
- TemplateEngine* m_templateEngine;
+ std::auto_ptr<TemplateEngine> m_templateEngine;
/** Global URLEncoder instance for use by URL-related functions. */
- URLEncoder* m_urlEncoder;
+ std::auto_ptr<URLEncoder> m_urlEncoder;
public:
virtual ~XMLToolingConfig();
@@ -183,6 +188,13 @@ namespace xmltooling {
ReplayCache* getReplayCache() const;
/**
+ * Returns the global DataSealer instance.
+ *
+ * @return global DataSealer or nullptr
+ */
+ const DataSealer* getDataSealer() const;
+
+ /**
* Sets the global KeyInfoResolver instance.
* <p>This method must be externally synchronized with any code that uses the object.
* Any previously set object is destroyed.
@@ -199,6 +211,15 @@ namespace xmltooling {
* @param replayCache new ReplayCache instance to store
*/
void setReplayCache(ReplayCache* replayCache);
+
+ /**
+ * Sets the global DataSealer instance.
+ * <p>This method must be externally synchronized with any code that uses the object.
+ * Any previously set object is destroyed.
+ *
+ * @param dataSealer new DataSealer instance to store
+ */
+ void setDataSealer(DataSealer* dataSealer);
#endif
/**
diff --git a/xmltooling/internal.h b/xmltooling/internal.h
index 3144fee..4fcee44 100644
--- a/xmltooling/internal.h
+++ b/xmltooling/internal.h
@@ -127,7 +127,7 @@ namespace xmltooling {
bool isXMLAlgorithmSupported(const XMLCh* xmlAlgorithm, XMLSecurityAlgorithmType type=ALGTYPE_UNK);
void registerXMLAlgorithms();
- XSECProvider* m_xsecProvider;
+ std::auto_ptr<XSECProvider> m_xsecProvider;
private:
typedef std::map<XMLSecurityAlgorithmType, std::map< xstring,std::pair<std::string,unsigned int> > > algmap_t;
algmap_t m_algorithmMap;
@@ -138,8 +138,8 @@ namespace xmltooling {
std::auto_ptr<Mutex> m_lock;
std::map<std::string,Mutex*> m_namedLocks;
std::vector<void*> m_libhandles;
- ParserPool* m_parserPool;
- ParserPool* m_validatingPool;
+ std::auto_ptr<ParserPool> m_parserPool;
+ std::auto_ptr<ParserPool> m_validatingPool;
};
#ifndef XMLTOOLING_NO_XMLSEC
diff --git a/xmltooling/util/DataSealer.cpp b/xmltooling/util/DataSealer.cpp
new file mode 100644
index 0000000..f1b2889
--- /dev/null
+++ b/xmltooling/util/DataSealer.cpp
@@ -0,0 +1,112 @@
+/**
+ * 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.
+ *
+ * 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
+ *
+ * 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.
+ */
+
+/**
+ * URLEncoder.cpp
+ *
+ * Interface to a URL-encoding mechanism along with a
+ * default implementation.
+ */
+
+#include "internal.h"
+#include "logging.h"
+#include "util/DataSealer.h"
+#include "util/XMLHelper.h"
+
+#include <sstream>
+#include <xercesc/util/Base64.hpp>
+#include <xercesc/util/XMLDateTime.hpp>
+
+using namespace xmltooling;
+using xercesc::Base64;
+using xercesc::XMLDateTime;
+using namespace std;
+
+DataSealer::DataSealer()
+{
+}
+
+DataSealer::~DataSealer()
+{
+}
+
+// TODO: add encryption ;-)
+
+string DataSealer::wrap(const char* s, time_t exp) const
+{
+#ifndef HAVE_GMTIME_R
+ struct tm* ptime = gmtime(&exp);
+#else
+ struct tm res;
+ struct tm* ptime = gmtime_r(exp, &res);
+#endif
+ char timebuf[32];
+ strftime(timebuf, 32, "%Y-%m-%dT%H:%M:%SZ", ptime);
+
+ string towrap(timebuf);
+ towrap += s;
+
+ unsigned int len;
+ char* deflated = XMLHelper::deflate(const_cast<char*>(towrap.c_str()), towrap.length(), &len);
+ if (!deflated)
+ throw IOException("Failed to deflate data.");
+
+ XMLSize_t xlen;
+ XMLByte* encoded = Base64::encode(reinterpret_cast<XMLByte*>(deflated), len, &xlen);
+ delete[] deflated;
+ if (!encoded)
+ throw IOException("Base64 encoding of deflated data failed.");
+
+ string wrapped;
+ for (const XMLByte* xb = encoded; *xb; ++xb) {
+ if (!isspace(*xb))
+ wrapped += *xb;
+ }
+ XMLString::release((char**)&encoded);
+
+ return wrapped;
+}
+
+string DataSealer::decode(const char* wrapped) const
+{
+ XMLSize_t x;
+ XMLByte* decoded = Base64::decode(reinterpret_cast<const XMLByte*>(wrapped), &x);
+ if (!decoded)
+ throw IOException("Unable to decode base64 data.");
+
+ // Now we have to inflate it.
+ stringstream s;
+ if (XMLHelper::inflate(reinterpret_cast<char*>(decoded), x, s) == 0) {
+ XMLString::release((char**)&decoded);
+ throw IOException("Unable to inflate wrapped data.");
+ }
+ XMLString::release((char**)&decoded);
+
+ string decrypted = s.str();
+ string dstr = decrypted.substr(0, 20);
+ auto_ptr_XMLCh expstr(dstr.c_str());
+ XMLDateTime exp(expstr.get());
+ exp.parseDateTime();
+ if (exp.getEpoch() < time(nullptr) - XMLToolingConfig::getConfig().clock_skew_secs) {
+ logging::Category::getInstance(XMLTOOLING_LOGCAT ".DataSealer").debug("Decrypted data has expired");
+ }
+
+ return decrypted.substr(20);
+}
diff --git a/xmltooling/util/DataSealer.h b/xmltooling/util/DataSealer.h
new file mode 100644
index 0000000..4b6fc0b
--- /dev/null
+++ b/xmltooling/util/DataSealer.h
@@ -0,0 +1,79 @@
+/**
+ * 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.
+ *
+ * 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
+ *
+ * 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.
+ */
+
+/**
+ * @file xmltooling/util/DataSealer.h
+ *
+ * Generic data protection interface.
+ */
+
+#if !defined(__xmltooling_sealer_h__) && !defined(XMLTOOLING_NO_XMLSEC)
+#define __xmltooling_sealer_h__
+
+#include <xmltooling/base.h>
+
+#include <ctime>
+#include <string>
+
+namespace xmltooling {
+
+ /**
+ * Interface to a data integrity and confidentiality tool, and a default implementation.
+ */
+ class XMLTOOL_API DataSealer {
+ MAKE_NONCOPYABLE(DataSealer);
+ public:
+ DataSealer();
+
+ virtual ~DataSealer();
+
+ /**
+ * Encodes data into an AEAD-encrypted blob, gzip(exp|data)
+ *
+ * <ul>
+ * <li>exp = expiration time of the data; encoded into ISO format</li>
+ * <li>data = the data; a UTF-8-encoded string</li>
+ * </ul>
+ *
+ * <p>As part of encryption, the key alias is supplied as additional authenticated data
+ * to the cipher. Afterwards, the encrypted data is prepended by the IV and then again by the alias
+ * (in length-prefixed UTF-8 format), which identifies the key used. Finally the result is encoded
+ * safely for ASCII use (e.g., base64).</p>
+ *
+ * @param data the data to wrap
+ * @param exp expiration time
+ * @return the encoded blob
+ */
+ virtual std::string wrap(const char* s, time_t exp) const;
+
+ /**
+ * Decrypts and verifies an encrypted bundle wrapped via this object.
+ *
+ * @param wrapped the encoded blob
+ *
+ * @return the decrypted data, if it's unexpired
+ */
+ virtual std::string decode(const char* wrapped) const;
+
+ };
+
+};
+
+#endif /* __xmltooling_sealer_h__ */
diff --git a/xmltooling/util/XMLHelper.cpp b/xmltooling/util/XMLHelper.cpp
index 9214f30..0d788c1 100644
--- a/xmltooling/util/XMLHelper.cpp
+++ b/xmltooling/util/XMLHelper.cpp
@@ -36,9 +36,12 @@
#include <boost/lambda/bind.hpp>
#include <boost/lambda/if.hpp>
#include <boost/lambda/lambda.hpp>
+
#include <xercesc/framework/MemBufFormatTarget.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
+#include <zlib.h>
+using namespace xmltooling::logging;
using namespace xmltooling;
using namespace xercesc;
using namespace boost::lambda;
@@ -373,7 +376,7 @@ bool XMLHelper::getCaseSensitive(const xercesc::DOMElement* e, bool defValue, co
if (e) {
const XMLCh* ic = e->getAttributeNS(ns, ignoreCase);
if (ic && * ic) {
- logging::Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").warn("Deprecated attribute \"ignoreCase\" encountered in configuration. Use \"caseSensitive\".");
+ Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").warn("Deprecated attribute \"ignoreCase\" encountered in configuration. Use \"caseSensitive\".");
// caseInsensitive = !"ignoreCase"
if (*ic == chLatin_t || *ic == chDigit_1)
@@ -384,7 +387,7 @@ bool XMLHelper::getCaseSensitive(const xercesc::DOMElement* e, bool defValue, co
const XMLCh* ci = e->getAttributeNS(ns, caseSensitive);
if (ci && *ci) {
if (ic && *ic) {
- logging::Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").warn("Attribute \"ignoreCase\" and \"caseSensitive\" should not be used in the same element.");
+ Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").warn("Attribute \"ignoreCase\" and \"caseSensitive\" should not be used in the same element.");
}
if (*ci == chLatin_t || *ci == chDigit_1) {
result = true;
@@ -508,3 +511,112 @@ ostream& xmltooling::operator<<(ostream& ostr, const XMLObject& obj)
throw XMLParserException(msg.get());
}
}
+
+namespace {
+ extern "C" {
+ voidpf saml_zalloc(void* opaque, uInt items, uInt size)
+ {
+ return malloc(items*size);
+ }
+
+ void saml_zfree(void* opaque, voidpf addr)
+ {
+ free(addr);
+ }
+ };
+};
+
+char* XMLHelper::deflate(char* in, unsigned int in_len, unsigned int* out_len)
+{
+ z_stream z;
+ memset(&z, 0, sizeof(z_stream));
+
+ z.zalloc = saml_zalloc;
+ z.zfree = saml_zfree;
+ z.opaque = nullptr;
+ z.next_in = (Bytef*)in;
+ z.avail_in = in_len;
+ *out_len = 0;
+
+ int ret = deflateInit2(&z, 9, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY);
+ if (ret != Z_OK) {
+ Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").error("zlib deflateInit2 failed with error code (%d)", ret);
+ return nullptr;
+ }
+
+ int dlen = in_len + (in_len >> 8) + 12; /* orig_size * 1.001 + 12 */
+ char* out = new char[dlen];
+ z.next_out = (Bytef*)out;
+ z.avail_out = dlen;
+
+ ret = ::deflate(&z, Z_FINISH);
+ if (ret != Z_STREAM_END) {
+ deflateEnd(&z);
+ Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").error("zlib deflateInit2 failed with error code (%d)", ret);
+ delete[] out;
+ }
+
+ *out_len = z.total_out;
+ deflateEnd(&z);
+ return out;
+}
+
+unsigned int XMLHelper::inflate(char* in, unsigned int in_len, ostream& out)
+{
+ z_stream z;
+ memset(&z, 0, sizeof(z_stream));
+
+ z.zalloc = saml_zalloc;
+ z.zfree = saml_zfree;
+ z.opaque = nullptr;
+ z.next_in = (Bytef*)in;
+ z.avail_in = in_len;
+
+ int dlen = in_len << 3; /* guess inflated size: orig_size * 8 */
+ Byte* buf = new Byte[dlen];
+ memset(buf, 0, dlen);
+ z.next_out = buf;
+ z.avail_out = dlen;
+
+ int ret = inflateInit2(&z, -15);
+ if (ret != Z_OK) {
+ Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").error("zlib inflateInit2 failed with error code (%d)", ret);
+ delete[] buf;
+ return 0;
+ }
+
+ size_t diff;
+ int iter = 30;
+ while (--iter) { /* Make sure we can never be caught in infinite loop */
+ ret = ::inflate(&z, Z_SYNC_FLUSH);
+ switch (ret) {
+ case Z_STREAM_END:
+ diff = z.next_out - buf;
+ z.next_out = buf;
+ while (diff--)
+ out << *(z.next_out++);
+ goto done;
+
+ case Z_OK: /* avail_out should be 0 now. Time to dump the buffer. */
+ diff = z.next_out - buf;
+ z.next_out = buf;
+ while (diff--)
+ out << *(z.next_out++);
+ memset(buf, 0, dlen);
+ z.next_out = buf;
+ z.avail_out = dlen;
+ break;
+
+ default:
+ delete[] buf;
+ inflateEnd(&z);
+ Category::getInstance(XMLTOOLING_LOGCAT ".XMLHelper").error("zlib inflate failed with error code (%d)", ret);
+ return 0;
+ }
+ }
+done:
+ delete[] buf;
+ int out_len = z.total_out;
+ inflateEnd(&z);
+ return out_len;
+}
diff --git a/xmltooling/util/XMLHelper.h b/xmltooling/util/XMLHelper.h
index 357eaa3..835d26f 100644
--- a/xmltooling/util/XMLHelper.h
+++ b/xmltooling/util/XMLHelper.h
@@ -386,7 +386,29 @@ namespace xmltooling {
* @return reference to output stream
*/
static std::ostream& serialize(const xercesc::DOMNode* n, std::ostream& out, bool pretty=false);
- };
+
+ /**
+ * Deflates data in accordance with RFC1951. The caller must free the
+ * resulting buffer using delete[]
+ *
+ * @param in the data to compress
+ * @param in_len length of input data
+ * @param out_len will contain the length of the resulting data
+ * @return allocated buffer of out_len bytes containing deflated data
+ */
+ static char* deflate(char* in, unsigned int in_len, unsigned int* out_len);
+
+ /**
+ * Inflates data compressed in accordance with RFC1951 and sends the
+ * results to an output stream.
+ *
+ * @param in the data to inflate
+ * @param in_len length of input data
+ * @param out reference to output stream to receive data
+ * @return number of bytes written to stream
+ */
+ static unsigned int inflate(char* in, unsigned int in_len, std::ostream& out);
+ };
/**
* Serializes the DOM node provided to a stream using UTF-8 encoding and
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list