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
036c3b37
Commit
036c3b37
authored
Dec 26, 2016
by
ElenaSubbotina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XlsFormatReader - decrypter ...
parent
dddaeb3e
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
126 additions
and
126 deletions
+126
-126
ASCOfficeXlsFile2/ASCOfficeXlsFileTest/ASCOfficeXlsFileTest.cpp
...iceXlsFile2/ASCOfficeXlsFileTest/ASCOfficeXlsFileTest.cpp
+1
-1
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.cpp
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.cpp
+5
-5
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.h
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.h
+3
-5
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.cpp
...XlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.cpp
+13
-14
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.h
...ceXlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.h
+1
-2
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/EncryptionHeader.h
...source/XlsFormat/Logic/Biff_structures/EncryptionHeader.h
+6
-7
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/EncryptionHeaderFlags.h
...e/XlsFormat/Logic/Biff_structures/EncryptionHeaderFlags.h
+0
-1
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/EncryptionVerifier.h
...urce/XlsFormat/Logic/Biff_structures/EncryptionVerifier.h
+0
-1
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.cpp
...e/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.cpp
+7
-25
ASCOfficeXlsFile2/source/XlsFormat/Logic/GlobalWorkbookInfo.h
...fficeXlsFile2/source/XlsFormat/Logic/GlobalWorkbookInfo.h
+1
-1
ASCOfficeXlsFile2/source/XlsFormat/Logic/GlobalsSubstream.cpp
...fficeXlsFile2/source/XlsFormat/Logic/GlobalsSubstream.cpp
+1
-32
ASCOfficeXlsFile2/source/XlsFormat/Logic/WorkbookStreamObject.cpp
...eXlsFile2/source/XlsFormat/Logic/WorkbookStreamObject.cpp
+1
-0
ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp
ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp
+5
-10
ASCOfficeXlsFile2/source/win32/XlsXlsxConverter.vcproj
ASCOfficeXlsFile2/source/win32/XlsXlsxConverter.vcproj
+0
-4
OfficeCryptReader/source/CryptTransform.cpp
OfficeCryptReader/source/CryptTransform.cpp
+69
-13
OfficeCryptReader/source/CryptTransform.h
OfficeCryptReader/source/CryptTransform.h
+13
-5
No files found.
ASCOfficeXlsFile2/ASCOfficeXlsFileTest/ASCOfficeXlsFileTest.cpp
View file @
036c3b37
...
@@ -55,7 +55,7 @@ int _tmain(int argc, _TCHAR* argv[])
...
@@ -55,7 +55,7 @@ int _tmain(int argc, _TCHAR* argv[])
std
::
wstring
outputDir
=
FileSystem
::
Directory
::
GetFolderPath
(
dstPath
);
std
::
wstring
outputDir
=
FileSystem
::
Directory
::
GetFolderPath
(
dstPath
);
std
::
wstring
dstTempPath
=
FileSystem
::
Directory
::
CreateDirectoryWithUniqueName
(
outputDir
);
std
::
wstring
dstTempPath
=
FileSystem
::
Directory
::
CreateDirectoryWithUniqueName
(
outputDir
);
hr
=
ConvertXls2Xlsx
(
srcFileName
,
dstTempPath
,
L""
,
L"C:
\\
Windows
\\
Fonts"
,
NULL
);
hr
=
ConvertXls2Xlsx
(
srcFileName
,
dstTempPath
,
L"
password
"
,
L"C:
\\
Windows
\\
Fonts"
,
NULL
);
if
(
hr
==
S_OK
)
if
(
hr
==
S_OK
)
{
{
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.cpp
View file @
036c3b37
...
@@ -37,11 +37,11 @@
...
@@ -37,11 +37,11 @@
namespace
CRYPT
namespace
CRYPT
{
{
RC4Decryptor
::
RC4Decryptor
(
CryptRC4Data
&
header
,
std
::
wstring
password
,
int
type
)
:
RC4Decryptor
::
RC4Decryptor
(
CryptRC4Data
&
header
,
std
::
wstring
_password
,
int
_type
)
:
crypt
(
new
RC4Crypt
(
header
,
password
,
type
)),
crypt
(
new
RC4Crypt
(
header
,
_password
,
_type
))
type
(
Crypt
::
RC4
)
{
{
crypt_data
=
header
;
crypt_data
=
header
;
type
=
_type
;
}
}
void
RC4Decryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
void
RC4Decryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
...
@@ -54,7 +54,7 @@ namespace CRYPT
...
@@ -54,7 +54,7 @@ namespace CRYPT
return
crypt
->
IsVerify
();
return
crypt
->
IsVerify
();
}
}
bool
RC4Decryptor
::
SetPassword
(
std
::
wstring
password
,
int
type
)
bool
RC4Decryptor
::
SetPassword
(
std
::
wstring
password
)
{
{
crypt
.
reset
();
crypt
.
reset
();
crypt
=
CryptPtr
(
new
RC4Crypt
(
crypt_data
,
password
,
type
));
crypt
=
CryptPtr
(
new
RC4Crypt
(
crypt_data
,
password
,
type
));
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.h
View file @
036c3b37
...
@@ -43,18 +43,16 @@ namespace CRYPT
...
@@ -43,18 +43,16 @@ namespace CRYPT
RC4Decryptor
(
CryptRC4Data
&
header
,
std
::
wstring
password
,
int
type
);
RC4Decryptor
(
CryptRC4Data
&
header
,
std
::
wstring
password
,
int
type
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
);
virtual
bool
SetPassword
(
std
::
wstring
password
);
bool
IsVerify
();
virtual
bool
IsVerify
();
bool
SetPassword
(
std
::
wstring
password
,
int
type
=
1
);
private:
private:
int
type
;
CryptPtr
crypt
;
CryptPtr
crypt
;
Crypt
::
crypt_type
type
;
CryptRC4Data
crypt_data
;
CryptRC4Data
crypt_data
;
};
};
typedef
boost
::
shared_ptr
<
RC4Decryptor
>
RC4DecryptorPtr
;
typedef
boost
::
shared_ptr
<
RC4Decryptor
>
RC4DecryptorPtr
;
}
// namespace CRYPT
}
// namespace CRYPT
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.cpp
View file @
036c3b37
...
@@ -70,27 +70,26 @@ void FilePass::readFields(CFRecord& record)
...
@@ -70,27 +70,26 @@ void FilePass::readFields(CFRecord& record)
majorVer
=
*
record
.
getCurData
<
unsigned
short
>
();
majorVer
=
*
record
.
getCurData
<
unsigned
short
>
();
rc4
HeaderPtr
=
CRYPTO
::
RC4EncryptionHeaderPtr
(
new
CRYPTO
::
RC4EncryptionHeader
());
crypt
HeaderPtr
=
CRYPTO
::
RC4EncryptionHeaderPtr
(
new
CRYPTO
::
RC4EncryptionHeader
());
rc4HeaderPtr
->
bStandard
=
0x0001
==
majorVer
?
true
:
false
;
// _S2dvT1xU_R3bOPwre4_.xls
cryptHeaderPtr
->
bStandard
=
0x0001
==
majorVer
?
true
:
false
;
// _S2dvT1xU_R3bOPwre4_.xls
rc4HeaderPtr
->
load
(
record
);
if
(
rc4HeaderPtr
->
bStandard
)
cryptHeaderPtr
->
load
(
record
);
if
(
cryptHeaderPtr
->
bStandard
)
{
{
record
.
getGlobalWorkbookInfo
()
->
decryptor
=
record
.
getGlobalWorkbookInfo
()
->
decryptor
=
CRYPT
::
RC4DecryptorPtr
(
new
CRYPT
::
RC4Decryptor
(
rc4
HeaderPtr
->
crypt_data_rc4
,
record
.
getGlobalWorkbookInfo
()
->
password
,
2
));
CRYPT
::
DecryptorPtr
(
new
CRYPT
::
RC4Decryptor
(
crypt
HeaderPtr
->
crypt_data_rc4
,
record
.
getGlobalWorkbookInfo
()
->
password
,
2
));
}
}
else
else
{
{
//CRYPT::ECMADecryptor Decryptor;
record
.
getGlobalWorkbookInfo
()
->
decryptor
=
CRYPT
::
DecryptorPtr
(
new
CRYPT
::
ECMADecryptor
());
//Decryptor.SetCryptData(rc4HeaderPtr->crypt_data_aes
);
CRYPT
::
ECMADecryptor
*
crypter
=
dynamic_cast
<
CRYPT
::
ECMADecryptor
*>
(
record
.
getGlobalWorkbookInfo
()
->
decryptor
.
get
()
);
//if (Decryptor.SetPassword(L"VelvetSweatshop") == false)
crypter
->
SetCryptData
(
cryptHeaderPtr
->
crypt_data_aes
);
//{
crypter
->
SetPassword
(
record
.
getGlobalWorkbookInfo
()
->
password
);
//}
// //record.getGlobalWorkbookInfo()->decryptor =
// //CRYPT::ECMADecryptor(new CRYPT::RC4Decryptor(rc4HeaderPtr->crypt_data_rc4, record.getGlobalWorkbookInfo()->password, 2));
}
}
}
}
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.h
View file @
036c3b37
...
@@ -60,8 +60,7 @@ public:
...
@@ -60,8 +60,7 @@ public:
XORObfuscation
key
;
XORObfuscation
key
;
_UINT16
majorVer
;
_UINT16
majorVer
;
CRYPTO
::
RC4EncryptionHeaderPtr
rc4HeaderPtr
;
CRYPTO
::
RC4EncryptionHeaderPtr
cryptHeaderPtr
;
CRYPTO
::
RC4CryptoAPIEncryptionHeader
rc4CryptoAPIHeader
;
};
};
}
// namespace XLS
}
// namespace XLS
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/EncryptionHeader.h
View file @
036c3b37
...
@@ -49,7 +49,6 @@ public:
...
@@ -49,7 +49,6 @@ public:
virtual
void
load
(
XLS
::
CFRecord
&
record
);
virtual
void
load
(
XLS
::
CFRecord
&
record
);
EncryptionHeaderFlags
Flags
;
EncryptionHeaderFlags
Flags
;
_INT32
AlgID
;
_INT32
AlgID
;
_INT32
AlgIDHash
;
_INT32
AlgIDHash
;
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/EncryptionHeaderFlags.h
View file @
036c3b37
...
@@ -50,7 +50,6 @@ public:
...
@@ -50,7 +50,6 @@ public:
virtual
void
load
(
XLS
::
CFRecord
&
record
);
virtual
void
load
(
XLS
::
CFRecord
&
record
);
bool
fCryptoAPI
;
bool
fCryptoAPI
;
bool
fDocProps
;
bool
fDocProps
;
bool
fExternal
;
bool
fExternal
;
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/EncryptionVerifier.h
View file @
036c3b37
...
@@ -48,7 +48,6 @@ public:
...
@@ -48,7 +48,6 @@ public:
virtual
void
load
(
XLS
::
CFRecord
&
record
);
virtual
void
load
(
XLS
::
CFRecord
&
record
);
_UINT32
SaltSize
;
_UINT32
SaltSize
;
struct
SALT_TAG
struct
SALT_TAG
{
{
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.cpp
View file @
036c3b37
...
@@ -65,8 +65,9 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
...
@@ -65,8 +65,9 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
bool
fExternal
=
GETBIT
(
flags
,
3
);
bool
fExternal
=
GETBIT
(
flags
,
3
);
bool
fAES
=
GETBIT
(
flags
,
4
);
bool
fAES
=
GETBIT
(
flags
,
4
);
record
>>
flags
;
unsigned
short
Reserved3
;
//EncryptionHeader
record
>>
Reserved3
;
_UINT32
HeaderSize
;
record
>>
HeaderSize
;
_UINT32
HeaderSize
;
record
>>
HeaderSize
;
_UINT32
Flags
;
record
>>
Flags
;
_UINT32
Flags
;
record
>>
Flags
;
_UINT32
SizeExtra
;
record
>>
SizeExtra
;
_UINT32
SizeExtra
;
record
>>
SizeExtra
;
...
@@ -80,19 +81,9 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
...
@@ -80,19 +81,9 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
int
pos
=
record
.
getRdPtr
();
int
pos
=
record
.
getRdPtr
();
int
size
=
record
.
getDataSize
();
int
size
=
record
.
getDataSize
();
std
::
vector
<
char
>
dataCSPName
;
std
::
wstring
providerName
;
while
(
pos
<
size
-
1
)
record
>>
providerName
;
{
char
s
;
record
>>
s
;
dataCSPName
.
push_back
(
s
);
record
>>
s
;
dataCSPName
.
push_back
(
s
);
if
(
dataCSPName
[
dataCSPName
.
size
()
-
1
]
==
0
&&
dataCSPName
[
dataCSPName
.
size
()
-
2
]
==
0
)
{
break
;
}
pos
+=
2
;
//unicode null-terminate string
}
//EncryptionVerifier
//EncryptionVerifier
record
>>
crypt_data_aes
.
saltSize
;
record
>>
crypt_data_aes
.
saltSize
;
...
@@ -134,7 +125,7 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
...
@@ -134,7 +125,7 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
pos
=
record
.
getRdPtr
();
pos
=
record
.
getRdPtr
();
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
crypt_data_aes
.
hashAlgorithm
=
CRYPT_METHOD
::
SHA1
;
//by AlgIDHash -> 0x0000
|| 0x8004
crypt_data_aes
.
hashAlgorithm
=
CRYPT_METHOD
::
SHA1
;
//by AlgIDHash -> 0x0000
(reserved ??) || 0x8004(sha1)
crypt_data_aes
.
spinCount
=
50000
;
crypt_data_aes
.
spinCount
=
50000
;
switch
(
AlgID
)
switch
(
AlgID
)
...
@@ -162,15 +153,6 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
...
@@ -162,15 +153,6 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
case
0x0001
:
crypt_data_aes
.
cipherAlgorithm
=
CRYPT_METHOD
::
RC4
;
break
;
case
0x0001
:
crypt_data_aes
.
cipherAlgorithm
=
CRYPT_METHOD
::
RC4
;
break
;
case
0x0018
:
crypt_data_aes
.
cipherAlgorithm
=
CRYPT_METHOD
::
AES_ECB
;
break
;
case
0x0018
:
crypt_data_aes
.
cipherAlgorithm
=
CRYPT_METHOD
::
AES_ECB
;
break
;
}
}
if
(
crypt_data_aes
.
cipherAlgorithm
==
CRYPT_METHOD
::
RC4
)
{
bStandard
=
true
;
memcpy
(
&
crypt_data_rc4
.
Salt
,
crypt_data_aes
.
saltValue
.
c_str
(),
16
);
memcpy
(
&
crypt_data_rc4
.
EncryptedVerifier
,
crypt_data_aes
.
encryptedVerifierValue
.
c_str
(),
16
);
memcpy
(
&
crypt_data_rc4
.
EncryptedVerifierHash
,
crypt_data_aes
.
encryptedVerifierInput
.
c_str
(),
16
);
}
}
}
}
}
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/GlobalWorkbookInfo.h
View file @
036c3b37
...
@@ -77,7 +77,7 @@ public:
...
@@ -77,7 +77,7 @@ public:
unsigned
short
CodePage
;
unsigned
short
CodePage
;
CRYPT
::
RC4DecryptorPtr
decryptor
;
CRYPT
::
DecryptorPtr
decryptor
;
std
::
wstring
password
;
std
::
wstring
password
;
std
::
vector
<
std
::
wstring
>
sheets_state
;
std
::
vector
<
std
::
wstring
>
sheets_state
;
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/GlobalsSubstream.cpp
View file @
036c3b37
...
@@ -151,37 +151,6 @@ BaseObjectPtr GlobalsSubstream::clone()
...
@@ -151,37 +151,6 @@ BaseObjectPtr GlobalsSubstream::clone()
return
BaseObjectPtr
(
new
GlobalsSubstream
(
*
this
));
return
BaseObjectPtr
(
new
GlobalsSubstream
(
*
this
));
}
}
// class Parenthesis_Window1_Backup_HideObj_Date1904 : public ABNFParenthesis
// {
// public:
// BaseObjectPtr clone()
// {
// return BaseObjectPtr(new Parenthesis_OO_order_workaround_1(*this));
// }
//
// const bool loadContent(BinProcessor& proc)
// {
// if(!proc.mandatory<SXAddl_SXCCacheField_SXDCaption>())
// {
// return false;
// }
// proc.repeated<Continue_SxaddlSxString>(0, 0);
// return true;
// };
// };
//
/*
WORKBOOKCONTENT = [WriteProtect] [FilePass] [Template] INTERFACE WriteAccess [FileSharing] CodePage
*2047Lel DSF [Excel9File] RRTabId [ObProj] [ObNoMacros] [CodeName [FNGROUPS] *Lbl
[OleObjectSize] PROTECTION 1*Window1 Backup HideObj Date1904 CalcPrecision RefreshAll
BookBool FORMATTING *(PIVOTCACHEDEFINITION) [DOCROUTE] *UserBView UsesELFs 1*BUNDLESHEET
METADATA [MTRSettings] [ForceFullCalculation] Country *SUPBOOK *LBL *RTD [RecalcId]
*HFPicture *MSODRAWINGGROUP [SHAREDSTRINGS] ExtSST *WebPub [WOpt] [CrErr] [BookExt]
*FeatHdr *DConn [THEME] [CompressPictures] [Compat12] [GUIDTypeLib] EOF
WORKBOOK = BOF WORKBOOKCONTENT
*/
const
bool
GlobalsSubstream
::
loadContent
(
BinProcessor
&
proc
)
const
bool
GlobalsSubstream
::
loadContent
(
BinProcessor
&
proc
)
{
{
int
count
=
0
;
int
count
=
0
;
...
@@ -229,7 +198,7 @@ const bool GlobalsSubstream::loadContent(BinProcessor& proc)
...
@@ -229,7 +198,7 @@ const bool GlobalsSubstream::loadContent(BinProcessor& proc)
if
((
proc
.
getGlobalWorkbookInfo
()
->
decryptor
)
&&
if
((
proc
.
getGlobalWorkbookInfo
()
->
decryptor
)
&&
(
proc
.
getGlobalWorkbookInfo
()
->
decryptor
->
IsVerify
()
==
false
))
(
proc
.
getGlobalWorkbookInfo
()
->
decryptor
->
IsVerify
()
==
false
))
{
{
if
(
!
proc
.
getGlobalWorkbookInfo
()
->
decryptor
->
SetPassword
(
L"VelvetSweatshop"
,
2
))
if
(
!
proc
.
getGlobalWorkbookInfo
()
->
decryptor
->
SetPassword
(
L"VelvetSweatshop"
))
return
false
;
return
false
;
}
}
}
}
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/WorkbookStreamObject.cpp
View file @
036c3b37
...
@@ -105,6 +105,7 @@ const bool WorkbookStreamObject::loadContent(BinProcessor& proc)
...
@@ -105,6 +105,7 @@ const bool WorkbookStreamObject::loadContent(BinProcessor& proc)
m_GlobalsSubstream
=
elements_
.
back
();
m_GlobalsSubstream
=
elements_
.
back
();
elements_
.
pop_back
();
elements_
.
pop_back
();
}
}
if
(
!
GlobalsSubstream_found
)
return
false
;
}
}
break
;
break
;
case
BOF
:
:
st_Worksheet
:
case
BOF
:
:
st_Worksheet
:
...
...
ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp
View file @
036c3b37
...
@@ -203,7 +203,6 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
...
@@ -203,7 +203,6 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
xls_document
=
boost
::
shared_ptr
<
XLS
::
WorkbookStreamObject
>
(
new
XLS
::
WorkbookStreamObject
(
workbook_code_page
));
xls_document
=
boost
::
shared_ptr
<
XLS
::
WorkbookStreamObject
>
(
new
XLS
::
WorkbookStreamObject
(
workbook_code_page
));
XLS
::
BinReaderProcessor
proc
(
stream_reader
,
xls_document
.
get
()
,
true
);
XLS
::
BinReaderProcessor
proc
(
stream_reader
,
xls_document
.
get
()
,
true
);
proc
.
mandatory
(
*
xls_document
.
get
());
proc
.
mandatory
(
*
xls_document
.
get
());
...
@@ -211,7 +210,6 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
...
@@ -211,7 +210,6 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
{
{
is_encrypted
=
true
;
is_encrypted
=
true
;
if
(
xls_global_info
->
decryptor
->
IsVerify
()
==
false
)
return
;
if
(
xls_global_info
->
decryptor
->
IsVerify
()
==
false
)
return
;
}
}
}
}
catch
(...)
catch
(...)
...
@@ -225,10 +223,7 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
...
@@ -225,10 +223,7 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
std
::
wstring
sVer
=
STR
::
int2hex_wstr
(
xls_global_info
->
Version
);
std
::
wstring
sVer
=
STR
::
int2hex_wstr
(
xls_global_info
->
Version
);
Log
::
error
(
"Version xls is old !!! - "
+
std
::
string
(
sVer
.
begin
(),
sVer
.
end
()));
Log
::
error
(
"Version xls is old !!! - "
+
std
::
string
(
sVer
.
begin
(),
sVer
.
end
()));
is_older_version
=
true
;
is_older_version
=
true
;
//return;
}
}
output_document
=
new
oox
::
package
::
xlsx_document
();
output_document
=
new
oox
::
package
::
xlsx_document
();
xlsx_context
=
new
oox
::
xlsx_conversion_context
(
output_document
);
xlsx_context
=
new
oox
::
xlsx_conversion_context
(
output_document
);
}
}
...
...
ASCOfficeXlsFile2/source/win32/XlsXlsxConverter.vcproj
View file @
036c3b37
...
@@ -288,10 +288,6 @@
...
@@ -288,10 +288,6 @@
RelativePath=
"..\common\simple_xml_writer.h"
RelativePath=
"..\common\simple_xml_writer.h"
>
>
</File>
</File>
<File
RelativePath=
"..\..\..\Common\DocxFormat\Source\XML\stringcommon.cpp"
>
</File>
<File
<File
RelativePath=
"..\common\utils.cpp"
RelativePath=
"..\common\utils.cpp"
>
>
...
...
OfficeCryptReader/source/CryptTransform.cpp
View file @
036c3b37
...
@@ -38,8 +38,14 @@
...
@@ -38,8 +38,14 @@
#include "../../Common/3dParty/cryptopp/aes.h"
#include "../../Common/3dParty/cryptopp/aes.h"
#include "../../Common/3dParty/cryptopp/sha.h"
#include "../../Common/3dParty/cryptopp/sha.h"
#include "../../Common/3dParty/cryptopp/md5.h"
#include "../../Common/3dParty/cryptopp/md5.h"
#include "../../Common/3dParty/cryptopp/rsa.h"
#include "../../Common/3dParty/cryptopp/rc2.h"
#include "../../Common/3dParty/cryptopp/arc4.h"
#include "../../Common/3dParty/cryptopp/rc5.h"
#include "../../Common/3dParty/cryptopp/pwdbased.h"
#include "../../Common/3dParty/cryptopp/pwdbased.h"
#include "../../Common/3dParty/cryptopp/filters.h"
#include "../../Common/3dParty/cryptopp/filters.h"
#include "../../Common/3dParty/cryptopp/osrng.h"
#include "../../Common/3dParty/cryptopp/hex.h"
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
#include "../../Common/DocxFormat/Source/Base/unicode_util.h"
...
@@ -266,11 +272,47 @@ bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYP
...
@@ -266,11 +272,47 @@ bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYP
{
{
if
(
algorithm
==
CRYPT_METHOD
::
RC4
)
if
(
algorithm
==
CRYPT_METHOD
::
RC4
)
{
{
//CryptoPP::ARC4 rc4(key.ptr, key.size);
//data_out.ptr = new unsigned char[data_inp.size];
//data_out.size = data_inp.size;
//rc4.ProcessData(data_out.ptr, data_inp.ptr, data_inp.size);
//CryptoPP::RC2::Decryption rc2Decryption(key.ptr, key.size);
//modeDecryption = new CryptoPP::ECB_Mode_ExternalCipher::Decryption(rc2Decryption, iv.ptr );
//CryptoPP::RC5::Decryption rc5Decryption(key.ptr, key.size);
//modeDecryption = new CryptoPPp::ECB_Mode_ExternalCipher::Decryption(rc5Decryption, iv.ptr );
//rsa aes
//CryptoPP::HexDecoder buffer;
//buffer.Put(key.ptr, key.size);
//
////CryptoPP::StringSource buffer(key.ptr, key.size, true);
//CryptoPP::RSA::PrivateKey priv;
//priv.Load(buffer);
//CryptoPP::AutoSeededRandomPool rng;
//if(!priv.Validate(rng, 3))
// throw std::runtime_error("Rsa private key validation failed");
//if(!priv.Validate(rng, 3))
// throw std::runtime_error("Dsa private key validation failed");
//CryptoPP::RSAES_PKCS1v15_Decryptor rsaDecryption(priv);
//std::string data((char*)data_inp.ptr, data_inp.size);
//std::string decrypted;
// CryptoPP::StringSource ss(data, true,
// new CryptoPP::PK_DecryptorFilter(rng, rsaDecryption,
// new CryptoPP::StringSink(decrypted)) );
// data_out = decrypted;
//return true;
return
false
;
}
}
else
else
{
{
CryptoPP
::
AES
::
Decryption
aesDecryption
(
key
.
ptr
,
key
.
size
);
CryptoPP
::
StreamTransformation
*
modeDecryption
=
NULL
;
CryptoPP
::
StreamTransformation
*
modeDecryption
=
NULL
;
CryptoPP
::
AES
::
Decryption
aesDecryption
(
key
.
ptr
,
key
.
size
);
switch
(
algorithm
)
switch
(
algorithm
)
{
{
...
@@ -281,6 +323,7 @@ bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYP
...
@@ -281,6 +323,7 @@ bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYP
modeDecryption
=
new
CryptoPP
::
CBC_Mode_ExternalCipher
::
Decryption
(
aesDecryption
,
iv
.
ptr
);
modeDecryption
=
new
CryptoPP
::
CBC_Mode_ExternalCipher
::
Decryption
(
aesDecryption
,
iv
.
ptr
);
break
;
break
;
}
}
if
(
!
modeDecryption
)
return
false
;
if
(
!
modeDecryption
)
return
false
;
if
(
!
data_out
.
ptr
)
if
(
!
data_out
.
ptr
)
...
@@ -303,11 +346,15 @@ namespace CRYPT
...
@@ -303,11 +346,15 @@ namespace CRYPT
ECMADecryptor
::
ECMADecryptor
()
ECMADecryptor
::
ECMADecryptor
()
{
{
bVerify
=
false
;
}
}
bool
ECMADecryptor
::
SetPassword
(
std
::
wstring
password_
)
bool
ECMADecryptor
::
SetPassword
(
std
::
wstring
_password
)
{
{
password
=
password_
;
bVerify
=
false
;
password
=
_password
;
if
(
password
.
empty
())
return
false
;
if
(
cryptData
.
bAgile
)
if
(
cryptData
.
bAgile
)
{
{
...
@@ -334,7 +381,7 @@ bool ECMADecryptor::SetPassword(std::wstring password_)
...
@@ -334,7 +381,7 @@ bool ECMADecryptor::SetPassword(std::wstring password_)
_buf
verifierHashKey
=
GenerateAgileKey
(
pSalt
,
pPassword
,
pValueBlockKey
,
cryptData
.
keySize
,
cryptData
.
spinCount
,
cryptData
.
hashAlgorithm
);
_buf
verifierHashKey
=
GenerateAgileKey
(
pSalt
,
pPassword
,
pValueBlockKey
,
cryptData
.
keySize
,
cryptData
.
spinCount
,
cryptData
.
hashAlgorithm
);
DecryptCipher
(
verifierHashKey
,
pSalt
,
pEncVerValue
,
decryptedVerifierHashBytes
,
cryptData
.
cipherAlgorithm
);
DecryptCipher
(
verifierHashKey
,
pSalt
,
pEncVerValue
,
decryptedVerifierHashBytes
,
cryptData
.
cipherAlgorithm
);
return
(
decryptedVerifierHashBytes
==
hashBuf
);
bVerify
=
(
decryptedVerifierHashBytes
==
hashBuf
);
}
}
else
else
{
{
...
@@ -359,8 +406,14 @@ bool ECMADecryptor::SetPassword(std::wstring password_)
...
@@ -359,8 +406,14 @@ bool ECMADecryptor::SetPassword(std::wstring password_)
DecryptCipher
(
hashKey
,
empty
,
pEncVerValue
,
decryptedVerifierHashBytes
,
cryptData
.
cipherAlgorithm
);
DecryptCipher
(
hashKey
,
empty
,
pEncVerValue
,
decryptedVerifierHashBytes
,
cryptData
.
cipherAlgorithm
);
return
(
decryptedVerifierHashBytes
==
hashBuf
);
bVerify
=
(
decryptedVerifierHashBytes
==
hashBuf
);
}
}
return
bVerify
;
}
bool
ECMADecryptor
::
IsVerify
()
{
return
bVerify
;
}
}
void
ECMADecryptor
::
SetCryptData
(
_cryptData
&
data
)
void
ECMADecryptor
::
SetCryptData
(
_cryptData
&
data
)
...
@@ -369,6 +422,8 @@ void ECMADecryptor::SetCryptData(_cryptData &data)
...
@@ -369,6 +422,8 @@ void ECMADecryptor::SetCryptData(_cryptData &data)
}
}
void
ECMADecryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
void
ECMADecryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
{
{
if
(
bVerify
)
{
unsigned
char
*
data_out
=
NULL
;
unsigned
char
*
data_out
=
NULL
;
Decrypt
((
unsigned
char
*
)
data
,
size
,
data_out
);
Decrypt
((
unsigned
char
*
)
data
,
size
,
data_out
);
...
@@ -377,6 +432,7 @@ void ECMADecryptor::Decrypt(char* data , const size_t size, const unsigned long
...
@@ -377,6 +432,7 @@ void ECMADecryptor::Decrypt(char* data , const size_t size, const unsigned long
delete
[]
data
;
delete
[]
data
;
data
=
(
char
*
)
data_out
;
data
=
(
char
*
)
data_out
;
}
}
}
}
}
void
ECMADecryptor
::
Decrypt
(
unsigned
char
*
data_inp
,
int
size
,
unsigned
char
*&
data_out
)
void
ECMADecryptor
::
Decrypt
(
unsigned
char
*
data_inp
,
int
size
,
unsigned
char
*&
data_out
)
{
{
...
...
OfficeCryptReader/source/CryptTransform.h
View file @
036c3b37
...
@@ -34,6 +34,8 @@
...
@@ -34,6 +34,8 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <boost/shared_ptr.hpp>
namespace
CRYPT_METHOD
namespace
CRYPT_METHOD
{
{
enum
_hashAlgorithm
enum
_hashAlgorithm
...
@@ -60,7 +62,11 @@ class Decryptor
...
@@ -60,7 +62,11 @@ class Decryptor
{
{
public:
public:
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
=
0
;
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
=
0
;
virtual
bool
SetPassword
(
std
::
wstring
password
)
=
0
;
virtual
bool
IsVerify
()
=
0
;
};
};
typedef
boost
::
shared_ptr
<
Decryptor
>
DecryptorPtr
;
class
ECMADecryptor
:
public
Decryptor
class
ECMADecryptor
:
public
Decryptor
{
{
...
@@ -102,16 +108,18 @@ public:
...
@@ -102,16 +108,18 @@ public:
ECMADecryptor
();
ECMADecryptor
();
virtual
~
ECMADecryptor
(){}
virtual
~
ECMADecryptor
(){}
void
Decrypt
(
unsigned
char
*
data
,
int
size
,
unsigned
char
*&
data_out
);
void
Decrypt
(
unsigned
char
*
data
,
int
size
,
unsigned
char
*&
data_out
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
);
bool
SetPassword
(
std
::
wstring
password
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
);
virtual
bool
SetPassword
(
std
::
wstring
password
);
virtual
bool
IsVerify
();
void
SetCryptData
(
_cryptData
&
data
);
void
SetCryptData
(
_cryptData
&
data
);
private:
private:
_cryptData
cryptData
;
std
::
wstring
password
;
std
::
wstring
password
;
_cryptData
cryptData
;
bool
bVerify
;
};
};
}
}
\ No newline at end of file
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