mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Refactoring
This commit is contained in:
@ -59,4 +59,9 @@
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DISABLE_Q_DECL_EXPORT
|
||||
#undef Q_DECL_EXPORT
|
||||
#define Q_DECL_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // _BUILD_BASE_EXPORTIMPORT_H
|
||||
|
||||
@ -26,6 +26,8 @@ namespace NSOpenSSL
|
||||
{
|
||||
Q_DECL_EXPORT int LoadKey(std::wstring file, std::string password);
|
||||
Q_DECL_EXPORT int LoadCert(std::wstring file, std::string password);
|
||||
Q_DECL_EXPORT int LoadKeyRaw(unsigned char* data, unsigned int len, std::string password);
|
||||
Q_DECL_EXPORT int LoadCertRaw(unsigned char* data, unsigned int len, std::string password);
|
||||
}
|
||||
|
||||
class Q_DECL_EXPORT CCertificateInfo
|
||||
|
||||
@ -13,6 +13,15 @@ namespace NSOpenSSL
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LoadKeyRaw(unsigned char* data, unsigned int len, std::string password)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int LoadCertRaw(unsigned char* data, unsigned int len, std::string password)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@ -548,6 +548,37 @@ public:
|
||||
GetHashAlgs();
|
||||
return true;
|
||||
}
|
||||
bool FromFilesRaw(unsigned char* key, unsigned int keyLen, const std::string& keyPassword,
|
||||
unsigned char* cert, unsigned int certLen, const std::string& certPassword)
|
||||
{
|
||||
std::string sKeyPassword = keyPassword;
|
||||
std::string sCertPassword = certPassword;
|
||||
if (NULL == cert)
|
||||
{
|
||||
cert = key;
|
||||
certLen = keyLen;
|
||||
sCertPassword = sKeyPassword;
|
||||
}
|
||||
if (NULL == key)
|
||||
{
|
||||
key = cert;
|
||||
keyLen = certLen;
|
||||
sKeyPassword = sCertPassword;
|
||||
}
|
||||
|
||||
int nErr = LoadKey(key, keyLen, sKeyPassword, &m_key);
|
||||
|
||||
if (nErr != OPEN_SSL_WARNING_OK && nErr != OPEN_SSL_WARNING_ALL_OK)
|
||||
return false;
|
||||
|
||||
nErr = LoadCert(cert, certLen, sCertPassword, &m_cert);
|
||||
|
||||
if (nErr != OPEN_SSL_WARNING_OK && nErr != OPEN_SSL_WARNING_ALL_OK)
|
||||
return false;
|
||||
|
||||
GetHashAlgs();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FromKey(const std::string& sId)
|
||||
{
|
||||
@ -986,6 +1017,12 @@ bool CCertificate_openssl::FromFiles(const std::wstring& keyPath, const std::str
|
||||
return m_internal->FromFiles(keyPath, keyPassword, certPath, certPassword);
|
||||
}
|
||||
|
||||
bool CCertificate_openssl::FromFilesRaw(unsigned char* key, unsigned int keyLen, const std::string& keyPassword,
|
||||
unsigned char* cert, unsigned int certLen, const std::string& certPassword)
|
||||
{
|
||||
return m_internal->FromFilesRaw(key, keyLen, keyPassword, cert, certLen, certPassword);
|
||||
}
|
||||
|
||||
bool CCertificate_openssl::FromId(const std::string& id)
|
||||
{
|
||||
return m_internal->FromKey(id);
|
||||
@ -1016,4 +1053,13 @@ namespace NSOpenSSL
|
||||
{
|
||||
return CCertificate_openssl_private::LoadCert(file, password, NULL);
|
||||
}
|
||||
|
||||
int LoadKeyRaw(unsigned char* data, unsigned int len, std::string password)
|
||||
{
|
||||
return CCertificate_openssl_private::LoadKey(data, (DWORD)len, password, NULL);
|
||||
}
|
||||
int LoadCertRaw(unsigned char* data, unsigned int len, std::string password)
|
||||
{
|
||||
return CCertificate_openssl_private::LoadCert(data, (DWORD)len, password, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,9 @@ public:
|
||||
virtual std::string Print();
|
||||
|
||||
virtual bool FromFiles(const std::wstring& keyPath, const std::string& keyPassword, const std::wstring& certPath, const std::string& certPassword);
|
||||
virtual bool FromFilesRaw(unsigned char* key, unsigned int keyLen, const std::string& keyPassword,
|
||||
unsigned char* cert, unsigned int certLen, const std::string& certPassword);
|
||||
|
||||
bool FromId(const std::string& id);
|
||||
};
|
||||
|
||||
|
||||
168
DesktopEditor/xmlsec/src/wasm/main.cpp
Normal file
168
DesktopEditor/xmlsec/src/wasm/main.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
#include "../../../common/File.h"
|
||||
|
||||
#include "../include/XmlCertificate.h"
|
||||
#include "../src/XmlSigner_openssl.h"
|
||||
|
||||
#include "../include/OOXMLSigner.h"
|
||||
#include "../include/OOXMLVerifier.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WASM_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define WASM_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WASM_EXPORT void* XmlSirnature_Malloc(unsigned int size)
|
||||
{
|
||||
return ::malloc(size);
|
||||
}
|
||||
WASM_EXPORT void XmlSirnature_Free(void* p)
|
||||
{
|
||||
if (p) ::free(p);
|
||||
}
|
||||
|
||||
class CMemoryFile
|
||||
{
|
||||
public:
|
||||
unsigned int Length;
|
||||
BYTE* Data;
|
||||
|
||||
public:
|
||||
CMemoryFile(BYTE* data = NULL, unsigned int len = 0) { Length = len; Data = data; }
|
||||
~CMemoryFile() { if (Data) delete [] Data; }
|
||||
};
|
||||
|
||||
class CCertificate
|
||||
{
|
||||
public:
|
||||
CCertificate_openssl* m_pCert;
|
||||
|
||||
private:
|
||||
unsigned char* m_key;
|
||||
unsigned int m_keyLen;
|
||||
std::string m_keyPass;
|
||||
|
||||
unsigned char* m_cert;
|
||||
unsigned int m_certLen;
|
||||
std::string m_certPass;
|
||||
|
||||
public:
|
||||
CCertificate()
|
||||
{
|
||||
m_pCert = new CCertificate_openssl();
|
||||
}
|
||||
~CCertificate()
|
||||
{
|
||||
delete m_pCert;
|
||||
}
|
||||
|
||||
public:
|
||||
int LoadCert(unsigned char* data, unsigned int len, char* pass)
|
||||
{
|
||||
m_cert = NULL; m_certLen = 0; m_certPass = "";
|
||||
int nRes = NSOpenSSL::LoadCertRaw(data, len, pass);
|
||||
|
||||
if (OPEN_SSL_WARNING_ALL_OK == nRes || OPEN_SSL_WARNING_OK == nRes)
|
||||
{
|
||||
m_cert = data;
|
||||
m_certLen = len;
|
||||
m_certPass = (NULL != pass) ? std::string(pass) : "";
|
||||
}
|
||||
if (OPEN_SSL_WARNING_ALL_OK == nRes)
|
||||
{
|
||||
m_key = m_cert;
|
||||
m_keyLen = m_certLen;
|
||||
m_keyPass = m_certPass;
|
||||
}
|
||||
|
||||
return nRes;
|
||||
}
|
||||
int LoadKey(unsigned char* data, unsigned int len, char* pass)
|
||||
{
|
||||
m_key = NULL; m_keyLen = 0; m_keyPass = "";
|
||||
int nRes = NSOpenSSL::LoadKeyRaw(data, len, pass);
|
||||
|
||||
if (OPEN_SSL_WARNING_ALL_OK == nRes || OPEN_SSL_WARNING_OK == nRes)
|
||||
{
|
||||
m_key = data;
|
||||
m_keyLen = len;
|
||||
m_keyPass = (NULL != pass) ? std::string(pass) : "";
|
||||
}
|
||||
if (OPEN_SSL_WARNING_ALL_OK == nRes)
|
||||
{
|
||||
m_cert = m_key;
|
||||
m_certLen = m_keyLen;
|
||||
m_certPass = m_keyPass;
|
||||
}
|
||||
|
||||
return nRes;
|
||||
}
|
||||
|
||||
void Load()
|
||||
{
|
||||
m_pCert->FromFilesRaw(m_key, m_keyLen, m_keyPass, m_cert, m_certLen, m_certPass);
|
||||
}
|
||||
|
||||
ICertificate* GetCertificate()
|
||||
{
|
||||
return m_pCert;
|
||||
}
|
||||
};
|
||||
|
||||
WASM_EXPORT void* XmlSignature_CreateCertificate()
|
||||
{
|
||||
return new CCertificate();
|
||||
}
|
||||
WASM_EXPORT int XmlSignature_LoadCert(CCertificate* cert, unsigned char* data, unsigned int len, char* pass)
|
||||
{
|
||||
return cert->LoadCert(data, len, pass);
|
||||
}
|
||||
WASM_EXPORT int XmlSignature_LoadKey(CCertificate* cert, unsigned char* data, unsigned int len, char* pass)
|
||||
{
|
||||
return cert->LoadKey(data, len, pass);
|
||||
}
|
||||
WASM_EXPORT void XmlSignature_DestroyCertificate(void* cert)
|
||||
{
|
||||
CCertificate* pCert = (CCertificate*)cert;
|
||||
delete pCert;
|
||||
}
|
||||
|
||||
WASM_EXPORT void* XmlSignature_CreateFile(unsigned char* file, unsigned int len)
|
||||
{
|
||||
return new CMemoryFile(file, len);
|
||||
}
|
||||
WASM_EXPORT void XmlSignature_DestroyFile(void* file)
|
||||
{
|
||||
CMemoryFile* pZipFile = (CMemoryFile*)file;
|
||||
delete pZipFile;
|
||||
}
|
||||
|
||||
WASM_EXPORT void* XmlSignature_Sign(CMemoryFile* file, CCertificate* cert)
|
||||
{
|
||||
cert->Load();
|
||||
COOXMLSigner oSigner(file->Data, file->Length, cert->GetCertificate());
|
||||
|
||||
BYTE* pDataDst = NULL;
|
||||
unsigned long lDataDstLen = 0;
|
||||
|
||||
oSigner.Sign(pDataDst, lDataDstLen);
|
||||
|
||||
CMemoryFile* fileDst = new CMemoryFile(pDataDst, (unsigned int)lDataDstLen);
|
||||
return fileDst;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_AS_EXECUTABLE
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
103
DesktopEditor/xmlsec/src/wasm/module/make.py
Normal file
103
DesktopEditor/xmlsec/src/wasm/module/make.py
Normal file
@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
sys.path.append('../../build_tools/scripts')
|
||||
import base
|
||||
import os
|
||||
import codecs
|
||||
|
||||
def run_as_bash(file, commands):
|
||||
if base.is_file(file):
|
||||
base.delete_file(file)
|
||||
file_bash = codecs.open(file, "w", "utf-8")
|
||||
file_bash.write("#!/bin/bash\n")
|
||||
file_bash.write("\n".join(commands))
|
||||
file_bash.close()
|
||||
base.cmd("chmod", ["+x", file])
|
||||
base.cmd(file)
|
||||
return
|
||||
|
||||
if ("windows" == base.host_platform()):
|
||||
print("Windows system not supported. Please use Linux or MacOS")
|
||||
exit(0)
|
||||
|
||||
base.configure_common_apps()
|
||||
base_dir = os.getcwd()
|
||||
|
||||
# fetch emsdk
|
||||
if not base.is_dir("emsdk"):
|
||||
base.print_info("Fetching emsdk...")
|
||||
base.cmd("git", ["clone", "https://github.com/emscripten-core/emsdk.git"])
|
||||
os.chdir(base_dir + "/emsdk")
|
||||
base.cmd("./emsdk", ["install", "latest"])
|
||||
base.cmd("./emsdk", ["activate", "latest"])
|
||||
os.chdir(base_dir)
|
||||
|
||||
# fetch freetype
|
||||
if not base.is_dir("openssl"):
|
||||
base.print_info("Fetching openssl...")
|
||||
base.cmd("git", ["clone", "--depth=1", "--branch", "OpenSSL_1_1_1f", "https://github.com/openssl/openssl.git"])
|
||||
|
||||
# compile openssl
|
||||
if not base.is_file(base_dir + "/openssl/libcrypto.a"):
|
||||
base.print_info("Compile openssl...")
|
||||
os.chdir(base_dir + "/openssl")
|
||||
#run_as_bash("./compile_openssl.sh", ["./config no-shared no-asm no-ssl2 no-ssl3", "source ./../emsdk/emsdk_env.sh", "export CC=emcc", "export CXX=emcc", "make"])
|
||||
run_as_bash("./compile_openssl.sh", ["source ./../emsdk/emsdk_env.sh", "emconfigure ./config no-shared no-asm no-threads", "sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile", "emmake make build_generated libssl.a libcrypto.a"])
|
||||
os.chdir(base_dir)
|
||||
|
||||
# compile wasm module with bindings
|
||||
compiler_flags = ["-o openssl.js",
|
||||
"-O3",
|
||||
"-fno-exceptions",
|
||||
"-fno-rtti",
|
||||
"-s WASM=1",
|
||||
"-s ALLOW_MEMORY_GROWTH=1",
|
||||
"-s FILESYSTEM=0",
|
||||
"-s ENVIRONMENT='web'"]
|
||||
|
||||
exported_functions = ["_malloc",
|
||||
"_free",
|
||||
"_ASC_Generate_Param",
|
||||
"_ASC_GetHash"]
|
||||
|
||||
sources = ["./openssl/libcrypto.a", "./openssl.c"]
|
||||
|
||||
compiler_flags.append("-Iopenssl/include")
|
||||
|
||||
# arguments
|
||||
arguments = ""
|
||||
for item in compiler_flags:
|
||||
arguments += (item + " ")
|
||||
|
||||
arguments += "-s EXPORTED_FUNCTIONS=\"["
|
||||
for item in exported_functions:
|
||||
arguments += ("'" + item + "',")
|
||||
arguments = arguments[:-1]
|
||||
arguments += "]\" "
|
||||
|
||||
for item in sources:
|
||||
arguments += (item + " ")
|
||||
|
||||
run_as_bash("./compile_module.sh", ["source ./emsdk/emsdk_env.sh", "emcc " + arguments])
|
||||
|
||||
# finalize
|
||||
base.replaceInFile("./openssl.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){window.AscCrypto.onLoadModule();}];")
|
||||
base.replaceInFile("./openssl.js", "function getBinaryPromise(){", "function getBinaryPromise2(){")
|
||||
|
||||
openssl_js_content = base.readFile("./openssl.js")
|
||||
engine_base_js_content = base.readFile("./engine.js")
|
||||
engine_js_content = engine_base_js_content.replace("//module", openssl_js_content)
|
||||
|
||||
if not base.is_dir("./deploy"):
|
||||
base.create_dir("./deploy")
|
||||
|
||||
# remove previous version
|
||||
if base.is_file("./deploy/openssl.js"):
|
||||
base.delete_file("./deploy/openssl.js")
|
||||
if base.is_file("./deploy/openssl.wasm"):
|
||||
base.delete_file("./deploy/openssl.wasm")
|
||||
|
||||
# write new version
|
||||
base.writeFile("./deploy/openssl.js", engine_js_content)
|
||||
base.copy_file("./openssl.wasm", "./deploy/openssl.wasm")
|
||||
111
DesktopEditor/xmlsec/src/wasm/xmlsec.pro
Normal file
111
DesktopEditor/xmlsec/src/wasm/xmlsec.pro
Normal file
@ -0,0 +1,111 @@
|
||||
QT -= core gui
|
||||
|
||||
TARGET = wasm
|
||||
TEMPLATE = app
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
DEFINES += TEST_AS_EXECUTABLE
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
|
||||
DEFINES += KERNEL_NO_USE_DYNAMIC_LIBRARY
|
||||
DEFINES += DISABLE_Q_DECL_EXPORT
|
||||
|
||||
# XML
|
||||
DEFINES += \
|
||||
HAVE_VA_COPY \
|
||||
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
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xml/libxml2/include \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xml/libxml2/include/libxml \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xml/build/qt
|
||||
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xml/build/qt/libxml2_all.c \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xml/build/qt/libxml2_all2.c \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xml/src/xmllight.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xml/src/xmldom.cpp
|
||||
|
||||
# KERNEL
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/common/StringBuilder.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/common/Base64.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/common/Path.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/common/File.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/common/Directory.cpp
|
||||
|
||||
# ZIP
|
||||
DEFINES += BUILD_ZLIB_AS_SOURCES
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11
|
||||
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/OfficeUtils.cpp \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/ZipBuffer.cpp \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/ZipUtilsCP.cpp \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip/ioapi.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip/miniunz.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip/minizip.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip/mztools.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip/unzip.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip/zip.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip/ioapibuf.c
|
||||
|
||||
core_windows:SOURCES += $$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/contrib/minizip/iowin32.c
|
||||
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/adler32.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/compress.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/crc32.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/deflate.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/gzclose.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/gzlib.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/gzread.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/gzwrite.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/infback.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/inffast.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/inflate.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/inftrees.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/trees.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/uncompr.c \
|
||||
$$CORE_ROOT_DIR/OfficeUtils/src/zlib-1.2.11/zutil.c
|
||||
|
||||
# SIGN
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/XmlTransform.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/XmlCertificate.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/OOXMLSigner.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/OOXMLVerifier.cpp \
|
||||
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/XmlSigner_openssl.cpp
|
||||
|
||||
core_windows {
|
||||
LIBS += -lcrypt32
|
||||
LIBS += -lcryptui
|
||||
LIBS += -lAdvapi32
|
||||
LIBS += -lws2_32
|
||||
LIBS += -lUser32
|
||||
LIBS += -lRpcrt4
|
||||
LIBS += -lShell32
|
||||
}
|
||||
|
||||
# OPENSSL
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/openssl/openssl.pri)
|
||||
|
||||
# WASM EXPORT
|
||||
SOURCES += main.cpp
|
||||
Reference in New Issue
Block a user