diff --git a/Cargo.toml b/Cargo.toml index 1a0705b..07aba3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,40 +1,21 @@ [package] -name = "vpn_libs_endpoint" +name = "vpn_endpoint" version = "0.1.0" authors = ["Sergei Gunchenko "] edition = "2021" -[lib] -name = "vpn_libs_endpoint" -path = "src/lib.rs" +[[bin]] +name = "vpn_endpoint" +path = "main.rs" -[build-dependencies] -cc = "1.0" +[workspace] +# The empty workspace prevents redundant builds of each component [dependencies] +vpn_libs_endpoint = { version = "0.1", path = "lib" } +chrono = "0.4" log = "0.4" -quiche = { version = "0.12", features = ["qlog"] } -ring = "0.16" -lazy_static = "1.4" -httparse = "1.7.1" -rustls = { version = "0.20", features = ["logging"] } -base64 = "0.13" -libc = "0.2" -tokio = { version = "1.18.0", features = ["net", "rt", "sync", "time", "macros", "rt-multi-thread"] } -h2 = "0.3" -http = "0.2" -tokio-rustls = "0.23" -rustls-pemfile = "1.0.0" -bytes = "1.1" -async-trait = "0.1" -futures = "0.3" -num_cpus = "1.13" -dynfmt = { version = "0.1", features = ["curly"], default-features = false } -serde = "1.0" -async-socks5 = "0.5" -radius = "0.2.1" -rust-crypto = "0.2.36" -md4 = "0.10.1" -des = "0.8.1" -cached = "0.34.0" -prometheus = { version = "0.13.0", features = ["process"] } +serde_json = "1.0" +clap = "3.1" +tokio = { version = "1.18.0", features = ["rt-multi-thread", "signal"] } +sentry = { version = "0.25.0", default-features = false, features = ["backtrace", "panic", "reqwest", "rustls", "contexts"] } diff --git a/README.md b/README.md index aff1951..1763474 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ # AdGuard VPN endpoint -## Building the library - -### Prerequisites - -* Rust 1.59.0 or higher: use a preferred way from https://www.rust-lang.org/tools/install +## Running endpoint ### Building @@ -18,10 +14,66 @@ cargo build --release ``` to build the release version. -## Building the executable +### Issuing self-signed cert and keys (RSA) -See [here](bin/README.md) +Execute the following commands in Terminal: +```shell +openssl req -config -new -x509 -sha256 -newkey rsa:2048 -nodes -days 1000 -keyout key.pem -out cert.pem +``` +where +* `` is an optional OpenSSL request template file -## License +### Endpoint configuration -Apache 2.0 +An endpoint can be configured using a JSON file. The file struct reflects the library settings +(see `struct Settings` in [settings.rs](./lib/src/settings.rs)). +The very basic configuration file can be found in [the example](#example-endpoint). +To explore the full set of settings see docs in [settings.rs](./lib/src/settings.rs). + +### Running + +To run the binary through `cargo`, execute the following commands in Terminal: +```shell +cargo run --bin vpn_endpoint -- +``` + +To run the binary directly, execute the following commands in Terminal: +```shell +/vpn_endpoint +``` +where `` is determined by the build command (by default it is `./target/debug` or +`./target/release` depending on the build type). + +### Example endpoint + +For a quic setup you can run the example endpoint (see [here](./examples/my_vpn)). +It shows the essential things needed to run an instance. +To start one run the following commands in Terminal: +```shell +cd ./examples/my_vpn && ./run.sh +``` +It may ask you to enter some information for generating your certificate. +Skip it clicking `enter` if it does not matter. + +### Testing with Google Chrome + +1) 2 options: + * Add the generated certificate to the trusted store and run the Google Chrome + * Run the Google Chrome from Terminal like this: + ```shell + google-chrome --ignore-certificate-errors + ``` + **IMPORTANT:** the second option should be used just for testing, it removes the first line + of defence against malicious resources +2) Set up the endpoint as an HTTPS proxy server in the browser (either via browser settings or +using an extension like `Proxy SwitchyOmega`) + +### Collecting metrics + +Common ways: + +* As plain text: send a GET request to `:/metrics`, for example, using CURL +or a web browser +* Set up Prometheus: + 1) Configure the instance to monitor the endpoint metrics (see [here](https://prometheus.io/docs/prometheus/latest/getting_started/#configure-prometheus-to-monitor-the-sample-targets)) + 2) Use [the graph interface](https://prometheus.io/docs/prometheus/latest/getting_started/#using-the-graphing-interface) diff --git a/bin/Cargo.toml b/bin/Cargo.toml deleted file mode 100644 index 7e74b09..0000000 --- a/bin/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "vpn_endpoint" -version = "0.1.0" -authors = ["Sergei Gunchenko "] -edition = "2021" - -[[bin]] -name = "vpn_endpoint" -path = "main.rs" - -[dependencies] -vpn_libs_endpoint = { version = "0.1", path = ".." } -chrono = "0.4" -log = "0.4" -serde_json = "1.0" -clap = "3.1" -tokio = { version = "1.18.0", features = ["rt-multi-thread", "signal"] } -sentry = { version = "0.25.0", default-features = false, features = ["backtrace", "panic", "reqwest", "rustls", "contexts"] } diff --git a/bin/README.md b/bin/README.md deleted file mode 100644 index 842dc3d..0000000 --- a/bin/README.md +++ /dev/null @@ -1,77 +0,0 @@ -# Running endpoint - -## Building - -Execute the following commands in Terminal: -```shell -cargo build -``` -to build the debug version, or -```shell -cargo build --release -``` -to build the release version. - -## Issuing self-signed cert and keys (RSA) - -Execute the following commands in Terminal: -```shell -openssl req -config -new -x509 -sha256 -newkey rsa:2048 -nodes -days 1000 -keyout key.pem -out cert.pem -``` -where -* `` is an optional OpenSSL request template file - -## Endpoint configuration - -An endpoint can be configured using a JSON file. The file struct reflects the library settings -(see `struct Settings` in [settings.rs](../src/settings.rs)). -The very basic configuration file can be found in [the example](#example-endpoint). -To explore the full set of settings see docs in [settings.rs](../src/settings.rs). - -## Running - -To run the binary through `cargo`, execute the following commands in Terminal: -```shell -cargo run --bin vpn_endpoint -- -``` - -To run the binary directly, execute the following commands in Terminal: -```shell -/vpn_endpoint -``` -where `` is determined by the build command (by default it is `./target/debug` or -`./target/release` depending on the build type). - -## Example endpoint - -For a quic setup you can run the example endpoint (see [here](../examples/my_vpn)). -It shows the essential things needed to run an instance. -To start one run the following commands in Terminal: -```shell -cd ../examples/my_vpn && ./run.sh -``` -It may ask you to enter some information for generating your certificate. -Skip it clicking `enter` if it does not matter. - -## Testing with Google Chrome - -1) 2 options: - * Add the generated certificate to the trusted store and run the Google Chrome - * Run the Google Chrome from Terminal like this: - ```shell - google-chrome --ignore-certificate-errors - ``` - **IMPORTANT:** the second option should be used just for testing, it removes the first line - of defence against malicious resources -2) Set up the endpoint as an HTTPS proxy server in the browser (either via browser settings or -using an extension like `Proxy SwitchyOmega`) - -## Collecting metrics - -Common ways: - -* As plain text: send a GET request to `:/metrics`, for example, using CURL -or a web browser -* Set up Prometheus: - 1) Configure the instance to monitor the endpoint metrics (see [here](https://prometheus.io/docs/prometheus/latest/getting_started/#configure-prometheus-to-monitor-the-sample-targets)) - 2) Use [the graph interface](https://prometheus.io/docs/prometheus/latest/getting_started/#using-the-graphing-interface) diff --git a/bin/examples/my_vpn/.gitignore b/examples/my_vpn/.gitignore similarity index 100% rename from bin/examples/my_vpn/.gitignore rename to examples/my_vpn/.gitignore diff --git a/bin/examples/my_vpn/auth_info.txt b/examples/my_vpn/auth_info.txt similarity index 100% rename from bin/examples/my_vpn/auth_info.txt rename to examples/my_vpn/auth_info.txt diff --git a/bin/examples/my_vpn/openssl.conf b/examples/my_vpn/openssl.conf similarity index 100% rename from bin/examples/my_vpn/openssl.conf rename to examples/my_vpn/openssl.conf diff --git a/bin/examples/my_vpn/run.sh b/examples/my_vpn/run.sh similarity index 100% rename from bin/examples/my_vpn/run.sh rename to examples/my_vpn/run.sh diff --git a/bin/examples/my_vpn/vpn.conf b/examples/my_vpn/vpn.conf similarity index 100% rename from bin/examples/my_vpn/vpn.conf rename to examples/my_vpn/vpn.conf diff --git a/lib/Cargo.toml b/lib/Cargo.toml new file mode 100644 index 0000000..1a0705b --- /dev/null +++ b/lib/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "vpn_libs_endpoint" +version = "0.1.0" +authors = ["Sergei Gunchenko "] +edition = "2021" + +[lib] +name = "vpn_libs_endpoint" +path = "src/lib.rs" + +[build-dependencies] +cc = "1.0" + +[dependencies] +log = "0.4" +quiche = { version = "0.12", features = ["qlog"] } +ring = "0.16" +lazy_static = "1.4" +httparse = "1.7.1" +rustls = { version = "0.20", features = ["logging"] } +base64 = "0.13" +libc = "0.2" +tokio = { version = "1.18.0", features = ["net", "rt", "sync", "time", "macros", "rt-multi-thread"] } +h2 = "0.3" +http = "0.2" +tokio-rustls = "0.23" +rustls-pemfile = "1.0.0" +bytes = "1.1" +async-trait = "0.1" +futures = "0.3" +num_cpus = "1.13" +dynfmt = { version = "0.1", features = ["curly"], default-features = false } +serde = "1.0" +async-socks5 = "0.5" +radius = "0.2.1" +rust-crypto = "0.2.36" +md4 = "0.10.1" +des = "0.8.1" +cached = "0.34.0" +prometheus = { version = "0.13.0", features = ["process"] } diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 0000000..a5f4557 --- /dev/null +++ b/lib/README.md @@ -0,0 +1,23 @@ +# AdGuard VPN endpoint + +## Building the library + +### Prerequisites + +* Rust 1.59.0 or higher: use a preferred way from https://www.rust-lang.org/tools/install + +### Building + +Execute the following commands in Terminal: +```shell +cargo build +``` +to build the debug version, or +```shell +cargo build --release +``` +to build the release version. + +## License + +Apache 2.0 diff --git a/build.rs b/lib/build.rs similarity index 100% rename from build.rs rename to lib/build.rs diff --git a/src/authentication/file_based.rs b/lib/src/authentication/file_based.rs similarity index 100% rename from src/authentication/file_based.rs rename to lib/src/authentication/file_based.rs diff --git a/src/authentication/mod.rs b/lib/src/authentication/mod.rs similarity index 100% rename from src/authentication/mod.rs rename to lib/src/authentication/mod.rs diff --git a/src/authentication/radius/eap.rs b/lib/src/authentication/radius/eap.rs similarity index 100% rename from src/authentication/radius/eap.rs rename to lib/src/authentication/radius/eap.rs diff --git a/src/authentication/radius/mod.rs b/lib/src/authentication/radius/mod.rs similarity index 100% rename from src/authentication/radius/mod.rs rename to lib/src/authentication/radius/mod.rs diff --git a/src/authentication/radius/ms_chap_v2.rs b/lib/src/authentication/radius/ms_chap_v2.rs similarity index 100% rename from src/authentication/radius/ms_chap_v2.rs rename to lib/src/authentication/radius/ms_chap_v2.rs diff --git a/src/authentication/radius/radius_utils.rs b/lib/src/authentication/radius/radius_utils.rs similarity index 100% rename from src/authentication/radius/radius_utils.rs rename to lib/src/authentication/radius/radius_utils.rs diff --git a/src/core.rs b/lib/src/core.rs similarity index 100% rename from src/core.rs rename to lib/src/core.rs diff --git a/src/datagram_pipe.rs b/lib/src/datagram_pipe.rs similarity index 100% rename from src/datagram_pipe.rs rename to lib/src/datagram_pipe.rs diff --git a/src/direct_forwarder.rs b/lib/src/direct_forwarder.rs similarity index 100% rename from src/direct_forwarder.rs rename to lib/src/direct_forwarder.rs diff --git a/src/downstream.rs b/lib/src/downstream.rs similarity index 100% rename from src/downstream.rs rename to lib/src/downstream.rs diff --git a/src/downstream_protocol_selector.rs b/lib/src/downstream_protocol_selector.rs similarity index 100% rename from src/downstream_protocol_selector.rs rename to lib/src/downstream_protocol_selector.rs diff --git a/src/forwarder.rs b/lib/src/forwarder.rs similarity index 100% rename from src/forwarder.rs rename to lib/src/forwarder.rs diff --git a/src/http1_codec.rs b/lib/src/http1_codec.rs similarity index 100% rename from src/http1_codec.rs rename to lib/src/http1_codec.rs diff --git a/src/http2_codec.rs b/lib/src/http2_codec.rs similarity index 100% rename from src/http2_codec.rs rename to lib/src/http2_codec.rs diff --git a/src/http3_codec.rs b/lib/src/http3_codec.rs similarity index 100% rename from src/http3_codec.rs rename to lib/src/http3_codec.rs diff --git a/src/http_codec.rs b/lib/src/http_codec.rs similarity index 100% rename from src/http_codec.rs rename to lib/src/http_codec.rs diff --git a/src/http_datagram_codec.rs b/lib/src/http_datagram_codec.rs similarity index 100% rename from src/http_datagram_codec.rs rename to lib/src/http_datagram_codec.rs diff --git a/src/http_downstream.rs b/lib/src/http_downstream.rs similarity index 100% rename from src/http_downstream.rs rename to lib/src/http_downstream.rs diff --git a/src/http_forwarded_stream.rs b/lib/src/http_forwarded_stream.rs similarity index 100% rename from src/http_forwarded_stream.rs rename to lib/src/http_forwarded_stream.rs diff --git a/src/http_icmp_codec.rs b/lib/src/http_icmp_codec.rs similarity index 100% rename from src/http_icmp_codec.rs rename to lib/src/http_icmp_codec.rs diff --git a/src/http_udp_codec.rs b/lib/src/http_udp_codec.rs similarity index 100% rename from src/http_udp_codec.rs rename to lib/src/http_udp_codec.rs diff --git a/src/icmp_forwarder.rs b/lib/src/icmp_forwarder.rs similarity index 100% rename from src/icmp_forwarder.rs rename to lib/src/icmp_forwarder.rs diff --git a/src/icmp_utils.rs b/lib/src/icmp_utils.rs similarity index 100% rename from src/icmp_utils.rs rename to lib/src/icmp_utils.rs diff --git a/src/lib.rs b/lib/src/lib.rs similarity index 100% rename from src/lib.rs rename to lib/src/lib.rs diff --git a/src/log_utils.rs b/lib/src/log_utils.rs similarity index 100% rename from src/log_utils.rs rename to lib/src/log_utils.rs diff --git a/src/metrics.rs b/lib/src/metrics.rs similarity index 100% rename from src/metrics.rs rename to lib/src/metrics.rs diff --git a/src/net_utils.c b/lib/src/net_utils.c similarity index 100% rename from src/net_utils.c rename to lib/src/net_utils.c diff --git a/src/net_utils.rs b/lib/src/net_utils.rs similarity index 100% rename from src/net_utils.rs rename to lib/src/net_utils.rs diff --git a/src/pipe.rs b/lib/src/pipe.rs similarity index 100% rename from src/pipe.rs rename to lib/src/pipe.rs diff --git a/src/quic_multiplexer.rs b/lib/src/quic_multiplexer.rs similarity index 100% rename from src/quic_multiplexer.rs rename to lib/src/quic_multiplexer.rs diff --git a/src/settings.rs b/lib/src/settings.rs similarity index 99% rename from src/settings.rs rename to lib/src/settings.rs index 61ef36a..87d2f51 100644 --- a/src/settings.rs +++ b/lib/src/settings.rs @@ -352,7 +352,7 @@ impl Default for Settings { ListenProtocolSettings::Http2(Http2Settings::builder().build()), ListenProtocolSettings::Quic(QuicSettings::builder().build()), ], - authorizer: Settings::default_authorizer(), + authenticator: Settings::default_authenticator(), icmp: None, metrics: Default::default(), } diff --git a/src/shutdown.rs b/lib/src/shutdown.rs similarity index 100% rename from src/shutdown.rs rename to lib/src/shutdown.rs diff --git a/src/socks5_forwarder.rs b/lib/src/socks5_forwarder.rs similarity index 100% rename from src/socks5_forwarder.rs rename to lib/src/socks5_forwarder.rs diff --git a/src/tcp_forwarder.rs b/lib/src/tcp_forwarder.rs similarity index 100% rename from src/tcp_forwarder.rs rename to lib/src/tcp_forwarder.rs diff --git a/src/tls_listener.rs b/lib/src/tls_listener.rs similarity index 100% rename from src/tls_listener.rs rename to lib/src/tls_listener.rs diff --git a/src/tunnel.rs b/lib/src/tunnel.rs similarity index 100% rename from src/tunnel.rs rename to lib/src/tunnel.rs diff --git a/src/udp_forwarder.rs b/lib/src/udp_forwarder.rs similarity index 100% rename from src/udp_forwarder.rs rename to lib/src/udp_forwarder.rs diff --git a/src/udp_pipe.rs b/lib/src/udp_pipe.rs similarity index 100% rename from src/udp_pipe.rs rename to lib/src/udp_pipe.rs diff --git a/src/utils.rs b/lib/src/utils.rs similarity index 100% rename from src/utils.rs rename to lib/src/utils.rs diff --git a/bin/main.rs b/main.rs similarity index 100% rename from bin/main.rs rename to main.rs