diff --git a/.gitignore b/.gitignore index d1ca2a8..d367d31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ /client/build /client/out -/client/cacert.pem -/client/libcurl.data -/srelay* -/websockify \ No newline at end of file +/server/.venv \ No newline at end of file diff --git a/README.md b/README.md index 6cdb526..2431547 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,13 @@ This is an experimental port of [libcurl](https://curl.se/libcurl/) to WebAssemb - Support for up to TLS 1.3 ## Building: -You can build this project by cloning this repo and running the following commands: +You can build this project by running the following commands: ``` +git clone https://github.com/ading2210/libcurl.js cd libcurl.js/client ./build.sh ``` -Make sure you have emscripten, git, and the various C build tools installed. +Make sure you have emscripten, git, and the various C build tools installed. The build script will generate `client/out/libcurl.js`. ## Javascript API: @@ -33,15 +34,22 @@ document.addEventListener("libcurl_load", ()=>{ Once loaded, there will be a `window.libcurl` object which includes all the API functions. -### Making HTTP Requests -To make HTTP requests, use `libcurl.fetch`, which takes the same arguments as the browser's regular `fetch` function. Like the standard Fetch API, `libcurl.fetch` will also return a `Response` object. +### Making HTTP Requests: +To perform HTTP requests, use `libcurl.fetch`, which takes the same arguments as the browser's regular `fetch` function. Like the standard Fetch API, `libcurl.fetch` will also return a `Response` object. ```js let r = await libcurl.fetch("https://ading.dev"); console.log(await r.text()); ``` ## Proxy Server: -The proxy server consists of a SOCKS5 proxy server behind a websocket TCP reverse proxy. Code for running this as a single program is planned. +The proxy server consists of a [SOCKS5 proxy server](https://github.com/Amaindex/asyncio-socks-server) behind a [websocket TCP proxy](https://github.com/novnc/websockify). + +To host the proxy server, run the following commands: +``` +git clone https://github.com/ading2210/libcurl.js +cd libcurl.js/server +./run.sh +``` ## Copyright: This project is licensed under the GNU AGPL v3. diff --git a/client/build.sh b/client/build.sh index d8afe1c..d1124e3 100755 --- a/client/build.sh +++ b/client/build.sh @@ -4,7 +4,6 @@ set -e INCLUDE_DIR="build/curl-wasm/include/" LIB_DIR="build/curl-wasm/lib/" -CACERT_FILE="cacert.pem" OUT_FILE="out/libcurl.js" MODULE_FILE="out/libcurl_module.js" WRAPPER_SOURCE="main.js" diff --git a/server/main.py b/server/main.py new file mode 100644 index 0000000..28e2ddb --- /dev/null +++ b/server/main.py @@ -0,0 +1,43 @@ +import logging +import threading +import os + +from asyncio_socks_server.app import SocksServer +from websockify.websocketproxy import WebSocketProxy + +#start a socks5 proxy as well as websockify + +def setup_logging(prefix): + stderr_handler = logging.StreamHandler() + stderr_handler.setLevel(logging.DEBUG) + log_formatter = logging.Formatter(prefix + "%(message)s") + stderr_handler.setFormatter(log_formatter) + root = logging.getLogger() + root.addHandler(stderr_handler) + root.setLevel(logging.INFO) + +def start_websockify(): + options = { + "listen_host": "127.0.0.1", + "listen_port": 6001, + "target_host": "127.0.0.1", + "target_port": 1080 + } + + server = WebSocketProxy(**options) + server.start_server() + +def start_socks(): + socks_app = SocksServer( + LISTEN_HOST="127.0.0.1", + LISTEN_PORT=1080 + ) + socks_app.run() + +if __name__ == "__main__": + pid = os.fork() + if pid == 0: + setup_logging("[websockify] ") + start_websockify() + else: + start_socks() \ No newline at end of file diff --git a/server/requirements.txt b/server/requirements.txt new file mode 100644 index 0000000..3241b52 --- /dev/null +++ b/server/requirements.txt @@ -0,0 +1,2 @@ +websockify +asyncio-socks-server \ No newline at end of file diff --git a/server/run.sh b/server/run.sh new file mode 100755 index 0000000..09af827 --- /dev/null +++ b/server/run.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +#install dependencies and run the proxy server + +set -e + +if [ ! -d ".venv" ]; then + python3 -m venv .venv +fi +source .venv/bin/activate + +if ! python3 -c "import asyncio_socks_server, websockify" 2> /dev/null; then + pip3 install -r requirements.txt +fi + +python3 main.py \ No newline at end of file