Compare commits

..

19 Commits

Author SHA1 Message Date
5caccb284a Merge branch 'develop' of https://github.com/ONLYOFFICE/core into develop 2017-06-01 12:27:46 +03:00
ce19969b52 PptxFormat - fix objects without replacement image 2017-06-01 12:24:27 +03:00
0f91dc392e test ParseAllCultureInfo 2017-06-01 11:52:36 +03:00
e9805cef30 PptxFormat - fix Ole object without image cash 2017-05-31 19:22:26 +03:00
e3e05eb2db test 2017-05-31 19:01:24 +03:00
c09f17cffb . 2017-05-31 17:56:45 +03:00
ce73dd5987 linux build error 2017-05-31 15:48:59 +03:00
77df8aacb9 . 2017-05-31 14:13:54 +03:00
ce45b2802f fix bug #34953 2017-05-31 13:46:49 +03:00
7886018d6f Oox file crypter 2017-05-31 12:35:27 +03:00
5b5cb4188e OfficeCryptReader - check data integrity 2017-05-30 19:49:54 +03:00
f797af5f17 . 2017-05-30 16:05:49 +03:00
055977535e fixed build error 2017-05-30 16:04:33 +03:00
6ab24f10f0 Added prefix for lib targets 2017-05-30 15:55:31 +03:00
12a03da231 Changed extension for ooxmlsignature 2017-05-30 15:29:43 +03:00
cb7088979a . 2017-05-30 15:26:56 +03:00
1fb1fc6c97 Added OOXMLSIGNATURE project 2017-05-30 13:15:14 +03:00
e633c3c5d1 fix bug 35012 2017-05-29 17:11:10 +03:00
0f04de34b1 OdfFormatWriter - dont write backgroud master notes, notes (errors in libre & open office) 2017-05-29 16:19:26 +03:00
42 changed files with 573 additions and 227 deletions

View File

@ -178,7 +178,9 @@ namespace BinXlsxRW{
{
std::wstring sXlsxFilename = L"Microsoft_Excel_Worksheet" + std::to_wstring(lChartNumber) + L".xlsx";
std::wstring sXlsxPath = sEmbedingPath + FILE_SEPARATOR_STR + sXlsxFilename;
writeChartXlsx(sXlsxPath, oChartSpace);
pReader->m_pRels->m_pManager->m_pContentTypes->AddDefault(L"xlsx");
std::wstring sChartsWorksheetRelsName = L"../embeddings/" + sXlsxFilename;
long rId;

View File

@ -34,8 +34,6 @@
#include "office_presentation.h"
#include "draw_page.h"
#include <boost/foreach.hpp>
#include <cpdoccore/xml/xmlchar.h>
#include <cpdoccore/xml/attributes.h>
@ -76,9 +74,10 @@ void office_presentation::docx_convert(oox::docx_conversion_context & Context)
{
Context.start_office_text();
_CP_LOG << L"[info][docx] process pages (" << pages_.size() << L" elmements)" << std::endl;
BOOST_FOREACH(const office_element_ptr & elm, pages_)
{
elm->docx_convert(Context);
for (size_t i = 0; i < pages_.size(); i++)
{
pages_[i]->docx_convert(Context);
}
Context.end_office_text();
}
@ -87,9 +86,10 @@ void office_presentation::xlsx_convert(oox::xlsx_conversion_context & Context)
{
Context.start_office_spreadsheet(this);
_CP_LOG << L"[info][xlsx] process pages (" << pages_.size() << L" elmements)" << std::endl;
BOOST_FOREACH(const office_element_ptr & elm, pages_)
{
elm->xlsx_convert(Context);
for (size_t i = 0; i < pages_.size(); i++)
{
pages_[i]->xlsx_convert(Context);
}
Context.end_office_spreadsheet();
}
@ -100,29 +100,29 @@ void office_presentation::pptx_convert(oox::pptx_conversion_context & Context)
_CP_LOG << L"[info][pptx] process pages(" << pages_.size() << L" elmements)" << std::endl;
BOOST_FOREACH(const office_element_ptr & elm, footer_decls_)
for (size_t i = 0; i < footer_decls_.size(); i++)
{
presentation_footer_decl * style = dynamic_cast<presentation_footer_decl *>(elm.get());
presentation_footer_decl * style = dynamic_cast<presentation_footer_decl *>(footer_decls_[i].get());
if (!style)
continue;
std::wstring style_name_ = L"footer:" + style->presentation_name_.get_value_or(L"");
Context.root()->odf_context().drawStyles().add(style_name_, elm);
Context.root()->odf_context().drawStyles().add(style_name_, footer_decls_[i]);
}
BOOST_FOREACH(const office_element_ptr & elm, date_time_decls_)
{
presentation_date_time_decl * style = dynamic_cast<presentation_date_time_decl *>(elm.get());
for (size_t i = 0; i < date_time_decls_.size(); i++)
{
presentation_date_time_decl * style = dynamic_cast<presentation_date_time_decl *>(date_time_decls_[i].get());
if (!style)
continue;
std::wstring style_name_ = L"datetime:" + style->presentation_name_.get_value_or(L"");
Context.root()->odf_context().drawStyles().add(style_name_, elm);
Context.root()->odf_context().drawStyles().add(style_name_, date_time_decls_[i]);
}
BOOST_FOREACH(const office_element_ptr & elm, pages_)
for (size_t i = 0; i < pages_.size(); i++)
{
elm->pptx_convert(Context);
pages_[i]->pptx_convert(Context);
}
Context.end_office_presentation();
}

View File

@ -602,17 +602,24 @@ void OoxConverter::convert(PPTX::Logic::SpPr *oox_spPr, PPTX::Logic::ShapeStyle*
bool bLine = odf_context()->drawing_context()->isLineShape();
if (!bLine)
if (custGeom && !custGeom->cxnLst.empty())
bLine = true;
odf_context()->drawing_context()->start_area_properties();
{
odf_context()->drawing_context()->start_area_properties();
if (bLine)
{
odf_context()->drawing_context()->set_no_fill();
}
else
{
if (oox_spPr->Fill.is_init())
convert(&oox_spPr->Fill);
else if (oox_sp_style)
convert(&oox_sp_style->fillRef, 1);
}
odf_context()->drawing_context()->end_area_properties();
}
odf_context()->drawing_context()->end_area_properties();
odf_context()->drawing_context()->start_line_properties();
{

View File

@ -72,6 +72,7 @@ using namespace cpdoccore;
namespace Oox2Odf
{
PptxConverter::PptxConverter(const std::wstring & path, const ProgressCallback* CallBack)
{
current_clrMap = NULL;
@ -342,7 +343,7 @@ void PptxConverter::convert_slides()
current_slide = slide->Master.operator->();
if (bShowLayoutMasterSp && bShowMasterSp)
convert_slide(&slide->Master->cSld, current_txStyles, false, true, 2);
convert_slide(&slide->Master->cSld, current_txStyles, false, true, Master);
else
convert(slide->Master->cSld.bg.GetPointer());
@ -350,7 +351,7 @@ void PptxConverter::convert_slides()
current_clrMap = slide->Layout->clrMapOvr->overrideClrMapping.GetPointer();
current_slide = slide->Layout.operator->();
convert_slide(&slide->Layout->cSld, current_txStyles, true, bShowLayoutMasterSp, 3);
convert_slide(&slide->Layout->cSld, current_txStyles, true, bShowLayoutMasterSp, Layout);
if (slide->Layout->transition.IsInit()) convert (slide->Layout->transition.GetPointer());
else convert (slide->Master->transition.GetPointer());
@ -402,7 +403,7 @@ void PptxConverter::convert_slides()
odp_context->current_slide().set_master_page (master_style_name);
odp_context->current_slide().set_layout_page (layout_style_name);
convert_slide (slide->cSld.GetPointer(), current_txStyles, true, bShowMasterSp, 1);
convert_slide (slide->cSld.GetPointer(), current_txStyles, true, bShowMasterSp, Slide);
convert (slide->comments.operator->());
convert (slide->Note.operator->());
@ -435,7 +436,7 @@ void PptxConverter::convert(PPTX::NotesMaster *oox_notes)
odf_context()->page_layout_context()->set_page_size(width, height);
}
convert_slide(&oox_notes->cSld, NULL, true, true, 2);
convert_slide(&oox_notes->cSld, NULL, true, true, NotesMaster);
odp_context->end_note();
@ -468,7 +469,7 @@ void PptxConverter::convert(PPTX::NotesSlide *oox_notes)
if (oox_notes->clrMapOvr.IsInit() && oox_notes->clrMapOvr->overrideClrMapping.IsInit())
current_clrMap = oox_notes->clrMapOvr->overrideClrMapping.GetPointer();
convert_slide(&oox_notes->cSld, NULL, true, true, 1);
convert_slide(&oox_notes->cSld, NULL, true, true, Notes);
odp_context->end_note();
@ -1312,13 +1313,19 @@ void PptxConverter::convert(PPTX::Logic::Bg *oox_background)
}
odf_writer::style* page_style_ = dynamic_cast<odf_writer::style*>(odp_context->current_slide().page_style_elm_.get());
odf_writer::style_drawing_page_properties* page_props = page_style_->content_.get_style_drawing_page_properties();
//необязательно
//if (page_props->content_.common_draw_fill_attlist_.draw_fill_image_name_)
//{
// page_props->content_.draw_background_size_ = L"border";
//}
odp_context->drawing_context()->end_drawing_background(page_props->content_.common_draw_fill_attlist_);
odp_context->end_drawings();
}
void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders, bool bFillUp, int type)
void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders, bool bFillUp, _typePages type)
{
if (oox_slide == NULL) return;
@ -1328,7 +1335,10 @@ void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxS
if (oox_slide->attrName.IsInit())
odp_context->current_slide().set_page_name(oox_slide->attrName.get());
convert(oox_slide->bg.GetPointer());
if (type != Notes && type != NotesMaster)
{
convert(oox_slide->bg.GetPointer());
}
for (size_t i = 0 ; i < oox_slide->spTree.SpTreeElems.size(); i++)
{
@ -1348,7 +1358,7 @@ void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxS
{
int ph_type = pShape->nvSpPr.nvPr.ph->type->GetBYTECode();
if (type == 3 && (ph_type == 5 || ph_type == 6 || ph_type == 7 || ph_type == 12))
if (type == Layout && (ph_type == 5 || ph_type == 6 || ph_type == 7 || ph_type == 12))
continue;
odf_context()->drawing_context()->set_placeholder_type(ph_type);

View File

@ -100,6 +100,14 @@ using namespace cpdoccore;
namespace Oox2Odf
{
enum _typePages
{
Slide,
Master,
Layout,
NotesMaster,
Notes
};
class PptxConverter : public OoxConverter
{
public:
@ -119,7 +127,7 @@ namespace Oox2Odf
void convert(OOX::WritingElement *oox_unknown);
void convert_slide (PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders, bool bFillUp, int type);
void convert_slide (PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders, bool bFillUp, _typePages type);
void convert_layout (PPTX::Logic::CSld *oox_slide);
void convert (PPTX::Comments *oox_comments);
void convert (PPTX::NotesSlide *oox_notes);

View File

@ -346,8 +346,11 @@ namespace NSBinPptxRW
{
oPathOutput = m_strDstMedia + FILE_SEPARATOR_STR + strImage + strExts;
if (oPathOutput.GetPath() != strInput)
CDirectory::CopyFile(strInput, oPathOutput.GetPath());
if (oPathOutput.GetPath() != strInput && NSFile::CFileBinary::Exists(strInput))
{
NSFile::CFileBinary::Copy(strInput, oPathOutput.GetPath());
oImageManagerInfo.sFilepathImage = oPathOutput.GetPath();
}
}
else
{
@ -355,8 +358,8 @@ namespace NSBinPptxRW
strExts = _T(".png");
oPathOutput = m_strDstMedia + FILE_SEPARATOR_STR + strImage + strExts;
SaveImageAsPng(strInput, oPathOutput.GetPath());
oImageManagerInfo.sFilepathImage = oPathOutput.GetPath();
}
oImageManagerInfo.sFilepathImage = oPathOutput.GetPath();
if ((!strAdditionalImage.empty() || !oleData.empty() ) && (nAdditionalType == 1))
{
@ -374,13 +377,14 @@ namespace NSBinPptxRW
if(!oleData.empty())
{
WriteOleData(strAdditionalImageOut, oleData);
oImageManagerInfo.sFilepathAdditional = strAdditionalImageOut;
}
else
else if (NSFile::CFileBinary::Exists(strAdditionalImage))
{
CDirectory::CopyFile(strAdditionalImage, strAdditionalImageOut);
NSFile::CFileBinary::Copy(strAdditionalImage, strAdditionalImageOut);
oImageManagerInfo.sFilepathAdditional = strAdditionalImageOut;
}
oImageManagerInfo.sFilepathAdditional = strAdditionalImageOut;
}
else if (!strAdditionalImage.empty() && nAdditionalType == 2)
{
@ -395,8 +399,11 @@ namespace NSBinPptxRW
std::wstring strAdditionalImageOut = pathOutput.GetPath();
CDirectory::CopyFile(strAdditionalImage, strAdditionalImageOut);
oImageManagerInfo.sFilepathAdditional = strAdditionalImageOut;
if (NSFile::CFileBinary::Exists(strAdditionalImage))
{
NSFile::CFileBinary::Copy(strAdditionalImage, strAdditionalImageOut);
oImageManagerInfo.sFilepathAdditional = strAdditionalImageOut;
}
}
return oImageManagerInfo;
@ -1236,24 +1243,28 @@ namespace NSBinPptxRW
if (m_pManager->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX) strImageRelsPath = L"media/";
else strImageRelsPath = L"../media/";
strImageRelsPath += OOX::CPath(oImageManagerInfo.sFilepathImage).GetFilename();
std::map<std::wstring, _relsGeneratorInfo>::iterator pPair = m_mapImages.find(strImageRelsPath);
if (m_mapImages.end() != pPair)
{
return pPair->second;
}
_relsGeneratorInfo oRelsGeneratorInfo;
oRelsGeneratorInfo.nImageRId = m_lNextRelsID++;
oRelsGeneratorInfo.sFilepathImage = oImageManagerInfo.sFilepathImage;
std::wstring strRid = L"rId" + std::to_wstring(oRelsGeneratorInfo.nImageRId);
if (!oImageManagerInfo.sFilepathImage.empty())
{
strImageRelsPath += OOX::CPath(oImageManagerInfo.sFilepathImage).GetFilename();
m_pWriter->WriteString( L"<Relationship Id=\"" + strRid +
L"\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\" Target=\"" + strImageRelsPath +
L"\"/>");
std::map<std::wstring, _relsGeneratorInfo>::iterator pPair = m_mapImages.find(strImageRelsPath);
if (m_mapImages.end() != pPair)
{
return pPair->second;
}
oRelsGeneratorInfo.nImageRId = m_lNextRelsID++;
oRelsGeneratorInfo.sFilepathImage = oImageManagerInfo.sFilepathImage;
std::wstring strRid = L"rId" + std::to_wstring(oRelsGeneratorInfo.nImageRId);
m_pWriter->WriteString( L"<Relationship Id=\"" + strRid +
L"\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\" Target=\"" + strImageRelsPath +
L"\"/>");
}
if(additionalFile.is<OOX::OleObject>())
{
@ -1285,7 +1296,7 @@ namespace NSBinPptxRW
}
}
}
if(additionalFile.is<OOX::Media>())
else if(additionalFile.is<OOX::Media>())
{
smart_ptr<OOX::Media> mediaFile = additionalFile.smart_dynamic_cast<OOX::Media>();

View File

@ -447,7 +447,10 @@ namespace PPTX
if (!blip.is_init())
blip = new PPTX::Logic::Blip();
blip->embed = new OOX::RId((size_t)oRelsGeneratorInfo.nImageRId);
if (oRelsGeneratorInfo.nImageRId >= 0)
{
blip->embed = new OOX::RId((size_t)oRelsGeneratorInfo.nImageRId);
}
if(oRelsGeneratorInfo.nOleRId > 0)
{

View File

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

View File

@ -409,7 +409,6 @@ namespace PPTX
pWriter->StartRecord(4);
pWriter->m_pMainDocument->getBinaryContentElem(OOX::et_w_sdtContent, oTextBoxShape.GetPointer(), *pWriter, lDataSize);
//pWriter->m_pMainDocument->getBinaryContent(TextBoxShape.get(), *pWriter, lDataSize);
pWriter->EndRecord();
if (oTextBoxBodyPr.is_init())
@ -419,6 +418,24 @@ namespace PPTX
pWriter->EndRecord();
}
}
else if (strTextBoxShape.is_init())//после конвертации старого шейпа (vml)
{
long lDataSize = 0;
ULONG lPos = pWriter->GetPosition();
pWriter->SetPosition(lPos);
pWriter->StartRecord(4);
pWriter->m_pMainDocument->getBinaryContent(strTextBoxShape.get(), *pWriter, lDataSize);
pWriter->EndRecord();
if (oTextBoxBodyPr.is_init())
{
pWriter->StartRecord(5);
oTextBoxBodyPr->toPPTY(pWriter);
pWriter->EndRecord();
}
}
else if (txBody.is_init())
{
std::wstring strContent = txBody->GetDocxTxBoxContent(pWriter, style);

View File

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

View File

@ -369,6 +369,71 @@ namespace XmlUtils
return buffer;
}
AVSINLINE static std::wstring EncodeXmlStringExtend(const std::wstring& data, bool bDeleteNoUnicode = false)
{
std::wstring buffer;
buffer.reserve(data.size());
if(bDeleteNoUnicode)
{
for(size_t pos = 0; pos < data.size(); ++pos)
{
switch(data[pos])
{
case '&': buffer.append(L"&amp;"); break;
case '\"': buffer.append(L"&quot;"); break;
case '\'': buffer.append(L"&apos;"); break;
case '<': buffer.append(L"&lt;"); break;
case '>': buffer.append(L"&gt;"); break;
case '\n': buffer.append(L"&#xA;"); break;
case '\r': buffer.append(L"&#xD;"); break;
case '\t': buffer.append(L"&#x9;"); break;
case 160: buffer.append(L"&#160;"); break;
default:
{
if ( false == IsUnicodeSymbol( data[pos] ) )
{
wchar_t symbol1 = data[pos];
if(0xD800 <= symbol1 && symbol1 <= 0xDFFF && pos + 1 < data.size())
{
pos++;
wchar_t symbol2 = data[pos];
if (symbol1 < 0xDC00 && symbol2 >= 0xDC00 && symbol2 <= 0xDFFF)
{
buffer.append(&data[pos-1], 2);
}
}
}
else
buffer.append(&data[pos], 1);
}break;
}
}
}
else
{
for(size_t pos = 0; pos < data.size(); ++pos)
{
switch(data[pos])
{
case '&': buffer.append(L"&amp;"); break;
case '\"': buffer.append(L"&quot;"); break;
case '\'': buffer.append(L"&apos;"); break;
case '<': buffer.append(L"&lt;"); break;
case '>': buffer.append(L"&gt;"); break;
case '\n': buffer.append(L"&#xA;"); break;
case '\r': buffer.append(L"&#xD;"); break;
case '\t': buffer.append(L"&#x9;"); break;
case 160: buffer.append(L"&#160;"); break;
case '\0':
return buffer;
default: buffer.append(&data[pos], 1); break;
}
}
}
return buffer;
}
//#ifndef _USE_LIBXML2_READER_
class CStringWriter
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,6 +18,7 @@ else
SHARED_EXT := .so*
SHELL_EXT := .sh
LIB_EXT := .a
LIB_PREFIX := lib
MAKE := make -j $(shell grep -c ^processor /proc/cpuinfo)
endif
UNAME_P := $(shell uname -p)
@ -36,29 +37,30 @@ LIBDIR := build/lib/$(TARGET)
ALLFONTSGEN := build/bin/AllFontsGen/$(TARGET)$(EXEC_EXT)
X2T := build/bin/$(TARGET)/x2t$(EXEC_EXT)
HTMLFILEINTERNAL := $(LIBDIR)/HtmlFileInternal$(EXEC_EXT)
XLSFORMATLIB := $(LIBDIR)/libXlsFormatLib$(LIB_EXT)
ODFFILEWRITERLIB := $(LIBDIR)/libOdfFileWriterLib$(LIB_EXT)
ODFFILEREADERLIB := $(LIBDIR)/libOdfFileReaderLib$(LIB_EXT)
DOCFORMATLIB := $(LIBDIR)/libDocFormatLib$(LIB_EXT)
PPTFORMATLIB := $(LIBDIR)/libPptFormatLib$(LIB_EXT)
RTFFORMATLIB := $(LIBDIR)/libRtfFormatLib$(LIB_EXT)
TXTXMLFORMATLIB := $(LIBDIR)/libTxtXmlFormatLib$(LIB_EXT)
PDFWRITER := $(LIBDIR)/libPdfWriter$(SHARED_EXT)
ASCOFFICEDOCXFILE2LIB := $(LIBDIR)/libASCOfficeDocxFile2Lib$(LIB_EXT)
PPTXFORMATLIB := $(LIBDIR)/libPPTXFormatLib$(LIB_EXT)
DOCXFORMATLIB := $(LIBDIR)/libDocxFormatLib$(LIB_EXT)
OFFICEUTILS := $(LIBDIR)/libOfficeUtils$(LIB_EXT)
GRAPHICS := $(LIBDIR)/libgraphics$(LIB_EXT)
DOCTRENDERER := $(LIBDIR)/libdoctrenderer$(SHARED_EXT)
HTMLRENDERER := $(LIBDIR)/libHtmlRenderer$(SHARED_EXT)
PDFREADER := $(LIBDIR)/libPdfReader$(SHARED_EXT)
DJVUFILE := $(LIBDIR)/libDjVuFile$(SHARED_EXT)
XPSFILE := $(LIBDIR)/libXpsFile$(SHARED_EXT)
HTMLFILE := $(LIBDIR)/libHtmlFile$(SHARED_EXT)
UNICODECONVERTER := $(LIBDIR)/libUnicodeConverter$(SHARED_EXT)
ASCDOCUMENTSCORE := $(LIBDIR)/libascdocumentscore$(SHARED_EXT)
LIBXML := $(LIBDIR)/liblibxml$(LIB_EXT)
LICENSEMANAGER := $(LIBDIR)/libLicenceManager$(LIB_EXT)
XLSFORMATLIB := $(LIBDIR)/$(LIB_PREFIX)XlsFormatLib$(LIB_EXT)
ODFFILEWRITERLIB := $(LIBDIR)/$(LIB_PREFIX)OdfFileWriterLib$(LIB_EXT)
ODFFILEREADERLIB := $(LIBDIR)/$(LIB_PREFIX)OdfFileReaderLib$(LIB_EXT)
DOCFORMATLIB := $(LIBDIR)/$(LIB_PREFIX)DocFormatLib$(LIB_EXT)
PPTFORMATLIB := $(LIBDIR)/$(LIB_PREFIX)PptFormatLib$(LIB_EXT)
RTFFORMATLIB := $(LIBDIR)/$(LIB_PREFIX)RtfFormatLib$(LIB_EXT)
TXTXMLFORMATLIB := $(LIBDIR)/$(LIB_PREFIX)TxtXmlFormatLib$(LIB_EXT)
PDFWRITER := $(LIBDIR)/$(LIB_PREFIX)PdfWriter$(SHARED_EXT)
ASCOFFICEDOCXFILE2LIB := $(LIBDIR)/$(LIB_PREFIX)ASCOfficeDocxFile2Lib$(LIB_EXT)
PPTXFORMATLIB := $(LIBDIR)/$(LIB_PREFIX)PPTXFormatLib$(LIB_EXT)
DOCXFORMATLIB := $(LIBDIR)/$(LIB_PREFIX)DocxFormatLib$(LIB_EXT)
OFFICEUTILS := $(LIBDIR)/$(LIB_PREFIX)OfficeUtils$(LIB_EXT)
GRAPHICS := $(LIBDIR)/$(LIB_PREFIX)graphics$(LIB_EXT)
DOCTRENDERER := $(LIBDIR)/$(LIB_PREFIX)doctrenderer$(SHARED_EXT)
HTMLRENDERER := $(LIBDIR)/$(LIB_PREFIX)HtmlRenderer$(SHARED_EXT)
PDFREADER := $(LIBDIR)/$(LIB_PREFIX)PdfReader$(SHARED_EXT)
DJVUFILE := $(LIBDIR)/$(LIB_PREFIX)DjVuFile$(SHARED_EXT)
XPSFILE := $(LIBDIR)/$(LIB_PREFIX)XpsFile$(SHARED_EXT)
HTMLFILE := $(LIBDIR)/$(LIB_PREFIX)HtmlFile$(SHARED_EXT)
UNICODECONVERTER := $(LIBDIR)/$(LIB_PREFIX)UnicodeConverter$(SHARED_EXT)
ASCDOCUMENTSCORE := $(LIBDIR)/$(LIB_PREFIX)ascdocumentscore$(SHARED_EXT)
LIBXML := $(LIBDIR)/$(LIB_PREFIX)libxml$(LIB_EXT)
LICENSEMANAGER := $(LIBDIR)/$(LIB_PREFIX)LicenceManager$(LIB_EXT)
OOXMLSIGNATURE := $(LIBDIR)/$(LIB_PREFIX)ooxmlsignature$(LIB_EXT)
TARGETS += $(ALLFONTSGEN)
TARGETS += $(X2T)
@ -86,6 +88,7 @@ TARGETS += $(UNICODECONVERTER)
TARGETS += $(ASCDOCUMENTSCORE)
TARGETS += $(LIBXML)
TARGETS += $(LICENSEMANAGER)
TARGETS += $(OOXMLSIGNATURE)
X2T_PRO := $(abspath X2tConverter/build/Qt/X2tSLN.pro)
HTMLFILEINTERNAL_PRO := $(abspath ../desktop-sdk/HtmlFile/Internal/Internal.pro)
@ -113,6 +116,7 @@ UNICODECONVERTER_PRO := $(abspath UnicodeConverter/UnicodeConverter.pro)
ASCDOCUMENTSCORE_PRO := $(abspath ../desktop-sdk/ChromiumBasedEditors/lib/AscDocumentsCore_$(PLATFORM).pro)
LIBXML_PRO := $(abspath DesktopEditor/xml/build/qt/libxml2.pro)
LICENSEMANAGER_PRO := $(abspath LicenceManager/linux/LicenseManager.pro)
OOXMLSIGNATURE_PRO := $(abspath DesktopEditor/xmlsec/src/ooxmlsignature.pro)
# PROS += $(basename $(X2T_PRO)).build
# PROS += ALLFONTSGEN_PRO
@ -163,6 +167,7 @@ QT_PROJ += UNICODECONVERTER
QT_PROJ += ASCDOCUMENTSCORE
QT_PROJ += LIBXML
QT_PROJ += LICENSEMANAGER
QT_PROJ += OOXMLSIGNATURE
# X2T_DEP += $(XLSFORMATLIB)
# X2T_DEP += $(ODFFILEWRITERLIB)
@ -211,6 +216,9 @@ ASCDOCUMENTSCORE_DEP += $(DJVUFILE)
ASCDOCUMENTSCORE_DEP += $(XPSFILE)
#ASCDOCUMENTSCORE_DEP += $(LICENSEMANAGER)
ASCDOCUMENTSCORE_DEP += $(LIBXML)
ASCDOCUMENTSCORE_DEP += $(OOXMLSIGNATURE)
OOXMLSIGNATURE_DEP += $(LIBXML)
PDFREADER_DEP += $(HTMLRENDERER)
@ -262,6 +270,8 @@ $(PDFREADER): $(PDFREADER_DEP)
$(PDFWRITER): $(PDFWRITER_DEP)
$(OOXMLSIGNATURE): $(OOXMLSIGNATURE_DEP)
%.build/Makefile: %.pro
mkdir -p $(dir $@) && cd $(dir $@) && qmake -r $<

View File

@ -12,9 +12,11 @@ int _tmain(int argc, _TCHAR* argv[])
std::wstring password = L"password";
ECMACryptFile crypt_file;
crypt_file.DecryptOfficeFile(srcFileName, dstFileName, password);
bool result, bDataIntegrity;
result = crypt_file.DecryptOfficeFile(srcFileName, dstFileName, password, bDataIntegrity);
crypt_file.EncryptOfficeFile(dstFileName, dstFileName2, password);
result = crypt_file.EncryptOfficeFile(dstFileName, dstFileName2, password);
return 0;
}

View File

@ -177,34 +177,40 @@ void CorrectHashSize(_buf & hashBuf, int size, unsigned char padding)
}
_buf Hmac(_buf & buf, CRYPT_METHOD::_hashAlgorithm algorithm, std::string & plain)
{
std::string mac;
if (algorithm == CRYPT_METHOD::SHA1)
{
CryptoPP::HMAC<CryptoPP::SHA1> hmac(buf.ptr, buf.size);
//return _buf(mac.BytePtr(), mac.SizeInBytes());
}
else if (algorithm == CRYPT_METHOD::SHA256)
{
CryptoPP::HMAC<CryptoPP::SHA256> hmac(buf.ptr, buf.size);
//return _buf(mac.BytePtr(), mac.SizeInBytes());
}
else if (algorithm == CRYPT_METHOD::SHA512)
{
CryptoPP::HMAC<CryptoPP::SHA512> hmac(buf.ptr, buf.size);
std::string mac;
CryptoPP::StringSource(plain, true,
new CryptoPP::HashFilter(hmac,
new CryptoPP::StringSink(mac)
) // HashFilter
); // StringSource
return _buf(mac);
}
else if (algorithm == CRYPT_METHOD::SHA256)
{
CryptoPP::HMAC<CryptoPP::SHA256> hmac(buf.ptr, buf.size);
CryptoPP::StringSource(plain, true,
new CryptoPP::HashFilter(hmac,
new CryptoPP::StringSink(mac)
) // HashFilter
); // StringSource
}
//else
return _buf();
else if (algorithm == CRYPT_METHOD::SHA512)
{
CryptoPP::HMAC<CryptoPP::SHA512> hmac(buf.ptr, buf.size);
CryptoPP::StringSource(plain, true,
new CryptoPP::HashFilter(hmac,
new CryptoPP::StringSink(mac)
) // HashFilter
); // StringSource
}
return _buf(mac);
}
@ -488,8 +494,10 @@ void ECMADecryptor::Decrypt(char* data , const size_t size, const unsigned long
}
}
}
bool ECMADecryptor::IsDataIntegrity(unsigned char* data, int size)
bool ECMADecryptor::CheckDataIntegrity(unsigned char* data, int size)
{
if (cryptData.bAgile == false) return true;
_buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8);
_buf pBlockHmacKey ((unsigned char*)encrDataIntegritySaltBlockKey, 8);
_buf pBlockHmacValue((unsigned char*)encrDataIntegrityHmacValueBlockKey, 8);
@ -514,15 +522,15 @@ bool ECMADecryptor::IsDataIntegrity(unsigned char* data, int size)
_buf iv2 = HashAppend(pDataSalt, pBlockHmacValue, cryptData.hashAlgorithm);
CorrectHashSize(iv2, cryptData.blockSize, 0x36);
_buf salt;
DecryptCipher(secretKey, iv1, pEncHmacKey, salt, cryptData.cipherAlgorithm);
_buf pSaltHmac;
DecryptCipher(secretKey, iv1, pEncHmacKey, pSaltHmac, cryptData.cipherAlgorithm);
_buf expected;
DecryptCipher(secretKey, iv2, pEncHmacValue, expected, cryptData.cipherAlgorithm);
std::string sData((char*)data, size);
_buf hmac = Hmac(salt, cryptData.hashAlgorithm, sData);
_buf hmac = Hmac(pSaltHmac, cryptData.hashAlgorithm, sData);
return (hmac == expected);
}
void ECMADecryptor::Decrypt(unsigned char* data_ptr, int data_size, unsigned char*& data_out)
@ -540,8 +548,6 @@ void ECMADecryptor::Decrypt(unsigned char* data_ptr, int data_size, unsigned ch
if (cryptData.bAgile)
{
bool isDataIntegrity = IsDataIntegrity(data_ptr, data_size);
_buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8);
_buf pDataSalt (cryptData.dataSaltValue);
_buf pKeyValue (cryptData.encryptedKeyValue);
@ -603,6 +609,7 @@ void ECMADecryptor::Decrypt(unsigned char* data_ptr, int data_size, unsigned ch
DecryptCipher(hashKey, empty, pInp, pOut, cryptData.cipherAlgorithm);
}
}
//-----------------------------------------------------------------------------------------------------------
ECMAEncryptor::ECMAEncryptor()
{
@ -611,6 +618,65 @@ ECMAEncryptor::ECMAEncryptor()
void ECMAEncryptor::SetPassword(std::wstring _password)
{
password = _password;
//---------
CryptoPP::RandomPool prng;
//сгенерить соль
CryptoPP::SecByteBlock seed_salt(cryptData.saltSize);
CryptoPP::OS_GenerateRandomBlock(false, seed_salt, seed_salt.size());
prng.IncorporateEntropy(seed_salt, seed_salt.size());
CryptoPP::SecByteBlock seed_datasalt(cryptData.saltSize);
CryptoPP::OS_GenerateRandomBlock(false, seed_datasalt, seed_datasalt.size());
prng.IncorporateEntropy(seed_datasalt, seed_datasalt.size());
//сгенерить ключ
CryptoPP::SecByteBlock seed_key(cryptData.keySize);
CryptoPP::OS_GenerateRandomBlock(false, seed_key, seed_key.size());
prng.IncorporateEntropy(seed_key, seed_key.size());
//сгенерить проверочный
CryptoPP::SecByteBlock seed_verify(cryptData.saltSize);
CryptoPP::OS_GenerateRandomBlock(false, seed_verify, seed_verify.size());
prng.IncorporateEntropy(seed_verify, seed_verify.size());
//---------
_buf pPassword (password);
_buf empty (NULL, 0, false);
_buf pBlockKey ((unsigned char*)encrKeyValueBlockKey, 8);
_buf pInputBlockKey ((unsigned char*)encrVerifierHashInputBlockKey, 8);
_buf pValueBlockKey ((unsigned char*)encrVerifierHashValueBlockKey, 8);
_buf pSalt (seed_salt.m_ptr, seed_salt.m_size);
_buf pDataSalt (seed_datasalt.m_ptr, seed_datasalt.m_size);
_buf pDecryptedKey (seed_key.m_ptr, seed_key.m_size);
//------------------------------------------------------------------------------------------------
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf pKeyValue;
EncryptCipher( agileKey, pSalt, pDecryptedKey, pKeyValue, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf decryptedVerifierHashInputBytes(seed_verify.m_ptr, seed_verify.m_size);
_buf verifierInputKey = GenerateAgileKey( pSalt, pPassword, pInputBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm );
_buf pEncVerInput;
EncryptCipher( verifierInputKey, pSalt, decryptedVerifierHashInputBytes, pEncVerInput, cryptData.cipherAlgorithm);
//--------------------------------------------
_buf decryptedVerifierHashBytes = HashAppend(decryptedVerifierHashInputBytes, empty, cryptData.hashAlgorithm);
_buf verifierHashKey = GenerateAgileKey(pSalt, pPassword, pValueBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf pEncVerValue;
EncryptCipher( verifierHashKey, pSalt, decryptedVerifierHashBytes, pEncVerValue, cryptData.cipherAlgorithm);
cryptData.saltValue = std::string((char*)pSalt.ptr, pSalt.size);
cryptData.dataSaltValue = std::string((char*)pDataSalt.ptr, pDataSalt.size);
cryptData.encryptedKeyValue = std::string((char*)pKeyValue.ptr, pKeyValue.size);
cryptData.encryptedVerifierInput = std::string((char*)pEncVerInput.ptr, pEncVerInput.size);
cryptData.encryptedVerifierValue = std::string((char*)pEncVerValue.ptr, pEncVerValue.size);
}
void ECMAEncryptor::SetCryptData(_ecmaCryptData & data)
@ -622,6 +688,7 @@ void ECMAEncryptor::GetCryptData(_ecmaCryptData &data)
{
data = cryptData;
}
void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size)
{
if (cryptData.bAgile == false) return;
@ -636,31 +703,41 @@ void ECMAEncryptor::UpdateDataIntegrity(unsigned char* data, int size)
_buf pDataSalt (cryptData.dataSaltValue);
_buf pKeyValue (cryptData.encryptedKeyValue);
_buf pEncHmacKey (cryptData.encryptedHmacKey);
_buf pEncHmacValue (cryptData.encryptedHmacValue);
//----
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
_buf secretKey;
DecryptCipher( agileKey, pSalt, pKeyValue, secretKey, cryptData.cipherAlgorithm);
//----
_buf iv1 = HashAppend(pDataSalt, pBlockHmacKey, cryptData.hashAlgorithm);
CorrectHashSize(iv1, cryptData.blockSize, 0x36);
_buf iv2 = HashAppend(pDataSalt, pBlockHmacValue, cryptData.hashAlgorithm);
CorrectHashSize(iv2, cryptData.blockSize, 0x36);
_buf salt;
DecryptCipher(secretKey, iv1, pEncHmacKey, salt, cryptData.cipherAlgorithm);
//----
CryptoPP::RandomPool prng;
CryptoPP::SecByteBlock seed(cryptData.hashSize);
CryptoPP::OS_GenerateRandomBlock(false, seed, seed.size());
prng.IncorporateEntropy(seed, seed.size());
_buf expected;
DecryptCipher(secretKey, iv2, pEncHmacValue, expected, cryptData.cipherAlgorithm);
_buf pSaltHmac(seed.m_ptr, seed.m_size);
std::string sData((char*)data, size);
_buf hmac = Hmac(salt, cryptData.hashAlgorithm, sData);
//return (hmac == expected);
_buf hmac = Hmac(pSaltHmac, cryptData.hashAlgorithm, sData);
_buf pEncHmacKey;
EncryptCipher(secretKey, iv1, pSaltHmac, pEncHmacKey, cryptData.cipherAlgorithm);
_buf pEncHmacValue;
EncryptCipher(secretKey, iv2, hmac, pEncHmacValue, cryptData.cipherAlgorithm);
cryptData.encryptedHmacKey = std::string((char*)pEncHmacKey.ptr, pEncHmacKey.size);
cryptData.encryptedHmacValue = std::string((char*)pEncHmacValue.ptr, pEncHmacValue.size);
}
int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*& data_out_ptr)
{
data_out_ptr = NULL;
@ -686,19 +763,17 @@ int ECMAEncryptor::Encrypt(unsigned char* data_inp_ptr, int size, unsigned char*
_buf pKeyValue (cryptData.encryptedKeyValue);
//------------------------------------------------------------------------------------------------
//соль нужно сгенерить
_buf agileKey = GenerateAgileKey( pSalt, pPassword, pBlockKey, cryptData.keySize, cryptData.spinCount, cryptData.hashAlgorithm);
//тут нужно именно дешифрованый генерить - пока их файла берем
_buf pDecryptedKey;
DecryptCipher( agileKey, pSalt, pKeyValue, pDecryptedKey, cryptData.cipherAlgorithm);
//зашифровать ключь
_buf pEncryptedKey;
EncryptCipher( agileKey, pSalt, pDecryptedKey, pEncryptedKey, cryptData.cipherAlgorithm);
////зашифровать ключь
//_buf pEncryptedKey;
//EncryptCipher( agileKey, pSalt, pDecryptedKey, pEncryptedKey, cryptData.cipherAlgorithm);
//??? pEncryptedKey == pKeyValue;
////??? pEncryptedKey == pKeyValue;
//-------------------------------------------------------------------------------------------------
_buf iv(cryptData.blockSize);

View File

@ -133,11 +133,12 @@ public:
virtual bool SetPassword (std::wstring password);
virtual bool IsVerify();
bool CheckDataIntegrity(unsigned char* data, int size);
void SetCryptData(_ecmaCryptData &data);
private:
bool IsDataIntegrity(unsigned char* data, int size);
std::wstring password;
_ecmaCryptData cryptData;
bool bVerify;

View File

@ -42,7 +42,7 @@
#include "../../ASCOfficeDocFile/DocDocxConverter/MemoryStream.h"
#include "simple_xml_writer.h"
CRYPT::_ecmaCryptData cryptDataGlobal;
//CRYPT::_ecmaCryptData cryptDataGlobal; for Test
using namespace CRYPT;
@ -489,19 +489,19 @@ bool ECMACryptFile::EncryptOfficeFile(std::wstring file_name_inp, std::wstring f
_ecmaCryptData cryptData;
cryptData.bAgile = true;
cryptData.hashAlgorithm = CRYPT_METHOD::SHA256;
cryptData.hashAlgorithm = CRYPT_METHOD::SHA512;
cryptData.keySize = 0x20;
cryptData.hashSize = 0x40;
cryptData.blockSize = 0x10;
cryptData.saltSize = 0x10;
ECMAEncryptor cryptor;
//cryptor.SetCryptData(cryptDataGlobal); //for test !!!
cryptor.SetCryptData(cryptData); //basic settings
cryptor.SetPassword(password);
cryptor.SetCryptData(cryptDataGlobal); //for test !!!
//cryptor.SetCryptData(cryptData); //basic settings
NSFile::CFileBinary file;
if (!file.OpenFile(file_name_inp)) return false;
@ -575,6 +575,9 @@ bool ECMACryptFile::EncryptOfficeFile(std::wstring file_name_inp, std::wstring f
{
unsigned char* data_out2 = NULL;
decryptor.Decrypt(data_out, lengthData, data_out2);
bool bDataIntegrity = decryptor.CheckDataIntegrity(data_out, lengthData);
NSFile::CFileBinary test;
test.CreateFileW(file_name_out + L"-back.oox");
@ -586,8 +589,10 @@ bool ECMACryptFile::EncryptOfficeFile(std::wstring file_name_inp, std::wstring f
return true;
}
bool ECMACryptFile::DecryptOfficeFile(std::wstring file_name_inp, std::wstring file_name_out, std::wstring password)
bool ECMACryptFile::DecryptOfficeFile(std::wstring file_name_inp, std::wstring file_name_out, std::wstring password, bool & bDataIntegrity)
{
bDataIntegrity = false;
POLE::Storage *pStorage = new POLE::Storage(file_name_inp.c_str());
if (!pStorage)return false;
@ -597,45 +602,10 @@ bool ECMACryptFile::DecryptOfficeFile(std::wstring file_name_inp, std::wstring f
delete pStorage;
return false;
}
_ecmaCryptData cryptData;
//-------------------------------------------------------------------------------------------
_ecmaCryptData cryptData;
bool result = false;
//------------------------------------------------------------------------
//{
// std::wstring f = file_name_out + L"-1.docx";
// POLE::Storage *pStorage1 = new POLE::Storage(f.c_str());
// pStorage1->open(true, true);
// POLE::Stream *pStrIn = new POLE::Stream(pStorage, "EncryptionInfo");
// POLE::uint64 sz = pStrIn->size();
// POLE::Stream *pStrOut = new POLE::Stream(pStorage1, "EncryptionInfo", true, sz);
// BYTE *d = new BYTE [sz];
// pStrIn->read(d, sz);
// pStrOut->write(d, sz);
// delete d;
// pStrOut->flush();
// delete pStrOut;
// delete pStrIn;
// pStrIn = new POLE::Stream(pStorage, "EncryptedPackage");
// sz = pStrIn->size();
// pStrOut = new POLE::Stream(pStorage1, "EncryptedPackage", true, sz);
// d = new BYTE [sz];
// pStrIn->read(d, sz);
// pStrOut->write(d, sz);
// delete d;
// pStrOut->flush();
// delete pStrOut;
// delete pStrIn;
// pStorage1->close();
// delete pStorage1;
//}
//----------------------------------------------------------------------------
POLE::Stream *pStream = new POLE::Stream(pStorage, "EncryptionInfo");
if (pStream)
@ -747,8 +717,6 @@ bool ECMACryptFile::DecryptOfficeFile(std::wstring file_name_inp, std::wstring f
lengthData = *((_UINT64*)data);
decryptor.Decrypt(data, readTrue, data_out);//todoo сделать покусочное чтение декриптование
delete pStream;
delete []data;
if (data_out)
{
@ -760,11 +728,16 @@ bool ECMACryptFile::DecryptOfficeFile(std::wstring file_name_inp, std::wstring f
delete []data_out;
result = true;
}
bDataIntegrity = decryptor.CheckDataIntegrity(data, readTrue);
delete pStream;
delete []data;
}
//-------------------------------------------------------------------
delete pStorage;
cryptDataGlobal = cryptData;
//cryptDataGlobal = cryptData; // for encrypt like sample & test
return result;
}

View File

@ -37,7 +37,7 @@
class ECMACryptFile
{
public:
bool DecryptOfficeFile(std::wstring file_name_inp, std::wstring file_name_out, std::wstring password);
bool DecryptOfficeFile(std::wstring file_name_inp, std::wstring file_name_out, std::wstring password, bool & bDataIntegrity);
bool EncryptOfficeFile(std::wstring file_name_inp, std::wstring file_name_out, std::wstring password);
struct _refComponent

View File

@ -138,22 +138,158 @@ namespace ParseAllCultureInfo
{
var index = aTemp[i];
if(nIndexD == index)
sShortDatePattern += "0";
else if (nIndexM == index)
sShortDatePattern += "1";
{
if (nIndexD + 1 < ShortDatePatternLower.Length && 'd' == ShortDatePatternLower[nIndexD + 1])
{
sShortDatePattern += "1";
}
else
{
sShortDatePattern += "0";
}
} else if (nIndexM == index)
{
if (nIndexM + 1 < ShortDatePatternLower.Length && 'm' == ShortDatePatternLower[nIndexM + 1])
{
sShortDatePattern += "3";
}
else
{
sShortDatePattern += "2";
}
}
else if (nIndexY == index)
sShortDatePattern += "2";
{
if (nIndexY + 2 < ShortDatePatternLower.Length && 'y' == ShortDatePatternLower[nIndexY + 2])
{
sShortDatePattern += "5";
}
else
{
sShortDatePattern += "4";
}
}
}
ShortDatePattern = sShortDatePattern;
}
}
static Dictionary<int, int> g_mapUsedValues = new Dictionary<int, int>() {
{4, 1},
{5, 1},
{7, 1},
{8, 1},
{9, 1},
{10, 1},
{11, 1},
{12, 1},
{16, 1},
{17, 1},
{18, 1},
{21, 1},
{22, 1},
{25, 1},
{31, 1},
{34, 1},
{36, 1},
{38, 1},
{42, 1},
{44, 1},
{1028, 1},
{1029, 1},
{1031, 1},
{1032, 1},
{1033, 1},
{1035, 1},
{1036, 1},
{1040, 1},
{1041, 1},
{1042, 1},
{1045, 1},
{1046, 1},
{1049, 1},
{1055, 1},
{1058, 1},
{1060, 1},
{1062, 1},
{1066, 1},
{1068, 1},
{2052, 1},
{2055, 1},
{2057, 1},
{2058, 1},
{2060, 1},
{2064, 1},
{2070, 1},
{2073, 1},
{2092, 1},
{3076, 1},
{3079, 1},
{3081, 1},
{3082, 1},
{3084, 1},
{4100, 1},
{4103, 1},
{4105, 1},
{4106, 1},
{4108, 1},
{5124, 1},
{5127, 1},
{5129, 1},
{5130, 1},
{5132, 1},
{6153, 1},
{6154, 1},
{6156, 1},
{7177, 1},
{7178, 1},
{7180, 1},
{8201, 1},
{8202, 1},
{8204, 1},
{9225, 1},
{9226, 1},
{9228, 1},
{10249, 1},
{10250, 1},
{10252, 1},
{11273, 1},
{11274, 1},
{11276, 1},
{12297, 1},
{12298, 1},
{12300, 1},
{13321, 1},
{13322, 1},
{13324, 1},
{14345, 1},
{14346, 1},
{14348, 1},
{15369, 1},
{15370, 1},
{15372, 1},
{16393, 1},
{16394, 1},
{17417, 1},
{17418, 1},
{18441, 1},
{18442, 1},
{19466, 1},
{20490, 1},
{21514, 1},
{22538, 1},
{23562, 1},
{29740, 1},
{30724, 1},
{30764, 1},
{31748, 1}
};
public static void parse()
{
List<int> aLcid = new List<int>();
Dictionary<int, CultureInfo> aInfos = new Dictionary<int, CultureInfo>();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
if (!aInfos.ContainsKey(ci.LCID))
if (!aInfos.ContainsKey(ci.LCID) && g_mapUsedValues.ContainsKey(ci.LCID))
{
aLcid.Add(ci.LCID);
aInfos[ci.LCID] = ci;

View File

@ -7,7 +7,7 @@
QT -= core
QT -= gui
VERSION = 2.4.462.0
VERSION = 2.4.463.0
DEFINES += INTVER=$$VERSION
TARGET = x2t

View File

@ -1457,14 +1457,21 @@ namespace NExtractTools
int mscrypt2oox (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params)
{
std::wstring password = params.getPassword();
//decrypt to sTo
ECMACryptFile cryptReader;
if (cryptReader.DecryptOfficeFile(sFrom, sTo, password) == false)
bool bDataIntegrity = false;
if (cryptReader.DecryptOfficeFile(sFrom, sTo, password, bDataIntegrity) == false)
{
if (password.empty()) return AVS_FILEUTILS_ERROR_CONVERT_DRM;
else return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD;
}
if (bDataIntegrity == false)
{
//было несанкционированое вешательство в файл
}
return S_OK;
}
int mscrypt2oot_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params)
@ -1473,9 +1480,16 @@ namespace NExtractTools
std::wstring sResultDecryptFile = sTemp + FILE_SEPARATOR_STR + L"uncrypt_file.oox";
ECMACryptFile cryptReader;
if (cryptReader.DecryptOfficeFile(sFrom, sResultDecryptFile, params.getPassword()) == false)
bool bDataIntegrity = false;
if (cryptReader.DecryptOfficeFile(sFrom, sResultDecryptFile, params.getPassword(), bDataIntegrity) == false)
return AVS_FILEUTILS_ERROR_CONVERT_PASSWORD;
if (bDataIntegrity == false)
{
//было несанкционированое вешательство в файл
}
COfficeFileFormatChecker OfficeFileFormatChecker;
if (OfficeFileFormatChecker.isOfficeFile(sResultDecryptFile))
@ -1500,6 +1514,19 @@ namespace NExtractTools
}
return AVS_FILEUTILS_ERROR_CONVERT;
}
int oox2mscrypt (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params)
{
std::wstring password = params.getPassword();
ECMACryptFile cryptReader;
if (cryptReader.EncryptOfficeFile(sFrom, sTo, password) == false)
{
return AVS_FILEUTILS_ERROR_CONVERT;
}
return S_OK;
}
int fromMscrypt (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring & sTemp, InputParams& params)
{
std::wstring password = params.getPassword();
@ -1556,7 +1583,7 @@ namespace NExtractTools
}
return nRes;
}
//html
//html
int html2doct_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
std::vector<std::wstring> arFiles;

View File

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

View File

@ -544,7 +544,7 @@ namespace NExtractTools
}
sRes = L"<xmlOptions><fileOptions fileType='" + std::to_wstring(nFileType);
sRes += L"' codePage='" + std::to_wstring(nCsvEncoding);
sRes += L"' delimiter='" + XmlUtils::EncodeXmlString(cDelimiter) + L"' " + sSaveType;
sRes += L"' delimiter='" + XmlUtils::EncodeXmlStringExtend(cDelimiter) + L"' " + sSaveType;
sRes += L"/><TXTOptions><Encoding>" + std::to_wstring(nCsvEncoding) + L"</Encoding></TXTOptions></xmlOptions>";
return sRes;