Compare commits

..

10 Commits

12 changed files with 1009 additions and 566 deletions

View File

@ -148,8 +148,8 @@ odf_document::Impl::Impl(xml::sax * Reader, const std::wstring & tempPath):
}
}
odf_document::Impl::Impl(const std::wstring & srcPath, const std::wstring & tempPath, const std::wstring & Password, const ProgressCallback* CallBack) :
context_(new odf_read_context()), pCallBack(CallBack), bUserStopConvert (0), bError(false)
odf_document::Impl::Impl(const std::wstring & srcPath, const std::wstring & tempPath, const std::wstring & password, const ProgressCallback* callBack) :
context_(new odf_read_context()), pCallBack(callBack), bUserStopConvert (0), bError(false)
{
office_mime_type_ = 0;
@ -178,12 +178,12 @@ odf_document::Impl::Impl(const std::wstring & srcPath, const std::wstring & temp
if (false == map_encryptions_.empty())
{
if (Password.empty()) return;
if (password.empty()) return;
//decrypt files
tmp_folder_ = NSDirectory::CreateDirectoryWithUniqueName(tempPath);
bError = !decrypt_folder(base_folder_, tmp_folder_);
bError = !decrypt_folder(password, base_folder_, tmp_folder_);
if (bError)
return;
@ -248,7 +248,7 @@ odf_document::Impl::~Impl()
NSDirectory::DeleteDirectory(tmp_folder_);
}
bool odf_document::Impl::decrypt_folder (const std::wstring & srcPath, const std::wstring & dstPath)
bool odf_document::Impl::decrypt_folder (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath)
{
std::vector<std::wstring> arFiles = NSDirectory::GetFiles(srcPath, false);
std::vector<std::wstring> arDirectories = NSDirectory::GetDirectories(srcPath);
@ -261,7 +261,7 @@ bool odf_document::Impl::decrypt_folder (const std::wstring & srcPath, const std
std::map<std::wstring, std::pair<office_element_ptr, int>>::iterator pFind = map_encryptions_.find(arFiles[i]);
if ( pFind != map_encryptions_.end() )
{
result = decrypt_file(arFiles[i], dstPath + FILE_SEPARATOR_STR + sFileName, pFind->second.first, pFind->second.second);
result = decrypt_file(password, arFiles[i], dstPath + FILE_SEPARATOR_STR + sFileName, pFind->second.first, pFind->second.second);
if (false == result)
break;
@ -277,7 +277,7 @@ bool odf_document::Impl::decrypt_folder (const std::wstring & srcPath, const std
NSDirectory::CreateDirectory(dstPath + FILE_SEPARATOR_STR + sDirName);
result = decrypt_folder(arDirectories[i], dstPath + FILE_SEPARATOR_STR + sDirName);
result = decrypt_folder(password, arDirectories[i], dstPath + FILE_SEPARATOR_STR + sDirName);
}
return result;
}
@ -297,14 +297,11 @@ std::string DecodeBase64(const std::wstring & value1)
}
return result;
}
bool odf_document::Impl::decrypt_file (const std::wstring & srcPath, const std::wstring & dstPath, office_element_ptr element, int size )
bool odf_document::Impl::decrypt_file (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath, office_element_ptr element, int file_size )
{
manifest_encryption_data* encryption_data = dynamic_cast<manifest_encryption_data*>(element.get());
if (!encryption_data) return false;
//std::wstring checksum_;
//std::wstring checksum_type_;
manifest_algorithm* algorithm = dynamic_cast<manifest_algorithm*>(encryption_data->algorithm_.get());
manifest_key_derivation* key_derivation = dynamic_cast<manifest_key_derivation*>(encryption_data->key_derivation_.get());
manifest_start_key_generation* start_key_generation = dynamic_cast<manifest_start_key_generation*>(encryption_data->start_key_generation_.get());
@ -312,86 +309,77 @@ bool odf_document::Impl::decrypt_file (const std::wstring & srcPath, const std::
CRYPT::ODFDecryptor decryptor;
CRYPT::_odfCryptData cryptData;
cryptData.saltValue = DecodeBase64(key_derivation->salt_);
cryptData.saltSize = cryptData.saltValue.length();
cryptData.spinCount = key_derivation->iteration_count_;
//------------------------------------------------------------------------------------------
if (std::wstring::npos != start_key_generation->start_key_generation_name_.find(L"sha"))
if (key_derivation)
{
if (std::wstring::npos != start_key_generation->start_key_generation_name_.find(L"512"))
{
cryptData.hashAlgorithm = CRYPT_METHOD::SHA512;
cryptData.hashSize = 40; //320 bit
}
if (std::wstring::npos != start_key_generation->start_key_generation_name_.find(L"256"))
{
cryptData.hashAlgorithm = CRYPT_METHOD::SHA256;
cryptData.hashSize = 40; //320 bit
}
else
{
cryptData.hashAlgorithm = CRYPT_METHOD::SHA1;
cryptData.hashSize = 20; //160 bit
}
}
else
{
cryptData.hashAlgorithm = CRYPT_METHOD::MD5; //????
cryptData.hashSize = 16; //128 bit
cryptData.saltValue = DecodeBase64(key_derivation->salt_);
cryptData.spinCount = key_derivation->iteration_count_;
cryptData.keySize = key_derivation->key_size_;
}
//------------------------------------------------------------------------------------------
cryptData.initializationVector = DecodeBase64(algorithm->initialisation_vector_);
if (start_key_generation)
{
if (std::wstring::npos != start_key_generation->start_key_generation_name_.find(L"sha"))
{
if (std::wstring::npos != start_key_generation->start_key_generation_name_.find(L"512"))
{
cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA512;
}
if (std::wstring::npos != start_key_generation->start_key_generation_name_.find(L"256"))
{
cryptData.start_hashAlgorithm = CRYPT_METHOD::SHA256;
}
}
cryptData.start_hashSize = start_key_generation->key_size_;
}
//------------------------------------------------------------------------------------------
if (algorithm)
{
cryptData.initializationVector = DecodeBase64(algorithm->initialisation_vector_);
if (std::wstring::npos != algorithm->algorithm_name.find(L"aes"))
{
if (std::wstring::npos != algorithm->algorithm_name.find(L"cbc"))
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC;
else
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_ECB;//??
if (std::wstring::npos != algorithm->algorithm_name.find(L"512"))
cryptData.keySize = 512 /8;
else if (std::wstring::npos != algorithm->algorithm_name.find(L"256"))
cryptData.keySize = 256 /8;
else
cryptData.keySize = 128 /8; //??
}
else if (std::wstring::npos != algorithm->algorithm_name.find(L"blowfish"))
{
cryptData.cipherAlgorithm = CRYPT_METHOD::Blowfish;//CFB
if (std::wstring::npos != algorithm->algorithm_name_.find(L"aes"))
{
if (std::wstring::npos != algorithm->algorithm_name_.find(L"cbc"))
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_CBC;
else
cryptData.cipherAlgorithm = CRYPT_METHOD::AES_ECB;//??
}
else if (std::wstring::npos != algorithm->algorithm_name_.find(L"blowfish"))
{
cryptData.cipherAlgorithm = CRYPT_METHOD::Blowfish_CFB;
}
}
//------------------------------------------------------------------------------------------
cryptData.checksum = DecodeBase64(encryption_data->checksum_);
if (std::wstring::npos != encryption_data->checksum_type_.find(L"sha"))
if (encryption_data)
{
if (std::wstring::npos != start_key_generation->start_key_generation_name_.find(L"512"))
cryptData.checksum = DecodeBase64(encryption_data->checksum_);
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA1;
if (std::wstring::npos != encryption_data->checksum_type_.find(L"sha"))
{
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA512;
if (std::wstring::npos != encryption_data->checksum_type_.find(L"512"))
{
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA512;
}
if (std::wstring::npos != encryption_data->checksum_type_.find(L"256"))
{
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA256;
}
}
if (std::wstring::npos != start_key_generation->start_key_generation_name_.find(L"256"))
size_t nPosChecksumSize = encryption_data->checksum_type_.find(L"-");
if (std::wstring::npos == nPosChecksumSize)
nPosChecksumSize = encryption_data->checksum_type_.find(L"/");
if (std::wstring::npos != nPosChecksumSize)
{
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA256;
}
else
{
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::SHA1;
}
}
else
{
cryptData.checksum_hashAlgorithm = CRYPT_METHOD::MD5; //????
}
size_t nPosChecksumSize = encryption_data->checksum_type_.find(L"-");
if (std::wstring::npos != nPosChecksumSize)
{
std::wstring strSize = encryption_data->checksum_type_.substr(nPosChecksumSize + 1);
if (strSize == L"1k")
{
cryptData.checksum_size = 1024;
}
else
{
//???
std::wstring strSize = encryption_data->checksum_type_.substr(nPosChecksumSize + 1);
if (strSize == L"1k")
{
cryptData.checksum_size = 1024;
}
else
{
//???
}
}
}
@ -401,42 +389,31 @@ bool odf_document::Impl::decrypt_file (const std::wstring & srcPath, const std::
return false;
DWORD dwSizeRead = 0;
_UINT64 lengthData, lengthRead = file_inp.GetFileSize();
_UINT64 lengthRead = file_inp.GetFileSize();
unsigned char* data = new unsigned char[lengthRead];
unsigned char* data_out = NULL;
file_inp.ReadFile(data, lengthRead, dwSizeRead);
cryptData.input = std::string((char*)data, cryptData.checksum_size) ;
//------------------------------------------------------------------------------------------
decryptor.SetCryptData(cryptData);
if (!decryptor.SetPassword(L"password"))
{
return false;
}
bool result = decryptor.Decrypt(password, data, dwSizeRead, data_out, file_size);
delete []data;
//------------------------------------------------------------------------------------------------------------
int readData = dwSizeRead;// - 8;
lengthData = *((_UINT64*)data);
bool result = false;
decryptor.Decrypt(data /*+ 8*/, readData, data_out, 0);//todoo сделать покусочное чтение декриптование
if (data_out)
if (result && data_out)
{
NSFile::CFileBinary file_out;
file_out.CreateFileW(dstPath);
file_out.WriteFile(data_out, lengthData);
file_out.WriteFile(data_out, file_size);
file_out.CloseFile();
delete []data_out;
result = true;
delete []data_out;
return result;
}
delete []data;
return result;
}
const std::wstring & odf_document::Impl::get_temp_folder() const

View File

@ -97,8 +97,8 @@ private:
void parse_manifests(office_element *element);
void parse_settings (office_element *element);
bool decrypt_folder (const std::wstring & srcPath, const std::wstring & dstPath);
bool decrypt_file (const std::wstring & srcPath, const std::wstring & dstPath, office_element_ptr data, int size );
bool decrypt_folder (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath);
bool decrypt_file (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath, office_element_ptr data, int size );
content_xml_t_ptr content_xml_;
content_xml_t_ptr styles_xml_;

View File

@ -164,6 +164,7 @@ void manifest_encryption_data::add_attributes( const xml::attributes_wc_ptr & At
{
checksum_type_ = checksum_type_.substr(nFind + 1);
}
checksum_type_ = XmlUtils::GetLower(checksum_type_);
}
void manifest_encryption_data::add_child_element(cpdoccore::xml::sax *Reader, const std::wstring &Ns, const std::wstring &Name)
{
@ -187,14 +188,15 @@ const wchar_t * manifest_algorithm::name = L"algorithm";
void manifest_algorithm::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"manifest:algorithm-name", algorithm_name, std::wstring(L""));
CP_APPLY_ATTR(L"manifest:algorithm-name", algorithm_name_, std::wstring(L""));
CP_APPLY_ATTR(L"manifest:initialisation-vector", initialisation_vector_, std::wstring(L""));
size_t nFind = algorithm_name.find(L"#");
size_t nFind = algorithm_name_.find(L"#");
if (nFind != std::wstring::npos)
{
algorithm_name = algorithm_name.substr(nFind + 1);
algorithm_name_ = algorithm_name_.substr(nFind + 1);
}
algorithm_name_ = XmlUtils::GetLower(algorithm_name_);
}
// manifest:key-derivation
//////////////////////////////////////////////////////////////////////////////////////////////////
@ -205,7 +207,7 @@ void manifest_key_derivation::add_attributes( const xml::attributes_wc_ptr & Att
{
CP_APPLY_ATTR(L"manifest:key-derivation-name", key_derivation_name_, std::wstring(L""));
CP_APPLY_ATTR(L"manifest:key-size", key_size_, 16);
CP_APPLY_ATTR(L"manifest:iteration-count", iteration_count_, 100000);
CP_APPLY_ATTR(L"manifest:iteration-count", iteration_count_, 1024);
CP_APPLY_ATTR(L"manifest:salt", salt_, std::wstring(L""));
size_t nFind = key_derivation_name_.find(L"#");
@ -213,6 +215,7 @@ void manifest_key_derivation::add_attributes( const xml::attributes_wc_ptr & Att
{
key_derivation_name_ = key_derivation_name_.substr(nFind + 1);
}
key_derivation_name_ = XmlUtils::GetLower(key_derivation_name_);
}
// manifest:start-key-generation
//////////////////////////////////////////////////////////////////////////////////////////////////
@ -229,6 +232,7 @@ void manifest_start_key_generation::add_attributes( const xml::attributes_wc_ptr
{
start_key_generation_name_ = start_key_generation_name_.substr(nFind + 1);
}
start_key_generation_name_ = XmlUtils::GetLower(start_key_generation_name_);
}
}
}

View File

@ -253,7 +253,7 @@ public:
CPDOCCORE_DEFINE_VISITABLE();
std::wstring algorithm_name;
std::wstring algorithm_name_;
std::wstring initialisation_vector_;
};
CP_REGISTER_OFFICE_ELEMENT2(manifest_algorithm);

View File

@ -80,15 +80,15 @@ void CFileDownloader::Stop()
return m_pInternal->Stop();
}
inline int CFileDownloader::IsSuspended()
int CFileDownloader::IsSuspended()
{
return m_pInternal->IsSuspended();
}
inline int CFileDownloader::IsRunned()
int CFileDownloader::IsRunned()
{
return m_pInternal->IsRunned();
}
inline int CFileDownloader::GetError()
int CFileDownloader::GetError()
{
return m_pInternal->GetError();
}

View File

@ -56,9 +56,9 @@ public:
void Resume();
void Stop();
inline int IsSuspended();
inline int IsRunned();
inline int GetError();
int IsSuspended();
int IsRunned();
int GetError();
int GetPriority();

View File

@ -46,10 +46,14 @@
#include "../../Common/3dParty/cryptopp/filters.h"
#include "../../Common/3dParty/cryptopp/osrng.h"
#include "../../Common/3dParty/cryptopp/hex.h"
#include "../../Common/3dParty/cryptopp/blowfish.h"
#include "../../Common/3dParty/cryptopp/zinflate.h"
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
#include "../../Common/DocxFormat/Source/Base/Types_32.h"
#include "../../DesktopEditor/common/File.h"
static const unsigned char encrVerifierHashInputBlockKey[8] = { 0xfe, 0xa7, 0xd2, 0x76, 0x3b, 0x4b, 0x9e, 0x79 };
static const unsigned char encrVerifierHashValueBlockKey[8] = { 0xd7, 0xaa, 0x0f, 0x6d, 0x30, 0x61, 0x34, 0x4e };
static const unsigned char encrKeyValueBlockKey[8] = { 0x14, 0x6e, 0x0b, 0xe7, 0xab, 0xac, 0xd0, 0xd6 };
@ -66,10 +70,15 @@ public:
int size;
//-----------------------------------------------------------------------------------
_buf() : ptr(NULL), size(0), bDelete(true){}
_buf(int sz) : ptr(NULL), size(0), bDelete(true)
_buf(int sz, bool zero_set = false) : ptr(NULL), size(0), bDelete(true)
{
ptr = new unsigned char [sz];
size = sz;
if (ptr && zero_set)
{
memset(ptr, 0, size);
}
}
_buf(unsigned char * buf, int sz, bool bDelete_ = true ): ptr(NULL), size(0), bDelete(true)
{
@ -284,36 +293,18 @@ _buf GenerateAgileKey(_buf & salt, _buf & password, _buf & blockKey, int hashSiz
return _buf(pHashBuf.ptr, pHashBuf.size);
}
_buf GenerateOdfKey(_buf & salt, _buf & password, _buf & blockKey, int hashSize, int spin, CRYPT_METHOD::_hashAlgorithm algorithm, int block_index = 0)
_buf GenerateOdfKey(_buf & pSalt, _buf & pPassword, int keySize, int spin, CRYPT_METHOD::_hashAlgorithm algorithm)
{
_buf pHashBuf = HashAppend(salt, password, algorithm);
_buf pKey (keySize);
_buf empty (NULL, 0, false);
for (int i = 0; i < spin; i++)
{
_buf iterator((unsigned char*)&i, 4, false);
pHashBuf = HashAppend(iterator, pHashBuf, algorithm);
}
_buf pPassword_hash = HashAppend(pPassword, empty, algorithm);
pHashBuf = HashAppend(pHashBuf, blockKey, algorithm);
PKCS5_PBKDF2_HMAC<SHA1> pbkdf;
pbkdf.DeriveKey(pKey.ptr, pKey.size, 0, pPassword_hash.ptr, pPassword_hash.size, pSalt.ptr, pSalt.size, spin);
CorrectHashSize(pHashBuf, hashSize, 0x36);
return _buf(pHashBuf.ptr, pHashBuf.size);
//unsigned char *out = NULL;
//SecByteBlock derived(hashSize);
//PKCS5_PBKDF2_HMAC<SHA256> pbkdf2;
//pbkdf2.DeriveKey(
// derived.data(),
// derived.size(),
// 0,
// password.ptr, password.size,
// salt.ptr, salt.size,
// spin);
//
//return _buf(derived.data(), derived.size());
return _buf(pKey.ptr, pKey.size);
}
_buf GenerateHashKey(_buf & salt, _buf & password, int hashSize, int spin, CRYPT_METHOD::_hashAlgorithm algorithm, int block_index = 0)
@ -434,6 +425,11 @@ bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRY
{
rc4Decryption.ProcessData(data_out.ptr, data_inp.ptr, data_inp.size);
}
else if (algorithm == CRYPT_METHOD::Blowfish_CFB)
{
CFB_Mode<Blowfish>::Decryption decryption(key.ptr, key.size, iv.ptr);
decryption.ProcessData(data_out.ptr, data_inp.ptr, data_inp.size);
}
else //AES
{
StreamTransformation *modeDecryption = NULL;
@ -682,8 +678,7 @@ void ECMADecryptor::Decrypt(unsigned char* data_inp, int size, unsigned char*&
_buf pDecryptedKey;
DecryptCipher( agileKey, pSalt, pKeyValue, pDecryptedKey, cryptData.cipherAlgorithm);
_buf iv(cryptData.blockSize);
memset( iv.ptr, 0x00, cryptData.blockSize );
_buf iv(cryptData.blockSize, true);
int i = start_iv_block, sz = 4096, pos = 0;//aes block size = 4096
@ -891,8 +886,7 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
////??? pEncryptedKey == pKeyValue;
//-------------------------------------------------------------------------------------------------
_buf iv(cryptData.blockSize);
memset( iv.ptr, 0x00, cryptData.blockSize );
_buf iv(cryptData.blockSize, true);
int i = 0, sz = 4096, enc_size = 0;
@ -948,83 +942,53 @@ ODFDecryptor::~ODFDecryptor()
{
}
bool ODFDecryptor::SetPassword(std::wstring _password)
{
bVerify = false;
password = _password;
if (password.empty()) return false;
_buf pPassword (password);
_buf pSalt (cryptData.saltValue);
_buf empty (NULL, 0, false);
_buf pEncVerInput (cryptData.input);
_buf pEncVerValue (cryptData.checksum);
_buf pIvi (cryptData.initializationVector);
_buf hashBufIvi = HashAppend(pIvi, empty, cryptData.hashAlgorithm);
//_buf verifierKey1 = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.spinCount, cryptData.checksum_hashAlgorithm);
_buf verifierKey = GenerateOdfKey(pSalt, pPassword, pIvi, cryptData.hashSize, cryptData.spinCount, cryptData.checksum_hashAlgorithm);
CorrectHashSize(verifierKey, cryptData.keySize, 0);//??
////--------------------------------------------
_buf decryptedVerifierHashInputBytes;
DecryptCipher(verifierKey, pIvi, pEncVerInput, decryptedVerifierHashInputBytes, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf hashBuf = HashAppend(decryptedVerifierHashInputBytes, empty, cryptData.hashAlgorithm);
//--------------------------------------------
_buf decryptedVerifierHashBytes;
DecryptCipher(verifierKey, pIvi, pEncVerValue, decryptedVerifierHashBytes, cryptData.cipherAlgorithm);
bVerify = (decryptedVerifierHashBytes==hashBuf);
return true;
}
bool ODFDecryptor::IsVerify()
{
return bVerify;
}
void ODFDecryptor::SetCryptData(_odfCryptData & data)
{
cryptData = data;
}
void ODFDecryptor::Decrypt(char* data, const size_t size, const unsigned long start_iv_block)
bool ODFDecryptor::Decrypt(const std::wstring &wpassword, unsigned char* data_inp, int size_inp, unsigned char*& data_out, int &size_out)
{
if (!bVerify) return;
unsigned char* data_out = NULL;
Decrypt((unsigned char*)data, size, data_out, start_iv_block);
if (data_out)
{
memcpy(data, data_out, size);
delete []data_out;
}
}
void ODFDecryptor::Decrypt(unsigned char* data_inp, int size, unsigned char*& data_out, unsigned long start_iv_block)
{
data_out = new unsigned char[size];
bVerify = false;
std::string password = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(wpassword);
_buf pPassword (password);
_buf pSalt (cryptData.saltValue);
_buf ivi (cryptData.initializationVector);
_buf empty (NULL, 0, false);
_buf start (cryptData.initializationVector);
_buf hashKey = GenerateOdfKey(pSalt, pPassword, start, cryptData.hashSize, cryptData.spinCount, cryptData.hashAlgorithm, start_iv_block);
CorrectHashSize(hashKey, cryptData.keySize, 0);
_buf pInp(data_inp, size, false);
_buf pOut(data_out, size, false);
_buf ivi(cryptData.initializationVector);
_buf pKey = GenerateOdfKey(pSalt, pPassword, cryptData.keySize, cryptData.spinCount, cryptData.start_hashAlgorithm);
DecryptCipher(hashKey, ivi, pInp, pOut, cryptData.cipherAlgorithm);
_buf pInp(data_inp, size_inp, false);
_buf pOut(size_inp);
if (false == DecryptCipher(pKey, ivi, pInp, pOut, cryptData.cipherAlgorithm))
return false;
_buf pChecksum (cryptData.checksum);
_buf pOutLimit(pOut.ptr, (std::min)(cryptData.checksum_size, pOut.size), false);
_buf pOutHash = HashAppend(pOutLimit, empty, cryptData.checksum_hashAlgorithm);
bVerify = (pChecksum == pOutHash);
try
{
if (bVerify)
{
data_out = new unsigned char[size_out];
Inflator inflator(new ArraySink( data_out, size_out));
inflator.Put(pOut.ptr, pOut.size);
inflator.MessageEnd();
}
}
catch(...)
{
return false;
}
return bVerify;
}

View File

@ -55,7 +55,7 @@ namespace CRYPT_METHOD
AES_CBC,
AES_CFB,
AES_ECB,
Blowfish
Blowfish_CFB
};
}
namespace CRYPT
@ -109,17 +109,16 @@ struct _ecmaCryptData
struct _odfCryptData
{
CRYPT_METHOD::_cipherAlgorithm cipherAlgorithm = CRYPT_METHOD::AES_CBC;
CRYPT_METHOD::_hashAlgorithm hashAlgorithm = CRYPT_METHOD::SHA1;
CRYPT_METHOD::_hashAlgorithm start_hashAlgorithm = CRYPT_METHOD::SHA1;
int start_hashSize = 20;
int spinCount = 100000;
int keySize = 0x10;
int hashSize = 0x14;
int saltSize = 0x10;
int spinCount = 1024;
int keySize = 16;
std::string saltValue;
std::string initializationVector;
std::string input;
std::string checksum;
int checksum_size = 1024;
CRYPT_METHOD::_hashAlgorithm checksum_hashAlgorithm = CRYPT_METHOD::SHA1;
@ -172,27 +171,17 @@ private:
bool bVerify;
};
class ODFDecryptor : public Decryptor
class ODFDecryptor
{
public:
ODFDecryptor();
virtual ~ODFDecryptor();
virtual void Init(const unsigned long val) {}
virtual void Decrypt (char* data, const size_t size, const unsigned long stream_pos, const size_t block_size){}
virtual void Decrypt (char* data, const size_t size, const unsigned long start_iv_block);
virtual bool SetPassword (std::wstring password);
virtual bool IsVerify();
void SetCryptData(_odfCryptData &data);
void Decrypt (unsigned char* data, int size, unsigned char*& data_out, unsigned long start_iv_block);
bool Decrypt (const std::wstring &wpassword, unsigned char* data_inp, int size_inp, unsigned char*& data_out, int &size_out);
private:
std::wstring password;
_odfCryptData cryptData;
bool bVerify;
};

View File

@ -282,7 +282,10 @@ void CInflate::Init()
{
inflateInit(&m_internal->m_stream);
}
void CInflate::Init2()
{
inflateInit2(&m_internal->m_stream,-MAX_WBITS);
}
int CInflate::Process(int flush)
{
return inflate(&m_internal->m_stream, flush);

View File

@ -121,6 +121,7 @@ public:
void ClearFuncs();
void Init();
void Init2();
int Process(int flush);
void End();
};

View File

@ -208,8 +208,8 @@
X2tConverter* conv = [[X2tConverter alloc]init];
conv.isNoBase64 = YES;
conv.delimiter = [X2tConverter delimiters].firstObject;
conv.encoding = [NSNumber numberWithInteger:46];
conv.delimiter = @(4);
conv.encoding = @(46);
int result = [conv sdk_csv2xlst_bin:fullFileName nsTo:fullFileNameTo nsFontPath:fontsPath];
if (result != 0) {
NSLog(@"ERROR OPEN CSV : %d",result);