From 6d29cda8ea38e623d92f348fedcbcdbacf8631fc Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Tue, 13 Dec 2022 12:45:08 +0300 Subject: [PATCH] Add code for engine_base.js --- .../wasm/oform_plugin/module/deploy/engine.js | 221 ++++++++++++--- .../oform_plugin/module/deploy/engine_ie.js | 256 ++++++++++++++---- .../wasm/oform_plugin/module/engine_base.js | 221 ++++++++++++--- 3 files changed, 552 insertions(+), 146 deletions(-) diff --git a/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/deploy/engine.js b/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/deploy/engine.js index f68f4367b9..9b93b7e4ae 100644 --- a/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/deploy/engine.js +++ b/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/deploy/engine.js @@ -195,11 +195,81 @@ else })(); + function toBase64(buf) + { + if(typeof buf === "string") + { + let old = buf; + buf = []; + for (let i = 0, len = old.length; i < len; i++) + buf.push(old.charCodeAt(i)); + } - var Module=typeof Module!="undefined"?Module:{};var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=true;var ENVIRONMENT_IS_WORKER=false;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=(url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)}}setWindowTitle=title=>document.title=title}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.warn.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];var noExitRuntime=Module["noExitRuntime"]||true;if(typeof WebAssembly!="object"){abort("no native wasm support detected")}var wasmMemory;var ABORT=false;var EXITSTATUS;var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):undefined;function UTF8ArrayToString(heapOrArray,idx,maxBytesToRead){var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023)}}return str}function UTF8ToString(ptr,maxBytesToRead){return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):""}var buffer,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateGlobalBufferAndViews(buf){buffer=buf;Module["HEAP8"]=HEAP8=new Int8Array(buf);Module["HEAP16"]=HEAP16=new Int16Array(buf);Module["HEAP32"]=HEAP32=new Int32Array(buf);Module["HEAPU8"]=HEAPU8=new Uint8Array(buf);Module["HEAPU16"]=HEAPU16=new Uint16Array(buf);Module["HEAPU32"]=HEAPU32=new Uint32Array(buf);Module["HEAPF32"]=HEAPF32=new Float32Array(buf);Module["HEAPF64"]=HEAPF64=new Float64Array(buf)}var INITIAL_MEMORY=Module["INITIAL_MEMORY"]||16777216;var wasmTable;var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[function(){window.Asc.cryptoJS.onLoad();}];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){{if(Module["onAbort"]){Module["onAbort"](what)}}what="Aborted("+what+")";err(what);ABORT=true;EXITSTATUS=1;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return filename.startsWith(dataURIPrefix)}var wasmBinaryFile;wasmBinaryFile="engine.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}function getBinary(file){try{if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}catch(err){abort(err)}}function getBinaryPromise2(){if(!wasmBinary&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)){if(typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){if(!response["ok"]){throw"failed to load wasm binary file at '"+wasmBinaryFile+"'"}return response["arrayBuffer"]()}).catch(function(){return getBinary(wasmBinaryFile)})}}return Promise.resolve().then(function(){return getBinary(wasmBinaryFile)})}function createWasm(){var info={"a":asmLibraryArg};function receiveInstance(instance,module){var exports=instance.exports;Module["asm"]=exports;wasmMemory=Module["asm"]["A"];updateGlobalBufferAndViews(wasmMemory.buffer);wasmTable=Module["asm"]["C"];addOnInit(Module["asm"]["B"]);removeRunDependency("wasm-instantiate")}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}function instantiateArrayBuffer(receiver){return getBinaryPromise().then(function(binary){return WebAssembly.instantiate(binary,info)}).then(function(instance){return instance}).then(receiver,function(reason){err("failed to asynchronously prepare wasm: "+reason);abort(reason)})}function instantiateAsync(){if(!wasmBinary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(wasmBinaryFile)&&typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){var result=WebAssembly.instantiateStreaming(response,info);return result.then(receiveInstantiationResult,function(reason){err("wasm streaming compile failed: "+reason);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(receiveInstantiationResult)})})}else{return instantiateArrayBuffer(receiveInstantiationResult)}}if(Module["instantiateWasm"]){try{var exports=Module["instantiateWasm"](info,receiveInstance);return exports}catch(e){err("Module.instantiateWasm callback failed with error: "+e);return false}}instantiateAsync();return{}}function callRuntimeCallbacks(callbacks){while(callbacks.length>0){callbacks.shift()(Module)}}function ___cxa_allocate_exception(size){return _malloc(size+24)+24}function ExceptionInfo(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24;this.set_type=function(type){HEAPU32[this.ptr+4>>2]=type};this.get_type=function(){return HEAPU32[this.ptr+4>>2]};this.set_destructor=function(destructor){HEAPU32[this.ptr+8>>2]=destructor};this.get_destructor=function(){return HEAPU32[this.ptr+8>>2]};this.set_refcount=function(refcount){HEAP32[this.ptr>>2]=refcount};this.set_caught=function(caught){caught=caught?1:0;HEAP8[this.ptr+12>>0]=caught};this.get_caught=function(){return HEAP8[this.ptr+12>>0]!=0};this.set_rethrown=function(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>0]=rethrown};this.get_rethrown=function(){return HEAP8[this.ptr+13>>0]!=0};this.init=function(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor);this.set_refcount(0);this.set_caught(false);this.set_rethrown(false)};this.add_ref=function(){var value=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=value+1};this.release_ref=function(){var prev=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=prev-1;return prev===1};this.set_adjusted_ptr=function(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr};this.get_adjusted_ptr=function(){return HEAPU32[this.ptr+16>>2]};this.get_exception_ptr=function(){var isPointer=___cxa_is_pointer_type(this.get_type());if(isPointer){return HEAPU32[this.excPtr>>2]}var adjusted=this.get_adjusted_ptr();if(adjusted!==0)return adjusted;return this.excPtr}}var exceptionLast=0;var uncaughtExceptionCount=0;function ___cxa_throw(ptr,type,destructor){var info=new ExceptionInfo(ptr);info.init(type,destructor);exceptionLast=ptr;uncaughtExceptionCount++;throw ptr}var SYSCALLS={varargs:undefined,get:function(){SYSCALLS.varargs+=4;var ret=HEAP32[SYSCALLS.varargs-4>>2];return ret},getStr:function(ptr){var ret=UTF8ToString(ptr);return ret}};function ___syscall_fcntl64(fd,cmd,varargs){SYSCALLS.varargs=varargs;return 0}function ___syscall_fstat64(fd,buf){}function ___syscall_getdents64(fd,dirp,count){}function ___syscall_ioctl(fd,op,varargs){SYSCALLS.varargs=varargs;return 0}function ___syscall_lstat64(path,buf){}function ___syscall_newfstatat(dirfd,path,buf,flags){}function ___syscall_openat(dirfd,path,flags,varargs){SYSCALLS.varargs=varargs}function ___syscall_stat64(path,buf){}function __dlinit(main_dso_handle){}var dlopenMissingError="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function __dlopen_js(filename,flag){abort(dlopenMissingError)}function __dlsym_js(handle,symbol){abort(dlopenMissingError)}var nowIsMonotonic=true;function __emscripten_get_now_is_monotonic(){return nowIsMonotonic}function __munmap_js(addr,len,prot,flags,fd,offset){}function _abort(){abort("")}function _emscripten_date_now(){return Date.now()}var _emscripten_get_now;_emscripten_get_now=()=>performance.now();function _emscripten_memcpy_big(dest,src,num){HEAPU8.copyWithin(dest,src,src+num)}function getHeapMax(){return 2147483648}function emscripten_realloc_buffer(size){try{wasmMemory.grow(size-buffer.byteLength+65535>>>16);updateGlobalBufferAndViews(wasmMemory.buffer);return 1}catch(e){}}function _emscripten_resize_heap(requestedSize){var oldSize=HEAPU8.length;requestedSize=requestedSize>>>0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}let alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=emscripten_realloc_buffer(newSize);if(replacement){return true}}return false}var ENV={};function getExecutableName(){return thisProgram||"./this.program"}function getEnvStrings(){if(!getEnvStrings.strings){var lang=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8";var env={"USER":"web_user","LOGNAME":"web_user","PATH":"/","PWD":"/","HOME":"/home/web_user","LANG":lang,"_":getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(x+"="+env[x])}getEnvStrings.strings=strings}return getEnvStrings.strings}function writeAsciiToMemory(str,buffer,dontAddNull){for(var i=0;i>0]=str.charCodeAt(i)}if(!dontAddNull)HEAP8[buffer>>0]=0}function _environ_get(__environ,environ_buf){var bufSize=0;getEnvStrings().forEach(function(string,i){var ptr=environ_buf+bufSize;HEAPU32[__environ+i*4>>2]=ptr;writeAsciiToMemory(string,ptr);bufSize+=string.length+1});return 0}function _environ_sizes_get(penviron_count,penviron_buf_size){var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;strings.forEach(function(string){bufSize+=string.length+1});HEAPU32[penviron_buf_size>>2]=bufSize;return 0}function _fd_close(fd){return 52}function _fd_read(fd,iov,iovcnt,pnum){return 52}function _fd_seek(fd,offset_low,offset_high,whence,newOffset){return 70}var printCharBuffers=[null,[],[]];function printChar(stream,curr){var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}}function _fd_write(fd,iov,iovcnt,pnum){var num=0;for(var i=0;i>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j>2]=num;return 0}var asmLibraryArg={"z":___cxa_allocate_exception,"y":___cxa_throw,"g":___syscall_fcntl64,"w":___syscall_fstat64,"p":___syscall_getdents64,"f":___syscall_ioctl,"t":___syscall_lstat64,"u":___syscall_newfstatat,"h":___syscall_openat,"v":___syscall_stat64,"k":__dlinit,"m":__dlopen_js,"l":__dlsym_js,"i":__emscripten_get_now_is_monotonic,"q":__munmap_js,"c":_abort,"b":_emscripten_date_now,"x":_emscripten_get_now,"j":_emscripten_memcpy_big,"o":_emscripten_resize_heap,"r":_environ_get,"s":_environ_sizes_get,"a":_fd_close,"d":_fd_read,"n":_fd_seek,"e":_fd_write};var asm=createWasm();var ___wasm_call_ctors=Module["___wasm_call_ctors"]=function(){return(___wasm_call_ctors=Module["___wasm_call_ctors"]=Module["asm"]["B"]).apply(null,arguments)};var _malloc=Module["_malloc"]=function(){return(_malloc=Module["_malloc"]=Module["asm"]["D"]).apply(null,arguments)};var _free=Module["_free"]=function(){return(_free=Module["_free"]=Module["asm"]["E"]).apply(null,arguments)};var _Crypto_Malloc=Module["_Crypto_Malloc"]=function(){return(_Crypto_Malloc=Module["_Crypto_Malloc"]=Module["asm"]["F"]).apply(null,arguments)};var _Crypto_Free=Module["_Crypto_Free"]=function(){return(_Crypto_Free=Module["_Crypto_Free"]=Module["asm"]["G"]).apply(null,arguments)};var _Crypto_CreateKeys=Module["_Crypto_CreateKeys"]=function(){return(_Crypto_CreateKeys=Module["_Crypto_CreateKeys"]=Module["asm"]["H"]).apply(null,arguments)};var _Crypto_Sign=Module["_Crypto_Sign"]=function(){return(_Crypto_Sign=Module["_Crypto_Sign"]=Module["asm"]["I"]).apply(null,arguments)};var _Crypto_ChangePassword=Module["_Crypto_ChangePassword"]=function(){return(_Crypto_ChangePassword=Module["_Crypto_ChangePassword"]=Module["asm"]["J"]).apply(null,arguments)};var ___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=function(){return(___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=Module["asm"]["K"]).apply(null,arguments)};var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(args){args=args||arguments_;if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run(); + const chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; + const chars_map = [ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, + -1, 9, 10, 11, 12, 13, 14, 15, 16, -1, 17, 18, 19, 20, 21, -1, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1, + -1, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, -1, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + ]; + let result = []; + for (let i = 0, len = buf.length; i < len; i++) + { + let carry = buf[i]; + for (let j = 0; j < result.length; ++j) + { + const x = (chars_map[result[j]] << 8) + carry; + result[j] = chars.charCodeAt(x % 58); + carry = (x / 58) >> 0; + } + while (carry) + { + result.push(chars.charCodeAt(carry % 58)); + carry = (carry / 58) >> 0; + } + } - function CryptoJS() + let char1 = "1".charCodeAt(0); + for (let i = 0, len = buf.length; i < len; i++) + { + if (buf[i]) + break; + else + result.push(char1); + } + + result.reverse(); + return String.fromCharCode.apply(null, result); + } + + function random(length) + { + let byteArray = new Uint8Array(length); + let engine = window.crypto || window.msCrypto; + if (engine) + engine.getRandomValues(byteArray); + else + { + for (let i = 0; i < length; i++) + byteArray[i] = (Math.random() * 256) >> 0; + } + return byteArray; + } + + function CryptoJS() { this.isModuleInit = false; }; @@ -207,58 +277,121 @@ else { CryptoJS.prototype.isModuleInit = true; }; - CryptoJS.prototype.isModuleInit = false; - window.Asc = window.Asc || {}; - window.Asc.cryptoJS = new CryptoJS(); - window.Asc.CryptoErrors = { - OPEN_SSL_WARNING_OK : 0, - OPEN_SSL_WARNING_ERR : 1, - OPEN_SSL_WARNING_ALL_OK : 2, - OPEN_SSL_WARNING_PASS : 4, - OPEN_SSL_WARNING_NOVERIFY : 8 - }; - - var Module=typeof Module!="undefined"?Module:{};var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=true;var ENVIRONMENT_IS_WORKER=false;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=(url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)}}setWindowTitle=title=>document.title=title}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.warn.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];var noExitRuntime=Module["noExitRuntime"]||true;if(typeof WebAssembly!="object"){abort("no native wasm support detected")}var wasmMemory;var ABORT=false;var EXITSTATUS;var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):undefined;function UTF8ArrayToString(heapOrArray,idx,maxBytesToRead){var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023)}}return str}function UTF8ToString(ptr,maxBytesToRead){return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):""}var buffer,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateGlobalBufferAndViews(buf){buffer=buf;Module["HEAP8"]=HEAP8=new Int8Array(buf);Module["HEAP16"]=HEAP16=new Int16Array(buf);Module["HEAP32"]=HEAP32=new Int32Array(buf);Module["HEAPU8"]=HEAPU8=new Uint8Array(buf);Module["HEAPU16"]=HEAPU16=new Uint16Array(buf);Module["HEAPU32"]=HEAPU32=new Uint32Array(buf);Module["HEAPF32"]=HEAPF32=new Float32Array(buf);Module["HEAPF64"]=HEAPF64=new Float64Array(buf)}var INITIAL_MEMORY=Module["INITIAL_MEMORY"]||16777216;var wasmTable;var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[function(){window.Asc.cryptoJS.onLoad();}];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){{if(Module["onAbort"]){Module["onAbort"](what)}}what="Aborted("+what+")";err(what);ABORT=true;EXITSTATUS=1;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return filename.startsWith(dataURIPrefix)}var wasmBinaryFile;wasmBinaryFile="engine.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}function getBinary(file){try{if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}catch(err){abort(err)}}function getBinaryPromise2(){if(!wasmBinary&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)){if(typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){if(!response["ok"]){throw"failed to load wasm binary file at '"+wasmBinaryFile+"'"}return response["arrayBuffer"]()}).catch(function(){return getBinary(wasmBinaryFile)})}}return Promise.resolve().then(function(){return getBinary(wasmBinaryFile)})}function createWasm(){var info={"a":asmLibraryArg};function receiveInstance(instance,module){var exports=instance.exports;Module["asm"]=exports;wasmMemory=Module["asm"]["A"];updateGlobalBufferAndViews(wasmMemory.buffer);wasmTable=Module["asm"]["C"];addOnInit(Module["asm"]["B"]);removeRunDependency("wasm-instantiate")}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}function instantiateArrayBuffer(receiver){return getBinaryPromise().then(function(binary){return WebAssembly.instantiate(binary,info)}).then(function(instance){return instance}).then(receiver,function(reason){err("failed to asynchronously prepare wasm: "+reason);abort(reason)})}function instantiateAsync(){if(!wasmBinary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(wasmBinaryFile)&&typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){var result=WebAssembly.instantiateStreaming(response,info);return result.then(receiveInstantiationResult,function(reason){err("wasm streaming compile failed: "+reason);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(receiveInstantiationResult)})})}else{return instantiateArrayBuffer(receiveInstantiationResult)}}if(Module["instantiateWasm"]){try{var exports=Module["instantiateWasm"](info,receiveInstance);return exports}catch(e){err("Module.instantiateWasm callback failed with error: "+e);return false}}instantiateAsync();return{}}function callRuntimeCallbacks(callbacks){while(callbacks.length>0){callbacks.shift()(Module)}}function ___cxa_allocate_exception(size){return _malloc(size+24)+24}function ExceptionInfo(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24;this.set_type=function(type){HEAPU32[this.ptr+4>>2]=type};this.get_type=function(){return HEAPU32[this.ptr+4>>2]};this.set_destructor=function(destructor){HEAPU32[this.ptr+8>>2]=destructor};this.get_destructor=function(){return HEAPU32[this.ptr+8>>2]};this.set_refcount=function(refcount){HEAP32[this.ptr>>2]=refcount};this.set_caught=function(caught){caught=caught?1:0;HEAP8[this.ptr+12>>0]=caught};this.get_caught=function(){return HEAP8[this.ptr+12>>0]!=0};this.set_rethrown=function(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>0]=rethrown};this.get_rethrown=function(){return HEAP8[this.ptr+13>>0]!=0};this.init=function(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor);this.set_refcount(0);this.set_caught(false);this.set_rethrown(false)};this.add_ref=function(){var value=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=value+1};this.release_ref=function(){var prev=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=prev-1;return prev===1};this.set_adjusted_ptr=function(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr};this.get_adjusted_ptr=function(){return HEAPU32[this.ptr+16>>2]};this.get_exception_ptr=function(){var isPointer=___cxa_is_pointer_type(this.get_type());if(isPointer){return HEAPU32[this.excPtr>>2]}var adjusted=this.get_adjusted_ptr();if(adjusted!==0)return adjusted;return this.excPtr}}var exceptionLast=0;var uncaughtExceptionCount=0;function ___cxa_throw(ptr,type,destructor){var info=new ExceptionInfo(ptr);info.init(type,destructor);exceptionLast=ptr;uncaughtExceptionCount++;throw ptr}var SYSCALLS={varargs:undefined,get:function(){SYSCALLS.varargs+=4;var ret=HEAP32[SYSCALLS.varargs-4>>2];return ret},getStr:function(ptr){var ret=UTF8ToString(ptr);return ret}};function ___syscall_fcntl64(fd,cmd,varargs){SYSCALLS.varargs=varargs;return 0}function ___syscall_fstat64(fd,buf){}function ___syscall_getdents64(fd,dirp,count){}function ___syscall_ioctl(fd,op,varargs){SYSCALLS.varargs=varargs;return 0}function ___syscall_lstat64(path,buf){}function ___syscall_newfstatat(dirfd,path,buf,flags){}function ___syscall_openat(dirfd,path,flags,varargs){SYSCALLS.varargs=varargs}function ___syscall_stat64(path,buf){}function __dlinit(main_dso_handle){}var dlopenMissingError="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function __dlopen_js(filename,flag){abort(dlopenMissingError)}function __dlsym_js(handle,symbol){abort(dlopenMissingError)}var nowIsMonotonic=true;function __emscripten_get_now_is_monotonic(){return nowIsMonotonic}function __munmap_js(addr,len,prot,flags,fd,offset){}function _abort(){abort("")}function _emscripten_date_now(){return Date.now()}var _emscripten_get_now;_emscripten_get_now=()=>performance.now();function _emscripten_memcpy_big(dest,src,num){HEAPU8.copyWithin(dest,src,src+num)}function getHeapMax(){return 2147483648}function emscripten_realloc_buffer(size){try{wasmMemory.grow(size-buffer.byteLength+65535>>>16);updateGlobalBufferAndViews(wasmMemory.buffer);return 1}catch(e){}}function _emscripten_resize_heap(requestedSize){var oldSize=HEAPU8.length;requestedSize=requestedSize>>>0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}let alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=emscripten_realloc_buffer(newSize);if(replacement){return true}}return false}var ENV={};function getExecutableName(){return thisProgram||"./this.program"}function getEnvStrings(){if(!getEnvStrings.strings){var lang=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8";var env={"USER":"web_user","LOGNAME":"web_user","PATH":"/","PWD":"/","HOME":"/home/web_user","LANG":lang,"_":getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(x+"="+env[x])}getEnvStrings.strings=strings}return getEnvStrings.strings}function writeAsciiToMemory(str,buffer,dontAddNull){for(var i=0;i>0]=str.charCodeAt(i)}if(!dontAddNull)HEAP8[buffer>>0]=0}function _environ_get(__environ,environ_buf){var bufSize=0;getEnvStrings().forEach(function(string,i){var ptr=environ_buf+bufSize;HEAPU32[__environ+i*4>>2]=ptr;writeAsciiToMemory(string,ptr);bufSize+=string.length+1});return 0}function _environ_sizes_get(penviron_count,penviron_buf_size){var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;strings.forEach(function(string){bufSize+=string.length+1});HEAPU32[penviron_buf_size>>2]=bufSize;return 0}function _fd_close(fd){return 52}function _fd_read(fd,iov,iovcnt,pnum){return 52}function _fd_seek(fd,offset_low,offset_high,whence,newOffset){return 70}var printCharBuffers=[null,[],[]];function printChar(stream,curr){var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}}function _fd_write(fd,iov,iovcnt,pnum){var num=0;for(var i=0;i>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j>2]=num;return 0}var asmLibraryArg={"z":___cxa_allocate_exception,"y":___cxa_throw,"g":___syscall_fcntl64,"w":___syscall_fstat64,"p":___syscall_getdents64,"f":___syscall_ioctl,"t":___syscall_lstat64,"u":___syscall_newfstatat,"h":___syscall_openat,"v":___syscall_stat64,"k":__dlinit,"m":__dlopen_js,"l":__dlsym_js,"i":__emscripten_get_now_is_monotonic,"q":__munmap_js,"c":_abort,"b":_emscripten_date_now,"x":_emscripten_get_now,"j":_emscripten_memcpy_big,"o":_emscripten_resize_heap,"r":_environ_get,"s":_environ_sizes_get,"a":_fd_close,"d":_fd_read,"n":_fd_seek,"e":_fd_write};var asm=createWasm();var ___wasm_call_ctors=Module["___wasm_call_ctors"]=function(){return(___wasm_call_ctors=Module["___wasm_call_ctors"]=Module["asm"]["B"]).apply(null,arguments)};var _malloc=Module["_malloc"]=function(){return(_malloc=Module["_malloc"]=Module["asm"]["D"]).apply(null,arguments)};var _free=Module["_free"]=function(){return(_free=Module["_free"]=Module["asm"]["E"]).apply(null,arguments)};var _Crypto_Malloc=Module["_Crypto_Malloc"]=function(){return(_Crypto_Malloc=Module["_Crypto_Malloc"]=Module["asm"]["F"]).apply(null,arguments)};var _Crypto_Free=Module["_Crypto_Free"]=function(){return(_Crypto_Free=Module["_Crypto_Free"]=Module["asm"]["G"]).apply(null,arguments)};var _Crypto_CreateKeys=Module["_Crypto_CreateKeys"]=function(){return(_Crypto_CreateKeys=Module["_Crypto_CreateKeys"]=Module["asm"]["H"]).apply(null,arguments)};var _Crypto_Sign=Module["_Crypto_Sign"]=function(){return(_Crypto_Sign=Module["_Crypto_Sign"]=Module["asm"]["I"]).apply(null,arguments)};var _Crypto_ChangePassword=Module["_Crypto_ChangePassword"]=function(){return(_Crypto_ChangePassword=Module["_Crypto_ChangePassword"]=Module["asm"]["J"]).apply(null,arguments)};var ___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=function(){return(___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=Module["asm"]["K"]).apply(null,arguments)};var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(args){args=args||arguments_;if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run(); - - - // AES - CryptoJS.prototype.AES_Encrypt = function(password, message) + CryptoJS.prototype.generateKeys = function(password, salt) { - // generate salt & encrypt message + if (!this.isModuleInit) + return null; + + if (!salt) + salt = toBase64(random(32)); + + let algPtr = "ed25519".toUtf8Pointer(); + let passwordPtr = password.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + + let keys = Module["_Crypto_CreateKeys"](algPtr.ptr, passwordPtr.ptr, saltPtr.ptr); + + algPtr.free(); + passwordPtr.free(); + saltPtr.free(); + + if (keys === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = keys; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + let publicKey = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + currentStart = currentEnd + 1; + currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + let privateKey = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](keys); + + return { + "salt" : salt, + "privateKey" : privateKey, + "publicKey" : publicKey + }; }; - CryptoJS.prototype.AES_Encrypt = function(password, salt, message) + + CryptoJS.prototype.sign = function(privateKey, password, salt, xml) { + if (!this.isModuleInit) + return null; + let privateKeyPtr = privateKey.toUtf8Pointer(); + let passwordPtr = password.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + let xmlPtr = xml.toUtf8Pointer(); + + let signData = Module["_Crypto_Sign"](privateKeyPtr.ptr, passwordPtr.ptr, saltPtr.ptr, + xmlPtr.ptr, xmlPtr.length); + + privateKeyPtr.free(); + passwordPtr.free(); + saltPtr.free(); + xmlPtr.free(); + + if (signData === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = signData; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + + let signString = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](signData); + return signString; }; - CryptoJS.prototype.AES_Decrypt = function(password, message) + CryptoJS.prototype.changePassword = function(privateKey, passwordOld, passwordNew, salt) { + if (!this.isModuleInit) + return null; + + let privateKeyPtr = privateKey.toUtf8Pointer(); + let passwordOldPtr = passwordOld.toUtf8Pointer(); + let passwordNewPtr = passwordNew.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + + let privateKeyEnc = Module["_Crypto_Sign"](privateKeyPtr.ptr, + passwordOldPtr.ptr, passwordNewPtr.ptr, saltPtr.length); + + privateKeyPtr.free(); + passwordOldPtr.free(); + passwordNewPtr.free(); + saltPtr.free(); + + if (privateKeyEnc === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = privateKeyEnc; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + + let privateKeyString = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](privateKeyEnc); + return privateKeyString; }; - // Signature - CryptoJS.prototype.CreateED25519Keys = function() - { - - }; - - CryproJS.prototype.Sign = function(privateKey, message) - { - - }; - - CryproJS.prototype.Verify = function(publicKey, message) - { - - }; - - // Certificate & keys - CryproJS.prototype.loadCert = function(data, password) - { - }; - CryproJS.prototype.loadKey = function(data, password) - { - }; + window.CryptoJS = CryptoJS; + var Module=typeof Module!="undefined"?Module:{};var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=true;var ENVIRONMENT_IS_WORKER=false;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=(url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)}}setWindowTitle=title=>document.title=title}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.warn.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];var noExitRuntime=Module["noExitRuntime"]||true;if(typeof WebAssembly!="object"){abort("no native wasm support detected")}var wasmMemory;var ABORT=false;var EXITSTATUS;var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):undefined;function UTF8ArrayToString(heapOrArray,idx,maxBytesToRead){var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023)}}return str}function UTF8ToString(ptr,maxBytesToRead){return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):""}var buffer,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateGlobalBufferAndViews(buf){buffer=buf;Module["HEAP8"]=HEAP8=new Int8Array(buf);Module["HEAP16"]=HEAP16=new Int16Array(buf);Module["HEAP32"]=HEAP32=new Int32Array(buf);Module["HEAPU8"]=HEAPU8=new Uint8Array(buf);Module["HEAPU16"]=HEAPU16=new Uint16Array(buf);Module["HEAPU32"]=HEAPU32=new Uint32Array(buf);Module["HEAPF32"]=HEAPF32=new Float32Array(buf);Module["HEAPF64"]=HEAPF64=new Float64Array(buf)}var INITIAL_MEMORY=Module["INITIAL_MEMORY"]||16777216;var wasmTable;var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[function(){window.Asc.cryptoJS.onLoad();}];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){{if(Module["onAbort"]){Module["onAbort"](what)}}what="Aborted("+what+")";err(what);ABORT=true;EXITSTATUS=1;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return filename.startsWith(dataURIPrefix)}var wasmBinaryFile;wasmBinaryFile="engine.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}function getBinary(file){try{if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}catch(err){abort(err)}}function getBinaryPromise2(){if(!wasmBinary&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)){if(typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){if(!response["ok"]){throw"failed to load wasm binary file at '"+wasmBinaryFile+"'"}return response["arrayBuffer"]()}).catch(function(){return getBinary(wasmBinaryFile)})}}return Promise.resolve().then(function(){return getBinary(wasmBinaryFile)})}function createWasm(){var info={"a":asmLibraryArg};function receiveInstance(instance,module){var exports=instance.exports;Module["asm"]=exports;wasmMemory=Module["asm"]["A"];updateGlobalBufferAndViews(wasmMemory.buffer);wasmTable=Module["asm"]["C"];addOnInit(Module["asm"]["B"]);removeRunDependency("wasm-instantiate")}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}function instantiateArrayBuffer(receiver){return getBinaryPromise().then(function(binary){return WebAssembly.instantiate(binary,info)}).then(function(instance){return instance}).then(receiver,function(reason){err("failed to asynchronously prepare wasm: "+reason);abort(reason)})}function instantiateAsync(){if(!wasmBinary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(wasmBinaryFile)&&typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){var result=WebAssembly.instantiateStreaming(response,info);return result.then(receiveInstantiationResult,function(reason){err("wasm streaming compile failed: "+reason);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(receiveInstantiationResult)})})}else{return instantiateArrayBuffer(receiveInstantiationResult)}}if(Module["instantiateWasm"]){try{var exports=Module["instantiateWasm"](info,receiveInstance);return exports}catch(e){err("Module.instantiateWasm callback failed with error: "+e);return false}}instantiateAsync();return{}}function callRuntimeCallbacks(callbacks){while(callbacks.length>0){callbacks.shift()(Module)}}function ___cxa_allocate_exception(size){return _malloc(size+24)+24}function ExceptionInfo(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24;this.set_type=function(type){HEAPU32[this.ptr+4>>2]=type};this.get_type=function(){return HEAPU32[this.ptr+4>>2]};this.set_destructor=function(destructor){HEAPU32[this.ptr+8>>2]=destructor};this.get_destructor=function(){return HEAPU32[this.ptr+8>>2]};this.set_refcount=function(refcount){HEAP32[this.ptr>>2]=refcount};this.set_caught=function(caught){caught=caught?1:0;HEAP8[this.ptr+12>>0]=caught};this.get_caught=function(){return HEAP8[this.ptr+12>>0]!=0};this.set_rethrown=function(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>0]=rethrown};this.get_rethrown=function(){return HEAP8[this.ptr+13>>0]!=0};this.init=function(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor);this.set_refcount(0);this.set_caught(false);this.set_rethrown(false)};this.add_ref=function(){var value=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=value+1};this.release_ref=function(){var prev=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=prev-1;return prev===1};this.set_adjusted_ptr=function(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr};this.get_adjusted_ptr=function(){return HEAPU32[this.ptr+16>>2]};this.get_exception_ptr=function(){var isPointer=___cxa_is_pointer_type(this.get_type());if(isPointer){return HEAPU32[this.excPtr>>2]}var adjusted=this.get_adjusted_ptr();if(adjusted!==0)return adjusted;return this.excPtr}}var exceptionLast=0;var uncaughtExceptionCount=0;function ___cxa_throw(ptr,type,destructor){var info=new ExceptionInfo(ptr);info.init(type,destructor);exceptionLast=ptr;uncaughtExceptionCount++;throw ptr}var SYSCALLS={varargs:undefined,get:function(){SYSCALLS.varargs+=4;var ret=HEAP32[SYSCALLS.varargs-4>>2];return ret},getStr:function(ptr){var ret=UTF8ToString(ptr);return ret}};function ___syscall_fcntl64(fd,cmd,varargs){SYSCALLS.varargs=varargs;return 0}function ___syscall_fstat64(fd,buf){}function ___syscall_getdents64(fd,dirp,count){}function ___syscall_ioctl(fd,op,varargs){SYSCALLS.varargs=varargs;return 0}function ___syscall_lstat64(path,buf){}function ___syscall_newfstatat(dirfd,path,buf,flags){}function ___syscall_openat(dirfd,path,flags,varargs){SYSCALLS.varargs=varargs}function ___syscall_stat64(path,buf){}function __dlinit(main_dso_handle){}var dlopenMissingError="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function __dlopen_js(filename,flag){abort(dlopenMissingError)}function __dlsym_js(handle,symbol){abort(dlopenMissingError)}var nowIsMonotonic=true;function __emscripten_get_now_is_monotonic(){return nowIsMonotonic}function __munmap_js(addr,len,prot,flags,fd,offset){}function _abort(){abort("")}function _emscripten_date_now(){return Date.now()}var _emscripten_get_now;_emscripten_get_now=()=>performance.now();function _emscripten_memcpy_big(dest,src,num){HEAPU8.copyWithin(dest,src,src+num)}function getHeapMax(){return 2147483648}function emscripten_realloc_buffer(size){try{wasmMemory.grow(size-buffer.byteLength+65535>>>16);updateGlobalBufferAndViews(wasmMemory.buffer);return 1}catch(e){}}function _emscripten_resize_heap(requestedSize){var oldSize=HEAPU8.length;requestedSize=requestedSize>>>0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}let alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=emscripten_realloc_buffer(newSize);if(replacement){return true}}return false}var ENV={};function getExecutableName(){return thisProgram||"./this.program"}function getEnvStrings(){if(!getEnvStrings.strings){var lang=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8";var env={"USER":"web_user","LOGNAME":"web_user","PATH":"/","PWD":"/","HOME":"/home/web_user","LANG":lang,"_":getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(x+"="+env[x])}getEnvStrings.strings=strings}return getEnvStrings.strings}function writeAsciiToMemory(str,buffer,dontAddNull){for(var i=0;i>0]=str.charCodeAt(i)}if(!dontAddNull)HEAP8[buffer>>0]=0}function _environ_get(__environ,environ_buf){var bufSize=0;getEnvStrings().forEach(function(string,i){var ptr=environ_buf+bufSize;HEAPU32[__environ+i*4>>2]=ptr;writeAsciiToMemory(string,ptr);bufSize+=string.length+1});return 0}function _environ_sizes_get(penviron_count,penviron_buf_size){var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;strings.forEach(function(string){bufSize+=string.length+1});HEAPU32[penviron_buf_size>>2]=bufSize;return 0}function _fd_close(fd){return 52}function _fd_read(fd,iov,iovcnt,pnum){return 52}function _fd_seek(fd,offset_low,offset_high,whence,newOffset){return 70}var printCharBuffers=[null,[],[]];function printChar(stream,curr){var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}}function _fd_write(fd,iov,iovcnt,pnum){var num=0;for(var i=0;i>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j>2]=num;return 0}var asmLibraryArg={"z":___cxa_allocate_exception,"y":___cxa_throw,"g":___syscall_fcntl64,"w":___syscall_fstat64,"p":___syscall_getdents64,"f":___syscall_ioctl,"t":___syscall_lstat64,"u":___syscall_newfstatat,"h":___syscall_openat,"v":___syscall_stat64,"k":__dlinit,"m":__dlopen_js,"l":__dlsym_js,"i":__emscripten_get_now_is_monotonic,"q":__munmap_js,"c":_abort,"b":_emscripten_date_now,"x":_emscripten_get_now,"j":_emscripten_memcpy_big,"o":_emscripten_resize_heap,"r":_environ_get,"s":_environ_sizes_get,"a":_fd_close,"d":_fd_read,"n":_fd_seek,"e":_fd_write};var asm=createWasm();var ___wasm_call_ctors=Module["___wasm_call_ctors"]=function(){return(___wasm_call_ctors=Module["___wasm_call_ctors"]=Module["asm"]["B"]).apply(null,arguments)};var _malloc=Module["_malloc"]=function(){return(_malloc=Module["_malloc"]=Module["asm"]["D"]).apply(null,arguments)};var _free=Module["_free"]=function(){return(_free=Module["_free"]=Module["asm"]["E"]).apply(null,arguments)};var _Crypto_Malloc=Module["_Crypto_Malloc"]=function(){return(_Crypto_Malloc=Module["_Crypto_Malloc"]=Module["asm"]["F"]).apply(null,arguments)};var _Crypto_Free=Module["_Crypto_Free"]=function(){return(_Crypto_Free=Module["_Crypto_Free"]=Module["asm"]["G"]).apply(null,arguments)};var _Crypto_CreateKeys=Module["_Crypto_CreateKeys"]=function(){return(_Crypto_CreateKeys=Module["_Crypto_CreateKeys"]=Module["asm"]["H"]).apply(null,arguments)};var _Crypto_Sign=Module["_Crypto_Sign"]=function(){return(_Crypto_Sign=Module["_Crypto_Sign"]=Module["asm"]["I"]).apply(null,arguments)};var _Crypto_ChangePassword=Module["_Crypto_ChangePassword"]=function(){return(_Crypto_ChangePassword=Module["_Crypto_ChangePassword"]=Module["asm"]["J"]).apply(null,arguments)};var ___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=function(){return(___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=Module["asm"]["K"]).apply(null,arguments)};var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(args){args=args||arguments_;if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run(); })(window, undefined); diff --git a/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/deploy/engine_ie.js b/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/deploy/engine_ie.js index 107087d252..49e041c188 100644 --- a/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/deploy/engine_ie.js +++ b/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/deploy/engine_ie.js @@ -246,6 +246,202 @@ Uint8Array.prototype.copyWithin = Uint8Array.prototype.copyWithin || function(ta })(); + function toBase64(buf) + { + if(typeof buf === "string") + { + let old = buf; + buf = []; + for (let i = 0, len = old.length; i < len; i++) + buf.push(old.charCodeAt(i)); + } + + const chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; + const chars_map = [ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, + -1, 9, 10, 11, 12, 13, 14, 15, 16, -1, 17, 18, 19, 20, 21, -1, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1, + -1, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, -1, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + ]; + + let result = []; + for (let i = 0, len = buf.length; i < len; i++) + { + let carry = buf[i]; + for (let j = 0; j < result.length; ++j) + { + const x = (chars_map[result[j]] << 8) + carry; + result[j] = chars.charCodeAt(x % 58); + carry = (x / 58) >> 0; + } + while (carry) + { + result.push(chars.charCodeAt(carry % 58)); + carry = (carry / 58) >> 0; + } + } + + let char1 = "1".charCodeAt(0); + for (let i = 0, len = buf.length; i < len; i++) + { + if (buf[i]) + break; + else + result.push(char1); + } + + result.reverse(); + return String.fromCharCode.apply(null, result); + } + + function random(length) + { + let byteArray = new Uint8Array(length); + let engine = window.crypto || window.msCrypto; + if (engine) + engine.getRandomValues(byteArray); + else + { + for (let i = 0; i < length; i++) + byteArray[i] = (Math.random() * 256) >> 0; + } + return byteArray; + } + + function CryptoJS() + { + this.isModuleInit = false; + }; + CryptoJS.prototype.onLoad = function() + { + CryptoJS.prototype.isModuleInit = true; + }; + + CryptoJS.prototype.generateKeys = function(password, salt) + { + if (!this.isModuleInit) + return null; + + if (!salt) + salt = toBase64(random(32)); + + let algPtr = "ed25519".toUtf8Pointer(); + let passwordPtr = password.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + + let keys = Module["_Crypto_CreateKeys"](algPtr.ptr, passwordPtr.ptr, saltPtr.ptr); + + algPtr.free(); + passwordPtr.free(); + saltPtr.free(); + + if (keys === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = keys; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + let publicKey = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + currentStart = currentEnd + 1; + currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + let privateKey = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](keys); + + return { + "salt" : salt, + "privateKey" : privateKey, + "publicKey" : publicKey + }; + }; + + CryptoJS.prototype.sign = function(privateKey, password, salt, xml) + { + if (!this.isModuleInit) + return null; + + let privateKeyPtr = privateKey.toUtf8Pointer(); + let passwordPtr = password.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + let xmlPtr = xml.toUtf8Pointer(); + + let signData = Module["_Crypto_Sign"](privateKeyPtr.ptr, passwordPtr.ptr, saltPtr.ptr, + xmlPtr.ptr, xmlPtr.length); + + privateKeyPtr.free(); + passwordPtr.free(); + saltPtr.free(); + xmlPtr.free(); + + if (signData === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = signData; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + + let signString = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](signData); + return signString; + }; + + CryptoJS.prototype.changePassword = function(privateKey, passwordOld, passwordNew, salt) + { + if (!this.isModuleInit) + return null; + + let privateKeyPtr = privateKey.toUtf8Pointer(); + let passwordOldPtr = passwordOld.toUtf8Pointer(); + let passwordNewPtr = passwordNew.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + + let privateKeyEnc = Module["_Crypto_Sign"](privateKeyPtr.ptr, + passwordOldPtr.ptr, passwordNewPtr.ptr, saltPtr.length); + + privateKeyPtr.free(); + passwordOldPtr.free(); + passwordNewPtr.free(); + saltPtr.free(); + + if (privateKeyEnc === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = privateKeyEnc; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + + let privateKeyString = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](privateKeyEnc); + return privateKeyString; + }; + + window.CryptoJS = CryptoJS; var Module=typeof Module!="undefined"?Module:{}; var Promise=function(){function noop(){}function bind(fn,thisArg){return function(){fn.apply(thisArg,arguments)}}function Promise(fn){if(!(this instanceof Promise))throw new TypeError("Promises must be constructed via new");if(typeof fn!="function")throw new TypeError("not a function");this._state=0;this._handled=false;this._value=undefined;this._deferreds=[];doResolve(fn,this)}function handle(self,deferred){while(self._state===3)self=self._value;if(self._state===0){self._deferreds.push(deferred); @@ -323,27 +519,6 @@ dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dep function run(args){args=args||arguments_;if(runDependencies>0)return;preRun();if(runDependencies>0)return;function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else doRun()} if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0)Module["preInit"].pop()()}run(); - - function CryptoJS() - { - this.isModuleInit = false; - }; - CryptoJS.prototype.onLoad = function() - { - CryptoJS.prototype.isModuleInit = true; - }; - CryptoJS.prototype.isModuleInit = false; - - window.Asc = window.Asc || {}; - window.Asc.cryptoJS = new CryptoJS(); - window.Asc.CryptoErrors = { - OPEN_SSL_WARNING_OK : 0, - OPEN_SSL_WARNING_ERR : 1, - OPEN_SSL_WARNING_ALL_OK : 2, - OPEN_SSL_WARNING_PASS : 4, - OPEN_SSL_WARNING_NOVERIFY : 8 - }; - var Module=typeof Module!="undefined"?Module:{}; var Promise=function(){function noop(){}function bind(fn,thisArg){return function(){fn.apply(thisArg,arguments)}}function Promise(fn){if(!(this instanceof Promise))throw new TypeError("Promises must be constructed via new");if(typeof fn!="function")throw new TypeError("not a function");this._state=0;this._handled=false;this._value=undefined;this._deferreds=[];doResolve(fn,this)}function handle(self,deferred){while(self._state===3)self=self._value;if(self._state===0){self._deferreds.push(deferred); return}self._handled=true;Promise._immediateFn(function(){var cb=self._state===1?deferred.onFulfilled:deferred.onRejected;if(cb===null){(self._state===1?resolve:reject)(deferred.promise,self._value);return}var ret;try{ret=cb(self._value)}catch(e){reject(deferred.promise,e);return}resolve(deferred.promise,ret)})}function resolve(self,newValue){try{if(newValue===self)throw new TypeError("A promise cannot be resolved with itself.");if(newValue&&(typeof newValue=="object"||typeof newValue=="function")){var then= @@ -420,44 +595,5 @@ dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dep function run(args){args=args||arguments_;if(runDependencies>0)return;preRun();if(runDependencies>0)return;function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else doRun()} if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0)Module["preInit"].pop()()}run(); - - // AES - CryptoJS.prototype.AES_Encrypt = function(password, message) - { - // generate salt & encrypt message - }; - CryptoJS.prototype.AES_Encrypt = function(password, salt, message) - { - - }; - - CryptoJS.prototype.AES_Decrypt = function(password, message) - { - }; - - // Signature - CryptoJS.prototype.CreateED25519Keys = function() - { - - }; - - CryproJS.prototype.Sign = function(privateKey, message) - { - - }; - - CryproJS.prototype.Verify = function(publicKey, message) - { - - }; - - // Certificate & keys - CryproJS.prototype.loadCert = function(data, password) - { - }; - CryproJS.prototype.loadKey = function(data, password) - { - }; - })(window, undefined); diff --git a/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/engine_base.js b/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/engine_base.js index 67d1a1bd43..d3a5bd0d30 100644 --- a/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/engine_base.js +++ b/DesktopEditor/xmlsec/src/wasm/oform_plugin/module/engine_base.js @@ -6,9 +6,81 @@ //string_utf8 - //module + function toBase64(buf) + { + if(typeof buf === "string") + { + let old = buf; + buf = []; + for (let i = 0, len = old.length; i < len; i++) + buf.push(old.charCodeAt(i)); + } - function CryptoJS() + const chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; + const chars_map = [ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, + -1, 9, 10, 11, 12, 13, 14, 15, 16, -1, 17, 18, 19, 20, 21, -1, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1, + -1, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, -1, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + ]; + + let result = []; + for (let i = 0, len = buf.length; i < len; i++) + { + let carry = buf[i]; + for (let j = 0; j < result.length; ++j) + { + const x = (chars_map[result[j]] << 8) + carry; + result[j] = chars.charCodeAt(x % 58); + carry = (x / 58) >> 0; + } + while (carry) + { + result.push(chars.charCodeAt(carry % 58)); + carry = (carry / 58) >> 0; + } + } + + let char1 = "1".charCodeAt(0); + for (let i = 0, len = buf.length; i < len; i++) + { + if (buf[i]) + break; + else + result.push(char1); + } + + result.reverse(); + return String.fromCharCode.apply(null, result); + } + + function random(length) + { + let byteArray = new Uint8Array(length); + let engine = window.crypto || window.msCrypto; + if (engine) + engine.getRandomValues(byteArray); + else + { + for (let i = 0; i < length; i++) + byteArray[i] = (Math.random() * 256) >> 0; + } + return byteArray; + } + + function CryptoJS() { this.isModuleInit = false; }; @@ -16,57 +88,122 @@ { CryptoJS.prototype.isModuleInit = true; }; - CryptoJS.prototype.isModuleInit = false; - window.Asc = window.Asc || {}; - window.Asc.cryptoJS = new CryptoJS(); - window.Asc.CryptoErrors = { - OPEN_SSL_WARNING_OK : 0, - OPEN_SSL_WARNING_ERR : 1, - OPEN_SSL_WARNING_ALL_OK : 2, - OPEN_SSL_WARNING_PASS : 4, - OPEN_SSL_WARNING_NOVERIFY : 8 - }; - - //module - - // AES - CryptoJS.prototype.AES_Encrypt = function(password, message) + CryptoJS.prototype.generateKeys = function(password, salt) { - // generate salt & encrypt message + if (!this.isModuleInit) + return null; + + if (!salt) + salt = toBase64(random(32)); + + let algPtr = "ed25519".toUtf8Pointer(); + let passwordPtr = password.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + + let keys = Module["_Crypto_CreateKeys"](algPtr.ptr, passwordPtr.ptr, saltPtr.ptr); + + algPtr.free(); + passwordPtr.free(); + saltPtr.free(); + + if (keys === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = keys; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + let publicKey = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + currentStart = currentEnd + 1; + currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + let privateKey = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](keys); + + return { + "salt" : salt, + "privateKey" : privateKey, + "publicKey" : publicKey + }; }; - CryptoJS.prototype.AES_Encrypt = function(password, salt, message) + + CryptoJS.prototype.sign = function(privateKey, password, salt, xml) { + if (!this.isModuleInit) + return null; + let privateKeyPtr = privateKey.toUtf8Pointer(); + let passwordPtr = password.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + let xmlPtr = xml.toUtf8Pointer(); + + let signData = Module["_Crypto_Sign"](privateKeyPtr.ptr, passwordPtr.ptr, saltPtr.ptr, + xmlPtr.ptr, xmlPtr.length); + + privateKeyPtr.free(); + passwordPtr.free(); + saltPtr.free(); + xmlPtr.free(); + + if (signData === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = signData; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + + let signString = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](signData); + return signString; }; - CryptoJS.prototype.AES_Decrypt = function(password, message) + CryptoJS.prototype.changePassword = function(privateKey, passwordOld, passwordNew, salt) { + if (!this.isModuleInit) + return null; + + let privateKeyPtr = privateKey.toUtf8Pointer(); + let passwordOldPtr = passwordOld.toUtf8Pointer(); + let passwordNewPtr = passwordNew.toUtf8Pointer(); + let saltPtr = salt.toUtf8Pointer(); + + let privateKeyEnc = Module["_Crypto_Sign"](privateKeyPtr.ptr, + passwordOldPtr.ptr, passwordNewPtr.ptr, saltPtr.length); + + privateKeyPtr.free(); + passwordOldPtr.free(); + passwordNewPtr.free(); + saltPtr.free(); + + if (privateKeyEnc === 0) + return null; + + let heap = Module["HEAP8"]; + + let currentStart = privateKeyEnc; + let currentEnd = currentStart; + while (heap[currentEnd] != 0) + currentEnd++; + + let privateKeyString = String.fromUtf8(heap, currentStart, currentEnd - currentStart); + + Module["_Crypto_Free"](privateKeyEnc); + return privateKeyString; }; - // Signature - CryptoJS.prototype.CreateED25519Keys = function() - { + window.CryptoJS = CryptoJS; - }; - - CryproJS.prototype.Sign = function(privateKey, message) - { - - }; - - CryproJS.prototype.Verify = function(publicKey, message) - { - - }; - - // Certificate & keys - CryproJS.prototype.loadCert = function(data, password) - { - }; - CryproJS.prototype.loadKey = function(data, password) - { - }; + //module })(window, undefined);