mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 02:48:12 +08:00
.
This commit is contained in:
120
DesktopEditor/xmlsec/src/OOXMLVerifier.h
Normal file
120
DesktopEditor/xmlsec/src/OOXMLVerifier.h
Normal file
@ -0,0 +1,120 @@
|
||||
#ifndef _XML_OOXMLVERIFIER_H_
|
||||
#define _XML_OOXMLVERIFIER_H_
|
||||
|
||||
#include "./XmlCanonicalizator.h"
|
||||
#include "./XmlSignerBase.h"
|
||||
#include "./XmlTransform.h"
|
||||
|
||||
#define OOXML_SIGNATURE_VALID 0
|
||||
#define OOXML_SIGNATURE_INVALID 1
|
||||
#define OOXML_SIGNATURE_NOTSUPPORTED 2
|
||||
|
||||
class COOXMLSignature
|
||||
{
|
||||
private:
|
||||
int m_valid;
|
||||
std::string m_guid;
|
||||
ICertificate* m_cert;
|
||||
|
||||
std::string m_sImageValidBase64;
|
||||
std::string m_sImageInvalidBase64;
|
||||
|
||||
private:
|
||||
XmlUtils::CXmlNode m_node; // signature file
|
||||
|
||||
public:
|
||||
COOXMLSignature()
|
||||
{
|
||||
m_valid = OOXML_SIGNATURE_INVALID;
|
||||
m_guid = "";
|
||||
m_cert = NULL;
|
||||
}
|
||||
~COOXMLSignature()
|
||||
{
|
||||
RELEASEOBJECT(m_cert);
|
||||
}
|
||||
|
||||
public:
|
||||
int GetValid()
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
std::string GetGuid()
|
||||
{
|
||||
return m_guid;
|
||||
}
|
||||
ICertificate* GetCertificate()
|
||||
{
|
||||
return m_cert;
|
||||
}
|
||||
std::string GetImageValidBase64()
|
||||
{
|
||||
return m_sImageValidBase64;
|
||||
}
|
||||
std::string GetImageInvalidBase64()
|
||||
{
|
||||
return m_sImageInvalidBase64;
|
||||
}
|
||||
|
||||
public:
|
||||
void Check();
|
||||
|
||||
friend class COOXMLVerifier;
|
||||
};
|
||||
|
||||
class COOXMLVerifier
|
||||
{
|
||||
public:
|
||||
std::wstring m_sFolder;
|
||||
std::vector<COOXMLSignature*> m_arSignatures;
|
||||
|
||||
public:
|
||||
COOXMLVerifier(const std::wstring& sFolder)
|
||||
{
|
||||
m_sFolder = sFolder;
|
||||
|
||||
if (!NSFile::CFileBinary::Exists(m_sFolder + L"/_xmlsignatures/origin.sigs"))
|
||||
return;
|
||||
|
||||
XmlUtils::CXmlNode oContentTypes;
|
||||
if (!oContentTypes.FromXmlFile(m_sFolder + L"/[Content_Types].xml"))
|
||||
return;
|
||||
|
||||
XmlUtils::CXmlNodes oOverrides = oContentTypes.GetNodes(L"Override");
|
||||
int nCount = oOverrides.GetCount();
|
||||
|
||||
for (int i = 0; i < nCount; i++)
|
||||
{
|
||||
XmlUtils::CXmlNode node;
|
||||
oOverrides.GetAt(i, node);
|
||||
|
||||
if (node.GetAttributeA("ContentType") != "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml")
|
||||
continue;
|
||||
|
||||
std::wstring sFile = m_sFolder + node.GetAttribute("PartName");
|
||||
XmlUtils::CXmlNode nodeSig;
|
||||
if (!nodeSig.FromXmlFile(sFile))
|
||||
continue;
|
||||
|
||||
if (nodeSig.GetName() != L"Signature")
|
||||
continue;
|
||||
|
||||
COOXMLSignature* pSignature = new COOXMLSignature();
|
||||
pSignature->m_node = nodeSig;
|
||||
pSignature->Check();
|
||||
|
||||
m_arSignatures.push_back(pSignature);
|
||||
}
|
||||
}
|
||||
~COOXMLVerifier()
|
||||
{
|
||||
for (std::vector<COOXMLSignature*>::iterator i = m_arSignatures.begin(); i != m_arSignatures.end(); i++)
|
||||
{
|
||||
COOXMLSignature* v = *i;
|
||||
RELEASEOBJECT(v);
|
||||
}
|
||||
m_arSignatures.clear();
|
||||
}
|
||||
};
|
||||
|
||||
#endif //_XML_OOXMLVERIFIER_H_
|
||||
17
DesktopEditor/xmlsec/src/XmlCertificate.h
Normal file
17
DesktopEditor/xmlsec/src/XmlCertificate.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef _XMLSIGNER_CERTIFICATE_H_
|
||||
#define _XMLSIGNER_CERTIFICATE_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#include "XmlSigner_mscrypto.h"
|
||||
#define CCertificate CCertificate_mscrypto
|
||||
#endif
|
||||
|
||||
#if defined(_LINUX) && !defined(_MAC)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MAC
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _XMLSIGNER_CERTIFICATE_H_
|
||||
@ -1,5 +1,6 @@
|
||||
#include "../../src/XmlSigner_mscrypto.h"
|
||||
#include "../../src/XmlCertificate.h"
|
||||
#include "../../src/OOXMLSigner.h"
|
||||
#include "../../src/OOXMLVerifier.h"
|
||||
|
||||
#pragma comment (lib, "crypt32.lib")
|
||||
#pragma comment (lib, "cryptui.lib")
|
||||
@ -7,50 +8,13 @@
|
||||
|
||||
void main(void)
|
||||
{
|
||||
if (false)
|
||||
{
|
||||
BYTE* pData = NULL;
|
||||
DWORD dwDataLen = 0;
|
||||
bool bRes = NSFile::CFileBinary::ReadAllBytes(L"D:\\cert2.bin", &pData, dwDataLen);
|
||||
|
||||
if (!bRes)
|
||||
return;
|
||||
|
||||
PCCERT_CONTEXT context = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, pData, dwDataLen);
|
||||
|
||||
if (!context)
|
||||
{
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL result = CryptUIDlgViewContext(CERT_STORE_CERTIFICATE_CONTEXT, context, NULL, NULL, 0, NULL);
|
||||
result;
|
||||
|
||||
if (context)
|
||||
CertFreeCertificateContext(context);
|
||||
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
return;
|
||||
}
|
||||
|
||||
if (false)
|
||||
{
|
||||
xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
|
||||
xmlSubstituteEntitiesDefault(1);
|
||||
|
||||
std::string sXmlCan = CXmlCanonicalizator::Execute(L"D:\\1.xml", XML_C14N_1_0);
|
||||
NSFile::CFileBinary::SaveToFile(L"D:\\2.xml", UTF8_TO_U(sXmlCan));
|
||||
return;
|
||||
}
|
||||
|
||||
//std::wstring sFolderOOOXML = NSFile::GetProcessDirectory() + L"/ImageStamp";
|
||||
//std::wstring sSignId = L"{39B6B9C7-60AD-45A2-9F61-40C74A24042E}";
|
||||
|
||||
std::wstring sFolderOOXML = L"D:\\555";
|
||||
std::wstring sSignId = L"{9792D33F-AB37-4E5B-A465-481B9465818B}";
|
||||
|
||||
CCertificate_mscrypto oCertificate;
|
||||
CCertificate oCertificate;
|
||||
if (!oCertificate.ShowSelectDialog())
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user