Refactoring modules [hash, oform, all]

This commit is contained in:
Oleg Korshul
2022-12-13 18:26:43 +03:00
parent 41a358764f
commit 791c786bf7
36 changed files with 267 additions and 829 deletions

View File

@ -11,6 +11,7 @@
#endif
#include "./../include/CertificateCommon.h"
#include "../../../common/File.h"
ICertificate::ICertificate()
{

View File

@ -0,0 +1,3 @@
oform_plugin/module/deploy
hash/deploy
all/deploy

View File

@ -22,26 +22,18 @@ if "windows" == base.host_platform():
exit(0)
# fetch openssl
if not base.is_dir("openssl"):
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"])
# correct for wasm builds
common.apply_patch("./openssl/crypto/rand/rand_lib.c", "./patches/openssl1.patch")
base.copy_file("../../../../../Common/3dParty/openssl/openssl/apps/progs.h", "./openssl/apps/progs.h")
if not base.is_dir("xml"):
base.print_info("Copy xml...")
base.copy_dir("./../../../../xml", "./xml")
base.replaceInFile("./xml/libxml2/libxml.h", "xmlNop(void)", "xmlNop(void* context, char* buffer, int len)")
base.replaceInFile("./xml/libxml2/xmlIO.c", "xmlNop(void)", "xmlNop(void* context, char* buffer, int len)")
base.replaceInFile("./xml/src/xmllight_private.h", "#include \"../../common/", "#include \"../../../../../../common/")
base.replaceInFile("./xml/include/xmlutils.h", "#include \"../../common/", "#include \"../../../../../../common/")
base.replaceInFile("./xml/include/xmlwriter.h", "#include \"../../common/", "#include \"../../../../../../common/")
# compile openssl
if not base.is_file("./openssl/libcrypto.a"):
if not base.is_file("./openssl/libcrypto.a"):
base.print_info("Compile openssl...")
os.chdir("./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 ./../../../../../../Common/js/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("../")
run_as_bash("./compile_openssl.sh", ["source ./../../../../../../Common/js/emsdk/emsdk_env.sh", "emconfigure ./config no-shared no-asm no-threads no-dso", "sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile", "emmake make build_generated libssl.a libcrypto.a"])
os.chdir("./..")
common.apply_patch("./openssl/include/openssl/opensslconf.h", "./patches/openssl2.patch")

View File

@ -0,0 +1,11 @@
<<<<<<<
#ifndef OPENSSL_NO_MD2
# define OPENSSL_NO_MD2
#endif
=======
#ifndef OPENSSL_MD2_ENABLED
#ifndef OPENSSL_NO_MD2
# define OPENSSL_NO_MD2
#endif
#endif
>>>>>>>

View File

@ -0,0 +1,11 @@
import sys;
sys.path.append("../../../../../../build_tools/scripts");
import base;
base.replaceInFile("./deploy/openssl.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){self.onEngineInit();}];");
base.replaceInFile("./deploy/openssl.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){self.onEngineInit();}];");
base.replaceInFile("./deploy/openssl.js", "function getBinaryPromise()", "function getBinaryPromise2()");
base.replaceInFile("./deploy/openssl_ie.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){self.onEngineInit();}];");
base.replaceInFile("./deploy/openssl_ie.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){self.onEngineInit();}];");
base.replaceInFile("./deploy/openssl_ie.js", "function getBinaryPromise()", "function getBinaryPromise2()");

View File

@ -0,0 +1,14 @@
import sys
sys.path.append("../../../../../../build_tools/scripts")
import base
base.cmd_in_dir("./../3rdParty", "python", ["openssl.py"])
if not base.is_dir("./../3rdPartyxml"):
base.print_info("Copy xml...")
base.copy_dir("./../../../../xml", "./../3rdParty/xml")
base.replaceInFile("./../3rdParty/xml/libxml2/libxml.h", "xmlNop(void)", "xmlNop(void* context, char* buffer, int len)")
base.replaceInFile("./../3rdParty/xml/libxml2/xmlIO.c", "xmlNop(void)", "xmlNop(void* context, char* buffer, int len)")
base.replaceInFile("./../3rdParty/xml/src/xmllight_private.h", "#include \"../../common/", "#include \"../../../../../../common/")
base.replaceInFile("./../3rdParty/xml/include/xmlutils.h", "#include \"../../common/", "#include \"../../../../../../common/")
base.replaceInFile("./../3rdParty/xml/include/xmlwriter.h", "#include \"../../common/", "#include \"../../../../../../common/")

View File

@ -1,10 +1,10 @@
#include "../../../common/File.h"
#include "../../../../common/File.h"
#include "../include/Certificate.h"
#include "../include/CertificateCommon.h"
#include "../../include/Certificate.h"
#include "../../include/CertificateCommon.h"
#include "../include/OOXMLSigner.h"
#include "../include/OOXMLVerifier.h"
#include "../../include/OOXMLSigner.h"
#include "../../include/OOXMLVerifier.h"
#ifdef _WIN32
#define WASM_EXPORT __declspec(dllexport)

View File

@ -2,9 +2,10 @@
"name": "openssl",
"res_folder": "./deploy",
"wasm": true,
"asm": false,
"asm": true,
"embed_mem_file": true,
"run_before": "before.py",
"run_after": "import sys;sys.path.append(\"../../../../../../build_tools/scripts\");import base;base.replaceInFile(\"./deploy/openssl.js\", \"__ATPOSTRUN__=[];\", \"__ATPOSTRUN__=[function(){self.onEngineInit();}];\");base.replaceInFile(\"./deploy/openssl.js\", \"__ATPOSTRUN__ = [];\", \"__ATPOSTRUN__=[function(){self.onEngineInit();}];\");base.replaceInFile(\"./deploy/openssl.js\", \"function getBinaryPromise()\", \"function getBinaryPromise2()\");base.copy_file(\"./index.html\", \"./deploy/index.html\");base.copy_file(\"./code.js\", \"./deploy/code.js\")",
"run_after": "after.py",
"base_js_content": "./engine.js",
"compiler_flags": [
@ -31,15 +32,21 @@
"_XmlSignature_Sign"
],
"include_path": [
"./xml/libxml2/include", "./xml/libxml2/include/libxml", "./xml/build/qt", "../../../../../OfficeUtils/src/zlib-1.2.11/contrib/minizip", "../../../../../OfficeUtils/src/zlib-1.2.11", "../../../../../OfficeUtils/src", "openssl/include", "openssl", "emsdk/node/14.15.5_64bit/include/node/openssl/archs/linux-x86_64/no-asm/include"
"./../3rdParty/openssl/include", "./../3rdParty/openssl",
"./../../../../../OfficeUtils/src/zlib-1.2.11/contrib/minizip", "./../../../../../OfficeUtils/src/zlib-1.2.11", "./../../../../../OfficeUtils/src",
"./../3rdParty/xml/libxml2/include", "./../3rdParty/xml/libxml2/include/libxml", "./../3rdParty/xml/build/qt",
"emsdk/node/14.15.5_64bit/include/node/openssl/archs/linux-x86_64/no-asm/include"
],
"define": [
"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", "BUILD_ZLIB_AS_SOURCES", "__linux__", "_LINUX"
"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",
"BUILD_ZLIB_AS_SOURCES",
"__linux__", "_LINUX"
],
"compile_files_array": [
{
"name": "x",
"folder": "./xml/",
"folder": "./../3rdParty/xml/",
"files": ["build/qt/libxml2_all.c", "build/qt/libxml2_all2.c", "src/xmllight.cpp", "src/xmldom.cpp"]
},
{
@ -70,8 +77,8 @@
{
"name": "a",
"folder": "./",
"files": ["openssl/apps/openssl.c", "../main.cpp"]
"files": ["main.cpp"]
}
],
"sources": ["./openssl/libcrypto.a"]
"sources": ["./../3rdParty/openssl/libcrypto.a"]
}

View File

@ -7,7 +7,7 @@ CONFIG -= app_bundle
DEFINES += TEST_AS_EXECUTABLE
CORE_ROOT_DIR = $$PWD/../../../..
CORE_ROOT_DIR = $$PWD/../../../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
@ -94,9 +94,9 @@ SOURCES += \
# SIGN
SOURCES += \
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/XmlTransform.cpp \
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/CertificateCommon.cpp \
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/CertificateCommon.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/OOXMLVerifier.cpp
core_windows {
LIBS += -lcrypt32
@ -108,6 +108,12 @@ core_windows {
LIBS += -lShell32
}
core_linux {
LIBS += -ldl
}
DEFINES += SUPPORT_OPENSSL
# OPENSSL
include($$CORE_ROOT_DIR/Common/3dParty/openssl/openssl.pri)

View File

@ -1,5 +1,5 @@
import sys
sys.path.append('../../../../../../../build_tools/scripts')
sys.path.append('../../../../../../build_tools/scripts')
import base
import os

View File

@ -0,0 +1,5 @@
import sys
sys.path.append("../../../../../../build_tools/scripts")
import base
base.cmd_in_dir("./../3rdParty", "python", ["openssl.py"])

View File

@ -3,7 +3,7 @@
"res_folder": "./deploy",
"wasm": true,
"asm": true,
"run_before": "",
"run_before": "before.py",
"run_after": "after.py",
"base_js_content": "./hash_base.js",
"embed_mem_file": true,
@ -28,45 +28,45 @@
],
"include_path": [
"./", "./../openssl/include"
"./", "./../3rdParty/openssl/include"
],
"define": [
"WIN32", "DNDEBUG"
"WIN32", "DNDEBUG", "OPENSSL_MD2_ENABLED"
],
"compile_files_array": [
{
"name": "a1",
"folder": "../openssl/crypto/sha/",
"folder": "./../3rdParty/openssl/crypto/sha/",
"files": ["keccak1600.c", "sha1_one.c", "sha1dgst.c", "sha256.c", "sha512.c"]
},
{
"name": "a2",
"folder": "../openssl/crypto/md2/",
"folder": "./../3rdParty/openssl/crypto/md2/",
"files": ["md2_dgst.c", "md2_one.c"]
},
{
"name": "a3",
"folder": "../openssl/crypto/md4/",
"folder": "./../3rdParty/openssl/crypto/md4/",
"files": ["md4_dgst.c", "md4_one.c"]
},
{
"name": "a4",
"folder": "../openssl/crypto/md5/",
"folder": "./../3rdParty/openssl/crypto/md5/",
"files": ["md5_dgst.c", "md5_one.c"]
},
{
"name": "a5",
"folder": "../openssl/crypto/ripemd/",
"folder": "./../3rdParty/openssl/crypto/ripemd/",
"files": ["rmd_dgst.c", "rmd_one.c"]
},
{
"name": "a6",
"folder": "../openssl/crypto/whrlpool/",
"folder": "./../3rdParty/openssl/crypto/whrlpool/",
"files": ["wp_block.c", "wp_dgst.c"]
},
{
"name": "a7",
"folder": "../openssl/crypto/",
"folder": "./../3rdParty/openssl/crypto/",
"files": ["mem_clr.c"]
},
{

View File

@ -5,9 +5,11 @@ TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
DEFINES += TEST_AS_EXECUTABLE
DEFINES += \
TEST_AS_EXECUTABLE \
OPENSSL_MD2_ENABLED
OPENSSL_DIR = $$PWD/../openssl
OPENSSL_DIR = $$PWD/../3rdParty/openssl
INCLUDEPATH += \
$$OPENSSL_DIR/include \
@ -50,11 +52,11 @@ openssl_sha3 {
DEFINES += OOXML_SUPPORT_SHA3_512
SOURCES += \
$$OPENSSL_DIR/crypto/evp/digest.c \
$$OPENSSL_DIR/crypto/mem.c
$$OPENSSL_DIR/crypto/evp/digest.c \
$$OPENSSL_DIR/crypto/mem.c
INCLUDEPATH += $$OPENSSL_DIR/include
INCLUDEPATH += $$OPENSSL_DIR/include/openssl
INCLUDEPATH += $$OPENSSL_DIR/include/openssl
}

View File

@ -1,13 +1,16 @@
#include <memory>
#include "../openssl/include/openssl/sha.h"
#include "../openssl/include/openssl/md2.h"
#include "../openssl/include/openssl/md4.h"
#include "../openssl/include/openssl/md5.h"
#include "../openssl/include/openssl/whrlpool.h"
#include "../openssl/include/openssl/ripemd.h"
#include <string.h>
#define OPENSSL_MD2_ENABLED
#include "./../3rdParty/openssl/include/openssl/sha.h"
#include "./../3rdParty/openssl/include/openssl/md2.h"
#include "./../3rdParty/openssl/include/openssl/md4.h"
#include "./../3rdParty/openssl/include/openssl/md5.h"
#include "./../3rdParty/openssl/include/openssl/whrlpool.h"
#include "./../3rdParty/openssl/include/openssl/ripemd.h"
#ifdef OOXML_SUPPORT_SHA3_512
#include "../openssl/include/openssl/evp.h"
#include "./../3rdParty/openssl/include/openssl/evp.h"
#endif
#ifdef _WIN32
@ -519,7 +522,6 @@ WASM_EXPORT unsigned char* hash2(char* password, char* salt, int spinCount, int
#endif
#ifdef TEST_AS_EXECUTABLE
#include <string>
int main()
{
std::string data = "test";

View File

@ -1,44 +0,0 @@
{
"name": "engine",
"res_folder": "./deploy",
"wasm": true,
"asm": true,
"run_before": "",
"run_after": "after.py",
"base_js_content": "./hash_base.js",
"embed_mem_file": true,
"compiler_flags": [
"-O3",
"-fno-exceptions",
"-fno-rtti",
"-Wno-unused-command-line-argument",
"-s ALLOW_MEMORY_GROWTH=1",
"-s FILESYSTEM=0",
"-s ENVIRONMENT='worker'",
"-s TOTAL_STACK=1MB",
"-s TOTAL_MEMORY=2MB"
],
"exported_functions": [
"_malloc",
"_free",
"_hash",
"_hash2"
],
"include_path": [
"./", "./../openssl/include"
],
"define": [
"WIN32", "DNDEBUG"
],
"compile_files_array": [
{
"name": "m",
"folder": "./",
"files": ["main.cpp"]
}
],
"sources": ["./openssl/libcrypto.a"]
}

View File

@ -1,146 +0,0 @@
import sys
sys.path.append('../../../../../../../build_tools/scripts')
import base
import os
base.configure_common_apps()
# remove previous version
if base.is_dir("./deploy"):
base.delete_dir("./deploy")
base.create_dir("./deploy")
# fetch emsdk
command_prefix = "" if ("windows" == base.host_platform()) else "./"
if not base.is_dir("emsdk"):
base.cmd("git", ["clone", "https://github.com/emscripten-core/emsdk.git"])
os.chdir("emsdk")
base.cmd(command_prefix + "emsdk", ["install", "latest"])
base.cmd(command_prefix + "emsdk", ["activate", "latest"])
os.chdir("../")
# compile
compiler_flags = ["-o engine.js",
"-O3",
"-fno-exceptions",
"-fno-rtti",
"-s WASM=1",
"-s ALLOW_MEMORY_GROWTH=1",
"-s FILESYSTEM=0",
"-s ENVIRONMENT='worker'",
"-s TOTAL_STACK=1MB",
"-s TOTAL_MEMORY=2MB",
"--memory-init-file 0"]
exported_functions = ["_malloc",
"_free",
"_hash",
"_hash2"]
sources = []
sources.append("./../openssl/crypto/sha/keccak1600.c")
sources.append("./../openssl/crypto/sha/sha1_one.c")
sources.append("./../openssl/crypto/sha/sha1dgst.c")
sources.append("./../openssl/crypto/sha/sha256.c")
sources.append("./../openssl/crypto/sha/sha512.c")
sources.append("./../openssl/crypto/md2/md2_dgst.c")
sources.append("./../openssl/crypto/md2/md2_one.c")
sources.append("./../openssl/crypto/md4/md4_dgst.c")
sources.append("./../openssl/crypto/md4/md4_one.c")
sources.append("./../openssl/crypto/md5/md5_dgst.c")
sources.append("./../openssl/crypto/md5/md5_one.c")
sources.append("./../openssl/crypto/ripemd/rmd_dgst.c")
sources.append("./../openssl/crypto/ripemd/rmd_one.c")
sources.append("./../openssl/crypto/whrlpool/wp_block.c")
sources.append("./../openssl/crypto/whrlpool/wp_dgst.c")
sources.append("./../openssl/crypto/mem_clr.c")
sources.append("./main.cpp")
compiler_flags.append("-I./")
compiler_flags.append("-I./../openssl/include")
compiler_flags.append("-DWIN32 -DNDEBUG")
# 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 + " ")
# command
windows_bat = []
if (base.host_platform() == "windows"):
windows_bat.append("call emsdk/emsdk_env.bat")
windows_bat.append("call emcc " + arguments)
#windows_bat.append("emcc --help")
else:
windows_bat.append("#!/bin/bash")
windows_bat.append("source ./emsdk/emsdk_env.sh")
windows_bat.append("emcc " + arguments)
base.run_as_bat(windows_bat)
# finalize
base.replaceInFile("./engine.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){self.onEngineInit();}];")
base.replaceInFile("./engine.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){self.onEngineInit();}];")
base.replaceInFile("./engine.js", "function getBinaryPromise()", "function getBinaryPromise2()")
module_js_content = base.readFile("./engine.js")
engine_base_js_content = base.readFile("./hash_base.js")
string_utf8_content = base.readFile("./../../../../../../Common/js/string_utf8.js")
polyfill_js_content = base.readFile("./../../../../../../Common/3dParty/hunspell/wasm/js/polyfill.js")
polyfill_js_content = polyfill_js_content.replace("&&window===this?this", "?window")
base64_js_content = base.readFile("./../../../../../../../sdkjs/common/stringserialize.js")
base64_js_content = base64_js_content.replace("(window);", "(self);")
engine_js_content = engine_base_js_content.replace("//module", module_js_content)
engine_js_content = engine_js_content.replace("//string_utf8", string_utf8_content)
engine_js_content = engine_js_content.replace("//polyfill", polyfill_js_content)
engine_js_content = engine_js_content.replace("//base64", base64_js_content)
base.writeFile("./deploy/engine.js", engine_js_content)
base.copy_file("./engine.wasm", "./deploy/engine.wasm")
# ie asm version
arguments = arguments.replace("WASM=1", "WASM=0")
# command
windows_bat = []
if (base.host_platform() == "windows"):
windows_bat.append("call emsdk/emsdk_env.bat")
windows_bat.append("call emcc " + arguments)
#windows_bat.append("emcc --help")
else:
windows_bat.append("#!/bin/bash")
windows_bat.append("source ./emsdk/emsdk_env.sh")
windows_bat.append("emcc " + arguments)
base.run_as_bat(windows_bat)
# finalize
base.replaceInFile("./engine.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){self.onEngineInit();}];")
base.replaceInFile("./engine.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){self.onEngineInit();}];")
base.replaceInFile("./engine.js", "function getBinaryPromise()", "function getBinaryPromise2()")
module_js_content = base.readFile("./engine.js")
engine_base_js_content = base.readFile("./hash_base.js")
string_utf8_content = base.readFile("./../../../../../../Common/js/string_utf8.js")
polyfill_js_content = base.readFile("./../../../../../../Common/3dParty/hunspell/wasm/js/polyfill.js")
engine_js_content = engine_base_js_content.replace("//module", module_js_content)
engine_js_content = engine_js_content.replace("//string_utf8", string_utf8_content)
engine_js_content = engine_js_content.replace("//polyfill", polyfill_js_content)
engine_js_content = engine_js_content.replace("//base64", base64_js_content)
base.writeFile("./deploy/engine_ie.js", engine_js_content)

View File

@ -1,198 +0,0 @@
/*
* WARNING: do not edit!
* Generated by makefile from include\openssl\opensslconf.h.in
*
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/opensslv.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef OPENSSL_ALGORITHM_DEFINES
# error OPENSSL_ALGORITHM_DEFINES no longer supported
#endif
/*
* OpenSSL was configured with the following options:
*/
#ifndef OPENSSL_SYS_WIN64A
# define OPENSSL_SYS_WIN64A 1
#endif
#ifndef OPENSSL_NO_RC5
# define OPENSSL_NO_RC5
#endif
#ifndef OPENSSL_THREADS
# define OPENSSL_THREADS
#endif
#ifndef OPENSSL_RAND_SEED_OS
# define OPENSSL_RAND_SEED_OS
#endif
#ifndef OPENSSL_NO_AFALGENG
# define OPENSSL_NO_AFALGENG
#endif
#ifndef OPENSSL_NO_ASAN
# define OPENSSL_NO_ASAN
#endif
#ifndef OPENSSL_NO_ASM
# define OPENSSL_NO_ASM
#endif
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
# define OPENSSL_NO_CRYPTO_MDEBUG
#endif
#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
# define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
#endif
#ifndef OPENSSL_NO_DEVCRYPTOENG
# define OPENSSL_NO_DEVCRYPTOENG
#endif
#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
# define OPENSSL_NO_EC_NISTP_64_GCC_128
#endif
#ifndef OPENSSL_NO_EGD
# define OPENSSL_NO_EGD
#endif
#ifndef OPENSSL_NO_EXTERNAL_TESTS
# define OPENSSL_NO_EXTERNAL_TESTS
#endif
#ifndef OPENSSL_NO_FUZZ_AFL
# define OPENSSL_NO_FUZZ_AFL
#endif
#ifndef OPENSSL_NO_FUZZ_LIBFUZZER
# define OPENSSL_NO_FUZZ_LIBFUZZER
#endif
#ifndef OPENSSL_NO_HEARTBEATS
# define OPENSSL_NO_HEARTBEATS
#endif
#ifndef OPENSSL_NO_MSAN
# define OPENSSL_NO_MSAN
#endif
#ifndef OPENSSL_NO_SCTP
# define OPENSSL_NO_SCTP
#endif
#ifndef OPENSSL_NO_SSL_TRACE
# define OPENSSL_NO_SSL_TRACE
#endif
#ifndef OPENSSL_NO_SSL3
# define OPENSSL_NO_SSL3
#endif
#ifndef OPENSSL_NO_SSL3_METHOD
# define OPENSSL_NO_SSL3_METHOD
#endif
#ifndef OPENSSL_NO_UBSAN
# define OPENSSL_NO_UBSAN
#endif
#ifndef OPENSSL_NO_UNIT_TEST
# define OPENSSL_NO_UNIT_TEST
#endif
#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS
# define OPENSSL_NO_WEAK_SSL_CIPHERS
#endif
#ifndef OPENSSL_NO_DYNAMIC_ENGINE
# define OPENSSL_NO_DYNAMIC_ENGINE
#endif
/*
* Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
* don't like that. This will hopefully silence them.
*/
#define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;
/*
* Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
* declarations of functions deprecated in or before <version>. Otherwise, they
* still won't see them if the library has been built to disable deprecated
* functions.
*/
#ifndef DECLARE_DEPRECATED
# define DECLARE_DEPRECATED(f) f;
# ifdef __GNUC__
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
# undef DECLARE_DEPRECATED
# define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated));
# endif
# endif
#endif
#ifndef OPENSSL_FILE
# ifdef OPENSSL_NO_FILENAMES
# define OPENSSL_FILE ""
# define OPENSSL_LINE 0
# else
# define OPENSSL_FILE __FILE__
# define OPENSSL_LINE __LINE__
# endif
#endif
#ifndef OPENSSL_MIN_API
# define OPENSSL_MIN_API 0
#endif
#if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API
# undef OPENSSL_API_COMPAT
# define OPENSSL_API_COMPAT OPENSSL_MIN_API
#endif
/*
* Do not deprecate things to be deprecated in version 1.2.0 before the
* OpenSSL version number matches.
*/
#if OPENSSL_VERSION_NUMBER < 0x10200000L
# define DEPRECATEDIN_1_2_0(f) f;
#elif OPENSSL_API_COMPAT < 0x10200000L
# define DEPRECATEDIN_1_2_0(f) DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_1_2_0(f)
#endif
#if OPENSSL_API_COMPAT < 0x10100000L
# define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_1_1_0(f)
#endif
#if OPENSSL_API_COMPAT < 0x10000000L
# define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_1_0_0(f)
#endif
#if OPENSSL_API_COMPAT < 0x00908000L
# define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_0_9_8(f)
#endif
/* Generate 80386 code? */
#undef I386_ONLY
#undef OPENSSL_UNISTD
#define OPENSSL_UNISTD <unistd.h>
#define OPENSSL_EXPORT_VAR_AS_FUNCTION
/*
* The following are cipher-specific, but are part of the public API.
*/
#if !defined(OPENSSL_SYS_UEFI)
# undef BN_LLONG
/* Only one for the following should be defined */
# undef SIXTY_FOUR_BIT_LONG
# define SIXTY_FOUR_BIT
# undef THIRTY_TWO_BIT
#endif
#define RC4_INT unsigned int
#ifdef __cplusplus
}
#endif

View File

@ -6,5 +6,6 @@ base.replaceInFile("./deploy/engine.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[fu
base.replaceInFile("./deploy/engine.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
base.replaceInFile("./deploy/engine.js", "function getBinaryPromise()", "function getBinaryPromise2()");
base.copy_file("./index.html", "./deploy/index.html");
base.copy_file("./code.js", "./deploy/code.js")
base.replaceInFile("./deploy/engine_ie.js", "__ATPOSTRUN__=[];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
base.replaceInFile("./deploy/engine_ie.js", "__ATPOSTRUN__ = [];", "__ATPOSTRUN__=[function(){window.cryptoJS.onLoad();}];");
base.replaceInFile("./deploy/engine_ie.js", "function getBinaryPromise()", "function getBinaryPromise2()");

View File

@ -1,38 +1,5 @@
import sys
sys.path.append("../../../../../../../build_tools/scripts")
sys.path.append("../../../../../../Common/js")
import base
import os
import codecs
import common
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)
# fetch openssl
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"])
# correct for wasm builds
common.apply_patch("./openssl/crypto/rand/rand_lib.c", "./../module/patches/openssl1.patch")
base.copy_file("../../../../../../Common/3dParty/openssl/openssl/apps/progs.h", "./openssl/apps/progs.h")
# compile openssl
if not base.is_file("./openssl/libcrypto.a"):
base.print_info("Compile openssl...")
os.chdir("./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 ./../../../../../../../Common/js/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.cmd_in_dir("./../../3rdParty", "python", ["openssl.py"])

View File

@ -1,6 +1,6 @@
window.onload = function()
{
let url = "./engine";
let url = "./deploy/engine";
let useWasm = false;
let webAsmObj = window["WebAssembly"];
if (typeof webAsmObj === "object" && typeof webAsmObj["Memory"] === "function")

View File

@ -1,134 +0,0 @@
window.onload = function()
{
var xmlCertificate = new window.XmlSignature();
var XmlError = window.XmlSignatureError;
function loadCert(data, password)
{
window.certFileData = data;
var err = xmlCertificate.loadCert(window.certFileData, password);
switch (err)
{
case XmlError.OPEN_SSL_WARNING_ERR:
{
alert("error");
break;
}
case XmlError.OPEN_SSL_WARNING_ALL_OK:
{
document.getElementById("key").style.display = "none";
document.getElementById("password").style.display = "none";
break;
}
case XmlError.OPEN_SSL_WARNING_OK:
{
document.getElementById("key").style.display = "";
document.getElementById("password").style.display = "none";
break;
}
case XmlError.OPEN_SSL_WARNING_PASS:
{
document.getElementById("key").style.display = "none";
document.getElementById("password").style.display = "";
break;
}
default:
break;
}
}
function loadKey(data, password)
{
window.keyFileData = data;
var err = xmlCertificate.loadKey(window.keyFileData, password);
switch (err)
{
case XmlError.OPEN_SSL_WARNING_ERR:
{
alert("error");
break;
}
case XmlError.OPEN_SSL_WARNING_ALL_OK:
case XmlError.OPEN_SSL_WARNING_OK:
{
document.getElementById("password").style.display = "none";
break;
}
case XmlError.OPEN_SSL_WARNING_PASS:
{
document.getElementById("password").style.display = "";
break;
}
default:
break;
}
}
document.getElementById('button_certificate').onchange = function() {
var reader = new FileReader();
reader.onload = function() {
loadCert(this.result);
};
reader.readAsArrayBuffer(this.files[0]);
};
document.getElementById('button_key').onchange = function() {
var reader = new FileReader();
reader.onload = function() {
loadKey(this.result);
};
reader.readAsArrayBuffer(this.files[0]);
};
document.getElementById('file_select').onchange = function() {
var reader = new FileReader();
reader.onload = function() {
window.fileFileData = this.result;
};
reader.readAsArrayBuffer(this.files[0]);
};
document.getElementById('button_password').onclick = function() {
if (document.getElementById("key").style.display == "none")
loadCert(window.certFileData, document.getElementById("area_password").value);
else
loadKey(window.keyFileData, document.getElementById("area_password").value);
};
document.getElementById('button_sign').onclick = function() {
if (!window.fileFileData)
{
alert("Please select file");
return;
}
function downloadBlob(data, fileName, mimeType) {
var blob, url;
blob = new Blob([data], {
type: mimeType
});
url = window.URL.createObjectURL(blob);
downloadURL(url, fileName);
setTimeout(function() {
return window.URL.revokeObjectURL(url);
}, 1000);
};
function downloadURL(data, fileName) {
var a;
a = document.createElement('a');
a.href = data;
a.download = fileName;
document.body.appendChild(a);
a.style = 'display: none';
a.click();
a.remove();
};
var result = xmlCertificate.sign(window.fileFileData);
downloadBlob(result, 'sign_file.docx', 'application/octet-stream');
};
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,42 +0,0 @@
<!doctype html>
<html style="width:100%;height:100%;margin:0;padding:0;">
<head>
<title>ONLYOFFICE Documents</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8">
<script src="./code.js"></script>
<script src="./openssl.js"></script>
<style>
div {
margin: 10px;
}
</style>
</head>
<body style="width:100%;height:100%;margin:50;padding:0;overflow:hidden;">
<div id="certificate">
<label for="button_certificate">Select Certificate</label>
<input type="file" id="button_certificate">
</div>
<div id="key" style="display:none;">
<label for="button_key">Select Private Key</label>
<input type="file" id="button_key" value="load key">
</div>
<div id="password" style="display:none;">
<textarea id="area_password" placeholder="password..."></textarea>
<input type="button" id="button_password" value="setup password">
</div>
<div id="file">
<label for="file_select">Select OOXML File</label>
<input type="file" id="file_select" value="load file">
</div>
<div id="sign">
<input type="button" id="button_sign" value="Sign">
</div>
</body>
</html>

View File

@ -10,11 +10,12 @@
"compiler_flags": [
"-O3",
"-fno-rtti",
"-Wno-unused-command-line-argument",
"-s ALLOW_MEMORY_GROWTH=1",
"-s FILESYSTEM=0",
"-s ENVIRONMENT='web'"
"-s ENVIRONMENT='web'",
"-s ASSERTIONS",
"-s LLD_REPORT_UNDEFINED"
],
"exported_functions": [
"_malloc",
@ -26,27 +27,27 @@
"_Crypto_ChangePassword"
],
"include_path": [
"openssl/include", "openssl", "emsdk/node/14.15.5_64bit/include/node/openssl/archs/linux-x86_64/no-asm/include"
"./../../3rdParty/openssl/include", "./../../3rdParty/openssl", "emsdk/node/14.15.5_64bit/include/node/openssl/archs/linux-x86_64/no-asm/include"
],
"define": [
"__linux__", "_LINUX", "DISABLE_XMLSEC"
],
"compile_files_array": [
{
"name": "k",
"name": "a",
"folder": "../../../../../common/",
"files": ["Base64.cpp", "File.cpp"]
},
{
"name": "s",
"name": "b",
"folder": "../../../../../../Common/3dParty/openssl/common/",
"files": ["common_openssl.cpp"]
},
{
"name": "a",
"folder": "./../",
"files": ["./main.cpp"]
"name": "c",
"folder": "./",
"files": ["main.cpp"]
}
],
"sources": ["./openssl/libcrypto.a"]
"sources": ["./../../3rdParty/openssl/libcrypto.a"]
}

View File

@ -116,13 +116,13 @@
let currentEnd = currentStart;
while (heap[currentEnd] != 0)
currentEnd++;
let publicKey = String.fromUtf8(heap, currentStart, currentEnd - currentStart);
let publicKey = "".fromUtf8(heap, currentStart, currentEnd - currentStart);
currentStart = currentEnd + 1;
currentEnd = currentStart;
while (heap[currentEnd] != 0)
currentEnd++;
let privateKey = String.fromUtf8(heap, currentStart, currentEnd - currentStart);
let privateKey = "".fromUtf8(heap, currentStart, currentEnd - currentStart);
Module["_Crypto_Free"](keys);
@ -161,7 +161,7 @@
while (heap[currentEnd] != 0)
currentEnd++;
let signString = String.fromUtf8(heap, currentStart, currentEnd - currentStart);
let signString = "".fromUtf8(heap, currentStart, currentEnd - currentStart);
Module["_Crypto_Free"](signData);
return signString;
@ -177,8 +177,8 @@
let passwordNewPtr = passwordNew.toUtf8Pointer();
let saltPtr = salt.toUtf8Pointer();
let privateKeyEnc = Module["_Crypto_Sign"](privateKeyPtr.ptr,
passwordOldPtr.ptr, passwordNewPtr.ptr, saltPtr.length);
let privateKeyEnc = Module["_Crypto_ChangePassword"](privateKeyPtr.ptr,
passwordOldPtr.ptr, passwordNewPtr.ptr, saltPtr.ptr);
privateKeyPtr.free();
passwordOldPtr.free();
@ -195,7 +195,7 @@
while (heap[currentEnd] != 0)
currentEnd++;
let privateKeyString = String.fromUtf8(heap, currentStart, currentEnd - currentStart);
let privateKeyString = "".fromUtf8(heap, currentStart, currentEnd - currentStart);
Module["_Crypto_Free"](privateKeyEnc);
return privateKeyString;

View File

@ -1,9 +1,9 @@
#include "../../../../common/File.h"
#include "../../../../../Common/3dParty/openssl/common/common_openssl.h"
#include "../../../../../common/File.h"
#include "../../../../../../Common/3dParty/openssl/common/common_openssl.h"
#ifndef DISABLE_XMLSEC
#include "../../include/Certificate.h"
#include "../../include/CertificateCommon.h"
#include "../../../include/Certificate.h"
#include "../../../include/CertificateCommon.h"
#endif
#ifdef _WIN32

View File

@ -13,7 +13,7 @@ oform_only {
DEFINES += DISABLE_XMLSEC
}
CORE_ROOT_DIR = $$PWD/../../../../..
CORE_ROOT_DIR = $$PWD/../../../../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
@ -22,18 +22,18 @@ DEFINES += COMMON_OPENSSL_BUILDING_INTERNAL
SOURCES += \
$$CORE_ROOT_DIR/DesktopEditor/common/File.cpp \
$$CORE_ROOT_DIR/DesktopEditor/common/Base64.cpp
$$CORE_ROOT_DIR/DesktopEditor/common/Base64.cpp
oform_only {
HEADERS += \
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/include/Certificate.h \
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/include/CertificateCommon.h
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/include/Certificate.h \
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/include/CertificateCommon.h
SOURCES += \
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/CertificateCommon.cpp
$$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/CertificateCommon.cpp
DEFINES += SUPPORT_OFORM
HEADERS += $$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/Certificate_oform.h
HEADERS += $$CORE_ROOT_DIR/DesktopEditor/xmlsec/src/src/Certificate_oform.h
}
# OPENSSL
@ -42,12 +42,15 @@ include($$CORE_ROOT_DIR/Common/3dParty/openssl/openssl.pri)
core_windows {
LIBS += -lcrypt32
LIBS += -lcryptui
LIBS += -lAdvapi32
LIBS += -lws2_32
LIBS += -lUser32
LIBS += -lcryptui
LIBS += -lAdvapi32
LIBS += -lws2_32
LIBS += -lUser32
}
core_linux {
LIBS += -ldl
}
# WASM EXPORT
SOURCES += main.cpp