X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fopensaml2.git;a=blobdiff_plain;f=saml%2FSAMLConfig.cpp;h=695964a5c3c996b1a90219d70d608ecdba79fcb9;hp=ad8a6df7106e10474854b0085f03660f4665b62f;hb=d4eecdb1583eef60317093bfd488c10ce39b27db;hpb=2719cace5918a717985018481ba3cb9a165cfc0a diff --git a/saml/SAMLConfig.cpp b/saml/SAMLConfig.cpp index ad8a6df..695964a 100644 --- a/saml/SAMLConfig.cpp +++ b/saml/SAMLConfig.cpp @@ -20,10 +20,9 @@ * Library configuration */ -#define SAML_DECLARE_VALIDATORS - #include "internal.h" #include "exceptions.h" +#include "SAMLArtifact.h" #include "SAMLConfig.h" #include "saml1/core/Assertions.h" #include "saml1/core/Protocols.h" @@ -38,15 +37,18 @@ #include #include +#include #include + using namespace opensaml; using namespace xmlsignature; using namespace xmltooling; using namespace log4cpp; using namespace std; -//DECL_EXCEPTION_FACTORY(XMLParserException,xmltooling); +DECL_EXCEPTION_FACTORY(ArtifactException,opensaml); +DECL_EXCEPTION_FACTORY(MetadataFilterException,opensaml::saml2md); namespace opensaml { SAMLInternalConfig g_config; @@ -73,6 +75,10 @@ bool SAMLInternalConfig::init() XMLToolingConfig::getConfig().init(); log.debug("XMLTooling library initialized"); + REGISTER_EXCEPTION_FACTORY(ArtifactException,opensaml); + REGISTER_EXCEPTION_FACTORY(MetadataFilterException,opensaml::saml2md); + + registerSAMLArtifacts(); saml1::registerAssertionClasses(); saml1p::registerProtocolClasses(); saml2::registerAssertionClasses(); @@ -96,6 +102,7 @@ void SAMLInternalConfig::term() saml2::AssertionSchemaValidators.destroyValidators(); saml2md::MetadataSchemaValidators.destroyValidators(); + SAMLArtifactManager.deregisterFactories(); MetadataFilterManager.deregisterFactories(); MetadataProviderManager.deregisterFactories(); @@ -135,3 +142,31 @@ XMLCh* SAMLInternalConfig::generateIdentifier() hexform[33]=0; return XMLString::transcode(hexform); } + +string SAMLInternalConfig::hashSHA1(const char* s, bool toHex) +{ + static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + + auto_ptr hasher(XSECPlatformUtils::g_cryptoProvider->hashSHA1()); + if (hasher.get()) { + auto_ptr dup(strdup(s)); + unsigned char buf[21]; + hasher->hash(reinterpret_cast(dup.get()),strlen(dup.get())); + if (hasher->finish(buf,20)==20) { + string ret; + if (toHex) { + for (unsigned int i=0; i<20; i++) { + ret+=(DIGITS[((unsigned char)(0xF0 & buf[i])) >> 4 ]); + ret+=(DIGITS[0x0F & buf[i]]); + } + } + else { + for (unsigned int i=0; i<20; i++) { + ret+=buf[i]; + } + } + return ret; + } + } + throw XMLSecurityException("Unable to generate SHA-1 hash."); +}