connectivity/source/commontools/ConnectionWrapper.cxx | 19 ++++++++---------- filter/source/msfilter/mscodec.cxx | 14 +++++++++---- 2 files changed, 19 insertions(+), 14 deletions(-)
New commits: commit f66fbd947f70f6be6b22ab372facaeb9e2fb63ae Author: Michael Stahl <mst...@redhat.com> Date: Thu Jan 11 10:28:42 2018 +0100 tdf#114939 filter: don't use StarOffice SHA1 in MS Office filters Always use real SHA1 here, to avoid interop issues. Change-Id: I28388db34f923bfc476a7eae526934b14d4473b5 diff --git a/filter/source/msfilter/mscodec.cxx b/filter/source/msfilter/mscodec.cxx index 1d7cd35b1125..02a1a1b444d1 100644 --- a/filter/source/msfilter/mscodec.cxx +++ b/filter/source/msfilter/mscodec.cxx @@ -24,6 +24,7 @@ #include <string.h> #include <tools/solar.h> +#include <comphelper/hash.hxx> #include <comphelper/sequenceashashmap.hxx> #include <comphelper/docpasswordhelper.hxx> @@ -373,7 +374,10 @@ void MSCodec_CryptoAPI::InitKey ( } // calculate SHA1 hash of initialData - rtl_digest_SHA1(initialData.data(), initialData.size(), m_aDigestValue.data(), m_aDigestValue.size()); + std::vector<unsigned char> const sha1(::comphelper::Hash::calculateHash( + initialData.data(), initialData.size(), + ::comphelper::HashType::SHA1)); + m_aDigestValue = sha1; lcl_PrintDigest(m_aDigestValue.data(), "digest value"); @@ -419,7 +423,9 @@ void MSCodec_CryptoAPI::GetDigestFromSalt(const sal_uInt8* pSaltData, sal_uInt8* rtl_cipher_decode(m_hCipher, pSaltData, 16, verifier.data(), verifier.size()); - rtl_digest_SHA1(verifier.data(), verifier.size(), pDigest, RTL_DIGEST_LENGTH_SHA1); + std::vector<unsigned char> const sha1(::comphelper::Hash::calculateHash( + verifier.data(), verifier.size(), ::comphelper::HashType::SHA1)); + ::std::copy(sha1.begin(), sha1.end(), pDigest); } bool MSCodec_Std97::InitCipher(sal_uInt32 nCounter) @@ -467,8 +473,8 @@ bool MSCodec_CryptoAPI::InitCipher(sal_uInt32 nCounter) aKeyData.push_back(sal_uInt8((nCounter >> 16) & 0xff)); aKeyData.push_back(sal_uInt8((nCounter >> 24) & 0xff)); - std::vector<sal_uInt8> hash(RTL_DIGEST_LENGTH_SHA1); - rtl_digest_SHA1(aKeyData.data(), aKeyData.size(), hash.data(), RTL_DIGEST_LENGTH_SHA1); + std::vector<unsigned char> const hash(::comphelper::Hash::calculateHash( + aKeyData.data(), aKeyData.size(), ::comphelper::HashType::SHA1)); rtlCipherError result = rtl_cipher_init(m_hCipher, rtl_Cipher_DirectionDecode, commit 162ffd57de49b1f007b88fb247a592acbac0aaf7 Author: Michael Stahl <mst...@redhat.com> Date: Thu Jan 11 10:25:23 2018 +0100 (related:tdf#114939) connectivity: use real SHA1 It looks like OConnectionWrapper::createUniqueId() doesn't really care what particular hash is used, it just wants to create something unique, so don't use the 'special' StarOffice SHA1 here. Change-Id: I817be900ecc9c6d686f21cce4a46f9eadd244b71 diff --git a/connectivity/source/commontools/ConnectionWrapper.cxx b/connectivity/source/commontools/ConnectionWrapper.cxx index 7ac9ed6dc1c2..ff966e65bbee 100644 --- a/connectivity/source/commontools/ConnectionWrapper.cxx +++ b/connectivity/source/commontools/ConnectionWrapper.cxx @@ -23,10 +23,10 @@ #include <com/sun/star/lang/DisposedException.hpp> #include <comphelper/uno3.hxx> #include <comphelper/sequence.hxx> +#include <comphelper/hash.hxx> #include <cppuhelper/supportsservice.hxx> #include <cppuhelper/typeprovider.hxx> #include <com/sun/star/reflection/ProxyFactory.hpp> -#include <rtl/digest.h> #include <algorithm> #include <string.h> @@ -195,12 +195,12 @@ void OConnectionWrapper::createUniqueId( const OUString& _rURL ,const OUString& _rPassword) { // first we create the digest we want to have - rtlDigest aDigest = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); - rtl_digest_update(aDigest,_rURL.getStr(),_rURL.getLength()*sizeof(sal_Unicode)); + ::comphelper::Hash sha1(::comphelper::HashType::SHA1); + sha1.update(reinterpret_cast<unsigned char const*>(_rURL.getStr()), _rURL.getLength() * sizeof(sal_Unicode)); if ( !_rUserName.isEmpty() ) - rtl_digest_update(aDigest,_rUserName.getStr(),_rUserName.getLength()*sizeof(sal_Unicode)); + sha1.update(reinterpret_cast<unsigned char const*>(_rUserName.getStr()), _rUserName.getLength() * sizeof(sal_Unicode)); if ( !_rPassword.isEmpty() ) - rtl_digest_update(aDigest,_rPassword.getStr(),_rPassword.getLength()*sizeof(sal_Unicode)); + sha1.update(reinterpret_cast<unsigned char const*>(_rPassword.getStr()), _rPassword.getLength() * sizeof(sal_Unicode)); // now we need to sort the properties std::sort(_rInfo.begin(),_rInfo.end(),TPropertyValueLessFunctor()); @@ -221,20 +221,19 @@ void OConnectionWrapper::createUniqueId( const OUString& _rURL if ( prop.Value >>= aSeq ) { for(OUString const & s : aSeq) - rtl_digest_update(aDigest,s.getStr(),s.getLength()*sizeof(sal_Unicode)); + sha1.update(reinterpret_cast<unsigned char const*>(s.getStr()), s.getLength() * sizeof(sal_Unicode)); } } } if ( !sValue.isEmpty() ) { // we don't have to convert this into UTF8 because we don't store on a file system - rtl_digest_update(aDigest,sValue.getStr(),sValue.getLength()*sizeof(sal_Unicode)); + sha1.update(reinterpret_cast<unsigned char const*>(sValue.getStr()), sValue.getLength() * sizeof(sal_Unicode)); } } - rtl_digest_get(aDigest,_pBuffer,RTL_DIGEST_LENGTH_SHA1); - // we have to destroy the digest - rtl_digest_destroy(aDigest); + std::vector<unsigned char> result(sha1.finalize()); + std::copy(result.begin(), result.end(), _pBuffer); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits