You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by sc...@apache.org on 2017/12/11 22:47:45 UTC

svn commit: r1817863 [7/7] - in /santuario/xml-security-cpp/trunk: Projects/VC15.0/xsec/xsec_lib/ xsec/ xsec/dsig/ xsec/enc/ xsec/enc/NSS/ xsec/enc/OpenSSL/ xsec/enc/WinCAPI/ xsec/transformers/ xsec/xenc/impl/ xsec/xkms/

Copied: santuario/xml-security-cpp/trunk/xsec/transformers/TXFMHash.cpp (from r1817395, santuario/xml-security-cpp/trunk/xsec/transformers/TXFMSHA1.cpp)
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/transformers/TXFMHash.cpp?p2=santuario/xml-security-cpp/trunk/xsec/transformers/TXFMHash.cpp&p1=santuario/xml-security-cpp/trunk/xsec/transformers/TXFMSHA1.cpp&r1=1817395&r2=1817863&rev=1817863&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/transformers/TXFMSHA1.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/transformers/TXFMHash.cpp Mon Dec 11 22:47:43 2017
@@ -20,161 +20,121 @@
 /*
  * XSEC
  *
- * TXFMSHA1 := Class that performs a SHA1 transform
+ * TXFMHash := Class that performs a hash/HMAC transform
  *
  * $Id$
  *
  */
 
-// XSEC
-
-#include <xsec/transformers/TXFMSHA1.hpp>
+#include <xsec/transformers/TXFMHash.hpp>
 #include <xsec/utils/XSECPlatformUtils.hpp>
 #include <xsec/framework/XSECException.hpp>
 
 XERCES_CPP_NAMESPACE_USE
 
-TXFMSHA1::TXFMSHA1(DOMDocument *doc, hashMethod hm, const XSECCryptoKey * key) :
-	TXFMBase (doc), mp_h(NULL), md_value(NULL), md_len(0), toOutput(0) {
-
-	int hashLen = 0;
+TXFMHash::TXFMHash(DOMDocument* doc, XSECCryptoHash::HashType type, const XSECCryptoKey* key) :
+    TXFMBase(doc), mp_h(NULL), md_value(NULL), md_len(0), toOutput(0) {
 
-	switch (hm) {
-	case HASH_SHA224 :
-		hashLen = 224;
-		break;
-	case HASH_SHA256 :
-		hashLen = 256;
-		break;
-	case HASH_SHA384 :
-		hashLen = 384;
-		break;
-	case HASH_SHA512 :
-		hashLen = 512;
-		break;
-	default:
-		hashLen = 160;
-	}
-
-	if (key == NULL)
-		// Get a SHA1 worker
-		mp_h = XSECPlatformUtils::g_cryptoProvider->hashSHA(hashLen);
-	else {
-		// Get an HMAC Sha1
-		
-		mp_h = XSECPlatformUtils::g_cryptoProvider->hashHMACSHA(hashLen);
-		if (!mp_h) {
-
-			throw XSECException(XSECException::CryptoProviderError, 
-					"Error requesting SHA1 object from Crypto Provider");
-
-		}
-		mp_h->setKey(key);
-	}
-
-	
-	if (!mp_h) {
-
-		throw XSECException(XSECException::CryptoProviderError, 
-				"Error requesting SHA1 object from Crypto Provider");
-
-	}
-
-	md_value = new unsigned char[XSECPlatformUtils::g_cryptoProvider->getMaxHashSize()];
-	if (!md_value) {
-		delete mp_h;
-	}
+    if (key == NULL) {
+        // Get a hash worker
+        mp_h = XSECPlatformUtils::g_cryptoProvider->hash(type);
+        if (!mp_h) {
+            throw XSECException(XSECException::CryptoProviderError,
+                "Error requesting hash object from Crypto Provider");
+        }
+    } 
+    else {
+        // Get an HMAC worker
+
+        mp_h = XSECPlatformUtils::g_cryptoProvider->HMAC(type);
+        if (!mp_h) {
+            throw XSECException(XSECException::CryptoProviderError,
+                    "Error requesting HMAC object from Crypto Provider");
+        }
+        mp_h->setKey(key);
+    }
+
+    md_value = new unsigned char[XSECPlatformUtils::g_cryptoProvider->getMaxHashSize()];
+    if (!md_value) {
+        delete mp_h;
+    }
 };
 
-TXFMSHA1::~TXFMSHA1() {
+TXFMHash::~TXFMHash() {
 
-	// Clean up
-	if (mp_h)
-		delete mp_h;
+    // Clean up
+    if (mp_h)
+        delete mp_h;
 
-	if (md_value)
-		delete[] md_value;
+    if (md_value)
+        delete[] md_value;
 };
 
-	// Methods to set the inputs
-
-//void TXFMSHA1::setInput(TXFMBase *input);
-
-	// Methods to get tranform output type and input requirement
+    // Methods to set the inputs
 
-TXFMBase::ioType TXFMSHA1::getInputType(void) const {
+//void TXFMHash::setInput(TXFMBase *input);
 
-	return TXFMBase::BYTE_STREAM;
+    // Methods to get tranform output type and input requirement
 
+TXFMBase::ioType TXFMHash::getInputType() const {
+    return TXFMBase::BYTE_STREAM;
 }
-TXFMBase::ioType TXFMSHA1::getOutputType(void) const {
-
-	return TXFMBase::BYTE_STREAM;
 
+TXFMBase::ioType TXFMHash::getOutputType() const {
+    return TXFMBase::BYTE_STREAM;
 }
 
-
-TXFMBase::nodeType TXFMSHA1::getNodeType(void) const {
-
-	return TXFMBase::DOM_NODE_NONE;
-
+TXFMBase::nodeType TXFMHash::getNodeType() const {
+    return TXFMBase::DOM_NODE_NONE;
 }
 
-	// Methods to set input data
+    // Methods to set input data
 
-void TXFMSHA1::setInput(TXFMBase * inputT) {
+void TXFMHash::setInput(TXFMBase* inputT) {
 
-	input = inputT;
+    input = inputT;
 
-	keepComments = input->getCommentsStatus();
+    keepComments = input->getCommentsStatus();
 
-	// Now run through the data
-	unsigned char buffer[1024];
-	unsigned int size;
+    // Now run through the data
+    unsigned char buffer[1024];
+    unsigned int size;
 
-	while ((size = input->readBytes((XMLByte *) buffer, 1024)) != 0) {
-#if 0
-		// Some useful debbugging code
-		FILE * f = fopen("debug.out","a+b");
-		fwrite(buffer, size, 1, f);
-		fclose(f);
-#endif
-		mp_h->hash(buffer, size);
-	}
-	
-	// Finalise
+    while ((size = input->readBytes((XMLByte *) buffer, 1024)) != 0) {
+        mp_h->hash(buffer, size);
+    }
 
-	md_len = mp_h->finish(md_value, XSECPlatformUtils::g_cryptoProvider->getMaxHashSize());
+    // Finalise
 
-	toOutput = md_len;
+    md_len = mp_h->finish(md_value, XSECPlatformUtils::g_cryptoProvider->getMaxHashSize());
 
+    toOutput = md_len;
 }
 
 
-unsigned int TXFMSHA1::readBytes(XMLByte * const toFill, unsigned int maxToFill) {
-	
-	unsigned int ret;
+unsigned int TXFMHash::readBytes(XMLByte * const toFill, unsigned int maxToFill) {
 
-	if (toOutput == 0)
-		return 0;
+    unsigned int ret;
 
-	// Check if we can just output everything left
-	if (toOutput <= maxToFill) {
+    if (toOutput == 0)
+        return 0;
 
-		memcpy((char *) toFill, &md_value[md_len - toOutput], toOutput);
-		ret = toOutput;
-		toOutput = 0;
+    // Check if we can just output everything left
+    if (toOutput <= maxToFill) {
 
-		return ret;
+        memcpy((char *) toFill, &md_value[md_len - toOutput], toOutput);
+        ret = toOutput;
+        toOutput = 0;
 
-	}
+        return ret;
 
-	// Output just some
+    }
 
-	memcpy((char *) toFill, &md_value[md_len - toOutput], maxToFill);
-	ret = maxToFill;
-	toOutput -= maxToFill;
+    // Output just some
 
-	return ret;
+    memcpy((char *) toFill, &md_value[md_len - toOutput], maxToFill);
+    ret = maxToFill;
+    toOutput -= maxToFill;
 
+    return ret;
 }

Added: santuario/xml-security-cpp/trunk/xsec/transformers/TXFMHash.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/transformers/TXFMHash.hpp?rev=1817863&view=auto
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/transformers/TXFMHash.hpp (added)
+++ santuario/xml-security-cpp/trunk/xsec/transformers/TXFMHash.hpp Mon Dec 11 22:47:43 2017
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.
+ */
+
+/*
+ * XSEC
+ *
+ * TXFMSHA1 := Class that performs a hash or HMAC transform
+ *
+ * $Id: TXFMSHA1.hpp 1817135 2017-12-04 22:24:05Z scantor $
+ *
+ */
+
+// XSEC Includes
+
+#include <xsec/transformers/TXFMBase.hpp>
+#include <xsec/enc/XSECCryptoProvider.hpp>
+
+/**
+ * \brief Transformer to handle create a hash or HMAC from a chain
+ * @ingroup internal
+ */
+
+class XSEC_EXPORT TXFMHash : public TXFMBase {
+
+private:
+    XSECCryptoHash* mp_h; 		// To hold the hash
+    unsigned char* md_value;    // Final output
+    unsigned int md_len;        // Length of digest
+
+    unsigned int toOutput;      // Amount still to output
+
+public:
+    TXFMHash(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc, XSECCryptoHash::HashType type, const XSECCryptoKey * key = NULL);
+    virtual ~TXFMHash();
+
+    // Methods to get tranform output type and input requirement
+
+    virtual TXFMBase::ioType getInputType() const;
+    virtual TXFMBase::ioType getOutputType() const;
+    virtual nodeType getNodeType() const;
+
+    // Methods to set input data
+
+    virtual void setInput(TXFMBase * inputT);
+
+    // Methods to get output data
+
+    virtual unsigned int readBytes(XMLByte * const toFill, const unsigned int maxToFill);
+};

Modified: santuario/xml-security-cpp/trunk/xsec/xenc/impl/XENCAlgorithmHandlerDefault.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/xenc/impl/XENCAlgorithmHandlerDefault.cpp?rev=1817863&r1=1817862&r2=1817863&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/xenc/impl/XENCAlgorithmHandlerDefault.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/xenc/impl/XENCAlgorithmHandlerDefault.cpp Mon Dec 11 22:47:43 2017
@@ -29,15 +29,15 @@
 
 // XSEC Includes
 
-#include <xsec/framework/XSECDefs.hpp>
+#include <xsec/dsig/DSIGConstants.hpp>
+#include <xsec/enc/XSECCryptoKey.hpp>
+#include <xsec/enc/XSECCryptoSymmetricKey.hpp>
+#include <xsec/framework/XSECError.hpp>
 #include <xsec/transformers/TXFMChain.hpp>
 #include <xsec/transformers/TXFMCipher.hpp>
 #include <xsec/transformers/TXFMBase64.hpp>
 #include <xsec/transformers/TXFMSB.hpp>
 #include <xsec/xenc/XENCEncryptionMethod.hpp>
-#include <xsec/enc/XSECCryptoKey.hpp>
-#include <xsec/enc/XSECCryptoSymmetricKey.hpp>
-#include <xsec/framework/XSECError.hpp>
 #include <xsec/utils/XSECDOMUtils.hpp>
 
 #include "../../utils/XSECAutoPtr.hpp"
@@ -427,7 +427,7 @@ unsigned int XENCAlgorithmHandlerDefault
 	offset += sk->decryptFinish(&buf[offset], _MY_MAX_KEY_SIZE - offset);
 
 	// Calculate the CMS Key Checksum
-	XSECCryptoHash * sha1 = XSECPlatformUtils::g_cryptoProvider->hashSHA();
+	XSECCryptoHash * sha1 = XSECPlatformUtils::g_cryptoProvider->hash(XSECCryptoHash::HASH_SHA1);
 	if (!sha1) {
 
 		throw XSECException(XSECException::CryptoProviderError, 
@@ -485,7 +485,7 @@ bool XENCAlgorithmHandlerDefault::wrapKe
 	// Do the first encrypt
 	XMLByte buf2[_MY_MAX_KEY_SIZE + 16];
 
-	XSECCryptoHash * sha1 = XSECPlatformUtils::g_cryptoProvider->hashSHA();
+	XSECCryptoHash * sha1 = XSECPlatformUtils::g_cryptoProvider->hash(XSECCryptoHash::HASH_SHA1);
 	if (!sha1) {
 
 		throw XSECException(XSECException::CryptoProviderError, 
@@ -714,19 +714,19 @@ unsigned int XENCAlgorithmHandlerDefault
 												  offset, 
 												  rsa->getLength(), 
 												  XSECCryptoKeyRSA::PAD_PKCS_1_5, 
-												  HASH_NONE);
+                                                  XSECCryptoHash::HASH_NONE);
 	}
 	else if (strEquals(encryptionMethod->getAlgorithm(), DSIGConstants::s_unicodeStrURIRSA_OAEP_MGFP1) ||
              strEquals(encryptionMethod->getAlgorithm(), DSIGConstants::s_unicodeStrURIRSA_OAEP)) {
 
-        hashMethod hm;
+        XSECCryptoHash::HashType hashType;
 	    const XMLCh* digmeth = encryptionMethod->getDigestMethod();
 
 	    // Is this a URI we recognize?
 	    if (!digmeth|| !*digmeth) {
-	        hm = HASH_SHA1;
+	        hashType = XSECCryptoHash::HASH_SHA1;
 	    }
-	    else if (!XSECmapURIToHashMethod(digmeth, hm)) {
+	    else if (!XSECmapURIToHashType(digmeth, hashType)) {
 	        safeBuffer sb;
 	        sb.sbTranscodeIn("XENCAlgorithmHandlerDefault - Unknown Digest URI : ");
 	        sb.sbXMLChCat(digmeth);
@@ -780,7 +780,7 @@ unsigned int XENCAlgorithmHandlerDefault
 												  offset, 
 												  rsa->getLength(), 
 												  XSECCryptoKeyRSA::PAD_OAEP_MGFP1, 
-												  hm);
+												  hashType);
 
 	}
 
@@ -944,18 +944,18 @@ bool XENCAlgorithmHandlerDefault::doRSAE
 												  offset, 
 												  rsa->getLength(), 
 												  XSECCryptoKeyRSA::PAD_PKCS_1_5, 
-												  HASH_NONE);
+												  XSECCryptoHash::HASH_NONE);
 	}
 
 	else if (strEquals(encryptionMethod->getAlgorithm(), DSIGConstants::s_unicodeStrURIRSA_OAEP_MGFP1) ||
             strEquals(encryptionMethod->getAlgorithm(), DSIGConstants::s_unicodeStrURIRSA_OAEP)) {
         
-        hashMethod hm;
+        XSECCryptoHash::HashType hashType;
         if (encryptionMethod->getDigestMethod() == NULL) {
-            hm = HASH_SHA1;
+            hashType = XSECCryptoHash::HASH_SHA1;
 		    encryptionMethod->setDigestMethod(DSIGConstants::s_unicodeStrURISHA1);
         }
-        else if (!XSECmapURIToHashMethod(encryptionMethod->getDigestMethod(), hm)) {
+        else if (!XSECmapURIToHashType(encryptionMethod->getDigestMethod(), hashType)) {
 	        safeBuffer sb;
 	        sb.sbTranscodeIn("XENCAlgorithmHandlerDefault - Unknown Digest URI : ");
 	        sb.sbXMLChCat(encryptionMethod->getDigestMethod());
@@ -1010,7 +1010,7 @@ bool XENCAlgorithmHandlerDefault::doRSAE
 										  offset, 
 										  rsa->getLength(), 
 										  XSECCryptoKeyRSA::PAD_OAEP_MGFP1, 
-										  hm);
+										  hashType);
 
 	}
 	else {

Modified: santuario/xml-security-cpp/trunk/xsec/xkms/XKMSConstants.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/xkms/XKMSConstants.cpp?rev=1817863&r1=1817862&r2=1817863&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/xkms/XKMSConstants.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/xkms/XKMSConstants.cpp Mon Dec 11 22:47:43 2017
@@ -26,6 +26,8 @@
  *
  */
 
+#ifdef XSEC_XKMS_ENABLED
+
 #include <xsec/xkms/XKMSConstants.hpp>
 
 #include <xercesc/util/XMLUniDefs.hpp>
@@ -1826,3 +1828,5 @@ void XKMSConstants::destroy() {
     s_unicodeStrURISOAP11 = NULL;
     s_unicodeStrURISOAP12 = NULL;
 }
+
+#endif /* XSEC_XKMS_ENABLED */