Compare commits

...

7 Commits

Author SHA1 Message Date
e9805cef30 PptxFormat - fix Ole object without image cash 2017-05-31 19:22:26 +03:00
e3e05eb2db test 2017-05-31 19:01:24 +03:00
c09f17cffb . 2017-05-31 17:56:45 +03:00
ce73dd5987 linux build error 2017-05-31 15:48:59 +03:00
77df8aacb9 . 2017-05-31 14:13:54 +03:00
ce45b2802f fix bug #34953 2017-05-31 13:46:49 +03:00
7886018d6f Oox file crypter 2017-05-31 12:35:27 +03:00
26 changed files with 165 additions and 81 deletions

View File

@ -1324,7 +1324,9 @@ namespace PPTX
}
if(oleObject->m_oId.IsInit())
{
blipFill.blip->oleRid = oleObject->m_oId.get().ToString();
if (blipFill.blip.IsInit() == false)
blipFill.blip.Init();
blipFill.blip->oleRid = oleObject->m_oId->get();
}
}
} // namespace Logic

View File

@ -221,7 +221,7 @@ int CELL_GROUP::serialize(std::wostream & stream)
CP_XML_ATTR(L"customFormat", true);
}
}
if (row->miyRw > 0/* && std::abs(row->miyRw/20. - sheet_info.defaultRowHeight) > 0.01*/)
if (row->miyRw > 0 && row->miyRw < 0x8000) //v8_14A_1b13.xls
{
CP_XML_ATTR(L"ht", row->miyRw / 20.);
CP_XML_ATTR(L"customHeight", true);

View File

@ -11,18 +11,7 @@ TEMPLATE = lib
CONFIG += staticlib
QMAKE_CXXFLAGS += -Wall -g
DEFINES += \
LIBXML_READER_ENABLED \
LIBXML_PUSH_ENABLED \
LIBXML_HTML_ENABLED \
LIBXML_XPATH_ENABLED \
LIBXML_OUTPUT_ENABLED \
LIBXML_C14N_ENABLED \
LIBXML_SAX1_ENABLED \
LIBXML_TREE_ENABLED \
LIBXML_XPTR_ENABLED \
IN_LIBXML \
LIBXML_STATIC
CONFIG += core_static_link_xml_full
CORE_ROOT_DIR = $$PWD/../../../..
PWD_ROOT_DIR = $$PWD

View File

@ -19,7 +19,8 @@ PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
INCLUDEPATH += \
$$PWD_ROOT_DIR/xmlsec/include
$$PWD_ROOT_DIR/xmlsec/include \
$$CORE_ROOT_DIR/DesktopEditor/xml/build/qt
DEFINES += \
LIBXML_READER_ENABLED \
@ -38,15 +39,15 @@ include($$CORE_ROOT_DIR/DesktopEditor/xml/build/qt/libxml2_src.pri)
DEFINES += PACKAGE=\\\"xmlsec1\\\"
DEFINES += VERSION=\\\"1.2.23\\\"
DEFINES += XMLSEC_DEFAULT_CRYPTO=\\\"mscrypto\\\"
DEFINES += XMLSEC_DEFAULT_CRYPTO=\\\"openssl\\\"
DEFINES += \
IN_XMLSEC \
XMLSEC_STATIC
core_linux {
CONFIG += use_gcrypt
CONFIG += use_gnutls
#CONFIG += use_gcrypt
#CONFIG += use_gnutls
#CONFIG += use_mscrypto
#CONFIG += use_nss
CONFIG += use_openssl
@ -246,6 +247,10 @@ SOURCES += \
use_openssl {
DEFINES += XMLSEC_OPENSSL_110
INCLUDEPATH += $$PWD/openssl/include
HEADERS += \
xmlsec/include/xmlsec/openssl/app.h \
xmlsec/include/xmlsec/openssl/bn.h \
@ -258,21 +263,21 @@ HEADERS += \
xmlsec/src/openssl/openssl11_wrapper.h
SOURCES += \
xmlsec/src/openssl/app.c \
xmlsec/src/openssl/bn.c \
xmlsec/src/openssl/ciphers.c \
xmlsec/src/openssl/crypto.c \
xmlsec/src/openssl/digests.c \
xmlsec/src/openssl/evp.c \
xmlsec/src/openssl/evp_signatures.c \
xmlsec/src/openssl/hmac.c \
xmlsec/src/openssl/kt_rsa.c \
xmlsec/src/openssl/kw_aes.c \
xmlsec/src/openssl/kw_des.c \
xmlsec/src/openssl/signatures.c \
xmlsec/src/openssl/symkeys.c \
xmlsec/src/openssl/x509.c \
xmlsec/src/openssl/x509vfy.c
xmlsec/src/openssl/_app.c \
xmlsec/src/openssl/_bn.c \
xmlsec/src/openssl/_ciphers.c \
xmlsec/src/openssl/_crypto.c \
xmlsec/src/openssl/_digests.c \
xmlsec/src/openssl/_evp.c \
xmlsec/src/openssl/_evp_signatures.c \
xmlsec/src/openssl/_hmac.c \
xmlsec/src/openssl/_kt_rsa.c \
xmlsec/src/openssl/_kw_aes.c \
xmlsec/src/openssl/_kw_des.c \
xmlsec/src/openssl/_signatures.c \
xmlsec/src/openssl/_symkeys.c \
xmlsec/src/openssl/_x509.c \
xmlsec/src/openssl/_x509vfy.c
}

View File

@ -174,7 +174,8 @@ public:
return;
}
std::wstring sSetupID = FindFirstChild(GetObjectById("idOfficeObject"), L"SetupID").GetText();
XmlUtils::CXmlNode firstChild = GetObjectById("idOfficeObject");
std::wstring sSetupID = FindFirstChild(firstChild, L"SetupID").GetText();
m_guid = U_TO_UTF8(sSetupID);
// 2) Images

View File

@ -42,6 +42,8 @@
#include <xmlsec/templates.h>
#include <xmlsec/crypto.h>
#include "../../../common/File.h"
int sign_file(const char* xml_file, const char* key_file, const char* cert_file);
int
@ -50,13 +52,11 @@ main(int argc, char **argv) {
xsltSecurityPrefsPtr xsltSecPrefs = NULL;
#endif /* XMLSEC_NO_XSLT */
assert(argv);
if(argc != 4) {
fprintf(stderr, "Error: wrong number of arguments.\n");
fprintf(stderr, "Usage: %s <xml-file> <key-file> <cert-file>\n", argv[0]);
return(1);
}
std::wstring sFolderW = NSFile::GetProcessDirectory();
std::string sFolder = U_TO_UTF8(sFolderW);
std::string __file = sFolder + "/settings.xml";
std::string __key = sFolder + "/rsakey.pem";
std::string __cert = sFolder + "/rsacert.pem";
/* Init libxml and libxslt libraries */
xmlInitParser();
@ -117,7 +117,7 @@ main(int argc, char **argv) {
return(-1);
}
if(sign_file(argv[1], argv[2], argv[3]) < 0) {
if(sign_file(__file.c_str(), __key.c_str(), __cert.c_str()) < 0) {
return(-1);
}

View File

@ -15,7 +15,7 @@ PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
#DEFINES += XMLSEC_CRYPTO_DYNAMIC_LOADING
DEFINES += XMLSEC_CRYPTO_MSCRYPTO
DEFINES += XMLSEC_CRYPTO_OPENSSL
INCLUDEPATH += \
$$CORE_ROOT_DIR/DesktopEditor/xml/libxml2/include \
@ -40,8 +40,8 @@ DEFINES += XMLSEC_STATIC
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -llibxmlsec
LIBS += -lcrypt32
LIBS += -lcryptui
LIBS += -lAdvapi32
LIBS += -L$$PWD/../../openssl -lcrypto -lssl
LIBS += -ldl
SOURCES += main.cpp

View File

@ -177,34 +177,40 @@ void CorrectHashSize(_buf & hashBuf, int size, unsigned char padding)
}
_buf Hmac(_buf & buf, CRYPT_METHOD::_hashAlgorithm algorithm, std::string & plain)
{
std::string mac;
if (algorithm == CRYPT_METHOD::SHA1)
{
CryptoPP::HMAC<CryptoPP::SHA1> hmac(buf.ptr, buf.size);
//return _buf(mac.BytePtr(), mac.SizeInBytes());
}
else if (algorithm == CRYPT_METHOD::SHA256)
{
CryptoPP::HMAC<CryptoPP::SHA256> hmac(buf.ptr, buf.size);
//return _buf(mac.BytePtr(), mac.SizeInBytes());
}
else if (algorithm == CRYPT_METHOD::SHA512)
{
CryptoPP::HMAC<CryptoPP::SHA512> hmac(buf.ptr, buf.size);
std::string mac;
CryptoPP::StringSource(plain, true,
new CryptoPP::HashFilter(hmac,
new CryptoPP::StringSink(mac)
) // HashFilter
); // StringSource
return _buf(mac);
}
else if (algorithm == CRYPT_METHOD::SHA256)
{
CryptoPP::HMAC<CryptoPP::SHA256> hmac(buf.ptr, buf.size);
CryptoPP::StringSource(plain, true,
new CryptoPP::HashFilter(hmac,
new CryptoPP::StringSink(mac)
) // HashFilter
); // StringSource
}
//else
return _buf();
else if (algorithm == CRYPT_METHOD::SHA512)
{
CryptoPP::HMAC<CryptoPP::SHA512> hmac(buf.ptr, buf.size);
CryptoPP::StringSource(plain, true,
new CryptoPP::HashFilter(hmac,
new CryptoPP::StringSink(mac)
) // HashFilter
); // StringSource
}
return _buf(mac);
}
@ -516,14 +522,14 @@ bool ECMADecryptor::CheckDataIntegrity(unsigned char* data, int size)
_buf iv2 = HashAppend(pDataSalt, pBlockHmacValue, cryptData.hashAlgorithm);
CorrectHashSize(iv2, cryptData.blockSize, 0x36);
_buf salt;
DecryptCipher(secretKey, iv1, pEncHmacKey, salt, cryptData.cipherAlgorithm);
_buf pSaltHmac;
DecryptCipher(secretKey, iv1, pEncHmacKey, pSaltHmac, cryptData.cipherAlgorithm);
_buf expected;
DecryptCipher(secretKey, iv2, pEncHmacValue, expected, cryptData.cipherAlgorithm);
std::string sData((char*)data, size);
_buf hmac = Hmac(salt, cryptData.hashAlgorithm, sData);
_buf hmac = Hmac(pSaltHmac, cryptData.hashAlgorithm, sData);
return (hmac == expected);
}
@ -612,6 +618,65 @@ ECMAEncryptor::ECMAEncryptor()
void ECMAEncryptor::SetPassword(std::wstring _password)
{
password = _password;
//---------
CryptoPP::RandomPool prng;
//сгенерить соль
CryptoPP::SecByteBlock seed_salt(cryptData.saltSize);
CryptoPP::OS_GenerateRandomBlock(false, seed_salt, seed_salt.size());
prng.IncorporateEntropy(seed_salt, seed_salt.size());
CryptoPP::SecByteBlock seed_datasalt(cryptData.saltSize);
CryptoPP::OS_GenerateRandomBlock(false, seed_datasalt, seed_datasalt.size());
prng.IncorporateEntropy(seed_datasalt, seed_datasalt.size());
//сгенерить ключ
CryptoPP::SecByteBlock seed_key(cryptData.keySize);
CryptoPP::OS_GenerateRandomBlock(false, seed_key, seed_key.size());
prng.IncorporateEntropy(seed_key, seed_key.size());
//сгенерить проверочный
CryptoPP::SecByteBlock seed_verify(cryptData.saltSize);
CryptoPP::OS_GenerateRandomBlock(false, seed_verify, seed_verify.size());
prng.IncorporateEntropy(seed_verify, seed_verify.size());
//---------
_buf pPassword (password);
_buf empty (NULL, 0, false);
_buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8);
_buf pInputBlockKey ((unsigned char*)encrVerifierHashInputBlockKey, 8);
_buf pValueBlockKey ((unsigned char*)encrVerifierHashValueBlockKey, 8);
_buf pSalt (seed_salt.m_ptr, seed_salt.m_size);
_buf pDataSalt (seed_datasalt.m_ptr, seed_datasalt.m_size);
_buf pDecryptedKey (seed_key.m_ptr, seed_key.m_size);
//------------------------------------------------------------------------------------------------
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf pKeyValue;
EncryptCipher( agileKey, pSalt, pDecryptedKey, pKeyValue, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf decryptedVerifierHashInputBytes(seed_verify.m_ptr, seed_verify.m_size);
_buf verifierInputKey = GenerateAgileKey( pSalt, pPassword, pInputBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm );
_buf pEncVerInput;
EncryptCipher( verifierInputKey, pSalt, decryptedVerifierHashInputBytes, pEncVerInput, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf decryptedVerifierHashBytes = HashAppend(decryptedVerifierHashInputBytes, empty, cryptData.hashAlgorithm);
_buf verifierHashKey = GenerateAgileKey(pSalt, pPassword, pValueBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf pEncVerValue;
EncryptCipher( verifierHashKey, pSalt, decryptedVerifierHashBytes, pEncVerValue, cryptData.cipherAlgorithm);
cryptData.saltValue = std::string((char*)pSalt.ptr, pSalt.size);
cryptData.dataSaltValue = std::string((char*)pDataSalt.ptr, pDataSalt.size);
cryptData.encryptedKeyValue = std::string((char*)pKeyValue.ptr, pKeyValue.size);
cryptData.encryptedVerifierInput = std::string((char*)pEncVerInput.ptr, pEncVerInput.size);
cryptData.encryptedVerifierValue = std::string((char*)pEncVerValue.ptr, pEncVerValue.size);
}
void ECMAEncryptor::SetCryptData(_ecmaCryptData & data)
@ -639,6 +704,7 @@ void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size)
_buf pDataSalt (cryptData.dataSaltValue);
_buf pKeyValue (cryptData.encryptedKeyValue);
//----
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf secretKey;
@ -651,11 +717,19 @@ void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size)
CorrectHashSize(iv2, cryptData.blockSize, 0x36);
//----
CryptoPP::RandomPool prng;
CryptoPP::SecByteBlock seed(cryptData.hashSize);
CryptoPP::OS_GenerateRandomBlock(false, seed, seed.size());
prng.IncorporateEntropy(seed, seed.size());
_buf pSaltHmac(seed.m_ptr, seed.m_size);
std::string sData((char*)data, size);
_buf hmac = Hmac(pSalt, cryptData.hashAlgorithm, sData);
_buf hmac = Hmac(pSaltHmac, cryptData.hashAlgorithm, sData);
_buf pEncHmacKey;
EncryptCipher(secretKey, iv1, pSalt, pEncHmacKey, cryptData.cipherAlgorithm);
EncryptCipher(secretKey, iv1, pSaltHmac, pEncHmacKey, cryptData.cipherAlgorithm);
_buf pEncHmacValue;
EncryptCipher(secretKey, iv2, hmac, pEncHmacValue, cryptData.cipherAlgorithm);
@ -689,19 +763,17 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
_buf pKeyValue (cryptData.encryptedKeyValue);
//------------------------------------------------------------------------------------------------
//соль нужно сгенерить
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
//тут нужно именно дешифрованый генерить - пока их файла берем
_buf pDecryptedKey;
DecryptCipher( agileKey, pSalt, pKeyValue, pDecryptedKey, cryptData.cipherAlgorithm);
//зашифровать ключь
_buf pEncryptedKey;
EncryptCipher( agileKey, pSalt, pDecryptedKey, pEncryptedKey, cryptData.cipherAlgorithm);
////зашифровать ключь
//_buf pEncryptedKey;
//EncryptCipher( agileKey, pSalt, pDecryptedKey, pEncryptedKey, cryptData.cipherAlgorithm);
//??? pEncryptedKey == pKeyValue;
////??? pEncryptedKey == pKeyValue;
//-------------------------------------------------------------------------------------------------
_buf iv(cryptData.blockSize);

View File

@ -42,7 +42,7 @@
#include "../../ASCOfficeDocFile/DocDocxConverter/MemoryStream.h"
#include "simple_xml_writer.h"
CRYPT::_ecmaCryptData cryptDataGlobal;
//CRYPT::_ecmaCryptData cryptDataGlobal; for Test
using namespace CRYPT;
@ -489,19 +489,19 @@ bool ECMACryptFile::EncryptOfficeFile(std::wstring file_name_inp, std::wstring f
_ecmaCryptData cryptData;
cryptData.bAgile = true;
cryptData.hashAlgorithm = CRYPT_METHOD::SHA256;
cryptData.hashAlgorithm = CRYPT_METHOD::SHA512;
cryptData.keySize = 0x20;
cryptData.hashSize = 0x40;
cryptData.blockSize = 0x10;
cryptData.saltSize = 0x10;
ECMAEncryptor cryptor;
//cryptor.SetCryptData(cryptDataGlobal); //for test !!!
cryptor.SetCryptData(cryptData); //basic settings
cryptor.SetPassword(password);
cryptor.SetCryptData(cryptDataGlobal); //for test !!!
//cryptor.SetCryptData(cryptData); //basic settings
NSFile::CFileBinary file;
if (!file.OpenFile(file_name_inp)) return false;
@ -737,7 +737,7 @@ bool ECMACryptFile::DecryptOfficeFile(std::wstring file_name_inp, std::wstring f
//-------------------------------------------------------------------
delete pStorage;
cryptDataGlobal = cryptData; // for encrypt like sample
//cryptDataGlobal = cryptData; // for encrypt like sample & test
return result;
}

View File

@ -1514,6 +1514,19 @@ namespace NExtractTools
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
int oox2mscrypt (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params)
{
std::wstring password = params.getPassword();
ECMACryptFile cryptReader;
if (cryptReader.EncryptOfficeFile(sFrom, sTo, password) == false)
{
return AVS_FILEUTILS_ERROR_CONVERT;
}
return S_OK;
}
int fromMscrypt (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params)
{
std::wstring password = params.getPassword();
@ -1570,7 +1583,7 @@ namespace NExtractTools
}
return nRes;
}
//html
//html
int html2doct_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
std::vector<std::wstring> arFiles;

View File

@ -128,6 +128,8 @@ namespace NExtractTools
int mscrypt2oox (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params);
int mscrypt2oot (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params);
int mscrypt2oot_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params);
int oox2mscrypt (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params);
//-------------------------------------------------------------------------------------------------------------------------------------------------
int dir2zip (const std::wstring &sFrom, const std::wstring &sTo);