Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
7886018d
Commit
7886018d
authored
May 31, 2017
by
ElenaSubbotina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oox file crypter
parent
5b5cb418
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
25 deletions
+111
-25
OfficeCryptReader/source/CryptTransform.cpp
OfficeCryptReader/source/CryptTransform.cpp
+90
-18
OfficeCryptReader/source/ECMACryptFile.cpp
OfficeCryptReader/source/ECMACryptFile.cpp
+6
-6
X2tConverter/src/ASCConverters.cpp
X2tConverter/src/ASCConverters.cpp
+15
-1
No files found.
OfficeCryptReader/source/CryptTransform.cpp
View file @
7886018d
...
...
@@ -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
);
CryptoPP
::
StringSource
(
plain
,
true
,
new
CryptoPP
::
HashFilter
(
hmac
,
new
CryptoPP
::
StringSink
(
mac
)
)
// HashFilter
);
// StringSource
//return _buf(mac.BytePtr(), mac.SizeInBytes());
}
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
//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
return
_buf
(
);
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
(
pSalt
Hmac
,
cryptData
.
hashAlgorithm
,
sData
);
_buf
pEncHmacKey
;
EncryptCipher
(
secretKey
,
iv1
,
pSalt
,
pEncHmacKey
,
cryptData
.
cipherAlgorithm
);
EncryptCipher
(
secretKey
,
iv1
,
pSalt
Hmac
,
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
);
...
...
OfficeCryptReader/source/ECMACryptFile.cpp
View file @
7886018d
...
...
@@ -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
::
SHA
256
;
cryptData
.
hashAlgorithm
=
CRYPT_METHOD
::
SHA
512
;
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
;
}
X2tConverter/src/ASCConverters.cpp
View file @
7886018d
...
...
@@ -1514,6 +1514,20 @@ 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
;
bool
bDataIntegrity
=
false
;
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 +1584,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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment