Compare commits

..

4 Commits

Author SHA1 Message Date
1839350526 . 2017-04-24 19:57:38 +03:00
d7587e91b1 windows sign 2017-04-24 18:57:37 +03:00
7b0a342cf9 . 2017-04-24 17:49:47 +03:00
3d01b0782e . 2017-04-24 15:30:57 +03:00
8 changed files with 346 additions and 87 deletions

View File

@ -336,6 +336,7 @@ void odf_drawing_context::set_background_state(bool Val)
impl_->is_background_ = Val;
impl_->current_graphic_properties = new graphic_format_properties();
start_area_properties();
}
void odf_drawing_context::check_anchor()
@ -473,6 +474,7 @@ void odf_drawing_context::start_drawing()
}
void odf_drawing_context::end_drawing_background(odf_types::common_draw_fill_attlist & common_draw_attlist)
{
end_area_properties();
if (impl_->current_drawing_state_.elements_.empty() == false) return;
if (!impl_->is_background_ || !impl_->current_graphic_properties) return;
@ -491,15 +493,13 @@ void odf_drawing_context::end_drawing()
draw_base* draw = dynamic_cast<draw_base*>(impl_->current_drawing_state_.elements_[0].elm.get());
if (draw)
{
if (impl_->is_presentation_)
if (impl_->current_drawing_state_.presentation_class_ || impl_->current_drawing_state_.presentation_placeholder_)
{
_CP_OPT(std::wstring) draw_layer;
if (impl_->is_presentation_.get() == true)
{//master
draw_layer = L"backgroundobjects";
//if (impl_->current_drawing_state_.presentation_class_)
// draw_layer = L"backgroundobjects";
//else draw_layer = L"layout";
if (!impl_->current_drawing_state_.presentation_class_)
impl_->current_drawing_state_.presentation_class_ = presentation_class::outline;
@ -1186,10 +1186,14 @@ void odf_drawing_context::set_shadow(int type, std::wstring hexColor, _CP_OPT(do
void odf_drawing_context::set_placeholder_id (std::wstring val)
{
if (!impl_->is_presentation_) return;
impl_->current_drawing_state_.presentation_placeholder_ = val;
}
void odf_drawing_context::set_placeholder_type (int val)
{
if (!impl_->is_presentation_) return;
switch(val)
{
case 0: impl_->current_drawing_state_.presentation_class_ = presentation_class::outline; break;

View File

@ -433,6 +433,8 @@ void OoxConverter::convert(PPTX::Logic::Shape *oox_shape)
{
if (oox_shape == NULL) return;
_CP_OPT(bool) bMasterPresentation = odf_context()->drawing_context()->get_presentation();
odf_context()->drawing_context()->start_drawing();
int type = 1000; //custom
@ -448,7 +450,8 @@ void OoxConverter::convert(PPTX::Logic::Shape *oox_shape)
type = preset.GetValue();
}
if (type == SimpleTypes::shapetypeRect && oox_shape->txBody.IsInit()) type = 2000;
if (type == SimpleTypes::shapetypeRect && oox_shape->txBody.IsInit())
type = 2000;
if (type == 2000 && oox_shape->txBody->bodyPr.IsInit()
&& oox_shape->txBody->bodyPr->fromWordArt.get_value_or(false))

View File

@ -130,6 +130,8 @@ bool OoxConverter::UpdateProgress(long nComplete)
void OoxConverter::set_fonts_directory(const std::wstring &fontsPath)
{
if (odf_context() == NULL) return;
odf_context()->set_fonts_directory(fontsPath);
}

View File

@ -60,7 +60,18 @@ namespace Oox2Odf
{
PptxConverter::PptxConverter(const std::wstring & path, const ProgressCallback* CallBack)
{
const OOX::CPath oox_path(std::wstring(path.c_str()));
current_clrMap = NULL;
current_slide = NULL;
current_theme = NULL;
current_tableStyles = NULL;
presentation = NULL;
output_document = NULL;
odp_context = NULL;
pCallBack = CallBack;
const OOX::CPath oox_path(std::wstring(path.c_str()));
pptx_document = new PPTX::Folder();
if (!pptx_document->isValid(oox_path.GetPath())) // true ???
@ -82,13 +93,6 @@ PptxConverter::PptxConverter(const std::wstring & path, const ProgressCallback*
output_document = new odf_writer::package::odf_document(L"presentation");
odp_context = new odf_writer::odp_conversion_context(output_document);
current_clrMap = NULL;
current_slide = NULL;
current_theme = NULL;
current_tableStyles = NULL;
pCallBack = CallBack;
if (UpdateProgress(290000))return;
}
PptxConverter::~PptxConverter()
@ -339,7 +343,7 @@ void PptxConverter::convert_slides()
current_slide = slide->Master.operator->();
if (bShowLayoutMasterSp && bShowMasterSp)
convert_slide(&slide->Master->cSld, current_txStyles, false);
convert_slide(&slide->Master->cSld, current_txStyles, false, true);
else
convert(slide->Master->cSld.bg.GetPointer());
@ -347,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);
convert_slide(&slide->Layout->cSld, current_txStyles, true, bShowLayoutMasterSp);
//add note master
odp_context->end_master_slide();
@ -387,7 +391,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);
convert_slide (slide->cSld.GetPointer(), current_txStyles, true, bShowMasterSp);
convert (slide->comments.operator->());
convert (slide->Note.operator->());
@ -943,7 +947,7 @@ void PptxConverter::convert(PPTX::Logic::Bg *oox_background)
odp_context->end_drawings();
}
void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders)
void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders, bool bFillUp)
{
if (oox_slide == NULL) return;
@ -966,14 +970,15 @@ void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxS
{
if (pShape->nvSpPr.nvPr.ph.is_init())
{
pShape->FillLevelUp();
if (bFillUp)
pShape->FillLevelUp();
if (pShape->nvSpPr.nvPr.ph->type.IsInit())
{
int ph_type = pShape->nvSpPr.nvPr.ph->type->GetBYTECode();
if (!bMaster && (ph_type == 5 || ph_type == 6 || ph_type == 7 || ph_type == 12))
continue;
//if (!bMaster && (ph_type == 5 || ph_type == 6 || ph_type == 7 || ph_type == 12))
// continue;
odf_context()->drawing_context()->set_placeholder_type(ph_type);
}

View File

@ -106,7 +106,7 @@ namespace Oox2Odf
void convert(OOX::WritingElement *oox_unknown);
void convert_slide (PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders = true);
void convert_slide (PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxStyles* txStyles, bool bPlaceholders, bool bFillUp);
void convert_layout (PPTX::Logic::CSld *oox_slide);
void convert (PPTX::Comments *oox_comments);
void convert (PPTX::NotesSlide *oox_note);

View File

@ -160,7 +160,8 @@ namespace PPTX
if (pShape->nvSpPr.nvPr.ph->idx.IsInit())
{
//not found in layout !! 100818_건강보험과_보건의료_김용익_최종.pptx
if (Master.IsInit())
bool bShapeMaster = showMasterSp.get_value_or(true);
if (Master.IsInit() && bShapeMaster)
{
Master->GetLevelUp(pShape);
}

View File

@ -45,7 +45,8 @@
#include <windows.h>
#endif
#define U_TO_UTF8(val) NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(val.c_str(), val.length())
#define U_TO_UTF8(val) NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(val.c_str(), (LONG)val.length())
#define UTF8_TO_U(val) NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)val.c_str(), (LONG)val.length())
#if defined(__linux__) || defined(_MAC) && !defined(_IOS)
#include <unistd.h>

View File

@ -7,11 +7,14 @@
#include <string>
#include "../../../common/File.h"
#include "../../../common/Directory.h"
#include "../../../common/BigInteger.h"
#include "../../../xml/include/xmlutils.h"
#include "../../../xml/libxml2/include/libxml/c14n.h"
#include <vector>
#pragma comment (lib, "crypt32.lib")
#pragma comment (lib, "cryptui.lib")
#pragma comment (lib, "Advapi32.lib")
@ -170,7 +173,7 @@ public:
return sReturn;
}
std::string GetHash(std::string& sXml)
std::string GetHash(BYTE* pData, DWORD dwSize)
{
BOOL bResult = TRUE;
DWORD dwKeySpec = 0;
@ -186,7 +189,7 @@ public:
if (!bResult)
return "";
bResult = CryptHashData(hHash, (BYTE*)sXml.c_str(), (DWORD)sXml.length(), 0);
bResult = CryptHashData(hHash, pData, dwSize, 0);
if (!bResult)
{
CryptDestroyHash(hHash);
@ -206,11 +209,11 @@ public:
bResult = CryptGetHashParam(hHash, HP_HASHVAL, pDataHashRaw, &cbHashSize, 0);
delete[] pDataHashRaw;
CryptDestroyHash(hHash);
if (!bResult)
{
CryptDestroyHash(hHash);
return "";
}
char* pBase64_hash = NULL;
int nBase64Len_hash = 0;
@ -219,21 +222,19 @@ public:
std::string sReturn(pBase64_hash, nBase64Len_hash);
delete [] pBase64_hash;
//delete [] pDataHashRaw;
CryptDestroyHash(hHash);
return sReturn;
}
std::string GetHash(std::string& sXml)
{
return GetHash((BYTE*)sXml.c_str(), (DWORD)sXml.length());
}
std::string GetHash(std::wstring& sXmlFile)
{
BOOL bResult = TRUE;
DWORD dwKeySpec = 0;
HCRYPTHASH hHash = NULL;
if (NULL == m_hCryptProv)
bResult = CryptAcquireCertificatePrivateKey(m_context, 0, NULL, &m_hCryptProv, &dwKeySpec, NULL);
if (!bResult)
return "";
BYTE* pFileData = NULL;
DWORD dwFileDataLen = 0;
NSFile::CFileBinary::ReadAllBytes(sXmlFile, &pFileData, dwFileDataLen);
@ -241,50 +242,9 @@ public:
if (0 == dwFileDataLen)
return "";
bResult = CryptCreateHash(m_hCryptProv, CALG_SHA1, 0, 0, &hHash);
if (!bResult)
{
RELEASEARRAYOBJECTS(pFileData);
return "";
}
bResult = CryptHashData(hHash, pFileData, dwFileDataLen, 0);
if (!bResult)
{
RELEASEARRAYOBJECTS(pFileData);
CryptDestroyHash(hHash);
return "";
}
DWORD cbHashSize = 0, dwCount = sizeof(DWORD);
bResult = CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE*)&cbHashSize, &dwCount, 0);
if (!bResult)
{
RELEASEARRAYOBJECTS(pFileData);
CryptDestroyHash(hHash);
return "";
}
std::string sReturn = GetHash(pFileData, dwFileDataLen);
RELEASEARRAYOBJECTS(pFileData);
BYTE* pDataHashRaw = new BYTE[dwCount];
bResult = CryptGetHashParam(hHash, HP_HASHVAL, pDataHashRaw, &cbHashSize, 0);
delete[] pDataHashRaw;
CryptDestroyHash(hHash);
if (!bResult)
return "";
char* pBase64_hash = NULL;
int nBase64Len_hash = 0;
NSFile::CBase64Converter::Encode(pDataHashRaw, (int)cbHashSize, pBase64_hash, nBase64Len_hash, NSBase64::B64_BASE64_FLAG_NOCRLF);
std::string sReturn(pBase64_hash, nBase64Len_hash);
delete [] pBase64_hash;
return sReturn;
}
@ -320,7 +280,7 @@ public:
bResult = CryptHashData(hHash, (BYTE*)sXml.c_str(), (DWORD)sXml.length(), 0);
// Get the public key from the certificate
CryptImportPublicKeyInfo(m_hCryptProv, PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, &m_context->pCertInfo->SubjectPublicKeyInfo, &hPubKey);
CryptImportPublicKeyInfo(m_hCryptProv, m_context->dwCertEncodingType, &m_context->pCertInfo->SubjectPublicKeyInfo, &hPubKey);
BOOL bResultRet = CryptVerifySignature(hHash, pDataHashMem, dwHashLen, hPubKey, NULL, 0);
@ -333,8 +293,23 @@ public:
return bResultRet && bResult;
}
private:
void ConvertEndian(const BYTE* src, BYTE* dst, DWORD size)
std::string GetCertificateBase64()
{
char* pData = NULL;
int nDataLen = 0;
NSFile::CBase64Converter::Encode(m_context->pbCertEncoded, (int)m_context->cbCertEncoded, pData, nDataLen, NSBase64::B64_BASE64_FLAG_NOCRLF);
std::string sReturn(pData, nDataLen);
RELEASEARRAYOBJECTS(pData);
return sReturn;
}
std::string GetCertificateHash()
{
return GetHash(m_context->pbCertEncoded, (int)m_context->cbCertEncoded);
}
public:
static void ConvertEndian(const BYTE* src, BYTE* dst, DWORD size)
{
for(BYTE* p = dst + size - 1; p >= dst; ++src, --p)
(*p) = (*src);
@ -346,6 +321,7 @@ void MyHandleError(char *s);
bool Sign(PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSignatureFile);
bool Verify(PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSignatureFile);
bool SignDocument(std::wstring sFolderOOXML, PCCERT_CONTEXT pCertContext);
void main(void)
{
@ -653,10 +629,19 @@ void main(void)
MyHandleError("Select UI failed." );
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool bRes = true;
bRes = Sign(pCertContext, NSFile::GetProcessDirectory() + L"/test.xml", NSFile::GetProcessDirectory() + L"/result.txt");
bRes = Verify(pCertContext, NSFile::GetProcessDirectory() + L"/test.xml", NSFile::GetProcessDirectory() + L"/result.txt");
if (false)
{
bool bRes = true;
bRes = Sign(pCertContext, NSFile::GetProcessDirectory() + L"/test.xml", NSFile::GetProcessDirectory() + L"/result.txt");
bRes = Verify(pCertContext, NSFile::GetProcessDirectory() + L"/test.xml", NSFile::GetProcessDirectory() + L"/result.txt");
CXmlSigner oSigner(pCertContext);
std::string sCertBase64 = oSigner.GetCertificateBase64();
std::string sCertHash = oSigner.GetCertificateHash();
}
SignDocument(NSFile::GetProcessDirectory() + L"/ImageStamp", pCertContext);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CertFreeCertificateContext(pCertContext);
@ -705,7 +690,265 @@ bool Verify(PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSi
return (TRUE == oSigner.Verify(sXmlUtf8Prepare, sXmlUtf8Signature));
}
class COOXMLSigner
{
public:
PCCERT_CONTEXT m_context;
std::wstring m_sFolder;
CXmlSigner* m_signer;
public:
COOXMLSigner(const std::wstring& sFolder, PCCERT_CONTEXT pContext)
{
m_sFolder = sFolder;
m_context = pContext;
m_signer = new CXmlSigner(pContext);
}
~COOXMLSigner()
{
RELEASEOBJECT(m_signer);
}
std::wstring GetReference(const std::wstring& file, const std::wstring& content_type)
{
std::wstring sXml = L"<Reference URI=\">" + file + L"?ContentType=" + content_type + L"\">";
sXml += L"<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>";
sXml += L"<DigestValue>";
sXml += UTF8_TO_U(m_signer->GetHash(m_sFolder + file));
sXml += L"</DigestValue>";
sXml += L"</Reference>";
return sXml;
}
std::string GetHashXml(const std::wstring& xml)
{
std::string sXmlSigned = U_TO_UTF8(xml);
sXmlSigned = CXmlCanonicalizator::Execute(sXmlSigned, XML_C14N_1_0);
return m_signer->GetHash(sXmlSigned);
}
std::string GetReferenceMain(const std::wstring& xml, const std::wstring& id, const bool& isCannon = true)
{
std::wstring sXml1 = L"<Object xmlns=\"http://www.w3.org/2000/09/xmldsig#\"";
if (id.empty())
sXml1 += L">";
else
sXml1 += (L" Id=\"#" + id + L"\">");
sXml1 += xml;
sXml1 += L"</Object>";
std::string sHash = GetHashXml(sXml1);
std::string sRet;
if (isCannon)
sRet = "<Transforms><Transform Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/></Transforms>";
sRet += ("<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>" + sHash + "</DigestValue>");
return sRet;
}
std::wstring GetImageBase64(const std::wstring& file)
{
BYTE* pData = NULL;
DWORD dwLen = 0;
if (!NSFile::CFileBinary::ReadAllBytes(file, &pData, dwLen))
return L"";
char* pDataC = NULL;
int nLen = 0;
NSFile::CBase64Converter::Encode(pData, (int)dwLen, pDataC, nLen, NSBase64::B64_BASE64_FLAG_NOCRLF);
std::wstring sReturn = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(pDataC, (LONG)nLen, FALSE);
RELEASEARRAYOBJECTS(pData);
RELEASEARRAYOBJECTS(pDataC);
return sReturn;
}
};
bool SignDocument(std::wstring sFolderOOXML, PCCERT_CONTEXT pCertContext)
{
std::wstring sFolder = NSFile::GetProcessDirectory();
COOXMLSigner oOOXMLSigner(sFolderOOXML, pCertContext);
std::string sSignedData;
std::wstring sXmlData;
std::wstring sDataSign = L"2017-04-21T08:30:21Z";
sSignedData += "<CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>\
<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>";
if (true)
{
// idPackageObject
std::wstring sXml = L"<Manifect>";
// TODO: rels
sXml += oOOXMLSigner.GetReference(L"/word/document.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
sXml += oOOXMLSigner.GetReference(L"/word/fontTable.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml");
sXml += oOOXMLSigner.GetReference(L"/word/settings.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml");
sXml += oOOXMLSigner.GetReference(L"/word/styles.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml");
sXml += oOOXMLSigner.GetReference(L"/word/theme/theme1.xml", L"application/vnd.openxmlformats-officedocument.theme+xml");
sXml += oOOXMLSigner.GetReference(L"/word/webSettings.xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml");
sXml += L"</Manifect>";
sXml += L"<SignatureProperties><SignatureProperty Id=\"idSignatureTime\" Target=\"#idPackageSignature\">";
sXml += (L"<mdssi:SignatureTime xmlns:mdssi=\"http://schemas.openxmlformats.org/package/2006/digital-signature\">\
<mdssi:Format>YYYY-MM-DDThh:mm:ssTZD</mdssi:Format>\
<mdssi:Value>" + sDataSign + L"</mdssi:Value>\
</mdssi:SignatureTime></SignatureProperty></SignatureProperties>");
sXmlData += (L"<Object Id=\"idPackageObject\">" + sXml + L"</Object>");
sSignedData += ("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idPackageObject\">" +
oOOXMLSigner.GetReferenceMain(sXml, L"idPackageObject") + "</Reference>");
}
std::wstring sImageValid = oOOXMLSigner.GetImageBase64(sFolder + L"/../../../resources/valid.png");
std::wstring sImageInValid = oOOXMLSigner.GetImageBase64(sFolder + L"/../../../resources/invalid.png");
if (true)
{
// idOfficeObject
std::wstring sXml = L"<SignatureProperties>\
<SignatureProperty Id=\"idOfficeV1Details\" Target=\"#idPackageSignature\">\
<SignatureInfoV1 xmlns=\"http://schemas.microsoft.com/office/2006/digsig\">\
<SetupID>{39B6B9C7-60AD-45A2-9F61-40C74A24042E}</SetupID>\
<SignatureText></SignatureText>\
<SignatureImage>" + sImageValid + L"</SignatureImage>\
<SignatureComments/>\
<WindowsVersion>10.0</WindowsVersion>\
<OfficeVersion>16.0</OfficeVersion>\
<ApplicationVersion>16.0</ApplicationVersion>\
<Monitors>2</Monitors>\
<HorizontalResolution>1680</HorizontalResolution>\
<VerticalResolution>1050</VerticalResolution>\
<ColorDepth>32</ColorDepth>\
<SignatureProviderId>{00000000-0000-0000-0000-000000000000}</SignatureProviderId>\
<SignatureProviderUrl/>\
<SignatureProviderDetails>9</SignatureProviderDetails>\
<SignatureType>2</SignatureType>\
</SignatureInfoV1>\
</SignatureProperty>\
</SignatureProperties>";
sXmlData += (L"<Object Id=\"idOfficeObject\">" + sXml + L"</Object>");
sSignedData += ("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idOfficeObject\">" +
oOOXMLSigner.GetReferenceMain(sXml, L"idOfficeObject") + "</Reference>");
}
if (true)
{
DWORD dwNameLen = CertGetNameStringW(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, NULL, 0);
wchar_t* pNameData = new wchar_t[dwNameLen];
CertGetNameStringW(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, pNameData, dwNameLen);
std::wstring sName(pNameData);
RELEASEARRAYOBJECTS(pNameData);
int nNumberLen = (int)pCertContext->pCertInfo->SerialNumber.cbData;
BYTE* pNumberData = new BYTE[nNumberLen];
CXmlSigner::ConvertEndian(pCertContext->pCertInfo->SerialNumber.pbData, pNumberData, (DWORD)nNumberLen);
CBigInteger oInteger(pNumberData, nNumberLen);
delete[] pNumberData;
std::string sKeyA = oInteger.ToString();
std::wstring sKey = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sKeyA.c_str(), (LONG)sKeyA.length());
std::wstring sXml = (L"<xd:SignedSignatureProperties>\
<xd:SigningTime>" + sDataSign + L"</xd:SigningTime>\
<xd:SigningCertificate>\
<xd:Cert>\
<xd:CertDigest>\
<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/>\
<DigestValue>MJJT2Y0iMxaPGVXBmOLb9bY60pA=</DigestValue>\
</xd:CertDigest>\
<xd:IssuerSerial>\
<X509IssuerName>CN=" + sName + L"</X509IssuerName>\
<X509SerialNumber>" + sKey + L"</X509SerialNumber>\
</xd:IssuerSerial>\
</xd:Cert>\
</xd:SigningCertificate>\
<xd:SignaturePolicyIdentifier>\
<xd:SignaturePolicyImplied/>\
</xd:SignaturePolicyIdentifier>\
</xd:SignedSignatureProperties>");
std::wstring sSignedXml = L"<xd:SignedProperties xmlns=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:xd=\"http://uri.etsi.org/01903/v1.3.2#\" Id=\"idSignedProperties\">";
sSignedXml += sXml;
sSignedXml += L"</xd:SignedProperties>";
sXmlData += L"<Object><xd:QualifyingProperties xmlns:xd=\"http://uri.etsi.org/01903/v1.3.2#\" Target=\"#idPackageSignature\">\
<xd:SignedProperties Id=\"idSignedProperties\">";
sXmlData += sXml;
sXmlData += L"</xd:SignedProperties></xd:QualifyingProperties></Object>";
sSignedData += "<Reference Type=\"http://uri.etsi.org/01903#SignedProperties\" URI=\"#idSignedProperties\">\
<Transforms><Transform Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/></Transforms>\
<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>";
std::string sXmlTmp = CXmlCanonicalizator::Execute(U_TO_UTF8(sSignedXml), XML_C14N_1_0);
sSignedData += oOOXMLSigner.m_signer->GetHash(sXmlTmp);
sSignedData += "</DigestValue></Reference>";
}
if (true)
{
std::wstring sXml = sImageValid;
sXmlData += (L"<Object Id=\"idValidSigLnImg\">" + sXml + L"</Object>");
sSignedData += ("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idValidSigLnImg\">" +
oOOXMLSigner.GetReferenceMain(sXml, L"idValidSigLnImg", false) + "</Reference>");
}
if (true)
{
std::wstring sXml = sImageInValid;
sXmlData += (L"<Object Id=\"idInvalidSigLnImg\">" + sXml + L"</Object>");
sSignedData += ("<Reference Type=\"http://www.w3.org/2000/09/xmldsig#Object\" URI=\"#idInvalidSigLnImg\">" +
oOOXMLSigner.GetReferenceMain(sXml, L"idInvalidSigLnImg", false) + "</Reference>");
}
std::string sXmlPrepend = ("<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\" Id=\"idPackageSignature\"><SignedInfo>");
sXmlPrepend += sSignedData;
sXmlPrepend += "</SignedInfo>";
sXmlPrepend += "<SignatureValue>";
sXmlPrepend += oOOXMLSigner.m_signer->Sign("<SignedInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + sSignedData + "</SignedInfo>");
sXmlPrepend += "</SignatureValue>";
sXmlPrepend += ("<KeyInfo><X509Data><X509Certificate>" + oOOXMLSigner.m_signer->GetCertificateBase64() + "</X509Certificate></X509Data></KeyInfo>");
sXmlData = (UTF8_TO_U(sXmlPrepend) + sXmlData);
sXmlData += L"</Signature>";
std::wstring sDirectory = sFolderOOXML + L"/_xmlsignatures";
NSDirectory::CreateDirectory(sDirectory);
NSFile::CFileBinary oFile;
oFile.CreateFileW(sDirectory + L"/origin.sigs");
oFile.CloseFile();
NSFile::CFileBinary::SaveToFile(sDirectory + L"/sig1.xml", sXmlData, true);
NSDirectory::CreateDirectory(sDirectory + L"/_rels");
std::wstring sRels = L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\
<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\
<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature\" Target=\"sig1.xml\"/>\
</Relationships>";
NSFile::CFileBinary::SaveToFile(sDirectory + L"/_rels/origin.sigs.rels", sRels, true);
return true;
}