├── .gitignore ├── Dockerfile ├── README.md ├── emscr ├── binary │ ├── openssl.js │ └── openssl.wasm └── builds │ └── openssl │ ├── build.sh │ └── openssl.cnf ├── index.js ├── package-lock.json ├── package.json ├── sources ├── OpenSSL_CommandLine.js ├── openssl-gui │ ├── CommandField.js │ ├── Helpers.js │ ├── OpenSSL_GUI.js │ └── tabs │ │ ├── EncryptionTab.js │ │ ├── FilesTab.js │ │ ├── GenKeysTab.js │ │ ├── HashesTab.js │ │ ├── SignVerifyTab.js │ │ └── WelcomeTab.js ├── translations.js └── xterm-for-react.js ├── static ├── index.html └── style.css └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | 4 | emscr/builds/**/src 5 | emscr/builds/**/*.tar.gz 6 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Multi-stage 2 | # 1) Node image for building frontend assets 3 | # 2) nginx stage to serve frontend assets 4 | # Name the node stage "builder" 5 | FROM node:16.3.0-alpine AS builder 6 | # Set working directory 7 | WORKDIR /app 8 | # Copy all files from current directory to working dir in image 9 | COPY . . 10 | # install node modules and build assets 11 | RUN npm install && npm run build 12 | 13 | # nginx state for serving content 14 | FROM nginx:alpine 15 | # Set working directory to nginx asset directory 16 | WORKDIR /usr/share/nginx/html 17 | # Remove default nginx static assets 18 | RUN rm -rf ./* 19 | # Copy static assets from builder stage 20 | COPY --from=builder /app/dist . 21 | # Containers run nginx with global directives and daemon off 22 | ENTRYPOINT ["nginx", "-g", "daemon off;"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenSSL Webterm 2 | 3 | User-friendly web app to use OpenSSL, based on WebAssembly. OpenSSL v3 has been compiled with Emscripten to run in a terminal/tty emulator in the browser. See the [Live Demo](https://www.cryptool.org/cto/openssl). You could also [host this on your own machine](#installation). 4 | 5 | We then built a graphical user interface (GUI) on top of that, so it's easy for newbies to operate. Your actions in the GUI are transformed to original OpenSSL commands on the command line, so you easily can learn their syntax. 6 | 7 | > **Disclaimer**: This tool is intended for teaching and educational purposes. It was developed in 2021 by the [CrypTool project](https://www.cryptool.org) in order to run OpenSSL v3 in a browser. You can also look at [its predecessor](https://github.com/janeumnn/openssl-webapp). 8 | 9 | ![image](https://user-images.githubusercontent.com/9321076/157410455-686ce0de-335f-4335-a639-07b6963e4589.png) 10 | 11 | 12 | ## Installation 13 | 14 | First, [install Node.js and npm](https://nodejs.org). Then clone this project and install its dependencies: 15 | 16 | ```shell 17 | $ git clone https://github.com/cryptool-org/openssl-webterm.git 18 | $ cd openssl-webterm 19 | $ npm install 20 | ``` 21 | 22 | Then start a Webpack development server: 23 | 24 | ```shell 25 | $ npm run serve 26 | ``` 27 | 28 | You can now view the OpenSSL Webterm at https://localhost:4200. 29 | 30 | 31 | ## Internal workings 32 | 33 | The React GUI just builds commands (as strings). These are then called upon the terminal, which is an instance of [wasm-webterm](https://github.com/cryptool-org/wasm-webterm). If your browser supports WebWorkers (including SharedArrayBuffers and Atomics), a new Worker thread is spawned and the WebAssembly binary ([`openssl.wasm`](/emscr/binary/openssl.wasm)) is ran there. Otherwise, it is executed on the main browser thread using a fallback (which can freeze the tab). 34 | 35 | The WebAssembly binary is executed using the (auto generated) Emscripten JS runtime contained in [`openssl.js`](/emscr/binary/openssl.js). It initializes a virtual memory filesystem and handles input/output calls. 36 | 37 | If the binary asks for input (reads from `/dev/stdin`), the thread will be paused until the user entered something. If the binary prints to `/dev/stdout` or `/dev/stderr`, it will be shown on the [xterm.js](https://github.com/xtermjs/xterm.js) web terminal. 38 | 39 | After each command, the files in the memory filesystem are gathered and passed to the React GUI. 40 | 41 | 42 | ## Compiling OpenSSL 43 | 44 | You can compile the OpenSSL WebAssembly binary by calling one the following commands. Note that this is not neccessary, as [it's already compiled](/emscr/binary). 45 | 46 | Both call the script in [`emscr/builds/openssl/build.sh`](/emscr/builds/openssl/build.sh). It fetches and extracts the OpenSSL sources as a `.tar.gz` archive from https://www.openssl.org/source. It then compiles them with Emscripten by calling `emconfigure` and `emmake` (both with specific flags). 47 | 48 | The created files `openssl.wasm` and `openssl.js` are then copied into `emscr/binary`, where the webpack server will deliver them from. 49 | 50 | ### Option 1: Using Docker 51 | 52 | First, [install and start Docker](https://docs.docker.com/get-docker). Then run the following command: 53 | 54 | ```shell 55 | $ npm run build:openssl:docker 56 | ``` 57 | 58 | This will fetch Emscripten's Docker image [`emscripten/emsdk`](https://hub.docker.com/r/emscripten/emsdk) and run the build script. 59 | 60 | > This option should work cross-platform. 61 | 62 | ### Option 2: Manually (without Docker) 63 | 64 | First, [install the Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html). Then run the following command: 65 | 66 | ```shell 67 | $ npm run build:openssl 68 | ``` 69 | 70 | > This option may only work using Linux. It failed for us on macOS and we therefore recommend [Option 1: Using Docker](#option-1-using-docker). 71 | 72 | 73 | ## Running this project with Docker 74 | 75 | The source code contains a [`Dockerfile`](/Dockerfile) which allows you to create ready-to-run [Docker](https://www.docker.com) images. These are comparable to snapshots in virtual machines. 76 | 77 | First, [install and start Docker](https://docs.docker.com/get-docker). Then create a Docker image: 78 | 79 | ```shell 80 | $ docker build -t openssl-webterm . 81 | ``` 82 | 83 | > This installs [Alpine Linux](https://www.alpinelinux.org) with Node.js (v16.3) and [nginx](https://github.com/nginx/nginx) into a virtual image, builds the OpenSSL Webterm sources, and copies the built files into nginx's web server directory. 84 | 85 | You can then instanciate this image into a Docker container: 86 | 87 | ```shell 88 | $ docker run --rm -it -p 4300:80 -d openssl-webterm 89 | ``` 90 | 91 | > This runs the nginx web server. 92 | 93 | You should now be able to view the OpenSSL Webterm at http://localhost:4300 94 | 95 | 96 | ## Contributing 97 | 98 | Any contributions are greatly appreciated. If you have a suggestion that would make this better, please open an issue or fork the repository and create a pull request. 99 | 100 | ## License 101 | 102 | [Apache License v2](http://www.apache.org/licenses/) 103 | This mainly requests to keep the name of the original authors and give according credit to them if you change or redistribute the sources. 104 | -------------------------------------------------------------------------------- /emscr/binary/openssl.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | var EmscrJSR_openssl = (() => { 3 | var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; 4 | 5 | return ( 6 | function(EmscrJSR_openssl) { 7 | EmscrJSR_openssl = EmscrJSR_openssl || {}; 8 | 9 | var Module=typeof EmscrJSR_openssl!="undefined"?EmscrJSR_openssl:{};var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise(function(resolve,reject){readyPromiseResolve=resolve;readyPromiseReject=reject});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 ENVIRONMENT_IS_NODE=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(_scriptDir){scriptDirectory=_scriptDir}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"]||false;if(typeof WebAssembly!="object"){abort("no native wasm support detected")}var wasmMemory;var ABORT=false;var EXITSTATUS;function assert(condition,text){if(!condition){abort(text)}}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):""}function stringToUTF8Array(str,heap,outIdx,maxBytesToWrite){if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx}function stringToUTF8(str,outPtr,maxBytesToWrite){return stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite)}function lengthBytesUTF8(str){var len=0;for(var i=0;i=55296&&c<=57343){len+=4;++i}else{len+=3}}return len}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 __ATMAIN__=[];var __ATEXIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;var runtimeExited=false;var runtimeKeepaliveCounter=0;function keepRuntimeAlive(){return noExitRuntime||runtimeKeepaliveCounter>0}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;if(!Module["noFSInit"]&&!FS.init.initialized)FS.init();FS.ignorePermissions=false;TTY.init();SOCKFS.root=FS.mount(SOCKFS,{},null);PIPEFS.root=FS.mount(PIPEFS,{},null);callRuntimeCallbacks(__ATINIT__)}function preMain(){callRuntimeCallbacks(__ATMAIN__)}function exitRuntime(){___funcs_on_exit();callRuntimeCallbacks(__ATEXIT__);FS.quit();TTY.shutdown();runtimeExited=true}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 getUniqueRunDependency(id){return id}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);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return filename.startsWith(dataURIPrefix)}var wasmBinaryFile;wasmBinaryFile="openssl.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 getBinaryPromise(){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"]["V"];updateGlobalBufferAndViews(wasmMemory.buffer);wasmTable=Module["asm"]["X"];addOnInit(Module["asm"]["W"]);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);readyPromiseReject(e)}}instantiateAsync().catch(readyPromiseReject);return{}}var tempDouble;var tempI64;function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}function callRuntimeCallbacks(callbacks){while(callbacks.length>0){callbacks.shift()(Module)}}var wasmTableMirror=[];function getWasmTableEntry(funcPtr){var func=wasmTableMirror[funcPtr];if(!func){if(funcPtr>=wasmTableMirror.length)wasmTableMirror.length=funcPtr+1;wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr)}return func}function ___call_sighandler(fp,sig){getWasmTableEntry(fp)(sig)}var PATH={isAbs:path=>path.charAt(0)==="/",splitPath:filename=>{var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;return splitPathRe.exec(filename).slice(1)},normalizeArray:(parts,allowAboveRoot)=>{var up=0;for(var i=parts.length-1;i>=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up;up--){parts.unshift("..")}}return parts},normalize:path=>{var isAbsolute=PATH.isAbs(path),trailingSlash=path.substr(-1)==="/";path=PATH.normalizeArray(path.split("/").filter(p=>!!p),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path},dirname:path=>{var result=PATH.splitPath(path),root=result[0],dir=result[1];if(!root&&!dir){return"."}if(dir){dir=dir.substr(0,dir.length-1)}return root+dir},basename:path=>{if(path==="/")return"/";path=PATH.normalize(path);path=path.replace(/\/$/,"");var lastSlash=path.lastIndexOf("/");if(lastSlash===-1)return path;return path.substr(lastSlash+1)},join:function(){var paths=Array.prototype.slice.call(arguments);return PATH.normalize(paths.join("/"))},join2:(l,r)=>{return PATH.normalize(l+"/"+r)}};function getRandomDevice(){if(typeof crypto=="object"&&typeof crypto["getRandomValues"]=="function"){var randomBuffer=new Uint8Array(1);return()=>{crypto.getRandomValues(randomBuffer);return randomBuffer[0]}}else return()=>abort("randomDevice")}var PATH_FS={resolve:function(){var resolvedPath="",resolvedAbsolute=false;for(var i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?arguments[i]:FS.cwd();if(typeof path!="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){return""}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=PATH.isAbs(path)}resolvedPath=PATH.normalizeArray(resolvedPath.split("/").filter(p=>!!p),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."},relative:(from,to)=>{from=PATH_FS.resolve(from).substr(1);to=PATH_FS.resolve(to).substr(1);function trim(arr){var start=0;for(;start=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i0?length:lengthBytesUTF8(stringy)+1;var u8array=new Array(len);var numBytesWritten=stringToUTF8Array(stringy,u8array,0,u8array.length);if(dontAddNull)u8array.length=numBytesWritten;return u8array}var TTY={ttys:[],init:function(){},shutdown:function(){},register:function(dev,ops){TTY.ttys[dev]={input:[],output:[],ops:ops};FS.registerDevice(dev,TTY.stream_ops)},stream_ops:{open:function(stream){var tty=TTY.ttys[stream.node.rdev];if(!tty){throw new FS.ErrnoError(43)}stream.tty=tty;stream.seekable=false},close:function(stream){stream.tty.ops.fsync(stream.tty)},fsync:function(stream){stream.tty.ops.fsync(stream.tty)},read:function(stream,buffer,offset,length,pos){if(!stream.tty||!stream.tty.ops.get_char){throw new FS.ErrnoError(60)}var bytesRead=0;for(var i=0;i0){out(UTF8ArrayToString(tty.output,0));tty.output=[]}}},default_tty1_ops:{put_char:function(tty,val){if(val===null||val===10){err(UTF8ArrayToString(tty.output,0));tty.output=[]}else{if(val!=0)tty.output.push(val)}},fsync:function(tty){if(tty.output&&tty.output.length>0){err(UTF8ArrayToString(tty.output,0));tty.output=[]}}}};function zeroMemory(address,size){HEAPU8.fill(0,address,address+size);return address}function alignMemory(size,alignment){return Math.ceil(size/alignment)*alignment}function mmapAlloc(size){size=alignMemory(size,65536);var ptr=_emscripten_builtin_memalign(65536,size);if(!ptr)return 0;return zeroMemory(ptr,size)}var MEMFS={ops_table:null,mount:function(mount){return MEMFS.createNode(null,"/",16384|511,0)},createNode:function(parent,name,mode,dev){if(FS.isBlkdev(mode)||FS.isFIFO(mode)){throw new FS.ErrnoError(63)}if(!MEMFS.ops_table){MEMFS.ops_table={dir:{node:{getattr:MEMFS.node_ops.getattr,setattr:MEMFS.node_ops.setattr,lookup:MEMFS.node_ops.lookup,mknod:MEMFS.node_ops.mknod,rename:MEMFS.node_ops.rename,unlink:MEMFS.node_ops.unlink,rmdir:MEMFS.node_ops.rmdir,readdir:MEMFS.node_ops.readdir,symlink:MEMFS.node_ops.symlink},stream:{llseek:MEMFS.stream_ops.llseek}},file:{node:{getattr:MEMFS.node_ops.getattr,setattr:MEMFS.node_ops.setattr},stream:{llseek:MEMFS.stream_ops.llseek,read:MEMFS.stream_ops.read,write:MEMFS.stream_ops.write,allocate:MEMFS.stream_ops.allocate,mmap:MEMFS.stream_ops.mmap,msync:MEMFS.stream_ops.msync}},link:{node:{getattr:MEMFS.node_ops.getattr,setattr:MEMFS.node_ops.setattr,readlink:MEMFS.node_ops.readlink},stream:{}},chrdev:{node:{getattr:MEMFS.node_ops.getattr,setattr:MEMFS.node_ops.setattr},stream:FS.chrdev_stream_ops}}}var node=FS.createNode(parent,name,mode,dev);if(FS.isDir(node.mode)){node.node_ops=MEMFS.ops_table.dir.node;node.stream_ops=MEMFS.ops_table.dir.stream;node.contents={}}else if(FS.isFile(node.mode)){node.node_ops=MEMFS.ops_table.file.node;node.stream_ops=MEMFS.ops_table.file.stream;node.usedBytes=0;node.contents=null}else if(FS.isLink(node.mode)){node.node_ops=MEMFS.ops_table.link.node;node.stream_ops=MEMFS.ops_table.link.stream}else if(FS.isChrdev(node.mode)){node.node_ops=MEMFS.ops_table.chrdev.node;node.stream_ops=MEMFS.ops_table.chrdev.stream}node.timestamp=Date.now();if(parent){parent.contents[name]=node;parent.timestamp=node.timestamp}return node},getFileDataAsTypedArray:function(node){if(!node.contents)return new Uint8Array(0);if(node.contents.subarray)return node.contents.subarray(0,node.usedBytes);return new Uint8Array(node.contents)},expandFileStorage:function(node,newCapacity){var prevCapacity=node.contents?node.contents.length:0;if(prevCapacity>=newCapacity)return;var CAPACITY_DOUBLING_MAX=1024*1024;newCapacity=Math.max(newCapacity,prevCapacity*(prevCapacity>>0);if(prevCapacity!=0)newCapacity=Math.max(newCapacity,256);var oldContents=node.contents;node.contents=new Uint8Array(newCapacity);if(node.usedBytes>0)node.contents.set(oldContents.subarray(0,node.usedBytes),0)},resizeFileStorage:function(node,newSize){if(node.usedBytes==newSize)return;if(newSize==0){node.contents=null;node.usedBytes=0}else{var oldContents=node.contents;node.contents=new Uint8Array(newSize);if(oldContents){node.contents.set(oldContents.subarray(0,Math.min(newSize,node.usedBytes)))}node.usedBytes=newSize}},node_ops:{getattr:function(node){var attr={};attr.dev=FS.isChrdev(node.mode)?node.id:1;attr.ino=node.id;attr.mode=node.mode;attr.nlink=1;attr.uid=0;attr.gid=0;attr.rdev=node.rdev;if(FS.isDir(node.mode)){attr.size=4096}else if(FS.isFile(node.mode)){attr.size=node.usedBytes}else if(FS.isLink(node.mode)){attr.size=node.link.length}else{attr.size=0}attr.atime=new Date(node.timestamp);attr.mtime=new Date(node.timestamp);attr.ctime=new Date(node.timestamp);attr.blksize=4096;attr.blocks=Math.ceil(attr.size/attr.blksize);return attr},setattr:function(node,attr){if(attr.mode!==undefined){node.mode=attr.mode}if(attr.timestamp!==undefined){node.timestamp=attr.timestamp}if(attr.size!==undefined){MEMFS.resizeFileStorage(node,attr.size)}},lookup:function(parent,name){throw FS.genericErrors[44]},mknod:function(parent,name,mode,dev){return MEMFS.createNode(parent,name,mode,dev)},rename:function(old_node,new_dir,new_name){if(FS.isDir(old_node.mode)){var new_node;try{new_node=FS.lookupNode(new_dir,new_name)}catch(e){}if(new_node){for(var i in new_node.contents){throw new FS.ErrnoError(55)}}}delete old_node.parent.contents[old_node.name];old_node.parent.timestamp=Date.now();old_node.name=new_name;new_dir.contents[new_name]=old_node;new_dir.timestamp=old_node.parent.timestamp;old_node.parent=new_dir},unlink:function(parent,name){delete parent.contents[name];parent.timestamp=Date.now()},rmdir:function(parent,name){var node=FS.lookupNode(parent,name);for(var i in node.contents){throw new FS.ErrnoError(55)}delete parent.contents[name];parent.timestamp=Date.now()},readdir:function(node){var entries=[".",".."];for(var key in node.contents){if(!node.contents.hasOwnProperty(key)){continue}entries.push(key)}return entries},symlink:function(parent,newname,oldpath){var node=MEMFS.createNode(parent,newname,511|40960,0);node.link=oldpath;return node},readlink:function(node){if(!FS.isLink(node.mode)){throw new FS.ErrnoError(28)}return node.link}},stream_ops:{read:function(stream,buffer,offset,length,position){var contents=stream.node.contents;if(position>=stream.node.usedBytes)return 0;var size=Math.min(stream.node.usedBytes-position,length);if(size>8&&contents.subarray){buffer.set(contents.subarray(position,position+size),offset)}else{for(var i=0;i0||position+length{assert(arrayBuffer,'Loading data file "'+url+'" failed (no arrayBuffer).');onload(new Uint8Array(arrayBuffer));if(dep)removeRunDependency(dep)},event=>{if(onerror){onerror()}else{throw'Loading data file "'+url+'" failed.'}});if(dep)addRunDependency(dep)}var FS={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:"/",initialized:false,ignorePermissions:true,ErrnoError:null,genericErrors:{},filesystems:null,syncFSRequests:0,lookupPath:(path,opts={})=>{path=PATH_FS.resolve(path);if(!path)return{path:"",node:null};var defaults={follow_mount:true,recurse_count:0};opts=Object.assign(defaults,opts);if(opts.recurse_count>8){throw new FS.ErrnoError(32)}var parts=path.split("/").filter(p=>!!p);var current=FS.root;var current_path="/";for(var i=0;i40){throw new FS.ErrnoError(32)}}}}return{path:current_path,node:current}},getPath:node=>{var path;while(true){if(FS.isRoot(node)){var mount=node.mount.mountpoint;if(!path)return mount;return mount[mount.length-1]!=="/"?mount+"/"+path:mount+path}path=path?node.name+"/"+path:node.name;node=node.parent}},hashName:(parentid,name)=>{var hash=0;for(var i=0;i>>0)%FS.nameTable.length},hashAddNode:node=>{var hash=FS.hashName(node.parent.id,node.name);node.name_next=FS.nameTable[hash];FS.nameTable[hash]=node},hashRemoveNode:node=>{var hash=FS.hashName(node.parent.id,node.name);if(FS.nameTable[hash]===node){FS.nameTable[hash]=node.name_next}else{var current=FS.nameTable[hash];while(current){if(current.name_next===node){current.name_next=node.name_next;break}current=current.name_next}}},lookupNode:(parent,name)=>{var errCode=FS.mayLookup(parent);if(errCode){throw new FS.ErrnoError(errCode,parent)}var hash=FS.hashName(parent.id,name);for(var node=FS.nameTable[hash];node;node=node.name_next){var nodeName=node.name;if(node.parent.id===parent.id&&nodeName===name){return node}}return FS.lookup(parent,name)},createNode:(parent,name,mode,rdev)=>{var node=new FS.FSNode(parent,name,mode,rdev);FS.hashAddNode(node);return node},destroyNode:node=>{FS.hashRemoveNode(node)},isRoot:node=>{return node===node.parent},isMountpoint:node=>{return!!node.mounted},isFile:mode=>{return(mode&61440)===32768},isDir:mode=>{return(mode&61440)===16384},isLink:mode=>{return(mode&61440)===40960},isChrdev:mode=>{return(mode&61440)===8192},isBlkdev:mode=>{return(mode&61440)===24576},isFIFO:mode=>{return(mode&61440)===4096},isSocket:mode=>{return(mode&49152)===49152},flagModes:{"r":0,"r+":2,"w":577,"w+":578,"a":1089,"a+":1090},modeStringToFlags:str=>{var flags=FS.flagModes[str];if(typeof flags=="undefined"){throw new Error("Unknown file open mode: "+str)}return flags},flagsToPermissionString:flag=>{var perms=["r","w","rw"][flag&3];if(flag&512){perms+="w"}return perms},nodePermissions:(node,perms)=>{if(FS.ignorePermissions){return 0}if(perms.includes("r")&&!(node.mode&292)){return 2}else if(perms.includes("w")&&!(node.mode&146)){return 2}else if(perms.includes("x")&&!(node.mode&73)){return 2}return 0},mayLookup:dir=>{var errCode=FS.nodePermissions(dir,"x");if(errCode)return errCode;if(!dir.node_ops.lookup)return 2;return 0},mayCreate:(dir,name)=>{try{var node=FS.lookupNode(dir,name);return 20}catch(e){}return FS.nodePermissions(dir,"wx")},mayDelete:(dir,name,isdir)=>{var node;try{node=FS.lookupNode(dir,name)}catch(e){return e.errno}var errCode=FS.nodePermissions(dir,"wx");if(errCode){return errCode}if(isdir){if(!FS.isDir(node.mode)){return 54}if(FS.isRoot(node)||FS.getPath(node)===FS.cwd()){return 10}}else{if(FS.isDir(node.mode)){return 31}}return 0},mayOpen:(node,flags)=>{if(!node){return 44}if(FS.isLink(node.mode)){return 32}else if(FS.isDir(node.mode)){if(FS.flagsToPermissionString(flags)!=="r"||flags&512){return 31}}return FS.nodePermissions(node,FS.flagsToPermissionString(flags))},MAX_OPEN_FDS:4096,nextfd:(fd_start=0,fd_end=FS.MAX_OPEN_FDS)=>{for(var fd=fd_start;fd<=fd_end;fd++){if(!FS.streams[fd]){return fd}}throw new FS.ErrnoError(33)},getStream:fd=>FS.streams[fd],createStream:(stream,fd_start,fd_end)=>{if(!FS.FSStream){FS.FSStream=function(){this.shared={}};FS.FSStream.prototype={};Object.defineProperties(FS.FSStream.prototype,{object:{get:function(){return this.node},set:function(val){this.node=val}},isRead:{get:function(){return(this.flags&2097155)!==1}},isWrite:{get:function(){return(this.flags&2097155)!==0}},isAppend:{get:function(){return this.flags&1024}},flags:{get:function(){return this.shared.flags},set:function(val){this.shared.flags=val}},position:{get:function(){return this.shared.position},set:function(val){this.shared.position=val}}})}stream=Object.assign(new FS.FSStream,stream);var fd=FS.nextfd(fd_start,fd_end);stream.fd=fd;FS.streams[fd]=stream;return stream},closeStream:fd=>{FS.streams[fd]=null},chrdev_stream_ops:{open:stream=>{var device=FS.getDevice(stream.node.rdev);stream.stream_ops=device.stream_ops;if(stream.stream_ops.open){stream.stream_ops.open(stream)}},llseek:()=>{throw new FS.ErrnoError(70)}},major:dev=>dev>>8,minor:dev=>dev&255,makedev:(ma,mi)=>ma<<8|mi,registerDevice:(dev,ops)=>{FS.devices[dev]={stream_ops:ops}},getDevice:dev=>FS.devices[dev],getMounts:mount=>{var mounts=[];var check=[mount];while(check.length){var m=check.pop();mounts.push(m);check.push.apply(check,m.mounts)}return mounts},syncfs:(populate,callback)=>{if(typeof populate=="function"){callback=populate;populate=false}FS.syncFSRequests++;if(FS.syncFSRequests>1){err("warning: "+FS.syncFSRequests+" FS.syncfs operations in flight at once, probably just doing extra work")}var mounts=FS.getMounts(FS.root.mount);var completed=0;function doCallback(errCode){FS.syncFSRequests--;return callback(errCode)}function done(errCode){if(errCode){if(!done.errored){done.errored=true;return doCallback(errCode)}return}if(++completed>=mounts.length){doCallback(null)}}mounts.forEach(mount=>{if(!mount.type.syncfs){return done(null)}mount.type.syncfs(mount,populate,done)})},mount:(type,opts,mountpoint)=>{var root=mountpoint==="/";var pseudo=!mountpoint;var node;if(root&&FS.root){throw new FS.ErrnoError(10)}else if(!root&&!pseudo){var lookup=FS.lookupPath(mountpoint,{follow_mount:false});mountpoint=lookup.path;node=lookup.node;if(FS.isMountpoint(node)){throw new FS.ErrnoError(10)}if(!FS.isDir(node.mode)){throw new FS.ErrnoError(54)}}var mount={type:type,opts:opts,mountpoint:mountpoint,mounts:[]};var mountRoot=type.mount(mount);mountRoot.mount=mount;mount.root=mountRoot;if(root){FS.root=mountRoot}else if(node){node.mounted=mount;if(node.mount){node.mount.mounts.push(mount)}}return mountRoot},unmount:mountpoint=>{var lookup=FS.lookupPath(mountpoint,{follow_mount:false});if(!FS.isMountpoint(lookup.node)){throw new FS.ErrnoError(28)}var node=lookup.node;var mount=node.mounted;var mounts=FS.getMounts(mount);Object.keys(FS.nameTable).forEach(hash=>{var current=FS.nameTable[hash];while(current){var next=current.name_next;if(mounts.includes(current.mount)){FS.destroyNode(current)}current=next}});node.mounted=null;var idx=node.mount.mounts.indexOf(mount);node.mount.mounts.splice(idx,1)},lookup:(parent,name)=>{return parent.node_ops.lookup(parent,name)},mknod:(path,mode,dev)=>{var lookup=FS.lookupPath(path,{parent:true});var parent=lookup.node;var name=PATH.basename(path);if(!name||name==="."||name===".."){throw new FS.ErrnoError(28)}var errCode=FS.mayCreate(parent,name);if(errCode){throw new FS.ErrnoError(errCode)}if(!parent.node_ops.mknod){throw new FS.ErrnoError(63)}return parent.node_ops.mknod(parent,name,mode,dev)},create:(path,mode)=>{mode=mode!==undefined?mode:438;mode&=4095;mode|=32768;return FS.mknod(path,mode,0)},mkdir:(path,mode)=>{mode=mode!==undefined?mode:511;mode&=511|512;mode|=16384;return FS.mknod(path,mode,0)},mkdirTree:(path,mode)=>{var dirs=path.split("/");var d="";for(var i=0;i{if(typeof dev=="undefined"){dev=mode;mode=438}mode|=8192;return FS.mknod(path,mode,dev)},symlink:(oldpath,newpath)=>{if(!PATH_FS.resolve(oldpath)){throw new FS.ErrnoError(44)}var lookup=FS.lookupPath(newpath,{parent:true});var parent=lookup.node;if(!parent){throw new FS.ErrnoError(44)}var newname=PATH.basename(newpath);var errCode=FS.mayCreate(parent,newname);if(errCode){throw new FS.ErrnoError(errCode)}if(!parent.node_ops.symlink){throw new FS.ErrnoError(63)}return parent.node_ops.symlink(parent,newname,oldpath)},rename:(old_path,new_path)=>{var old_dirname=PATH.dirname(old_path);var new_dirname=PATH.dirname(new_path);var old_name=PATH.basename(old_path);var new_name=PATH.basename(new_path);var lookup,old_dir,new_dir;lookup=FS.lookupPath(old_path,{parent:true});old_dir=lookup.node;lookup=FS.lookupPath(new_path,{parent:true});new_dir=lookup.node;if(!old_dir||!new_dir)throw new FS.ErrnoError(44);if(old_dir.mount!==new_dir.mount){throw new FS.ErrnoError(75)}var old_node=FS.lookupNode(old_dir,old_name);var relative=PATH_FS.relative(old_path,new_dirname);if(relative.charAt(0)!=="."){throw new FS.ErrnoError(28)}relative=PATH_FS.relative(new_path,old_dirname);if(relative.charAt(0)!=="."){throw new FS.ErrnoError(55)}var new_node;try{new_node=FS.lookupNode(new_dir,new_name)}catch(e){}if(old_node===new_node){return}var isdir=FS.isDir(old_node.mode);var errCode=FS.mayDelete(old_dir,old_name,isdir);if(errCode){throw new FS.ErrnoError(errCode)}errCode=new_node?FS.mayDelete(new_dir,new_name,isdir):FS.mayCreate(new_dir,new_name);if(errCode){throw new FS.ErrnoError(errCode)}if(!old_dir.node_ops.rename){throw new FS.ErrnoError(63)}if(FS.isMountpoint(old_node)||new_node&&FS.isMountpoint(new_node)){throw new FS.ErrnoError(10)}if(new_dir!==old_dir){errCode=FS.nodePermissions(old_dir,"w");if(errCode){throw new FS.ErrnoError(errCode)}}FS.hashRemoveNode(old_node);try{old_dir.node_ops.rename(old_node,new_dir,new_name)}catch(e){throw e}finally{FS.hashAddNode(old_node)}},rmdir:path=>{var lookup=FS.lookupPath(path,{parent:true});var parent=lookup.node;var name=PATH.basename(path);var node=FS.lookupNode(parent,name);var errCode=FS.mayDelete(parent,name,true);if(errCode){throw new FS.ErrnoError(errCode)}if(!parent.node_ops.rmdir){throw new FS.ErrnoError(63)}if(FS.isMountpoint(node)){throw new FS.ErrnoError(10)}parent.node_ops.rmdir(parent,name);FS.destroyNode(node)},readdir:path=>{var lookup=FS.lookupPath(path,{follow:true});var node=lookup.node;if(!node.node_ops.readdir){throw new FS.ErrnoError(54)}return node.node_ops.readdir(node)},unlink:path=>{var lookup=FS.lookupPath(path,{parent:true});var parent=lookup.node;if(!parent){throw new FS.ErrnoError(44)}var name=PATH.basename(path);var node=FS.lookupNode(parent,name);var errCode=FS.mayDelete(parent,name,false);if(errCode){throw new FS.ErrnoError(errCode)}if(!parent.node_ops.unlink){throw new FS.ErrnoError(63)}if(FS.isMountpoint(node)){throw new FS.ErrnoError(10)}parent.node_ops.unlink(parent,name);FS.destroyNode(node)},readlink:path=>{var lookup=FS.lookupPath(path);var link=lookup.node;if(!link){throw new FS.ErrnoError(44)}if(!link.node_ops.readlink){throw new FS.ErrnoError(28)}return PATH_FS.resolve(FS.getPath(link.parent),link.node_ops.readlink(link))},stat:(path,dontFollow)=>{var lookup=FS.lookupPath(path,{follow:!dontFollow});var node=lookup.node;if(!node){throw new FS.ErrnoError(44)}if(!node.node_ops.getattr){throw new FS.ErrnoError(63)}return node.node_ops.getattr(node)},lstat:path=>{return FS.stat(path,true)},chmod:(path,mode,dontFollow)=>{var node;if(typeof path=="string"){var lookup=FS.lookupPath(path,{follow:!dontFollow});node=lookup.node}else{node=path}if(!node.node_ops.setattr){throw new FS.ErrnoError(63)}node.node_ops.setattr(node,{mode:mode&4095|node.mode&~4095,timestamp:Date.now()})},lchmod:(path,mode)=>{FS.chmod(path,mode,true)},fchmod:(fd,mode)=>{var stream=FS.getStream(fd);if(!stream){throw new FS.ErrnoError(8)}FS.chmod(stream.node,mode)},chown:(path,uid,gid,dontFollow)=>{var node;if(typeof path=="string"){var lookup=FS.lookupPath(path,{follow:!dontFollow});node=lookup.node}else{node=path}if(!node.node_ops.setattr){throw new FS.ErrnoError(63)}node.node_ops.setattr(node,{timestamp:Date.now()})},lchown:(path,uid,gid)=>{FS.chown(path,uid,gid,true)},fchown:(fd,uid,gid)=>{var stream=FS.getStream(fd);if(!stream){throw new FS.ErrnoError(8)}FS.chown(stream.node,uid,gid)},truncate:(path,len)=>{if(len<0){throw new FS.ErrnoError(28)}var node;if(typeof path=="string"){var lookup=FS.lookupPath(path,{follow:true});node=lookup.node}else{node=path}if(!node.node_ops.setattr){throw new FS.ErrnoError(63)}if(FS.isDir(node.mode)){throw new FS.ErrnoError(31)}if(!FS.isFile(node.mode)){throw new FS.ErrnoError(28)}var errCode=FS.nodePermissions(node,"w");if(errCode){throw new FS.ErrnoError(errCode)}node.node_ops.setattr(node,{size:len,timestamp:Date.now()})},ftruncate:(fd,len)=>{var stream=FS.getStream(fd);if(!stream){throw new FS.ErrnoError(8)}if((stream.flags&2097155)===0){throw new FS.ErrnoError(28)}FS.truncate(stream.node,len)},utime:(path,atime,mtime)=>{var lookup=FS.lookupPath(path,{follow:true});var node=lookup.node;node.node_ops.setattr(node,{timestamp:Math.max(atime,mtime)})},open:(path,flags,mode)=>{if(path===""){throw new FS.ErrnoError(44)}flags=typeof flags=="string"?FS.modeStringToFlags(flags):flags;mode=typeof mode=="undefined"?438:mode;if(flags&64){mode=mode&4095|32768}else{mode=0}var node;if(typeof path=="object"){node=path}else{path=PATH.normalize(path);try{var lookup=FS.lookupPath(path,{follow:!(flags&131072)});node=lookup.node}catch(e){}}var created=false;if(flags&64){if(node){if(flags&128){throw new FS.ErrnoError(20)}}else{node=FS.mknod(path,mode,0);created=true}}if(!node){throw new FS.ErrnoError(44)}if(FS.isChrdev(node.mode)){flags&=~512}if(flags&65536&&!FS.isDir(node.mode)){throw new FS.ErrnoError(54)}if(!created){var errCode=FS.mayOpen(node,flags);if(errCode){throw new FS.ErrnoError(errCode)}}if(flags&512&&!created){FS.truncate(node,0)}flags&=~(128|512|131072);var stream=FS.createStream({node:node,path:FS.getPath(node),flags:flags,seekable:true,position:0,stream_ops:node.stream_ops,ungotten:[],error:false});if(stream.stream_ops.open){stream.stream_ops.open(stream)}if(Module["logReadFiles"]&&!(flags&1)){if(!FS.readFiles)FS.readFiles={};if(!(path in FS.readFiles)){FS.readFiles[path]=1}}return stream},close:stream=>{if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if(stream.getdents)stream.getdents=null;try{if(stream.stream_ops.close){stream.stream_ops.close(stream)}}catch(e){throw e}finally{FS.closeStream(stream.fd)}stream.fd=null},isClosed:stream=>{return stream.fd===null},llseek:(stream,offset,whence)=>{if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if(!stream.seekable||!stream.stream_ops.llseek){throw new FS.ErrnoError(70)}if(whence!=0&&whence!=1&&whence!=2){throw new FS.ErrnoError(28)}stream.position=stream.stream_ops.llseek(stream,offset,whence);stream.ungotten=[];return stream.position},read:(stream,buffer,offset,length,position)=>{if(length<0||position<0){throw new FS.ErrnoError(28)}if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if((stream.flags&2097155)===1){throw new FS.ErrnoError(8)}if(FS.isDir(stream.node.mode)){throw new FS.ErrnoError(31)}if(!stream.stream_ops.read){throw new FS.ErrnoError(28)}var seeking=typeof position!="undefined";if(!seeking){position=stream.position}else if(!stream.seekable){throw new FS.ErrnoError(70)}var bytesRead=stream.stream_ops.read(stream,buffer,offset,length,position);if(!seeking)stream.position+=bytesRead;return bytesRead},write:(stream,buffer,offset,length,position,canOwn)=>{if(length<0||position<0){throw new FS.ErrnoError(28)}if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if((stream.flags&2097155)===0){throw new FS.ErrnoError(8)}if(FS.isDir(stream.node.mode)){throw new FS.ErrnoError(31)}if(!stream.stream_ops.write){throw new FS.ErrnoError(28)}if(stream.seekable&&stream.flags&1024){FS.llseek(stream,0,2)}var seeking=typeof position!="undefined";if(!seeking){position=stream.position}else if(!stream.seekable){throw new FS.ErrnoError(70)}var bytesWritten=stream.stream_ops.write(stream,buffer,offset,length,position,canOwn);if(!seeking)stream.position+=bytesWritten;return bytesWritten},allocate:(stream,offset,length)=>{if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if(offset<0||length<=0){throw new FS.ErrnoError(28)}if((stream.flags&2097155)===0){throw new FS.ErrnoError(8)}if(!FS.isFile(stream.node.mode)&&!FS.isDir(stream.node.mode)){throw new FS.ErrnoError(43)}if(!stream.stream_ops.allocate){throw new FS.ErrnoError(138)}stream.stream_ops.allocate(stream,offset,length)},mmap:(stream,length,position,prot,flags)=>{if((prot&2)!==0&&(flags&2)===0&&(stream.flags&2097155)!==2){throw new FS.ErrnoError(2)}if((stream.flags&2097155)===1){throw new FS.ErrnoError(2)}if(!stream.stream_ops.mmap){throw new FS.ErrnoError(43)}return stream.stream_ops.mmap(stream,length,position,prot,flags)},msync:(stream,buffer,offset,length,mmapFlags)=>{if(!stream.stream_ops.msync){return 0}return stream.stream_ops.msync(stream,buffer,offset,length,mmapFlags)},munmap:stream=>0,ioctl:(stream,cmd,arg)=>{if(!stream.stream_ops.ioctl){throw new FS.ErrnoError(59)}return stream.stream_ops.ioctl(stream,cmd,arg)},readFile:(path,opts={})=>{opts.flags=opts.flags||0;opts.encoding=opts.encoding||"binary";if(opts.encoding!=="utf8"&&opts.encoding!=="binary"){throw new Error('Invalid encoding type "'+opts.encoding+'"')}var ret;var stream=FS.open(path,opts.flags);var stat=FS.stat(path);var length=stat.size;var buf=new Uint8Array(length);FS.read(stream,buf,0,length,0);if(opts.encoding==="utf8"){ret=UTF8ArrayToString(buf,0)}else if(opts.encoding==="binary"){ret=buf}FS.close(stream);return ret},writeFile:(path,data,opts={})=>{opts.flags=opts.flags||577;var stream=FS.open(path,opts.flags,opts.mode);if(typeof data=="string"){var buf=new Uint8Array(lengthBytesUTF8(data)+1);var actualNumBytes=stringToUTF8Array(data,buf,0,buf.length);FS.write(stream,buf,0,actualNumBytes,undefined,opts.canOwn)}else if(ArrayBuffer.isView(data)){FS.write(stream,data,0,data.byteLength,undefined,opts.canOwn)}else{throw new Error("Unsupported data type")}FS.close(stream)},cwd:()=>FS.currentPath,chdir:path=>{var lookup=FS.lookupPath(path,{follow:true});if(lookup.node===null){throw new FS.ErrnoError(44)}if(!FS.isDir(lookup.node.mode)){throw new FS.ErrnoError(54)}var errCode=FS.nodePermissions(lookup.node,"x");if(errCode){throw new FS.ErrnoError(errCode)}FS.currentPath=lookup.path},createDefaultDirectories:()=>{FS.mkdir("/tmp");FS.mkdir("/home");FS.mkdir("/home/web_user")},createDefaultDevices:()=>{FS.mkdir("/dev");FS.registerDevice(FS.makedev(1,3),{read:()=>0,write:(stream,buffer,offset,length,pos)=>length});FS.mkdev("/dev/null",FS.makedev(1,3));TTY.register(FS.makedev(5,0),TTY.default_tty_ops);TTY.register(FS.makedev(6,0),TTY.default_tty1_ops);FS.mkdev("/dev/tty",FS.makedev(5,0));FS.mkdev("/dev/tty1",FS.makedev(6,0));var random_device=getRandomDevice();FS.createDevice("/dev","random",random_device);FS.createDevice("/dev","urandom",random_device);FS.mkdir("/dev/shm");FS.mkdir("/dev/shm/tmp")},createSpecialDirectories:()=>{FS.mkdir("/proc");var proc_self=FS.mkdir("/proc/self");FS.mkdir("/proc/self/fd");FS.mount({mount:()=>{var node=FS.createNode(proc_self,"fd",16384|511,73);node.node_ops={lookup:(parent,name)=>{var fd=+name;var stream=FS.getStream(fd);if(!stream)throw new FS.ErrnoError(8);var ret={parent:null,mount:{mountpoint:"fake"},node_ops:{readlink:()=>stream.path}};ret.parent=ret;return ret}};return node}},{},"/proc/self/fd")},createStandardStreams:()=>{if(Module["stdin"]){FS.createDevice("/dev","stdin",Module["stdin"])}else{FS.symlink("/dev/tty","/dev/stdin")}if(Module["stdout"]){FS.createDevice("/dev","stdout",null,Module["stdout"])}else{FS.symlink("/dev/tty","/dev/stdout")}if(Module["stderr"]){FS.createDevice("/dev","stderr",null,Module["stderr"])}else{FS.symlink("/dev/tty1","/dev/stderr")}var stdin=FS.open("/dev/stdin",0);var stdout=FS.open("/dev/stdout",1);var stderr=FS.open("/dev/stderr",1)},ensureErrnoError:()=>{if(FS.ErrnoError)return;FS.ErrnoError=function ErrnoError(errno,node){this.node=node;this.setErrno=function(errno){this.errno=errno};this.setErrno(errno);this.message="FS error"};FS.ErrnoError.prototype=new Error;FS.ErrnoError.prototype.constructor=FS.ErrnoError;[44].forEach(code=>{FS.genericErrors[code]=new FS.ErrnoError(code);FS.genericErrors[code].stack=""})},staticInit:()=>{FS.ensureErrnoError();FS.nameTable=new Array(4096);FS.mount(MEMFS,{},"/");FS.createDefaultDirectories();FS.createDefaultDevices();FS.createSpecialDirectories();FS.filesystems={"MEMFS":MEMFS}},init:(input,output,error)=>{FS.init.initialized=true;FS.ensureErrnoError();Module["stdin"]=input||Module["stdin"];Module["stdout"]=output||Module["stdout"];Module["stderr"]=error||Module["stderr"];FS.createStandardStreams()},quit:()=>{FS.init.initialized=false;_fflush(0);for(var i=0;i{var mode=0;if(canRead)mode|=292|73;if(canWrite)mode|=146;return mode},findObject:(path,dontResolveLastLink)=>{var ret=FS.analyzePath(path,dontResolveLastLink);if(!ret.exists){return null}return ret.object},analyzePath:(path,dontResolveLastLink)=>{try{var lookup=FS.lookupPath(path,{follow:!dontResolveLastLink});path=lookup.path}catch(e){}var ret={isRoot:false,exists:false,error:0,name:null,path:null,object:null,parentExists:false,parentPath:null,parentObject:null};try{var lookup=FS.lookupPath(path,{parent:true});ret.parentExists=true;ret.parentPath=lookup.path;ret.parentObject=lookup.node;ret.name=PATH.basename(path);lookup=FS.lookupPath(path,{follow:!dontResolveLastLink});ret.exists=true;ret.path=lookup.path;ret.object=lookup.node;ret.name=lookup.node.name;ret.isRoot=lookup.path==="/"}catch(e){ret.error=e.errno}return ret},createPath:(parent,path,canRead,canWrite)=>{parent=typeof parent=="string"?parent:FS.getPath(parent);var parts=path.split("/").reverse();while(parts.length){var part=parts.pop();if(!part)continue;var current=PATH.join2(parent,part);try{FS.mkdir(current)}catch(e){}parent=current}return current},createFile:(parent,name,properties,canRead,canWrite)=>{var path=PATH.join2(typeof parent=="string"?parent:FS.getPath(parent),name);var mode=FS.getMode(canRead,canWrite);return FS.create(path,mode)},createDataFile:(parent,name,data,canRead,canWrite,canOwn)=>{var path=name;if(parent){parent=typeof parent=="string"?parent:FS.getPath(parent);path=name?PATH.join2(parent,name):parent}var mode=FS.getMode(canRead,canWrite);var node=FS.create(path,mode);if(data){if(typeof data=="string"){var arr=new Array(data.length);for(var i=0,len=data.length;i{var path=PATH.join2(typeof parent=="string"?parent:FS.getPath(parent),name);var mode=FS.getMode(!!input,!!output);if(!FS.createDevice.major)FS.createDevice.major=64;var dev=FS.makedev(FS.createDevice.major++,0);FS.registerDevice(dev,{open:stream=>{stream.seekable=false},close:stream=>{if(output&&output.buffer&&output.buffer.length){output(10)}},read:(stream,buffer,offset,length,pos)=>{var bytesRead=0;for(var i=0;i{for(var i=0;i{if(obj.isDevice||obj.isFolder||obj.link||obj.contents)return true;if(typeof XMLHttpRequest!="undefined"){throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.")}else if(read_){try{obj.contents=intArrayFromString(read_(obj.url),true);obj.usedBytes=obj.contents.length}catch(e){throw new FS.ErrnoError(29)}}else{throw new Error("Cannot load without read() or XMLHttpRequest.")}},createLazyFile:(parent,name,url,canRead,canWrite)=>{function LazyUint8Array(){this.lengthKnown=false;this.chunks=[]}LazyUint8Array.prototype.get=function LazyUint8Array_get(idx){if(idx>this.length-1||idx<0){return undefined}var chunkOffset=idx%this.chunkSize;var chunkNum=idx/this.chunkSize|0;return this.getter(chunkNum)[chunkOffset]};LazyUint8Array.prototype.setDataGetter=function LazyUint8Array_setDataGetter(getter){this.getter=getter};LazyUint8Array.prototype.cacheLength=function LazyUint8Array_cacheLength(){var xhr=new XMLHttpRequest;xhr.open("HEAD",url,false);xhr.send(null);if(!(xhr.status>=200&&xhr.status<300||xhr.status===304))throw new Error("Couldn't load "+url+". Status: "+xhr.status);var datalength=Number(xhr.getResponseHeader("Content-length"));var header;var hasByteServing=(header=xhr.getResponseHeader("Accept-Ranges"))&&header==="bytes";var usesGzip=(header=xhr.getResponseHeader("Content-Encoding"))&&header==="gzip";var chunkSize=1024*1024;if(!hasByteServing)chunkSize=datalength;var doXHR=(from,to)=>{if(from>to)throw new Error("invalid range ("+from+", "+to+") or no bytes requested!");if(to>datalength-1)throw new Error("only "+datalength+" bytes available! programmer error!");var xhr=new XMLHttpRequest;xhr.open("GET",url,false);if(datalength!==chunkSize)xhr.setRequestHeader("Range","bytes="+from+"-"+to);xhr.responseType="arraybuffer";if(xhr.overrideMimeType){xhr.overrideMimeType("text/plain; charset=x-user-defined")}xhr.send(null);if(!(xhr.status>=200&&xhr.status<300||xhr.status===304))throw new Error("Couldn't load "+url+". Status: "+xhr.status);if(xhr.response!==undefined){return new Uint8Array(xhr.response||[])}return intArrayFromString(xhr.responseText||"",true)};var lazyArray=this;lazyArray.setDataGetter(chunkNum=>{var start=chunkNum*chunkSize;var end=(chunkNum+1)*chunkSize-1;end=Math.min(end,datalength-1);if(typeof lazyArray.chunks[chunkNum]=="undefined"){lazyArray.chunks[chunkNum]=doXHR(start,end)}if(typeof lazyArray.chunks[chunkNum]=="undefined")throw new Error("doXHR failed!");return lazyArray.chunks[chunkNum]});if(usesGzip||!datalength){chunkSize=datalength=1;datalength=this.getter(0).length;chunkSize=datalength;out("LazyFiles on gzip forces download of the whole file when length is accessed")}this._length=datalength;this._chunkSize=chunkSize;this.lengthKnown=true};if(typeof XMLHttpRequest!="undefined"){if(!ENVIRONMENT_IS_WORKER)throw"Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";var lazyArray=new LazyUint8Array;Object.defineProperties(lazyArray,{length:{get:function(){if(!this.lengthKnown){this.cacheLength()}return this._length}},chunkSize:{get:function(){if(!this.lengthKnown){this.cacheLength()}return this._chunkSize}}});var properties={isDevice:false,contents:lazyArray}}else{var properties={isDevice:false,url:url}}var node=FS.createFile(parent,name,properties,canRead,canWrite);if(properties.contents){node.contents=properties.contents}else if(properties.url){node.contents=null;node.url=properties.url}Object.defineProperties(node,{usedBytes:{get:function(){return this.contents.length}}});var stream_ops={};var keys=Object.keys(node.stream_ops);keys.forEach(key=>{var fn=node.stream_ops[key];stream_ops[key]=function forceLoadLazyFile(){FS.forceLoadFile(node);return fn.apply(null,arguments)}});function writeChunks(stream,buffer,offset,length,position){var contents=stream.node.contents;if(position>=contents.length)return 0;var size=Math.min(contents.length-position,length);if(contents.slice){for(var i=0;i{FS.forceLoadFile(node);return writeChunks(stream,buffer,offset,length,position)};stream_ops.mmap=(stream,length,position,prot,flags)=>{FS.forceLoadFile(node);var ptr=mmapAlloc(length);if(!ptr){throw new FS.ErrnoError(48)}writeChunks(stream,HEAP8,ptr,length,position);return{ptr:ptr,allocated:true}};node.stream_ops=stream_ops;return node},createPreloadedFile:(parent,name,url,canRead,canWrite,onload,onerror,dontCreateFile,canOwn,preFinish)=>{var fullname=name?PATH_FS.resolve(PATH.join2(parent,name)):parent;var dep=getUniqueRunDependency("cp "+fullname);function processData(byteArray){function finish(byteArray){if(preFinish)preFinish();if(!dontCreateFile){FS.createDataFile(parent,name,byteArray,canRead,canWrite,canOwn)}if(onload)onload();removeRunDependency(dep)}if(Browser.handledByPreloadPlugin(byteArray,fullname,finish,()=>{if(onerror)onerror();removeRunDependency(dep)})){return}finish(byteArray)}addRunDependency(dep);if(typeof url=="string"){asyncLoad(url,byteArray=>processData(byteArray),onerror)}else{processData(url)}},indexedDB:()=>{return window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB},DB_NAME:()=>{return"EM_FS_"+window.location.pathname},DB_VERSION:20,DB_STORE_NAME:"FILE_DATA",saveFilesToDB:(paths,onload,onerror)=>{onload=onload||(()=>{});onerror=onerror||(()=>{});var indexedDB=FS.indexedDB();try{var openRequest=indexedDB.open(FS.DB_NAME(),FS.DB_VERSION)}catch(e){return onerror(e)}openRequest.onupgradeneeded=()=>{out("creating db");var db=openRequest.result;db.createObjectStore(FS.DB_STORE_NAME)};openRequest.onsuccess=()=>{var db=openRequest.result;var transaction=db.transaction([FS.DB_STORE_NAME],"readwrite");var files=transaction.objectStore(FS.DB_STORE_NAME);var ok=0,fail=0,total=paths.length;function finish(){if(fail==0)onload();else onerror()}paths.forEach(path=>{var putRequest=files.put(FS.analyzePath(path).object.contents,path);putRequest.onsuccess=()=>{ok++;if(ok+fail==total)finish()};putRequest.onerror=()=>{fail++;if(ok+fail==total)finish()}});transaction.onerror=onerror};openRequest.onerror=onerror},loadFilesFromDB:(paths,onload,onerror)=>{onload=onload||(()=>{});onerror=onerror||(()=>{});var indexedDB=FS.indexedDB();try{var openRequest=indexedDB.open(FS.DB_NAME(),FS.DB_VERSION)}catch(e){return onerror(e)}openRequest.onupgradeneeded=onerror;openRequest.onsuccess=()=>{var db=openRequest.result;try{var transaction=db.transaction([FS.DB_STORE_NAME],"readonly")}catch(e){onerror(e);return}var files=transaction.objectStore(FS.DB_STORE_NAME);var ok=0,fail=0,total=paths.length;function finish(){if(fail==0)onload();else onerror()}paths.forEach(path=>{var getRequest=files.get(path);getRequest.onsuccess=()=>{if(FS.analyzePath(path).exists){FS.unlink(path)}FS.createDataFile(PATH.dirname(path),PATH.basename(path),getRequest.result,true,true,true);ok++;if(ok+fail==total)finish()};getRequest.onerror=()=>{fail++;if(ok+fail==total)finish()}});transaction.onerror=onerror};openRequest.onerror=onerror}};var SYSCALLS={DEFAULT_POLLMASK:5,calculateAt:function(dirfd,path,allowEmpty){if(PATH.isAbs(path)){return path}var dir;if(dirfd===-100){dir=FS.cwd()}else{var dirstream=SYSCALLS.getStreamFromFD(dirfd);dir=dirstream.path}if(path.length==0){if(!allowEmpty){throw new FS.ErrnoError(44)}return dir}return PATH.join2(dir,path)},doStat:function(func,path,buf){try{var stat=func(path)}catch(e){if(e&&e.node&&PATH.normalize(path)!==PATH.normalize(FS.getPath(e.node))){return-54}throw e}HEAP32[buf>>2]=stat.dev;HEAP32[buf+8>>2]=stat.ino;HEAP32[buf+12>>2]=stat.mode;HEAPU32[buf+16>>2]=stat.nlink;HEAP32[buf+20>>2]=stat.uid;HEAP32[buf+24>>2]=stat.gid;HEAP32[buf+28>>2]=stat.rdev;tempI64=[stat.size>>>0,(tempDouble=stat.size,+Math.abs(tempDouble)>=1?tempDouble>0?(Math.min(+Math.floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[buf+40>>2]=tempI64[0],HEAP32[buf+44>>2]=tempI64[1];HEAP32[buf+48>>2]=4096;HEAP32[buf+52>>2]=stat.blocks;tempI64=[Math.floor(stat.atime.getTime()/1e3)>>>0,(tempDouble=Math.floor(stat.atime.getTime()/1e3),+Math.abs(tempDouble)>=1?tempDouble>0?(Math.min(+Math.floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[buf+56>>2]=tempI64[0],HEAP32[buf+60>>2]=tempI64[1];HEAPU32[buf+64>>2]=0;tempI64=[Math.floor(stat.mtime.getTime()/1e3)>>>0,(tempDouble=Math.floor(stat.mtime.getTime()/1e3),+Math.abs(tempDouble)>=1?tempDouble>0?(Math.min(+Math.floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[buf+72>>2]=tempI64[0],HEAP32[buf+76>>2]=tempI64[1];HEAPU32[buf+80>>2]=0;tempI64=[Math.floor(stat.ctime.getTime()/1e3)>>>0,(tempDouble=Math.floor(stat.ctime.getTime()/1e3),+Math.abs(tempDouble)>=1?tempDouble>0?(Math.min(+Math.floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[buf+88>>2]=tempI64[0],HEAP32[buf+92>>2]=tempI64[1];HEAPU32[buf+96>>2]=0;tempI64=[stat.ino>>>0,(tempDouble=stat.ino,+Math.abs(tempDouble)>=1?tempDouble>0?(Math.min(+Math.floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[buf+104>>2]=tempI64[0],HEAP32[buf+108>>2]=tempI64[1];return 0},doMsync:function(addr,stream,len,flags,offset){if(!FS.isFile(stream.node.mode)){throw new FS.ErrnoError(43)}if(flags&2){return 0}var buffer=HEAPU8.slice(addr,addr+len);FS.msync(stream,buffer,offset,len,flags)},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},getStreamFromFD:function(fd){var stream=FS.getStream(fd);if(!stream)throw new FS.ErrnoError(8);return stream}};function ___syscall__newselect(nfds,readfds,writefds,exceptfds,timeout){try{var total=0;var srcReadLow=readfds?HEAP32[readfds>>2]:0,srcReadHigh=readfds?HEAP32[readfds+4>>2]:0;var srcWriteLow=writefds?HEAP32[writefds>>2]:0,srcWriteHigh=writefds?HEAP32[writefds+4>>2]:0;var srcExceptLow=exceptfds?HEAP32[exceptfds>>2]:0,srcExceptHigh=exceptfds?HEAP32[exceptfds+4>>2]:0;var dstReadLow=0,dstReadHigh=0;var dstWriteLow=0,dstWriteHigh=0;var dstExceptLow=0,dstExceptHigh=0;var allLow=(readfds?HEAP32[readfds>>2]:0)|(writefds?HEAP32[writefds>>2]:0)|(exceptfds?HEAP32[exceptfds>>2]:0);var allHigh=(readfds?HEAP32[readfds+4>>2]:0)|(writefds?HEAP32[writefds+4>>2]:0)|(exceptfds?HEAP32[exceptfds+4>>2]:0);var check=function(fd,low,high,val){return fd<32?low&val:high&val};for(var fd=0;fd>2]=dstReadLow;HEAP32[readfds+4>>2]=dstReadHigh}if(writefds){HEAP32[writefds>>2]=dstWriteLow;HEAP32[writefds+4>>2]=dstWriteHigh}if(exceptfds){HEAP32[exceptfds>>2]=dstExceptLow;HEAP32[exceptfds+4>>2]=dstExceptHigh}return total}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}var SOCKFS={mount:function(mount){Module["websocket"]=Module["websocket"]&&"object"===typeof Module["websocket"]?Module["websocket"]:{};Module["websocket"]._callbacks={};Module["websocket"]["on"]=function(event,callback){if("function"===typeof callback){this._callbacks[event]=callback}return this};Module["websocket"].emit=function(event,param){if("function"===typeof this._callbacks[event]){this._callbacks[event].call(this,param)}};return FS.createNode(null,"/",16384|511,0)},createSocket:function(family,type,protocol){type&=~526336;var streaming=type==1;if(streaming&&protocol&&protocol!=6){throw new FS.ErrnoError(66)}var sock={family:family,type:type,protocol:protocol,server:null,error:null,peers:{},pending:[],recv_queue:[],sock_ops:SOCKFS.websocket_sock_ops};var name=SOCKFS.nextname();var node=FS.createNode(SOCKFS.root,name,49152,0);node.sock=sock;var stream=FS.createStream({path:name,node:node,flags:2,seekable:false,stream_ops:SOCKFS.stream_ops});sock.stream=stream;return sock},getSocket:function(fd){var stream=FS.getStream(fd);if(!stream||!FS.isSocket(stream.node.mode)){return null}return stream.node.sock},stream_ops:{poll:function(stream){var sock=stream.node.sock;return sock.sock_ops.poll(sock)},ioctl:function(stream,request,varargs){var sock=stream.node.sock;return sock.sock_ops.ioctl(sock,request,varargs)},read:function(stream,buffer,offset,length,position){var sock=stream.node.sock;var msg=sock.sock_ops.recvmsg(sock,length);if(!msg){return 0}buffer.set(msg.buffer,offset);return msg.buffer.length},write:function(stream,buffer,offset,length,position){var sock=stream.node.sock;return sock.sock_ops.sendmsg(sock,buffer,offset,length)},close:function(stream){var sock=stream.node.sock;sock.sock_ops.close(sock)}},nextname:function(){if(!SOCKFS.nextname.current){SOCKFS.nextname.current=0}return"socket["+SOCKFS.nextname.current+++"]"},websocket_sock_ops:{createPeer:function(sock,addr,port){var ws;if(typeof addr=="object"){ws=addr;addr=null;port=null}if(ws){if(ws._socket){addr=ws._socket.remoteAddress;port=ws._socket.remotePort}else{var result=/ws[s]?:\/\/([^:]+):(\d+)/.exec(ws.url);if(!result){throw new Error("WebSocket URL must be in the format ws(s)://address:port")}addr=result[1];port=parseInt(result[2],10)}}else{try{var runtimeConfig=Module["websocket"]&&"object"===typeof Module["websocket"];var url="ws:#".replace("#","//");if(runtimeConfig){if("string"===typeof Module["websocket"]["url"]){url=Module["websocket"]["url"]}}if(url==="ws://"||url==="wss://"){var parts=addr.split("/");url=url+parts[0]+":"+port+"/"+parts.slice(1).join("/")}var subProtocols="binary";if(runtimeConfig){if("string"===typeof Module["websocket"]["subprotocol"]){subProtocols=Module["websocket"]["subprotocol"]}}var opts=undefined;if(subProtocols!=="null"){subProtocols=subProtocols.replace(/^ +| +$/g,"").split(/ *, */);opts=subProtocols}if(runtimeConfig&&null===Module["websocket"]["subprotocol"]){subProtocols="null";opts=undefined}var WebSocketConstructor;{WebSocketConstructor=WebSocket}ws=new WebSocketConstructor(url,opts);ws.binaryType="arraybuffer"}catch(e){throw new FS.ErrnoError(23)}}var peer={addr:addr,port:port,socket:ws,dgram_send_queue:[]};SOCKFS.websocket_sock_ops.addPeer(sock,peer);SOCKFS.websocket_sock_ops.handlePeerEvents(sock,peer);if(sock.type===2&&typeof sock.sport!="undefined"){peer.dgram_send_queue.push(new Uint8Array([255,255,255,255,"p".charCodeAt(0),"o".charCodeAt(0),"r".charCodeAt(0),"t".charCodeAt(0),(sock.sport&65280)>>8,sock.sport&255]))}return peer},getPeer:function(sock,addr,port){return sock.peers[addr+":"+port]},addPeer:function(sock,peer){sock.peers[peer.addr+":"+peer.port]=peer},removePeer:function(sock,peer){delete sock.peers[peer.addr+":"+peer.port]},handlePeerEvents:function(sock,peer){var first=true;var handleOpen=function(){Module["websocket"].emit("open",sock.stream.fd);try{var queued=peer.dgram_send_queue.shift();while(queued){peer.socket.send(queued);queued=peer.dgram_send_queue.shift()}}catch(e){peer.socket.close()}};function handleMessage(data){if(typeof data=="string"){var encoder=new TextEncoder;data=encoder.encode(data)}else{assert(data.byteLength!==undefined);if(data.byteLength==0){return}data=new Uint8Array(data)}var wasfirst=first;first=false;if(wasfirst&&data.length===10&&data[0]===255&&data[1]===255&&data[2]===255&&data[3]===255&&data[4]==="p".charCodeAt(0)&&data[5]==="o".charCodeAt(0)&&data[6]==="r".charCodeAt(0)&&data[7]==="t".charCodeAt(0)){var newport=data[8]<<8|data[9];SOCKFS.websocket_sock_ops.removePeer(sock,peer);peer.port=newport;SOCKFS.websocket_sock_ops.addPeer(sock,peer);return}sock.recv_queue.push({addr:peer.addr,port:peer.port,data:data});Module["websocket"].emit("message",sock.stream.fd)}if(ENVIRONMENT_IS_NODE){peer.socket.on("open",handleOpen);peer.socket.on("message",function(data,isBinary){if(!isBinary){return}handleMessage(new Uint8Array(data).buffer)});peer.socket.on("close",function(){Module["websocket"].emit("close",sock.stream.fd)});peer.socket.on("error",function(error){sock.error=14;Module["websocket"].emit("error",[sock.stream.fd,sock.error,"ECONNREFUSED: Connection refused"])})}else{peer.socket.onopen=handleOpen;peer.socket.onclose=function(){Module["websocket"].emit("close",sock.stream.fd)};peer.socket.onmessage=function peer_socket_onmessage(event){handleMessage(event.data)};peer.socket.onerror=function(error){sock.error=14;Module["websocket"].emit("error",[sock.stream.fd,sock.error,"ECONNREFUSED: Connection refused"])}}},poll:function(sock){if(sock.type===1&&sock.server){return sock.pending.length?64|1:0}var mask=0;var dest=sock.type===1?SOCKFS.websocket_sock_ops.getPeer(sock,sock.daddr,sock.dport):null;if(sock.recv_queue.length||!dest||dest&&dest.socket.readyState===dest.socket.CLOSING||dest&&dest.socket.readyState===dest.socket.CLOSED){mask|=64|1}if(!dest||dest&&dest.socket.readyState===dest.socket.OPEN){mask|=4}if(dest&&dest.socket.readyState===dest.socket.CLOSING||dest&&dest.socket.readyState===dest.socket.CLOSED){mask|=16}return mask},ioctl:function(sock,request,arg){switch(request){case 21531:var bytes=0;if(sock.recv_queue.length){bytes=sock.recv_queue[0].data.length}HEAP32[arg>>2]=bytes;return 0;default:return 28}},close:function(sock){if(sock.server){try{sock.server.close()}catch(e){}sock.server=null}var peers=Object.keys(sock.peers);for(var i=0;i>2]=value;return value}function inetPton4(str){var b=str.split(".");for(var i=0;i<4;i++){var tmp=Number(b[i]);if(isNaN(tmp))return null;b[i]=tmp}return(b[0]|b[1]<<8|b[2]<<16|b[3]<<24)>>>0}function jstoi_q(str){return parseInt(str)}function inetPton6(str){var words;var w,offset,z;var valid6regx=/^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i;var parts=[];if(!valid6regx.test(str)){return null}if(str==="::"){return[0,0,0,0,0,0,0,0]}if(str.startsWith("::")){str=str.replace("::","Z:")}else{str=str.replace("::",":Z:")}if(str.indexOf(".")>0){str=str.replace(new RegExp("[.]","g"),":");words=str.split(":");words[words.length-4]=jstoi_q(words[words.length-4])+jstoi_q(words[words.length-3])*256;words[words.length-3]=jstoi_q(words[words.length-2])+jstoi_q(words[words.length-1])*256;words=words.slice(0,words.length-2)}else{words=str.split(":")}offset=0;z=0;for(w=0;w>2]=16}HEAP16[sa>>1]=family;HEAP32[sa+4>>2]=addr;HEAP16[sa+2>>1]=_htons(port);break;case 10:addr=inetPton6(addr);zeroMemory(sa,28);if(addrlen){HEAP32[addrlen>>2]=28}HEAP32[sa>>2]=family;HEAP32[sa+8>>2]=addr[0];HEAP32[sa+12>>2]=addr[1];HEAP32[sa+16>>2]=addr[2];HEAP32[sa+20>>2]=addr[3];HEAP16[sa+2>>1]=_htons(port);break;default:return 5}return 0}var DNS={address_map:{id:1,addrs:{},names:{}},lookup_name:function(name){var res=inetPton4(name);if(res!==null){return name}res=inetPton6(name);if(res!==null){return name}var addr;if(DNS.address_map.addrs[name]){addr=DNS.address_map.addrs[name]}else{var id=DNS.address_map.id++;assert(id<65535,"exceeded max address mappings of 65535");addr="172.29."+(id&255)+"."+(id&65280);DNS.address_map.names[addr]=name;DNS.address_map.addrs[name]=addr}return addr},lookup_addr:function(addr){if(DNS.address_map.names[addr]){return DNS.address_map.names[addr]}return null}};function ___syscall_accept4(fd,addr,addrlen,flags){try{var sock=getSocketFromFD(fd);var newsock=sock.sock_ops.accept(sock);if(addr){var errno=writeSockaddr(addr,newsock.family,DNS.lookup_name(newsock.daddr),newsock.dport,addrlen)}return newsock.stream.fd}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function inetNtop4(addr){return(addr&255)+"."+(addr>>8&255)+"."+(addr>>16&255)+"."+(addr>>24&255)}function inetNtop6(ints){var str="";var word=0;var longest=0;var lastzero=0;var zstart=0;var len=0;var i=0;var parts=[ints[0]&65535,ints[0]>>16,ints[1]&65535,ints[1]>>16,ints[2]&65535,ints[2]>>16,ints[3]&65535,ints[3]>>16];var hasipv4=true;var v4part="";for(i=0;i<5;i++){if(parts[i]!==0){hasipv4=false;break}}if(hasipv4){v4part=inetNtop4(parts[6]|parts[7]<<16);if(parts[5]===-1){str="::ffff:";str+=v4part;return str}if(parts[5]===0){str="::";if(v4part==="0.0.0.0")v4part="";if(v4part==="0.0.0.1")v4part="1";str+=v4part;return str}}for(word=0;word<8;word++){if(parts[word]===0){if(word-lastzero>1){len=0}lastzero=word;len++}if(len>longest){longest=len;zstart=word-longest+1}}for(word=0;word<8;word++){if(longest>1){if(parts[word]===0&&word>=zstart&&word>1];var port=_ntohs(HEAPU16[sa+2>>1]);var addr;switch(family){case 2:if(salen!==16){return{errno:28}}addr=HEAP32[sa+4>>2];addr=inetNtop4(addr);break;case 10:if(salen!==28){return{errno:28}}addr=[HEAP32[sa+8>>2],HEAP32[sa+12>>2],HEAP32[sa+16>>2],HEAP32[sa+20>>2]];addr=inetNtop6(addr);break;default:return{errno:5}}return{family:family,addr:addr,port:port}}function getSocketAddress(addrp,addrlen,allowNull){if(allowNull&&addrp===0)return null;var info=readSockaddr(addrp,addrlen);if(info.errno)throw new FS.ErrnoError(info.errno);info.addr=DNS.lookup_addr(info.addr)||info.addr;return info}function ___syscall_bind(fd,addr,addrlen){try{var sock=getSocketFromFD(fd);var info=getSocketAddress(addr,addrlen);sock.sock_ops.bind(sock,info.addr,info.port);return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_chmod(path,mode){try{path=SYSCALLS.getStr(path);FS.chmod(path,mode);return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_connect(fd,addr,addrlen){try{var sock=getSocketFromFD(fd);var info=getSocketAddress(addr,addrlen);sock.sock_ops.connect(sock,info.addr,info.port);return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_faccessat(dirfd,path,amode,flags){try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);if(amode&~7){return-28}var lookup=FS.lookupPath(path,{follow:true});var node=lookup.node;if(!node){return-44}var perms="";if(amode&4)perms+="r";if(amode&2)perms+="w";if(amode&1)perms+="x";if(perms&&FS.nodePermissions(node,perms)){return-2}return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_fcntl64(fd,cmd,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(fd);switch(cmd){case 0:{var arg=SYSCALLS.get();if(arg<0){return-28}var newStream;newStream=FS.createStream(stream,arg);return newStream.fd}case 1:case 2:return 0;case 3:return stream.flags;case 4:{var arg=SYSCALLS.get();stream.flags|=arg;return 0}case 5:{var arg=SYSCALLS.get();var offset=0;HEAP16[arg+offset>>1]=2;return 0}case 6:case 7:return 0;case 16:case 8:return-28;case 9:setErrNo(28);return-1;default:{return-28}}}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_fstat64(fd,buf){try{var stream=SYSCALLS.getStreamFromFD(fd);return SYSCALLS.doStat(FS.stat,stream.path,buf)}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_getdents64(fd,dirp,count){try{var stream=SYSCALLS.getStreamFromFD(fd);if(!stream.getdents){stream.getdents=FS.readdir(stream.path)}var struct_size=280;var pos=0;var off=FS.llseek(stream,0,1);var idx=Math.floor(off/struct_size);while(idx>>0,(tempDouble=id,+Math.abs(tempDouble)>=1?tempDouble>0?(Math.min(+Math.floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[dirp+pos>>2]=tempI64[0],HEAP32[dirp+pos+4>>2]=tempI64[1];tempI64=[(idx+1)*struct_size>>>0,(tempDouble=(idx+1)*struct_size,+Math.abs(tempDouble)>=1?tempDouble>0?(Math.min(+Math.floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[dirp+pos+8>>2]=tempI64[0],HEAP32[dirp+pos+12>>2]=tempI64[1];HEAP16[dirp+pos+16>>1]=280;HEAP8[dirp+pos+18>>0]=type;stringToUTF8(name,dirp+pos+19,256);pos+=struct_size;idx+=1}FS.llseek(stream,idx*struct_size,0);return pos}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_getsockname(fd,addr,addrlen){try{err("__syscall_getsockname "+fd);var sock=getSocketFromFD(fd);var errno=writeSockaddr(addr,sock.family,DNS.lookup_name(sock.saddr||"0.0.0.0"),sock.sport,addrlen);return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_getsockopt(fd,level,optname,optval,optlen){try{var sock=getSocketFromFD(fd);if(level===1){if(optname===4){HEAP32[optval>>2]=sock.error;HEAP32[optlen>>2]=4;sock.error=null;return 0}}return-50}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_ioctl(fd,op,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(fd);switch(op){case 21509:case 21505:{if(!stream.tty)return-59;return 0}case 21510:case 21511:case 21512:case 21506:case 21507:case 21508:{if(!stream.tty)return-59;return 0}case 21519:{if(!stream.tty)return-59;var argp=SYSCALLS.get();HEAP32[argp>>2]=0;return 0}case 21520:{if(!stream.tty)return-59;return-28}case 21531:{var argp=SYSCALLS.get();return FS.ioctl(stream,op,argp)}case 21523:{if(!stream.tty)return-59;return 0}case 21524:{if(!stream.tty)return-59;return 0}default:return-28}}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_listen(fd,backlog){try{var sock=getSocketFromFD(fd);sock.sock_ops.listen(sock,backlog);return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_lstat64(path,buf){try{path=SYSCALLS.getStr(path);return SYSCALLS.doStat(FS.lstat,path,buf)}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_newfstatat(dirfd,path,buf,flags){try{path=SYSCALLS.getStr(path);var nofollow=flags&256;var allowEmpty=flags&4096;flags=flags&~4352;path=SYSCALLS.calculateAt(dirfd,path,allowEmpty);return SYSCALLS.doStat(nofollow?FS.lstat:FS.stat,path,buf)}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_openat(dirfd,path,flags,varargs){SYSCALLS.varargs=varargs;try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);var mode=varargs?SYSCALLS.get():0;return FS.open(path,flags,mode).fd}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}var PIPEFS={BUCKET_BUFFER_SIZE:8192,mount:function(mount){return FS.createNode(null,"/",16384|511,0)},createPipe:function(){var pipe={buckets:[],refcnt:2};pipe.buckets.push({buffer:new Uint8Array(PIPEFS.BUCKET_BUFFER_SIZE),offset:0,roffset:0});var rName=PIPEFS.nextname();var wName=PIPEFS.nextname();var rNode=FS.createNode(PIPEFS.root,rName,4096,0);var wNode=FS.createNode(PIPEFS.root,wName,4096,0);rNode.pipe=pipe;wNode.pipe=pipe;var readableStream=FS.createStream({path:rName,node:rNode,flags:0,seekable:false,stream_ops:PIPEFS.stream_ops});rNode.stream=readableStream;var writableStream=FS.createStream({path:wName,node:wNode,flags:1,seekable:false,stream_ops:PIPEFS.stream_ops});wNode.stream=writableStream;return{readable_fd:readableStream.fd,writable_fd:writableStream.fd}},stream_ops:{poll:function(stream){var pipe=stream.node.pipe;if((stream.flags&2097155)===1){return 256|4}if(pipe.buckets.length>0){for(var i=0;i0){return 64|1}}}return 0},ioctl:function(stream,request,varargs){return 28},fsync:function(stream){return 28},read:function(stream,buffer,offset,length,position){var pipe=stream.node.pipe;var currentLength=0;for(var i=0;i=dataLen){currBucket.buffer.set(data,currBucket.offset);currBucket.offset+=dataLen;return dataLen}else if(freeBytesInCurrBuffer>0){currBucket.buffer.set(data.subarray(0,freeBytesInCurrBuffer),currBucket.offset);currBucket.offset+=freeBytesInCurrBuffer;data=data.subarray(freeBytesInCurrBuffer,data.byteLength)}var numBuckets=data.byteLength/PIPEFS.BUCKET_BUFFER_SIZE|0;var remElements=data.byteLength%PIPEFS.BUCKET_BUFFER_SIZE;for(var i=0;i0){var newBucket={buffer:new Uint8Array(PIPEFS.BUCKET_BUFFER_SIZE),offset:data.byteLength,roffset:0};pipe.buckets.push(newBucket);newBucket.buffer.set(data)}return dataLen},close:function(stream){var pipe=stream.node.pipe;pipe.refcnt--;if(pipe.refcnt===0){pipe.buckets=null}}},nextname:function(){if(!PIPEFS.nextname.current){PIPEFS.nextname.current=0}return"pipe["+PIPEFS.nextname.current+++"]"}};function ___syscall_pipe(fdPtr){try{if(fdPtr==0){throw new FS.ErrnoError(21)}var res=PIPEFS.createPipe();HEAP32[fdPtr>>2]=res.readable_fd;HEAP32[fdPtr+4>>2]=res.writable_fd;return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_readlinkat(dirfd,path,buf,bufsize){try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);if(bufsize<=0)return-28;var ret=FS.readlink(path);var len=Math.min(bufsize,lengthBytesUTF8(ret));var endChar=HEAP8[buf+len];stringToUTF8(ret,buf,bufsize+1);HEAP8[buf+len]=endChar;return len}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_renameat(olddirfd,oldpath,newdirfd,newpath){try{oldpath=SYSCALLS.getStr(oldpath);newpath=SYSCALLS.getStr(newpath);oldpath=SYSCALLS.calculateAt(olddirfd,oldpath);newpath=SYSCALLS.calculateAt(newdirfd,newpath);FS.rename(oldpath,newpath);return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_sendto(fd,message,length,flags,addr,addr_len){try{var sock=getSocketFromFD(fd);var dest=getSocketAddress(addr,addr_len,true);if(!dest){return FS.write(sock.stream,HEAP8,message,length)}return sock.sock_ops.sendmsg(sock,HEAP8,message,length,dest.addr,dest.port)}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_socket(domain,type,protocol){try{var sock=SOCKFS.createSocket(domain,type,protocol);return sock.stream.fd}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_stat64(path,buf){try{path=SYSCALLS.getStr(path);return SYSCALLS.doStat(FS.stat,path,buf)}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_symlink(target,linkpath){try{target=SYSCALLS.getStr(target);linkpath=SYSCALLS.getStr(linkpath);FS.symlink(target,linkpath);return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function ___syscall_unlinkat(dirfd,path,flags){try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);if(flags===0){FS.unlink(path)}else if(flags===512){FS.rmdir(path)}else{abort("Invalid flags passed to unlinkat")}return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function __emscripten_fs_load_embedded_files(ptr){do{var name_addr=HEAPU32[ptr>>2];ptr+=4;var len=HEAPU32[ptr>>2];ptr+=4;var content=HEAPU32[ptr>>2];ptr+=4;var name=UTF8ToString(name_addr);FS.createPath("/",PATH.dirname(name),true,true);FS.createDataFile(name,null,HEAP8.subarray(content,content+len),true,true,true)}while(HEAPU32[ptr>>2])}var nowIsMonotonic=true;function __emscripten_get_now_is_monotonic(){return nowIsMonotonic}function readI53FromI64(ptr){return HEAPU32[ptr>>2]+HEAP32[ptr+4>>2]*4294967296}function __gmtime_js(time,tmPtr){var date=new Date(readI53FromI64(time)*1e3);HEAP32[tmPtr>>2]=date.getUTCSeconds();HEAP32[tmPtr+4>>2]=date.getUTCMinutes();HEAP32[tmPtr+8>>2]=date.getUTCHours();HEAP32[tmPtr+12>>2]=date.getUTCDate();HEAP32[tmPtr+16>>2]=date.getUTCMonth();HEAP32[tmPtr+20>>2]=date.getUTCFullYear()-1900;HEAP32[tmPtr+24>>2]=date.getUTCDay();var start=Date.UTC(date.getUTCFullYear(),0,1,0,0,0,0);var yday=(date.getTime()-start)/(1e3*60*60*24)|0;HEAP32[tmPtr+28>>2]=yday}function __munmap_js(addr,len,prot,flags,fd,offset){try{var stream=SYSCALLS.getStreamFromFD(fd);if(prot&2){SYSCALLS.doMsync(addr,stream,len,flags,offset)}FS.munmap(stream)}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return-e.errno}}function allocateUTF8(str){var size=lengthBytesUTF8(str)+1;var ret=_malloc(size);if(ret)stringToUTF8Array(str,HEAP8,ret,size);return ret}function __tzset_js(timezone,daylight,tzname){var currentYear=(new Date).getFullYear();var winter=new Date(currentYear,0,1);var summer=new Date(currentYear,6,1);var winterOffset=winter.getTimezoneOffset();var summerOffset=summer.getTimezoneOffset();var stdTimezoneOffset=Math.max(winterOffset,summerOffset);HEAPU32[timezone>>2]=stdTimezoneOffset*60;HEAP32[daylight>>2]=Number(winterOffset!=summerOffset);function extractZone(date){var match=date.toTimeString().match(/\(([A-Za-z ]+)\)$/);return match?match[1]:"GMT"}var winterName=extractZone(winter);var summerName=extractZone(summer);var winterNamePtr=allocateUTF8(winterName);var summerNamePtr=allocateUTF8(summerName);if(summerOffset>2]=winterNamePtr;HEAPU32[tzname+4>>2]=summerNamePtr}else{HEAPU32[tzname>>2]=summerNamePtr;HEAPU32[tzname+4>>2]=winterNamePtr}}function _abort(){abort("")}function handleException(e){if(e instanceof ExitStatus||e=="unwind"){return EXITSTATUS}quit_(1,e)}function _proc_exit(code){EXITSTATUS=code;if(!keepRuntimeAlive()){if(Module["onExit"])Module["onExit"](code);ABORT=true}quit_(code,new ExitStatus(code))}function exitJS(status,implicit){EXITSTATUS=status;if(!keepRuntimeAlive()){exitRuntime()}_proc_exit(status)}var _exit=exitJS;function maybeExit(){if(!keepRuntimeAlive()){try{_exit(EXITSTATUS)}catch(e){handleException(e)}}}function callUserCallback(func){if(runtimeExited||ABORT){return}try{func();maybeExit()}catch(e){handleException(e)}}function _alarm(seconds){setTimeout(function(){callUserCallback(function(){_raise(14)})},seconds*1e3)}function _emscripten_date_now(){return Date.now()}function getHeapMax(){return 2147483648}function _emscripten_get_heap_max(){return getHeapMax()}var _emscripten_get_now;_emscripten_get_now=()=>performance.now();function _emscripten_memcpy_big(dest,src,num){HEAPU8.copyWithin(dest,src,src+num)}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){try{var stream=SYSCALLS.getStreamFromFD(fd);FS.close(stream);return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return e.errno}}function doReadv(stream,iov,iovcnt,offset){var ret=0;for(var i=0;i>2];var len=HEAPU32[iov+4>>2];iov+=8;var curr=FS.read(stream,HEAP8,ptr,len,offset);if(curr<0)return-1;ret+=curr;if(curr>2]=num;return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return e.errno}}function convertI32PairToI53Checked(lo,hi){return hi+2097152>>>0<4194305-!!lo?(lo>>>0)+hi*4294967296:NaN}function _fd_seek(fd,offset_low,offset_high,whence,newOffset){try{var offset=convertI32PairToI53Checked(offset_low,offset_high);if(isNaN(offset))return 61;var stream=SYSCALLS.getStreamFromFD(fd);FS.llseek(stream,offset,whence);tempI64=[stream.position>>>0,(tempDouble=stream.position,+Math.abs(tempDouble)>=1?tempDouble>0?(Math.min(+Math.floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[newOffset>>2]=tempI64[0],HEAP32[newOffset+4>>2]=tempI64[1];if(stream.getdents&&offset===0&&whence===0)stream.getdents=null;return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return e.errno}}function doWritev(stream,iov,iovcnt,offset){var ret=0;for(var i=0;i>2];var len=HEAPU32[iov+4>>2];iov+=8;var curr=FS.write(stream,HEAP8,ptr,len,offset);if(curr<0)return-1;ret+=curr}return ret}function _fd_write(fd,iov,iovcnt,pnum){try{var stream=SYSCALLS.getStreamFromFD(fd);var num=doWritev(stream,iov,iovcnt);HEAPU32[pnum>>2]=num;return 0}catch(e){if(typeof FS=="undefined"||!(e instanceof FS.ErrnoError))throw e;return e.errno}}function _getaddrinfo(node,service,hint,out){var addr=0;var port=0;var flags=0;var family=0;var type=0;var proto=0;var ai;function allocaddrinfo(family,type,proto,canon,addr,port){var sa,salen,ai;var errno;salen=family===10?28:16;addr=family===10?inetNtop6(addr):inetNtop4(addr);sa=_malloc(salen);errno=writeSockaddr(sa,family,addr,port);assert(!errno);ai=_malloc(32);HEAP32[ai+4>>2]=family;HEAP32[ai+8>>2]=type;HEAP32[ai+12>>2]=proto;HEAP32[ai+24>>2]=canon;HEAPU32[ai+20>>2]=sa;if(family===10){HEAP32[ai+16>>2]=28}else{HEAP32[ai+16>>2]=16}HEAP32[ai+28>>2]=0;return ai}if(hint){flags=HEAP32[hint>>2];family=HEAP32[hint+4>>2];type=HEAP32[hint+8>>2];proto=HEAP32[hint+12>>2]}if(type&&!proto){proto=type===2?17:6}if(!type&&proto){type=proto===17?2:1}if(proto===0){proto=6}if(type===0){type=1}if(!node&&!service){return-2}if(flags&~(1|2|4|1024|8|16|32)){return-1}if(hint!==0&&HEAP32[hint>>2]&2&&!node){return-1}if(flags&32){return-2}if(type!==0&&type!==1&&type!==2){return-7}if(family!==0&&family!==2&&family!==10){return-6}if(service){service=UTF8ToString(service);port=parseInt(service,10);if(isNaN(port)){if(flags&1024){return-2}return-8}}if(!node){if(family===0){family=2}if((flags&1)===0){if(family===2){addr=_htonl(2130706433)}else{addr=[0,0,0,1]}}ai=allocaddrinfo(family,type,proto,null,addr,port);HEAPU32[out>>2]=ai;return 0}node=UTF8ToString(node);addr=inetPton4(node);if(addr!==null){if(family===0||family===2){family=2}else if(family===10&&flags&8){addr=[0,0,_htonl(65535),addr];family=10}else{return-2}}else{addr=inetPton6(node);if(addr!==null){if(family===0||family===10){family=10}else{return-2}}}if(addr!=null){ai=allocaddrinfo(family,type,proto,node,addr,port);HEAPU32[out>>2]=ai;return 0}if(flags&4){return-2}node=DNS.lookup_name(node);addr=inetPton4(node);if(family===0){family=2}else if(family===10){addr=[0,0,_htonl(65535),addr]}ai=allocaddrinfo(family,type,proto,null,addr,port);HEAPU32[out>>2]=ai;return 0}function _getnameinfo(sa,salen,node,nodelen,serv,servlen,flags){var info=readSockaddr(sa,salen);if(info.errno){return-6}var port=info.port;var addr=info.addr;var overflowed=false;if(node&&nodelen){var lookup;if(flags&1||!(lookup=DNS.lookup_addr(addr))){if(flags&8){return-2}}else{addr=lookup}var numBytesWrittenExclNull=stringToUTF8(addr,node,nodelen);if(numBytesWrittenExclNull+1>=nodelen){overflowed=true}}if(serv&&servlen){port=""+port;var numBytesWrittenExclNull=stringToUTF8(port,serv,servlen);if(numBytesWrittenExclNull+1>=servlen){overflowed=true}}if(overflowed){return-12}return 0}function __isLeapYear(year){return year%4===0&&(year%100!==0||year%400===0)}function __arraySum(array,index){var sum=0;for(var i=0;i<=index;sum+=array[i++]){}return sum}var __MONTH_DAYS_LEAP=[31,29,31,30,31,30,31,31,30,31,30,31];var __MONTH_DAYS_REGULAR=[31,28,31,30,31,30,31,31,30,31,30,31];function __addDays(date,days){var newDate=new Date(date.getTime());while(days>0){var leap=__isLeapYear(newDate.getFullYear());var currentMonth=newDate.getMonth();var daysInCurrentMonth=(leap?__MONTH_DAYS_LEAP:__MONTH_DAYS_REGULAR)[currentMonth];if(days>daysInCurrentMonth-newDate.getDate()){days-=daysInCurrentMonth-newDate.getDate()+1;newDate.setDate(1);if(currentMonth<11){newDate.setMonth(currentMonth+1)}else{newDate.setMonth(0);newDate.setFullYear(newDate.getFullYear()+1)}}else{newDate.setDate(newDate.getDate()+days);return newDate}}return newDate}function writeArrayToMemory(array,buffer){HEAP8.set(array,buffer)}function _strftime(s,maxsize,format,tm){var tm_zone=HEAP32[tm+40>>2];var date={tm_sec:HEAP32[tm>>2],tm_min:HEAP32[tm+4>>2],tm_hour:HEAP32[tm+8>>2],tm_mday:HEAP32[tm+12>>2],tm_mon:HEAP32[tm+16>>2],tm_year:HEAP32[tm+20>>2],tm_wday:HEAP32[tm+24>>2],tm_yday:HEAP32[tm+28>>2],tm_isdst:HEAP32[tm+32>>2],tm_gmtoff:HEAP32[tm+36>>2],tm_zone:tm_zone?UTF8ToString(tm_zone):""};var pattern=UTF8ToString(format);var EXPANSION_RULES_1={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var rule in EXPANSION_RULES_1){pattern=pattern.replace(new RegExp(rule,"g"),EXPANSION_RULES_1[rule])}var WEEKDAYS=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];var MONTHS=["January","February","March","April","May","June","July","August","September","October","November","December"];function leadingSomething(value,digits,character){var str=typeof value=="number"?value.toString():value||"";while(str.length0?1:0}var compare;if((compare=sgn(date1.getFullYear()-date2.getFullYear()))===0){if((compare=sgn(date1.getMonth()-date2.getMonth()))===0){compare=sgn(date1.getDate()-date2.getDate())}}return compare}function getFirstWeekStartDate(janFourth){switch(janFourth.getDay()){case 0:return new Date(janFourth.getFullYear()-1,11,29);case 1:return janFourth;case 2:return new Date(janFourth.getFullYear(),0,3);case 3:return new Date(janFourth.getFullYear(),0,2);case 4:return new Date(janFourth.getFullYear(),0,1);case 5:return new Date(janFourth.getFullYear()-1,11,31);case 6:return new Date(janFourth.getFullYear()-1,11,30)}}function getWeekBasedYear(date){var thisDate=__addDays(new Date(date.tm_year+1900,0,1),date.tm_yday);var janFourthThisYear=new Date(thisDate.getFullYear(),0,4);var janFourthNextYear=new Date(thisDate.getFullYear()+1,0,4);var firstWeekStartThisYear=getFirstWeekStartDate(janFourthThisYear);var firstWeekStartNextYear=getFirstWeekStartDate(janFourthNextYear);if(compareByDay(firstWeekStartThisYear,thisDate)<=0){if(compareByDay(firstWeekStartNextYear,thisDate)<=0){return thisDate.getFullYear()+1}return thisDate.getFullYear()}return thisDate.getFullYear()-1}var EXPANSION_RULES_2={"%a":function(date){return WEEKDAYS[date.tm_wday].substring(0,3)},"%A":function(date){return WEEKDAYS[date.tm_wday]},"%b":function(date){return MONTHS[date.tm_mon].substring(0,3)},"%B":function(date){return MONTHS[date.tm_mon]},"%C":function(date){var year=date.tm_year+1900;return leadingNulls(year/100|0,2)},"%d":function(date){return leadingNulls(date.tm_mday,2)},"%e":function(date){return leadingSomething(date.tm_mday,2," ")},"%g":function(date){return getWeekBasedYear(date).toString().substring(2)},"%G":function(date){return getWeekBasedYear(date)},"%H":function(date){return leadingNulls(date.tm_hour,2)},"%I":function(date){var twelveHour=date.tm_hour;if(twelveHour==0)twelveHour=12;else if(twelveHour>12)twelveHour-=12;return leadingNulls(twelveHour,2)},"%j":function(date){return leadingNulls(date.tm_mday+__arraySum(__isLeapYear(date.tm_year+1900)?__MONTH_DAYS_LEAP:__MONTH_DAYS_REGULAR,date.tm_mon-1),3)},"%m":function(date){return leadingNulls(date.tm_mon+1,2)},"%M":function(date){return leadingNulls(date.tm_min,2)},"%n":function(){return"\n"},"%p":function(date){if(date.tm_hour>=0&&date.tm_hour<12){return"AM"}return"PM"},"%S":function(date){return leadingNulls(date.tm_sec,2)},"%t":function(){return"\t"},"%u":function(date){return date.tm_wday||7},"%U":function(date){var days=date.tm_yday+7-date.tm_wday;return leadingNulls(Math.floor(days/7),2)},"%V":function(date){var val=Math.floor((date.tm_yday+7-(date.tm_wday+6)%7)/7);if((date.tm_wday+371-date.tm_yday-2)%7<=2){val++}if(!val){val=52;var dec31=(date.tm_wday+7-date.tm_yday-1)%7;if(dec31==4||dec31==5&&__isLeapYear(date.tm_year%400-1)){val++}}else if(val==53){var jan1=(date.tm_wday+371-date.tm_yday)%7;if(jan1!=4&&(jan1!=3||!__isLeapYear(date.tm_year)))val=1}return leadingNulls(val,2)},"%w":function(date){return date.tm_wday},"%W":function(date){var days=date.tm_yday+7-(date.tm_wday+6)%7;return leadingNulls(Math.floor(days/7),2)},"%y":function(date){return(date.tm_year+1900).toString().substring(2)},"%Y":function(date){return date.tm_year+1900},"%z":function(date){var off=date.tm_gmtoff;var ahead=off>=0;off=Math.abs(off)/60;off=off/60*100+off%60;return(ahead?"+":"-")+String("0000"+off).slice(-4)},"%Z":function(date){return date.tm_zone},"%%":function(){return"%"}};pattern=pattern.replace(/%%/g,"\0\0");for(var rule in EXPANSION_RULES_2){if(pattern.includes(rule)){pattern=pattern.replace(new RegExp(rule,"g"),EXPANSION_RULES_2[rule](date))}}pattern=pattern.replace(/\0\0/g,"%");var bytes=intArrayFromString(pattern,false);if(bytes.length>maxsize){return 0}writeArrayToMemory(bytes,s);return bytes.length-1}function allocateUTF8OnStack(str){var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8Array(str,HEAP8,ret,size);return ret}var FSNode=function(parent,name,mode,rdev){if(!parent){parent=this}this.parent=parent;this.mount=parent.mount;this.mounted=null;this.id=FS.nextInode++;this.name=name;this.mode=mode;this.node_ops={};this.stream_ops={};this.rdev=rdev};var readMode=292|73;var writeMode=146;Object.defineProperties(FSNode.prototype,{read:{get:function(){return(this.mode&readMode)===readMode},set:function(val){val?this.mode|=readMode:this.mode&=~readMode}},write:{get:function(){return(this.mode&writeMode)===writeMode},set:function(val){val?this.mode|=writeMode:this.mode&=~writeMode}},isFolder:{get:function(){return FS.isDir(this.mode)}},isDevice:{get:function(){return FS.isChrdev(this.mode)}}});FS.FSNode=FSNode;FS.staticInit();Module["FS_createPath"]=FS.createPath;Module["FS_createDataFile"]=FS.createDataFile;Module["FS_createPreloadedFile"]=FS.createPreloadedFile;Module["FS_unlink"]=FS.unlink;Module["FS_createLazyFile"]=FS.createLazyFile;Module["FS_createDevice"]=FS.createDevice;var asmLibraryArg={"F":___call_sighandler,"A":___syscall__newselect,"u":___syscall_accept4,"t":___syscall_bind,"T":___syscall_chmod,"r":___syscall_connect,"U":___syscall_faccessat,"d":___syscall_fcntl64,"N":___syscall_fstat64,"E":___syscall_getdents64,"q":___syscall_getsockname,"p":___syscall_getsockopt,"h":___syscall_ioctl,"o":___syscall_listen,"K":___syscall_lstat64,"L":___syscall_newfstatat,"j":___syscall_openat,"G":___syscall_pipe,"C":___syscall_readlinkat,"B":___syscall_renameat,"n":___syscall_sendto,"i":___syscall_socket,"M":___syscall_stat64,"z":___syscall_symlink,"w":___syscall_unlinkat,"l":__emscripten_fs_load_embedded_files,"P":__emscripten_get_now_is_monotonic,"Q":__gmtime_js,"H":__munmap_js,"R":__tzset_js,"s":_abort,"a":_alarm,"e":_emscripten_date_now,"y":_emscripten_get_heap_max,"k":_emscripten_get_now,"S":_emscripten_memcpy_big,"v":_emscripten_resize_heap,"I":_environ_get,"J":_environ_sizes_get,"b":_exit,"c":_fd_close,"g":_fd_read,"m":_fd_seek,"f":_fd_write,"D":_getaddrinfo,"O":_getnameinfo,"x":_strftime};var asm=createWasm();var ___wasm_call_ctors=Module["___wasm_call_ctors"]=function(){return(___wasm_call_ctors=Module["___wasm_call_ctors"]=Module["asm"]["W"]).apply(null,arguments)};var _main=Module["_main"]=function(){return(_main=Module["_main"]=Module["asm"]["Y"]).apply(null,arguments)};var ___errno_location=Module["___errno_location"]=function(){return(___errno_location=Module["___errno_location"]=Module["asm"]["Z"]).apply(null,arguments)};var _fflush=Module["_fflush"]=function(){return(_fflush=Module["_fflush"]=Module["asm"]["_"]).apply(null,arguments)};var _ntohs=Module["_ntohs"]=function(){return(_ntohs=Module["_ntohs"]=Module["asm"]["$"]).apply(null,arguments)};var _malloc=Module["_malloc"]=function(){return(_malloc=Module["_malloc"]=Module["asm"]["aa"]).apply(null,arguments)};var ___funcs_on_exit=Module["___funcs_on_exit"]=function(){return(___funcs_on_exit=Module["___funcs_on_exit"]=Module["asm"]["ba"]).apply(null,arguments)};var _htonl=Module["_htonl"]=function(){return(_htonl=Module["_htonl"]=Module["asm"]["ca"]).apply(null,arguments)};var _htons=Module["_htons"]=function(){return(_htons=Module["_htons"]=Module["asm"]["da"]).apply(null,arguments)};var _raise=Module["_raise"]=function(){return(_raise=Module["_raise"]=Module["asm"]["ea"]).apply(null,arguments)};var _emscripten_builtin_memalign=Module["_emscripten_builtin_memalign"]=function(){return(_emscripten_builtin_memalign=Module["_emscripten_builtin_memalign"]=Module["asm"]["fa"]).apply(null,arguments)};var stackAlloc=Module["stackAlloc"]=function(){return(stackAlloc=Module["stackAlloc"]=Module["asm"]["ga"]).apply(null,arguments)};var ___emscripten_embedded_file_data=Module["___emscripten_embedded_file_data"]=749224;Module["addRunDependency"]=addRunDependency;Module["removeRunDependency"]=removeRunDependency;Module["FS_createPath"]=FS.createPath;Module["FS_createDataFile"]=FS.createDataFile;Module["FS_createPreloadedFile"]=FS.createPreloadedFile;Module["FS_createLazyFile"]=FS.createLazyFile;Module["FS_createDevice"]=FS.createDevice;Module["FS_unlink"]=FS.unlink;Module["callMain"]=callMain;Module["FS"]=FS;Module["TTY"]=TTY;var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function callMain(args){var entryFunction=Module["_main"];args=args||[];args.unshift(thisProgram);var argc=args.length;var argv=stackAlloc((argc+1)*4);var argv_ptr=argv>>2;args.forEach(arg=>{HEAP32[argv_ptr++]=allocateUTF8OnStack(arg)});HEAP32[argv_ptr]=0;try{var ret=entryFunction(argc,argv);exitJS(ret,true);return ret}catch(e){return handleException(e)}}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();preMain();readyPromiseResolve(Module);if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();if(shouldRunNow)callMain(args);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()()}}var shouldRunNow=false;if(Module["noInitialRun"])shouldRunNow=false;run(); 10 | 11 | 12 | return EmscrJSR_openssl.ready 13 | } 14 | ); 15 | })(); 16 | if (typeof exports === 'object' && typeof module === 'object') 17 | module.exports = EmscrJSR_openssl; 18 | else if (typeof define === 'function' && define['amd']) 19 | define([], function() { return EmscrJSR_openssl; }); 20 | else if (typeof exports === 'object') 21 | exports["EmscrJSR_openssl"] = EmscrJSR_openssl; 22 | -------------------------------------------------------------------------------- /emscr/binary/openssl.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cryptool-org/openssl-webterm/eabeb9358453ccedad933be6d961a19fc7c3d54d/emscr/binary/openssl.wasm -------------------------------------------------------------------------------- /emscr/builds/openssl/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OPENSSL_VERSION="openssl-3.1.0" 4 | OPENSSL_DIR="src" 5 | 6 | if [ -d ${OPENSSL_DIR} ]; then 7 | rm -rf ${OPENSSL_DIR} 8 | fi 9 | 10 | if [ ! -f ${OPENSSL_VERSION}.tar.gz ]; then 11 | curl -O https://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz 12 | fi 13 | 14 | mkdir ${OPENSSL_DIR} 15 | tar xf ${OPENSSL_VERSION}.tar.gz --strip-components=1 --directory=${OPENSSL_DIR} 16 | cd ${OPENSSL_DIR} || exit 1 17 | 18 | mkdir -p usr/local/ssl/ 19 | cp ../openssl.cnf usr/local/ssl/openssl.cnf 20 | 21 | LDFLAGS="\ 22 | -s ENVIRONMENT='web'\ 23 | -s FILESYSTEM=1\ 24 | -s MODULARIZE=1\ 25 | -s EXPORTED_RUNTIME_METHODS=\"['callMain', 'FS', 'TTY']\"\ 26 | -s INVOKE_RUN=0\ 27 | -s EXIT_RUNTIME=1\ 28 | -s EXPORT_ES6=0\ 29 | -s EXPORT_NAME='EmscrJSR_openssl'\ 30 | -s USE_ES6_IMPORT_META=0\ 31 | -s ALLOW_MEMORY_GROWTH=1\ 32 | --embed-file usr/local/ssl/openssl.cnf" 33 | 34 | if [[ $1 == "debug" ]]; then 35 | LDFLAGS="$LDFLAGS -s ASSERTIONS=1" # For logging purposes. 36 | fi 37 | 38 | export LDFLAGS 39 | export CC=emcc 40 | export CXX=emcc 41 | 42 | emconfigure ./Configure \ 43 | no-hw \ 44 | no-shared \ 45 | no-asm \ 46 | no-threads \ 47 | no-ssl3 \ 48 | no-dtls \ 49 | no-engine \ 50 | no-dso \ 51 | linux-x32 \ 52 | -static\ 53 | 54 | sed -i 's/$(CROSS_COMPILE)//' Makefile 55 | emmake make -j 16 build_generated libssl.a libcrypto.a apps/openssl 56 | mv apps/openssl apps/openssl.js 57 | 58 | 59 | # import wasm build 60 | cp apps/openssl.js ../../../binary/openssl.js || exit 1 61 | cp apps/openssl.wasm ../../../binary/openssl.wasm || exit 1 62 | sed -i '1s;^;\/* eslint-disable *\/;' ../../../binary/openssl.js 63 | 64 | # clean up directory 65 | cd .. && rm -rf ${OPENSSL_DIR} ${OPENSSL_VERSION}.tar.gz 66 | -------------------------------------------------------------------------------- /emscr/builds/openssl/openssl.cnf: -------------------------------------------------------------------------------- 1 | openssl_conf = openssl_init 2 | 3 | [openssl_init] 4 | providers = provider_sect 5 | 6 | [provider_sect] 7 | default = default_sect 8 | legacy = legacy_sect 9 | 10 | [default_sect] 11 | activate = 1 12 | 13 | [legacy_sect] 14 | activate = 1 15 | 16 | [ req ] 17 | distinguished_name = req_distinguished_name 18 | 19 | [ req_distinguished_name ] 20 | countryName = Country Name (2 letter code) 21 | countryName_default = AU 22 | countryName_min = 2 23 | countryName_max = 2 24 | 25 | stateOrProvinceName = State or Province Name (full name) 26 | stateOrProvinceName_default = Some-State 27 | 28 | localityName = Locality Name (eg, city) 29 | 30 | 0.organizationName = Organization Name (eg, company) 31 | 0.organizationName_default = Internet Widgits Pty Ltd 32 | 33 | # we can do this but it is not needed normally :-) 34 | #1.organizationName = Second Organization Name (eg, company) 35 | #1.organizationName_default = World Wide Web Pty Ltd 36 | 37 | organizationalUnitName = Organizational Unit Name (eg, section) 38 | #organizationalUnitName_default = 39 | 40 | commonName = Common Name (e.g. server FQDN or YOUR name) 41 | commonName_max = 64 42 | 43 | emailAddress = Email Address 44 | emailAddress_max = 64 45 | 46 | # SET-ex3 = SET extension number 3 47 | 48 | [ req_attributes ] 49 | challengePassword = A challenge password 50 | challengePassword_min = 4 51 | challengePassword_max = 20 52 | 53 | unstructuredName = An optional company name 54 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import ReactDOM from "react-dom" 3 | 4 | import "./sources/translations" 5 | import CommandLine from "./sources/OpenSSL_CommandLine" 6 | 7 | import "./static/style.css" 8 | 9 | // initialize command line component 10 | ReactDOM.render(, document.getElementById("commandline")) 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "openssl-webterm", 3 | "version": "0.0.3", 4 | "description": "openssl running in browsers", 5 | "scripts": { 6 | "serve": "webpack serve --mode development", 7 | "build": "rm -rf dist && webpack --mode production && rm -f dist/*.LICENSE.txt", 8 | "build:openssl": "cd emscr/builds/openssl && ./build.sh ${ARG}", 9 | "build:openssl:docker": "docker run --rm -v $(pwd):$(pwd) -w $(pwd)/emscr/builds/openssl -u $(id -u):$(id -g) --platform linux/amd64 emscripten/emsdk /bin/bash ./build.sh ${ARG}" 10 | }, 11 | "keywords": [ 12 | "openssl", 13 | "wasm", 14 | "webassembly", 15 | "emscripten", 16 | "xterm.js", 17 | "js", 18 | "javascript", 19 | "react" 20 | ], 21 | "author": "cryptool-org", 22 | "license": "UNLICENSED", 23 | "dependencies": { 24 | "@babel/core": "^7.17.4", 25 | "@babel/preset-react": "^7.16.7", 26 | "babel-loader": "^8.2.3", 27 | "copy-webpack-plugin": "^10.2.4", 28 | "css-loader": "^6.6.0", 29 | "html-webpack-plugin": "^5.5.0", 30 | "i18next": "^21.6.13", 31 | "react": "^17.0.2", 32 | "react-bootstrap": "^1.6.4", 33 | "react-dom": "^17.0.2", 34 | "react-i18next": "^11.15.6", 35 | "style-loader": "^3.3.1", 36 | "wasm-webterm": "github:cryptool-org/wasm-webterm", 37 | "webpack": "^5.69.0", 38 | "webpack-cli": "^4.9.2", 39 | "webpack-dev-server": "^4.7.4" 40 | }, 41 | "babel": { 42 | "presets": [ 43 | "@babel/preset-react" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sources/OpenSSL_CommandLine.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | 3 | import { Trans } from "react-i18next" 4 | import i18next from "./translations" 5 | 6 | import XTerm from "./xterm-for-react" 7 | import WasmWebTerm from "wasm-webterm" 8 | 9 | import OpenSSLGUI from "./openssl-gui/OpenSSL_GUI" 10 | import { Button } from "react-bootstrap" 11 | 12 | class CommandLine extends React.Component { 13 | 14 | wasmTerm 15 | 16 | constructor(props) { 17 | super(props) 18 | 19 | window.commandLine = this // todo: debug 20 | 21 | // init wasm xterm addon (try cto url first) 22 | const baseUrl = window.CTO_Globals?.pluginRoot || "./" 23 | this.wasmTerm = new WasmWebTerm(baseUrl + "bin") 24 | 25 | // register api handlers for addon interaction 26 | this.wasmTerm.onFileSystemUpdate = files => this.setFiles(files) 27 | this.wasmTerm.onBeforeCommandRun = () => { if(!this.wasmTerm._worker) return new Promise(resolve => // using promise + timeout to show 28 | { this.setLoading(i18next.t("executing command"), () => setTimeout(() => resolve(), 20)) }) } // the animation before gui freezes ^^ 29 | this.wasmTerm.onCommandRunFinish = () => { if(!this.wasmTerm._worker) this.setLoading(false) } 30 | 31 | this.state = { 32 | 33 | loading: false, 34 | files: this.wasmTerm._wasmFsFiles, 35 | fullscreen: this.props.fullscreen || false, 36 | 37 | openSSL: { // internal data fetched from openssl 38 | curvesList: [], cipherList: [], hashfunList: [] 39 | } 40 | } 41 | 42 | // implement echo with js 43 | this.wasmTerm.registerJsCommand("echo", async function*(argv) { 44 | for(const char of argv.join(" ")) yield char 45 | }) 46 | 47 | // set custom openssl welcome message 48 | this.wasmTerm.printWelcomeMessage = () => { 49 | return new Promise(resolve => { 50 | 51 | let welcomemessage = `\x1b[1;32m 52 | _ _ _ _ _____ _____ _____ __ \r 53 | | | | |___| |_ | |___ ___ ___| __| __| | \r 54 | | | | | -_| . | | | | . | -_| |__ |__ | |__ \r 55 | |_____|___|___| |_____| _|___|_|_|_____|_____|_____|\r 56 | |_| \r 57 | \x1b[37m\r` 58 | 59 | this.wasmTerm.runWasmCommandHeadless("openssl", ["version"], null, version => { 60 | 61 | welcomemessage += "\r\n" + version.output + "\r" 62 | welcomemessage += i18next.t("Compiled to WebAssembly with Emscripten") + ". " 63 | + (this.wasmTerm._worker ? i18next.t("Running in WebWorker") 64 | : i18next.t("Worker not available")) + ".\r\n\r\n" 65 | welcomemessage += i18next.t("Usage: openssl [command] [params]") + "\r\n\r\n" 66 | 67 | resolve(welcomemessage) // continue execution flow 68 | 69 | }).catch(e => console.error(i18next.t("error while") + " printWelcomeMessage:", e)) 70 | }) 71 | } 72 | 73 | // init component values depending on openssl internals 74 | this.wasmTerm.onActivated = async () => { 75 | 76 | let curves = [] 77 | let ciphers = [] 78 | let hashes = [] 79 | 80 | // 1) fetch elliptic curves list from openssl 81 | const curvesList = await this.wasmTerm.runWasmCommandHeadless("openssl", ["ecparam", "-list_curves"]) 82 | curvesList.stdout.split("\n").forEach(row => { 83 | 84 | let name, description 85 | let cols = row.split(":") 86 | 87 | if(cols.length == 0) return // skip 88 | 89 | if(cols.length == 1) { // multiple lines description, append to last elem 90 | if(!curves[curves.length-1]) return 91 | curves[curves.length-1].description = curves[curves.length-1].description.trim() + " " + cols[0].trim() 92 | } 93 | 94 | if(cols.length > 1) { // name + description + x 95 | name = cols.shift().trim() 96 | description = cols.map(col => col.trim()).join(" ") 97 | curves.push({ name: name, description: description }) 98 | } 99 | 100 | }) 101 | 102 | // 2) fetch encrypt decrypt ciphers list from openssl 103 | ciphers = (await this.wasmTerm.runWasmCommandHeadless("openssl", ["enc", "-list"])) 104 | .stdout.split("\n").slice(1).map(x => x.split(" ").filter(y => y)) 105 | .reduce((a, b) => a.concat(b), []).map(x => x.substring(1)) 106 | 107 | // 3) fetch hash functions list from openssl 108 | hashes = (await this.wasmTerm.runWasmCommandHeadless("openssl", ["dgst", "-list"])) 109 | .stdout.split("\n").slice(1).map(x => x.split(" ").filter(y => y)) 110 | .reduce((a, b) => a.concat(b), []).map(x => x.substring(1)) 111 | 112 | // sort the lists alphabetically 113 | curves.sort((a, b) => a.name.localeCompare(b.name)) 114 | ciphers.sort((a, b) => a.localeCompare(b)) 115 | hashes.sort((a, b) => a.localeCompare(b)) 116 | 117 | // assign fetched values to component state 118 | this.setState({ openSSL: Object.assign({}, this.state.openSSL, 119 | { curvesList: curves, cipherList: ciphers, hashfunList: hashes }) }) 120 | 121 | } 122 | 123 | } 124 | 125 | render() { 126 | 127 | return ( 128 |
129 | 130 |
131 | 132 | 133 | 134 | { this.state.loading &&
135 | 136 |
{this.state.loading}
137 |
} 138 |
139 | 140 | {this.state.fullscreen &&
this._onFullscreenResize(e)}>
} 142 | 143 | this.setFiles(files)} 144 | fullscreen={this.state.fullscreen} exitFullscreen={() => this.exitFullscreen()} 145 | runCommand={line => this.runCommandFromOpenSSLGUI(line)} cipherList={this.state.openSSL.cipherList} 146 | curvesList={this.state.openSSL.curvesList} hashfunList={this.state.openSSL.hashfunList} /> 147 | 148 | {!this.state.fullscreen &&
149 | 150 | 153 | 154 | {typeof CTO_Globals == "undefined" && 155 | 156 |  {(window.lang == "en") ? "Deutsch" : "English"} 157 | } 158 | 159 |
} 160 | 161 |
162 | ) 163 | } 164 | 165 | componentDidUpdate(prevProps, prevState) { 166 | 167 | // resize on fullscreen mode change 168 | if(this.state.fullscreen != prevState.fullscreen) 169 | this.wasmTerm._xtermFitAddon.fit() 170 | 171 | return true // render anyway 172 | } 173 | 174 | 175 | setLoading(value, callback) { // value is string or boolean 176 | if(value) this.setState({ loading: value }, callback) 177 | else this.setState({ loading: false }, callback) 178 | } 179 | 180 | setFiles(files) { 181 | this.wasmTerm._wasmFsFiles = files 182 | this.setState(() => ({ files: this.wasmTerm._wasmFsFiles })) 183 | // state is passed as a function to use latest reference to wasmFsFiles 184 | } 185 | 186 | 187 | async runCommandFromOpenSSLGUI(line) { 188 | 189 | // only run one command at a time 190 | if(this.wasmTerm._isRunningCommand) return 191 | 192 | // show command on terminal 193 | this.wasmTerm._xterm.write(line + "\r\n") 194 | 195 | // abort current repl 196 | this.wasmTerm._xtermEcho.abortRead("Everything is fine, running command from GUI") 197 | 198 | // add command to history 199 | this.wasmTerm._xtermEcho.history.push(line) 200 | 201 | // show loading animation 202 | await this.wasmTerm.onBeforeCommandRun() 203 | 204 | // execute line of commands 205 | await this.wasmTerm.runLine(line) 206 | 207 | // print newline after 208 | this.wasmTerm._xterm.write("\r\n") 209 | 210 | // hide loading animation 211 | await this.wasmTerm.onCommandRunFinish() 212 | 213 | // restart repl 214 | this.wasmTerm.repl() 215 | 216 | } 217 | 218 | _onFullscreenResize(e) { 219 | const x = e.clientX, y = e.clientY 220 | const parentElem = e.target.parentNode 221 | const leftElem = e.target.previousElementSibling 222 | const leftWidth = leftElem.getBoundingClientRect().width 223 | document.onmousemove = (e) => { 224 | const dx = e.clientX - x, dy = e.clientY - y 225 | const newLeftWidth = ((leftWidth + dx) * 100) / parentElem.getBoundingClientRect().width 226 | leftElem.style.width = newLeftWidth + "%" 227 | this.wasmTerm._xtermFitAddon.fit() 228 | } 229 | document.onmouseup = () => document.onmousemove = document.onmouseup = null 230 | } 231 | 232 | enterFullscreen() { 233 | this.setState({ fullscreen: true }) 234 | document.getElementsByTagName("html")[0].style.overflow = "hidden" 235 | } 236 | 237 | exitFullscreen() { 238 | this.setState({ fullscreen: false }) 239 | document.getElementsByTagName("html")[0].style.overflow = "" 240 | } 241 | 242 | } 243 | 244 | export default CommandLine 245 | -------------------------------------------------------------------------------- /sources/openssl-gui/CommandField.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import { Trans } from "react-i18next" 3 | 4 | import Button from "react-bootstrap/Button" 5 | import FormControl from "react-bootstrap/FormControl" 6 | import InputGroup from "react-bootstrap/InputGroup" 7 | 8 | class CommandField extends React.Component { 9 | 10 | render() { 11 | return ( 12 | 13 | 14 | 15 | Command: 16 | 17 | 19 | 20 | 23 | 24 | 25 | 26 | ) 27 | } 28 | 29 | onClickRunButton() { 30 | this.props.runCommand(this.props.command) 31 | } 32 | 33 | } 34 | 35 | export default CommandField 36 | -------------------------------------------------------------------------------- /sources/openssl-gui/Helpers.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Helper functions for React components. 3 | */ 4 | 5 | class Helpers { 6 | 7 | /** 8 | * filter files for specific file types 9 | * looks at the first n chars of the files *content* 10 | * returns only a list of file *names* (no contents) 11 | */ 12 | static filterFilesByRegExp(files, regexp, n = 100) { 13 | let matchingFiles = [] 14 | files.forEach(file => { 15 | 16 | // get first n chars of file (todo: maybe until line break?) 17 | const fileHead = (new TextDecoder).decode(file.bytes.subarray(0, n)) 18 | 19 | // check if it matches -> save filename 20 | if(fileHead.match(new RegExp(regexp)) != null) matchingFiles.push(file.name) 21 | 22 | }) 23 | return matchingFiles 24 | } 25 | 26 | // filter files for private keys -> return array of file names 27 | static getPrivateKeysFilenamesFromFiles(files) { 28 | return Helpers.filterFilesByRegExp(files, "^-----BEGIN.* PRIVATE KEY-----") 29 | // -----BEGIN ENCRYPTED PRIVATE KEY----- 30 | } 31 | 32 | // filter files for private keys -> return array of file names 33 | static getPublicKeysFilenamesFromFiles(files) { 34 | return Helpers.filterFilesByRegExp(files, "^-----BEGIN.* PUBLIC KEY-----") 35 | } 36 | 37 | // filter files for ec param files -> return array of file names 38 | static getEllipticCurvesParamsFilenamesFromFiles(files) { 39 | return Helpers.filterFilesByRegExp(files, "^-----BEGIN EC PARAMETERS-----") 40 | } 41 | 42 | // check if some key seems to be encrypted -> return boolean 43 | static isKeyEncrypted(keyfile) { // keyfile => type object 44 | console.log("keyfile", keyfile) 45 | return Helpers.filterFilesByRegExp([keyfile], "ENCRYPTED").length > 0 46 | } 47 | 48 | } 49 | 50 | export default Helpers 51 | -------------------------------------------------------------------------------- /sources/openssl-gui/OpenSSL_GUI.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import { Trans } from "react-i18next" 3 | 4 | import Badge from "react-bootstrap/Badge" 5 | import Card from "react-bootstrap/Card" 6 | import Nav from "react-bootstrap/Nav" 7 | import Tab from "react-bootstrap/Tab" 8 | 9 | import EncryptionTab from "./tabs/EncryptionTab" 10 | import FilesTab from "./tabs/FilesTab" 11 | import GenKeysTab from "./tabs/GenKeysTab" 12 | import SignVerifyTab from "./tabs/SignVerifyTab" 13 | import HashesTab from "./tabs/HashesTab" 14 | import WelcomeTabContent from "./tabs/WelcomeTab" 15 | 16 | class OpenSSLGUI extends React.Component { 17 | 18 | state = { filesdirty: false } 19 | 20 | shouldComponentUpdate(nextProps, nextState) { 21 | 22 | // checks if files have changed 23 | 24 | const prevPropsFileList = this.props.files.map(file => file.name) 25 | const nextPropsFileList = nextProps.files.map(file => file.name) 26 | 27 | const combinedFileList = prevPropsFileList.concat(nextPropsFileList 28 | .filter(file => prevPropsFileList.indexOf(file) < 0)) 29 | 30 | for(const filename of combinedFileList) { 31 | 32 | if(!prevPropsFileList.includes(filename)) { 33 | console.log("file " + filename + " was newly created") 34 | nextState.filesdirty = true 35 | break 36 | } 37 | 38 | else if(!nextPropsFileList.includes(filename)) { 39 | console.log("file " + filename + " was deleted") 40 | nextState.filesdirty = true 41 | break 42 | } 43 | 44 | else { 45 | const prevFile = this.props.files.find(file => file.name == filename) 46 | const nextFile = nextProps.files.find(file => file.name == filename) 47 | 48 | if(prevFile.bytes.length != nextFile.bytes.length) { 49 | console.log("contents of " + filename + " have changed") 50 | nextState.filesdirty = true 51 | break 52 | } 53 | } 54 | } 55 | 56 | // todo: show in files tab which files have changed? 57 | 58 | return true // update anyway 59 | } 60 | 61 | render() { 62 | 63 | return ( 64 | this.onTabSelect(ek)}> 65 | 66 | 67 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | ) 121 | 122 | } 123 | 124 | onTabSelect(eventKey) { 125 | if(eventKey == "files") this.setState({ filesdirty: false }) 126 | } 127 | 128 | } 129 | 130 | export default OpenSSLGUI 131 | -------------------------------------------------------------------------------- /sources/openssl-gui/tabs/EncryptionTab.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | 3 | import { Trans } from "react-i18next" 4 | import i18next from "../../translations" 5 | 6 | import Button from "react-bootstrap/Button" 7 | import Col from "react-bootstrap/Col" 8 | import Form from "react-bootstrap/Form" 9 | import Row from "react-bootstrap/Row" 10 | 11 | import CommandField from "../CommandField" 12 | import Helpers from "../Helpers" 13 | 14 | class EncryptionTab extends React.Component { 15 | 16 | // should get props: files, cipherList, runCommand 17 | 18 | constructor(props) { 19 | super(props) 20 | 21 | this.state = { 22 | 23 | /* default values */ 24 | mode: "encrypt", 25 | inputtype: "text", 26 | inputtext: i18next.t("Hello world"), 27 | method: "cipher", 28 | cipher: "aes-256-cbc", 29 | passphrasetype: "text", 30 | outputfile: "encrypted.data", 31 | pbkdf2: "true", 32 | salt: "true", 33 | base64: "true" 34 | 35 | } 36 | 37 | // save initial state for reset (copy - no reference) 38 | this._initialState = JSON.parse(JSON.stringify(this.state)) 39 | } 40 | 41 | render() { 42 | 43 | // filter files for private or public keys 44 | const keyfiles = (this.state.mode == "encrypt") 45 | ? Helpers.getPublicKeysFilenamesFromFiles(this.props.files) 46 | : Helpers.getPrivateKeysFilenamesFromFiles(this.props.files) 47 | 48 | // check if last selected key file is still available 49 | if(this.state.key != 0 && !keyfiles.includes(this.state.key)) 50 | this.state.key = undefined 51 | 52 | // set default key file (on files update) 53 | if(this.state.key == undefined && keyfiles.length > 0) 54 | this.state.key = keyfiles[0] 55 | 56 | // check if selected private key is encrypted 57 | if(this.state.method == "key" && this.state.mode == "decrypt" && this.state.key != "") { 58 | let privateKey = this.props.files.find(file => file.name == this.state.key) 59 | this.isPrivateKeyEncrypted = privateKey ? Helpers.isKeyEncrypted(privateKey) : undefined 60 | } else this.isPrivateKeyEncrypted = undefined 61 | 62 | // validate fields and build command 63 | const whatsValid = this._validateFields() 64 | const command = this._buildCommand(whatsValid) 65 | 66 | return
e.preventDefault()}> 67 | 68 | 69 | 70 | 74 | 75 | 76 | 77 | Mode: 78 | this.onChange(e)} id="encdec-mode-encrypt" 80 | checked={this.state.mode == "encrypt"} /> 81 | this.onChange(e)} id="encdec-mode-decrypt" 83 | checked={this.state.mode == "decrypt"} /> 84 | 85 | 86 | 87 | 88 |
89 | 90 | 91 | 92 | 93 | Input: 94 | this.onChange(e)} id="encdec-inputtype-text" 96 | checked={this.state.inputtype == "text"} /> 97 | this.onChange(e)} id="encdec-inputtype-file" 99 | checked={this.state.inputtype == "file"} /> 100 | 101 | 102 | {this.state.inputtype == "text" && 103 | this.onChange(e)} isValid={whatsValid.inputtext} 105 | isInvalid={this._isInvalid(whatsValid.inputtext)} rows={3} />} 106 | 107 | {this.state.inputtype == "file" && 108 | this.onChange(e)} 109 | isInvalid={this._isInvalid(whatsValid.inputfile)} isValid={whatsValid.inputfile}> 110 | 111 | {this.props.files.map(file => )} 112 | } 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | Method: 122 | this.onChange(e)} id="encdec-method-cipher" 124 | checked={this.state.method == "cipher"} /> 125 | this.onChange(e)} id="encdec-method-key" 127 | checked={this.state.method == "key"} /> 128 | 129 | 130 | {this.state.method == "cipher" && 131 | this.onChange(e)} 132 | isInvalid={this._isInvalid(whatsValid.cipher)} isValid={whatsValid.cipher}> 133 | {this.props.cipherList.map(cipher => )} 134 | } 135 | 136 | {this.state.method == "key" && 137 | this.onChange(e)} 138 | isInvalid={this._isInvalid(whatsValid.key)} isValid={whatsValid.key}> 139 | 140 | {keyfiles.map(keyfile => )} 141 | } 142 | 143 | 144 | 145 | 146 | 147 | 148 | 150 | 151 | {i18next.t("Passphrase" )}: 152 | this.onChange(e)} id="encdec-passphrasetype-text" 154 | disabled={(this.state.method == "key" && this.state.mode == "encrypt") || (this.state.method == "key" && this.state.mode == "decrypt" && !this.isPrivateKeyEncrypted)} 155 | checked={this.state.passphrasetype == "text"} /> 156 | this.onChange(e)} id="encdec-passphrasetype-file" 158 | disabled={(this.state.method == "key" && this.state.mode == "encrypt") || (this.state.method == "key" && this.state.mode == "decrypt" && !this.isPrivateKeyEncrypted)} 159 | checked={this.state.passphrasetype == "file"} /> 160 | 161 | 162 | {this.state.passphrasetype == "text" && 163 | 0 ? i18next.t("Private key not encrypted") : i18next.t("No private key selected") ) : i18next.t("Enter passphrase ..") )} 164 | value={(this.state.method == "key" && this.state.mode == "encrypt") ? "" : (this.state.passphrasetext || "")} 165 | name="passphrasetext" onChange={e => this.onChange(e)} disabled={(this.state.method == "key" && this.state.mode == "encrypt") || (this.state.method == "key" && this.state.mode == "decrypt" && !this.isPrivateKeyEncrypted)} 166 | isInvalid={this._isInvalid(whatsValid.passphrasetext)} isValid={whatsValid.passphrasetext} />} 167 | 168 | {this.state.passphrasetype == "file" && 169 | this.onChange(e)} 171 | isInvalid={this._isInvalid(whatsValid.passphrasefile)} isValid={whatsValid.passphrasefile} 172 | disabled={(this.state.method == "key" && this.state.mode == "encrypt") || (this.state.method == "key" && this.state.mode == "decrypt" && !this.isPrivateKeyEncrypted)}> 173 | 174 | {this.props.files.map(file => )} 175 | } 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | this.onChange(e)} checked={this.state.useoutputfile == "true"} /> 188 | 189 | this.onChange(e)} disabled={this.state.useoutputfile != "true"} 191 | isInvalid={this._isInvalid(whatsValid.outputfile)} isValid={whatsValid.outputfile} /> 192 | 193 | 194 | 195 | 196 | Options: 197 | 198 | this.onChange(e)} checked={(this.state.method == "key") ? false : this.state.pbkdf2 == "true"} 201 | disabled={this.state.method == "key"} /> 202 | this.onChange(e)} checked={(this.state.method == "key") ? false : this.state.salt == "true"} 205 | disabled={this.state.method == "key"} /> 206 | this.onChange(e)} checked={(this.state.method == "key") ? false : this.state.base64 == "true"} 209 | disabled={this.state.method == "key"} /> 210 | 211 | 212 | 213 |
214 | 216 | 217 | 218 | } 219 | 220 | 221 | onChange(e) { 222 | let fields = { ...this.state, [e.target.name]: e.target.value } 223 | 224 | // special case: replace output filename on mode change (for unchanged values) 225 | if(e.target.name == "mode") { 226 | const encryptOriginalValue = this._initialState.outputfile.replace("decrypt", "encrypt") 227 | const decryptOriginalValue = this._initialState.outputfile.replace("encrypt", "decrypt") 228 | if(fields.outputfile == encryptOriginalValue) fields.outputfile = decryptOriginalValue 229 | else if(fields.outputfile == decryptOriginalValue) fields.outputfile = encryptOriginalValue 230 | } 231 | 232 | this.setState(fields) 233 | } 234 | 235 | _validateFields() { 236 | 237 | let whatsValid = {} 238 | 239 | // check if input text is valid 240 | if(this.state.inputtype == "text") 241 | whatsValid.inputtext = !(!this.state.inputtext) 242 | 243 | // check if input file is valid 244 | if(this.state.inputtype == "file") 245 | whatsValid.inputfile = !(!this.state.inputfile) 246 | 247 | // check if cipher was selected 248 | if(this.state.method == "cipher") 249 | whatsValid.cipher = this.props.cipherList.includes(this.state.cipher) 250 | 251 | // check if key was selected 252 | if(this.state.method == "key") 253 | whatsValid.key = !(!this.state.key) 254 | 255 | // only use passphrase for ciphers and decryption with encrypted private keys 256 | if(this.state.method == "cipher" || (this.state.mode == "decrypt" && this.isPrivateKeyEncrypted)) { 257 | 258 | // check if passphrase text is valid 259 | if(this.state.passphrasetype == "text") 260 | whatsValid.passphrasetext = !(!this.state.passphrasetext) 261 | 262 | // check if passphrase file is valid 263 | if(this.state.passphrasetype == "file") 264 | whatsValid.passphrasefile = !(!this.state.passphrasefile) 265 | 266 | } 267 | 268 | // check if output file is valid 269 | if(this.state.useoutputfile == "true") 270 | whatsValid.outputfile = !(!(this.state.outputfile || "").trim()) 271 | 272 | return whatsValid 273 | 274 | } 275 | 276 | _buildCommand(whatsValid = {}) { 277 | 278 | if(Object.values(whatsValid).includes(false)) return i18next.t("Please fill in all fields") 279 | 280 | let command = "openssl" 281 | 282 | if(this.state.method == "cipher") { 283 | command += " enc -" + this.state.cipher 284 | if(this.state.mode == "encrypt") command += " -e" 285 | if(this.state.mode == "decrypt") command += " -d" 286 | } 287 | 288 | if(this.state.method == "key") { 289 | command += " pkeyutl" 290 | 291 | if(this.state.mode == "encrypt") { 292 | command += " --encrypt" 293 | command += " -pubin -inkey " + this.state.key 294 | } 295 | 296 | if(this.state.mode == "decrypt") { 297 | command += " --decrypt" 298 | command += " -inkey " + this.state.key 299 | 300 | if(this.isPrivateKeyEncrypted) { 301 | 302 | if(this.state.passphrasetype == "text") 303 | command += " -passin pass:" + this.state.passphrasetext 304 | 305 | if(this.state.passphrasetype == "file") 306 | command += " -passin file:" + this.state.passphrasefile 307 | } 308 | } 309 | } 310 | 311 | if(this.state.inputtype == "text") 312 | command = "echo " + this.state.inputtext + " | " + command 313 | 314 | if(this.state.inputtype == "file") 315 | command += " -in " + this.state.inputfile 316 | 317 | if(this.state.method == "cipher") { 318 | 319 | if(this.state.passphrasetype == "text") 320 | command += " -k " + this.state.passphrasetext 321 | 322 | if(this.state.passphrasetype == "file") 323 | command += " -kfile " + this.state.passphrasefile 324 | 325 | if(this.state.pbkdf2 == "true") 326 | command += " -pbkdf2" 327 | 328 | if(this.state.salt != "true") 329 | command += " -nosalt" 330 | 331 | if(this.state.base64 == "true") 332 | command += " -a" 333 | 334 | } 335 | 336 | if(this.state.useoutputfile == "true") 337 | command += " -out " + this.state.outputfile 338 | 339 | return command 340 | 341 | } 342 | 343 | _resetFields() { 344 | // overwrite current state with initial state (including undefined) 345 | this.setState(prevState => Object.fromEntries(Object.entries(prevState) 346 | .map(([key, value]) => [key, this._initialState[key]]))) 347 | } 348 | 349 | _isInvalid(value) { 350 | // make undefined not mean false 351 | if(value == undefined) return undefined 352 | else return !value 353 | } 354 | 355 | } 356 | 357 | export default EncryptionTab 358 | -------------------------------------------------------------------------------- /sources/openssl-gui/tabs/FilesTab.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | 3 | import { Trans } from "react-i18next" 4 | import i18next from "../../translations" 5 | 6 | import Table from "react-bootstrap/Table" 7 | import ButtonGroup from "react-bootstrap/ButtonGroup" 8 | import Button from "react-bootstrap/Button" 9 | import Form from "react-bootstrap/Form" 10 | import InputGroup from "react-bootstrap/InputGroup" 11 | 12 | class FilesTab extends React.Component { 13 | 14 | // should get props: files, setFiles 15 | 16 | render() { 17 | 18 | return <> 19 | 20 |
this.onFileSelect(e)}> 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | {this.props.files.map(file => { 40 | 41 | return 42 | 43 | 44 | 45 | 57 | 58 | 59 | })} 60 | {this.props.files.length == 0 && } 61 | 62 |
FilenameLast modifiedFile sizeActions
{file.name}{(new Date(file.timestamp)).toUTCString()}{this._formatBytes(file.bytes.byteLength)} 46 | 47 | 51 | 55 | 56 |
----
63 | 64 | 65 | 66 | } 67 | 68 | onFileSelect(event) { 69 | event.preventDefault() 70 | console.log("selected file from pc:", event.target.files[0]) 71 | Array.from(event.target.files).forEach(file => { 72 | file.arrayBuffer().then(buffer => { 73 | const bytes = new Uint8Array(buffer) 74 | this.props.setFiles([...this.props.files, { 75 | name: file.name, 76 | timestamp: file.lastModified, 77 | bytes: bytes 78 | }]) 79 | }) 80 | }) 81 | } 82 | 83 | downloadFile(filename) { 84 | let file = this.props.files.find(file => file.name == filename) 85 | if(filename[0] == "/") filename = filename.substring(1) 86 | file = new File([file.bytes], file.name, { 87 | type: "application/octet-stream" 88 | }) 89 | let url = window.URL.createObjectURL(file) 90 | let a = document.createElement("a") 91 | a.href = url 92 | a.download = filename 93 | a.click() 94 | window.URL.revokeObjectURL(url) 95 | } 96 | 97 | deleteFile(filename) { 98 | this.props.setFiles(this.props.files.filter(file => file.name != filename)) 99 | } 100 | 101 | _formatBytes(bytes, decimals = 2) { 102 | if(bytes == 0) return "0 Bytes" 103 | const k = 1000 // alternative: 1024 104 | const dm = decimals < 0 ? 0 : decimals 105 | const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] 106 | const i = Math.floor(Math.log(bytes) / Math.log(k)) 107 | return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i] 108 | } 109 | 110 | } 111 | 112 | export default FilesTab 113 | -------------------------------------------------------------------------------- /sources/openssl-gui/tabs/GenKeysTab.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | 3 | import { Trans } from "react-i18next" 4 | import i18next from "../../translations" 5 | 6 | import Button from "react-bootstrap/Button" 7 | import Card from "react-bootstrap/Card" 8 | import Col from "react-bootstrap/Col" 9 | import Form from "react-bootstrap/Form" 10 | import Row from "react-bootstrap/Row" 11 | 12 | import CommandField from "../CommandField" 13 | import Helpers from "../Helpers" 14 | 15 | class GenKeysTab extends React.Component { 16 | 17 | // should get props: files, cipherList, curvesList, runCommand 18 | 19 | constructor(props) { 20 | super(props) 21 | 22 | // define static form values 23 | this._numbits = [1024, 2048, 4096] // available key lenghts 24 | this._keyFormats = ["PEM", "DER"] // available key formats 25 | 26 | this.state = { 27 | 28 | /* default values */ 29 | 30 | keytype: "rsa", 31 | 32 | privkeyFields: { 33 | outputfile: "privkey." + this._keyFormats[0].toLowerCase(), 34 | keylength: this._numbits[0], 35 | elcurvename: "prime256v1", // this.props.curvesList[0]?.name 36 | passphrasetype: "text", 37 | cipher: "aes-256-cbc" 38 | }, 39 | 40 | pubkeyFields: { 41 | outputfile: "pubkey." + this._keyFormats[0].toLowerCase(), 42 | passphrasetype: "text", 43 | keyformat: this._keyFormats[0] 44 | } 45 | 46 | } 47 | 48 | // save initial state for reset (copy - no reference) 49 | this._initialState = JSON.parse(JSON.stringify(this.state)) 50 | } 51 | 52 | render() { 53 | 54 | // filter files for needed private key format 55 | this.privateKeys = (this.state.keytype == "ec") 56 | ? Helpers.getEllipticCurvesParamsFilenamesFromFiles(this.props.files) 57 | : Helpers.getPrivateKeysFilenamesFromFiles(this.props.files) 58 | 59 | // check if last selected file (inputprivkey) is still available 60 | if(this.state.pubkeyFields.inputprivkey != "" // "" means "Select file" 61 | && !this.privateKeys.includes(this.state.pubkeyFields.inputprivkey)) 62 | this.state.pubkeyFields.inputprivkey = undefined 63 | 64 | // set default pubkey input privkey file (on files update) 65 | if(this.state.pubkeyFields.inputprivkey == undefined && this.privateKeys.length > 0) 66 | this.state.pubkeyFields.inputprivkey = this.privateKeys[0] 67 | 68 | // todo: maybe make the upper more general? -> update all file selects 69 | // note: will also be used in EncryptionTab.js 70 | 71 | // check if selected inputprivkey (for pubkey derivation) is encrypted 72 | if(this.state.pubkeyFields.inputprivkey != "") { 73 | let inputprivkeyFile = this.props.files.find(file => file.name == this.state.pubkeyFields.inputprivkey) 74 | this.isInputprivkeyEncrypted = inputprivkeyFile ? Helpers.isKeyEncrypted(inputprivkeyFile) : undefined 75 | } else this.isInputprivkeyEncrypted = undefined 76 | 77 | // validate fields and build command for privkey 78 | const whatsValidPriv = this._validatePrivkeyFields() 79 | const privkeyCommand = this._buildPrivkeyCommand(whatsValidPriv) 80 | 81 | // validate fields and build command for pubkey 82 | const whatsValidPub = this._validatePubkeyFields() 83 | const pubkeyCommand = this._buildPubkeyCommand(whatsValidPub) 84 | 85 | return <> 86 | 87 | 88 | Key type: 89 | this.onChange(e)} id="genkey-keytype-rsa" 91 | checked={this.state.keytype == "rsa"} /> 92 | this.onChange(e)} 94 | checked={this.state.keytype == "ec"} id="genkey-keytype-ec" /> 95 | 96 | 97 |
e.preventDefault()}> 98 | 99 | 100 | 101 | 1) {this.state.keytype != "ec" ? i18next.t("Generate private key") : i18next.t("Generate parameters")} 102 | 105 | 106 | 107 | 108 | 109 | 110 | {this.state.keytype == "rsa" && 111 | 112 | Key length 113 | this._onPrivkeyFieldChange(e)} 115 | isValid={whatsValidPriv.keylength} isInvalid={this._isInvalid(whatsValidPriv.keylength)}> 116 | {this._numbits.map(numbit => )} 117 | 118 | } 119 | 120 | {this.state.keytype == "ec" && 121 | 122 | Elliptic curve name 123 | this._onPrivkeyFieldChange(e)} 125 | isValid={whatsValidPriv.elcurvename} isInvalid={this._isInvalid(whatsValidPriv.elcurvename)}> 126 | {this.props.curvesList.map(curve => 127 | )} 128 | 129 | } 130 | 131 | 132 | 133 | this._onPrivkeyFieldChange(e)} checked={this.state.privkeyFields.useoutputfile == "true"} /> 136 | 137 | this._onPrivkeyFieldChange(e)} disabled={this.state.privkeyFields.useoutputfile != "true"} 139 | isInvalid={this._isInvalid(whatsValidPriv.outputfile)} isValid={whatsValidPriv.outputfile} /> 140 | 141 | 142 | 143 | {this.state.keytype == "rsa" && 144 | 145 | 146 | 147 | 148 | 149 | this._onPrivkeyFieldChange(e)} checked={this.state.privkeyFields.encrypt == "true"} /> 152 | this._onPrivkeyFieldChange(e)} id="genkey-privkey-passphrasetype-text" 154 | disabled={this.state.privkeyFields.encrypt != "true"} 155 | checked={this.state.privkeyFields.passphrasetype == "text"} /> 156 | this._onPrivkeyFieldChange(e)} id="genkey-privkey-passphrasetype-file" 158 | disabled={this.state.privkeyFields.encrypt != "true"} 159 | checked={this.state.privkeyFields.passphrasetype == "file"} /> 160 | 161 | 162 | {this.state.privkeyFields.passphrasetype == "text" && 163 | this._onPrivkeyFieldChange(e)} disabled={this.state.privkeyFields.encrypt != "true"} 166 | isInvalid={this._isInvalid(whatsValidPriv.passphrasetext)} isValid={whatsValidPriv.passphrasetext} />} 167 | 168 | {this.state.privkeyFields.passphrasetype == "file" && 169 | this._onPrivkeyFieldChange(e)} disabled={this.state.privkeyFields.encrypt != "true"} 171 | isInvalid={this._isInvalid(whatsValidPriv.passphrasefile)} isValid={whatsValidPriv.passphrasefile} > 172 | 173 | {this.props.files.map(file => )} 174 | } 175 | 176 | 177 | 178 | 179 | Cipher (for encryption) 180 | this._onPrivkeyFieldChange(e)} disabled={this.state.privkeyFields.encrypt != "true"} 182 | isInvalid={this._isInvalid(whatsValidPriv.cipher)} isValid={whatsValidPriv.cipher}> 183 | 184 | {this.props.cipherList.map(cipher => )} 185 | 186 | 187 | 188 | } 189 | 190 | 191 | 192 |
193 | 195 | 196 |
197 |
198 | 199 |
200 |
e.preventDefault()}> 201 | 202 | 203 | 204 | 2) Derive public key 205 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | {this.state.keytype != "ec" ? "Private key" : "EC params"} input file 215 | this._onPubkeyFieldChange(e)} 217 | isValid={whatsValidPub.inputprivkey} isInvalid={this._isInvalid(whatsValidPub.inputprivkey)}> 218 | 219 | {this.privateKeys.map(privkey => )} 220 | 221 | 222 | 223 | 224 | {this.state.keytype == "rsa" && 225 | 226 | 227 | 228 | 229 | 230 | Decrypt private key: 231 | this._onPubkeyFieldChange(e)} id="genkey-pubkey-passphrasetype-text" 233 | disabled={!this.isInputprivkeyEncrypted} checked={this.state.pubkeyFields.passphrasetype == "text"} /> 234 | this._onPubkeyFieldChange(e)} id="genkey-pubkey-passphrasetype-file" 236 | disabled={!this.isInputprivkeyEncrypted} checked={this.state.pubkeyFields.passphrasetype == "file"} /> 237 | 238 | 239 | {this.state.pubkeyFields.passphrasetype == "text" && 240 | 0 ? i18next.t("Private key not encrypted") : i18next.t("No private key selected") )} 241 | name="passphrasetext" value={(this.isInputprivkeyEncrypted) ? (this.state.pubkeyFields.passphrasetext || "") : ""} 242 | onChange={e => this._onPubkeyFieldChange(e)} disabled={!this.isInputprivkeyEncrypted} 243 | isInvalid={this._isInvalid(whatsValidPub.passphrasetext)} isValid={whatsValidPub.passphrasetext} />} 244 | 245 | {this.state.pubkeyFields.passphrasetype == "file" && 246 | this._onPubkeyFieldChange(e)} disabled={!this.isInputprivkeyEncrypted} 248 | isInvalid={this._isInvalid(whatsValidPub.passphrasefile)} isValid={whatsValidPub.passphrasefile} > 249 | 250 | {this.props.files.map(file => )} 251 | } 252 | 253 | 254 | 255 | } 256 | 257 | 258 | 259 | 260 | this._onPubkeyFieldChange(e)} checked={this.state.pubkeyFields.useoutputfile == "true"} /> 263 | 264 | this._onPubkeyFieldChange(e)} disabled={this.state.pubkeyFields.useoutputfile != "true"} 266 | isInvalid={this._isInvalid(whatsValidPub.outputfile)} isValid={whatsValidPub.outputfile} /> 267 | 268 | 269 | 270 | 271 | 272 | Public key output format 273 | this._onPubkeyFieldChange(e)} 275 | isValid={whatsValidPub.keyformat} isInvalid={this._isInvalid(whatsValidPub.keyformat)}> 276 | {this._keyFormats.map(format => )} 277 | 278 | 279 | 280 | 281 | 282 | 283 |
284 | 286 | 287 |
288 |
289 | 290 |
291 | 292 | 293 | 294 | } 295 | 296 | onChange(e) { 297 | // special case: reset pubkey field "inputprivkey" on keytype change 298 | if(e.target.name == "keytype") this.state.pubkeyFields.inputprivkey 299 | = this._initialState.pubkeyFields.inputprivkey // todo: maybe copy not reference? 300 | 301 | this.setState({ [e.target.name]: e.target.value }) 302 | } 303 | 304 | 305 | /* private key fields handling */ 306 | 307 | _onPrivkeyFieldChange(e) { 308 | this.setState({ privkeyFields: { ...this.state.privkeyFields, 309 | [e.target.name]: e.target.value } }) 310 | } 311 | 312 | _validatePrivkeyFields() { 313 | 314 | let whatsValid = {} 315 | 316 | // check if output filename is valid 317 | if(this.state.privkeyFields.useoutputfile == "true") 318 | whatsValid.outputfile = !(!(this.state.privkeyFields.outputfile || "").trim()) 319 | 320 | if(this.state.keytype == "rsa") { 321 | 322 | // check if key length is valid 323 | whatsValid.keylength = this._numbits.includes(parseInt(this.state.privkeyFields.keylength)) 324 | 325 | if(this.state.privkeyFields.encrypt == "true") { 326 | 327 | // check if passphrase text is valid 328 | if(this.state.privkeyFields.passphrasetype == "text") 329 | whatsValid.passphrasetext = !(!this.state.privkeyFields.passphrasetext) 330 | 331 | // check if passphrase file is valid 332 | if(this.state.privkeyFields.passphrasetype == "file") 333 | whatsValid.passphrasefile = !(!this.state.privkeyFields.passphrasefile) 334 | 335 | // check if cipher is valid 336 | whatsValid.cipher = this.props.cipherList.includes(this.state.privkeyFields.cipher) 337 | 338 | } 339 | 340 | } 341 | 342 | if(this.state.keytype == "ec") { 343 | 344 | // check if elliptic curve is valid 345 | whatsValid.elcurvename = !(!(this.state.privkeyFields.elcurvename || "").trim()) 346 | 347 | } 348 | 349 | return whatsValid 350 | 351 | } 352 | 353 | _buildPrivkeyCommand(whatsValid = {}) { 354 | 355 | if(Object.values(whatsValid).includes(false)) return i18next.t("Please fill in all fields") 356 | 357 | let command = "openssl" 358 | 359 | if(this.state.keytype == "rsa") { 360 | 361 | command += " genrsa" 362 | 363 | // todo: replace special chars or add quotation marks to parameters 364 | // otherwise spaces or special characters might break the command 365 | 366 | if(this.state.privkeyFields.encrypt == "true") { 367 | command += " -" + this.state.privkeyFields.cipher 368 | 369 | if(this.state.privkeyFields.passphrasetype == "text") 370 | command += " -passout pass:" + this.state.privkeyFields.passphrasetext 371 | 372 | if(this.state.privkeyFields.passphrasetype == "file") 373 | command += " -passout file:" + this.state.privkeyFields.passphrasefile 374 | } 375 | 376 | if(this.state.privkeyFields.useoutputfile == "true") 377 | command += " -out " + this.state.privkeyFields.outputfile 378 | 379 | command += " " + this.state.privkeyFields.keylength 380 | 381 | } 382 | 383 | if(this.state.keytype == "ec") { 384 | command += " ecparam -genkey" 385 | command += " -name " + this.state.privkeyFields.elcurvename 386 | 387 | if(this.state.privkeyFields.useoutputfile == "true") 388 | command += " -out " + this.state.privkeyFields.outputfile 389 | } 390 | 391 | return command 392 | 393 | } 394 | 395 | _resetPrivkeyFields() { 396 | this.setState({ privkeyFields: this._initialState.privkeyFields }) 397 | } 398 | 399 | 400 | /* public key fields handling */ 401 | 402 | _onPubkeyFieldChange(e) { 403 | let pubkeyFields = { ...this.state.pubkeyFields, 404 | [e.target.name]: e.target.value } 405 | 406 | // special case: replace extension in outputfile on keyformat change 407 | if(e.target.name == "keyformat") pubkeyFields.outputfile = pubkeyFields.outputfile 408 | .replace(new RegExp("\\.(" + this.state.pubkeyFields.keyformat.toLowerCase() + ")$"), 409 | "." + e.target.value.toLowerCase()) 410 | 411 | this.setState({ pubkeyFields: pubkeyFields }) 412 | } 413 | 414 | _validatePubkeyFields() { 415 | 416 | let whatsValid = {} 417 | 418 | // check if input privkey is valid 419 | whatsValid.inputprivkey = this.privateKeys.includes(this.state.pubkeyFields.inputprivkey) 420 | 421 | if(this.isInputprivkeyEncrypted) { 422 | 423 | // check if passphrase text is valid 424 | if(this.state.pubkeyFields.passphrasetype == "text") 425 | whatsValid.passphrasetext = !(!this.state.pubkeyFields.passphrasetext) 426 | 427 | // check if passphrase file is valid 428 | if(this.state.pubkeyFields.passphrasetype == "file") 429 | whatsValid.passphrasefile = !(!this.state.pubkeyFields.passphrasefile) 430 | 431 | } 432 | 433 | // check if output filename is valid 434 | if(this.state.pubkeyFields.useoutputfile == "true") 435 | whatsValid.outputfile = !(!(this.state.pubkeyFields.outputfile || "").trim()) 436 | 437 | // check if output key format is valid 438 | whatsValid.keyformat = this._keyFormats.includes(this.state.pubkeyFields.keyformat) 439 | 440 | return whatsValid 441 | 442 | } 443 | 444 | _buildPubkeyCommand(whatsValid = {}) { 445 | 446 | if(Object.values(whatsValid).includes(false)) return i18next.t("Please fill in all fields") 447 | 448 | let command = "openssl" 449 | 450 | if(this.state.keytype == "rsa") { 451 | command += " rsa -pubout" 452 | command += " -in " + this.state.pubkeyFields.inputprivkey 453 | 454 | if(this.isInputprivkeyEncrypted) { 455 | 456 | if(this.state.pubkeyFields.passphrasetype == "text") 457 | command += " -passin pass:" + this.state.pubkeyFields.passphrasetext 458 | 459 | if(this.state.pubkeyFields.passphrasetype == "file") 460 | command += " -passin file:" + this.state.pubkeyFields.passphrasefile 461 | } 462 | 463 | command += " -outform " + this.state.pubkeyFields.keyformat 464 | if(this.state.pubkeyFields.useoutputfile == "true") 465 | command += " -out " + this.state.pubkeyFields.outputfile 466 | } 467 | 468 | if(this.state.keytype == "ec") { 469 | command += " ec -pubout" 470 | command += " -in " + this.state.pubkeyFields.inputprivkey 471 | command += " -outform " + this.state.pubkeyFields.keyformat 472 | 473 | if(this.state.pubkeyFields.useoutputfile == "true") 474 | command += " -out " + this.state.pubkeyFields.outputfile 475 | } 476 | 477 | return command 478 | 479 | } 480 | 481 | _resetPubkeyFields() { 482 | this.setState({ pubkeyFields: this._initialState.pubkeyFields }) 483 | } 484 | 485 | 486 | /* helper functions */ 487 | 488 | _isInvalid(value) { 489 | // make undefined not mean false 490 | if(value == undefined) return undefined 491 | else return !value 492 | } 493 | 494 | /* _replaceSpecialChars(string) { 495 | 496 | // todo: replace special chars in file name 497 | const specialChars = ["|", "&", ";", "<", ">", "(", ")", "$", "`", "\\", "\"", "'", " ", "\t", "\n"] 498 | let cleanedValue = "" 499 | e.target.value.split("").forEach(char => { 500 | if(specialChars.includes(char)) char += "\\" 501 | cleanedValue += char 502 | }) 503 | 504 | return string 505 | } */ 506 | 507 | } 508 | 509 | export default GenKeysTab 510 | -------------------------------------------------------------------------------- /sources/openssl-gui/tabs/HashesTab.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | 3 | import { Trans } from "react-i18next" 4 | import i18next from "../../translations" 5 | 6 | import Col from "react-bootstrap/Col" 7 | import Form from "react-bootstrap/Form" 8 | import Row from "react-bootstrap/Row" 9 | 10 | import CommandField from "../CommandField" 11 | 12 | class HashesTab extends React.Component { 13 | 14 | // should get props: files, hashfunList, runCommand 15 | 16 | constructor(props) { 17 | super(props) 18 | 19 | this.state = { 20 | 21 | /* default values */ 22 | inputtype: "text", 23 | inputtext: i18next.t("Hello world"), 24 | hashfun: "sha256", 25 | outputfile: "hashed.data" 26 | 27 | } 28 | 29 | // save initial state for reset (copy - no reference) 30 | this._initialState = JSON.parse(JSON.stringify(this.state)) 31 | } 32 | 33 | render() { 34 | 35 | // validate fields and build command 36 | const whatsValid = this._validateFields() 37 | const command = this._buildCommand(whatsValid) 38 | 39 | return
e.preventDefault()}> 40 | 41 | 42 | 43 | 44 | Input: 45 | this.onChange(e)} id="hashes-inputtype-text" 47 | checked={this.state.inputtype == "text"} /> 48 | this.onChange(e)} id="hashes-inputtype-file" 50 | checked={this.state.inputtype == "file"} /> 51 | 52 | 53 | {this.state.inputtype == "text" && 54 | this.onChange(e)} isValid={whatsValid.inputtext} 56 | isInvalid={this._isInvalid(whatsValid.inputtext)} rows={3} />} 57 | 58 | {this.state.inputtype == "file" && 59 | this.onChange(e)} 60 | isInvalid={this._isInvalid(whatsValid.inputfile)} isValid={whatsValid.inputfile}> 61 | 62 | {this.props.files.map(file => )} 63 | } 64 | 65 | 66 | 67 | 68 | 69 | 70 | Hash function 71 | this.onChange(e)} 72 | isInvalid={this._isInvalid(whatsValid.hashfun)} isValid={whatsValid.hashfun}> 73 | {this.props.hashfunList.map(hashfun => )} 74 | 75 | 76 | 77 | 78 | 79 | 80 | this.onChange(e)} checked={this.state.useoutputfile == "true"} /> 83 | 84 | this.onChange(e)} disabled={this.state.useoutputfile != "true"} 86 | isInvalid={this._isInvalid(whatsValid.outputfile)} isValid={whatsValid.outputfile} /> 87 | 88 | 89 | 90 | 91 |
92 | 94 | 95 | 96 | } 97 | 98 | 99 | onChange(e) { 100 | this.setState({ [e.target.name]: e.target.value }) 101 | } 102 | 103 | _validateFields() { 104 | 105 | let whatsValid = {} 106 | 107 | // check if input text is valid 108 | if(this.state.inputtype == "text") { 109 | whatsValid.inputtext = !(!this.state.inputtext) 110 | } else whatsValid.inputtext = undefined 111 | 112 | // check if input file is valid 113 | if(this.state.inputtype == "file") { 114 | whatsValid.inputfile = !(!this.state.inputfile) 115 | } else whatsValid.inputfile = undefined 116 | 117 | // check if hash fun was selected 118 | whatsValid.hashfun = !(!this.state.hashfun) 119 | 120 | // check if output file is valid 121 | if(this.state.useoutputfile == "true") { 122 | whatsValid.outputfile = !(!(this.state.outputfile || "").trim()) 123 | } else whatsValid.outputfile = undefined 124 | 125 | return whatsValid 126 | 127 | } 128 | 129 | _buildCommand(whatsValid = {}) { 130 | 131 | if(Object.values(whatsValid).includes(false)) return i18next.t("Please fill in all fields") 132 | 133 | let command = "openssl dgst" 134 | 135 | command += " -" + this.state.hashfun 136 | 137 | if(this.state.useoutputfile == "true") 138 | command += " -out " + this.state.outputfile 139 | 140 | if(this.state.inputtype == "text") 141 | command = "echo " + this.state.inputtext + " | " + command 142 | 143 | if(this.state.inputtype == "file") 144 | command += " " + this.state.inputfile 145 | 146 | return command 147 | 148 | } 149 | 150 | 151 | _resetFields() { 152 | // overwrite current state with initial state (including undefined) 153 | this.setState(prevState => Object.fromEntries(Object.entries(prevState) 154 | .map(([key, value]) => [key, this._initialState[key]]))) 155 | } 156 | 157 | _isInvalid(value) { 158 | // make undefined not mean false 159 | if(value == undefined) return undefined 160 | else return !value 161 | } 162 | 163 | } 164 | 165 | export default HashesTab 166 | -------------------------------------------------------------------------------- /sources/openssl-gui/tabs/SignVerifyTab.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | 3 | import { Trans } from "react-i18next" 4 | import i18next from "../../translations" 5 | 6 | import Button from "react-bootstrap/Button" 7 | import Card from "react-bootstrap/Card" 8 | import Col from "react-bootstrap/Col" 9 | import Form from "react-bootstrap/Form" 10 | import Row from "react-bootstrap/Row" 11 | 12 | import CommandField from "../CommandField" 13 | import Helpers from "../Helpers" 14 | 15 | class SignVerifyTab extends React.Component { 16 | 17 | // should get props: files, runCommand 18 | 19 | constructor(props) { 20 | super(props) 21 | 22 | this.state = { 23 | 24 | /* default values */ 25 | 26 | signingFields: { 27 | inputtype: "text", 28 | inputtext: i18next.t("Hello world"), 29 | passphrasetype: "text", 30 | outputfile: "signed.data" 31 | }, 32 | 33 | verifyFields: { 34 | inputtype: "text", 35 | inputtext: i18next.t("Hello world") 36 | } 37 | 38 | } 39 | 40 | // save initial state for reset (copy - no reference) 41 | this._initialState = JSON.parse(JSON.stringify(this.state)) 42 | } 43 | 44 | render() { 45 | 46 | // filter files for private and public keys 47 | this.privateKeys = Helpers.getPrivateKeysFilenamesFromFiles(this.props.files) 48 | this.publicKeys = Helpers.getPublicKeysFilenamesFromFiles(this.props.files) 49 | 50 | // check if last selected privkey is still available 51 | if(this.state.signingFields.privkey != "" // "" means "Select file" 52 | && !this.privateKeys.includes(this.state.signingFields.privkey)) 53 | this.state.signingFields.privkey = undefined 54 | 55 | // check if last selected pubkey is still available 56 | if(this.state.verifyFields.pubkey != "" // "" means "Select file" 57 | && !this.publicKeys.includes(this.state.verifyFields.pubkey)) 58 | this.state.verifyFields.pubkey = undefined 59 | 60 | // check if last selected sigfile is still available 61 | if(this.state.verifyFields.sigfile != "" // "" means "Select file" 62 | && !this.props.files.some(f => f.name == this.state.verifyFields.sigfile)) 63 | this.state.verifyFields.sigfile = undefined 64 | 65 | // set default privkey file (on files update) 66 | if(this.state.signingFields.privkey == undefined && this.privateKeys.length > 0) 67 | this.state.signingFields.privkey = this.privateKeys[0] 68 | 69 | // set default pubkey file (on files update) 70 | if(this.state.verifyFields.pubkey == undefined && this.publicKeys.length > 0) 71 | this.state.verifyFields.pubkey = this.publicKeys[0] 72 | 73 | // check if selected privkey is encrypted 74 | if(this.state.signingFields.privkey != "") { 75 | let privkeyFile = this.props.files.find(file => file.name == this.state.signingFields.privkey) 76 | this.isPrivateKeyEncrypted = privkeyFile ? Helpers.isKeyEncrypted(privkeyFile) : undefined 77 | } else this.isPrivateKeyEncrypted = undefined 78 | 79 | // validate fields and build command for signing 80 | const whatsValidSign = this._validateSigningFields() 81 | const signingCommand = this._buildSigningCommand(whatsValidSign) 82 | 83 | // validate fields and build command for verify 84 | const whatsValidVery = this._validateVerifyFields() 85 | const verifyCommand = this._buildVerifyCommand(whatsValidVery) 86 | 87 | return <> 88 | 89 | 90 | 91 | 1) Sign with private key 92 | 95 | 96 | 97 | 98 |
e.preventDefault()}> 99 | 100 | 101 | 102 | 103 | Input: 104 | this._onSigningFieldChange(e)} id="signing-inputtype-text" 106 | checked={this.state.signingFields.inputtype == "text"} /> 107 | this._onSigningFieldChange(e)} id="signing-inputtype-file" 109 | checked={this.state.signingFields.inputtype == "file"} /> 110 | 111 | 112 | {this.state.signingFields.inputtype == "text" && 113 | this._onSigningFieldChange(e)} isValid={whatsValidSign.inputtext} 115 | isInvalid={this._isInvalid(whatsValidSign.inputtext)} rows={3} />} 116 | 117 | {this.state.signingFields.inputtype == "file" && 118 | this._onSigningFieldChange(e)} 119 | isInvalid={this._isInvalid(whatsValidSign.inputfile)} isValid={whatsValidSign.inputfile}> 120 | 121 | {this.props.files.map(file => )} 122 | } 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | Private key 131 | this._onSigningFieldChange(e)} 133 | isValid={whatsValidSign.privkey} isInvalid={this._isInvalid(whatsValidSign.privkey)}> 134 | 135 | {this.privateKeys.map(privkey => )} 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | Passphrase: 145 | this._onSigningFieldChange(e)} id="signing-passphrasetype-text" 147 | disabled={!this.isPrivateKeyEncrypted} checked={this.state.signingFields.passphrasetype == "text"} /> 148 | this._onSigningFieldChange(e)} id="signing-passphrasetype-file" 150 | disabled={!this.isPrivateKeyEncrypted} checked={this.state.signingFields.passphrasetype == "file"} /> 151 | 152 | 153 | {this.state.signingFields.passphrasetype == "text" && 154 | 0 ? "Private key not encrypted" : "No private key selected" ))} 155 | name="passphrasetext" value={(this.isPrivateKeyEncrypted) ? (this.state.signingFields.passphrasetext || "") : ""} 156 | onChange={e => this._onSigningFieldChange(e)} disabled={!this.isPrivateKeyEncrypted} 157 | isInvalid={this._isInvalid(whatsValidSign.passphrasetext)} isValid={whatsValidSign.passphrasetext} />} 158 | 159 | {this.state.signingFields.passphrasetype == "file" && 160 | this._onSigningFieldChange(e)} disabled={!this.isPrivateKeyEncrypted} 162 | isInvalid={this._isInvalid(whatsValidSign.passphrasefile)} isValid={whatsValidSign.passphrasefile} > 163 | 164 | {this.props.files.map(file => )} 165 | } 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | this._onSigningFieldChange(e)} checked={this.state.signingFields.useoutputfile == "true"} /> 179 | 180 | this._onSigningFieldChange(e)} disabled={this.state.signingFields.useoutputfile != "true"} 182 | isInvalid={this._isInvalid(whatsValidSign.outputfile)} isValid={whatsValidSign.outputfile} /> 183 | 184 | 185 | 186 | 187 | Options: 188 | this._onSigningFieldChange(e)} checked={this.state.base64 == "true"} /> 191 | 192 | 193 | 194 | 195 |
196 | 197 |
198 | 200 | 201 |
202 |
203 | 204 | 205 | 206 | 2) Verify with public key 207 | 210 | 211 | 212 | 213 |
e.preventDefault()}> 214 | 215 | 216 | 217 | 218 | Input: 219 | this._onVerifyFieldChange(e)} id="verify-inputtype-text" 221 | checked={this.state.verifyFields.inputtype == "text"} /> 222 | this._onVerifyFieldChange(e)} id="verify-inputtype-file" 224 | checked={this.state.verifyFields.inputtype == "file"} /> 225 | 226 | 227 | {this.state.verifyFields.inputtype == "text" && 228 | this._onVerifyFieldChange(e)} isValid={whatsValidVery.inputtext} 230 | isInvalid={this._isInvalid(whatsValidVery.inputtext)} rows={3} />} 231 | 232 | {this.state.verifyFields.inputtype == "file" && 233 | this._onVerifyFieldChange(e)} isValid={whatsValidVery.inputfile} 235 | isInvalid={this._isInvalid(whatsValidVery.inputfile)} > 236 | 237 | {this.props.files.map(file => )} 238 | } 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | Public key 247 | this._onVerifyFieldChange(e)} 249 | isValid={whatsValidVery.pubkey} isInvalid={this._isInvalid(whatsValidVery.pubkey)}> 250 | 251 | {this.publicKeys.map(pubkey => )} 252 | 253 | 254 | 255 | 256 | 257 | 258 | Signature file 259 | this._onVerifyFieldChange(e)} 261 | isValid={whatsValidVery.sigfile} isInvalid={this._isInvalid(whatsValidVery.sigfile)}> 262 | 263 | {this.props.files.map(file => )} 264 | 265 | 266 | 267 | 268 | 269 | 270 |
271 | 272 |
273 | 275 | 276 |
277 |
278 | 279 | 280 | } 281 | 282 | 283 | /* signing fields handling */ 284 | 285 | _onSigningFieldChange(e) { 286 | this.setState({ signingFields: { ...this.state.signingFields, 287 | [e.target.name]: e.target.value } }) 288 | } 289 | 290 | _validateSigningFields() { 291 | 292 | let whatsValid = {} 293 | 294 | // check if input text is valid 295 | if(this.state.signingFields.inputtype == "text") 296 | whatsValid.inputtext = !(!this.state.signingFields.inputtext) 297 | 298 | // check if input file is valid 299 | if(this.state.signingFields.inputtype == "file") 300 | whatsValid.inputfile = !(!this.state.signingFields.inputfile) 301 | 302 | // check if privkey was selected 303 | whatsValid.privkey = !(!this.state.signingFields.privkey) 304 | 305 | // check if passphrase was provided 306 | if(this.isPrivateKeyEncrypted) { 307 | 308 | // check if passphrase text is valid 309 | if(this.state.signingFields.passphrasetype == "text") 310 | whatsValid.passphrasetext = !(!this.state.signingFields.passphrasetext) 311 | 312 | // check if passphrase file is valid 313 | if(this.state.signingFields.passphrasetype == "file") 314 | whatsValid.passphrasefile = !(!this.state.signingFields.passphrasefile) 315 | 316 | } 317 | 318 | // check if output file is valid 319 | if(this.state.signingFields.useoutputfile == "true") 320 | whatsValid.outputfile = !(!(this.state.signingFields.outputfile || "").trim()) 321 | 322 | return whatsValid 323 | } 324 | 325 | _buildSigningCommand(whatsValid = {}) { 326 | 327 | if(Object.values(whatsValid).includes(false)) return i18next.t("Please fill in all fields") 328 | 329 | let command = "openssl pkeyutl -sign" 330 | command += " -inkey " + this.state.signingFields.privkey 331 | 332 | if(this.isPrivateKeyEncrypted) { 333 | 334 | if(this.state.signingFields.passphrasetype == "text") 335 | command += " -passin pass:" + this.state.signingFields.passphrasetext 336 | 337 | if(this.state.signingFields.passphrasetype == "file") 338 | command += " -passin file:" + this.state.signingFields.passphrasefile 339 | } 340 | 341 | if(this.state.signingFields.inputtype == "text") 342 | command = "echo " + this.state.signingFields.inputtext + " | " + command 343 | 344 | if(this.state.signingFields.inputtype == "file") 345 | command += " -in " + this.state.signingFields.inputfile 346 | 347 | if(this.state.signingFields.useoutputfile == "true") 348 | command += " -out " + this.state.signingFields.outputfile 349 | 350 | return command 351 | } 352 | 353 | _resetSigningFields() { 354 | this.setState({ signingFields: this._initialState.signingFields }) 355 | } 356 | 357 | 358 | /* verification fields handling */ 359 | 360 | _onVerifyFieldChange(e) { 361 | this.setState({ verifyFields: { ...this.state.verifyFields, 362 | [e.target.name]: e.target.value } }) 363 | } 364 | 365 | _validateVerifyFields() { 366 | 367 | let whatsValid = {} 368 | 369 | // check if input text is valid 370 | if(this.state.verifyFields.inputtype == "text") 371 | whatsValid.inputtext = !(!this.state.verifyFields.inputtext) 372 | 373 | // check if input file is valid 374 | if(this.state.verifyFields.inputtype == "file") 375 | whatsValid.inputfile = !(!this.state.verifyFields.inputfile) 376 | 377 | // check if public key was selected 378 | whatsValid.pubkey = !(!this.state.verifyFields.pubkey) 379 | 380 | // check if signature file was selected 381 | whatsValid.sigfile = !(!this.state.verifyFields.sigfile) 382 | 383 | return whatsValid 384 | } 385 | 386 | _buildVerifyCommand(whatsValid = {}) { 387 | 388 | if(Object.values(whatsValid).includes(false)) return i18next.t("Please fill in all fields") 389 | 390 | let command = "openssl pkeyutl -verify" 391 | command += " -pubin -inkey " + this.state.verifyFields.pubkey 392 | 393 | if(this.state.verifyFields.inputtype == "text") 394 | command = "echo " + this.state.verifyFields.inputtext + " | " + command 395 | 396 | if(this.state.verifyFields.inputtype == "file") 397 | command += " -in " + this.state.verifyFields.inputfile 398 | 399 | command += " -sigfile " + this.state.verifyFields.sigfile 400 | 401 | return command 402 | } 403 | 404 | _resetVerifyFields() { 405 | this.setState({ verifyFields: this._initialState.verifyFields }) 406 | } 407 | 408 | 409 | 410 | /* helper functions */ 411 | 412 | _isInvalid(value) { 413 | // make undefined not mean false 414 | if(value == undefined) return undefined 415 | else return !value 416 | } 417 | 418 | } 419 | 420 | export default SignVerifyTab 421 | -------------------------------------------------------------------------------- /sources/openssl-gui/tabs/WelcomeTab.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import { Trans } from "react-i18next" 3 | 4 | class WelcomeTabContent extends React.Component { 5 | 6 | render() { 7 | return Welcome to OpenSSL in your browser! 8 | } 9 | 10 | } 11 | 12 | export default WelcomeTabContent 13 | -------------------------------------------------------------------------------- /sources/translations.js: -------------------------------------------------------------------------------- 1 | import i18n from "i18next" 2 | import { initReactI18next } from "react-i18next" 3 | 4 | // get selected language based on url parameter ?lang=xx or use "en" 5 | window.lang = (new URLSearchParams(location.search)).get("lang") || "en" 6 | 7 | const resources = { 8 | 9 | en: { translation: { 10 | "Welcome to OpenSSL in your browser!": "Welcome to OpenSSL in your browser! The upper terminal runs OpenSSL compiled to WebAssembly. You can also use the graphical user interface (GUI) to build and run commands. Have fun :)" 11 | }}, 12 | 13 | de: { translation: { 14 | "Welcome to OpenSSL in your browser!": "Willkommen zu OpenSSL im Browser! Im obigen Terminal läuft ein zu WebAssembly kompiliertes OpenSSL. Sie können auch die grafische Benutzeroberfläche benutzen, um Befehle zu erzeugen. Viel Spaß :)", 15 | "Enter split screen": "Nebeneinander-Modus", 16 | "Exit": "Schließen", 17 | "Command": "Befehl", 18 | "Run": "Ausführen", 19 | "Welcome": "Willkommen", 20 | "Encrypt & Decrypt": "Verschlüsseln", 21 | "Generate Keys": "Schlüssel erzeugen", 22 | "Sign & Verify": "Signieren & Verifizieren", 23 | "Hashes": "Prüfsummen", 24 | "Files": "Dateien", 25 | "New": "Neu", 26 | "Reset fields": "Felder zurücksetzen", 27 | "Mode": "Modus", 28 | "Input": "Eingabe", 29 | "Select file": "Datei auswählen", 30 | "Method": "Methode", 31 | "Filename": "Dateiname", 32 | "Last modified": "Zuletzt verändert", 33 | "File size": "Dateigröße", 34 | "Actions": "Aktionen", 35 | "Key length": "Schlüssellänge", 36 | "Elliptic curve name": "Name der elliptischen Kurve", 37 | "Derive public key": "Public Key ableiten", 38 | "Private key input file": "Private Key Eingabedatei", 39 | "EC params input file": "Parameter Eingabedatei", 40 | "Decrypt private key": "Private Key entschlüsseln", 41 | "Public key output format": "Public Key Ausgabeformat", 42 | "Hash function": "Hash-Funktion", 43 | "Sign with private key": "Mit Private Key signieren", 44 | "Private key": "Private Key", 45 | "Verify with public key": "Mit Public Key verifizieren", 46 | "Public key": "Public Key", 47 | "Signature file": "Signaturdatei", 48 | "Key type": "Schlüsseltyp", 49 | "Options": "Optionen", 50 | 51 | "Encrypt": "Verschlüsseln", 52 | "Decrypt": "Entschlüsseln", 53 | "executing command": "Befehl wird ausgeführt", 54 | "Compiled to WebAssembly with Emscripten": "Zu WebAssembly kompiliert mit Emscripten", 55 | "Running in WebWorker": "Läuft im WebWorker", 56 | "Worker not available": "Worker nicht verfügbar", 57 | "Usage: openssl [command] [params]": "Benutzung: openssl [Befehl] [Parameter]", 58 | "error while": "Fehler während", 59 | "Hello world": "Hallo Welt", 60 | "File": "Datei", 61 | "Cipher": "Chiffre", 62 | "Public keys are not encrypted": "Public Keys sind nicht verschlüsselt", 63 | "Private key not encrypted": "Private Key nicht verschlüsselt", 64 | "No private key selected": "Kein Private Key ausgewählt", 65 | "Enter passphrase ..": "Passphrase eingeben ..", 66 | "Output to file": "Ausgabe in Datei", 67 | "Please fill in all fields": "Bitte füllen Sie alle Felder aus", 68 | "Select a file from your computer": "Wählen Sie eine Datei von Ihrem Computer aus", 69 | "Elliptic curves": "Elliptische Kurven", 70 | "Generate private key": "Private Key erzeugen", 71 | "Generate parameters": "Parameter erzeugen", 72 | "Cipher (for encryption)": "Chiffre (zum Verschlüsseln)", 73 | "Select cipher": "Chiffre auswählen", 74 | "key": "Key" 75 | 76 | }} 77 | } 78 | 79 | i18n.use(initReactI18next).init({ resources, 80 | lng: window.ioApp?.lang || window.lang, // ioApp = cryptool.org 81 | interpolation: { escapeValue: false } 82 | }) 83 | 84 | export default i18n 85 | -------------------------------------------------------------------------------- /sources/xterm-for-react.js: -------------------------------------------------------------------------------- 1 | /** 2 | * React wrapper for xterm.js 3 | * Taken from https://github.com/robert-harbison/xterm-for-react 4 | */ 5 | 6 | 7 | import * as React from 'react' 8 | import PropTypes from 'prop-types' 9 | 10 | import 'xterm/css/xterm.css' 11 | 12 | // We are using these as types. 13 | // eslint-disable-next-line no-unused-vars 14 | import { Terminal, ITerminalOptions, ITerminalAddon } from 'xterm' 15 | 16 | export default class Xterm extends React.Component { 17 | /** 18 | * The ref for the containing element. 19 | */ 20 | terminalRef 21 | 22 | /** 23 | * XTerm.js Terminal object. 24 | */ 25 | terminal // This is assigned in the setupTerminal() which is called from the constructor 26 | 27 | static propTypes = { 28 | className: PropTypes.string, 29 | options: PropTypes.object, 30 | addons: PropTypes.array, 31 | onBinary: PropTypes.func, 32 | onCursorMove: PropTypes.func, 33 | onData: PropTypes.func, 34 | onKey: PropTypes.func, 35 | onLineFeed: PropTypes.func, 36 | onScroll: PropTypes.func, 37 | onSelectionChange: PropTypes.func, 38 | onRender: PropTypes.func, 39 | onResize: PropTypes.func, 40 | onTitleChange: PropTypes.func, 41 | customKeyEventHandler: PropTypes.func, 42 | } 43 | 44 | constructor(props) { 45 | super(props) 46 | 47 | this.terminalRef = React.createRef() 48 | 49 | // Bind Methods 50 | this.onData = this.onData.bind(this) 51 | this.onCursorMove = this.onCursorMove.bind(this) 52 | this.onKey = this.onKey.bind(this) 53 | this.onBinary = this.onBinary.bind(this) 54 | this.onLineFeed = this.onLineFeed.bind(this) 55 | this.onScroll = this.onScroll.bind(this) 56 | this.onSelectionChange = this.onSelectionChange.bind(this) 57 | this.onRender = this.onRender.bind(this) 58 | this.onResize = this.onResize.bind(this) 59 | this.onTitleChange = this.onTitleChange.bind(this) 60 | 61 | this.setupTerminal() 62 | } 63 | 64 | setupTerminal() { 65 | // Setup the XTerm terminal. 66 | this.terminal = new Terminal(this.props.options) 67 | 68 | // Load addons if the prop exists. 69 | if (this.props.addons) { 70 | this.props.addons.forEach((addon) => { 71 | this.terminal.loadAddon(addon) 72 | }) 73 | } 74 | 75 | // Create Listeners 76 | this.terminal.onBinary(this.onBinary) 77 | this.terminal.onCursorMove(this.onCursorMove) 78 | this.terminal.onData(this.onData) 79 | this.terminal.onKey(this.onKey) 80 | this.terminal.onLineFeed(this.onLineFeed) 81 | this.terminal.onScroll(this.onScroll) 82 | this.terminal.onSelectionChange(this.onSelectionChange) 83 | this.terminal.onRender(this.onRender) 84 | this.terminal.onResize(this.onResize) 85 | this.terminal.onTitleChange(this.onTitleChange) 86 | 87 | // Add Custom Key Event Handler 88 | if (this.props.customKeyEventHandler) { 89 | this.terminal.attachCustomKeyEventHandler(this.props.customKeyEventHandler) 90 | } 91 | } 92 | 93 | componentDidMount() { 94 | if (this.terminalRef.current) { 95 | // Creates the terminal within the container element. 96 | this.terminal.open(this.terminalRef.current) 97 | } 98 | } 99 | 100 | componentWillUnmount() { 101 | // When the component unmounts dispose of the terminal and all of its listeners. 102 | this.terminal.dispose() 103 | } 104 | 105 | onBinary(data) { 106 | if (this.props.onBinary) this.props.onBinary(data) 107 | } 108 | 109 | onCursorMove() { 110 | if (this.props.onCursorMove) this.props.onCursorMove() 111 | } 112 | 113 | onData(data) { 114 | if (this.props.onData) this.props.onData(data) 115 | } 116 | 117 | onKey(event) { 118 | if (this.props.onKey) this.props.onKey(event) 119 | } 120 | 121 | onLineFeed() { 122 | if (this.props.onLineFeed) this.props.onLineFeed() 123 | } 124 | 125 | onScroll(newPosition) { 126 | if (this.props.onScroll) this.props.onScroll(newPosition) 127 | } 128 | 129 | onSelectionChange() { 130 | if (this.props.onSelectionChange) this.props.onSelectionChange() 131 | } 132 | 133 | onRender(event) { 134 | if (this.props.onRender) this.props.onRender(event) 135 | } 136 | 137 | onResize(event) { 138 | if (this.props.onResize) this.props.onResize(event) 139 | } 140 | 141 | onTitleChange(newTitle) { 142 | if (this.props.onTitleChange) this.props.onTitleChange(newTitle) 143 | } 144 | 145 | render() { 146 | return
147 | } 148 | } -------------------------------------------------------------------------------- /static/index.html: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | OpenSSL Web Terminal 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /static/style.css: -------------------------------------------------------------------------------- 1 | 2 | /* CommandLine.css */ 3 | 4 | .osslcmdline.fullscreen { 5 | display: flex; 6 | align-items: stretch; 7 | overflow-y: hidden; 8 | 9 | position: fixed; 10 | top: 0; bottom: 0; 11 | left: 0; right: 0; 12 | z-index: 9999999999999999; 13 | background: #222; 14 | } 15 | 16 | .osslcmdline.fullscreen > div { 17 | resize: horizontal; 18 | } 19 | 20 | .osslcmdline .fullscreenresizer { 21 | width: 5px; max-width: 5px; 22 | cursor: col-resize; 23 | user-select: none; 24 | } 25 | 26 | .osslcmdline .xterm.terminal { 27 | padding: 1rem; 28 | } 29 | 30 | .osslcmdline.abovebelow .xterm.terminal { 31 | height: 500px; 32 | } 33 | 34 | .osslcmdline.fullscreen .xterm.terminal { 35 | height: 100vh; 36 | } 37 | 38 | .osslcmdline .loading { 39 | position: absolute; 40 | left: 0; right: 0; 41 | top: 0; bottom: 0; 42 | background-color: rgba(0, 0, 0, 0.75); 43 | display: flex; 44 | justify-content: center; 45 | align-items: center; 46 | flex-direction: column; 47 | color: #fff; 48 | } 49 | 50 | .osslcmdline .custom-radio, 51 | .osslcmdline .custom-checkbox { 52 | user-select: none; 53 | } 54 | 55 | .osslcmdline table { 56 | white-space: nowrap; 57 | } 58 | 59 | 60 | /* GuiControls.css */ 61 | 62 | .osslcmdline.fullscreen .osslgui { 63 | margin: 0 !important; 64 | border-radius: 0; 65 | flex: 1; 66 | } 67 | 68 | @media(min-width: 768px) { 69 | .osslcmdline.fullscreen .osslgui > .card-body { 70 | overflow-y: scroll; 71 | } 72 | } 73 | 74 | .osslcmdline .osslgui .table td, 75 | .osslcmdline .osslgui .table th { 76 | vertical-align: middle !important; 77 | } 78 | 79 | 80 | /* fix behaviour in CTO */ 81 | 82 | .osslcmdline .card-header button { 83 | padding-left: 0.5rem !important; 84 | padding-right: 0.5rem !important; 85 | } 86 | 87 | .osslcmdline .card-header button:after { 88 | content: "" !important; 89 | } 90 | 91 | 92 | /* development environment */ 93 | 94 | body.development { 95 | background: #222 !important; 96 | overflow-y: scroll; 97 | } 98 | 99 | body.development .osslcmdline.abovebelow { 100 | max-width: 1000px; 101 | margin: 2rem auto; 102 | } 103 | 104 | select.form-control.is-valid, .was-validated select.form-control:valid, 105 | select.form-control.is-invalid, .was-validated select.form-control:invalid { 106 | background-position: right calc(.5em + .5rem) center; 107 | } 108 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const CopyPlugin = require("copy-webpack-plugin") 2 | const HtmlWebPackPlugin = require("html-webpack-plugin") 3 | 4 | module.exports = { 5 | entry: { 6 | "main": "./index.js" 7 | }, 8 | output: { 9 | path: __dirname + "/dist", 10 | filename: "[name].js" 11 | }, 12 | devServer: { 13 | port: 4200, 14 | headers: { 15 | "Cross-Origin-Embedder-Policy": "require-corp", 16 | "Cross-Origin-Opener-Policy": "same-origin" 17 | }, 18 | https: true 19 | }, 20 | module: { 21 | rules: [{ 22 | test: /\.(js|jsx)$/, 23 | exclude: ["/node_modules/", "/bin/"], 24 | use: ["babel-loader"] 25 | }, { 26 | test: /\.css$/, 27 | use: ["style-loader", "css-loader"] 28 | }] 29 | }, 30 | plugins: [ 31 | new CopyPlugin({ 32 | patterns: [ 33 | { from: "emscr/binary/*.js", to: "bin/[name][ext]" }, 34 | { from: "emscr/binary/*.wasm", to: "bin/[name][ext]" }, 35 | // { from: "emscr/binary/*.data", to: "bin/[name][ext]" } 36 | ] 37 | }), 38 | new HtmlWebPackPlugin({ 39 | template: "./static/index.html", inject: false 40 | }) 41 | ] 42 | } 43 | --------------------------------------------------------------------------------