From 27aa9ff74c190d55a739e8ef4575b2548df9bb9a Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 1 Jan 2024 07:25:49 -0500 Subject: [PATCH] initial commit --- .gitignore | 8 ++++++++ .vscode/settings.json | 5 +++++ build.sh | 6 ++++++ curl.sh | 26 ++++++++++++++++++++++++++ index.html | 10 ++++++++++ main.c | 34 ++++++++++++++++++++++++++++++++++ main.js | 21 +++++++++++++++++++++ openssl.sh | 24 ++++++++++++++++++++++++ 8 files changed, 134 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100755 build.sh create mode 100755 curl.sh create mode 100644 index.html create mode 100644 main.c create mode 100644 main.js create mode 100755 openssl.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f04f5a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/curl +/curl-wasm +/openssl +/openssl-wasm +/srelay* +/websockify +/a.out* +/cacert.pem \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..eb7c70d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "clangd.fallbackFlags": [ + "-I/usr/share/emscripten/cache/sysroot/include/" + ] +} \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..bd74d52 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +if [ ! -f cacert.pem ]; then + wget "https://curl.se/ca/cacert.pem" +fi +emcc main.c -lcurl -lssl -lcrypto -I curl-wasm/include/ -L curl-wasm/lib/ -lwebsocket.js -sWEBSOCKET_URL=wss://debug.ading.dev/ws -pthread -sPROXY_TO_PTHREAD --preload-file cacert.pem -Os \ No newline at end of file diff --git a/curl.sh b/curl.sh new file mode 100755 index 0000000..949bf96 --- /dev/null +++ b/curl.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +#compile openssl for use with emscripten + +CORE_COUNT=$(nproc --all) +PREFIX=$(realpath curl-wasm) +OPENSSL_PREFIX=$(realpath openssl-wasm) +mkdir -p $PREFIX + +rm -rf curl +git clone -b master --depth=1 https://github.com/curl/curl +cd curl + +autoreconf -fi +emconfigure ./configure --host i686-linux --prefix=$PREFIX --disable-shared --disable-threaded-resolver --without-libpsl --disable-netrc --disable-ipv6 --disable-tftp --disable-ntlm-wb --with-ssl=$OPENSSL_PREFIX +emmake make -j$CORE_COUNT CFLAGS="-pthread" + +rm -rf $PREFIX/include/* +rm -rf $PREFIX/lib/* +mkdir -p $PREFIX/include +mkdir -p $PREFIX/lib +cp -r include/curl $PREFIX/include +cp lib/.libs/libcurl.a $PREFIX/lib +cp -r $OPENSSL_PREFIX/* $PREFIX + +cd .. diff --git a/index.html b/index.html new file mode 100644 index 0000000..bf8d038 --- /dev/null +++ b/index.html @@ -0,0 +1,10 @@ + + + + + + + +

emscripten tests

+ + \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..8fb91d0 --- /dev/null +++ b/main.c @@ -0,0 +1,34 @@ +#include +#include + +int main() { + CURL *curl; + CURLcode res; + + char* url = "https://ading.dev/"; + + printf("downloading %s\n", url); + + curl = curl_easy_init(); + if (curl) { + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_PROXY, "socks5h://127.0.0.1:1234"); + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); + curl_easy_setopt(curl, CURLOPT_CAINFO, "/cacert.pem"); + curl_easy_setopt(curl, CURLOPT_CAPATH, "/cacert.pem"); + + /* example.com is redirected, so we tell libcurl to follow redirection */ + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} diff --git a/main.js b/main.js new file mode 100644 index 0000000..d758e1f --- /dev/null +++ b/main.js @@ -0,0 +1,21 @@ +const wsproxy_base = "wss://anura.pro/"; + +function allocate_str(str) { + return allocate(intArrayFromString(str), ALLOC_NORMAL); +} + +function websocket_connect(websocket) { + return new Promise((resolve, reject) => { + websocket.onopen = () => {resolve()} + websocket.onerror = () => {reject()} + }) +} + +async function main() { + +} + +window.onload = () => { + console.log("page loaded, waiting for emscripten module load"); + Module.onRuntimeInitialized = main; +}; \ No newline at end of file diff --git a/openssl.sh b/openssl.sh new file mode 100755 index 0000000..a39b5f2 --- /dev/null +++ b/openssl.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +#compile openssl for use with emscripten + +CORE_COUNT=$(nproc --all) +PREFIX=$(realpath openssl-wasm) +mkdir -p $PREFIX + +rm -rf openssl +git clone -b master --depth=1 https://github.com/openssl/openssl +cd openssl + +emconfigure ./Configure linux-x32 --prefix=$PREFIX -no-asm -static -no-afalgeng -no-dso -DOPENSSL_SYS_NETWARE -DSIG_DFL=0 -DSIG_IGN=0 -DHAVE_FORK=0 -DOPENSSL_NO_AFALGENG=1 -DOPENSSL_NO_SPEED=1 -DOPENSSL_NO_DYNAMIC_ENGINE -DDLOPEN_FLAG=0 +sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile +emmake make -j$CORE_COUNT build_generated libssl.a libcrypto.a + +rm -rf $PREFIX/include/* +rm -rf $PREFIX/lib/* +mkdir -p $PREFIX/include +mkdir -p $PREFIX/lib +cp -r include/openssl $PREFIX/include +cp libcrypto.a libssl.a $PREFIX/lib + +cd ..