Pull request #13: Turn the project structure inside out

Squashed commit of the following:

commit 3e8836cf2ac92ad22291d83b31e9ab83cbdb0330
Author: Sergei Gunchenko <s.gunchenko@adguard.com>
Date:   Mon May 23 19:34:51 2022 +0300

    add comment

commit f08a48bd6c7c386814417f89b6b818d1bfae8613
Author: Sergei Gunchenko <s.gunchenko@adguard.com>
Date:   Mon May 23 19:28:36 2022 +0300

    Fix readmes

commit a83825713de051cdc407a3885b0cab50739d9876
Author: Sergei Gunchenko <s.gunchenko@adguard.com>
Date:   Mon May 23 19:23:54 2022 +0300

    Fix merge artifact

commit fae5b022123a664b34ec3a5104f90d7f6405196f
Author: Sergei Gunchenko <s.gunchenko@adguard.com>
Date:   Mon May 23 19:23:27 2022 +0300

    Turn the project structure inside out
This commit is contained in:
Sergei Gunchenko 2022-05-24 12:49:06 +03:00
parent a6677254eb
commit 60c57ee112
52 changed files with 137 additions and 136 deletions

View file

@ -1,40 +1,21 @@
[package]
name = "vpn_libs_endpoint"
name = "vpn_endpoint"
version = "0.1.0"
authors = ["Sergei Gunchenko <s.gunchenko@adguard.com>"]
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"] }

View file

@ -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 <openssl.conf> -new -x509 -sha256 -newkey rsa:2048 -nodes -days 1000 -keyout key.pem -out cert.pem
```
where
* `<openssl.conf>` 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 -- <path/to/vpn.config>
```
To run the binary directly, execute the following commands in Terminal:
```shell
<path/to/target>/vpn_endpoint <path/to/vpn.config>
```
where `<path/to/target>` 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 `<ip>:<port>/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)

View file

@ -1,18 +0,0 @@
[package]
name = "vpn_endpoint"
version = "0.1.0"
authors = ["Sergei Gunchenko <s.gunchenko@adguard.com>"]
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"] }

View file

@ -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 <openssl.conf> -new -x509 -sha256 -newkey rsa:2048 -nodes -days 1000 -keyout key.pem -out cert.pem
```
where
* `<openssl.conf>` 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 -- <path/to/vpn.config>
```
To run the binary directly, execute the following commands in Terminal:
```shell
<path/to/target>/vpn_endpoint <path/to/vpn.config>
```
where `<path/to/target>` 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 `<ip>:<port>/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)

40
lib/Cargo.toml Normal file
View file

@ -0,0 +1,40 @@
[package]
name = "vpn_libs_endpoint"
version = "0.1.0"
authors = ["Sergei Gunchenko <s.gunchenko@adguard.com>"]
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"] }

23
lib/README.md Normal file
View file

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

View file

@ -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(),
}