initial commit

This commit is contained in:
ading2210 2024-01-01 07:25:49 -05:00
commit 27aa9ff74c
8 changed files with 134 additions and 0 deletions

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
/curl
/curl-wasm
/openssl
/openssl-wasm
/srelay*
/websockify
/a.out*
/cacert.pem

5
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"clangd.fallbackFlags": [
"-I/usr/share/emscripten/cache/sysroot/include/"
]
}

6
build.sh Executable file
View file

@ -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

26
curl.sh Executable file
View file

@ -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 ..

10
index.html Normal file
View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<script src="./a.out.js"></script>
<script src="./main.js"></script>
</head>
<body>
<p>emscripten tests</p>
</body>
</html>

34
main.c Normal file
View file

@ -0,0 +1,34 @@
#include <stdio.h>
#include <curl/curl.h>
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;
}

21
main.js Normal file
View file

@ -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;
};

24
openssl.sh Executable file
View file

@ -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 ..