├── .gitignore ├── emscr ├── binary │ ├── openssl.wasm │ └── openssl.js └── builds │ └── openssl │ ├── speed_sched.patch │ ├── openssl.cnf │ └── build.sh ├── sources ├── openssl-gui │ ├── tabs │ │ ├── WelcomeTab.js │ │ ├── FilesTab.js │ │ ├── HashesTab.js │ │ ├── EncryptionTab.js │ │ ├── SignVerifyTab.js │ │ └── GenKeysTab.js │ ├── CommandField.js │ ├── Helpers.js │ └── OpenSSL_GUI.js ├── translations.js ├── xterm-for-react.js └── OpenSSL_CommandLine.js ├── index.js ├── Dockerfile ├── static ├── index.html └── style.css ├── webpack.config.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | 4 | emscr/builds/**/src 5 | emscr/builds/**/*.tar.gz 6 | 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /emscr/binary/openssl.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cryptool-org/openssl-webterm/HEAD/emscr/binary/openssl.wasm -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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;"] -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 emscripten:emscripten --platform linux/amd64 emscripten/emsdk:4.0.12 /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 | -------------------------------------------------------------------------------- /emscr/builds/openssl/speed_sched.patch: -------------------------------------------------------------------------------- 1 | diff --git a/apps/lib/apps.c b/apps/lib/apps.c 2 | index 50e83b50c4..752c32cf90 100644 3 | --- a/apps/lib/apps.c 4 | +++ b/apps/lib/apps.c 5 | @@ -2889,7 +2889,7 @@ double app_tminterval(int stop, int usertime) 6 | return ret; 7 | } 8 | 9 | -#elif defined(_SC_CLK_TCK) /* by means of unistd.h */ 10 | +#elif defined(_SC_CLK_TCK) && !defined(__EMSCRIPTEN__) /* by means of unistd.h */ 11 | # include 12 | 13 | double app_tminterval(int stop, int usertime) 14 | diff --git a/apps/speed.c b/apps/speed.c 15 | index 059183ddc7..f3e2fa55b3 100644 16 | --- a/apps/speed.c 17 | +++ b/apps/speed.c 18 | @@ -118,7 +118,7 @@ typedef struct openssl_speed_sec_st { 19 | static volatile int run = 0; 20 | 21 | static int mr = 0; /* machine-readeable output format to merge fork results */ 22 | -static int usertime = 1; 23 | +static int usertime = 0; 24 | 25 | static double Time_F(int s); 26 | static void print_message(const char *s, int length, int tm); 27 | @@ -512,7 +512,12 @@ static size_t sigs_algs_len = 0; 28 | static char *sigs_algname[MAX_SIG_NUM] = { NULL }; 29 | static double sigs_results[MAX_SIG_NUM][3]; /* keygen, sign, verify */ 30 | 31 | +#ifdef __EMSCRIPTEN__ 32 | +#include "sched.h" 33 | +#define COND(unused_cond) (sched_yield(), run && count < (testmode ? 1 : INT_MAX)) 34 | +#else 35 | #define COND(unused_cond) (run && count < (testmode ? 1 : INT_MAX)) 36 | +#endif 37 | #define COUNT(d) (count) 38 | 39 | #define TAG_LEN 16 /* 16 bytes tag length works for all AEAD modes */ 40 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /emscr/builds/openssl/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OPENSSL_VERSION="openssl-3.6.0" 4 | 5 | FILENAME="$OPENSSL_VERSION.tar.gz" 6 | DOWNLOAD_PATH="https://github.com/openssl/openssl/releases/download/$OPENSSL_VERSION/$FILENAME" 7 | 8 | OPENSSL_DIR="src" 9 | 10 | if [ -d ${OPENSSL_DIR} ]; then 11 | rm -rf ${OPENSSL_DIR} 12 | fi 13 | 14 | if [ ! -f ${FILENAME} ]; then 15 | echo Downloading from ${DOWNLOAD_PATH} $'\n' 16 | curl -L -O ${DOWNLOAD_PATH} 17 | fi 18 | 19 | mkdir ${OPENSSL_DIR} 20 | echo Extracting tar archive ${FILENAME} $'\n' 21 | tar xf ${FILENAME} --strip-components=1 --directory=${OPENSSL_DIR} 22 | cd ${OPENSSL_DIR} || exit 1 23 | 24 | echo Apply patches $'\n' 25 | patch -p1 -i ../speed_sched.patch 26 | echo '' 27 | 28 | echo Copying OpenSSL config $'\n' 29 | mkdir -p usr/local/ssl/ 30 | cp ../openssl.cnf usr/local/ssl/openssl.cnf 31 | 32 | LDFLAGS="\ 33 | -s ENVIRONMENT='web'\ 34 | -s FILESYSTEM=1\ 35 | -s MODULARIZE=1\ 36 | -s EXPORTED_RUNTIME_METHODS=\"['callMain', 'FS', 'TTY']\"\ 37 | -s INVOKE_RUN=0\ 38 | -s EXIT_RUNTIME=1\ 39 | -s EXPORT_ES6=0\ 40 | -s EXPORT_NAME='EmscrJSR_openssl'\ 41 | -s ALLOW_MEMORY_GROWTH=1\ 42 | --embed-file usr/local/ssl/openssl.cnf" 43 | 44 | if [[ $1 == "debug" ]]; then 45 | LDFLAGS="$LDFLAGS -s ASSERTIONS=1" # For logging purposes. 46 | fi 47 | 48 | export LDFLAGS 49 | export CC=emcc 50 | export CXX=emcc 51 | 52 | echo Running Emscripten $'\n' 53 | 54 | emconfigure ./Configure \ 55 | no-shared \ 56 | no-asm \ 57 | no-threads \ 58 | no-ssl3 \ 59 | no-dtls \ 60 | no-engine \ 61 | no-dso \ 62 | linux-x32 \ 63 | -static\ 64 | 65 | sed -i 's/$(CROSS_COMPILE)//' Makefile 66 | emmake make -j 16 build_generated libssl.a libcrypto.a apps/openssl 67 | mv apps/openssl apps/openssl.js 68 | 69 | echo Copying OpenSSL binary into emscr/binary folder 70 | 71 | # import wasm build 72 | cp apps/openssl.js ../../../binary/openssl.js || exit 1 73 | cp apps/openssl.wasm ../../../binary/openssl.wasm || exit 1 74 | sed -i '1s;^;\/* eslint-disable *\/;' ../../../binary/openssl.js 75 | 76 | # clean up directory 77 | cd .. && rm -rf ${OPENSSL_DIR} ${FILENAME} 78 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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_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/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/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/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 | -------------------------------------------------------------------------------- /emscr/binary/openssl.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */var EmscrJSR_openssl=(()=>{var _scriptName=typeof document!="undefined"?document.currentScript?.src:undefined;return async function(moduleArg={}){var moduleRtn;var Module=moduleArg;var ENVIRONMENT_IS_WEB=true;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var EXITSTATUS;var readyPromiseResolve,readyPromiseReject;var wasmMemory;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;var runtimeExited=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;if(!Module["noFSInit"]&&!FS.initialized)FS.init();TTY.init();SOCKFS.root=FS.mount(SOCKFS,{},null);PIPEFS.root=FS.mount(PIPEFS,{},null);wasmExports["_"]();FS.ignorePermissions=false}function preMain(){}function exitRuntime(){___funcs_on_exit();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(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject?.(e);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("openssl.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){return{a:wasmImports}}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["Z"];updateMemoryViews();wasmTable=wasmExports["$"];assignWasmExports(wasmExports);return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(mod,inst)=>{resolve(receiveInstance(mod,inst))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var noExitRuntime=false;var wasmTableMirror=[];var wasmTable;var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func){wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr)}return func};var ___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.slice(-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.slice(0,-1)}return root+dir},basename:path=>path&&path.match(/([^\/]+|\/)\/*$/)[1],join:(...paths)=>PATH.normalize(paths.join("/")),join2:(l,r)=>PATH.normalize(l+"/"+r)};var initRandomFill=()=>view=>crypto.getRandomValues(view);var randomFill=view=>{(randomFill=initRandomFill())(view)};var PATH_FS={resolve:(...args)=>{var resolvedPath="",resolvedAbsolute=false;for(var i=args.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?args[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).slice(1);to=PATH_FS.resolve(to).slice(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;i{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023)}}return str};var FS_stdin_getChar_buffer=[];var lengthBytesUTF8=str=>{var len=0;for(var i=0;i=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=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;i++}}heap[outIdx]=0;return outIdx-startIdx};var intArrayFromString=(stringy,dontAddNull,length)=>{var len=length>0?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 FS_stdin_getChar=()=>{if(!FS_stdin_getChar_buffer.length){var result=null;if(typeof window!="undefined"&&typeof window.prompt=="function"){result=window.prompt("Input: ");if(result!==null){result+="\n"}}else{}if(!result){return null}FS_stdin_getChar_buffer=intArrayFromString(result,true)}return FS_stdin_getChar_buffer.shift()};var TTY={ttys:[],init(){},shutdown(){},register(dev,ops){TTY.ttys[dev]={input:[],output:[],ops};FS.registerDevice(dev,TTY.stream_ops)},stream_ops:{open(stream){var tty=TTY.ttys[stream.node.rdev];if(!tty){throw new FS.ErrnoError(43)}stream.tty=tty;stream.seekable=false},close(stream){stream.tty.ops.fsync(stream.tty)},fsync(stream){stream.tty.ops.fsync(stream.tty)},read(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));tty.output=[]}},ioctl_tcgets(tty){return{c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ioctl_tcsets(tty,optional_actions,data){return 0},ioctl_tiocgwinsz(tty){return[24,80]}},default_tty1_ops:{put_char(tty,val){if(val===null||val===10){err(UTF8ArrayToString(tty.output));tty.output=[]}else{if(val!=0)tty.output.push(val)}},fsync(tty){if(tty.output?.length>0){err(UTF8ArrayToString(tty.output));tty.output=[]}}}};var zeroMemory=(ptr,size)=>HEAPU8.fill(0,ptr,ptr+size);var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var mmapAlloc=size=>{size=alignMemory(size,65536);var ptr=_emscripten_builtin_memalign(65536,size);if(ptr)zeroMemory(ptr,size);return ptr};var MEMFS={ops_table:null,mount(mount){return MEMFS.createNode(null,"/",16895,0)},createNode(parent,name,mode,dev){if(FS.isBlkdev(mode)||FS.isFIFO(mode)){throw new FS.ErrnoError(63)}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,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.atime=node.mtime=node.ctime=Date.now();if(parent){parent.contents[name]=node;parent.atime=parent.mtime=parent.ctime=node.atime}return node},getFileDataAsTypedArray(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(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(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(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.atime);attr.mtime=new Date(node.mtime);attr.ctime=new Date(node.ctime);attr.blksize=4096;attr.blocks=Math.ceil(attr.size/attr.blksize);return attr},setattr(node,attr){for(const key of["mode","atime","mtime","ctime"]){if(attr[key]!=null){node[key]=attr[key]}}if(attr.size!==undefined){MEMFS.resizeFileStorage(node,attr.size)}},lookup(parent,name){if(!MEMFS.doesNotExistError){MEMFS.doesNotExistError=new FS.ErrnoError(44);MEMFS.doesNotExistError.stack=""}throw MEMFS.doesNotExistError},mknod(parent,name,mode,dev){return MEMFS.createNode(parent,name,mode,dev)},rename(old_node,new_dir,new_name){var new_node;try{new_node=FS.lookupNode(new_dir,new_name)}catch(e){}if(new_node){if(FS.isDir(old_node.mode)){for(var i in new_node.contents){throw new FS.ErrnoError(55)}}FS.hashRemoveNode(new_node)}delete old_node.parent.contents[old_node.name];new_dir.contents[new_name]=old_node;old_node.name=new_name;new_dir.ctime=new_dir.mtime=old_node.parent.ctime=old_node.parent.mtime=Date.now()},unlink(parent,name){delete parent.contents[name];parent.ctime=parent.mtime=Date.now()},rmdir(parent,name){var node=FS.lookupNode(parent,name);for(var i in node.contents){throw new FS.ErrnoError(55)}delete parent.contents[name];parent.ctime=parent.mtime=Date.now()},readdir(node){return[".","..",...Object.keys(node.contents)]},symlink(parent,newname,oldpath){var node=MEMFS.createNode(parent,newname,511|40960,0);node.link=oldpath;return node},readlink(node){if(!FS.isLink(node.mode)){throw new FS.ErrnoError(28)}return node.link}},stream_ops:{read(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{var flagModes={r:0,"r+":2,w:512|64|1,"w+":512|64|2,a:1024|64|1,"a+":1024|64|2};var flags=flagModes[str];if(typeof flags=="undefined"){throw new Error(`Unknown file open mode: ${str}`)}return flags};var FS_getMode=(canRead,canWrite)=>{var mode=0;if(canRead)mode|=292|73;if(canWrite)mode|=146;return mode};var asyncLoad=async url=>{var arrayBuffer=await readAsync(url);return new Uint8Array(arrayBuffer)};var FS_createDataFile=(...args)=>FS.createDataFile(...args);var getUniqueRunDependency=id=>id;var runDependencies=0;var dependenciesFulfilled=null;var removeRunDependency=id=>{runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}};var addRunDependency=id=>{runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)};var preloadPlugins=[];var FS_handledByPreloadPlugin=async(byteArray,fullname)=>{if(typeof Browser!="undefined")Browser.init();for(var plugin of preloadPlugins){if(plugin["canHandle"](fullname)){return plugin["handle"](byteArray,fullname)}}return byteArray};var FS_preloadFile=async(parent,name,url,canRead,canWrite,dontCreateFile,canOwn,preFinish)=>{var fullname=name?PATH_FS.resolve(PATH.join2(parent,name)):parent;var dep=getUniqueRunDependency(`cp ${fullname}`);addRunDependency(dep);try{var byteArray=url;if(typeof url=="string"){byteArray=await asyncLoad(url)}byteArray=await FS_handledByPreloadPlugin(byteArray,fullname);preFinish?.();if(!dontCreateFile){FS_createDataFile(parent,name,byteArray,canRead,canWrite,canOwn)}}finally{removeRunDependency(dep)}};var FS_createPreloadedFile=(parent,name,url,canRead,canWrite,onload,onerror,dontCreateFile,canOwn,preFinish)=>{FS_preloadFile(parent,name,url,canRead,canWrite,dontCreateFile,canOwn,preFinish).then(onload).catch(onerror)};var FS={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:"/",initialized:false,ignorePermissions:true,filesystems:null,syncFSRequests:0,readFiles:{},ErrnoError:class{name="ErrnoError";constructor(errno){this.errno=errno}},FSStream:class{shared={};get object(){return this.node}set object(val){this.node=val}get isRead(){return(this.flags&2097155)!==1}get isWrite(){return(this.flags&2097155)!==0}get isAppend(){return this.flags&1024}get flags(){return this.shared.flags}set flags(val){this.shared.flags=val}get position(){return this.shared.position}set position(val){this.shared.position=val}},FSNode:class{node_ops={};stream_ops={};readMode=292|73;writeMode=146;mounted=null;constructor(parent,name,mode,rdev){if(!parent){parent=this}this.parent=parent;this.mount=parent.mount;this.id=FS.nextInode++;this.name=name;this.mode=mode;this.rdev=rdev;this.atime=this.mtime=this.ctime=Date.now()}get read(){return(this.mode&this.readMode)===this.readMode}set read(val){val?this.mode|=this.readMode:this.mode&=~this.readMode}get write(){return(this.mode&this.writeMode)===this.writeMode}set write(val){val?this.mode|=this.writeMode:this.mode&=~this.writeMode}get isFolder(){return FS.isDir(this.mode)}get isDevice(){return FS.isChrdev(this.mode)}},lookupPath(path,opts={}){if(!path){throw new FS.ErrnoError(44)}opts.follow_mount??=true;if(!PATH.isAbs(path)){path=FS.cwd()+"/"+path}linkloop:for(var nlinks=0;nlinks<40;nlinks++){var parts=path.split("/").filter(p=>!!p);var current=FS.root;var current_path="/";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)}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},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){if(!FS.isDir(dir.mode))return 54;var errCode=FS.nodePermissions(dir,"x");if(errCode)return errCode;if(!dir.node_ops.lookup)return 2;return 0},mayCreate(dir,name){if(!FS.isDir(dir.mode)){return 54}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|64)){return 31}}return FS.nodePermissions(node,FS.flagsToPermissionString(flags))},checkOpExists(op,err){if(!op){throw new FS.ErrnoError(err)}return op},MAX_OPEN_FDS:4096,nextfd(){for(var fd=0;fd<=FS.MAX_OPEN_FDS;fd++){if(!FS.streams[fd]){return fd}}throw new FS.ErrnoError(33)},getStreamChecked(fd){var stream=FS.getStream(fd);if(!stream){throw new FS.ErrnoError(8)}return stream},getStream:fd=>FS.streams[fd],createStream(stream,fd=-1){stream=Object.assign(new FS.FSStream,stream);if(fd==-1){fd=FS.nextfd()}stream.fd=fd;FS.streams[fd]=stream;return stream},closeStream(fd){FS.streams[fd]=null},dupStream(origStream,fd=-1){var stream=FS.createStream(origStream,fd);stream.stream_ops?.dup?.(stream);return stream},doSetAttr(stream,node,attr){var setattr=stream?.stream_ops.setattr;var arg=setattr?stream:node;setattr??=node.node_ops.setattr;FS.checkOpExists(setattr,63);setattr(arg,attr)},chrdev_stream_ops:{open(stream){var device=FS.getDevice(stream.node.rdev);stream.stream_ops=device.stream_ops;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(...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,opts,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){throw new FS.ErrnoError(28)}if(name==="."||name===".."){throw new FS.ErrnoError(20)}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)},statfs(path){return FS.statfsNode(FS.lookupPath(path,{follow:true}).node)},statfsStream(stream){return FS.statfsNode(stream.node)},statfsNode(node){var rtn={bsize:4096,frsize:4096,blocks:1e6,bfree:5e5,bavail:5e5,files:FS.nextInode,ffree:FS.nextInode-1,fsid:42,flags:2,namelen:255};if(node.node_ops.statfs){Object.assign(rtn,node.node_ops.statfs(node.mount.opts.root))}return rtn},create(path,mode=438){mode&=4095;mode|=32768;return FS.mknod(path,mode,0)},mkdir(path,mode=511){mode&=511|512;mode|=16384;return FS.mknod(path,mode,0)},mkdirTree(path,mode){var dirs=path.split("/");var d="";for(var dir of dirs){if(!dir)continue;if(d||PATH.isAbs(path))d+="/";d+=dir;try{FS.mkdir(d,mode)}catch(e){if(e.errno!=20)throw e}}},mkdev(path,mode,dev){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);old_node.parent=new_dir}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;var readdir=FS.checkOpExists(node.node_ops.readdir,54);return 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 link.node_ops.readlink(link)},stat(path,dontFollow){var lookup=FS.lookupPath(path,{follow:!dontFollow});var node=lookup.node;var getattr=FS.checkOpExists(node.node_ops.getattr,63);return getattr(node)},fstat(fd){var stream=FS.getStreamChecked(fd);var node=stream.node;var getattr=stream.stream_ops.getattr;var arg=getattr?stream:node;getattr??=node.node_ops.getattr;FS.checkOpExists(getattr,63);return getattr(arg)},lstat(path){return FS.stat(path,true)},doChmod(stream,node,mode,dontFollow){FS.doSetAttr(stream,node,{mode:mode&4095|node.mode&~4095,ctime:Date.now(),dontFollow})},chmod(path,mode,dontFollow){var node;if(typeof path=="string"){var lookup=FS.lookupPath(path,{follow:!dontFollow});node=lookup.node}else{node=path}FS.doChmod(null,node,mode,dontFollow)},lchmod(path,mode){FS.chmod(path,mode,true)},fchmod(fd,mode){var stream=FS.getStreamChecked(fd);FS.doChmod(stream,stream.node,mode,false)},doChown(stream,node,dontFollow){FS.doSetAttr(stream,node,{timestamp:Date.now(),dontFollow})},chown(path,uid,gid,dontFollow){var node;if(typeof path=="string"){var lookup=FS.lookupPath(path,{follow:!dontFollow});node=lookup.node}else{node=path}FS.doChown(null,node,dontFollow)},lchown(path,uid,gid){FS.chown(path,uid,gid,true)},fchown(fd,uid,gid){var stream=FS.getStreamChecked(fd);FS.doChown(stream,stream.node,false)},doTruncate(stream,node,len){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)}FS.doSetAttr(stream,node,{size:len,timestamp:Date.now()})},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}FS.doTruncate(null,node,len)},ftruncate(fd,len){var stream=FS.getStreamChecked(fd);if(len<0||(stream.flags&2097155)===0){throw new FS.ErrnoError(28)}FS.doTruncate(stream,stream.node,len)},utime(path,atime,mtime){var lookup=FS.lookupPath(path,{follow:true});var node=lookup.node;var setattr=FS.checkOpExists(node.node_ops.setattr,63);setattr(node,{atime,mtime})},open(path,flags,mode=438){if(path===""){throw new FS.ErrnoError(44)}flags=typeof flags=="string"?FS_modeStringToFlags(flags):flags;if(flags&64){mode=mode&4095|32768}else{mode=0}var node;var isDirPath;if(typeof path=="object"){node=path}else{isDirPath=path.endsWith("/");var lookup=FS.lookupPath(path,{follow:!(flags&131072),noent_okay:true});node=lookup.node;path=lookup.path}var created=false;if(flags&64){if(node){if(flags&128){throw new FS.ErrnoError(20)}}else if(isDirPath){throw new FS.ErrnoError(31)}else{node=FS.mknod(path,mode|511,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,path:FS.getPath(node),flags,seekable:true,position:0,stream_ops:node.stream_ops,ungotten:[],error:false});if(stream.stream_ops.open){stream.stream_ops.open(stream)}if(created){FS.chmod(node,mode&511)}if(Module["logReadFiles"]&&!(flags&1)){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},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)}if(!length){throw new FS.ErrnoError(28)}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)},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"){abort(`Invalid encoding type "${opts.encoding}"`)}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"){buf=UTF8ArrayToString(buf)}FS.close(stream);return buf},writeFile(path,data,opts={}){opts.flags=opts.flags||577;var stream=FS.open(path,opts.flags,opts.mode);if(typeof data=="string"){data=new Uint8Array(intArrayFromString(data,true))}if(ArrayBuffer.isView(data)){FS.write(stream,data,0,data.byteLength,undefined,opts.canOwn)}else{abort("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,llseek:()=>0});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 randomBuffer=new Uint8Array(1024),randomLeft=0;var randomByte=()=>{if(randomLeft===0){randomFill(randomBuffer);randomLeft=randomBuffer.byteLength}return randomBuffer[--randomLeft]};FS.createDevice("/dev","random",randomByte);FS.createDevice("/dev","urandom",randomByte);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",16895,73);node.stream_ops={llseek:MEMFS.stream_ops.llseek};node.node_ops={lookup(parent,name){var fd=+name;var stream=FS.getStreamChecked(fd);var ret={parent:null,mount:{mountpoint:"fake"},node_ops:{readlink:()=>stream.path},id:fd+1};ret.parent=ret;return ret},readdir(){return Array.from(FS.streams.entries()).filter(([k,v])=>v).map(([k,v])=>k.toString())}};return node}},{},"/proc/self/fd")},createStandardStreams(input,output,error){if(input){FS.createDevice("/dev","stdin",input)}else{FS.symlink("/dev/tty","/dev/stdin")}if(output){FS.createDevice("/dev","stdout",null,output)}else{FS.symlink("/dev/tty","/dev/stdout")}if(error){FS.createDevice("/dev","stderr",null,error)}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)},staticInit(){FS.nameTable=new Array(4096);FS.mount(MEMFS,{},"/");FS.createDefaultDirectories();FS.createDefaultDevices();FS.createSpecialDirectories();FS.filesystems={MEMFS}},init(input,output,error){FS.initialized=true;input??=Module["stdin"];output??=Module["stdout"];error??=Module["stderr"];FS.createStandardStreams(input,output,error)},quit(){FS.initialized=false;_fflush(0);for(var stream of FS.streams){if(stream){FS.close(stream)}}},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){if(e.errno!=20)throw 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;ithis.length-1||idx<0){return undefined}var chunkOffset=idx%this.chunkSize;var chunkNum=idx/this.chunkSize|0;return this.getter(chunkNum)[chunkOffset]}setDataGetter(getter){this.getter=getter}cacheLength(){var xhr=new XMLHttpRequest;xhr.open("HEAD",url,false);xhr.send(null);if(!(xhr.status>=200&&xhr.status<300||xhr.status===304))abort("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)abort("invalid range ("+from+", "+to+") or no bytes requested!");if(to>datalength-1)abort("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))abort("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")abort("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}get length(){if(!this.lengthKnown){this.cacheLength()}return this._length}get chunkSize(){if(!this.lengthKnown){this.cacheLength()}return this._chunkSize}}if(typeof XMLHttpRequest!="undefined"){if(!ENVIRONMENT_IS_WORKER)abort("Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc");var lazyArray=new LazyUint8Array;var properties={isDevice:false,contents:lazyArray}}else{var properties={isDevice:false,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]=(...args)=>{FS.forceLoadFile(node);return fn(...args)}});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,allocated:true}};node.stream_ops=stream_ops;return node}};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):"";var SYSCALLS={DEFAULT_POLLMASK:5,calculateAt(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 dir+"/"+path},writeStat(buf,stat){HEAPU32[buf>>2]=stat.dev;HEAPU32[buf+4>>2]=stat.mode;HEAPU32[buf+8>>2]=stat.nlink;HEAPU32[buf+12>>2]=stat.uid;HEAPU32[buf+16>>2]=stat.gid;HEAPU32[buf+20>>2]=stat.rdev;HEAP64[buf+24>>3]=BigInt(stat.size);HEAP32[buf+32>>2]=4096;HEAP32[buf+36>>2]=stat.blocks;var atime=stat.atime.getTime();var mtime=stat.mtime.getTime();var ctime=stat.ctime.getTime();HEAP64[buf+40>>3]=BigInt(Math.floor(atime/1e3));HEAPU32[buf+48>>2]=atime%1e3*1e3*1e3;HEAP64[buf+56>>3]=BigInt(Math.floor(mtime/1e3));HEAPU32[buf+64>>2]=mtime%1e3*1e3*1e3;HEAP64[buf+72>>3]=BigInt(Math.floor(ctime/1e3));HEAPU32[buf+80>>2]=ctime%1e3*1e3*1e3;HEAP64[buf+88>>3]=BigInt(stat.ino);return 0},writeStatFs(buf,stats){HEAPU32[buf+4>>2]=stats.bsize;HEAPU32[buf+60>>2]=stats.bsize;HEAP64[buf+8>>3]=BigInt(stats.blocks);HEAP64[buf+16>>3]=BigInt(stats.bfree);HEAP64[buf+24>>3]=BigInt(stats.bavail);HEAP64[buf+32>>3]=BigInt(stats.files);HEAP64[buf+40>>3]=BigInt(stats.ffree);HEAPU32[buf+48>>2]=stats.fsid;HEAPU32[buf+64>>2]=stats.flags;HEAPU32[buf+56>>2]=stats.namelen},doMsync(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)},getStreamFromFD(fd){var stream=FS.getStreamChecked(fd);return stream},varargs:undefined,getStr(ptr){var ret=UTF8ToString(ptr);return ret}};var ___syscall__newselect=function(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=(fd,low,high,val)=>fd<32?low&val:high&val;for(var fd=0;fd>2]:0,tv_usec=readfds?HEAP32[timeout+4>>2]:0;timeoutInMillis=(tv_sec+tv_usec/1e6)*1e3}flags=stream.stream_ops.poll(stream,timeoutInMillis)}if(flags&1&&check(fd,srcReadLow,srcReadHigh,mask)){fd<32?dstReadLow=dstReadLow|mask:dstReadHigh=dstReadHigh|mask;total++}if(flags&4&&check(fd,srcWriteLow,srcWriteHigh,mask)){fd<32?dstWriteLow=dstWriteLow|mask:dstWriteHigh=dstWriteHigh|mask;total++}if(flags&2&&check(fd,srcExceptLow,srcExceptHigh,mask)){fd<32?dstExceptLow=dstExceptLow|mask:dstExceptHigh=dstExceptHigh|mask;total++}}if(readfds){HEAP32[readfds>>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.name==="ErrnoError"))throw e;return-e.errno}};var SOCKFS={websocketArgs:{},callbacks:{},on(event,callback){SOCKFS.callbacks[event]=callback},emit(event,param){SOCKFS.callbacks[event]?.(param)},mount(mount){SOCKFS.websocketArgs=Module["websocket"]||{};(Module["websocket"]??={})["on"]=SOCKFS.on;return FS.createNode(null,"/",16895,0)},createSocket(family,type,protocol){if(family!=2){throw new FS.ErrnoError(5)}type&=~526336;if(type!=1&&type!=2){throw new FS.ErrnoError(28)}var streaming=type==1;if(streaming&&protocol&&protocol!=6){throw new FS.ErrnoError(66)}var sock={family,type,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,flags:2,seekable:false,stream_ops:SOCKFS.stream_ops});sock.stream=stream;return sock},getSocket(fd){var stream=FS.getStream(fd);if(!stream||!FS.isSocket(stream.node.mode)){return null}return stream.node.sock},stream_ops:{poll(stream){var sock=stream.node.sock;return sock.sock_ops.poll(sock)},ioctl(stream,request,varargs){var sock=stream.node.sock;return sock.sock_ops.ioctl(sock,request,varargs)},read(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(stream,buffer,offset,length,position){var sock=stream.node.sock;return sock.sock_ops.sendmsg(sock,buffer,offset,length)},close(stream){var sock=stream.node.sock;sock.sock_ops.close(sock)}},nextname(){if(!SOCKFS.nextname.current){SOCKFS.nextname.current=0}return`socket[${SOCKFS.nextname.current++}]`},websocket_sock_ops:{createPeer(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 url="ws://".replace("#","//");var subProtocols="binary";var opts=undefined;if(SOCKFS.websocketArgs["url"]){url=SOCKFS.websocketArgs["url"]}if(SOCKFS.websocketArgs["subprotocol"]){subProtocols=SOCKFS.websocketArgs["subprotocol"]}else if(SOCKFS.websocketArgs["subprotocol"]===null){subProtocols="null"}if(url==="ws://"||url==="wss://"){var parts=addr.split("/");url=url+parts[0]+":"+port+"/"+parts.slice(1).join("/")}if(subProtocols!=="null"){subProtocols=subProtocols.replace(/^ +| +$/g,"").split(/ *, */);opts=subProtocols}var WebSocketConstructor;{WebSocketConstructor=WebSocket}ws=new WebSocketConstructor(url,opts);ws.binaryType="arraybuffer"}catch(e){throw new FS.ErrnoError(23)}}var peer={addr,port,socket:ws,msg_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.msg_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(sock,addr,port){return sock.peers[addr+":"+port]},addPeer(sock,peer){sock.peers[peer.addr+":"+peer.port]=peer},removePeer(sock,peer){delete sock.peers[peer.addr+":"+peer.port]},handlePeerEvents(sock,peer){var first=true;var handleOpen=function(){sock.connecting=false;SOCKFS.emit("open",sock.stream.fd);try{var queued=peer.msg_send_queue.shift();while(queued){peer.socket.send(queued);queued=peer.msg_send_queue.shift()}}catch(e){peer.socket.close()}};function handleMessage(data){if(typeof data=="string"){var encoder=new TextEncoder;data=encoder.encode(data)}else{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});SOCKFS.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(){SOCKFS.emit("close",sock.stream.fd)});peer.socket.on("error",function(error){sock.error=14;SOCKFS.emit("error",[sock.stream.fd,sock.error,"ECONNREFUSED: Connection refused"])})}else{peer.socket.onopen=handleOpen;peer.socket.onclose=function(){SOCKFS.emit("close",sock.stream.fd)};peer.socket.onmessage=function peer_socket_onmessage(event){handleMessage(event.data)};peer.socket.onerror=function(error){sock.error=14;SOCKFS.emit("error",[sock.stream.fd,sock.error,"ECONNREFUSED: Connection refused"])}}},poll(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){if(sock.connecting){mask|=4}else{mask|=16}}return mask},ioctl(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;case 21537:var on=HEAP32[arg>>2];if(on){sock.stream.flags|=2048}else{sock.stream.flags&=~2048}return 0;default:return 28}},close(sock){if(sock.server){try{sock.server.close()}catch(e){}sock.server=null}for(var peer of Object.values(sock.peers)){try{peer.socket.close()}catch(e){}SOCKFS.websocket_sock_ops.removePeer(sock,peer)}return 0},bind(sock,addr,port){if(typeof sock.saddr!="undefined"||typeof sock.sport!="undefined"){throw new FS.ErrnoError(28)}sock.saddr=addr;sock.sport=port;if(sock.type===2){if(sock.server){sock.server.close();sock.server=null}try{sock.sock_ops.listen(sock,0)}catch(e){if(!(e.name==="ErrnoError"))throw e;if(e.errno!==138)throw e}}},connect(sock,addr,port){if(sock.server){throw new FS.ErrnoError(138)}if(typeof sock.daddr!="undefined"&&typeof sock.dport!="undefined"){var dest=SOCKFS.websocket_sock_ops.getPeer(sock,sock.daddr,sock.dport);if(dest){if(dest.socket.readyState===dest.socket.CONNECTING){throw new FS.ErrnoError(7)}else{throw new FS.ErrnoError(30)}}}var peer=SOCKFS.websocket_sock_ops.createPeer(sock,addr,port);sock.daddr=peer.addr;sock.dport=peer.port;sock.connecting=true},listen(sock,backlog){if(!ENVIRONMENT_IS_NODE){throw new FS.ErrnoError(138)}},accept(listensock){if(!listensock.server||!listensock.pending.length){throw new FS.ErrnoError(28)}var newsock=listensock.pending.shift();newsock.stream.flags=listensock.stream.flags;return newsock},getname(sock,peer){var addr,port;if(peer){if(sock.daddr===undefined||sock.dport===undefined){throw new FS.ErrnoError(53)}addr=sock.daddr;port=sock.dport}else{addr=sock.saddr||0;port=sock.sport||0}return{addr,port}},sendmsg(sock,buffer,offset,length,addr,port){if(sock.type===2){if(addr===undefined||port===undefined){addr=sock.daddr;port=sock.dport}if(addr===undefined||port===undefined){throw new FS.ErrnoError(17)}}else{addr=sock.daddr;port=sock.dport}var dest=SOCKFS.websocket_sock_ops.getPeer(sock,addr,port);if(sock.type===1){if(!dest||dest.socket.readyState===dest.socket.CLOSING||dest.socket.readyState===dest.socket.CLOSED){throw new FS.ErrnoError(53)}}if(ArrayBuffer.isView(buffer)){offset+=buffer.byteOffset;buffer=buffer.buffer}var data=buffer.slice(offset,offset+length);if(!dest||dest.socket.readyState!==dest.socket.OPEN){if(sock.type===2){if(!dest||dest.socket.readyState===dest.socket.CLOSING||dest.socket.readyState===dest.socket.CLOSED){dest=SOCKFS.websocket_sock_ops.createPeer(sock,addr,port)}}dest.msg_send_queue.push(data);return length}try{dest.socket.send(data);return length}catch(e){throw new FS.ErrnoError(28)}},recvmsg(sock,length){if(sock.type===1&&sock.server){throw new FS.ErrnoError(53)}var queued=sock.recv_queue.shift();if(!queued){if(sock.type===1){var dest=SOCKFS.websocket_sock_ops.getPeer(sock,sock.daddr,sock.dport);if(!dest){throw new FS.ErrnoError(53)}if(dest.socket.readyState===dest.socket.CLOSING||dest.socket.readyState===dest.socket.CLOSED){return null}throw new FS.ErrnoError(6)}throw new FS.ErrnoError(6)}var queuedLength=queued.data.byteLength||queued.data.length;var queuedOffset=queued.data.byteOffset||0;var queuedBuffer=queued.data.buffer||queued.data;var bytesRead=Math.min(length,queuedLength);var res={buffer:new Uint8Array(queuedBuffer,queuedOffset,bytesRead),addr:queued.addr,port:queued.port};if(sock.type===1&&bytesRead{var socket=SOCKFS.getSocket(fd);if(!socket)throw new FS.ErrnoError(8);return socket};var 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};var 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]=Number(words[words.length-4])+Number(words[words.length-3])*256;words[words.length-3]=Number(words[words.length-2])+Number(words[words.length-1])*256;words=words.slice(0,words.length-2)}else{words=str.split(":")}offset=0;z=0;for(w=0;w{switch(family){case 2:addr=inetPton4(addr);zeroMemory(sa,16);if(addrlen){HEAP32[addrlen>>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(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++;addr="172.29."+(id&255)+"."+(id&65280);DNS.address_map.names[addr]=name;DNS.address_map.addrs[name]=addr}return addr},lookup_addr(addr){if(DNS.address_map.names[addr]){return DNS.address_map.names[addr]}return null}};function ___syscall_accept4(fd,addr,addrlen,flags,d1,d2){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.name==="ErrnoError"))throw e;return-e.errno}}var inetNtop4=addr=>(addr&255)+"."+(addr>>8&255)+"."+(addr>>16&255)+"."+(addr>>24&255);var 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{var family=HEAP16[sa>>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,addr,port}};var getSocketAddress=(addrp,addrlen)=>{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,d1,d2,d3){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.name==="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.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_connect(fd,addr,addrlen,d1,d2,d3){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.name==="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.name==="ErrnoError"))throw e;return-e.errno}}var syscallGetVarargI=()=>{var ret=HEAP32[+SYSCALLS.varargs>>2];SYSCALLS.varargs+=4;return ret};var syscallGetVarargP=syscallGetVarargI;function ___syscall_fcntl64(fd,cmd,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(fd);switch(cmd){case 0:{var arg=syscallGetVarargI();if(arg<0){return-28}while(FS.streams[arg]){arg++}var newStream;newStream=FS.dupStream(stream,arg);return newStream.fd}case 1:case 2:return 0;case 3:return stream.flags;case 4:{var arg=syscallGetVarargI();stream.flags|=arg;return 0}case 12:{var arg=syscallGetVarargP();var offset=0;HEAP16[arg+offset>>1]=2;return 0}case 13:case 14:return 0}return-28}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_fstat64(fd,buf){try{return SYSCALLS.writeStat(buf,FS.fstat(fd))}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);function ___syscall_getdents64(fd,dirp,count){try{var stream=SYSCALLS.getStreamFromFD(fd);stream.getdents||=FS.readdir(stream.path);var struct_size=280;var pos=0;var off=FS.llseek(stream,0,1);var startIdx=Math.floor(off/struct_size);var endIdx=Math.min(stream.getdents.length,startIdx+Math.floor(count/struct_size));for(var idx=startIdx;idx>3]=BigInt(id);HEAP64[dirp+pos+8>>3]=BigInt((idx+1)*struct_size);HEAP16[dirp+pos+16>>1]=280;HEAP8[dirp+pos+18]=type;stringToUTF8(name,dirp+pos+19,256);pos+=struct_size}FS.llseek(stream,idx*struct_size,0);return pos}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_getpeername(fd,addr,addrlen,d1,d2,d3){try{var sock=getSocketFromFD(fd);if(!sock.daddr){return-53}var errno=writeSockaddr(addr,sock.family,DNS.lookup_name(sock.daddr),sock.dport,addrlen);return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_getsockname(fd,addr,addrlen,d1,d2,d3){try{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.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_getsockopt(fd,level,optname,optval,optlen,d1){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.name==="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:{if(!stream.tty)return-59;return 0}case 21505:{if(!stream.tty)return-59;if(stream.tty.ops.ioctl_tcgets){var termios=stream.tty.ops.ioctl_tcgets(stream);var argp=syscallGetVarargP();HEAP32[argp>>2]=termios.c_iflag||0;HEAP32[argp+4>>2]=termios.c_oflag||0;HEAP32[argp+8>>2]=termios.c_cflag||0;HEAP32[argp+12>>2]=termios.c_lflag||0;for(var i=0;i<32;i++){HEAP8[argp+i+17]=termios.c_cc[i]||0}return 0}return 0}case 21510:case 21511:case 21512:{if(!stream.tty)return-59;return 0}case 21506:case 21507:case 21508:{if(!stream.tty)return-59;if(stream.tty.ops.ioctl_tcsets){var argp=syscallGetVarargP();var c_iflag=HEAP32[argp>>2];var c_oflag=HEAP32[argp+4>>2];var c_cflag=HEAP32[argp+8>>2];var c_lflag=HEAP32[argp+12>>2];var c_cc=[];for(var i=0;i<32;i++){c_cc.push(HEAP8[argp+i+17])}return stream.tty.ops.ioctl_tcsets(stream.tty,op,{c_iflag,c_oflag,c_cflag,c_lflag,c_cc})}return 0}case 21519:{if(!stream.tty)return-59;var argp=syscallGetVarargP();HEAP32[argp>>2]=0;return 0}case 21520:{if(!stream.tty)return-59;return-28}case 21537:case 21531:{var argp=syscallGetVarargP();return FS.ioctl(stream,op,argp)}case 21523:{if(!stream.tty)return-59;if(stream.tty.ops.ioctl_tiocgwinsz){var winsize=stream.tty.ops.ioctl_tiocgwinsz(stream.tty);var argp=syscallGetVarargP();HEAP16[argp>>1]=winsize[0];HEAP16[argp+2>>1]=winsize[1]}return 0}case 21524:{if(!stream.tty)return-59;return 0}case 21515:{if(!stream.tty)return-59;return 0}default:return-28}}catch(e){if(typeof FS=="undefined"||!(e.name==="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.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_lstat64(path,buf){try{path=SYSCALLS.getStr(path);return SYSCALLS.writeStat(buf,FS.lstat(path))}catch(e){if(typeof FS=="undefined"||!(e.name==="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&~6400;path=SYSCALLS.calculateAt(dirfd,path,allowEmpty);return SYSCALLS.writeStat(buf,nofollow?FS.lstat(path):FS.stat(path))}catch(e){if(typeof FS=="undefined"||!(e.name==="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?syscallGetVarargI():0;return FS.open(path,flags,mode).fd}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}var PIPEFS={BUCKET_BUFFER_SIZE:8192,mount(mount){return FS.createNode(null,"/",16384|511,0)},createPipe(){var pipe={buckets:[],refcnt:2,timestamp:new Date};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:{getattr(stream){var node=stream.node;var timestamp=node.pipe.timestamp;return{dev:14,ino:node.id,mode:4480,nlink:1,uid:0,gid:0,rdev:0,size:0,atime:timestamp,mtime:timestamp,ctime:timestamp,blksize:4096,blocks:0}},poll(stream){var pipe=stream.node.pipe;if((stream.flags&2097155)===1){return 256|4}for(var bucket of pipe.buckets){if(bucket.offset-bucket.roffset>0){return 64|1}}return 0},dup(stream){stream.node.pipe.refcnt++},ioctl(stream,request,varargs){return 28},fsync(stream){return 28},read(stream,buffer,offset,length,position){var pipe=stream.node.pipe;var currentLength=0;for(var bucket of pipe.buckets){currentLength+=bucket.offset-bucket.roffset}var data=buffer.subarray(offset,offset+length);if(length<=0){return 0}if(currentLength==0){throw new FS.ErrnoError(6)}var toRead=Math.min(currentLength,length);var totalRead=toRead;var toRemove=0;for(var bucket of pipe.buckets){var bucketSize=bucket.offset-bucket.roffset;if(toRead<=bucketSize){var tmpSlice=bucket.buffer.subarray(bucket.roffset,bucket.offset);if(toRead=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(stream){var pipe=stream.node.pipe;pipe.refcnt--;if(pipe.refcnt===0){pipe.buckets=null}}},nextname(){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.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_poll(fds,nfds,timeout){try{var nonzero=0;for(var i=0;i>2];var events=HEAP16[pollfd+4>>1];var mask=32;var stream=FS.getStream(fd);if(stream){mask=SYSCALLS.DEFAULT_POLLMASK;if(stream.stream_ops.poll){mask=stream.stream_ops.poll(stream,-1)}}mask&=events|8|16;if(mask)nonzero++;HEAP16[pollfd+6>>1]=mask}return nonzero}catch(e){if(typeof FS=="undefined"||!(e.name==="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.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_recvfrom(fd,buf,len,flags,addr,addrlen){try{var sock=getSocketFromFD(fd);var msg=sock.sock_ops.recvmsg(sock,len);if(!msg)return 0;if(addr){var errno=writeSockaddr(addr,sock.family,DNS.lookup_name(msg.addr),msg.port,addrlen)}HEAPU8.set(msg.buffer,buf);return msg.buffer.byteLength}catch(e){if(typeof FS=="undefined"||!(e.name==="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.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_sendto(fd,message,length,flags,addr,addr_len){try{var sock=getSocketFromFD(fd);if(!addr){return FS.write(sock.stream,HEAP8,message,length)}var dest=getSocketAddress(addr,addr_len);return sock.sock_ops.sendmsg(sock,HEAP8,message,length,dest.addr,dest.port)}catch(e){if(typeof FS=="undefined"||!(e.name==="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.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_stat64(path,buf){try{path=SYSCALLS.getStr(path);return SYSCALLS.writeStat(buf,FS.stat(path))}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_symlinkat(target,dirfd,linkpath){try{target=SYSCALLS.getStr(target);linkpath=SYSCALLS.getStr(linkpath);linkpath=SYSCALLS.calculateAt(dirfd,linkpath);FS.symlink(target,linkpath);return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_unlinkat(dirfd,path,flags){try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);if(!flags){FS.unlink(path)}else if(flags===512){FS.rmdir(path)}else{return-28}return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}var __abort_js=()=>abort("");var __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 runtimeKeepaliveCounter=0;var __emscripten_runtime_keepalive_clear=()=>{noExitRuntime=false;runtimeKeepaliveCounter=0};var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>numINT53_MAX?NaN:Number(num);function __gmtime_js(time,tmPtr){time=bigintToI53Checked(time);var date=new Date(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){offset=bigintToI53Checked(offset);try{var stream=SYSCALLS.getStreamFromFD(fd);if(prot&2){SYSCALLS.doMsync(addr,stream,len,flags,offset)}}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}var timers={};var handleException=e=>{if(e instanceof ExitStatus||e=="unwind"){return EXITSTATUS}quit_(1,e)};var keepRuntimeAlive=()=>noExitRuntime||runtimeKeepaliveCounter>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var exitJS=(status,implicit)=>{EXITSTATUS=status;if(!keepRuntimeAlive()){exitRuntime()}_proc_exit(status)};var _exit=exitJS;var maybeExit=()=>{if(runtimeExited){return}if(!keepRuntimeAlive()){try{_exit(EXITSTATUS)}catch(e){handleException(e)}}};var callUserCallback=func=>{if(runtimeExited||ABORT){return}try{func();maybeExit()}catch(e){handleException(e)}};var _emscripten_get_now=()=>performance.now();var __setitimer_js=(which,timeout_ms)=>{if(timers[which]){clearTimeout(timers[which].id);delete timers[which]}if(!timeout_ms)return 0;var id=setTimeout(()=>{delete timers[which];callUserCallback(()=>__emscripten_timeout(which,_emscripten_get_now()))},timeout_ms);timers[which]={id,timeout_ms};return 0};var __tzset_js=(timezone,daylight,std_name,dst_name)=>{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);var extractZone=timezoneOffset=>{var sign=timezoneOffset>=0?"-":"+";var absOffset=Math.abs(timezoneOffset);var hours=String(Math.floor(absOffset/60)).padStart(2,"0");var minutes=String(absOffset%60).padStart(2,"0");return`UTC${sign}${hours}${minutes}`};var winterName=extractZone(winterOffset);var summerName=extractZone(summerOffset);if(summerOffsetDate.now();var nowIsMonotonic=1;var checkWasiClock=clock_id=>clock_id>=0&&clock_id<=3;function _clock_time_get(clk_id,ignored_precision,ptime){ignored_precision=bigintToI53Checked(ignored_precision);if(!checkWasiClock(clk_id)){return 28}var now;if(clk_id===0){now=_emscripten_date_now()}else if(nowIsMonotonic){now=_emscripten_get_now()}else{return 52}var nsec=Math.round(now*1e3*1e3);HEAP64[ptime>>3]=BigInt(nsec);return 0}var getHeapMax=()=>2147483648;var _emscripten_get_heap_max=()=>getHeapMax();var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}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,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var ENV={};var getExecutableName=()=>thisProgram||"./this.program";var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(typeof navigator=="object"&&navigator.language||"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};var _environ_get=(__environ,environ_buf)=>{var bufSize=0;var envp=0;for(var string of getEnvStrings()){var ptr=environ_buf+bufSize;HEAPU32[__environ+envp>>2]=ptr;bufSize+=stringToUTF8(string,ptr,Infinity)+1;envp+=4}return 0};var _environ_sizes_get=(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;for(var string of strings){bufSize+=lengthBytesUTF8(string)+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.name==="ErrnoError"))throw e;return e.errno}}function _fd_fdstat_get(fd,pbuf){try{var rightsBase=0;var rightsInheriting=0;var flags=0;{var stream=SYSCALLS.getStreamFromFD(fd);var type=stream.tty?2:FS.isDir(stream.mode)?3:FS.isLink(stream.mode)?7:4}HEAP8[pbuf]=type;HEAP16[pbuf+2>>1]=flags;HEAP64[pbuf+8>>3]=BigInt(rightsBase);HEAP64[pbuf+16>>3]=BigInt(rightsInheriting);return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return e.errno}}var 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.name==="ErrnoError"))throw e;return e.errno}}function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);try{if(isNaN(offset))return 61;var stream=SYSCALLS.getStreamFromFD(fd);FS.llseek(stream,offset,whence);HEAP64[newOffset>>3]=BigInt(stream.position);if(stream.getdents&&offset===0&&whence===0)stream.getdents=null;return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return e.errno}}var 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;if(curr>2]=num;return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return e.errno}}var _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);ai=_malloc(32);HEAP32[ai+4>>2]=family;HEAP32[ai+8>>2]=type;HEAP32[ai+12>>2]=proto;HEAPU32[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,_htonl(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};var _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};var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var FS_createPath=(...args)=>FS.createPath(...args);var FS_unlink=(...args)=>FS.unlink(...args);var FS_createLazyFile=(...args)=>FS.createLazyFile(...args);var FS_createDevice=(...args)=>FS.createDevice(...args);FS.createPreloadedFile=FS_createPreloadedFile;FS.preloadFile=FS_preloadFile;FS.staticInit();{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["preloadPlugins"])preloadPlugins=Module["preloadPlugins"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}Module["callMain"]=callMain;Module["addRunDependency"]=addRunDependency;Module["removeRunDependency"]=removeRunDependency;Module["FS_preloadFile"]=FS_preloadFile;Module["FS_unlink"]=FS_unlink;Module["FS_createPath"]=FS_createPath;Module["FS_createDevice"]=FS_createDevice;Module["FS"]=FS;Module["FS_createDataFile"]=FS_createDataFile;Module["FS_createLazyFile"]=FS_createLazyFile;Module["TTY"]=TTY;var _main,_fflush,_ntohs,_malloc,___funcs_on_exit,_htonl,_htons,_emscripten_builtin_memalign,__emscripten_timeout,__emscripten_stack_alloc;function assignWasmExports(wasmExports){Module["_main"]=_main=wasmExports["aa"];_fflush=wasmExports["ba"];_ntohs=wasmExports["ca"];_malloc=wasmExports["da"];___funcs_on_exit=wasmExports["ea"];_htonl=wasmExports["fa"];_htons=wasmExports["ga"];_emscripten_builtin_memalign=wasmExports["ha"];__emscripten_timeout=wasmExports["ia"];__emscripten_stack_alloc=wasmExports["ja"]}var wasmImports={D:___call_sighandler,z:___syscall__newselect,u:___syscall_accept4,t:___syscall_bind,V:___syscall_chmod,s:___syscall_connect,W:___syscall_faccessat,d:___syscall_fcntl64,T:___syscall_fstat64,C:___syscall_getdents64,r:___syscall_getpeername,q:___syscall_getsockname,g:___syscall_getsockopt,f:___syscall_ioctl,p:___syscall_listen,Q:___syscall_lstat64,R:___syscall_newfstatat,k:___syscall_openat,H:___syscall_pipe,G:___syscall_poll,B:___syscall_readlinkat,o:___syscall_recvfrom,A:___syscall_renameat,n:___syscall_sendto,i:___syscall_socket,S:___syscall_stat64,y:___syscall_symlinkat,w:___syscall_unlinkat,X:__abort_js,F:__emscripten_fs_load_embedded_files,E:__emscripten_runtime_keepalive_clear,J:__gmtime_js,I:__munmap_js,j:__setitimer_js,K:__tzset_js,U:_clock_time_get,l:_emscripten_date_now,x:_emscripten_get_heap_max,a:_emscripten_get_now,v:_emscripten_resize_heap,N:_environ_get,O:_environ_sizes_get,b:_exit,c:_fd_close,M:_fd_fdstat_get,h:_fd_read,L:_fd_seek,e:_fd_write,P:_getaddrinfo,Y:_getnameinfo,m:_proc_exit};function callMain(args=[]){var entryFunction=_main;args.unshift(thisProgram);var argc=args.length;var argv=stackAlloc((argc+1)*4);var argv_ptr=argv;args.forEach(arg=>{HEAPU32[argv_ptr>>2]=stringToUTF8OnStack(arg);argv_ptr+=4});HEAPU32[argv_ptr>>2]=0;try{var ret=entryFunction(argc,argv);exitJS(ret,true);return ret}catch(e){return handleException(e)}}function run(args=arguments_){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();preMain();readyPromiseResolve?.(Module);Module["onRuntimeInitialized"]?.();var noInitialRun=Module["noInitialRun"]||true;if(!noInitialRun)callMain(args);postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;wasmExports=await (createWasm());run();if(runtimeInitialized){moduleRtn=Module}else{moduleRtn=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject})} 2 | ;return moduleRtn}})();if(typeof exports==="object"&&typeof module==="object"){module.exports=EmscrJSR_openssl;module.exports.default=EmscrJSR_openssl}else if(typeof define==="function"&&define["amd"])define([],()=>EmscrJSR_openssl); 3 | --------------------------------------------------------------------------------