#include <xmltooling/logging.h>
#include <xmltooling/XMLToolingConfig.h>
+#include <xmltooling/security/SecurityHelper.h>
#include <xmltooling/signature/Signature.h>
#include <xmltooling/util/NDC.h>
#include <xmltooling/util/PathResolver.h>
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<XSECCryptoHash> hasher(XSECPlatformUtils::g_cryptoProvider->hashSHA1());
- if (hasher.get()) {
- unsigned char buf[21];
- hasher->hash(reinterpret_cast<unsigned char*>(const_cast<char*>(s)),strlen(s));
- 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.");
+ return SecurityHelper::doHash("SHA1", s, strlen(s), toHex);
}
SignableObject::SignableObject()
virtual XMLCh* generateIdentifier()=0;
/**
+ * @deprecated
* Generate the SHA-1 hash of a string
*
* @param s NULL-terminated string to hash
#include <xmltooling/XMLToolingConfig.h>
#include <xmltooling/security/Credential.h>
#include <xmltooling/security/KeyInfoResolver.h>
+#include <xmltooling/security/SecurityHelper.h>
#include <xmltooling/util/Threads.h>
#include <xmltooling/util/XMLHelper.h>
}
// Hash the ID.
- m_sources.insert(sitemap_t::value_type(SAMLConfig::getConfig().hashSHA1(id.get(), true),site));
+ m_sources.insert(sitemap_t::value_type(SecurityHelper::doHash("SHA1", id.get(), strlen(id.get())),site));
// Load endpoints for type 0x0002 artifacts.
const vector<ArtifactResolutionService*>& locs=const_cast<const IDPSSODescriptor*>(*i)->getArtifactResolutionServices();
// SAML 2.0?
if ((*i)->hasSupport(samlconstants::SAML20P_NS)) {
// Hash the ID.
- m_sources.insert(sitemap_t::value_type(SAMLConfig::getConfig().hashSHA1(id.get(), true),site));
+ m_sources.insert(sitemap_t::value_type(SecurityHelper::doHash("SHA1", id.get(), strlen(id.get())),site));
}
}
}
/*
- * Copyright 2001-2007 Internet2
+ * Copyright 2001-2009 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "saml/binding/ArtifactMap.h"
#include <saml/saml2/binding/SAML2ArtifactType0004.h>
#include <saml/saml2/core/Protocols.h>
+#include <xmltooling/security/SecurityHelper.h>
using namespace opensaml::saml2p;
using namespace opensaml;
void testArtifactMap(void) {
auto_ptr<Response> response(ResponseBuilder::buildResponse());
- SAML2ArtifactType0004 artifact(SAMLConfig::getConfig().hashSHA1(providerIdStr.c_str()),666,handle);
+ SAML2ArtifactType0004 artifact(
+ SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false), 666, handle
+ );
ArtifactMap* artifactMap = SAMLConfig::getConfig().getArtifactMap();
artifactMap->storeContent(response.get(), &artifact, providerIdStr.c_str());
/*
- * Copyright 2001-2007 Internet2
+ * Copyright 2001-2009 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <saml/saml1/binding/SAMLArtifactType0001.h>
#include <saml/saml1/binding/SAMLArtifactType0002.h>
#include <saml/saml2/binding/SAML2ArtifactType0004.h>
+#include <xmltooling/security/SecurityHelper.h>
using namespace opensaml::saml1p;
using namespace opensaml::saml2p;
SAMLArtifactType0001 artifact1(sourceId,handle);
//printResults(artifact1);
- SAMLArtifactType0001 artifact2(conf.hashSHA1(providerIdStr.c_str()),handle);
+ SAMLArtifactType0001 artifact2(
+ SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false), handle
+ );
//printResults(artifact2,providerIdStr.c_str());
}
}
void testSAMLArtifactType0004(void) {
- SAML2ArtifactType0004 artifact(SAMLConfig::getConfig().hashSHA1(providerIdStr.c_str()),666,handle);
+ SAML2ArtifactType0004 artifact(
+ SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false), 666, handle
+ );
//printResults(artifact,providerIdStr.c_str());
}
/*
- * Copyright 2001-2007 Internet2
+ * Copyright 2001-2009 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "internal.h"
#include <saml/SAMLConfig.h>
#include <saml/saml1/binding/SAMLArtifactType0001.h>
+#include <xmltooling/security/SecurityHelper.h>
using namespace opensaml::saml1p;
using namespace opensaml;
}
void testSAMLArtifactType0001(void) {
- string sourceId = SAMLConfig::getConfig().hashSHA1(providerIdStr.c_str());
+ string sourceId = SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false);
auto_ptr<SAMLArtifactType0001> artifact(new SAMLArtifactType0001(sourceId));
auto_ptr<SAMLArtifact> tempArtifact(SAMLArtifact::parse(artifact->encode().c_str()));
/*
- * Copyright 2001-2007 Internet2
+ * Copyright 2001-2009 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "internal.h"
#include <saml/SAMLConfig.h>
#include <saml/saml2/binding/SAML2ArtifactType0004.h>
+#include <xmltooling/security/SecurityHelper.h>
using namespace opensaml::saml2p;
using namespace opensaml;
}
void testSAMLArtifactType0004(void) {
- string sourceId = SAMLConfig::getConfig().hashSHA1(providerIdStr.c_str());
+ string sourceId = SecurityHelper::doHash("SHA1", providerIdStr.data(), providerIdStr.length(), false);
auto_ptr<SAML2ArtifactType0004> artifact(new SAML2ArtifactType0004(sourceId,666));
auto_ptr<SAML2Artifact> tempArtifact(dynamic_cast<SAML2Artifact*>(SAMLArtifact::parse(artifact->encode().c_str())));
#include <saml/saml1/core/Assertions.h>
#include <saml/saml1/core/Protocols.h>
#include <saml/saml1/binding/SAMLArtifactType0001.h>
+#include <xmltooling/security/SecurityHelper.h>
#include <xmltooling/signature/Signature.h>
#include <xmltooling/validation/ValidatorSuite.h>
}
SAMLArtifact* generateSAML1Artifact(const EntityDescriptor* relyingParty) const {
- return new SAMLArtifactType0001(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"));
+ static const char* providerIdStr = "https://idp.example.org/";
+ return new SAMLArtifactType0001(
+ SecurityHelper::doHash("SHA1", providerIdStr, strlen(providerIdStr), false)
+ );
}
saml2p::SAML2Artifact* generateSAML2Artifact(const EntityDescriptor* relyingParty) const {
#include <saml/binding/ArtifactMap.h>
#include <saml/saml2/core/Protocols.h>
#include <saml/saml2/binding/SAML2ArtifactType0004.h>
+#include <xmltooling/security/SecurityHelper.h>
#include <xmltooling/validation/ValidatorSuite.h>
using namespace opensaml::saml2p;
}
saml2p::SAML2Artifact* generateSAML2Artifact(const EntityDescriptor* relyingParty) const {
- return new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"),1);
+ static const char* providerIdStr = "https://idp.example.org/";
+ return new SAML2ArtifactType0004(
+ SecurityHelper::doHash("SHA1", providerIdStr, strlen(providerIdStr), false), 1
+ );
}
saml1p::Response* resolve(
/*
- * Copyright 2001-2007 Internet2
+ * Copyright 2001-2009 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <saml/saml2/binding/SAML2ArtifactType0004.h>
#include <saml/saml2/metadata/Metadata.h>
#include <saml/saml2/metadata/MetadataProvider.h>
+#include <xmltooling/security/SecurityHelper.h>
using namespace opensaml::saml2md;
using namespace opensaml::saml2p;
TSM_ASSERT("Role lookup failed", find_if(descriptor->getIDPSSODescriptors(), isValidForProtocol(supportedProtocol))!=NULL);
TSM_ASSERT("Role lookup failed", find_if(descriptor->getIDPSSODescriptors(), isValidForProtocol(supportedProtocol2))!=NULL);
+ static const char* providerIdStr = "urn:mace:incommon:washington.edu";
auto_ptr<SAML2ArtifactType0004> artifact(
- new SAML2ArtifactType0004(SAMLConfig::getConfig().hashSHA1("urn:mace:incommon:washington.edu"),1)
+ new SAML2ArtifactType0004(
+ SecurityHelper::doHash("SHA1", providerIdStr, strlen(providerIdStr), false), 1
+ )
);
descriptor = metadataProvider->getEntityDescriptor(MetadataProvider::Criteria(artifact.get(),NULL,NULL,false)).first;
TSM_ASSERT("Retrieved entity descriptor was null", descriptor!=NULL);