Compare commits

..

31 Commits

Author SHA1 Message Date
961bde6723 RtfFormatReader - fix bug #45439, fix bug #45477 2020-05-27 20:02:12 +03:00
2261de2884 Fix build without UNICODE
(cherry picked from commit 4503678e2c)
2020-05-26 12:33:36 +03:00
7bc4ab9655 Use boost 1.72 2020-05-26 12:32:02 +03:00
5e6d2f12d5 x2t - bin reader - fix error 2020-05-25 19:35:52 +03:00
fb7d20c7e0 Merge pull request #257 from ONLYOFFICE/feature/fixFor554
Feature/fix for554
2020-05-25 16:22:34 +00:00
ba518d7c85 . 2020-05-25 18:26:26 +03:00
a045f57430 . 2020-05-25 18:24:18 +03:00
b10274c65d x2t - fix users files; fix bug #45439 2020-05-25 17:21:05 +03:00
c1e4a2ce33 v5.5.3 2020-05-22 11:21:42 +03:00
ee091e7ca9 [x2t] Fix writing corrupted docx
any docx file with chart in group shape
2020-05-06 10:30:07 +03:00
3d814e7b40 Merge pull request #253 from ONLYOFFICE/hotfix/v5.5.2 2020-04-27 18:37:39 +03:00
bb65549dc1 RtfFormat - fix bug #45195 (#250) 2020-04-17 15:56:01 +03:00
5294089fd0 [builder] Stop work with local resources in web mode (#249) 2020-04-16 17:37:14 +03:00
3ec24e5e39 RtfFormat - fix bug #45166 2020-04-16 16:32:25 +03:00
dc44dc5e84 RtfFormat - fix bug #45150 2020-04-16 16:32:25 +03:00
cf76de8811 . 2020-04-16 16:32:25 +03:00
86421d8235 DocxFormat - fix bug #44709 2020-04-16 16:32:25 +03:00
5e77e96e5f [x2t] Fix bug 45171 (#248) 2020-04-16 15:52:16 +03:00
973b89609d v5.5.1r2 2020-04-15 13:04:24 +03:00
a0c0171d12 Set small fontscache size by allfontsgen working... (#244) 2020-04-11 12:12:50 +03:00
d5c5c4b8cf v5.5.1 2020-04-09 12:40:22 +03:00
60904a6df0 Fix windows xp support for non-console apps (#240) 2020-04-06 12:08:03 +03:00
72315d1229 Add sort to application fonts list (#239) 2020-04-06 10:51:12 +03:00
abb5fd1ec1 x2t - fix bug #44957 (#238) 2020-04-02 13:16:09 +03:00
fd6beb0044 return error from abnormal zip (#237) 2020-04-02 11:46:00 +03:00
1b6eff5cb7 Fix writing sdk version when linking binary files (macos) (#236) 2020-04-01 10:38:33 +03:00
4fc6511b37 . (#235) 2020-03-31 19:00:41 +03:00
52ff8af2be Feature/year (#234)
* Correct year detect on windows

* Remove qmake message
2020-03-31 15:15:17 +03:00
d29475b6fb Update base.pri (#233) 2020-03-30 17:45:42 +03:00
32e7193212 [x2t] Fix bug 44934 (#232) 2020-03-28 19:39:47 +03:00
23fc146eca Fix wget/curl parameters injection 2020-03-24 13:38:10 +03:00
35 changed files with 1417 additions and 131 deletions

View File

@ -100,6 +100,7 @@ public:
bSectionType = false;
bPageNumStart = false;
bRtlGutter = false;
bGutter = false;
}
std::wstring Write()
{
@ -730,10 +731,12 @@ public:
{
pCStringWriter->WriteString(L"<w:sz w:val=\"" + std::to_wstring(FontSize) + L"\"/>");
}
if(bFontSizeCs)
{
if(bFontSizeCs)
{
if(false == bFontSize)
pCStringWriter->WriteString(L"<w:sz w:val=\"" + std::to_wstring(FontSizeCs) + L"\"/>");
pCStringWriter->WriteString(L"<w:szCs w:val=\"" + std::to_wstring(FontSizeCs) + L"\"/>");
}
}
if(bHighLight)
{
docRGB& H = HighLight;

View File

@ -1254,6 +1254,14 @@
<File
RelativePath="..\src\odf\chart_build_oox.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/bigobj"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
@ -1302,6 +1310,14 @@
<File
RelativePath="..\src\odf\draw_frame_docx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/bigobj"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
@ -1314,6 +1330,14 @@
<File
RelativePath="..\src\odf\draw_frame_pptx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/bigobj"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
@ -1326,6 +1350,14 @@
<File
RelativePath="..\src\odf\draw_frame_xlsx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/bigobj"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>

View File

@ -350,9 +350,10 @@ namespace PPTX
{
nvGraphicFramePr.toXmlWriter(pWriter);
if (xfrm.IsInit() && pWriter->m_lDocType != XMLWRITER_DOC_TYPE_DOCX)
if (xfrm.IsInit() && (pWriter->m_lDocType != XMLWRITER_DOC_TYPE_DOCX || pWriter->m_lGroupIndex >= 0))
{
if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_XLSX && pWriter->m_lGroupIndex >= 0) xfrm->m_ns = L"xdr";
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_DOCX && pWriter->m_lGroupIndex >= 0) xfrm->m_ns = L"wpg";
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_GRAPHICS) xfrm->m_ns = L"a";
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_CHART_DRAWING) xfrm->m_ns = L"cdr";

View File

@ -1726,6 +1726,7 @@ bool RtfFieldReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader,
else if ( "fldinst" == sCommand )
{
RtfFieldInstPtr oNewFieldInst = RtfFieldInstPtr(new RtfFieldInst());
oNewFieldInst->m_oCharProperty = oReader.m_oState->m_oCharProp;
RtfFieldInstReader oFieldInstReader( *oNewFieldInst );
StartSubReader( oFieldInstReader, oDocument, oReader );
@ -1740,6 +1741,7 @@ bool RtfFieldReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader,
else if ( "fldrslt" == sCommand )
{
RtfFieldInstPtr oNewFieldInst = RtfFieldInstPtr(new RtfFieldInst());
oNewFieldInst->m_oCharProperty = oReader.m_oState->m_oCharProp;
RtfFieldInstReader oFieldInstReader( *oNewFieldInst );
StartSubReader( oFieldInstReader, oDocument, oReader );
@ -2528,6 +2530,11 @@ bool RtfParagraphPropDestination::ExecuteCommand(RtfDocument& oDocument, RtfRead
}
else if ( "cell" == sCommand || "nestcell" == sCommand )
{
if (oReader.m_oState->m_oParagraphProp.m_bInTable == PROP_DEF && oReader.m_oState->m_oParagraphProp.m_nItap == PROP_DEF)
{//пример п 9 п 12.rtf
oReader.m_oState->m_oParagraphProp.m_bInTable = 1;
oReader.m_oState->m_oParagraphProp.m_nItap = 1;
}
if (oReader.m_oState->m_oParagraphProp.m_bInTable == 1 && 0 == oReader.m_oState->m_oParagraphProp.m_nItap )//Платежное_поручение.rtf (ели по другому сбойная строка заменяется параграфами
oReader.m_oState->m_oParagraphProp.m_nItap = 1;
@ -2918,7 +2925,15 @@ bool RtfParagraphPropDestination::ExecuteCommand(RtfDocument& oDocument, RtfRead
// pNewChar->m_eType = RtfCharSpecial::rsc_chatn;
// m_oCurParagraph->AddItem( pNewChar );
//}
else if ( "chftn" == sCommand )
else if ( "chpgn" == sCommand ) //todooo - other special
{//header & footer
RtfCharSpecialPtr pNewChar ( new RtfCharSpecial() );
pNewChar->m_oProperty = oReader.m_oState->m_oCharProp;
pNewChar->m_eType = RtfCharSpecial::rsc_chpgn;
m_oCurParagraph->AddItem( pNewChar );
}
else if ( "chftn" == sCommand )
{
if ( 1 == oReader.m_nFootnote )
{

View File

@ -86,7 +86,7 @@ public:
if( NULL != oParam.poTableStyle )
oNewParagraph->m_oProperty.m_nTableStyle = oParam.poTableStyle->m_nID;
oNewParagraph->m_oProperty.m_nItap = oParam.oReader->m_nCurItap;
oNewParagraph->m_oProperty.m_bInTable = true;
oNewParagraph->m_oProperty.m_bInTable = 1;
oOutputCell.AddItem( oNewParagraph );
}break;

View File

@ -97,8 +97,8 @@ std::wstring RtfFieldInst::RenderToRtf(RenderParameter oRenderParameter)
}
std::wstring RtfFieldInst::RenderToOOX(RenderParameter oRenderParameter)
{
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* pOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
if (m_pTextItems)
return m_pTextItems->RenderToOOX(oRenderParameter);
@ -145,8 +145,8 @@ std::wstring RtfField::RenderToRtf(RenderParameter oRenderParameter)
std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
{
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* pOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
std::wstring sResult;
@ -168,20 +168,20 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
{
bInsert = true;
sAuthor = poRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauth);
sAuthor = pRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauth);
sDate = std::wstring(RtfUtility::convertDateTime(m_pInsert->m_oCharProperty.m_nRevdttm).c_str());
sResult += L"<w:ins w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
sResult += L"<w:ins w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(pOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
m_pInsert->m_oCharProperty.m_nRevised = PROP_DEF;
}
if (m_pInsert->m_oCharProperty.m_nDeleted != PROP_DEF)
{
bDelete = true;
sAuthor = poRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauthDel);
sAuthor = pRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauthDel);
sDate = std::wstring(RtfUtility::convertDateTime(m_pInsert->m_oCharProperty.m_nRevdttmDel).c_str());
sResult += L"<w:del w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
sResult += L"<w:del w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(pOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
m_pInsert->m_oCharProperty.m_nDeleted = PROP_DEF;
}
//поверяем на наличие гиперссылки
@ -224,7 +224,7 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
RenderParameter oNewParametr = oRenderParameter;
oNewParametr.nType = RENDER_TO_OOX_PARAM_PLAIN;
std::wstring props = m_pResult->m_oCharProperty.RenderToOOX(oRenderParameter);
std::wstring props = m_pResult->m_oCharProperty.RenderToOOX(oRenderParameter);
if (!props.empty()) props = L"<w:rPr>" + props + L"</w:rPr>";
//начинаем Field
@ -235,6 +235,8 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
sResult += L"</w:r>";
//-----------
sResult += L"<w:r>";
if (!props.empty())
sResult += props;
sResult += L"<w:instrText xml:space=\"preserve\">";

View File

@ -87,8 +87,8 @@ std::wstring RtfParagraph::RenderToRtf(RenderParameter oRenderParameter)
std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
{
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* poOOXWriter = static_cast<OOXWriter*>(oRenderParameter.poWriter);
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
OOXWriter* pOOXWriter = static_cast<OOXWriter*>(oRenderParameter.poWriter);
std::wstring sResult ;
@ -134,7 +134,7 @@ std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
sResult += L"<w:p";
if (oRenderParameter.nType == RENDER_TO_OOX_PARAM_COMMENT)
{
std::wstring sParaId = XmlUtils::IntToString(++poOOXWriter->m_nextParaId, L"%08X");
std::wstring sParaId = XmlUtils::IntToString(++pOOXWriter->m_nextParaId, L"%08X");
sResult += L" w14:paraId=\"" + sParaId + L"\" w14:textId=\"" + sParaId + L"\"";
}
sResult += L"><w:pPr>";
@ -145,7 +145,7 @@ std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
if ( PROP_DEF != m_oProperty.m_nTableStyle && m_oProperty.m_bInTable > 0)
{
RtfStylePtr oCurStyle;
if( true == poRtfDocument->m_oStyleTable.GetStyle( m_oProperty.m_nTableStyle, oCurStyle ) )
if( true == pRtfDocument->m_oStyleTable.GetStyle( m_oProperty.m_nTableStyle, oCurStyle ) )
{
RtfParagraphStyle* oCurParaStyle = dynamic_cast<RtfParagraphStyle*>(oCurStyle.get());

View File

@ -261,13 +261,13 @@ std::wstring RtfFont::RenderToOOX(RenderParameter oRenderParameter)
break;
}
sResult += L"<w:rFonts w:ascii=\"";
sResult += sFontName;
sResult += XmlUtils::EncodeXmlString( sFontName, true );
sResult += L"\" w:eastAsia=\"";
sResult += sFontName;
sResult += XmlUtils::EncodeXmlString( sFontName, true );
sResult += L"\" w:hAnsi=\"";
sResult += sFontName;
sResult += XmlUtils::EncodeXmlString( sFontName, true );
sResult += L"\" w:cs=\"";
sResult += sFontName;
sResult += XmlUtils::EncodeXmlString( sFontName, true );
sResult += L"\"";
sResult += sHint;
sResult += L"/>";
@ -2948,8 +2948,14 @@ std::wstring RtfTableProperty::RenderToOOX(RenderParameter oRenderParameter)
sDefCellMargins += L"<w:bottom w:w=\"" + std::to_wstring(m_nDefCellMarBottom) + L"\" w:type=\"dxa\"/>";
if( PROP_DEF != m_nDefCellMarLeft && 3 == m_eDefCellMarLeftUnit )
sDefCellMargins += L"<w:left w:w=\"" + std::to_wstring(m_nDefCellMarLeft) + L"\" w:type=\"dxa\"/>";
else
sDefCellMargins += L"<w:left w:w=\"0\" w:type=\"dxa\"/>";
if( PROP_DEF != m_nDefCellMarRight && 3 == m_eDefCellMarRightUnit )
sDefCellMargins += L"<w:right w:w=\"" + std::to_wstring(m_nDefCellMarRight) + L"\" w:type=\"dxa\"/>";
else
sDefCellMargins += L"<w:right w:w=\"0\" w:type=\"dxa\"/>";
if( PROP_DEF != m_nDefCellMarTop && 3 == m_eDefCellMarTopUnit )
sDefCellMargins += L"<w:top w:w=\"" + std::to_wstring(m_nDefCellMarTop) + L"\" w:type=\"dxa\"/>";
@ -3111,7 +3117,7 @@ std::wstring RtfRowProperty::RenderToOOX(RenderParameter oRenderParameter)
{
switch( m_eWidthEndInvCellUnit )
{
case mu_Percent: sResult += L"<w:wAfter w:type=\"pct\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"%\"/>"; break;
case mu_Percent: sResult += L"<w:wAfter w:type=\"pct\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"\"/>"; break;
case mu_Twips: sResult += L"<w:wAfter w:type=\"dxa\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"\"/>"; break;
default:
break;

View File

@ -270,6 +270,7 @@ public:
m_byteShade = oColor.m_byteShade;
m_byteTint = oColor.m_byteTint;
m_bAuto = oColor.m_bAuto;
return (*this);
}

View File

@ -2,13 +2,16 @@ INCLUDEPATH += $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/include
CORE_BOOST_LIBS = $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib
core_windows {
BOOST_POSTFIX = vc140
core_debug:BOOST_POSTFIX=$$BOOST_POSTFIX-mt-gd-1_58
core_release:BOOST_POSTFIX=$$BOOST_POSTFIX-mt-1_58
core_win_64:BOOST_POSTFIX = -vc140-mt-x64-1_72
core_win_32:BOOST_POSTFIX = -vc140-mt-x32-1_72
core_debug {
core_win_64:BOOST_POSTFIX = -vc140-mt-gd-x64-1_72
core_win_32:BOOST_POSTFIX = -vc140-mt-gd-x32-1_72
}
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -llibboost_system-$$BOOST_POSTFIX -llibboost_filesystem-$$BOOST_POSTFIX
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex-$$BOOST_POSTFIX
core_boost_date_time:LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time-$$BOOST_POSTFIX
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -llibboost_system$$BOOST_POSTFIX -llibboost_filesystem$$BOOST_POSTFIX
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex$$BOOST_POSTFIX
core_boost_date_time:LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time$$BOOST_POSTFIX
} else {
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -lboost_system -lboost_filesystem
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -lboost_regex

View File

@ -0,0 +1,486 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "./common_openssl.h"
#include <openssl/sha.h>
#include <openssl/rsa.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/aes.h>
namespace NSOpenSSL
{
unsigned char* openssl_alloc(unsigned int len)
{
return (unsigned char*)malloc(len);
}
void openssl_free(unsigned char* data)
{
free(data);
}
// hash
unsigned int GetHashSize(const int& alg)
{
switch (alg)
{
case OPENSSL_HASH_ALG_SHA1:
return 20;
case OPENSSL_HASH_ALG_SHA224:
return 28;
case OPENSSL_HASH_ALG_SHA256:
return 32;
case OPENSSL_HASH_ALG_SHA384:
return 48;
case OPENSSL_HASH_ALG_SHA512:
return 64;
default:
break;
}
return 0;
}
unsigned char* GetHash(const unsigned char* data, const unsigned int& size, const int& alg, unsigned int& len)
{
len = GetHashSize(alg);
if (0 == len)
return NULL;
unsigned char* res = openssl_alloc(len);
switch (alg)
{
case OPENSSL_HASH_ALG_SHA1:
SHA1(data, (size_t)size, res);
break;
case OPENSSL_HASH_ALG_SHA224:
SHA224(data, (size_t)size, res);
break;
case OPENSSL_HASH_ALG_SHA256:
SHA256(data, (size_t)size, res);
break;
case OPENSSL_HASH_ALG_SHA384:
SHA384(data, (size_t)size, res);
break;
case OPENSSL_HASH_ALG_SHA512:
SHA512(data, (size_t)size, res);
break;
default:
break;
}
return res;
}
// rsa
bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey)
{
publicKey = NULL;
privateKey = NULL;
RSA* rsa = RSA_new();
BIGNUM *exponent = BN_new();
BN_set_word(exponent, RSA_F4);
int result = RSA_generate_multi_prime_key(rsa, 2048, 2, exponent, NULL);
if (0 == result)
return false;
if (true)
{
BIO* bio = BIO_new(BIO_s_mem());
if (PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, NULL))
{
int key_length = BIO_pending(bio);
privateKey = openssl_alloc(key_length + 1);
if (key_length != BIO_read(bio, privateKey, key_length))
{
openssl_free(privateKey);
privateKey = NULL;
}
else
{
privateKey[key_length] = '\0';
}
}
BIO_free_all(bio);
}
if (true)
{
BIO* bio = BIO_new(BIO_s_mem());
if (PEM_write_bio_RSA_PUBKEY(bio, rsa))
{
int key_length = BIO_pending(bio);
publicKey = openssl_alloc(key_length + 1);
if (key_length != BIO_read(bio, publicKey, key_length))
{
openssl_free(publicKey);
publicKey = NULL;
}
else
{
publicKey[key_length] = '\0';
}
}
BIO_free_all(bio);
}
BN_free(exponent);
RSA_free(rsa);
return (NULL != publicKey && NULL != privateKey) ? true : false;
}
//#define USE_DEPRECATED
bool RSA_EncryptPublic(const unsigned char* publicKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len)
{
BIO* bio = BIO_new_mem_buf(publicKey, (int)strlen((char*)publicKey));
#ifdef USE_DEPRECATED
RSA* rsa = RSA_new();
RSA* resrsa = PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, NULL);
unsigned int key_size = (unsigned int)RSA_size(rsa);
data_crypt = openssl_alloc(key_size);
int res = RSA_public_encrypt((int)size, data, data_crypt, rsa, RSA_NO_PADDING);
data_crypt_len = key_size;
BIO_free(bio);
RSA_free(rsa);
return (-1 != res) ? true : false;
#else
EVP_PKEY* publicKeyEngine = NULL;
PEM_read_bio_PUBKEY(bio, &publicKeyEngine, 0, NULL);
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(publicKeyEngine, NULL);
EVP_PKEY_encrypt_init(ctx);
EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
size_t out_len = 0;
EVP_PKEY_encrypt(ctx, NULL, &out_len, data, (size_t)size);
data_crypt = openssl_alloc((unsigned int)out_len);
EVP_PKEY_encrypt(ctx, data_crypt, &out_len, data, (size_t)size);
data_crypt_len = (unsigned int)out_len;
EVP_PKEY_CTX_free(ctx);
EVP_PKEY_free(publicKeyEngine);
BIO_free(bio);
return (out_len > 0) ? true : false;
#endif
}
bool RSA_DecryptPrivate(const unsigned char* privateKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len)
{
BIO* bio = BIO_new_mem_buf(privateKey, (int)strlen((char*)privateKey));
#ifdef USE_DEPRECATED
RSA* rsa = RSA_new();
PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, NULL);
unsigned int key_size = (unsigned int)RSA_size(rsa);
data_decrypt = openssl_alloc(key_size);
int res = RSA_private_decrypt((int)size, data, data_decrypt, rsa, RSA_NO_PADDING);
data_decrypt_len = key_size;
BIO_free(bio);
RSA_free(rsa);
return (-1 != res) ? true : false;
#else
EVP_PKEY* privateKeyEngine = NULL;
PEM_read_bio_PrivateKey(bio, &privateKeyEngine, 0, NULL);
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(privateKeyEngine, NULL);
EVP_PKEY_decrypt_init(ctx);
EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
size_t out_len = 0;
EVP_PKEY_decrypt(ctx, NULL, &out_len, data, (size_t)size);
data_decrypt = openssl_alloc((unsigned int)out_len);
EVP_PKEY_decrypt(ctx, data_decrypt, &out_len, data, (size_t)size);
data_decrypt_len = (unsigned int)out_len;
EVP_PKEY_CTX_free(ctx);
EVP_PKEY_free(privateKeyEngine);
BIO_free(bio);
return (out_len > 0) ? true : false;
#endif
}
bool RSA_EncryptPublic_desktop(const unsigned char* publicKey, const std::string& input, std::string& out)
{
unsigned char* out_ptr = NULL;
unsigned int out_ptr_len = 0;
if (!RSA_EncryptPublic(publicKey, (unsigned char*)input.c_str(), (unsigned int)input.length(), out_ptr, out_ptr_len))
return false;
out = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_BASE64);
openssl_free(out_ptr);
return true;
}
bool RSA_DecryptPrivate_desktop(const unsigned char* privateKey, const std::string& input, std::string& out)
{
unsigned char* input_ptr = NULL;
int input_ptr_len = 0;
bool bBase64 = NSFile::CBase64Converter::Decode(input.c_str(), (int)input.length(), input_ptr, input_ptr_len);
if (!bBase64)
return false;
unsigned char* out_ptr = NULL;
unsigned int out_ptr_len = 0;
if (!RSA_DecryptPrivate(privateKey, input_ptr, (unsigned int)input_ptr_len, out_ptr, out_ptr_len))
{
openssl_free(input_ptr);
return false;
}
//out = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_ASCII);
out = std::string((char*)out_ptr, out_ptr_len);
openssl_free(input_ptr);
openssl_free(out_ptr);
return true;
}
// pbkdf2
const EVP_MD* Get_EVP_MD(int nAlg)
{
switch (nAlg)
{
case OPENSSL_HASH_ALG_SHA1:
{
return EVP_sha1();
}
case OPENSSL_HASH_ALG_SHA224:
{
return EVP_sha224();
}
case OPENSSL_HASH_ALG_SHA256:
{
return EVP_sha256();
}
case OPENSSL_HASH_ALG_SHA384:
{
return EVP_sha384();
}
case OPENSSL_HASH_ALG_SHA512:
{
return EVP_sha512();
}
default:
break;
}
return EVP_sha1();
}
unsigned char* PBKDF2(const char* pass, int passlen, const unsigned char* salt, int saltlen, int hash_alg, int key_len)
{
unsigned char* out = openssl_alloc(key_len);
if (0 == PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, 1000, Get_EVP_MD(hash_alg), key_len, out))
{
openssl_free(out);
out = NULL;
}
return out;
}
unsigned char* PBKDF2_desktop(const std::string& pass, const std::string& salt)
{
unsigned char* key_iv = NULL;
if (salt.empty())
{
unsigned int pass_salt_len = 0;
unsigned char* pass_salt = NSOpenSSL::GetHash((unsigned char*)pass.c_str(), (unsigned int)pass.length(), OPENSSL_HASH_ALG_SHA512, pass_salt_len);
key_iv = PBKDF2(pass.c_str(), (int)pass.length(), pass_salt, pass_salt_len, OPENSSL_HASH_ALG_SHA256, 32 + 16);
openssl_free(pass_salt);
}
else
{
key_iv = PBKDF2(pass.c_str(), (int)pass.length(), (const unsigned char*)salt.c_str(), (unsigned int)salt.length(), OPENSSL_HASH_ALG_SHA256, 32 + 16);
}
return key_iv;
}
// aes
int AES_GetKeySize(int type)
{
switch (type)
{
case OPENSSL_AES_256_CBC:
return 32;
}
return 32;
}
int AES_GetIvSize(int type)
{
switch (type)
{
case OPENSSL_AES_256_CBC:
return 16;
}
return 16;
}
const EVP_CIPHER* _get_cipher_aes(int type)
{
switch (type)
{
case OPENSSL_AES_256_CBC:
return EVP_aes_256_cbc();
}
return NULL;
}
bool AES_Encrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len)
{
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_init(ctx);
EVP_EncryptInit_ex(ctx, _get_cipher_aes(type), NULL, key, iv);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL);
int out_len1 = (int)size + AES_BLOCK_SIZE;
int out_len2 = 0;
data_crypt = openssl_alloc(out_len1);
EVP_EncryptUpdate(ctx, data_crypt, &out_len1, data, (int)size);
EVP_EncryptFinal_ex(ctx, data_crypt + out_len1, &out_len2);
data_crypt_len = out_len1 + out_len2;
EVP_CIPHER_CTX_free(ctx);
EVP_cleanup();
return true;
}
bool AES_Decrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len)
{
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_init(ctx);
EVP_DecryptInit_ex(ctx, _get_cipher_aes(type), NULL, key, iv);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL);
int out_len1 = (int)size;
int out_len2 = 0;
data_decrypt = openssl_alloc(out_len1);
EVP_DecryptUpdate(ctx, data_decrypt, &out_len1, data, (int)size);
EVP_DecryptFinal_ex(ctx, data_decrypt + out_len1, &out_len2);
data_decrypt_len = out_len1 + out_len2;
EVP_CIPHER_CTX_free(ctx);
EVP_cleanup();
return true;
}
bool AES_Encrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt)
{
unsigned char* key_iv = PBKDF2_desktop(pass, salt);
bool bRes = AES_Encrypt_desktop(key_iv, input, output);
openssl_free(key_iv);
return bRes;
}
bool AES_Decrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt)
{
unsigned char* key_iv = PBKDF2_desktop(pass, salt);
bool bRes = AES_Decrypt_desktop(key_iv, input, output);
openssl_free(key_iv);
return bRes;
}
bool AES_Encrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output)
{
unsigned char* data_crypt = NULL;
unsigned int data_crypt_len = 0;
bool bRes = AES_Encrypt(OPENSSL_AES_256_CBC, key_iv, key_iv + 32, (unsigned char*)input.c_str(), (unsigned int)input.length(), data_crypt, data_crypt_len);
if (!bRes)
return false;
output = Serialize(data_crypt, data_crypt_len, OPENSSL_SERIALIZE_TYPE_BASE64);
openssl_free(data_crypt);
return true;
}
bool AES_Decrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output)
{
unsigned char* input_ptr = NULL;
int input_ptr_len = 0;
bool bBase64 = NSFile::CBase64Converter::Decode(input.c_str(), (int)input.length(), input_ptr, input_ptr_len);
if (!bBase64)
return false;
unsigned char* data_decrypt = NULL;
unsigned int data_decrypt_len = 0;
bool bRes = AES_Decrypt(OPENSSL_AES_256_CBC, key_iv, key_iv + 32, input_ptr, input_ptr_len, data_decrypt, data_decrypt_len);
if (!bRes)
{
RELEASEARRAYOBJECTS(input_ptr);
return false;
}
//output = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_ASCII);
output = std::string((char*)data_decrypt, data_decrypt_len);
RELEASEARRAYOBJECTS(input_ptr);
openssl_free(data_decrypt);
return true;
}
// serialize
std::string Serialize(const unsigned char* data, const unsigned int& size, const int& alg)
{
switch (alg)
{
case OPENSSL_SERIALIZE_TYPE_ASCII:
{
return std::string((char*)data, size);
}
case OPENSSL_SERIALIZE_TYPE_HEX:
{
std::string res;
res.reserve(2 * size + 1);
char tmp[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
for (unsigned int i = 0; i < size; ++i)
{
res.append(1, tmp[data[i] >> 4]);
res.append(1, tmp[data[i] & 0x0F]);
}
return res;
}
case OPENSSL_SERIALIZE_TYPE_BASE64:
{
char* pDataDst = NULL;
int nDataDst = 0;
NSFile::CBase64Converter::Encode((BYTE*)data, (int)size, pDataDst, nDataDst, NSBase64::B64_BASE64_FLAG_NOCRLF);
std::string sBase64((char*)pDataDst, nDataDst);
RELEASEARRAYOBJECTS(pDataDst);
return sBase64;
}
default:
break;
}
return "";
}
}

View File

@ -0,0 +1,94 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef COMMON_OPENSSL_H
#define COMMON_OPENSSL_H
#define OPENSSL_HASH_ALG_SHA1 0
#define OPENSSL_HASH_ALG_INVALID 1
#define OPENSSL_HASH_ALG_SHA256 2
#define OPENSSL_HASH_ALG_SHA224 3
#define OPENSSL_HASH_ALG_SHA384 4
#define OPENSSL_HASH_ALG_SHA512 5
#define OPENSSL_SERIALIZE_TYPE_BASE64 0
#define OPENSSL_SERIALIZE_TYPE_HEX 1
#define OPENSSL_SERIALIZE_TYPE_ASCII 2
#define OPENSSL_AES_256_CBC 0
#include "../../../../DesktopEditor/common/File.h"
#ifdef COMMON_OPENSSL_BUILDING
#define OPENSSL_DECL Q_DECL_EXPORT
#else
#define OPENSSL_DECL Q_DECL_IMPORT
#endif
namespace NSOpenSSL
{
// alloc
OPENSSL_DECL unsigned char* openssl_alloc(unsigned int len);
OPENSSL_DECL void openssl_free(unsigned char* data);
// hash
OPENSSL_DECL unsigned int GetHashSize(const int& alg);
OPENSSL_DECL unsigned char* GetHash(const unsigned char* data, const unsigned int& size, const int& alg, unsigned int& len);
// rsa
OPENSSL_DECL bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey);
OPENSSL_DECL bool RSA_EncryptPublic(const unsigned char* publicKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
OPENSSL_DECL bool RSA_DecryptPrivate(const unsigned char* privateKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len);
OPENSSL_DECL bool RSA_EncryptPublic_desktop(const unsigned char* publicKey, const std::string& input, std::string& out);
OPENSSL_DECL bool RSA_DecryptPrivate_desktop(const unsigned char* privateKey, const std::string& input, std::string& out);
// pbkdf2
OPENSSL_DECL unsigned char* PBKDF2(const char* pass, int passlen, const unsigned char* salt, int saltlen, int hash_alg, int key_len);
OPENSSL_DECL unsigned char* PBKDF2_desktop(const std::string& pass, const std::string& salt = "");
// aes
OPENSSL_DECL int AES_GetKeySize(int type);
OPENSSL_DECL int AES_GetIvSize(int type);
OPENSSL_DECL bool AES_Encrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
OPENSSL_DECL bool AES_Decrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
OPENSSL_DECL bool AES_Encrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt = "");
OPENSSL_DECL bool AES_Decrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt = "");
OPENSSL_DECL bool AES_Encrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output);
OPENSSL_DECL bool AES_Decrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output);
// serialize
OPENSSL_DECL std::string Serialize(const unsigned char* data, const unsigned int& size, const int& alg);
}
#endif // COMMON_OPENSSL_H

View File

@ -1,18 +1,11 @@
core_linux {
INCLUDEPATH += $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/include
INCLUDEPATH += $$PWD/openssl/include
core_windows:LIBS += -L$$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib -llibcrypto -llibssl
!core_windows:LIBS += -L$$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib -lcrypto -lssl
QMAKE_LFLAGS += -fvisibility=hidden
LIBS += $$PWD/openssl/libssl.a
LIBS += $$PWD/openssl/libcrypto.a
}
core_mac {
INCLUDEPATH += $$PWD/openssl/include
LIBS += $$PWD/openssl/libssl.a
LIBS += $$PWD/openssl/libcrypto.a
open_ssl_common {
DEFINES += COMMON_OPENSSL_BUILDING
HEADERS += $$PWD/common/common_openssl.h
SOURCES += $$PWD/common/common_openssl.cpp
}

View File

@ -0,0 +1,94 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "./../common/common_openssl.h"
int main(int argc, char *argv[])
{
argc;
argv;
if (true)
{
std::string sTestHashString = "knoejnrgijwenrgiojwnergjiwnerigjnwerojgnweorigjn";
unsigned int data_len = 0;
unsigned char* data = NSOpenSSL::GetHash((unsigned char*)sTestHashString.c_str(), (unsigned int)sTestHashString.length(), OPENSSL_HASH_ALG_SHA256, data_len);
std::string sResult = NSOpenSSL::Serialize(data, data_len, OPENSSL_SERIALIZE_TYPE_HEX);
NSOpenSSL::openssl_free(data);
}
if (true)
{
unsigned char* publicKey = NULL;
unsigned char* privateKey = NULL;
bool bRes = NSOpenSSL::RSA_GenerateKeys(publicKey, privateKey);
bRes;
std::string sPublic((char*)publicKey);
std::string sPrivate((char*)privateKey);
NSOpenSSL::openssl_free(publicKey);
NSOpenSSL::openssl_free(privateKey);
std::string sMessage = "Hello world";
unsigned char* message_crypt = NULL;
unsigned int message_crypt_len = 0;
bool bEncrypt = NSOpenSSL::RSA_EncryptPublic((unsigned char*)sPublic.c_str(), (unsigned char*)sMessage.c_str(), (unsigned int)sMessage.length(), message_crypt, message_crypt_len);
bEncrypt;
unsigned char* message_decrypt = NULL;
unsigned int message_decrypt_len = 0;
bool bDecrypt = NSOpenSSL::RSA_DecryptPrivate((unsigned char*)sPrivate.c_str(), message_crypt, message_crypt_len, message_decrypt, message_decrypt_len);
bDecrypt;
std::string sMessageOut((char*)message_decrypt, message_decrypt_len);
NSOpenSSL::openssl_free(message_crypt);
NSOpenSSL::openssl_free(message_decrypt);
}
if (true)
{
std::string password = "{PASSWORD}";
std::string message = "{MESSAGE}";
std::string message_crypted = "";
std::string message_decrypted = "";
NSOpenSSL::AES_Encrypt_desktop(password, message, message_crypted);
NSOpenSSL::AES_Decrypt_desktop(password, message_crypted, message_decrypted);
message;
}
return 0;
}

View File

@ -0,0 +1,28 @@
QT -= core
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
CORE_ROOT_DIR = $$PWD/../../../../../core
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
############### destination path ###############
DESTDIR = $$PWD_ROOT_DIR/build/$$CORE_BUILDS_PLATFORM_PREFIX
################################################
INCLUDEPATH += $$PWD_ROOT_DIR/../build/$$CORE_BUILDS_PLATFORM_PREFIX/include
LIBS += -L$$PWD_ROOT_DIR/../build/$$CORE_BUILDS_PLATFORM_PREFIX/lib -llibcrypto
core_windows:LIBS += -lws2_32 -lAdvapi32 -lCrypt32 -lUser32
ADD_DEPENDENCY(kernel)
HEADERS += $$PWD_ROOT_DIR/../common/common_openssl.h
SOURCES += $$PWD_ROOT_DIR/../common/common_openssl.cpp
SOURCES += main.cpp

View File

@ -343,9 +343,7 @@ namespace OOX
}
}
}
void CTbl::fromXML(XmlUtils::CXmlLiteReader& oReader)
void CTbl::fromXML(XmlUtils::CXmlLiteReader& oReader)
{
if ( oReader.IsEmptyNode() )
return;
@ -411,7 +409,13 @@ namespace OOX
else if ( _T("w:sdt") == sName )
pItem = new CSdt( oReader );
else if ( _T("w:tblGrid") == sName )
m_oTblGrid = oReader;
{
if (false == m_oTblGrid.IsInit())
{
m_oTblGrid = new CTblGrid();
}
m_oTblGrid->fromXML(oReader);
}
else if ( _T("w:tblPr") == sName )
{
pItem = m_oTableProperties = new CTableProperty( oReader );
@ -657,7 +661,11 @@ namespace OOX
}
else if ( _T("w:trPr") == sName )
{
pItem = m_pTableRowProperties = new CTableRowProperties( oReader );
if (!m_pTableRowProperties)
{
pItem = m_pTableRowProperties = new CTableRowProperties();
}
m_pTableRowProperties->fromXML(oReader);
}
if ( pItem )
@ -872,7 +880,12 @@ namespace OOX
pItem = new CTbl( oReader );
else if ( _T("w:tcPr") == sName )
{
pItem = m_pTableCellProperties = new CTableCellProperties( oReader );
if (!m_pTableCellProperties)
{
pItem = m_pTableCellProperties = new CTableCellProperties();
}
m_pTableCellProperties->fromXML(oReader);
}
if ( pItem )
@ -905,9 +918,8 @@ namespace OOX
return sResult;
}
void CTc::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
void CTc::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{
// Читаем атрибуты
WritingElement_ReadAttributes_Start( oReader )
WritingElement_ReadAttributes_ReadSingle( oReader, _T("w:id"), m_sId )
WritingElement_ReadAttributes_End( oReader )

View File

@ -231,13 +231,11 @@ namespace XmlUtils
double d = 0;
#if defined (_WIN32) || defined (_WIN64)
swscanf_s(string.c_str(), L"%lf", &d);
#elif defined(_IOS) || defined(__ANDROID__)
swscanf(string.c_str(), L"%lf", &d);
swscanf_s(string.c_str(), L"%lf", &d);
#else
_stscanf(string.c_str(), L"%lf", &d);
swscanf(string.c_str(), L"%lf", &d);
#endif
return d;
return d;
}
AVSINLINE static float GetFloat (const std::wstring& string)
{
@ -245,13 +243,11 @@ namespace XmlUtils
float f = 0;
#if defined (_WIN32) || defined (_WIN64)
swscanf_s(string.c_str(), L"%f", &f);
#elif defined(_IOS) || defined(__ANDROID__)
swscanf(string.c_str(), L"%f", &f);
swscanf_s(string.c_str(), L"%f", &f);
#else
_stscanf(string.c_str(), L"%f", &f);
swscanf(string.c_str(), L"%f", &f);
#endif
return f;
return f;
}
AVSINLINE static std::wstring BoolToString (const bool & value)
{

View File

@ -47,6 +47,18 @@
#include <unistd.h>
#include <sys/wait.h>
std::string wget_url_validate(const std::string& url)
{
std::string::size_type pos = 0;
const char* url_ptr = url.c_str();
while ('-' == *url_ptr++) // '\0' => break
++pos;
if (*url_ptr == '\0')
return "";
return url.substr(pos);
}
int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
{
int nReturnCode = -1;
@ -68,13 +80,14 @@ int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
case 0: // child process
{
const char* nargs[6];
const char* nargs[7];
nargs[0] = "/usr/bin/curl";
nargs[1] = sUrlA.c_str();
nargs[2] = "--output";
nargs[3] = sOutputA.c_str();
nargs[4] = "--silent";
nargs[5] = NULL;
nargs[1] = "--url";
nargs[2] = sUrlA.c_str();
nargs[3] = "--output";
nargs[4] = sOutputA.c_str();
nargs[5] = "--silent";
nargs[6] = NULL;
const char* nenv[3];
nenv[0] = "LD_PRELOAD=";
@ -97,6 +110,8 @@ int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
if (0 != nReturnCode && NSFile::CFileBinary::Exists(L"/usr/bin/wget"))
{
std::string sUrlValidateA = wget_url_validate(sUrlA);
pid_t pid = fork(); // create child process
int status;
@ -109,7 +124,7 @@ int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
{
const char* nargs[6];
nargs[0] = "/usr/bin/wget";
nargs[1] = sUrlA.c_str();
nargs[1] = sUrlValidateA.c_str();
nargs[2] = "-O";
nargs[3] = sOutputA.c_str();
nargs[4] = "-q";

View File

@ -17,7 +17,11 @@ isEmpty(PUBLISHER_NAME){
}
win32 {
CURRENT_YEAR = $$system("echo %Date:~6,4%")
CURRENT_YEAR = $$system(wmic PATH Win32_LocalTime GET ^Year /FORMAT:VALUE | find \"=\")
CURRENT_YEAR = $$replace(CURRENT_YEAR, "Year=", "")
CURRENT_YEAR = $$replace(CURRENT_YEAR, "\r", "")
CURRENT_YEAR = $$replace(CURRENT_YEAR, "\n", "")
CURRENT_YEAR = $$replace(CURRENT_YEAR, "\t", "")
}
!win32 {
@ -131,6 +135,7 @@ core_linux {
core_mac {
DEFINES += LINUX _LINUX MAC _MAC
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.11
QMAKE_LFLAGS += -isysroot $$QMAKE_MAC_SDK_PATH
}
# PREFIXES
@ -145,8 +150,8 @@ core_windows {
core_win_64:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.02
core_win_32:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:CONSOLE,5.01
} else {
core_win_64:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:WINDOWS,5.02
core_win_32:QMAKE_LFLAGS_CONSOLE = /SUBSYSTEM:WINDOWS,5.01
core_win_64:QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.02
core_win_32:QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
}
}
}

View File

@ -392,6 +392,7 @@ namespace NSCommon
{
NSFonts::IFontManager* pManager = applicationFonts->GenerateFontManager();
NSFonts::IFontsCache* pCache = NSFonts::NSFontCache::Create();
pCache->SetCacheSize(3);
pCache->SetStreams(applicationFonts->GetStreams());
pManager->SetOwnerCache(pCache);
@ -427,6 +428,9 @@ namespace NSCommon
pRenderer->put_Width(lWidthPix * 25.4 / dDpi);
pRenderer->put_Height(lHeightPix * 25.4 / dDpi);
bool isUseMapForStreams = false;
std::map<std::wstring, bool> mapUsedFiles;
for (int index = 0; index < nCountFonts; ++index)
{
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(arrFonts[index]);
@ -476,6 +480,9 @@ namespace NSCommon
if (NULL != pInfoCur)
{
if (isUseMapForStreams)
mapUsedFiles.insert(std::pair<std::wstring, bool>(pInfoCur->m_wsFontPath, true));
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, 0, 14, dDpi, dDpi);
}
pRenderer->put_FontPath(pInfoCur->m_wsFontPath);
@ -503,6 +510,9 @@ namespace NSCommon
if (NULL != pInfoCur)
{
if (isUseMapForStreams)
mapUsedFiles.insert(std::pair<std::wstring, bool>(pInfoCur->m_wsFontPath, true));
pManager->LoadFontFromFile(pInfoCur->m_wsFontPath, 0, 14, dDpi, dDpi);
}
pRenderer->put_FontPath(pInfoCur->m_wsFontPath);
@ -514,6 +524,11 @@ namespace NSCommon
pRenderer->put_FontSize(14);
pRenderer->CommandDrawText(pPair->second.m_sName, 5, 25.4 * (index * lH1_px + lH1_px) / dDpi - 2, 0, 0);
if (isUseMapForStreams)
applicationFonts->GetStreams()->CheckStreams(mapUsedFiles);
else
applicationFonts->GetStreams()->Clear();
}
std::wstring strThumbnailPath = strFolderThumbnails + L"/fonts_thumbnail";

View File

@ -648,6 +648,8 @@ namespace NSDoctRenderer
}
void CDocBuilder::SetTmpFolder(const wchar_t* folder)
{
if (m_pInternal->m_bIsServerSafeVersion)
return;
m_pInternal->m_sTmpFolder = std::wstring(folder);
}
void CDocBuilder::CloseFile()
@ -907,7 +909,10 @@ namespace NSDoctRenderer
else if (sParam == "--cache-scripts")
m_pInternal->m_bIsCacheScript = (std::wstring(value) == L"true");
else if (sParam == "--save-use-only-names")
{
m_pInternal->m_bIsServerSafeVersion = true;
m_pInternal->m_sFolderForSaveOnlyUseNames = std::wstring(value);
}
else if (sParam == "--all-fonts-path")
{
m_pInternal->m_strAllFonts = std::wstring(value);

View File

@ -186,6 +186,7 @@ namespace NSDoctRenderer
bool m_bIsCacheScript;
bool m_bIsServerSafeVersion;
std::wstring m_sFolderForSaveOnlyUseNames;
std::string m_sGlobalVariable;
@ -214,6 +215,7 @@ namespace NSDoctRenderer
m_bIsGlobalVariableUse = false;
m_bIsNotUseConfigAllFontsDir = false;
m_bIsServerSafeVersion = false;
}
void Init()
@ -551,6 +553,10 @@ namespace NSDoctRenderer
}
#endif
// не открываем локальные файлы в серверной версии.
if (m_bIsServerSafeVersion)
return;
NSFile::CFileBinary::Copy(from, to);
}

View File

@ -119,6 +119,8 @@ NSFonts::IApplicationFonts* CApplicationFontsWorker::Check()
NSDirectory::GetFiles2(*i, strFontsW_Cur, true);
}
std::sort(strFontsW_Cur.begin(), strFontsW_Cur.end());
bool bIsEqual = true;
if (strFonts.size() != strFontsW_Cur.size())
bIsEqual = false;

View File

@ -104,7 +104,19 @@ NSFonts::IFontStream* CApplicationFontStreams::GetStream(const std::wstring &str
}
void CApplicationFontStreams::CheckStreams(std::map<std::wstring,bool> &mapFiles)
{
// TODO:
std::map<std::wstring, CFontStream*>::iterator iter = m_mapStreams.begin();
while (iter != m_mapStreams.end())
{
CFontStream* pFile = iter->second;
if (mapFiles.find(iter->first) != mapFiles.end())
{
iter = m_mapStreams.erase(iter);
RELEASEINTERFACE(pFile);
}
else
iter++;
}
}
void CApplicationFontStreams::Clear()

View File

@ -19,14 +19,6 @@ include($$CORE_ROOT_DIR/Common/base.pri)
ADD_DEPENDENCY(kernel)
DEFINES -= UNICODE
core_linux {
CONFIG += signature_openssl
}
core_mac {
CONFIG += signature_openssl
}
HEADERS += \
include/XmlCertificate.h \
include/OOXMLSigner.h \
@ -51,10 +43,12 @@ HEADERS += \
LIBS += -lcrypt32
LIBS += -lcryptui
LIBS += -lAdvapi32
LIBS += -lws2_32
LIBS += -lUser32
}
signature_openssl {
!core_windows {
HEADERS += \
src/XmlSigner_openssl.h
@ -64,8 +58,5 @@ SOURCES += \
}
signature_openssl {
CONFIG += open_ssl_common
include(../../../Common/3dParty/openssl/openssl.pri)
}

View File

@ -616,7 +616,7 @@ public:
void RemoveSignature(const std::string& sGuid)
{
int nCountSignatures = m_arSignatures.size();
int nCountSignatures = (int)m_arSignatures.size();
if (0 == nCountSignatures)
return;

View File

@ -3,6 +3,7 @@
#include "tchar.h"
#include "../source/ECMACryptFile.h"
#include "../../Common/OfficeFileFormatChecker.h"
#include "../../DesktopEditor/common/File.h"
#if defined(_WIN64)
#pragma comment(lib, "../../build/bin/icu/win_64/icuuc.lib")
@ -25,7 +26,7 @@ int _tmain(int argc, _TCHAR* argv[])
ECMACryptFile crypt_file;
bool result = false, bDataIntegrity = false;
std::wstring srcFileName = L"D:\\test\\_crypted\\test-111.docx";
std::wstring srcFileName = L"D:\\test\\_bad_86\\crypt_file_test.docx";
std::wstring dstFileName = srcFileName + L"-mycrypt.docx";
std::wstring dstFileName2 = dstFileName + L".oox";
@ -39,8 +40,17 @@ int _tmain(int argc, _TCHAR* argv[])
//std::wstring dstFileName1 = srcFileName1 + L".oox";
//result = crypt_file.DecryptOfficeFile(srcFileName1, dstFileName1, password, bDataIntegrity);
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
//result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
//result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
std::wstring addit_name = L"11111111111111111111111111111";
std::string addit_info = crypt_file.ReadAdditional(srcFileName, addit_name);
std::wstring temp = NSFile::CFileBinary::CreateTempFileWithUniqueName(L"", L"asd");
addit_info += std::string(temp.begin(), temp.end());
crypt_file.WriteAdditional(srcFileName, addit_name, addit_info);
return 0;
}

View File

@ -0,0 +1,314 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "./../source/ECMACryptFile.h"
#include "./../../DesktopEditor/common/File.h"
#include "./../../Common/3dParty/openssl/common/common_openssl.h"
#include <iostream>
// examples:
// ooxml_crypt --file=D:/cryptor/1.docx --password=111
// ooxml_crypt --file=D:/cryptor/1.docx --add={user-id-1}\ndata1
// ooxml_crypt --file=D:/cryptor/1.docx --remove={user-id-1}
// ooxml_crypt --file=D:/cryptor/1.docx --remove={user-id-1}\ndata1
// ooxml_crypt --file=D:/cryptor/1.docx --add={user-id-1}\ndata11
// ooxml_crypt --file=D:/cryptor/1.docx --info=
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
{
size_t posn = 0;
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
{
text.replace(posn, replaceFrom.length(), replaceTo);
posn += replaceTo.length();
}
}
void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
{
size_t posn = 0;
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
{
text.replace(posn, replaceFrom.length(), replaceTo);
posn += replaceTo.length();
}
}
#ifdef WIN32
int wmain(int argc, wchar_t** argv)
#else
int main(int argc, char** argv)
#endif
{
if (argc <= 0)
return 0;
std::wstring file_path;
std::wstring password;
bool is_print_info = false;
bool is_decrypt = false;
std::string user;
std::wstring user_key_file;
std::vector<std::string> add_records;
std::vector<std::string> remove_records;
for (int i = 0; i < argc; ++i)
{
#ifdef WIN32
std::wstring param(argv[i]);
#else
std::string paramA(argv[i]);
std::wstring param = UTF8_TO_U(paramA);
#endif
std::wstring::size_type len = param.length();
if (2 > len)
continue;
const wchar_t* param_str = param.c_str();
if (param_str[0] != '-' || param_str[1] != '-')
continue;
std::wstring::size_type pos = param.find('=');
if (std::wstring::npos == pos)
continue;
std::wstring key = param.substr(2, pos - 2);
std::wstring value = param.substr(pos + 1);
if (key == L"file")
{
file_path = value;
}
else if (key == L"add")
{
if (!value.empty())
{
if (value.c_str()[value.length() - 1] == '\n')
value = value.substr(0, value.length() - 1);
string_replace(value, L";;;", L"\n");
add_records.push_back(U_TO_UTF8(value));
}
}
else if (key == L"remove")
{
if (!value.empty())
{
if (value.c_str()[value.length() - 1] == '\n')
value = value.substr(0, value.length() - 1);
string_replace(value, L";;;", L"\n");
remove_records.push_back(U_TO_UTF8(value));
}
}
else if (key == L"password")
{
password = value;
}
else if (key == L"info")
{
is_print_info = true;
}
else if (key == L"decrypt")
{
is_decrypt = true;
}
else if (key == L"user")
{
user = U_TO_UTF8(value);
}
else if (key == L"key")
{
user_key_file = value;
}
}
if (file_path.empty() || !NSFile::CFileBinary::Exists(file_path))
{
std::cout << "error: file not exist" << std::endl;
return 1;
}
if (!password.empty())
{
// encrypt file
ECMACryptFile file;
bool result = file.EncryptOfficeFile(file_path, file_path, password);
if (!result)
{
std::cout << "error: file is not encrypted" << std::endl;
return 0;
}
return 2;
}
ECMACryptFile file;
std::string docinfo = file.ReadAdditional(file_path, L"DocumentID");
if (is_print_info)
{
std::cout << docinfo << std::endl;
return 0;
}
const char* doc_info_str = docinfo.c_str();
const char* doc_info_str_end = doc_info_str + docinfo.length();
if (is_decrypt)
{
std::string encrypted_password = "";
// находим нужную запись
while (doc_info_str < doc_info_str_end)
{
const char* rec_start = doc_info_str;
// 1) ищем старт записи
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
++doc_info_str;
if (user == std::string(rec_start, doc_info_str - rec_start))
{
rec_start = doc_info_str;
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
++doc_info_str;
encrypted_password = std::string(rec_start, doc_info_str - rec_start);
}
// идем в конец записи
while (doc_info_str < doc_info_str_end)
{
if (*doc_info_str++ == '\n')
{
if (*doc_info_str == '\n')
{
++doc_info_str;
break;
}
}
}
}
std::string private_key_content;
NSFile::CFileBinary::ReadAllTextUtf8A(user_key_file, private_key_content);
std::string passwordA;
NSOpenSSL::RSA_DecryptPrivate_desktop((unsigned char*)private_key_content.c_str(), encrypted_password, passwordA);
std::wstring password = UTF8_TO_U(passwordA);
// encrypt file
ECMACryptFile file;
bool bDataIntegrity;
bool result = file.DecryptOfficeFile(file_path, file_path, password, bDataIntegrity);
if (!result)
{
std::cout << "error: file is not decrypted" << std::endl;
return 0;
}
return 2;
}
std::string sResult = "";
sResult.reserve(1000);
while (doc_info_str < doc_info_str_end)
{
const char* rec_start = doc_info_str;
// 1) ищем старт записи
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
++doc_info_str;
std::string::size_type len_first = doc_info_str - rec_start;
// 2) ищем конец записи
while (doc_info_str < doc_info_str_end)
{
if (*doc_info_str++ == '\n')
{
if (*doc_info_str == '\n')
{
++doc_info_str;
break;
}
}
}
bool isAdd = true;
std::string sRec = std::string(rec_start, (doc_info_str - rec_start - 2));
// 3) проверяем запись на удаление
for (std::vector<std::string>::iterator iter = remove_records.begin(); iter != remove_records.end(); iter++)
{
if (*iter == std::string(rec_start, len_first))
{
isAdd = false;
}
else if (*iter == sRec)
{
isAdd = false;
}
}
// 4) проверяем запись на удаление
for (std::vector<std::string>::iterator iter = add_records.begin(); iter != add_records.end(); iter++)
{
if (*iter == sRec)
{
isAdd = false;
}
}
if (isAdd)
{
sResult += sRec;
sResult += "\n\n";
}
}
for (std::vector<std::string>::iterator iter = add_records.begin(); iter != add_records.end(); iter++)
{
sResult += *iter;
sResult += "\n\n";
}
bool result = file.WriteAdditional(file_path, L"DocumentID", sResult);
if (!result)
{
std::cout << "error: docinfo not writed" << std::endl;
return 3;
}
return 0;
}

View File

@ -0,0 +1,56 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
TARGET = ooxml_crypt
CORE_ROOT_DIR = $$PWD/../..
PWD_ROOT_DIR = $$PWD
CONFIG += core_static_link_libstd
include($$CORE_ROOT_DIR/Common/base.pri)
include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri)
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib
ADD_DEPENDENCY(kernel)
CONFIG += open_ssl_common
include($$CORE_ROOT_DIR/Common/3dParty/openssl/openssl.pri)
DEFINES += CRYPTOPP_DISABLE_ASM
DESTDIR = $$CORE_BUILDS_BINARY_PATH
HEADERS += \
$$PWD/../source/ECMACryptFile.h \
$$PWD/../source/CryptTransform.h \
$$PWD/../source/simple_xml_writer.h
SOURCES += \
$$PWD/../source/ECMACryptFile.cpp \
$$PWD/../source/CryptTransform.cpp
SOURCES += \
$$CORE_ROOT_DIR/Common/OfficeFileFormatChecker2.cpp \
$$CORE_ROOT_DIR/Common/3dParty/pole/pole.cpp \
$$CORE_ROOT_DIR/Common/DocxFormat/Source/Base/unicode_util.cpp
SOURCES += \
$$PWD/main.cpp
core_windows {
DEFINES -= UNICODE
DEFINES -= _DEBUG
LIBS += -lAdvapi32
LIBS += -lShell32
LIBS += -lGdi32
LIBS += -lUser32
LIBS += -lcrypt32
LIBS += -lcryptui
LIBS += -lws2_32
}
core_linux {
LIBS += -lz -pthread
QMAKE_LFLAGS += -Wl,--rpath=./
}

View File

@ -976,3 +976,56 @@ bool ECMACryptFile::DecryptOfficeFile(const std::wstring &file_name_inp, const s
return result;
}
std::string ECMACryptFile::ReadAdditional(const std::wstring &file_name, const std::wstring &addit_name)
{
POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
if (!pStorage->open(false, false))
{
delete pStorage;
return "";
}
std::string result;
POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name);
if ((pStream) && (pStream->size() > 0))
{
_UINT64 lengthData, size = pStream->size();
char* data = new char[size];
lengthData = pStream->read((unsigned char*)data, size);
result = std::string(data, lengthData);
delete []data;
delete pStream;
}
delete pStorage;
return result;
}
bool ECMACryptFile::WriteAdditional(const std::wstring &file_name, const std::wstring &addit_name, const std::string &addit_info)
{
POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
if (!pStorage)return false;
if (!pStorage->open(true, false))
{
delete pStorage;
return false;
}
POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name, true, addit_info.size());
pStream->write((unsigned char*)addit_info.c_str(), addit_info.size());
pStream->setSize(addit_info.size());
pStream->flush();
delete pStream;
pStorage->close();
delete pStorage;
return true;
}

View File

@ -40,6 +40,9 @@ public:
bool DecryptOfficeFile(const std::wstring &file_name_inp, const std::wstring &file_name_out, const std::wstring &password, bool & bDataIntegrity);
bool EncryptOfficeFile(const std::wstring &file_name_inp, const std::wstring &file_name_out, const std::wstring &password, const std::wstring &documentID = L"");
std::string ReadAdditional(const std::wstring &file_name, const std::wstring &addit_name);
bool WriteAdditional(const std::wstring &file_name, const std::wstring &addit_name, const std::string &addit_info);
struct _refComponent
{
int type;
@ -50,5 +53,5 @@ public:
std::vector<_refComponent> refComponents;
std::wstring dataSpaceName;
};
std::vector<_mapEntry> mapEntries;
std::vector<_mapEntry> mapEntries;
};

View File

@ -358,17 +358,14 @@ namespace ZLibZipUtils
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
(filename_withoutpath!=(wchar_t*)filename_inzip))
{
char c=*(filename_withoutpath-1);
*(filename_withoutpath-1)='\0';
makedir(write_filename);
*(filename_withoutpath-1)=c;
char* current_directory = getcwd(NULL, 0);
if (current_directory)
{
std::string current_path(current_directory);
free(current_directory);
current_path += FILE_SEPARATOR_STRA;
replace_all(current_path, "/", FILE_SEPARATOR_STRA);
replace_all(current_path, "\\", FILE_SEPARATOR_STRA);
@ -378,12 +375,17 @@ namespace ZLibZipUtils
replace_all(filename_inzip, "\\", FILE_SEPARATOR_STRA);
std::string norm_path = normalize_path(current_path + filename_inzip);
std::string norm_current_path = normalize_path(current_path);
if (std::string::npos == norm_path.find(current_path))
if (std::string::npos == norm_path.find(norm_current_path))
{
return UNZ_INTERNALERROR;
}
}
char c=*(filename_withoutpath-1);
*(filename_withoutpath-1)='\0';
makedir(write_filename);
*(filename_withoutpath-1)=c;
if(oFile.CreateFileW(write_filename))
{
@ -446,7 +448,10 @@ namespace ZLibZipUtils
if (do_extract_currentfile(uf,&opt_extract_without_path,
&opt_overwrite,
password) != UNZ_OK)
break;
{
err = -1;
break;
}
if ( progress != NULL )
{
@ -479,7 +484,7 @@ namespace ZLibZipUtils
(*progress)( UTILS_ONPROGRESSEVENT_ID, progressValue, &cancel );
}
return 0;
return err;
}
/*========================================================================================================*/
@ -635,23 +640,46 @@ int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback*
std::vector<std::wstring> aCurFiles = NSDirectory::GetFiles(szText);
std::vector<std::wstring> aCurDirectories = NSDirectory::GetDirectories(szText);
if (sorted)
{
std::sort(aCurFiles.begin(), aCurFiles.end());
std::sort(aCurDirectories.begin(), aCurDirectories.end());
}
for(size_t i = 0; i < aCurDirectories.size(); ++i)
for(size_t i = 0; i < aCurDirectories.size(); ++i)
{
std::wstring sDirName = NSSystemPath::GetFileName(aCurDirectories[i]);
StringDeque.push_back( aCurDirectories[i] );
zipDeque.push_back( zipDir + sDirName );
if (sorted)
{
if (sDirName == L"ppt")
{
StringDeque.push_front(aCurDirectories[i] );
zipDeque.push_front( zipDir + sDirName );
}
else if(sDirName == L"xl")
{
StringDeque.push_front( aCurDirectories[i] );
zipDeque.push_front( zipDir + sDirName );
}
else if (sDirName == L"word")
{
StringDeque.push_front( aCurDirectories[i] );
zipDeque.push_front( zipDir + sDirName );
}
else
{
StringDeque.push_back( aCurDirectories[i] );
zipDeque.push_back( zipDir + sDirName );
}
}
else
{
StringDeque.push_back( aCurDirectories[i] );
zipDeque.push_back( zipDir + sDirName );
}
}
for (size_t i = 0; i < aCurFiles.size(); ++i)
{
std::wstring cFileName = NSSystemPath::GetFileName(aCurFiles[i]);
if (std::wstring::npos != cFileName.find(L"mimetype")) // возможно и полное соответствие
if (std::wstring::npos != cFileName.find(L"mimetype") ||
std::wstring::npos != cFileName.find(L"[Content_Types]")) // возможно и полное соответствие
{
file = NSSystemPath::Combine(szText, cFileName);
zipFileName = zipDir + cFileName;
@ -839,9 +867,9 @@ int ZipDir( const WCHAR* dir, const WCHAR* outputFile, const OnProgressCallback*
if ( buffer != NULL )
{
#if defined(_WIN32) || defined (_WIN64)
err = _wchdir( buffer );
int err1 = _wchdir( buffer );
#else
err = chdir( buffer );
int err1 = chdir( buffer );
#endif
free( buffer );

View File

@ -147,9 +147,7 @@ namespace NExtractTools
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO)
return mscrypt2oot_bin(sFrom, sTo, sTemp, params);
else
{
//вместо docx другой формат!!
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
else return AVS_FILEUTILS_ERROR_CONVERT;
}
@ -228,7 +226,7 @@ namespace NExtractTools
}
else
{
nRes = dir2zip(sResultDocxDir, sTo);
nRes = dir2zip(sResultDocxDir, sTo, true);
}
}
@ -559,7 +557,7 @@ namespace NExtractTools
}
else
{
//вместо xlsx другой формат!!
return AVS_FILEUTILS_ERROR_CONVERT;
}
}
else return AVS_FILEUTILS_ERROR_CONVERT;
@ -648,7 +646,7 @@ namespace NExtractTools
}
else
{
nRes = dir2zip(sResultXlsxDir, sTo);
nRes = dir2zip(sResultXlsxDir, sTo, true);
}
}
return nRes;
@ -938,7 +936,8 @@ namespace NExtractTools
{
if (OfficeFileFormatChecker.nFileType == AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO)
return mscrypt2oot_bin(sFrom, sTo, sTemp, params);
//вместо pptx другой формат!!
else
return AVS_FILEUTILS_ERROR_CONVERT;
}
else return AVS_FILEUTILS_ERROR_CONVERT;
}
@ -1021,7 +1020,7 @@ namespace NExtractTools
}
else
{
nRes = dir2zip(sResultPptxDir, sTo);
nRes = dir2zip(sResultPptxDir, sTo, true);
}
}
return nRes;
@ -1071,10 +1070,10 @@ namespace NExtractTools
return pptt_bin2pptx(sTempPpttFileEditor, sTo, sTemp, bFromChanges, sThemeDir, params);
}
// zip dir
_UINT32 dir2zip (const std::wstring &sFrom, const std::wstring &sTo)
_UINT32 dir2zip (const std::wstring &sFrom, const std::wstring &sTo, bool bSorted, int method, short level)
{
COfficeUtils oCOfficeUtils(NULL);
return (S_OK == oCOfficeUtils.CompressFileOrDirectory(sFrom, sTo)) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
return (S_OK == oCOfficeUtils.CompressFileOrDirectory(sFrom, sTo, bSorted, method, level)) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
}
// unzip dir
@ -3170,7 +3169,7 @@ namespace NExtractTools
}
else
{
nRes = dir2zip(sFrom, sTo);
nRes = dir2zip(sFrom, sTo, true);
}
}
}
@ -3402,7 +3401,7 @@ namespace NExtractTools
}
else
{
nRes = dir2zip(sFrom, sTo);
nRes = dir2zip(sFrom, sTo, true);
}
}
}
@ -3649,7 +3648,7 @@ namespace NExtractTools
}
else
{
nRes = dir2zip(sFrom, sTo);
nRes = dir2zip(sFrom, sTo, true);
}
}
}

View File

@ -178,7 +178,7 @@ namespace NExtractTools
_UINT32 html2docx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params);
//-------------------------------------------------------------------------------------------------------------------------------------------------
_UINT32 dir2zip (const std::wstring &sFrom, const std::wstring &sTo);
_UINT32 dir2zip (const std::wstring &sFrom, const std::wstring &sTo, bool bSorted = false, int method = 8/*Z_DEFLATED*/, short level = -1);
_UINT32 zip2dir (const std::wstring &sFrom, const std::wstring &sTo);
_UINT32 convertmailmerge (const InputParamsMailMerge& oMailMergeSend,const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, bool bPaid, const std::wstring &sThemeDir, InputParams& params);

View File

@ -329,10 +329,13 @@ namespace CSVReader
}
else
{
const auto oEncodindId = std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
#ifdef __ANDROID__
const auto oEncodindId = *std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
#else
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
#endif
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId->Name);
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
}
//------------------------------------------------------------------------------------------------------------------------------
@ -340,10 +343,13 @@ namespace CSVReader
if (nSize < 1 && nInputBufferSize > 0)
{//для синхронности вывода превью и нормального результата
const auto oEncodindId = std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
#ifdef __ANDROID__
const auto oEncodindId = *std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
#else
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
#endif
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId->Name);
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
nSize = sFileDataW.length();
//return AVS_FILEUTILS_ERROR_CONVERT_ICU;