From f07860503130f180f881037a97b7a730d0948910 Mon Sep 17 00:00:00 2001 From: ElenaSubbotina Date: Thu, 4 Oct 2018 13:01:49 +0300 Subject: [PATCH] x2t - select method encrypt files --- .../source/Oox2OdfConverter/Converter.cpp | 42 ++++++++++++------- DesktopEditor/common/SystemUtils.h | 2 + OfficeCryptReader/source/ECMACryptFile.cpp | 33 +++++++++++---- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp index 52779c510c..963c5cdb14 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp @@ -65,6 +65,7 @@ #include "../../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Sparkline.h" #include "../../../OfficeCryptReader/source/CryptTransform.h" #include "../../../DesktopEditor/common/Directory.h" +#include "../../../DesktopEditor/common/SystemUtils.h" #define PROGRESSEVENT_ID 0 @@ -203,28 +204,37 @@ bool OoxConverter::encrypt_file (const std::wstring &password, const std::wstrin { CRYPT::ODFEncryptor encryptor; CRYPT::_odfCryptData cryptData; -//----------------------- -//aes - cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC; - cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA256; - cryptData.start_hashSize = 32; - cryptData.spinCount = 100000; - cryptData.keySize = 32; + std::wstring sApplication = NSSystemUtils::GetEnvVariable(NSSystemUtils::gc_EnvMethodEncrypt); - cryptData.checksum_size = 1024; - cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA256; + if (sApplication == L"Weak") + { //----------------------- //blowfish - //cryptData.cipherAlgorithm = CRYPT_METHOD::Blowfish_CFB; - //cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA1; - //cryptData.start_hashSize = 20; + cryptData.cipherAlgorithm = CRYPT_METHOD::Blowfish_CFB; + cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA1; + cryptData.start_hashSize = 20; - //cryptData.spinCount = 1024; - //cryptData.keySize = 7;//16; + cryptData.spinCount = 1024; + cryptData.keySize = 7;//16; - //cryptData.checksum_size = 1024; - //cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA1; + cryptData.checksum_size = 1024; + cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA1; + } + else + { +//----------------------- +//aes + cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC; + cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA256; + cryptData.start_hashSize = 32; + + cryptData.spinCount = 100000; + cryptData.keySize = 32; + + cryptData.checksum_size = 1024; + cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA256; + } //----------------------- NSFile::CFileBinary file; diff --git a/DesktopEditor/common/SystemUtils.h b/DesktopEditor/common/SystemUtils.h index c131c9efe8..6c610770f9 100644 --- a/DesktopEditor/common/SystemUtils.h +++ b/DesktopEditor/common/SystemUtils.h @@ -41,6 +41,8 @@ namespace NSSystemUtils static const wchar_t* gc_EnvApplicationNameDefault = L"ONLYOFFICE"; static const wchar_t* gc_EnvCompanyName = L"COMPANY_NAME"; static const wchar_t* gc_EnvCompanyNameDefault = L"Ascensio System SIA Copyright (c) 2018"; + static const wchar_t* gc_EnvMethodEncrypt = L"METHOD_CRYPT"; + static const wchar_t* gc_EnvMethodEncryptDefault = L"Strong"; KERNEL_DECL std::wstring GetEnvVariable(const std::wstring& strName); } diff --git a/OfficeCryptReader/source/ECMACryptFile.cpp b/OfficeCryptReader/source/ECMACryptFile.cpp index 88c3db7355..c98e63e4a0 100644 --- a/OfficeCryptReader/source/ECMACryptFile.cpp +++ b/OfficeCryptReader/source/ECMACryptFile.cpp @@ -37,6 +37,7 @@ #include "../../Common/DocxFormat/Source/Base/Types_32.h" #include "../../DesktopEditor/common/File.h" +#include "../../DesktopEditor/common/SystemUtils.h" #include "../../DesktopEditor/xml/include/xmlutils.h" #include "../../ASCOfficeDocFile/DocDocxConverter/MemoryStream.h" @@ -645,6 +646,30 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s { _ecmaCryptData cryptData; + std::wstring sApplication = NSSystemUtils::GetEnvVariable(NSSystemUtils::gc_EnvMethodEncrypt); + + if (sApplication == L"Weak") + { + cryptData.bAgile = false; + cryptData.cipherAlgorithm = CRYPT_METHOD::DES_ECB; + cryptData.hashAlgorithm = CRYPT_METHOD::SHA1; + cryptData.keySize = 0x08; + cryptData.hashSize = 0x14; + cryptData.blockSize = 0x10; + cryptData.saltSize = 0x10; + cryptData.spinCount = 50000; + } + else + { + cryptData.bAgile = true; + cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC; + cryptData.hashAlgorithm = CRYPT_METHOD::SHA512; + cryptData.keySize = 0x20; + cryptData.hashSize = 0x40; + cryptData.blockSize = 0x10; + cryptData.saltSize = 0x10; + cryptData.spinCount = 100000; + } //cryptData.bAgile = true; //cryptData.cipherAlgorithm = CRYPT_METHOD::DES_CBC; ////cryptData.hashAlgorithm = CRYPT_METHOD::SHA512; @@ -658,14 +683,6 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s //cryptData.blockSize = 0x10; //cryptData.saltSize = 0x10; - cryptData.bAgile = true; - cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC; - cryptData.hashAlgorithm = CRYPT_METHOD::SHA512; - cryptData.keySize = 0x20; - cryptData.hashSize = 0x40; - cryptData.blockSize = 0x10; - cryptData.saltSize = 0x10; - //cryptData.bAgile = false; //cryptData.cipherAlgorithm = CRYPT_METHOD::AES_ECB; //cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;