mirror of https://github.com/dswd/vpncloud.git
Merge branch 'master' into threading
This commit is contained in:
commit
dd665784c6
|
@ -27,6 +27,7 @@ mkdir -p %{buildroot}/lib/systemd/system
|
||||||
mkdir -p %{buildroot}/usr/share/man/man1
|
mkdir -p %{buildroot}/usr/share/man/man1
|
||||||
cp %{buildroot}/../../../../../assets/example.net.disabled %{buildroot}/etc/vpncloud/example.net.disabled
|
cp %{buildroot}/../../../../../assets/example.net.disabled %{buildroot}/etc/vpncloud/example.net.disabled
|
||||||
cp %{buildroot}/../../../../../assets/vpncloud@.service %{buildroot}/lib/systemd/system/vpncloud@.service
|
cp %{buildroot}/../../../../../assets/vpncloud@.service %{buildroot}/lib/systemd/system/vpncloud@.service
|
||||||
|
cp %{buildroot}/../../../../../assets/vpncloud-wsproxy.service %{buildroot}/lib/systemd/system/vpncloud-wsproxy.service
|
||||||
cp %{buildroot}/../../../../../target/vpncloud.1.gz %{buildroot}/usr/share/man/man1/vpncloud.1.gz
|
cp %{buildroot}/../../../../../target/vpncloud.1.gz %{buildroot}/usr/share/man/man1/vpncloud.1.gz
|
||||||
cp -a * %{buildroot}
|
cp -a * %{buildroot}
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ rm -rf %{buildroot}
|
||||||
/etc/vpncloud/example.net.disabled
|
/etc/vpncloud/example.net.disabled
|
||||||
/usr/bin/vpncloud
|
/usr/bin/vpncloud
|
||||||
/lib/systemd/system/vpncloud@.service
|
/lib/systemd/system/vpncloud@.service
|
||||||
|
/lib/systemd/system/vpncloud-wsproxy.service
|
||||||
/usr/share/man/man1/vpncloud.1.gz
|
/usr/share/man/man1/vpncloud.1.gz
|
||||||
|
|
||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
|
|
||||||
This project follows [semantic versioning](http://semver.org).
|
This project follows [semantic versioning](http://semver.org).
|
||||||
|
|
||||||
### UNRELEASED
|
### v2.1.0 (2021-02-06)
|
||||||
|
|
||||||
- [added] Support for creating shell completions
|
- [added] Support for websocket proxy mode
|
||||||
- [added] Support for hook scripts to handle certain situations
|
- [added] Support for hook scripts to handle certain situations
|
||||||
|
- [added] Support for creating shell completions
|
||||||
- [removed] Removed dummy device type
|
- [removed] Removed dummy device type
|
||||||
- [changed] Updated dependencies
|
- [changed] Updated dependencies
|
||||||
- [changed] Changed Rust version to 1.49.0
|
- [changed] Changed Rust version to 1.49.0
|
||||||
- [fixed] Added missing peer address propagation
|
- [fixed] Added missing peer address propagation
|
||||||
|
- [fixed] Fixed problem with peer addresses without port
|
||||||
|
|
||||||
### v2.0.1 (2020-11-07)
|
### v2.0.1 (2020-11-07)
|
||||||
|
|
||||||
|
|
|
@ -44,12 +44,27 @@ version = "0.2.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b"
|
checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "block-buffer"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "boxfnonce"
|
name = "boxfnonce"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
@ -58,9 +73,9 @@ checksum = "5988cb1d626264ac94100be357308f29ff7cbdd3b36bda27f450a4ee3f713426"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bstr"
|
name = "bstr"
|
||||||
version = "0.2.14"
|
version = "0.2.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf"
|
checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@ -70,9 +85,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.5.0"
|
version = "3.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f07aa6688c702439a1be0307b6a94dffe1168569e45b9500c1372bc580740d59"
|
checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
|
@ -134,6 +149,12 @@ version = "0.4.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6"
|
checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpuid-bool"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "criterion"
|
name = "criterion"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
|
@ -248,6 +269,15 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "discard"
|
name = "discard"
|
||||||
version = "1.0.4"
|
version = "1.0.4"
|
||||||
|
@ -282,6 +312,16 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generic-array"
|
||||||
|
version = "0.14.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
@ -329,10 +369,22 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idna"
|
name = "httparse"
|
||||||
version = "0.2.0"
|
version = "1.3.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
|
checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iai"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de910d521f7cc3135c4de8db1cb910e0b5ed1dc6f57c381cd07e8e661ce10094"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"matches",
|
"matches",
|
||||||
"unicode-bidi",
|
"unicode-bidi",
|
||||||
|
@ -352,6 +404,15 @@ dependencies = [
|
||||||
"xmltree",
|
"xmltree",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "input_buffer"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "instant"
|
name = "instant"
|
||||||
version = "0.1.9"
|
version = "0.1.9"
|
||||||
|
@ -402,9 +463,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.84"
|
version = "0.2.86"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff"
|
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked-hash-map"
|
name = "linked-hash-map"
|
||||||
|
@ -507,6 +568,12 @@ version = "11.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opaque-debug"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.11.1"
|
version = "0.11.1"
|
||||||
|
@ -745,9 +812,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ring"
|
name = "ring"
|
||||||
version = "0.16.19"
|
version = "0.16.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "024a1e66fea74c66c66624ee5622a7ff0e4b73a13b4f5c326ddb50c708944226"
|
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -835,9 +902,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.61"
|
version = "1.0.62"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a"
|
checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
@ -846,9 +913,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_yaml"
|
name = "serde_yaml"
|
||||||
version = "0.8.15"
|
version = "0.8.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "971be8f6e4d4a47163b405a3df70d14359186f9ab0f3a3ec37df144ca1ce089f"
|
checksum = "bdd2af560da3c1fdc02cb80965289254fc35dff869810061e2d8290ee48848ae"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dtoa",
|
"dtoa",
|
||||||
"linked-hash-map",
|
"linked-hash-map",
|
||||||
|
@ -856,6 +923,19 @@ dependencies = [
|
||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha-1"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f4b312c3731e3fe78a185e6b9b911a7aa715b8e31cce117975219aab2acf285d"
|
||||||
|
dependencies = [
|
||||||
|
"block-buffer",
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"cpuid-bool",
|
||||||
|
"digest",
|
||||||
|
"opaque-debug",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha1"
|
name = "sha1"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
|
@ -886,9 +966,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "standback"
|
name = "standback"
|
||||||
version = "0.2.14"
|
version = "0.2.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c66a8cff4fa24853fdf6b51f75c6d7f8206d7c75cab4e467bcd7f25c2b1febe0"
|
checksum = "a2beb4d1860a61f571530b3f855a1b538d0200f7871c63331ecd6f17b1f014f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
@ -1089,6 +1169,32 @@ version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tungstenite"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5fe8dada8c1a3aeca77d6b51a4f1314e0f4b8e438b7b1b71e3ddaca8080e4093"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"byteorder",
|
||||||
|
"bytes",
|
||||||
|
"http",
|
||||||
|
"httparse",
|
||||||
|
"input_buffer",
|
||||||
|
"log",
|
||||||
|
"rand",
|
||||||
|
"sha-1",
|
||||||
|
"thiserror",
|
||||||
|
"url",
|
||||||
|
"utf-8",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
|
@ -1100,9 +1206,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-normalization"
|
name = "unicode-normalization"
|
||||||
version = "0.1.16"
|
version = "0.1.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606"
|
checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
]
|
]
|
||||||
|
@ -1143,6 +1249,12 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf-8"
|
||||||
|
version = "0.7.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
@ -1163,12 +1275,13 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vpncloud"
|
name = "vpncloud"
|
||||||
version = "2.0.1"
|
version = "2.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"criterion",
|
"criterion",
|
||||||
"daemonize",
|
"daemonize",
|
||||||
"fnv",
|
"fnv",
|
||||||
|
"iai",
|
||||||
"igd",
|
"igd",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
|
@ -1184,6 +1297,8 @@ dependencies = [
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
|
"tungstenite",
|
||||||
|
"url",
|
||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
28
Cargo.toml
28
Cargo.toml
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "vpncloud"
|
name = "vpncloud"
|
||||||
version = "2.0.1"
|
version = "2.1.0"
|
||||||
authors = ["Dennis Schwerdel <schwerdel@googlemail.com>"]
|
authors = ["Dennis Schwerdel <schwerdel@googlemail.com>"]
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
@ -30,18 +30,25 @@ byteorder = "1.4"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
parking_lot = "*"
|
parking_lot = "*"
|
||||||
smallvec = "1.6"
|
smallvec = "1.6"
|
||||||
|
tungstenite = { version = "0.13", optional = true, default-features = false }
|
||||||
|
url = { version = "2.2", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
criterion = "0.3"
|
criterion = { version = "0.3", features = ["html_reports"] }
|
||||||
|
iai = "0.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["nat"]
|
default = ["nat", "websocket"]
|
||||||
bench = []
|
|
||||||
nat = ["igd"]
|
nat = ["igd"]
|
||||||
|
websocket = ["tungstenite", "url"]
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "bench"
|
name = "criterion"
|
||||||
|
harness = false
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "valgrind"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
@ -55,10 +62,12 @@ lto = false
|
||||||
|
|
||||||
[package.metadata.deb]
|
[package.metadata.deb]
|
||||||
extended-description = """\
|
extended-description = """\
|
||||||
VpnCloud is a simple VPN over UDP. It creates a virtual network interface on
|
VpnCloud is a high performance peer-to-peer mesh VPN over UDP supporting strong encryption,
|
||||||
the host and forwards all received data via UDP to the destination. VpnCloud
|
NAT traversal and a simple configuration. It establishes a fully-meshed self-healing VPN
|
||||||
establishes a fully-meshed VPN network in a peer-to-peer manner. It can work
|
network in a peer-to-peer manner with strong end-to-end encryption based on elliptic curve
|
||||||
on TUN devices (IP based) and TAP devices (Ethernet based)."""
|
keys and AES-256. VpnCloud creates a virtual network interface on the host and forwards all
|
||||||
|
received data via UDP to the destination. It can work on TUN devices (IP based) and TAP
|
||||||
|
devices (Ethernet based)."""
|
||||||
license-file = ["LICENSE.md", "1"]
|
license-file = ["LICENSE.md", "1"]
|
||||||
changelog = "assets/changelog.txt"
|
changelog = "assets/changelog.txt"
|
||||||
section = "net"
|
section = "net"
|
||||||
|
@ -68,6 +77,7 @@ assets = [
|
||||||
["target/release/vpncloud", "/usr/bin/vpncloud", "755"],
|
["target/release/vpncloud", "/usr/bin/vpncloud", "755"],
|
||||||
["assets/example.net.disabled", "/etc/vpncloud/example.net.disabled", "600"],
|
["assets/example.net.disabled", "/etc/vpncloud/example.net.disabled", "600"],
|
||||||
["assets/vpncloud@.service", "/lib/systemd/system/vpncloud@.service", "644"],
|
["assets/vpncloud@.service", "/lib/systemd/system/vpncloud@.service", "644"],
|
||||||
|
["assets/vpncloud-wsproxy.service", "/lib/systemd/system/vpncloud-wsproxy.service", "644"],
|
||||||
["target/vpncloud.1.gz", "/usr/share/man/man1/vpncloud.1.gz", "644"]
|
["target/vpncloud.1.gz", "/usr/share/man/man1/vpncloud.1.gz", "644"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
585
LICENSE.md
585
LICENSE.md
|
@ -1,7 +1,7 @@
|
||||||
# License: GPL-3
|
# License: GPL-3
|
||||||
|
|
||||||
VpnCloud - Peer-to-Peer VPN
|
VpnCloud - Peer-to-Peer VPN
|
||||||
Copyright (C) 2015-2020 Dennis Schwerdel
|
Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,106 +15,106 @@ GNU General Public License for more details.
|
||||||
|
|
||||||
Full license text follows.
|
Full license text follows.
|
||||||
|
|
||||||
|
### Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
software and other kinds of works.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
The licenses for most software and other practical works are designed
|
||||||
to take away your freedom to share and change the works. By contrast,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
the GNU General Public License is intended to guarantee your freedom
|
||||||
share and change all versions of a program--to make sure it remains free
|
to share and change all versions of a program--to make sure it remains
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
free software for all its users. We, the Free Software Foundation, use
|
||||||
GNU General Public License for most of our software; it applies also to
|
the GNU General Public License for most of our software; it applies
|
||||||
any other work released this way by its authors. You can apply it to
|
also to any other work released this way by its authors. You can apply
|
||||||
your programs, too.
|
it to your programs, too.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
have the freedom to distribute copies of free software (and charge for
|
have the freedom to distribute copies of free software (and charge for
|
||||||
them if you wish), that you receive source code or can get it if you
|
them if you wish), that you receive source code or can get it if you
|
||||||
want it, that you can change the software or use pieces of it in new
|
want it, that you can change the software or use pieces of it in new
|
||||||
free programs, and that you know you can do these things.
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
To protect your rights, we need to prevent others from denying you
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
these rights or asking you to surrender the rights. Therefore, you
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
have certain responsibilities if you distribute copies of the
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
software, or if you modify it: responsibilities to respect the freedom
|
||||||
|
of others.
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
For example, if you distribute copies of such a program, whether
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
or can get the source code. And you must show them these terms so they
|
or can get the source code. And you must show them these terms so they
|
||||||
know their rights.
|
know their rights.
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
that there is no warranty for this free software. For both users' and
|
that there is no warranty for this free software. For both users' and
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
changed, so that their problems will not be attributed erroneously to
|
changed, so that their problems will not be attributed erroneously to
|
||||||
authors of previous versions.
|
authors of previous versions.
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
Some devices are designed to deny users access to install or run
|
||||||
modified versions of the software inside them, although the manufacturer
|
modified versions of the software inside them, although the
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
manufacturer can do so. This is fundamentally incompatible with the
|
||||||
protecting users' freedom to change the software. The systematic
|
aim of protecting users' freedom to change the software. The
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
systematic pattern of such abuse occurs in the area of products for
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
individuals to use, which is precisely where it is most unacceptable.
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
Therefore, we have designed this version of the GPL to prohibit the
|
||||||
products. If such problems arise substantially in other domains, we
|
practice for those products. If such problems arise substantially in
|
||||||
stand ready to extend this provision to those domains in future versions
|
other domains, we stand ready to extend this provision to those
|
||||||
of the GPL, as needed to protect the freedom of users.
|
domains in future versions of the GPL, as needed to protect the
|
||||||
|
freedom of users.
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
Finally, every program is threatened constantly by software patents.
|
||||||
States should not allow patents to restrict development and use of
|
States should not allow patents to restrict development and use of
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
software on general-purpose computers, but in those that do, we wish
|
||||||
avoid the special danger that patents applied to a free program could
|
to avoid the special danger that patents applied to a free program
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
could make it effectively proprietary. To prevent this, the GPL
|
||||||
patents cannot be used to render the program non-free.
|
assures that patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
### TERMS AND CONDITIONS
|
||||||
|
|
||||||
0. Definitions.
|
#### 0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
"Copyright" also means copyright-like laws that apply to other kinds
|
||||||
works, such as semiconductor masks.
|
of works, such as semiconductor masks.
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
"recipients" may be individuals or organizations.
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
in a fashion requiring copyright permission, other than the making of
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
an exact copy. The resulting work is called a "modified version" of
|
||||||
earlier work or a work "based on" the earlier work.
|
the earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
A "covered work" means either the unmodified Program or a work based
|
||||||
on the Program.
|
on the Program.
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
To "propagate" a work means to do anything with it that, without
|
||||||
permission, would make you directly or secondarily liable for
|
permission, would make you directly or secondarily liable for
|
||||||
infringement under applicable copyright law, except executing it on a
|
infringement under applicable copyright law, except executing it on a
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
distribution (with or without modification), making available to the
|
distribution (with or without modification), making available to the
|
||||||
public, and in some countries other activities as well.
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
To "convey" a work means any kind of propagation that enables other
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
parties to make or receive copies. Mere interaction with a user
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
through a computer network, with no transfer of a copy, is not
|
||||||
|
conveying.
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
An interactive user interface displays "Appropriate Legal Notices" to
|
||||||
to the extent that it includes a convenient and prominently visible
|
the extent that it includes a convenient and prominently visible
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
tells the user that there is no warranty for the work (except to the
|
tells the user that there is no warranty for the work (except to the
|
||||||
extent that warranties are provided), that licensees may convey the
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
@ -122,18 +122,18 @@ work under this License, and how to view a copy of this License. If
|
||||||
the interface presents a list of user commands or options, such as a
|
the interface presents a list of user commands or options, such as a
|
||||||
menu, a prominent item in the list meets this criterion.
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
1. Source Code.
|
#### 1. Source Code.
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
The "source code" for a work means the preferred form of the work for
|
||||||
for making modifications to it. "Object code" means any non-source
|
making modifications to it. "Object code" means any non-source form of
|
||||||
form of a work.
|
a work.
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
A "Standard Interface" means an interface that either is an official
|
||||||
standard defined by a recognized standards body, or, in the case of
|
standard defined by a recognized standards body, or, in the case of
|
||||||
interfaces specified for a particular programming language, one that
|
interfaces specified for a particular programming language, one that
|
||||||
is widely used among developers working in that language.
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
The "System Libraries" of an executable work include anything, other
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
packaging a Major Component, but which is not part of that Major
|
packaging a Major Component, but which is not part of that Major
|
||||||
Component, and (b) serves only to enable use of the work with that
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
@ -144,7 +144,7 @@ implementation is available to the public in source code form. A
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
produce the work, or an object code interpreter used to run it.
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
The "Corresponding Source" for a work in object code form means all
|
||||||
the source code needed to generate, install, and (for an executable
|
the source code needed to generate, install, and (for an executable
|
||||||
work) run the object code and to modify the work, including scripts to
|
work) run the object code and to modify the work, including scripts to
|
||||||
control those activities. However, it does not include the work's
|
control those activities. However, it does not include the work's
|
||||||
|
@ -157,16 +157,15 @@ linked subprograms that the work is specifically designed to require,
|
||||||
such as by intimate data communication or control flow between those
|
such as by intimate data communication or control flow between those
|
||||||
subprograms and other parts of the work.
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
The Corresponding Source need not include anything that users can
|
||||||
can regenerate automatically from other parts of the Corresponding
|
regenerate automatically from other parts of the Corresponding Source.
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
The Corresponding Source for a work in source code form is that same
|
||||||
same work.
|
work.
|
||||||
|
|
||||||
2. Basic Permissions.
|
#### 2. Basic Permissions.
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
All rights granted under this License are granted for the term of
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
permission to run the unmodified Program. The output from running a
|
permission to run the unmodified Program. The output from running a
|
||||||
|
@ -174,40 +173,40 @@ covered work is covered by this License only if the output, given its
|
||||||
content, constitutes a covered work. This License acknowledges your
|
content, constitutes a covered work. This License acknowledges your
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
You may make, run and propagate covered works that you do not convey,
|
||||||
convey, without conditions so long as your license otherwise remains
|
without conditions so long as your license otherwise remains in force.
|
||||||
in force. You may convey covered works to others for the sole purpose
|
You may convey covered works to others for the sole purpose of having
|
||||||
of having them make modifications exclusively for you, or provide you
|
them make modifications exclusively for you, or provide you with
|
||||||
with facilities for running those works, provided that you comply with
|
facilities for running those works, provided that you comply with the
|
||||||
the terms of this License in conveying all material for which you do
|
terms of this License in conveying all material for which you do not
|
||||||
not control copyright. Those thus making or running the covered works
|
control copyright. Those thus making or running the covered works for
|
||||||
for you must do so exclusively on your behalf, under your direction
|
you must do so exclusively on your behalf, under your direction and
|
||||||
and control, on terms that prohibit them from making any copies of
|
control, on terms that prohibit them from making any copies of your
|
||||||
your copyrighted material outside their relationship with you.
|
copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
Conveying under any other circumstances is permitted solely under the
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
conditions stated below. Sublicensing is not allowed; section 10 makes
|
||||||
makes it unnecessary.
|
it unnecessary.
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
No covered work shall be deemed part of an effective technological
|
||||||
measure under any applicable law fulfilling obligations under article
|
measure under any applicable law fulfilling obligations under article
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
similar laws prohibiting or restricting circumvention of such
|
similar laws prohibiting or restricting circumvention of such
|
||||||
measures.
|
measures.
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
circumvention of technological measures to the extent such circumvention
|
circumvention of technological measures to the extent such
|
||||||
is effected by exercising rights under this License with respect to
|
circumvention is effected by exercising rights under this License with
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
respect to the covered work, and you disclaim any intention to limit
|
||||||
modification of the work as a means of enforcing, against the work's
|
operation or modification of the work as a means of enforcing, against
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
the work's users, your or third parties' legal rights to forbid
|
||||||
technological measures.
|
circumvention of technological measures.
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
#### 4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
You may convey verbatim copies of the Program's source code as you
|
||||||
receive it, in any medium, provided that you conspicuously and
|
receive it, in any medium, provided that you conspicuously and
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
keep intact all notices stating that this License and any
|
keep intact all notices stating that this License and any
|
||||||
|
@ -215,37 +214,35 @@ non-permissive terms added in accord with section 7 apply to the code;
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
recipients a copy of this License along with the Program.
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
You may charge any price or no price for each copy that you convey,
|
||||||
and you may offer support or warranty protection for a fee.
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
#### 5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
You may convey a work based on the Program, or the modifications to
|
||||||
produce it from the Program, in the form of source code under the
|
produce it from the Program, in the form of source code under the
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
terms of section 4, provided that you also meet all of these
|
||||||
|
conditions:
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
- a) The work must carry prominent notices stating that you modified
|
||||||
it, and giving a relevant date.
|
it, and giving a relevant date.
|
||||||
|
- b) The work must carry prominent notices stating that it is
|
||||||
b) The work must carry prominent notices stating that it is
|
released under this License and any conditions added under
|
||||||
released under this License and any conditions added under section
|
section 7. This requirement modifies the requirement in section 4
|
||||||
7. This requirement modifies the requirement in section 4 to
|
to "keep intact all notices".
|
||||||
"keep intact all notices".
|
- c) You must license the entire work, as a whole, under this
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
License to anyone who comes into possession of a copy. This
|
||||||
License will therefore apply, along with any applicable section 7
|
License will therefore apply, along with any applicable section 7
|
||||||
additional terms, to the whole of the work, and all its parts,
|
additional terms, to the whole of the work, and all its parts,
|
||||||
regardless of how they are packaged. This License gives no
|
regardless of how they are packaged. This License gives no
|
||||||
permission to license the work in any other way, but it does not
|
permission to license the work in any other way, but it does not
|
||||||
invalidate such permission if you have separately received it.
|
invalidate such permission if you have separately received it.
|
||||||
|
- d) If the work has interactive user interfaces, each must display
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
work need not make them do so.
|
work need not make them do so.
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
A compilation of a covered work with other separate and independent
|
||||||
works, which are not by their nature extensions of the covered work,
|
works, which are not by their nature extensions of the covered work,
|
||||||
and which are not combined with it such as to form a larger program,
|
and which are not combined with it such as to form a larger program,
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
@ -255,19 +252,18 @@ beyond what the individual works permit. Inclusion of a covered work
|
||||||
in an aggregate does not cause this License to apply to the other
|
in an aggregate does not cause this License to apply to the other
|
||||||
parts of the aggregate.
|
parts of the aggregate.
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
#### 6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
You may convey a covered work in object code form under the terms of
|
||||||
of sections 4 and 5, provided that you also convey the
|
sections 4 and 5, provided that you also convey the machine-readable
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
Corresponding Source under the terms of this License, in one of these
|
||||||
in one of these ways:
|
ways:
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
- a) Convey the object code in, or embodied in, a physical product
|
||||||
(including a physical distribution medium), accompanied by the
|
(including a physical distribution medium), accompanied by the
|
||||||
Corresponding Source fixed on a durable physical medium
|
Corresponding Source fixed on a durable physical medium
|
||||||
customarily used for software interchange.
|
customarily used for software interchange.
|
||||||
|
- b) Convey the object code in, or embodied in, a physical product
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
(including a physical distribution medium), accompanied by a
|
||||||
written offer, valid for at least three years and valid for as
|
written offer, valid for at least three years and valid for as
|
||||||
long as you offer spare parts or customer support for that product
|
long as you offer spare parts or customer support for that product
|
||||||
|
@ -276,16 +272,14 @@ in one of these ways:
|
||||||
product that is covered by this License, on a durable physical
|
product that is covered by this License, on a durable physical
|
||||||
medium customarily used for software interchange, for a price no
|
medium customarily used for software interchange, for a price no
|
||||||
more than your reasonable cost of physically performing this
|
more than your reasonable cost of physically performing this
|
||||||
conveying of source, or (2) access to copy the
|
conveying of source, or (2) access to copy the Corresponding
|
||||||
Corresponding Source from a network server at no charge.
|
Source from a network server at no charge.
|
||||||
|
- c) Convey individual copies of the object code with a copy of the
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
written offer to provide the Corresponding Source. This
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
only if you received the object code with such an offer, in accord
|
only if you received the object code with such an offer, in accord
|
||||||
with subsection 6b.
|
with subsection 6b.
|
||||||
|
- d) Convey the object code by offering access from a designated
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
Corresponding Source in the same way through the same place at no
|
Corresponding Source in the same way through the same place at no
|
||||||
further charge. You need not require recipients to copy the
|
further charge. You need not require recipients to copy the
|
||||||
|
@ -297,38 +291,38 @@ in one of these ways:
|
||||||
Corresponding Source. Regardless of what server hosts the
|
Corresponding Source. Regardless of what server hosts the
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
available for as long as needed to satisfy these requirements.
|
available for as long as needed to satisfy these requirements.
|
||||||
|
- e) Convey the object code using peer-to-peer transmission,
|
||||||
|
provided you inform other peers where the object code and
|
||||||
|
Corresponding Source of the work are being offered to the general
|
||||||
|
public at no charge under subsection 6d.
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
A separable portion of the object code, whose source code is excluded
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
from the Corresponding Source as a System Library, need not be
|
||||||
included in conveying the object code work.
|
included in conveying the object code work.
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
tangible personal property which is normally used for personal, family,
|
tangible personal property which is normally used for personal,
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
family, or household purposes, or (2) anything designed or sold for
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
incorporation into a dwelling. In determining whether a product is a
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
consumer product, doubtful cases shall be resolved in favor of
|
||||||
product received by a particular user, "normally used" refers to a
|
coverage. For a particular product received by a particular user,
|
||||||
typical or common use of that class of product, regardless of the status
|
"normally used" refers to a typical or common use of that class of
|
||||||
of the particular user or of the way in which the particular user
|
product, regardless of the status of the particular user or of the way
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
in which the particular user actually uses, or expects or is expected
|
||||||
is a consumer product regardless of whether the product has substantial
|
to use, the product. A product is a consumer product regardless of
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
whether the product has substantial commercial, industrial or
|
||||||
the only significant mode of use of the product.
|
non-consumer uses, unless such uses represent the only significant
|
||||||
|
mode of use of the product.
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
"Installation Information" for a User Product means any methods,
|
||||||
procedures, authorization keys, or other information required to install
|
procedures, authorization keys, or other information required to
|
||||||
and execute modified versions of a covered work in that User Product from
|
install and execute modified versions of a covered work in that User
|
||||||
a modified version of its Corresponding Source. The information must
|
Product from a modified version of its Corresponding Source. The
|
||||||
suffice to ensure that the continued functioning of the modified object
|
information must suffice to ensure that the continued functioning of
|
||||||
code is in no case prevented or interfered with solely because
|
the modified object code is in no case prevented or interfered with
|
||||||
modification has been made.
|
solely because modification has been made.
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
If you convey an object code work under this section in, or with, or
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
part of a transaction in which the right of possession and use of the
|
part of a transaction in which the right of possession and use of the
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
@ -339,23 +333,24 @@ if neither you nor any third party retains the ability to install
|
||||||
modified object code on the User Product (for example, the work has
|
modified object code on the User Product (for example, the work has
|
||||||
been installed in ROM).
|
been installed in ROM).
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
The requirement to provide Installation Information does not include a
|
||||||
requirement to continue to provide support service, warranty, or updates
|
requirement to continue to provide support service, warranty, or
|
||||||
for a work that has been modified or installed by the recipient, or for
|
updates for a work that has been modified or installed by the
|
||||||
the User Product in which it has been modified or installed. Access to a
|
recipient, or for the User Product in which it has been modified or
|
||||||
network may be denied when the modification itself materially and
|
installed. Access to a network may be denied when the modification
|
||||||
adversely affects the operation of the network or violates the rules and
|
itself materially and adversely affects the operation of the network
|
||||||
protocols for communication across the network.
|
or violates the rules and protocols for communication across the
|
||||||
|
network.
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
in accord with this section must be in a format that is publicly
|
in accord with this section must be in a format that is publicly
|
||||||
documented (and with an implementation available to the public in
|
documented (and with an implementation available to the public in
|
||||||
source code form), and must require no special password or key for
|
source code form), and must require no special password or key for
|
||||||
unpacking, reading or copying.
|
unpacking, reading or copying.
|
||||||
|
|
||||||
7. Additional Terms.
|
#### 7. Additional Terms.
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
License by making exceptions from one or more of its conditions.
|
License by making exceptions from one or more of its conditions.
|
||||||
Additional permissions that are applicable to the entire Program shall
|
Additional permissions that are applicable to the entire Program shall
|
||||||
be treated as though they were included in this License, to the extent
|
be treated as though they were included in this License, to the extent
|
||||||
|
@ -364,41 +359,36 @@ apply only to part of the Program, that part may be used separately
|
||||||
under those permissions, but the entire Program remains governed by
|
under those permissions, but the entire Program remains governed by
|
||||||
this License without regard to the additional permissions.
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
When you convey a copy of a covered work, you may at your option
|
||||||
remove any additional permissions from that copy, or from any part of
|
remove any additional permissions from that copy, or from any part of
|
||||||
it. (Additional permissions may be written to require their own
|
it. (Additional permissions may be written to require their own
|
||||||
removal in certain cases when you modify the work.) You may place
|
removal in certain cases when you modify the work.) You may place
|
||||||
additional permissions on material, added by you to a covered work,
|
additional permissions on material, added by you to a covered work,
|
||||||
for which you have or can give appropriate copyright permission.
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
Notwithstanding any other provision of this License, for material you
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
add to a covered work, you may (if authorized by the copyright holders
|
||||||
that material) supplement the terms of this License with terms:
|
of that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
- a) Disclaiming warranty or limiting liability differently from the
|
||||||
terms of sections 15 and 16 of this License; or
|
terms of sections 15 and 16 of this License; or
|
||||||
|
- b) Requiring preservation of specified reasonable legal notices or
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
author attributions in that material or in the Appropriate Legal
|
||||||
Notices displayed by works containing it; or
|
Notices displayed by works containing it; or
|
||||||
|
- c) Prohibiting misrepresentation of the origin of that material,
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
or requiring that modified versions of such material be marked in
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
reasonable ways as different from the original version; or
|
||||||
|
- d) Limiting the use for publicity purposes of names of licensors
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
or authors of the material; or
|
||||||
authors of the material; or
|
- e) Declining to grant rights under trademark law for use of some
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
trade names, trademarks, or service marks; or
|
||||||
|
- f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions
|
||||||
|
of it) with contractual assumptions of liability to the recipient,
|
||||||
|
for any liability that these contractual assumptions directly
|
||||||
|
impose on those licensors and authors.
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
All other non-permissive additional terms are considered "further
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
received it, or any part of it, contains a notice stating that it is
|
received it, or any part of it, contains a notice stating that it is
|
||||||
governed by this License along with a term that is a further
|
governed by this License along with a term that is a further
|
||||||
|
@ -408,47 +398,47 @@ License, you may add to a covered work material governed by the terms
|
||||||
of that license document, provided that the further restriction does
|
of that license document, provided that the further restriction does
|
||||||
not survive such relicensing or conveying.
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
If you add terms to a covered work in accord with this section, you
|
||||||
must place, in the relevant source files, a statement of the
|
must place, in the relevant source files, a statement of the
|
||||||
additional terms that apply to those files, or a notice indicating
|
additional terms that apply to those files, or a notice indicating
|
||||||
where to find the applicable terms.
|
where to find the applicable terms.
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
form of a separately written license, or stated as exceptions;
|
form of a separately written license, or stated as exceptions; the
|
||||||
the above requirements apply either way.
|
above requirements apply either way.
|
||||||
|
|
||||||
8. Termination.
|
#### 8. Termination.
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
You may not propagate or modify a covered work except as expressly
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
modify it is void, and will automatically terminate your rights under
|
modify it is void, and will automatically terminate your rights under
|
||||||
this License (including any patent licenses granted under the third
|
this License (including any patent licenses granted under the third
|
||||||
paragraph of section 11).
|
paragraph of section 11).
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
However, if you cease all violation of this License, then your license
|
||||||
license from a particular copyright holder is reinstated (a)
|
from a particular copyright holder is reinstated (a) provisionally,
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
unless and until the copyright holder explicitly and finally
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
terminates your license, and (b) permanently, if the copyright holder
|
||||||
holder fails to notify you of the violation by some reasonable means
|
fails to notify you of the violation by some reasonable means prior to
|
||||||
prior to 60 days after the cessation.
|
60 days after the cessation.
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
Moreover, your license from a particular copyright holder is
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
violation by some reasonable means, this is the first time you have
|
violation by some reasonable means, this is the first time you have
|
||||||
received notice of violation of this License (for any work) from that
|
received notice of violation of this License (for any work) from that
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
your receipt of the notice.
|
your receipt of the notice.
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
Termination of your rights under this section does not terminate the
|
||||||
licenses of parties who have received copies or rights from you under
|
licenses of parties who have received copies or rights from you under
|
||||||
this License. If your rights have been terminated and not permanently
|
this License. If your rights have been terminated and not permanently
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
material under section 10.
|
material under section 10.
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
#### 9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
You are not required to accept this License in order to receive or run
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
a copy of the Program. Ancillary propagation of a covered work
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
to receive a copy likewise does not require acceptance. However,
|
to receive a copy likewise does not require acceptance. However,
|
||||||
nothing other than this License grants you permission to propagate or
|
nothing other than this License grants you permission to propagate or
|
||||||
|
@ -456,14 +446,14 @@ modify any covered work. These actions infringe copyright if you do
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
#### 10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
Each time you convey a covered work, the recipient automatically
|
||||||
receives a license from the original licensors, to run, modify and
|
receives a license from the original licensors, to run, modify and
|
||||||
propagate that work, subject to this License. You are not responsible
|
propagate that work, subject to this License. You are not responsible
|
||||||
for enforcing compliance by third parties with this License.
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
An "entity transaction" is a transaction transferring control of an
|
||||||
organization, or substantially all assets of one, or subdividing an
|
organization, or substantially all assets of one, or subdividing an
|
||||||
organization, or merging organizations. If propagation of a covered
|
organization, or merging organizations. If propagation of a covered
|
||||||
work results from an entity transaction, each party to that
|
work results from an entity transaction, each party to that
|
||||||
|
@ -473,7 +463,7 @@ give under the previous paragraph, plus a right to possession of the
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
You may not impose any further restrictions on the exercise of the
|
||||||
rights granted or affirmed under this License. For example, you may
|
rights granted or affirmed under this License. For example, you may
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
rights granted under this License, and you may not initiate litigation
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
@ -481,14 +471,14 @@ rights granted under this License, and you may not initiate litigation
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
sale, or importing the Program or any portion of it.
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
11. Patents.
|
#### 11. Patents.
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
License of the Program or a work on which the Program is based. The
|
License of the Program or a work on which the Program is based. The
|
||||||
work thus licensed is called the contributor's "contributor version".
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
A contributor's "essential patent claims" are all patent claims owned
|
||||||
owned or controlled by the contributor, whether already acquired or
|
or controlled by the contributor, whether already acquired or
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
by this License, of making, using, or selling its contributor version,
|
by this License, of making, using, or selling its contributor version,
|
||||||
but do not include claims that would be infringed only as a
|
but do not include claims that would be infringed only as a
|
||||||
|
@ -497,19 +487,19 @@ purposes of this definition, "control" includes the right to grant
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
this License.
|
this License.
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
patent license under the contributor's essential patent claims, to
|
patent license under the contributor's essential patent claims, to
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
propagate the contents of its contributor version.
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
In the following three paragraphs, a "patent license" is any express
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
(such as an express permission to practice a patent or covenant not to
|
(such as an express permission to practice a patent or covenant not to
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
party means to make such an agreement or commitment not to enforce a
|
party means to make such an agreement or commitment not to enforce a
|
||||||
patent against the party.
|
patent against the party.
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
and the Corresponding Source of the work is not available for anyone
|
and the Corresponding Source of the work is not available for anyone
|
||||||
to copy, free of charge and under the terms of this License, through a
|
to copy, free of charge and under the terms of this License, through a
|
||||||
publicly available network server or other readily accessible means,
|
publicly available network server or other readily accessible means,
|
||||||
|
@ -523,7 +513,7 @@ covered work in a country, or your recipient's use of the covered work
|
||||||
in a country, would infringe one or more identifiable patents in that
|
in a country, would infringe one or more identifiable patents in that
|
||||||
country that you have reason to believe are valid.
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
If, pursuant to or in connection with a single transaction or
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
covered work, and grant a patent license to some of the parties
|
covered work, and grant a patent license to some of the parties
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
@ -531,40 +521,41 @@ or convey a specific copy of the covered work, then the patent license
|
||||||
you grant is automatically extended to all recipients of the covered
|
you grant is automatically extended to all recipients of the covered
|
||||||
work and works based on it.
|
work and works based on it.
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
A patent license is "discriminatory" if it does not include within the
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
scope of its coverage, prohibits the exercise of, or is conditioned on
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
the non-exercise of one or more of the rights that are specifically
|
||||||
specifically granted under this License. You may not convey a covered
|
granted under this License. You may not convey a covered work if you
|
||||||
work if you are a party to an arrangement with a third party that is
|
are a party to an arrangement with a third party that is in the
|
||||||
in the business of distributing software, under which you make payment
|
business of distributing software, under which you make payment to the
|
||||||
to the third party based on the extent of your activity of conveying
|
third party based on the extent of your activity of conveying the
|
||||||
the work, and under which the third party grants, to any of the
|
work, and under which the third party grants, to any of the parties
|
||||||
parties who would receive the covered work from you, a discriminatory
|
who would receive the covered work from you, a discriminatory patent
|
||||||
patent license (a) in connection with copies of the covered work
|
license (a) in connection with copies of the covered work conveyed by
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
you (or copies made from those copies), or (b) primarily for and in
|
||||||
for and in connection with specific products or compilations that
|
connection with specific products or compilations that contain the
|
||||||
contain the covered work, unless you entered into that arrangement,
|
covered work, unless you entered into that arrangement, or that patent
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
any implied license or other defenses to infringement that may
|
any implied license or other defenses to infringement that may
|
||||||
otherwise be available to you under applicable patent law.
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
#### 12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
covered work so as to satisfy simultaneously your obligations under
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
this License and any other pertinent obligations, then as a
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
consequence you may not convey it at all. For example, if you agree to
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
terms that obligate you to collect a royalty for further conveying
|
||||||
the Program, the only way you could satisfy both those terms and this
|
from those to whom you convey the Program, the only way you could
|
||||||
License would be to refrain entirely from conveying the Program.
|
satisfy both those terms and this License would be to refrain entirely
|
||||||
|
from conveying the Program.
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
#### 13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
Notwithstanding any other provision of this License, you have
|
||||||
permission to link or combine any covered work with a work licensed
|
permission to link or combine any covered work with a work licensed
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
combined work, and to convey the resulting work. The terms of this
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
@ -573,76 +564,78 @@ but the special requirements of the GNU Affero General Public License,
|
||||||
section 13, concerning interaction through a network will apply to the
|
section 13, concerning interaction through a network will apply to the
|
||||||
combination as such.
|
combination as such.
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
#### 14. Revised Versions of this License.
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
the GNU General Public License from time to time. Such new versions will
|
of the GNU General Public License from time to time. Such new versions
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
will be similar in spirit to the present version, but may differ in
|
||||||
address new problems or concerns.
|
detail to address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
Each version is given a distinguishing version number. If the Program
|
||||||
Program specifies that a certain numbered version of the GNU General
|
specifies that a certain numbered version of the GNU General Public
|
||||||
Public License "or any later version" applies to it, you have the
|
License "or any later version" applies to it, you have the option of
|
||||||
option of following the terms and conditions either of that numbered
|
following the terms and conditions either of that numbered version or
|
||||||
version or of any later version published by the Free Software
|
of any later version published by the Free Software Foundation. If the
|
||||||
Foundation. If the Program does not specify a version number of the
|
Program does not specify a version number of the GNU General Public
|
||||||
GNU General Public License, you may choose any version ever published
|
License, you may choose any version ever published by the Free
|
||||||
by the Free Software Foundation.
|
Software Foundation.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
If the Program specifies that a proxy can decide which future versions
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
of the GNU General Public License can be used, that proxy's public
|
||||||
public statement of acceptance of a version permanently authorizes you
|
statement of acceptance of a version permanently authorizes you to
|
||||||
to choose that version for the Program.
|
choose that version for the Program.
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
Later license versions may give you additional or different
|
||||||
permissions. However, no additional obligations are imposed on any
|
permissions. However, no additional obligations are imposed on any
|
||||||
author or copyright holder as a result of your choosing to follow a
|
author or copyright holder as a result of your choosing to follow a
|
||||||
later version.
|
later version.
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
#### 15. Disclaimer of Warranty.
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
|
||||||
|
CORRECTION.
|
||||||
|
|
||||||
16. Limitation of Liability.
|
#### 16. Limitation of Liability.
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
|
||||||
SUCH DAMAGES.
|
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
#### 17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
above cannot be given local legal effect according to their terms,
|
above cannot be given local legal effect according to their terms,
|
||||||
reviewing courts shall apply local law that most closely approximates
|
reviewing courts shall apply local law that most closely approximates
|
||||||
an absolute waiver of all civil liability in connection with the
|
an absolute waiver of all civil liability in connection with the
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
copy of the Program in return for a fee.
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
### How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
If you develop a new program, and you want it to be of the greatest
|
||||||
possible use to the public, the best way to achieve this is to make it
|
possible use to the public, the best way to achieve this is to make it
|
||||||
free software which everyone can redistribute and change under these terms.
|
free software which everyone can redistribute and change under these
|
||||||
|
terms.
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
To do so, attach the following notices to the program. It is safest to
|
||||||
to attach them to the start of each source file to most effectively
|
attach them to the start of each source file to most effectively state
|
||||||
state the exclusion of warranty; and each file should have at least
|
the exclusion of warranty; and each file should have at least the
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
Copyright (C) <year> <name of author>
|
Copyright (C) <year> <name of author>
|
||||||
|
@ -658,11 +651,12 @@ the "copyright" line and a pointer to where the full notice is found.
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper
|
||||||
|
mail.
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
If the program does terminal interaction, make it output a short
|
||||||
notice like this when it starts in an interactive mode:
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
@ -670,18 +664,19 @@ notice like this when it starts in an interactive mode:
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
The hypothetical commands \`show w' and \`show c' should show the
|
||||||
parts of the General Public License. Of course, your program's commands
|
appropriate parts of the General Public License. Of course, your
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
program's commands might be different; for a GUI interface, you would
|
||||||
|
use an "about box".
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
You should also get your employer (if you work as a programmer) or
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
necessary. For more information on this, and how to apply and follow
|
||||||
<http://www.gnu.org/licenses/>.
|
the GNU GPL, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
The GNU General Public License does not permit incorporating your
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
program into proprietary programs. If your program is a subroutine
|
||||||
may consider it more useful to permit linking proprietary applications with
|
library, you may consider it more useful to permit linking proprietary
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
applications with the library. If this is what you want to do, use the
|
||||||
Public License instead of this License. But first, please read
|
GNU Lesser General Public License instead of this License. But first,
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
please read <https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -35,6 +35,7 @@ somewhat stable state. VpnCloud features the following functionality:
|
||||||
* Support for different forwarding/routing behaviors (Hub, Switch, Router)
|
* Support for different forwarding/routing behaviors (Hub, Switch, Router)
|
||||||
* NAT and firewall traversal using hole punching
|
* NAT and firewall traversal using hole punching
|
||||||
* Automatic port forwarding via UPnP
|
* Automatic port forwarding via UPnP
|
||||||
|
* Websocket proxy mode for restrictive environments
|
||||||
* Support for tunneled VLans (TAP devices)
|
* Support for tunneled VLans (TAP devices)
|
||||||
* Support for publishing [beacons](https://vpncloud.ddswd.de/docs/beacons) to help nodes find each others
|
* Support for publishing [beacons](https://vpncloud.ddswd.de/docs/beacons) to help nodes find each others
|
||||||
* Support for statsd monitoring
|
* Support for statsd monitoring
|
||||||
|
@ -61,6 +62,9 @@ contributions are very welcome:
|
||||||
|
|
||||||
* **Linux packages**: VpnCloud is stable enough to be packaged for Linux
|
* **Linux packages**: VpnCloud is stable enough to be packaged for Linux
|
||||||
distributions. Maintainers who want to package VpnCloud are very welcome.
|
distributions. Maintainers who want to package VpnCloud are very welcome.
|
||||||
|
* **Help with other platforms**: If you are a Rust developer with experience
|
||||||
|
on Windows or MacOS your help on porting VpnCloud to those platforms is very
|
||||||
|
welcome.
|
||||||
* **Security review**: The security has been implemented with strong security
|
* **Security review**: The security has been implemented with strong security
|
||||||
primitives but it would be great if a cryptography expert could verify the
|
primitives but it would be great if a cryptography expert could verify the
|
||||||
system.
|
system.
|
||||||
|
|
|
@ -1,3 +1,16 @@
|
||||||
|
vpncloud (2.1.0) stable; urgency=medium
|
||||||
|
|
||||||
|
* [added] Support for websocket proxy mode
|
||||||
|
* [added] Support for hook scripts to handle certain situations
|
||||||
|
* [added] Support for creating shell completions
|
||||||
|
* [removed] Removed dummy device type
|
||||||
|
* [changed] Updated dependencies
|
||||||
|
* [changed] Changed Rust version to 1.49.0
|
||||||
|
* [fixed] Added missing peer address propagation
|
||||||
|
* [fixed] Fixed problem with peer addresses without port
|
||||||
|
|
||||||
|
-- Dennis Schwerdel <schwerdel@googlemail.com> Sat, 06 Feb 2020 13:13:00 +0100
|
||||||
|
|
||||||
vpncloud (2.0.1) stable; urgency=medium
|
vpncloud (2.0.1) stable; urgency=medium
|
||||||
|
|
||||||
* [changed] Changed documentation
|
* [changed] Changed documentation
|
||||||
|
|
|
@ -1,140 +1,82 @@
|
||||||
# This configuration file uses the YAML format.
|
# This configuration file uses the YAML format.
|
||||||
|
# ~ means "no value" (i.e. "default value")
|
||||||
# This configuration can be enabled/disabled and controlled by adding the
|
# Replace it by a value and put quotes (") around values with special characters
|
||||||
# network to `/etc/default/vpncloud` and starting/stopping it via
|
# List items start with a dash and a space (- )
|
||||||
# `/etc/init.d/vpncloud start/stop` on non-systemd systems and via
|
# Note that the whitespace before the settings names is important for the file structure
|
||||||
# `systemctl enable/disable vpncloud@NAME` and
|
|
||||||
# `service vpncloud@NAME start/stop` on systemd systems.
|
|
||||||
|
|
||||||
|
|
||||||
# The port number or ip:port on which to listen for data.
|
listen: 3210 # The port number or ip:port on which to listen for data.
|
||||||
# Note: Every VPN needs a different port number.
|
|
||||||
listen: 3210
|
|
||||||
|
|
||||||
# Address of a peer to connect to. The address should be in the form
|
peers: # Address of a peer to connect to.
|
||||||
# `addr:port`. If the node is not started, the connection will be retried
|
# The address should be in the form `addr:port`.
|
||||||
# periodically. This parameter can be repeated to connect to multiple peers.
|
# Put [] for an empty list
|
||||||
# Note: Several entries can be separated by spaces.
|
- node2.example.com:3210
|
||||||
peers:
|
- node3.example.com:3210
|
||||||
# - node2.example.com:3210
|
|
||||||
# - node3.example.com:3210
|
|
||||||
|
|
||||||
# Peer timeout in seconds. The peers will exchange information periodically
|
crypto: # Crypto settings
|
||||||
# and drop peers that are silent for this period of time.
|
password: ~ # <-- CHANGE # A password to encrypt the VPN data.
|
||||||
peer-timeout: 300
|
private-key: ~ # Private key (alternative to password)
|
||||||
|
public-key: ~ # Public key (alternative to password)
|
||||||
|
trusted-keys: [] # Trusted keys (alternative to password)
|
||||||
|
# Replace [] with list of keys
|
||||||
|
|
||||||
# Switch table entry timeout in seconds. This parameter is only used in switch
|
ip: ~ # <-- CHANGE # An IP address to set on the device, e.g. 10.0.0.1
|
||||||
# mode. Addresses that have not been seen for the given period of time will
|
# Must be different for every node on the VPN
|
||||||
# be forgot.
|
|
||||||
switch-timeout: 300
|
|
||||||
|
|
||||||
|
|
||||||
# Crypto settings
|
# ------------------ Advanced features ahead --------------------
|
||||||
#crypto:
|
|
||||||
|
|
||||||
# An optional password to encrypt the VPN data.
|
auto-claim: true # Whether to automatically claim the configured IP on tun devices
|
||||||
#password: ""
|
|
||||||
|
|
||||||
# Private key
|
claims: # The local subnets to use. This parameter should be in the form
|
||||||
#private-key: ""
|
# `address/prefixlen` where address is an IPv4 address, an IPv6 address, or a
|
||||||
|
# MAC address. The prefix length is the number of significant front bits that
|
||||||
# Public key
|
# distinguish the subnet from other subnets.
|
||||||
#public-key: ""
|
|
||||||
|
|
||||||
# Trusted keys
|
|
||||||
#trusted-keys:
|
|
||||||
|
|
||||||
# Supported algorithms. Subset of "aes128", "aes256", "chacha20", and
|
|
||||||
# "plain" where "plain" means unencrypted.
|
|
||||||
#algorithms:
|
|
||||||
|
|
||||||
|
|
||||||
# Device settings
|
|
||||||
device:
|
|
||||||
|
|
||||||
# Name of the virtual device. Any `%d` will be filled with a free number.
|
|
||||||
name: "vpncloud%d"
|
|
||||||
|
|
||||||
# Set the type of network. There are two options: **tap** devices process
|
|
||||||
# Ethernet frames **tun** devices process IP packets. [default: `tun`]
|
|
||||||
type: tun
|
|
||||||
|
|
||||||
# The path of the /dev/net/tun device. Only change if you need to.
|
|
||||||
#path: /dev/net/tun
|
|
||||||
|
|
||||||
# Whether to fix detected rp-filter problems
|
|
||||||
fix-rp-filter: false
|
|
||||||
|
|
||||||
|
|
||||||
# The mode of the VPN. The VPN can like a router, a switch or a hub. A **hub**
|
|
||||||
# will send all data always to all peers. A **switch** will learn addresses
|
|
||||||
# from incoming data and only send data to all peers when the address is
|
|
||||||
# unknown. A **router** will send data according to known subnets of the
|
|
||||||
# peers and ignore them otherwise. The **normal** mode is switch for tap
|
|
||||||
# devices and router for tun devices. [default: `normal`]
|
|
||||||
mode: normal
|
|
||||||
|
|
||||||
|
|
||||||
# The local subnets to use. This parameter should be in the form
|
|
||||||
# `address/prefixlen` where address is an IPv4 address, an IPv6 address, or a
|
|
||||||
# MAC address. The prefix length is the number of significant front bits that
|
|
||||||
# distinguish the subnet from other subnets. Example: `10.1.1.0/24`.
|
|
||||||
# Note: Several entries can be separated by spaces.
|
|
||||||
#claims:
|
|
||||||
# - 10.1.1.0/24
|
# - 10.1.1.0/24
|
||||||
|
|
||||||
# Whether to automatically claim the configured IP on tun devices
|
ifup: ~ # Command to setup the interface. Use $IFNAME for interface name.
|
||||||
auto-claim: true
|
ifdown: ~ # Command to tear down the interface. Use $IFNAME for interface name.
|
||||||
|
|
||||||
|
device: # Device settings
|
||||||
|
name: "vpncloud%d" # Name of the virtual device. Any `%d` will be filled with a free number.
|
||||||
|
type: tun # Set the type of network. There are two options: **tap** devices process
|
||||||
|
# Ethernet frames **tun** devices process IP packets. [default: `tun`]
|
||||||
|
path: "/dev/net/tun" # Path of the tun device
|
||||||
|
fix-rp-filter: false # Whether to fix detected rp-filter problems
|
||||||
|
|
||||||
|
mode: normal # Mode to run in, "normal", "hub", "switch", or "router" (see manpage)
|
||||||
|
|
||||||
|
port-forwarding: true # Try to map a port on the router
|
||||||
|
|
||||||
|
switch-timeout: 300 # Switch timeout in seconds (switch mode only)
|
||||||
|
|
||||||
|
peer-timeout: 300 # Peer timeout in seconds
|
||||||
|
keepalive: ~ # Keepalive interval in seconds
|
||||||
|
|
||||||
|
beacon: # Beacon settings
|
||||||
|
store: ~ # File or command (prefix: "|") to use for storing beacons
|
||||||
|
load: ~ # File or command (prefix: "|") to use for loading beacons
|
||||||
|
interval: 3600 # How often to load and store beacons (in seconds)
|
||||||
|
password: ~ # Password to encrypt beacon data with
|
||||||
|
|
||||||
|
statsd: # Statsd settings
|
||||||
|
server: ~ # Statsd server name:port
|
||||||
|
prefix: ~ # Prefix to use for stats keys
|
||||||
|
|
||||||
|
pid-file: ~ # Store the process id in this file when running in the background
|
||||||
|
stats-file: ~ # Periodically write statistics on peers and current traffic to the given file
|
||||||
|
|
||||||
|
hook: ~ # Hook script to run for every event
|
||||||
|
hooks: {} # Multiple hook scripts to run for specific events
|
||||||
|
|
||||||
|
|
||||||
# An IP address to set on the device
|
|
||||||
#ip: ""
|
|
||||||
|
|
||||||
# A command to setup the network interface. The command will be run (as
|
# Copy this template and save it to a file named /etc/vpncloud/MYNET.net (replace MYNET with your network name)
|
||||||
# parameter to `sh -c`) when the device has been created to configure it.
|
#
|
||||||
# The name of the allocated device will be available via the environment
|
# On systems using systemd (most common):
|
||||||
# variable `IFNAME`.
|
# start/stop the network: service vpncloud@MYNET start/stop
|
||||||
#ifup: ""
|
# enable/disable automatic startup: systemctl enable/disable vpncloud@MYNET
|
||||||
|
#
|
||||||
# A command to bring down the network interface. The command will be run (as
|
# On older systems (using sysv init):
|
||||||
# parameter to `sh -c`) to remove any configuration from the device.
|
# Add the network name to /etc/default/vpncloud
|
||||||
# The name of the allocated device will be available via the environment
|
# start/stop all VpnCloud networks: /etc/init.d/vpncloud start/stop
|
||||||
# variable `IFNAME`.
|
|
||||||
#ifdown: ""
|
|
||||||
|
|
||||||
# Store the process id in this file when running in the background. If set,
|
|
||||||
# the given file will be created containing the process id of the new
|
|
||||||
# background process. This option is only used when running in background.
|
|
||||||
#pid_file: ""
|
|
||||||
|
|
||||||
# Change the user and/or group of the process once all the setup has been
|
|
||||||
# done and before spawning the background process. This option is only used
|
|
||||||
# when running in background.
|
|
||||||
#user: ""
|
|
||||||
#group: ""
|
|
||||||
|
|
||||||
|
|
||||||
# Beacon settings
|
|
||||||
beacon:
|
|
||||||
|
|
||||||
# File or command (prefix: "|") to use for storing beacons
|
|
||||||
#store: ""
|
|
||||||
|
|
||||||
# File or command (prefix: "|") to use for loading beacons
|
|
||||||
#load: ""
|
|
||||||
|
|
||||||
# How often to load and store beacons (in seconds)
|
|
||||||
interval: 3600
|
|
||||||
|
|
||||||
# Password to encrypt beacon data with
|
|
||||||
#password: ""
|
|
||||||
|
|
||||||
|
|
||||||
# Statsd settings
|
|
||||||
#statsd:
|
|
||||||
|
|
||||||
# Statsd server name:port
|
|
||||||
#server: ""
|
|
||||||
|
|
||||||
# Prefix to use for stats keys
|
|
||||||
#prefix: ""
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
[Unit]
|
||||||
|
Description=VpnCloud websocket proxy
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
Documentation=man:vpncloud(1)
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/vpncloud ws-proxy -l 3210
|
||||||
|
RestartSec=5s
|
||||||
|
Restart=on-failure
|
||||||
|
TasksMax=10
|
||||||
|
MemoryMax=50M
|
||||||
|
PrivateTmp=yes
|
||||||
|
ProtectHome=yes
|
||||||
|
ProtectSystem=strict
|
||||||
|
ReadWritePaths=/var/log /run
|
||||||
|
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_SYS_CHROOT
|
||||||
|
DeviceAllow=/dev/null rw
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -1,860 +0,0 @@
|
||||||
'\" t
|
|
||||||
.\" Title: vpncloud
|
|
||||||
.\" Author: [see the "AUTHORS" section]
|
|
||||||
.\" Generator: Asciidoctor 1.5.5
|
|
||||||
.\" Date: 2020-06-03
|
|
||||||
.\" Manual: \ \&
|
|
||||||
.\" Source: \ \&
|
|
||||||
.\" Language: English
|
|
||||||
.\"
|
|
||||||
.TH "VPNCLOUD" "1" "2020-06-03" "\ \&" "\ \&"
|
|
||||||
.ie \n(.g .ds Aq \(aq
|
|
||||||
.el .ds Aq '
|
|
||||||
.ss \n[.ss] 0
|
|
||||||
.nh
|
|
||||||
.ad l
|
|
||||||
.de URL
|
|
||||||
\\$2 \(laURL: \\$1 \(ra\\$3
|
|
||||||
..
|
|
||||||
.if \n[.g] .mso www.tmac
|
|
||||||
.LINKSTYLE blue R < >
|
|
||||||
.SH "NAME"
|
|
||||||
vpncloud \- Peer\-to\-peer VPN
|
|
||||||
.SH "SYNOPSIS"
|
|
||||||
.sp
|
|
||||||
\fBvpncloud [options] [\-\-config <file>] [\-t <type>] [\-d <name>] [\-l <addr>] [\-c <addr>...]\fP
|
|
||||||
.SH "OPTIONS"
|
|
||||||
.sp
|
|
||||||
\fB\-\-config <file>\fP
|
|
||||||
.RS 4
|
|
||||||
Read configuration options from the specified file. Please see the section
|
|
||||||
\fBCONFIG FILES\fP for documentation on the file format.
|
|
||||||
If the same option is defined in the config file and as a parameter, the
|
|
||||||
parameter overrides the config file.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-t <type>\fP, \fB\-\-type <type>\fP
|
|
||||||
.RS 4
|
|
||||||
Set the type of network. There are two options: \fBtap\fP devices process
|
|
||||||
Ethernet frames \fBtun\fP devices process IP packets. [default: \fBtap\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-d <name>\fP, \fB\-\-device <name>\fP
|
|
||||||
.RS 4
|
|
||||||
Name of the virtual device. Any \fB%d\fP will be filled with a free number.
|
|
||||||
[default: \fBvpncloud%d\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-device\-path <path>\fP
|
|
||||||
.RS 4
|
|
||||||
The path of the base device inode, e.g. /dev/net/run.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-m <mode>\fP, \fB\-\-mode <mode>\fP
|
|
||||||
.RS 4
|
|
||||||
The mode of the VPN. The VPN can like a router, a switch or a hub. A \fBhub\fP
|
|
||||||
will send all data always to all peers. A \fBswitch\fP will learn addresses
|
|
||||||
from incoming data and only send data to all peers when the address is
|
|
||||||
unknown. A \fBrouter\fP will send data according to known subnets of the
|
|
||||||
peers and ignore them otherwise. The \fBnormal\fP mode is switch for tap
|
|
||||||
devices and router for tun devices. [default: \fBnormal\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-l <addr>\fP, \fB\-\-listen <addr>\fP
|
|
||||||
.RS 4
|
|
||||||
The address on which to listen for data. This can be simply a port number
|
|
||||||
or a full address in form IP:PORT. If the IP is specified as \(aq\(rs*\(aq or only
|
|
||||||
a port number is given, then the socket will listen on all IPs (v4 and v6),
|
|
||||||
otherwise the socket will only listen on the given IP. [default: \fB3210\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-c <addr>\fP, \fB\-\-connect <addr>\fP
|
|
||||||
.RS 4
|
|
||||||
Address of a peer to connect to. The address should be in the form
|
|
||||||
\fBaddr:port\fP. If the node is not started, the connection will be retried
|
|
||||||
periodically. This parameter can be repeated to connect to multiple peers.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-s <subnet>\fP, \fB\-\-subnet <subnet>\fP:
|
|
||||||
The local subnets to use. This parameter should be in the form
|
|
||||||
\fBaddress/prefixlen\fP where address is an IPv4 address, an IPv6 address, or a
|
|
||||||
MAC address. The prefix length is the number of significant front bits that
|
|
||||||
distinguish the subnet from other subnets. Example: \fB10.1.1.0/24\fP.
|
|
||||||
.sp
|
|
||||||
\fB\-\-shared\-key <key>\fP
|
|
||||||
.RS 4
|
|
||||||
An optional shared key to encrypt the VPN data. If this option is not set,
|
|
||||||
the traffic will be sent unencrypted.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-crypto <method>\fP
|
|
||||||
.RS 4
|
|
||||||
The encryption method to use ("aes256", or "chacha20"). Most current CPUs
|
|
||||||
have special support for AES256 so this should be faster. For older
|
|
||||||
computers lacking this support, only CHACHA20 is supported.
|
|
||||||
[default: \fBchacha20\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-magic <id>\fP
|
|
||||||
.RS 4
|
|
||||||
Override the 4\-byte magic header of each packet. This header identifies the
|
|
||||||
network and helps to distinguish it from other networks and other
|
|
||||||
applications. The id can either be a 4 byte / 8 character hexadecimal
|
|
||||||
string or an arbitrary string prefixed with "hash:" which will then be
|
|
||||||
hashed into 4 bytes.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-peer\-timeout <secs>\fP
|
|
||||||
.RS 4
|
|
||||||
Peer timeout in seconds. The peers will exchange information periodically
|
|
||||||
and drop peers that are silent for this period of time. [default: \fB600\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-keepalive <secs>\fP
|
|
||||||
.RS 4
|
|
||||||
Interval of peer exchange messages in seconds. The peers will exchange
|
|
||||||
information periodically to keep connections alive. This setting overrides
|
|
||||||
how often this will happen. [default: \fBpeer\-timeout/2\-60\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-dst\-timeout <secs>\fP
|
|
||||||
.RS 4
|
|
||||||
Switch table entry timeout in seconds. This parameter is only used in switch
|
|
||||||
mode. Addresses that have not been seen for the given period of time will
|
|
||||||
be forgotten. [default: \fB300\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-beacon\-store <path|command>\fP
|
|
||||||
.RS 4
|
|
||||||
Periodically store beacons containing the address of this node in the given
|
|
||||||
file or via the given command. If the parameter value starts with a pipe
|
|
||||||
character (\fB|\fP), the rest of the value is interpreted as a shell command.
|
|
||||||
Otherwise the value is interpreted as a file to write the beacon to.
|
|
||||||
If this parameter is not given, beacon storage is disabled.
|
|
||||||
Please see the section \fBBEACONS\fP for more information.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-beacon\-load <path|command>\fP
|
|
||||||
.RS 4
|
|
||||||
Periodically load beacons containing the addresses of other nodes from the
|
|
||||||
given file or via the given command. If the parameter value starts with a
|
|
||||||
pipe character (\fB|\fP), the rest of the value is interpreted as a shell
|
|
||||||
command. Otherwise the value is interpreted as a file to read the beacon
|
|
||||||
from.
|
|
||||||
If this parameter is not given, beacon loading is disabled.
|
|
||||||
Please see the section \fBBEACONS\fP for more information.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-beacon\-interval <secs>\fP
|
|
||||||
.RS 4
|
|
||||||
Beacon storage/loading interval in seconds. If configured to do so via
|
|
||||||
\fB\-\-beacon\-store\fP and \fB\-\-beacon\-load\fP, the node will periodically store its
|
|
||||||
beacon and load beacons of other nodes. This parameter defines the interval
|
|
||||||
in seconds. [default: \fB3600\fP]
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-ifup <command>\fP
|
|
||||||
.RS 4
|
|
||||||
A command to setup the network interface. The command will be run (as
|
|
||||||
parameter to \fBsh \-c\fP) when the device has been created to configure it.
|
|
||||||
The name of the allocated device will be available via the environment
|
|
||||||
variable \fBIFNAME\fP.
|
|
||||||
Please note that this command is executed with the full permissions of the
|
|
||||||
caller.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-ifdown <command>\fP
|
|
||||||
.RS 4
|
|
||||||
A command to bring down the network interface. The command will be run (as
|
|
||||||
parameter to \fBsh \-c\fP) to remove any configuration from the device.
|
|
||||||
The name of the allocated device will be available via the environment
|
|
||||||
variable \fBIFNAME\fP.
|
|
||||||
Please note that this command is executed with the (limited) permissions of
|
|
||||||
the user and group given as \fB\-\-user\fP and \fB\-\-group\fP.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-pid\-file <file>\fP
|
|
||||||
.RS 4
|
|
||||||
Store the process id in this file when running in the background. If set,
|
|
||||||
the given file will be created containing the process id of the new
|
|
||||||
background process. This option is only used when running in background.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-user <user>\fP, \fB\-\-group <group>\fP
|
|
||||||
.RS 4
|
|
||||||
Change the user and/or group of the process once all the setup has been
|
|
||||||
done.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-log\-file <file>\fP
|
|
||||||
.RS 4
|
|
||||||
If set, print logs also to the given file. The file will be created and
|
|
||||||
truncated if is exists.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-stats\-file <file>\fP
|
|
||||||
.RS 4
|
|
||||||
If set, periodically write statistics on peers and current traffic to the
|
|
||||||
given file. The file will be periodically overwritten with new data.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-daemon\fP
|
|
||||||
.RS 4
|
|
||||||
Spawn a background process instead of running the process in the foreground.
|
|
||||||
If this flag is set, the process will first carry out all the
|
|
||||||
initialization, then drop permissions if \fB\-\-user\fP or \fB\-\-group\fP is used and
|
|
||||||
then spawn a background process and write its process id to a file if
|
|
||||||
\fB\-\-pid\-file\fP is set. Then, the main process will exit and the background
|
|
||||||
process continues to provide the VPN. At the time, when the main process
|
|
||||||
exits, the interface exists and is properly configured to be used.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-\-no\-port\-forwarding\fP
|
|
||||||
.RS 4
|
|
||||||
Disable automatic port forward. If this option is not set, VpnCloud tries to
|
|
||||||
detect a NAT router and automatically add a port forwarding to it.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-v\fP, \fB\-\-verbose\fP
|
|
||||||
.RS 4
|
|
||||||
Print debug information, including information for data being received and
|
|
||||||
sent.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-q\fP, \fB\-\-quiet\fP
|
|
||||||
.RS 4
|
|
||||||
Only print errors and warnings.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB\-h\fP, \fB\-\-help\fP
|
|
||||||
.RS 4
|
|
||||||
Display the help.
|
|
||||||
.RE
|
|
||||||
.SH "DESCRIPTION"
|
|
||||||
.sp
|
|
||||||
\fBVpnCloud\fP is a simple VPN over UDP. It creates a virtual network interface on
|
|
||||||
the host and forwards all received data via UDP to the destination. It can work
|
|
||||||
in 3 different modes:
|
|
||||||
.sp
|
|
||||||
\fBSwitch mode\fP
|
|
||||||
.RS 4
|
|
||||||
In this mode, the VPN will dynamically learn addresses
|
|
||||||
as they are used as source addresses and use them to forward data to its
|
|
||||||
destination. Addresses that have not been seen for some time
|
|
||||||
(option \fBswitch_timeout\fP) will be forgotten. Data for unknown addresses will be
|
|
||||||
broadcast to all peers. This mode is the default mode for TAP devices that
|
|
||||||
process Ethernet frames but it can also be used with TUN devices and IP
|
|
||||||
packets.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBHub mode\fP
|
|
||||||
.RS 4
|
|
||||||
In this mode, all data will always be broadcast to all peers.
|
|
||||||
This mode uses lots of bandwidth and should only be used in special cases.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBRouter mode\fP
|
|
||||||
.RS 4
|
|
||||||
In this mode, data will be forwarded based on preconfigured
|
|
||||||
address ranges ("subnets"). Data for unknown nodes will be silently ignored.
|
|
||||||
This mode is the default mode for TUN devices that work with IP packets but
|
|
||||||
it can also be used with TAP devices and Ethernet frames.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
All connected VpnCloud nodes will form a peer\-to\-peer network and cross\-connect
|
|
||||||
automatically until the network is fully connected. The nodes will periodically
|
|
||||||
exchange information with the other nodes to signal that they are still active
|
|
||||||
and to allow the automatic cross\-connect behavior. There are some important
|
|
||||||
things to note:
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04' 1.\h'+01'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP " 1." 4.2
|
|
||||||
.\}
|
|
||||||
To avoid that different networks that reuse each others addresses merge due
|
|
||||||
to the cross\-connect behavior, the \fBmagic\fP option can be used and set
|
|
||||||
to any unique string to identify the network. The \fBmagic\fP must be the
|
|
||||||
same on all nodes of the same VPN network.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04' 2.\h'+01'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP " 2." 4.2
|
|
||||||
.\}
|
|
||||||
The cross\-connect behavior can be able to connect nodes that are behind
|
|
||||||
firewalls or NATs as it can function as hole\-punching.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04' 3.\h'+01'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP " 3." 4.2
|
|
||||||
.\}
|
|
||||||
The management traffic will increase with the peer number quadratically.
|
|
||||||
It should still be reasonably small for high node numbers (below 10 KiB/s
|
|
||||||
for 10.000 nodes). A longer \fBpeer_timeout\fP can be used to reduce the traffic
|
|
||||||
further. For high node numbers, router mode should be used as it never
|
|
||||||
broadcasts data.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
VpnCloud does not implement any loop\-avoidance. Since data received on the UDP
|
|
||||||
socket will only be sent to the local network interface and vice versa, VpnCloud
|
|
||||||
cannot produce loops on its own. On the TAP device, however STP data can be
|
|
||||||
transported to avoid loops caused by other network components.
|
|
||||||
.sp
|
|
||||||
For TAP devices, IEEE 802.1q frames (VLAN tagged) are detected and forwarded
|
|
||||||
based on separate MAC tables. Any nested tags (Q\-in\-Q) will be ignored.
|
|
||||||
.SH "EXAMPLES"
|
|
||||||
.SS "Switched TAP scenario"
|
|
||||||
.sp
|
|
||||||
In the example scenario, a simple layer 2 network tunnel is established. Most
|
|
||||||
likely those commands need to be run as \fBroot\fP using \fBsudo\fP.
|
|
||||||
.sp
|
|
||||||
First, VpnCloud need to be started on both nodes (the address after \fB\-c\fP is the
|
|
||||||
address of the remote node and the the \fBX\fP in the interface address must be
|
|
||||||
unique among all nodes, e.g. 0, 1, 2, ...):
|
|
||||||
.sp
|
|
||||||
.if n \{\
|
|
||||||
.RS 4
|
|
||||||
.\}
|
|
||||||
.nf
|
|
||||||
vpncloud \-c REMOTE_HOST:PORT \-\-ifup \(aqifconfig $IFNAME 10.0.0.X/24 mtu 1400 up\(aq
|
|
||||||
.fi
|
|
||||||
.if n \{\
|
|
||||||
.RE
|
|
||||||
.\}
|
|
||||||
.sp
|
|
||||||
Afterwards, the interface can be used to communicate.
|
|
||||||
.SS "Routed TUN example"
|
|
||||||
.sp
|
|
||||||
In this example, 2 nodes and their subnets should communicate using IP.
|
|
||||||
First, VpnCloud need to be started on both nodes:
|
|
||||||
.sp
|
|
||||||
.if n \{\
|
|
||||||
.RS 4
|
|
||||||
.\}
|
|
||||||
.nf
|
|
||||||
vpncloud \-t tun \-c REMOTE_HOST:PORT \-\-subnet 10.0.X.0/24 \-\-ifup \(aqifconfig $IFNAME 10.0.X.1/16 mtu 1400 up\(aq
|
|
||||||
.fi
|
|
||||||
.if n \{\
|
|
||||||
.RE
|
|
||||||
.\}
|
|
||||||
.sp
|
|
||||||
It is important to configure the interface in a way that all addresses on the
|
|
||||||
VPN can be reached directly. E.g. if subnets 10.0.1.0/24, 10.0.2.0/24 and so on
|
|
||||||
are used, the interface needs to be configured as 10.0.1.1/16.
|
|
||||||
For TUN devices, this means that the prefix length of the subnets
|
|
||||||
(/24 in this example) must be different than the prefix length that the
|
|
||||||
interface is configured with (/16 in this example).
|
|
||||||
.SS "Important notes"
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04' 1.\h'+01'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP " 1." 4.2
|
|
||||||
.\}
|
|
||||||
VpnCloud can be used to connect two separate networks. TAP networks can be
|
|
||||||
bridged using \fBbrctl\fP and TUN networks must be routed. It is very important
|
|
||||||
to be careful when setting up such a scenario in order to avoid network loops,
|
|
||||||
security issues, DHCP issues and many more problems.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04' 2.\h'+01'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP " 2." 4.2
|
|
||||||
.\}
|
|
||||||
TAP devices will forward DHCP data. If done intentionally, this can be used
|
|
||||||
to assign unique addresses to all participants. If this happens accidentally,
|
|
||||||
it can conflict with DHCP servers of the local network and can have severe
|
|
||||||
side effects.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04' 3.\h'+01'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP " 3." 4.2
|
|
||||||
.\}
|
|
||||||
VpnCloud is not designed for high security use cases. Although the used crypto
|
|
||||||
primitives are expected to be very secure, their application has not been
|
|
||||||
reviewed.
|
|
||||||
The shared key is hashed using \fIScryptSalsa208Sha256\fP to derive a key,
|
|
||||||
which is used to encrypt the payload of messages using \fIChaCha20Poly1305\fP or
|
|
||||||
\fIAES256\-GCM\fP. The encryption includes an authentication that also protects the
|
|
||||||
header.
|
|
||||||
This method does only protect against attacks on single messages but not
|
|
||||||
against attacks that manipulate the message series itself (i.e. suppress
|
|
||||||
messages, reorder them, or duplicate them).
|
|
||||||
.RE
|
|
||||||
.SH "CONFIG FILES"
|
|
||||||
.sp
|
|
||||||
The config file is a YAML file that contains configuration values. All entries
|
|
||||||
are optional and override the defaults. Please see the section \fBOPTIONS\fP for
|
|
||||||
detailed descriptions of the options.
|
|
||||||
.sp
|
|
||||||
\fBdevice_type\fP
|
|
||||||
.RS 4
|
|
||||||
Set the type of network. Same as \fB\-\-type\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBdevice_name\fP
|
|
||||||
.RS 4
|
|
||||||
Name of the virtual device. Same as \fB\-\-device\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBdevice_path\fP
|
|
||||||
.RS 4
|
|
||||||
Set the path of the base device. Same as \fB\-\-device\-path\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBifup\fP
|
|
||||||
.RS 4
|
|
||||||
A command to setup the network interface. Same as \fB\-\-ifup\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBifdown\fP
|
|
||||||
.RS 4
|
|
||||||
A command to bring down the network interface. Same as \fB\-\-ifdown\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBcrypto\fP
|
|
||||||
.RS 4
|
|
||||||
The encryption method to use. Same as \fB\-\-crypto\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBshared_key\fP
|
|
||||||
.RS 4
|
|
||||||
The shared key to encrypt all traffic. Same as \fB\-\-shared\-key\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBmagic\fP
|
|
||||||
.RS 4
|
|
||||||
Override the 4\-byte magic header of each packet. Same as \fB\-\-magic\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBport\fP
|
|
||||||
.RS 4
|
|
||||||
A port number to listen on. This option is DEPRECATED.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBlisten\fP
|
|
||||||
.RS 4
|
|
||||||
The address on which to listen for data. Same as \fB\-\-listen\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBpeers\fP
|
|
||||||
.RS 4
|
|
||||||
A list of addresses to connect to. See \fB\-\-connect\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBpeer_timeout\fP
|
|
||||||
.RS 4
|
|
||||||
Peer timeout in seconds. Same as\fB\-\-peer\-timeout\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBbeacon_store\fP
|
|
||||||
.RS 4
|
|
||||||
Path or command to store beacons. Same as \fB\-\-beacon\-store\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBbeacon_load\fP
|
|
||||||
.RS 4
|
|
||||||
Path or command to load beacons. Same as \fB\-\-beacon\-load\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBbeacon_interval\fP
|
|
||||||
.RS 4
|
|
||||||
Interval for loading and storing beacons in seconds. Same as \fB\-\-beacon\-interval\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBmode\fP
|
|
||||||
.RS 4
|
|
||||||
The mode of the VPN. Same as \fB\-\-mode\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBswitch_timeout\fP
|
|
||||||
.RS 4
|
|
||||||
Switch table entry timeout in seconds. Same as \fB\-\-dst\-timeout\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBsubnets\fP
|
|
||||||
.RS 4
|
|
||||||
A list of local subnets to use. See \fB\-\-subnet\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBport_forwarding\fP
|
|
||||||
.RS 4
|
|
||||||
Whether to activate port forwardig. See \fB\-\-no\-port\-forwarding\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBuser\fP
|
|
||||||
.RS 4
|
|
||||||
The name of a user to run the background process under. See \fB\-\-user\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBgroup\fP
|
|
||||||
.RS 4
|
|
||||||
The name of a group to run the background process under. See \fB\-\-group\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBpid_file\fP
|
|
||||||
.RS 4
|
|
||||||
The path of the pid file to create. See \fB\-\-pid\-file\fP
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBstats_file\fP
|
|
||||||
.RS 4
|
|
||||||
The path of the statistics file. See \fB\-\-stats\-file\fP
|
|
||||||
.RE
|
|
||||||
.SS "Example"
|
|
||||||
.sp
|
|
||||||
.if n \{\
|
|
||||||
.RS 4
|
|
||||||
.\}
|
|
||||||
.nf
|
|
||||||
device_type: tun
|
|
||||||
device_name: vpncloud%d
|
|
||||||
ifup: ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up
|
|
||||||
crypto: aes256
|
|
||||||
shared_key: mysecret
|
|
||||||
listen: 3210
|
|
||||||
peers:
|
|
||||||
\- remote.machine.foo:3210
|
|
||||||
\- remote.machine.bar:3210
|
|
||||||
peer_timeout: 600
|
|
||||||
mode: normal
|
|
||||||
subnets:
|
|
||||||
\- 10.0.1.0/24
|
|
||||||
port_forwarding: true
|
|
||||||
user: nobody
|
|
||||||
group: nogroup
|
|
||||||
pid_file: /run/vpncloud.pid
|
|
||||||
.fi
|
|
||||||
.if n \{\
|
|
||||||
.RE
|
|
||||||
.\}
|
|
||||||
.SH "BEACONS"
|
|
||||||
.sp
|
|
||||||
Beacons are short character sequences that contain a timestamp and a list of
|
|
||||||
addresses. They can be published and retrieved by other nodes to find peers
|
|
||||||
without the need for static addresses.
|
|
||||||
.sp
|
|
||||||
The beacons are short (less than 100 characters), encrypted and encoded with
|
|
||||||
printable characters to allow publishing them in various places on the
|
|
||||||
internet, e.g.:
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
On shared drives or synchronized folders (e.g. on Dropbox)
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Via a dedicated database
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Via a general purpose message board of message service (e.g. Twitter)
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
The beacons are very robust. They only consist of alphanumeric characters
|
|
||||||
and can be interleaved with non\-alphanumeric characters (e.g. whitespace).
|
|
||||||
Also the beacons contain a prefix and suffix that depends on the configured
|
|
||||||
network magic and secret key (if set) so that all nodes can find beacons in
|
|
||||||
a long text.
|
|
||||||
.sp
|
|
||||||
When beacons are stored or loaded via a command (using the pipe character \fB|\fP),
|
|
||||||
the command is interpreted using the configured shell \fBsh\fP. This command has
|
|
||||||
access to the following environment variables:
|
|
||||||
.sp
|
|
||||||
\fB$begin\fP
|
|
||||||
.RS 4
|
|
||||||
The prefix of the beacon.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB$end\fP
|
|
||||||
.RS 4
|
|
||||||
The suffix of the beacon.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB$data\fP (only on store)
|
|
||||||
.RS 4
|
|
||||||
The middle part of the beacon. Do not use this
|
|
||||||
without prefix and suffix!
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fB$beacon\fP (only on store)
|
|
||||||
.RS 4
|
|
||||||
The full beacon consisting of prefix, data and
|
|
||||||
suffix.
|
|
||||||
The commands are called in separate threads, so even longer running commands
|
|
||||||
will not block the node.
|
|
||||||
.RE
|
|
||||||
.SH "NETWORK PROTOCOL"
|
|
||||||
.sp
|
|
||||||
The protocol of VpnCloud is kept as simple as possible to allow other
|
|
||||||
implementations and to maximize the performance.
|
|
||||||
.sp
|
|
||||||
Every packet sent over UDP contains the following header (in order):
|
|
||||||
.sp
|
|
||||||
4 bytes \fBmagic\fP
|
|
||||||
.RS 4
|
|
||||||
This field is used to identify the packet and to sort out packets that do
|
|
||||||
not belong. The default is \fB[0x76, 0x70, 0x6e, 0x01]\fP ("vpn\(rsx01").
|
|
||||||
This field can be used to identify VpnCloud packets and might be set to
|
|
||||||
something different to hide the protocol.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
1 byte \fBcrypto method\fP
|
|
||||||
.RS 4
|
|
||||||
This field specifies the method that must be used to decrypt the rest of the
|
|
||||||
data. The currently supported methods are:
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Method \fB0\fP, \fBNo encryption\fP: Rest of the data can be read without
|
|
||||||
decrypting it.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Method \fB1\fP, \fBChaCha20\fP: The header is followed by a 12 byte
|
|
||||||
\fInonce\fP. The rest of the data is encrypted with the
|
|
||||||
\fBlibsodium::crypto_aead_chacha20poly1305_ietf\fP method, using the 8 byte
|
|
||||||
header as additional data.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Method \fB2\fP, \fBAES256\fP: The header is followed by a 12 byte \fInonce\fP.
|
|
||||||
The rest of the data is encrypted with the
|
|
||||||
\fBlibsodium::crypto_aead_aes256gcm\fP method, using the 8 byte header
|
|
||||||
as additional data.
|
|
||||||
.RE
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
2 \fBreserved bytes\fP
|
|
||||||
.RS 4
|
|
||||||
that are currently unused and set to 0
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
1 byte for the \fBmessage type\fP
|
|
||||||
.RS 4
|
|
||||||
This byte specifies the type of message that follows. Currently the
|
|
||||||
following message types are supported:
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Type 0: Data packet
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Type 1: Peer list
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Type 2: Initial message
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
Type 3: Closing message
|
|
||||||
.RE
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
After this 8 byte header, the rest of the message follows. It is encrypted using
|
|
||||||
the method specified in the header.
|
|
||||||
.sp
|
|
||||||
In the decrypted data, the message as specified in the \fBmessage type\fP field
|
|
||||||
will follow:
|
|
||||||
.sp
|
|
||||||
\fBData packet\fP (message type 0)
|
|
||||||
.RS 4
|
|
||||||
This packet contains payload. The format of the data depends on the device
|
|
||||||
type. For TUN devices, this data contains an IP packet. For TAP devices it
|
|
||||||
contains an Ethernet frame. The data starts right after the header and ends
|
|
||||||
at the end of the packet.
|
|
||||||
If it is an Ethernet frame, it will start with the destination MAC and end
|
|
||||||
with the payload. It does not contain the preamble, SFD, padding, and CRC
|
|
||||||
fields.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBPeer list\fP (message type 1)
|
|
||||||
.RS 4
|
|
||||||
This packet contains the peer list of the sender. The first byte after the
|
|
||||||
switch byte contains the number of IPv4 addresses that follow.
|
|
||||||
After that, the specified number of addresses follow, where each address
|
|
||||||
is encoded in 6 bytes. The first 4 bytes are the IPv4 address and the later
|
|
||||||
2 bytes are port number (both in network byte order).
|
|
||||||
After those addresses, the next byte contains the number of IPv6 addresses
|
|
||||||
that follow. After that, the specified number of addresses follow, where
|
|
||||||
each address is encoded in 18 bytes. The first 16 bytes are the IPv6 address
|
|
||||||
and the later 2 bytes are port number (both in network byte order).
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBInitial message\fP (message type 2)
|
|
||||||
.RS 4
|
|
||||||
This packet contains the following information:
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
The stage of the initialization process
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
A random node id to distinguish different nodes
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
.RS 4
|
|
||||||
.ie n \{\
|
|
||||||
\h'-04'\(bu\h'+03'\c
|
|
||||||
.\}
|
|
||||||
.el \{\
|
|
||||||
.sp -1
|
|
||||||
.IP \(bu 2.3
|
|
||||||
.\}
|
|
||||||
All the local subnets claimed by the nodes
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
Its first byte marks the stage of the initial handshake process.
|
|
||||||
The next 16 bytes contain the unique node id. After that,
|
|
||||||
the list of local subnets follows.
|
|
||||||
The subnet list is encoded in the following way: Its first byte of data
|
|
||||||
contains the number of encoded subnets that follow. After that, the given
|
|
||||||
number of encoded subnets follow.
|
|
||||||
For each subnet, the first byte is the length of bytes in the base address
|
|
||||||
and is followed by the given number of base address bytes and one additional
|
|
||||||
byte that is the prefix length of the subnet.
|
|
||||||
The addresses for the subnet will be encoded like they are encoded in their
|
|
||||||
native protocol (4 bytes for IPv4, 16 bytes for IPv6, and 6 bytes for a MAC
|
|
||||||
address) with the exception of MAC addresses in a VLan which will be encoded
|
|
||||||
in 8 bytes where the first 2 bytes are the VLan number in network byte order
|
|
||||||
and the later 6 bytes are the MAC address.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
\fBClosing message\fP (message type 3)
|
|
||||||
.RS 4
|
|
||||||
This packet does not contain any more data.
|
|
||||||
.RE
|
|
||||||
.sp
|
|
||||||
Nodes are expected to send an \fBinitial message\fP with stage 0 whenever they
|
|
||||||
connect to a node they were not connected to before. As a reply to this message,
|
|
||||||
another initial should be sent with stage 1. Also a \fBpeer list\fP message should
|
|
||||||
be sent as a reply.
|
|
||||||
.sp
|
|
||||||
When connected, nodes should periodically send their \fBpeer list\fP to all
|
|
||||||
of their peers to spread this information and to avoid peer timeouts.
|
|
||||||
To avoid the cubic growth of management traffic, nodes should at a certain
|
|
||||||
network size start sending partial peer lists instead of the full list. A
|
|
||||||
reasonable number would be about 20 peers. The subsets should be selected
|
|
||||||
randomly.
|
|
||||||
.sp
|
|
||||||
Nodes should remove peers from their peer list after a certain period of
|
|
||||||
inactivity or when receiving a \fBclosing message\fP. Before shutting down, nodes
|
|
||||||
should send the closing message to all of their peers in order to avoid
|
|
||||||
receiving further data until the timeout is reached.
|
|
||||||
.sp
|
|
||||||
Nodes should only add nodes to their peer list after receiving an initial
|
|
||||||
message from them instead of adding them right from the peer list of another
|
|
||||||
peer. This is necessary to avoid the case of a large network keeping dead nodes
|
|
||||||
alive.
|
|
||||||
.SH "COPYRIGHT"
|
|
||||||
.sp
|
|
||||||
Copyright \(co 2015\-2020 Dennis Schwerdel
|
|
||||||
This software is licensed under GPL\-3 or newer (see LICENSE.md)
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
#[macro_use]
|
||||||
|
mod util {
|
||||||
|
include!("../src/util.rs");
|
||||||
|
}
|
||||||
|
mod error {
|
||||||
|
include!("../src/error.rs");
|
||||||
|
}
|
||||||
|
mod payload {
|
||||||
|
include!("../src/payload.rs");
|
||||||
|
}
|
||||||
|
mod types {
|
||||||
|
include!("../src/types.rs");
|
||||||
|
}
|
||||||
|
mod table {
|
||||||
|
include!("../src/table.rs");
|
||||||
|
}
|
||||||
|
mod cloud {
|
||||||
|
include!("../src/cloud.rs");
|
||||||
|
}
|
||||||
|
mod config {
|
||||||
|
include!("../src/config.rs");
|
||||||
|
}
|
||||||
|
mod device {
|
||||||
|
include!("../src/device.rs");
|
||||||
|
}
|
||||||
|
mod net {
|
||||||
|
include!("../src/net.rs");
|
||||||
|
}
|
||||||
|
mod beacon {
|
||||||
|
include!("../src/beacon.rs");
|
||||||
|
}
|
||||||
|
mod messages {
|
||||||
|
include!("../src/messages.rs");
|
||||||
|
}
|
||||||
|
mod port_forwarding {
|
||||||
|
include!("../src/port_forwarding.rs");
|
||||||
|
}
|
||||||
|
mod traffic {
|
||||||
|
include!("../src/traffic.rs");
|
||||||
|
}
|
||||||
|
mod poll {
|
||||||
|
pub mod epoll{
|
||||||
|
include!("../src/poll/epoll.rs");
|
||||||
|
}
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
pub use self::epoll::EpollWait as WaitImpl;
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
pub enum WaitResult {
|
||||||
|
Timeout,
|
||||||
|
Socket,
|
||||||
|
Device,
|
||||||
|
Error(io::Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mod crypto {
|
||||||
|
pub mod core {
|
||||||
|
include!("../src/crypto/core.rs");
|
||||||
|
}
|
||||||
|
pub mod init {
|
||||||
|
include!("../src/crypto/init.rs");
|
||||||
|
}
|
||||||
|
pub mod rotate {
|
||||||
|
include!("../src/crypto/rotate.rs");
|
||||||
|
}
|
||||||
|
pub mod common {
|
||||||
|
include!("../src/crypto/common.rs");
|
||||||
|
}
|
||||||
|
pub use common::*;
|
||||||
|
pub use self::core::{EXTRA_LEN, TAG_LEN};
|
||||||
|
}
|
||||||
|
mod tests {
|
||||||
|
pub mod common {
|
||||||
|
include!("../src/tests/common.rs");
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,31 +10,17 @@ use ring::aead;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::net::{SocketAddr, Ipv4Addr, SocketAddrV4, UdpSocket};
|
use std::net::{SocketAddr, Ipv4Addr, SocketAddrV4, UdpSocket};
|
||||||
|
|
||||||
mod util {
|
include!(".code.rs");
|
||||||
include!("../src/util.rs");
|
|
||||||
}
|
|
||||||
mod error {
|
|
||||||
include!("../src/error.rs");
|
|
||||||
}
|
|
||||||
mod payload {
|
|
||||||
include!("../src/payload.rs");
|
|
||||||
}
|
|
||||||
mod types {
|
|
||||||
include!("../src/types.rs");
|
|
||||||
}
|
|
||||||
mod table {
|
|
||||||
include!("../src/table.rs");
|
|
||||||
}
|
|
||||||
mod crypto_core {
|
|
||||||
include!("../src/crypto/core.rs");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
use util::{MockTimeSource, MsgBuffer};
|
use util::{MockTimeSource, MsgBuffer};
|
||||||
use types::{Address, Range};
|
use types::{Address, Range};
|
||||||
use table::{ClaimTable};
|
use table::{ClaimTable};
|
||||||
|
use device::Type;
|
||||||
|
use config::Config;
|
||||||
use payload::{Packet, Frame, Protocol};
|
use payload::{Packet, Frame, Protocol};
|
||||||
use crypto_core::{create_dummy_pair, EXTRA_LEN};
|
use crypto::core::{create_dummy_pair, EXTRA_LEN};
|
||||||
|
use tests::common::{TunSimulator, TapSimulator};
|
||||||
|
|
||||||
fn udp_send(c: &mut Criterion) {
|
fn udp_send(c: &mut Criterion) {
|
||||||
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
|
@ -145,5 +131,74 @@ fn crypto_aes256(c: &mut Criterion) {
|
||||||
crypto_bench(c, &aead::AES_256_GCM)
|
crypto_bench(c, &aead::AES_256_GCM)
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches, udp_send, decode_ipv4, decode_ipv6, decode_ethernet, decode_ethernet_with_vlan, lookup_cold, lookup_warm, crypto_chacha20, crypto_aes128, crypto_aes256);
|
fn full_communication_tun_router(c: &mut Criterion) {
|
||||||
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
|
let config1 = Config {
|
||||||
|
device_type: Type::Tun,
|
||||||
|
auto_claim: false,
|
||||||
|
claims: vec!["1.1.1.1/32".to_string()],
|
||||||
|
..Config::default()
|
||||||
|
};
|
||||||
|
let config2 = Config {
|
||||||
|
device_type: Type::Tun,
|
||||||
|
auto_claim: false,
|
||||||
|
claims: vec!["2.2.2.2/32".to_string()],
|
||||||
|
..Config::default()
|
||||||
|
};
|
||||||
|
let mut sim = TunSimulator::new();
|
||||||
|
let node1 = sim.add_node(false, &config1);
|
||||||
|
let node2 = sim.add_node(false, &config2);
|
||||||
|
|
||||||
|
sim.connect(node1, node2);
|
||||||
|
sim.simulate_all_messages();
|
||||||
|
assert!(sim.is_connected(node1, node2));
|
||||||
|
assert!(sim.is_connected(node2, node1));
|
||||||
|
|
||||||
|
let mut payload = vec![0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2];
|
||||||
|
payload.append(&mut vec![0; 1400]);
|
||||||
|
let mut g = c.benchmark_group("full_communication");
|
||||||
|
g.throughput(Throughput::Bytes(2*1400));
|
||||||
|
g.bench_function("tun_router", |b| {
|
||||||
|
b.iter(|| {
|
||||||
|
sim.put_payload(node1, payload.clone());
|
||||||
|
sim.simulate_all_messages();
|
||||||
|
assert_eq!(Some(&payload), sim.pop_payload(node2).as_ref());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
g.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn full_communication_tap_switch(c: &mut Criterion) {
|
||||||
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
|
let config = Config { device_type: Type::Tap, ..Config::default() };
|
||||||
|
let mut sim = TapSimulator::new();
|
||||||
|
let node1 = sim.add_node(false, &config);
|
||||||
|
let node2 = sim.add_node(false, &config);
|
||||||
|
|
||||||
|
sim.connect(node1, node2);
|
||||||
|
sim.simulate_all_messages();
|
||||||
|
assert!(sim.is_connected(node1, node2));
|
||||||
|
assert!(sim.is_connected(node2, node1));
|
||||||
|
|
||||||
|
let mut payload = vec![2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5];
|
||||||
|
payload.append(&mut vec![0; 1400]);
|
||||||
|
let mut g = c.benchmark_group("full_communication");
|
||||||
|
g.throughput(Throughput::Bytes(2*1400));
|
||||||
|
g.bench_function("tap_switch", |b| {
|
||||||
|
b.iter(|| {
|
||||||
|
sim.put_payload(node1, payload.clone());
|
||||||
|
sim.simulate_all_messages();
|
||||||
|
assert_eq!(Some(&payload), sim.pop_payload(node2).as_ref());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
g.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches,
|
||||||
|
udp_send,
|
||||||
|
decode_ipv4, decode_ipv6, decode_ethernet, decode_ethernet_with_vlan,
|
||||||
|
lookup_cold, lookup_warm,
|
||||||
|
crypto_chacha20, crypto_aes128, crypto_aes256,
|
||||||
|
full_communication_tun_router, full_communication_tap_switch
|
||||||
|
);
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
|
@ -0,0 +1,155 @@
|
||||||
|
#![allow(dead_code, unused_macros, unused_imports)]
|
||||||
|
#[macro_use] extern crate serde;
|
||||||
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
|
use iai::{black_box, main};
|
||||||
|
|
||||||
|
use smallvec::smallvec;
|
||||||
|
use ring::aead;
|
||||||
|
|
||||||
|
use std::str::FromStr;
|
||||||
|
use std::net::{SocketAddr, Ipv4Addr, SocketAddrV4, UdpSocket};
|
||||||
|
|
||||||
|
include!(".code.rs");
|
||||||
|
|
||||||
|
pub use error::Error;
|
||||||
|
use util::{MockTimeSource, MsgBuffer};
|
||||||
|
use config::Config;
|
||||||
|
use types::{Address, Range};
|
||||||
|
use device::Type;
|
||||||
|
use table::{ClaimTable};
|
||||||
|
use payload::{Packet, Frame, Protocol};
|
||||||
|
use crypto::core::{create_dummy_pair, EXTRA_LEN};
|
||||||
|
use tests::common::{TunSimulator, TapSimulator};
|
||||||
|
|
||||||
|
fn udp_send() {
|
||||||
|
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
|
let data = [0; 1400];
|
||||||
|
let addr = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 1);
|
||||||
|
sock.send_to(&data, &black_box(addr)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_ipv4() {
|
||||||
|
let data = [0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 168, 1, 1, 192, 168, 1, 2];
|
||||||
|
Packet::parse(&black_box(data)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_ipv6() {
|
||||||
|
let data = [
|
||||||
|
0x60, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6, 5,
|
||||||
|
4, 3, 2, 1
|
||||||
|
];
|
||||||
|
Packet::parse(&black_box(data)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_ethernet() {
|
||||||
|
let data = [6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||||
|
Frame::parse(&black_box(data)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_ethernet_with_vlan() {
|
||||||
|
let data = [6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 0x81, 0, 4, 210, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||||
|
Frame::parse(&black_box(data)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup_warm() {
|
||||||
|
let mut table = ClaimTable::<MockTimeSource>::new(60, 60);
|
||||||
|
let addr = Address::from_str("1.2.3.4").unwrap();
|
||||||
|
table.cache(addr, SocketAddr::from_str("1.2.3.4:3210").unwrap());
|
||||||
|
for _ in 0..1000 {
|
||||||
|
table.lookup(black_box(addr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup_cold() {
|
||||||
|
let mut table = ClaimTable::<MockTimeSource>::new(60, 60);
|
||||||
|
let addr = Address::from_str("1.2.3.4").unwrap();
|
||||||
|
table.set_claims(SocketAddr::from_str("1.2.3.4:3210").unwrap(), smallvec![Range::from_str("1.2.3.4/32").unwrap()]);
|
||||||
|
for _ in 0..1000 {
|
||||||
|
table.clear_cache();
|
||||||
|
table.lookup(black_box(addr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn crypto_bench(algo: &'static aead::Algorithm) {
|
||||||
|
let mut buffer = MsgBuffer::new(EXTRA_LEN);
|
||||||
|
buffer.set_length(1400);
|
||||||
|
let (mut sender, mut receiver) = create_dummy_pair(algo);
|
||||||
|
for _ in 0..1000 {
|
||||||
|
sender.encrypt(black_box(&mut buffer));
|
||||||
|
receiver.decrypt(&mut buffer).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn crypto_chacha20() {
|
||||||
|
crypto_bench(&aead::CHACHA20_POLY1305)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn crypto_aes128() {
|
||||||
|
crypto_bench(&aead::AES_128_GCM)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn crypto_aes256() {
|
||||||
|
crypto_bench(&aead::AES_256_GCM)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn full_communication_tun_router() {
|
||||||
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
|
let config1 = Config {
|
||||||
|
device_type: Type::Tun,
|
||||||
|
auto_claim: false,
|
||||||
|
claims: vec!["1.1.1.1/32".to_string()],
|
||||||
|
..Config::default()
|
||||||
|
};
|
||||||
|
let config2 = Config {
|
||||||
|
device_type: Type::Tun,
|
||||||
|
auto_claim: false,
|
||||||
|
claims: vec!["2.2.2.2/32".to_string()],
|
||||||
|
..Config::default()
|
||||||
|
};
|
||||||
|
let mut sim = TunSimulator::new();
|
||||||
|
let node1 = sim.add_node(false, &config1);
|
||||||
|
let node2 = sim.add_node(false, &config2);
|
||||||
|
|
||||||
|
sim.connect(node1, node2);
|
||||||
|
sim.simulate_all_messages();
|
||||||
|
assert!(sim.is_connected(node1, node2));
|
||||||
|
assert!(sim.is_connected(node2, node1));
|
||||||
|
|
||||||
|
let mut payload = vec![0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2];
|
||||||
|
payload.append(&mut vec![0; 1400]);
|
||||||
|
for _ in 0..1000 {
|
||||||
|
sim.put_payload(node1, payload.clone());
|
||||||
|
sim.simulate_all_messages();
|
||||||
|
assert_eq!(Some(&payload), black_box(sim.pop_payload(node2).as_ref()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn full_communication_tap_switch() {
|
||||||
|
log::set_max_level(log::LevelFilter::Error);
|
||||||
|
let config = Config { device_type: Type::Tap, ..Config::default() };
|
||||||
|
let mut sim = TapSimulator::new();
|
||||||
|
let node1 = sim.add_node(false, &config);
|
||||||
|
let node2 = sim.add_node(false, &config);
|
||||||
|
|
||||||
|
sim.connect(node1, node2);
|
||||||
|
sim.simulate_all_messages();
|
||||||
|
assert!(sim.is_connected(node1, node2));
|
||||||
|
assert!(sim.is_connected(node2, node1));
|
||||||
|
|
||||||
|
let mut payload = vec![2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5];
|
||||||
|
payload.append(&mut vec![0; 1400]);
|
||||||
|
for _ in 0..1000 {
|
||||||
|
sim.put_payload(node1, payload.clone());
|
||||||
|
sim.simulate_all_messages();
|
||||||
|
assert_eq!(Some(&payload), black_box(sim.pop_payload(node2).as_ref()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iai::main!(
|
||||||
|
udp_send,
|
||||||
|
decode_ipv4, decode_ipv6, decode_ethernet, decode_ethernet_with_vlan,
|
||||||
|
lookup_cold, lookup_warm,
|
||||||
|
crypto_chacha20, crypto_aes128, crypto_aes256,
|
||||||
|
full_communication_tun_router, full_communication_tap_switch
|
||||||
|
);
|
2
build.rs
2
build.rs
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use std::{env, fs, path::Path, process::Command};
|
use std::{env, fs, path::Path, process::Command};
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
AWSTemplateFormatVersion: 2010-09-09
|
||||||
|
Description: |
|
||||||
|
VpnCloud Websocket Proxy
|
||||||
|
This will configure a websocket proxy to be used with VpnCloud.
|
||||||
|
Versions: Ubuntu Server 20.04 LTS + VpnCloud 2.1.0
|
||||||
|
Parameters:
|
||||||
|
LatestAmiId:
|
||||||
|
Description: "Image to use (just leave this as it is)"
|
||||||
|
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
|
||||||
|
Default: '/aws/service/canonical/ubuntu/server/20.04/stable/current/arm64/hvm/ebs-gp2/ami-id'
|
||||||
|
AllowedValues:
|
||||||
|
- '/aws/service/canonical/ubuntu/server/20.04/stable/current/arm64/hvm/ebs-gp2/ami-id'
|
||||||
|
Resources:
|
||||||
|
ProxySecurityGroup:
|
||||||
|
Type: 'AWS::EC2::SecurityGroup'
|
||||||
|
Properties:
|
||||||
|
GroupDescription: Enable HTTP access via port 80 and any UDP port
|
||||||
|
SecurityGroupIngress:
|
||||||
|
- IpProtocol: tcp
|
||||||
|
FromPort: '80'
|
||||||
|
ToPort: '80'
|
||||||
|
CidrIp: 0.0.0.0/0
|
||||||
|
- IpProtocol: udp
|
||||||
|
FromPort: '1024'
|
||||||
|
ToPort: '65535'
|
||||||
|
CidrIp: 0.0.0.0/0
|
||||||
|
LaunchTemplate:
|
||||||
|
Type: AWS::EC2::LaunchTemplate
|
||||||
|
DependsOn:
|
||||||
|
- ProxySecurityGroup
|
||||||
|
Properties:
|
||||||
|
LaunchTemplateData:
|
||||||
|
ImageId: !Ref LatestAmiId
|
||||||
|
SecurityGroups:
|
||||||
|
- !Ref ProxySecurityGroup
|
||||||
|
InstanceMarketOptions:
|
||||||
|
MarketType: spot
|
||||||
|
InstanceType: t4g.nano
|
||||||
|
TagSpecifications:
|
||||||
|
- ResourceType: instance
|
||||||
|
Tags:
|
||||||
|
- Key: Name
|
||||||
|
Value: VpnCloud WS Proxy
|
||||||
|
CreditSpecification:
|
||||||
|
CpuCredits: standard
|
||||||
|
BlockDeviceMappings:
|
||||||
|
- DeviceName: /dev/sda1
|
||||||
|
Ebs:
|
||||||
|
VolumeType: standard
|
||||||
|
VolumeSize: '8'
|
||||||
|
DeleteOnTermination: 'true'
|
||||||
|
Encrypted: 'false'
|
||||||
|
UserData:
|
||||||
|
Fn::Base64: !Sub |
|
||||||
|
#cloud-config
|
||||||
|
packages:
|
||||||
|
- iperf3
|
||||||
|
- socat
|
||||||
|
runcmd:
|
||||||
|
- wget https://github.com/dswd/vpncloud/releases/download/v2.1.0/vpncloud_2.1.0_arm64.deb -O /tmp/vpncloud.deb
|
||||||
|
- dpkg -i /tmp/vpncloud.deb
|
||||||
|
- nohup vpncloud ws-proxy -l 80 &
|
||||||
|
ProxyInstance:
|
||||||
|
Type: 'AWS::EC2::Instance'
|
||||||
|
DependsOn:
|
||||||
|
- LaunchTemplate
|
||||||
|
Properties:
|
||||||
|
LaunchTemplate:
|
||||||
|
LaunchTemplateId:
|
||||||
|
Ref: LaunchTemplate
|
||||||
|
Version: 1
|
||||||
|
Outputs:
|
||||||
|
ProxyURL:
|
||||||
|
Description: URL to use in VpnCloud config
|
||||||
|
Value: !Join
|
||||||
|
- ''
|
||||||
|
- - 'ws://'
|
||||||
|
- !GetAtt
|
||||||
|
- ProxyInstance
|
||||||
|
- PublicDnsName
|
||||||
|
- ':80'
|
|
@ -6,8 +6,8 @@ import time
|
||||||
setup = EC2Environment(
|
setup = EC2Environment(
|
||||||
region = "eu-central-1",
|
region = "eu-central-1",
|
||||||
node_count = 2,
|
node_count = 2,
|
||||||
instance_type = 't3.nano',
|
instance_type = 't3a.nano',
|
||||||
vpncloud_version = "1.4.0"
|
vpncloud_version = "2.1.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
sender = setup.nodes[0]
|
sender = setup.nodes[0]
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
{
|
||||||
|
"meta": {
|
||||||
|
"region": "eu-central-1",
|
||||||
|
"instance_type": "m5.large",
|
||||||
|
"ami": "ami-0a6dc7529cd559185",
|
||||||
|
"version": "2.1.0",
|
||||||
|
"duration": 622.053159236908
|
||||||
|
},
|
||||||
|
"native": {
|
||||||
|
"iperf": {
|
||||||
|
"throughput": 9672965000.0,
|
||||||
|
"cpu_sender": 11.936759,
|
||||||
|
"cpu_receiver": 70.348812
|
||||||
|
},
|
||||||
|
"ping_100": {
|
||||||
|
"rtt_min": 0.046,
|
||||||
|
"rtt_max": 0.246,
|
||||||
|
"rtt_avg": 0.053,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_500": {
|
||||||
|
"rtt_min": 0.048,
|
||||||
|
"rtt_max": 0.183,
|
||||||
|
"rtt_avg": 0.055,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_1000": {
|
||||||
|
"rtt_min": 0.05,
|
||||||
|
"rtt_max": 0.272,
|
||||||
|
"rtt_avg": 0.057,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"plain": {
|
||||||
|
"iperf": {
|
||||||
|
"throughput": 5728527000.0,
|
||||||
|
"cpu_sender": 11.004746,
|
||||||
|
"cpu_receiver": 67.527328
|
||||||
|
},
|
||||||
|
"ping_100": {
|
||||||
|
"rtt_min": 0.078,
|
||||||
|
"rtt_max": 0.372,
|
||||||
|
"rtt_avg": 0.095,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_500": {
|
||||||
|
"rtt_min": 0.078,
|
||||||
|
"rtt_max": 0.272,
|
||||||
|
"rtt_avg": 0.094,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_1000": {
|
||||||
|
"rtt_min": 0.082,
|
||||||
|
"rtt_max": 0.217,
|
||||||
|
"rtt_avg": 0.096,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"aes256": {
|
||||||
|
"iperf": {
|
||||||
|
"throughput": 3706944000.0,
|
||||||
|
"cpu_sender": 6.465523,
|
||||||
|
"cpu_receiver": 60.216674
|
||||||
|
},
|
||||||
|
"ping_100": {
|
||||||
|
"rtt_min": 0.079,
|
||||||
|
"rtt_max": 0.28,
|
||||||
|
"rtt_avg": 0.097,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_500": {
|
||||||
|
"rtt_min": 0.079,
|
||||||
|
"rtt_max": 13.372,
|
||||||
|
"rtt_avg": 0.099,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_1000": {
|
||||||
|
"rtt_min": 0.086,
|
||||||
|
"rtt_max": 0.358,
|
||||||
|
"rtt_avg": 0.102,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"aes128": {
|
||||||
|
"iperf": {
|
||||||
|
"throughput": 3876646000.0,
|
||||||
|
"cpu_sender": 6.800352,
|
||||||
|
"cpu_receiver": 61.738244
|
||||||
|
},
|
||||||
|
"ping_100": {
|
||||||
|
"rtt_min": 0.078,
|
||||||
|
"rtt_max": 0.219,
|
||||||
|
"rtt_avg": 0.096,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_500": {
|
||||||
|
"rtt_min": 0.083,
|
||||||
|
"rtt_max": 0.232,
|
||||||
|
"rtt_avg": 0.097,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_1000": {
|
||||||
|
"rtt_min": 0.087,
|
||||||
|
"rtt_max": 0.327,
|
||||||
|
"rtt_avg": 0.099,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"chacha20": {
|
||||||
|
"iperf": {
|
||||||
|
"throughput": 2917879000.0,
|
||||||
|
"cpu_sender": 5.066722,
|
||||||
|
"cpu_receiver": 55.171241
|
||||||
|
},
|
||||||
|
"ping_100": {
|
||||||
|
"rtt_min": 0.081,
|
||||||
|
"rtt_max": 0.283,
|
||||||
|
"rtt_avg": 0.097,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_500": {
|
||||||
|
"rtt_min": 0.087,
|
||||||
|
"rtt_max": 0.348,
|
||||||
|
"rtt_avg": 0.103,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
},
|
||||||
|
"ping_1000": {
|
||||||
|
"rtt_min": 0.088,
|
||||||
|
"rtt_max": 0.309,
|
||||||
|
"rtt_avg": 0.105,
|
||||||
|
"pkt_loss": 0.0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"results": {
|
||||||
|
"throughput_mbits": {
|
||||||
|
"native": 9672.965,
|
||||||
|
"plain": 5728.527,
|
||||||
|
"aes256": 3706.944,
|
||||||
|
"aes128": 3876.646,
|
||||||
|
"chacha20": 2917.879
|
||||||
|
},
|
||||||
|
"latency_us": {
|
||||||
|
"plain": {
|
||||||
|
"100": 21.0,
|
||||||
|
"500": 19.5,
|
||||||
|
"1000": 19.5
|
||||||
|
},
|
||||||
|
"aes256": {
|
||||||
|
"100": 22.000000000000004,
|
||||||
|
"500": 22.000000000000004,
|
||||||
|
"1000": 22.499999999999996
|
||||||
|
},
|
||||||
|
"aes128": {
|
||||||
|
"100": 21.5,
|
||||||
|
"500": 21.0,
|
||||||
|
"1000": 21.0
|
||||||
|
},
|
||||||
|
"chacha20": {
|
||||||
|
"100": 22.000000000000004,
|
||||||
|
"500": 23.999999999999996,
|
||||||
|
"1000": 23.999999999999996
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ from datetime import date
|
||||||
# Note: this script will run for ~8 minutes and incur costs of about $ 0.02
|
# Note: this script will run for ~8 minutes and incur costs of about $ 0.02
|
||||||
|
|
||||||
FILE = "../target/release/vpncloud"
|
FILE = "../target/release/vpncloud"
|
||||||
VERSION = "2.0.0-alpha1"
|
VERSION = "2.1.0"
|
||||||
REGION = "eu-central-1"
|
REGION = "eu-central-1"
|
||||||
|
|
||||||
env = EC2Environment(
|
env = EC2Environment(
|
||||||
|
|
|
@ -5,11 +5,11 @@ import atexit, argparse, os
|
||||||
|
|
||||||
REGION = "eu-central-1"
|
REGION = "eu-central-1"
|
||||||
|
|
||||||
VERSION = "2.0.0"
|
VERSION = "2.1.0"
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Create a test setup')
|
parser = argparse.ArgumentParser(description='Create a test setup')
|
||||||
parser.add_argument('--instancetype', default='t3.nano', help='EC2 instance type')
|
parser.add_argument('--instancetype', default='t3a.nano', help='EC2 instance type')
|
||||||
parser.add_argument('--version', default=VERSION, help='VpnCloud version to use')
|
parser.add_argument('--version', default=VERSION, help='VpnCloud version to use')
|
||||||
parser.add_argument('--count', '-c', dest="count", type=int, default=2, help='Number of instance to create')
|
parser.add_argument('--count', '-c', dest="count", type=int, default=2, help='Number of instance to create')
|
||||||
parser.add_argument('--cluster', action="store_true", help='Cluster instances to get reliable throughput')
|
parser.add_argument('--cluster', action="store_true", help='Cluster instances to get reliable throughput')
|
||||||
|
@ -25,15 +25,22 @@ if args.keyname:
|
||||||
with open(args.keyfile, 'r') as fp:
|
with open(args.keyfile, 'r') as fp:
|
||||||
privatekey = fp.read()
|
privatekey = fp.read()
|
||||||
|
|
||||||
|
opts = {}
|
||||||
|
if os.path.exists(args.version):
|
||||||
|
opts["vpncloud_file"] = args.version
|
||||||
|
opts["vpncloud_version"] = None
|
||||||
|
else:
|
||||||
|
opts["vpncloud_version"] = args.version
|
||||||
|
|
||||||
setup = EC2Environment(
|
setup = EC2Environment(
|
||||||
region = REGION,
|
region = REGION,
|
||||||
node_count = args.count,
|
node_count = args.count,
|
||||||
instance_type = args.instancetype,
|
instance_type = args.instancetype,
|
||||||
vpncloud_version = args.version,
|
|
||||||
cluster_nodes = args.cluster,
|
cluster_nodes = args.cluster,
|
||||||
subnet = args.subnet or CREATE,
|
subnet = args.subnet or CREATE,
|
||||||
keyname = args.keyname or CREATE,
|
keyname = args.keyname or CREATE,
|
||||||
privatekey = privatekey
|
privatekey = privatekey,
|
||||||
|
**opts
|
||||||
)
|
)
|
||||||
|
|
||||||
if not args.keyname:
|
if not args.keyname:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2019-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use ring::digest;
|
use ring::digest;
|
||||||
|
@ -325,15 +325,17 @@ impl<TS: TimeSource> BeaconSerializer<TS> {
|
||||||
fn encode() {
|
fn encode() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let mut peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!("WsHI31EWDMBYxvITiILIrm2k9gEik22E", ser.encode(&peers));
|
assert_eq!("WsHI31EWDMBYxvITiILIrm2k9gEik22E", ser.encode(&peers));
|
||||||
peers.push(SocketAddr::from_str("[::1]:5678").unwrap());
|
peers.push(SocketAddr::from_str("[::1]:5678").unwrap());
|
||||||
assert_eq!("WsHI3GXKaXCveo6uejmZizZ72kR6Y0L9T7h49TXONp1ugfKvvvEik22E", ser.encode(&peers));
|
assert_eq!("WsHI3GXKaXCveo6uejmZizZ72kR6Y0L9T7h49TXONp1ugfKvvvEik22E", ser.encode(&peers));
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:54").unwrap());
|
SocketAddr::from_str("6.6.6.6:54").unwrap()
|
||||||
|
];
|
||||||
assert_eq!("WsHI32gm9eMSHP3Lm1GXcdP7rD3ik22E", ser.encode(&peers));
|
assert_eq!("WsHI32gm9eMSHP3Lm1GXcdP7rD3ik22E", ser.encode(&peers));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,9 +343,10 @@ fn encode() {
|
||||||
fn decode() {
|
fn decode() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let mut peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!(format!("{:?}", peers), format!("{:?}", ser.decode("WsHI31EWDMBYxvITiILIrm2k9gEik22E", None)));
|
assert_eq!(format!("{:?}", peers), format!("{:?}", ser.decode("WsHI31EWDMBYxvITiILIrm2k9gEik22E", None)));
|
||||||
peers.push(SocketAddr::from_str("[::1]:5678").unwrap());
|
peers.push(SocketAddr::from_str("[::1]:5678").unwrap());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -356,9 +359,10 @@ fn decode() {
|
||||||
fn decode_split() {
|
fn decode_split() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", peers),
|
format!("{:?}", peers),
|
||||||
format!("{:?}", ser.decode("WsHI3-1E.WD:MB Yx\tvI\nTi(IL)Ir[m2]k9ügEäik22E", None))
|
format!("{:?}", ser.decode("WsHI3-1E.WD:MB Yx\tvI\nTi(IL)Ir[m2]k9ügEäik22E", None))
|
||||||
|
@ -373,9 +377,10 @@ fn decode_split() {
|
||||||
fn decode_offset() {
|
fn decode_offset() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", peers),
|
format!("{:?}", peers),
|
||||||
format!("{:?}", ser.decode("Hello World: WsHI31EWDMBYxvITiILIrm2k9gEik22E! End of the World", None))
|
format!("{:?}", ser.decode("Hello World: WsHI31EWDMBYxvITiILIrm2k9gEik22E! End of the World", None))
|
||||||
|
@ -386,9 +391,10 @@ fn decode_offset() {
|
||||||
fn decode_multiple() {
|
fn decode_multiple() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", peers),
|
format!("{:?}", peers),
|
||||||
format!("{:?}", ser.decode("WsHI31HVpqxFNMNSPrvik22E WsHI34yOBcZIulKdtn2ik22E", None))
|
format!("{:?}", ser.decode("WsHI31HVpqxFNMNSPrvik22E WsHI34yOBcZIulKdtn2ik22E", None))
|
||||||
|
@ -399,9 +405,6 @@ fn decode_multiple() {
|
||||||
fn decode_ttl() {
|
fn decode_ttl() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
assert_eq!(2, ser.decode("WsHI31EWDMBYxvITiILIrm2k9gEik22E", None).len());
|
assert_eq!(2, ser.decode("WsHI31EWDMBYxvITiILIrm2k9gEik22E", None).len());
|
||||||
MockTimeSource::set_time(2100 * 3600);
|
MockTimeSource::set_time(2100 * 3600);
|
||||||
|
@ -440,9 +443,10 @@ fn decode_invalid() {
|
||||||
fn encode_decode() {
|
fn encode_decode() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
let data = ser.encode(&peers);
|
let data = ser.encode(&peers);
|
||||||
let peers2 = ser.decode(&data, None);
|
let peers2 = ser.decode(&data, None);
|
||||||
assert_eq!(format!("{:?}", peers), format!("{:?}", peers2));
|
assert_eq!(format!("{:?}", peers), format!("{:?}", peers2));
|
||||||
|
@ -452,9 +456,10 @@ fn encode_decode() {
|
||||||
fn encode_decode_file() {
|
fn encode_decode_file() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
||||||
assert!(ser.write_to_file(&peers, file.path()).is_ok());
|
assert!(ser.write_to_file(&peers, file.path()).is_ok());
|
||||||
let peers2 = ser.read_from_file(file.path(), None);
|
let peers2 = ser.read_from_file(file.path(), None);
|
||||||
|
@ -466,9 +471,10 @@ fn encode_decode_file() {
|
||||||
fn encode_decode_cmd() {
|
fn encode_decode_cmd() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
||||||
assert!(ser.write_to_cmd(&peers, &format!("echo $beacon > {}", file.path().display())).is_ok());
|
assert!(ser.write_to_cmd(&peers, &format!("echo $beacon > {}", file.path().display())).is_ok());
|
||||||
thread::sleep(Duration::from_millis(100));
|
thread::sleep(Duration::from_millis(100));
|
||||||
|
|
148
src/config.rs
148
src/config.rs
|
@ -1,16 +1,15 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use super::{device::Type, types::Mode, util::Duration};
|
use super::{device::Type, types::Mode, util::Duration, util::run_cmd};
|
||||||
pub use crate::crypto::Config as CryptoConfig;
|
pub use crate::crypto::Config as CryptoConfig;
|
||||||
use crate::util::run_cmd;
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp::max,
|
cmp::max,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
net::{IpAddr, Ipv6Addr, SocketAddr},
|
process,
|
||||||
process::Command,
|
|
||||||
thread
|
thread
|
||||||
};
|
};
|
||||||
use structopt::{clap::Shell, StructOpt};
|
use structopt::{clap::Shell, StructOpt};
|
||||||
|
@ -18,17 +17,6 @@ use structopt::{clap::Shell, StructOpt};
|
||||||
pub const DEFAULT_PEER_TIMEOUT: u16 = 300;
|
pub const DEFAULT_PEER_TIMEOUT: u16 = 300;
|
||||||
pub const DEFAULT_PORT: u16 = 3210;
|
pub const DEFAULT_PORT: u16 = 3210;
|
||||||
|
|
||||||
fn parse_listen(addr: &str) -> SocketAddr {
|
|
||||||
if let Some(addr) = addr.strip_prefix("*:") {
|
|
||||||
let port = try_fail!(addr.parse::<u16>(), "Invalid port: {}");
|
|
||||||
SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), port)
|
|
||||||
} else if addr.contains(':') {
|
|
||||||
try_fail!(addr.parse::<SocketAddr>(), "Invalid address: {}: {}", addr)
|
|
||||||
} else {
|
|
||||||
let port = try_fail!(addr.parse::<u16>(), "Invalid port: {}");
|
|
||||||
SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), port)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq, Clone)]
|
#[derive(Deserialize, Debug, PartialEq, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
@ -43,7 +31,7 @@ pub struct Config {
|
||||||
|
|
||||||
pub crypto: CryptoConfig,
|
pub crypto: CryptoConfig,
|
||||||
|
|
||||||
pub listen: SocketAddr,
|
pub listen: String,
|
||||||
pub peers: Vec<String>,
|
pub peers: Vec<String>,
|
||||||
pub peer_timeout: Duration,
|
pub peer_timeout: Duration,
|
||||||
pub keepalive: Option<Duration>,
|
pub keepalive: Option<Duration>,
|
||||||
|
@ -78,7 +66,7 @@ impl Default for Config {
|
||||||
ifup: None,
|
ifup: None,
|
||||||
ifdown: None,
|
ifdown: None,
|
||||||
crypto: CryptoConfig::default(),
|
crypto: CryptoConfig::default(),
|
||||||
listen: "[::]:3210".parse::<SocketAddr>().unwrap(),
|
listen: "3210".to_string(),
|
||||||
peers: vec![],
|
peers: vec![],
|
||||||
peer_timeout: DEFAULT_PEER_TIMEOUT as Duration,
|
peer_timeout: DEFAULT_PEER_TIMEOUT as Duration,
|
||||||
keepalive: None,
|
keepalive: None,
|
||||||
|
@ -131,7 +119,7 @@ impl Config {
|
||||||
self.ifdown = Some(val);
|
self.ifdown = Some(val);
|
||||||
}
|
}
|
||||||
if let Some(val) = file.listen {
|
if let Some(val) = file.listen {
|
||||||
self.listen = parse_listen(&val);
|
self.listen = val;
|
||||||
}
|
}
|
||||||
if let Some(mut val) = file.peers {
|
if let Some(mut val) = file.peers {
|
||||||
self.peers.append(&mut val);
|
self.peers.append(&mut val);
|
||||||
|
@ -235,7 +223,7 @@ impl Config {
|
||||||
self.ifdown = Some(val);
|
self.ifdown = Some(val);
|
||||||
}
|
}
|
||||||
if let Some(val) = args.listen {
|
if let Some(val) = args.listen {
|
||||||
self.listen = parse_listen(&val);
|
self.listen = val;
|
||||||
}
|
}
|
||||||
self.peers.append(&mut args.peers);
|
self.peers.append(&mut args.peers);
|
||||||
if let Some(val) = args.peer_timeout {
|
if let Some(val) = args.peer_timeout {
|
||||||
|
@ -318,7 +306,7 @@ impl Config {
|
||||||
pub fn get_keepalive(&self) -> Duration {
|
pub fn get_keepalive(&self) -> Duration {
|
||||||
match self.keepalive {
|
match self.keepalive {
|
||||||
Some(dur) => dur,
|
Some(dur) => dur,
|
||||||
None => max(self.peer_timeout / 2 - 60, 1)
|
None => max(self.peer_timeout / 2 - 60, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +324,7 @@ impl Config {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let script = script.unwrap();
|
let script = script.unwrap();
|
||||||
let mut cmd = Command::new("sh");
|
let mut cmd = process::Command::new("sh");
|
||||||
cmd.arg("-c").arg(script).envs(envs).env("EVENT", event);
|
cmd.arg("-c").arg(script).envs(envs).env("EVENT", event);
|
||||||
debug!("Running event script: {:?}", cmd);
|
debug!("Running event script: {:?}", cmd);
|
||||||
if detach {
|
if detach {
|
||||||
|
@ -370,7 +358,7 @@ pub struct Args {
|
||||||
pub mode: Option<Mode>,
|
pub mode: Option<Mode>,
|
||||||
|
|
||||||
/// The shared password to encrypt all traffic
|
/// The shared password to encrypt all traffic
|
||||||
#[structopt(short, long, required_unless_one = &["private-key", "config", "genkey", "version", "completion"], env)]
|
#[structopt(short, long, env)]
|
||||||
pub password: Option<String>,
|
pub password: Option<String>,
|
||||||
|
|
||||||
/// The private key to use
|
/// The private key to use
|
||||||
|
@ -461,10 +449,6 @@ pub struct Args {
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub version: bool,
|
pub version: bool,
|
||||||
|
|
||||||
/// Generate and print a key-pair and exit
|
|
||||||
#[structopt(long, conflicts_with = "private_key")]
|
|
||||||
pub genkey: bool,
|
|
||||||
|
|
||||||
/// Disable automatic port forwarding
|
/// Disable automatic port forwarding
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub no_port_forwarding: bool,
|
pub no_port_forwarding: bool,
|
||||||
|
@ -501,17 +485,47 @@ pub struct Args {
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub log_file: Option<String>,
|
pub log_file: Option<String>,
|
||||||
|
|
||||||
/// Migrate an old config file
|
|
||||||
#[structopt(long, alias = "migrate", requires = "config")]
|
|
||||||
pub migrate_config: bool,
|
|
||||||
|
|
||||||
/// Generate shell completions
|
|
||||||
#[structopt(long)]
|
|
||||||
pub completion: Option<Shell>,
|
|
||||||
|
|
||||||
/// Call script on event
|
/// Call script on event
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
pub hook: Vec<String>
|
pub hook: Vec<String>,
|
||||||
|
|
||||||
|
#[structopt(subcommand)]
|
||||||
|
pub cmd: Option<Command>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt, Debug)]
|
||||||
|
pub enum Command {
|
||||||
|
/// Generate and print a key-pair and exit
|
||||||
|
#[structopt(name = "genkey", alias = "gen-key")]
|
||||||
|
GenKey {
|
||||||
|
/// The shared password to encrypt all traffic
|
||||||
|
#[structopt(short, long, env)]
|
||||||
|
password: Option<String>,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Run a websocket proxy
|
||||||
|
#[cfg(feature = "websocket")]
|
||||||
|
#[structopt(alias = "wsproxy")]
|
||||||
|
WsProxy {
|
||||||
|
/// Websocket listen address IP:PORT
|
||||||
|
#[structopt(long, short, default_value="3210")]
|
||||||
|
listen: String
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Migrate an old config file
|
||||||
|
#[structopt(alias = "migrate")]
|
||||||
|
MigrateConfig {
|
||||||
|
/// Config file
|
||||||
|
#[structopt(long)]
|
||||||
|
config_file: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Generate shell completions
|
||||||
|
Completion {
|
||||||
|
/// Shell to create completions for
|
||||||
|
#[structopt(long, default_value="bash")]
|
||||||
|
shell: Shell
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
||||||
|
@ -521,7 +535,7 @@ pub struct ConfigFileDevice {
|
||||||
pub type_: Option<Type>,
|
pub type_: Option<Type>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub path: Option<String>,
|
pub path: Option<String>,
|
||||||
pub fix_rp_filter: Option<bool>
|
pub fix_rp_filter: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
||||||
|
@ -530,14 +544,14 @@ pub struct ConfigFileBeacon {
|
||||||
pub store: Option<String>,
|
pub store: Option<String>,
|
||||||
pub load: Option<String>,
|
pub load: Option<String>,
|
||||||
pub interval: Option<Duration>,
|
pub interval: Option<Duration>,
|
||||||
pub password: Option<String>
|
pub password: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
||||||
#[serde(rename_all = "kebab-case", deny_unknown_fields, default)]
|
#[serde(rename_all = "kebab-case", deny_unknown_fields, default)]
|
||||||
pub struct ConfigFileStatsd {
|
pub struct ConfigFileStatsd {
|
||||||
pub server: Option<String>,
|
pub server: Option<String>,
|
||||||
pub prefix: Option<String>
|
pub prefix: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
|
||||||
|
@ -603,7 +617,9 @@ statsd:
|
||||||
server: example.com:1234
|
server: example.com:1234
|
||||||
prefix: prefix
|
prefix: prefix
|
||||||
";
|
";
|
||||||
assert_eq!(serde_yaml::from_str::<ConfigFile>(config_file).unwrap(), ConfigFile {
|
assert_eq!(
|
||||||
|
serde_yaml::from_str::<ConfigFile>(config_file).unwrap(),
|
||||||
|
ConfigFile {
|
||||||
device: Some(ConfigFileDevice {
|
device: Some(ConfigFileDevice {
|
||||||
type_: Some(Type::Tun),
|
type_: Some(Type::Tun),
|
||||||
name: Some("vpncloud%d".to_string()),
|
name: Some("vpncloud%d".to_string()),
|
||||||
|
@ -639,47 +655,13 @@ statsd:
|
||||||
}),
|
}),
|
||||||
hook: None,
|
hook: None,
|
||||||
hooks: HashMap::new()
|
hooks: HashMap::new()
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_config_as_default() {
|
fn parse_example_config() {
|
||||||
let mut default_config = Config {
|
|
||||||
device_type: Type::Tun,
|
|
||||||
device_name: "".to_string(),
|
|
||||||
device_path: None,
|
|
||||||
fix_rp_filter: false,
|
|
||||||
ip: None,
|
|
||||||
ifup: None,
|
|
||||||
ifdown: None,
|
|
||||||
crypto: CryptoConfig::default(),
|
|
||||||
listen: "[::]:3210".parse::<SocketAddr>().unwrap(),
|
|
||||||
peers: vec![],
|
|
||||||
peer_timeout: 0,
|
|
||||||
keepalive: None,
|
|
||||||
beacon_store: None,
|
|
||||||
beacon_load: None,
|
|
||||||
beacon_interval: 0,
|
|
||||||
beacon_password: None,
|
|
||||||
mode: Mode::Hub,
|
|
||||||
switch_timeout: 0,
|
|
||||||
claims: vec![],
|
|
||||||
auto_claim: true,
|
|
||||||
port_forwarding: true,
|
|
||||||
daemonize: false,
|
|
||||||
pid_file: None,
|
|
||||||
stats_file: None,
|
|
||||||
statsd_server: None,
|
|
||||||
statsd_prefix: None,
|
|
||||||
user: None,
|
|
||||||
group: None,
|
|
||||||
hook: None,
|
|
||||||
hooks: HashMap::new()
|
|
||||||
};
|
|
||||||
let default_config_file =
|
|
||||||
serde_yaml::from_str::<ConfigFile>(include_str!("../assets/example.net.disabled")).unwrap();
|
serde_yaml::from_str::<ConfigFile>(include_str!("../assets/example.net.disabled")).unwrap();
|
||||||
default_config.merge_file(default_config_file);
|
|
||||||
assert_eq!(default_config, Config::default());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -690,7 +672,7 @@ fn config_merge() {
|
||||||
type_: Some(Type::Tun),
|
type_: Some(Type::Tun),
|
||||||
name: Some("vpncloud%d".to_string()),
|
name: Some("vpncloud%d".to_string()),
|
||||||
path: None,
|
path: None,
|
||||||
fix_rp_filter: None
|
fix_rp_filter: None,
|
||||||
}),
|
}),
|
||||||
ip: None,
|
ip: None,
|
||||||
ifup: Some("ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up".to_string()),
|
ifup: Some("ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up".to_string()),
|
||||||
|
@ -704,7 +686,7 @@ fn config_merge() {
|
||||||
store: Some("/run/vpncloud.beacon.out".to_string()),
|
store: Some("/run/vpncloud.beacon.out".to_string()),
|
||||||
load: Some("/run/vpncloud.beacon.in".to_string()),
|
load: Some("/run/vpncloud.beacon.in".to_string()),
|
||||||
interval: Some(7200),
|
interval: Some(7200),
|
||||||
password: Some("test123".to_string())
|
password: Some("test123".to_string()),
|
||||||
}),
|
}),
|
||||||
mode: Some(Mode::Normal),
|
mode: Some(Mode::Normal),
|
||||||
switch_timeout: Some(300),
|
switch_timeout: Some(300),
|
||||||
|
@ -717,7 +699,7 @@ fn config_merge() {
|
||||||
stats_file: Some("/var/log/vpncloud.stats".to_string()),
|
stats_file: Some("/var/log/vpncloud.stats".to_string()),
|
||||||
statsd: Some(ConfigFileStatsd {
|
statsd: Some(ConfigFileStatsd {
|
||||||
server: Some("example.com:1234".to_string()),
|
server: Some("example.com:1234".to_string()),
|
||||||
prefix: Some("prefix".to_string())
|
prefix: Some("prefix".to_string()),
|
||||||
}),
|
}),
|
||||||
hook: None,
|
hook: None,
|
||||||
hooks: HashMap::new()
|
hooks: HashMap::new()
|
||||||
|
@ -729,7 +711,7 @@ fn config_merge() {
|
||||||
ip: None,
|
ip: None,
|
||||||
ifup: Some("ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up".to_string()),
|
ifup: Some("ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up".to_string()),
|
||||||
ifdown: Some("true".to_string()),
|
ifdown: Some("true".to_string()),
|
||||||
listen: "[::]:3210".parse::<SocketAddr>().unwrap(),
|
listen: "3210".to_string(),
|
||||||
peers: vec!["remote.machine.foo:3210".to_string(), "remote.machine.bar:3210".to_string()],
|
peers: vec!["remote.machine.foo:3210".to_string(), "remote.machine.bar:3210".to_string()],
|
||||||
peer_timeout: 600,
|
peer_timeout: 600,
|
||||||
keepalive: Some(840),
|
keepalive: Some(840),
|
||||||
|
@ -756,7 +738,7 @@ fn config_merge() {
|
||||||
ifup: Some("ifconfig $IFNAME 10.0.1.2/16 mtu 1400 up".to_string()),
|
ifup: Some("ifconfig $IFNAME 10.0.1.2/16 mtu 1400 up".to_string()),
|
||||||
ifdown: Some("ifconfig $IFNAME down".to_string()),
|
ifdown: Some("ifconfig $IFNAME down".to_string()),
|
||||||
password: Some("anothersecret".to_string()),
|
password: Some("anothersecret".to_string()),
|
||||||
listen: Some("3211".to_string()),
|
listen: Some("[::]:3211".to_string()),
|
||||||
peer_timeout: Some(1801),
|
peer_timeout: Some(1801),
|
||||||
keepalive: Some(850),
|
keepalive: Some(850),
|
||||||
switch_timeout: Some(301),
|
switch_timeout: Some(301),
|
||||||
|
@ -786,7 +768,7 @@ fn config_merge() {
|
||||||
ifup: Some("ifconfig $IFNAME 10.0.1.2/16 mtu 1400 up".to_string()),
|
ifup: Some("ifconfig $IFNAME 10.0.1.2/16 mtu 1400 up".to_string()),
|
||||||
ifdown: Some("ifconfig $IFNAME down".to_string()),
|
ifdown: Some("ifconfig $IFNAME down".to_string()),
|
||||||
crypto: CryptoConfig { password: Some("anothersecret".to_string()), ..CryptoConfig::default() },
|
crypto: CryptoConfig { password: Some("anothersecret".to_string()), ..CryptoConfig::default() },
|
||||||
listen: "[::]:3211".parse::<SocketAddr>().unwrap(),
|
listen: "[::]:3211".to_string(),
|
||||||
peers: vec![
|
peers: vec![
|
||||||
"remote.machine.foo:3210".to_string(),
|
"remote.machine.foo:3210".to_string(),
|
||||||
"remote.machine.bar:3210".to_string(),
|
"remote.machine.bar:3210".to_string(),
|
||||||
|
|
|
@ -0,0 +1,498 @@
|
||||||
|
use super::{
|
||||||
|
core::{test_speed, CryptoCore},
|
||||||
|
init::{self, InitResult, InitState, CLOSING},
|
||||||
|
rotate::RotationState
|
||||||
|
};
|
||||||
|
use crate::{
|
||||||
|
error::Error,
|
||||||
|
types::NodeId,
|
||||||
|
util::{from_base62, to_base62, MsgBuffer}
|
||||||
|
};
|
||||||
|
use ring::{
|
||||||
|
aead::{self, Algorithm, LessSafeKey, UnboundKey},
|
||||||
|
agreement::{EphemeralPrivateKey, UnparsedPublicKey},
|
||||||
|
pbkdf2,
|
||||||
|
rand::{SecureRandom, SystemRandom},
|
||||||
|
signature::{Ed25519KeyPair, KeyPair, ED25519_PUBLIC_KEY_LEN}
|
||||||
|
};
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
use std::{fmt::Debug, io::Read, num::NonZeroU32, sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
|
||||||
|
const SALT: &[u8; 32] = b"vpncloudVPNCLOUDvpncl0udVpnCloud";
|
||||||
|
const INIT_MESSAGE_FIRST_BYTE: u8 = 0xff;
|
||||||
|
const MESSAGE_TYPE_ROTATION: u8 = 0x10;
|
||||||
|
|
||||||
|
pub type Ed25519PublicKey = [u8; ED25519_PUBLIC_KEY_LEN];
|
||||||
|
pub type EcdhPublicKey = UnparsedPublicKey<SmallVec<[u8; 96]>>;
|
||||||
|
pub type EcdhPrivateKey = EphemeralPrivateKey;
|
||||||
|
pub type Key = SmallVec<[u8; 32]>;
|
||||||
|
|
||||||
|
|
||||||
|
const DEFAULT_ALGORITHMS: [&str; 3] = ["AES128", "AES256", "CHACHA20"];
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
const SPEED_TEST_TIME: f32 = 0.02;
|
||||||
|
#[cfg(not(test))]
|
||||||
|
const SPEED_TEST_TIME: f32 = 0.1;
|
||||||
|
|
||||||
|
const ROTATE_INTERVAL: usize = 120;
|
||||||
|
|
||||||
|
|
||||||
|
pub trait Payload: Debug + PartialEq + Sized {
|
||||||
|
fn write_to(&self, buffer: &mut MsgBuffer);
|
||||||
|
fn read_from<R: Read>(r: R) -> Result<Self, Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Algorithms {
|
||||||
|
pub algorithm_speeds: SmallVec<[(&'static Algorithm, f32); 3]>,
|
||||||
|
pub allow_unencrypted: bool
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
|
||||||
|
#[serde(rename_all = "kebab-case", deny_unknown_fields, default)]
|
||||||
|
pub struct Config {
|
||||||
|
pub password: Option<String>,
|
||||||
|
pub private_key: Option<String>,
|
||||||
|
pub public_key: Option<String>,
|
||||||
|
pub trusted_keys: Vec<String>,
|
||||||
|
pub algorithms: Vec<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Crypto {
|
||||||
|
node_id: NodeId,
|
||||||
|
key_pair: Arc<Ed25519KeyPair>,
|
||||||
|
trusted_keys: Arc<[Ed25519PublicKey]>,
|
||||||
|
algorithms: Algorithms
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Crypto {
|
||||||
|
pub fn new(node_id: NodeId, config: &Config) -> Result<Self, Error> {
|
||||||
|
let key_pair = if let Some(priv_key) = &config.private_key {
|
||||||
|
if let Some(pub_key) = &config.public_key {
|
||||||
|
Self::parse_keypair(priv_key, pub_key)?
|
||||||
|
} else {
|
||||||
|
Self::parse_private_key(priv_key)?
|
||||||
|
}
|
||||||
|
} else if let Some(password) = &config.password {
|
||||||
|
Self::keypair_from_password(password)
|
||||||
|
} else {
|
||||||
|
return Err(Error::InvalidConfig("Either private_key or password must be set"))
|
||||||
|
};
|
||||||
|
let mut trusted_keys = vec![];
|
||||||
|
for tn in &config.trusted_keys {
|
||||||
|
trusted_keys.push(Self::parse_public_key(tn)?);
|
||||||
|
}
|
||||||
|
if trusted_keys.is_empty() {
|
||||||
|
info!("Trusted keys not set, trusting only own public key");
|
||||||
|
let mut key = [0; ED25519_PUBLIC_KEY_LEN];
|
||||||
|
key.clone_from_slice(key_pair.public_key().as_ref());
|
||||||
|
trusted_keys.push(key);
|
||||||
|
}
|
||||||
|
let mut algos = Algorithms { algorithm_speeds: smallvec![], allow_unencrypted: false };
|
||||||
|
let algorithms = config.algorithms.iter().map(|a| a as &str).collect::<Vec<_>>();
|
||||||
|
let allowed = if algorithms.is_empty() { &DEFAULT_ALGORITHMS } else { &algorithms as &[&str] };
|
||||||
|
let duration = Duration::from_secs_f32(SPEED_TEST_TIME);
|
||||||
|
let mut speeds = Vec::new();
|
||||||
|
for name in allowed {
|
||||||
|
let algo = match &name.to_uppercase() as &str {
|
||||||
|
"UNENCRYPTED" | "NONE" | "PLAIN" => {
|
||||||
|
algos.allow_unencrypted = true;
|
||||||
|
warn!("Crypto settings allow unencrypted connections");
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
"AES128" | "AES128_GCM" | "AES_128" | "AES_128_GCM" => &aead::AES_128_GCM,
|
||||||
|
"AES256" | "AES256_GCM" | "AES_256" | "AES_256_GCM" => &aead::AES_256_GCM,
|
||||||
|
"CHACHA" | "CHACHA20" | "CHACHA20_POLY1305" => &aead::CHACHA20_POLY1305,
|
||||||
|
_ => return Err(Error::InvalidConfig("Unknown crypto method"))
|
||||||
|
};
|
||||||
|
let speed = test_speed(algo, &duration);
|
||||||
|
algos.algorithm_speeds.push((algo, speed as f32));
|
||||||
|
speeds.push((name, speed as f32));
|
||||||
|
}
|
||||||
|
if !speeds.is_empty() {
|
||||||
|
info!(
|
||||||
|
"Crypto speeds: {}",
|
||||||
|
speeds.into_iter().map(|(a, s)| format!("{}: {:.1} MiB/s", a, s)).collect::<Vec<_>>().join(", ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(Self {
|
||||||
|
node_id,
|
||||||
|
key_pair: Arc::new(key_pair),
|
||||||
|
trusted_keys: trusted_keys.into_boxed_slice().into(),
|
||||||
|
algorithms: algos
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_keypair(password: Option<&str>) -> (String, String) {
|
||||||
|
let mut bytes = [0; 32];
|
||||||
|
match password {
|
||||||
|
None => {
|
||||||
|
let rng = SystemRandom::new();
|
||||||
|
rng.fill(&mut bytes).unwrap();
|
||||||
|
}
|
||||||
|
Some(password) => {
|
||||||
|
pbkdf2::derive(
|
||||||
|
pbkdf2::PBKDF2_HMAC_SHA256,
|
||||||
|
NonZeroU32::new(4096).unwrap(),
|
||||||
|
SALT,
|
||||||
|
password.as_bytes(),
|
||||||
|
&mut bytes
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let keypair = Ed25519KeyPair::from_seed_unchecked(&bytes).unwrap();
|
||||||
|
let privkey = to_base62(&bytes);
|
||||||
|
let pubkey = to_base62(keypair.public_key().as_ref());
|
||||||
|
(privkey, pubkey)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn keypair_from_password(password: &str) -> Ed25519KeyPair {
|
||||||
|
let mut key = [0; 32];
|
||||||
|
pbkdf2::derive(pbkdf2::PBKDF2_HMAC_SHA256, NonZeroU32::new(4096).unwrap(), SALT, password.as_bytes(), &mut key);
|
||||||
|
Ed25519KeyPair::from_seed_unchecked(&key).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_keypair(privkey: &str, pubkey: &str) -> Result<Ed25519KeyPair, Error> {
|
||||||
|
let privkey = from_base62(privkey).map_err(|_| Error::InvalidConfig("Failed to parse private key"))?;
|
||||||
|
let pubkey = from_base62(pubkey).map_err(|_| Error::InvalidConfig("Failed to parse public key"))?;
|
||||||
|
let keypair = Ed25519KeyPair::from_seed_and_public_key(&privkey, &pubkey)
|
||||||
|
.map_err(|_| Error::InvalidConfig("Keys rejected by crypto library"))?;
|
||||||
|
Ok(keypair)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_private_key(privkey: &str) -> Result<Ed25519KeyPair, Error> {
|
||||||
|
let privkey = from_base62(privkey).map_err(|_| Error::InvalidConfig("Failed to parse private key"))?;
|
||||||
|
let keypair = Ed25519KeyPair::from_seed_unchecked(&privkey)
|
||||||
|
.map_err(|_| Error::InvalidConfig("Key rejected by crypto library"))?;
|
||||||
|
Ok(keypair)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_public_key(pubkey: &str) -> Result<Ed25519PublicKey, Error> {
|
||||||
|
let pubkey = from_base62(pubkey).map_err(|_| Error::InvalidConfig("Failed to parse public key"))?;
|
||||||
|
if pubkey.len() != ED25519_PUBLIC_KEY_LEN {
|
||||||
|
return Err(Error::InvalidConfig("Failed to parse public key"))
|
||||||
|
}
|
||||||
|
let mut result = [0; ED25519_PUBLIC_KEY_LEN];
|
||||||
|
result.clone_from_slice(&pubkey);
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn peer_instance<P: Payload>(&self, payload: P) -> PeerCrypto<P> {
|
||||||
|
PeerCrypto::new(
|
||||||
|
self.node_id,
|
||||||
|
payload,
|
||||||
|
self.key_pair.clone(),
|
||||||
|
self.trusted_keys.clone(),
|
||||||
|
self.algorithms.clone()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum MessageResult<P: Payload> {
|
||||||
|
Message(u8),
|
||||||
|
Initialized(P),
|
||||||
|
InitializedWithReply(P),
|
||||||
|
Reply,
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub struct PeerCrypto<P: Payload> {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
node_id: NodeId,
|
||||||
|
init: Option<InitState<P>>,
|
||||||
|
rotation: Option<RotationState>,
|
||||||
|
unencrypted: bool,
|
||||||
|
core: Option<CryptoCore>,
|
||||||
|
rotate_counter: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<P: Payload> PeerCrypto<P> {
|
||||||
|
pub fn new(
|
||||||
|
node_id: NodeId, init_payload: P, key_pair: Arc<Ed25519KeyPair>, trusted_keys: Arc<[Ed25519PublicKey]>,
|
||||||
|
algorithms: Algorithms
|
||||||
|
) -> Self
|
||||||
|
{
|
||||||
|
Self {
|
||||||
|
node_id,
|
||||||
|
init: Some(InitState::new(node_id, init_payload, key_pair, trusted_keys, algorithms)),
|
||||||
|
rotation: None,
|
||||||
|
unencrypted: false,
|
||||||
|
core: None,
|
||||||
|
rotate_counter: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_init(&mut self) -> Result<&mut InitState<P>, Error> {
|
||||||
|
if let Some(init) = &mut self.init {
|
||||||
|
Ok(init)
|
||||||
|
} else {
|
||||||
|
Err(Error::InvalidCryptoState("Initialization already finished"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_core(&mut self) -> Result<&mut CryptoCore, Error> {
|
||||||
|
if let Some(core) = &mut self.core {
|
||||||
|
Ok(core)
|
||||||
|
} else {
|
||||||
|
Err(Error::InvalidCryptoState("Crypto core not ready yet"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_rotation(&mut self) -> Result<&mut RotationState, Error> {
|
||||||
|
if let Some(rotation) = &mut self.rotation {
|
||||||
|
Ok(rotation)
|
||||||
|
} else {
|
||||||
|
Err(Error::InvalidCryptoState("Key rotation not initialized"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn initialize(&mut self, out: &mut MsgBuffer) -> Result<(), Error> {
|
||||||
|
let init = self.get_init()?;
|
||||||
|
if init.stage() != init::STAGE_PING {
|
||||||
|
Err(Error::InvalidCryptoState("Initialization already ongoing"))
|
||||||
|
} else {
|
||||||
|
init.send_ping(out);
|
||||||
|
out.prepend_byte(INIT_MESSAGE_FIRST_BYTE);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_init(&self) -> bool {
|
||||||
|
self.init.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_ready(&self) -> bool {
|
||||||
|
self.core.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn algorithm_name(&self) -> &'static str {
|
||||||
|
if let Some(ref core) = self.core {
|
||||||
|
let algo = core.algorithm();
|
||||||
|
if algo == &aead::CHACHA20_POLY1305 {
|
||||||
|
"CHACHA20"
|
||||||
|
} else if algo == &aead::AES_128_GCM {
|
||||||
|
"AES128"
|
||||||
|
} else if algo == &aead::AES_256_GCM {
|
||||||
|
"AES256"
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"PLAIN"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_init_message(&mut self, buffer: &mut MsgBuffer) -> Result<MessageResult<P>, Error> {
|
||||||
|
let result = self.get_init()?.handle_init(buffer)?;
|
||||||
|
if !buffer.is_empty() {
|
||||||
|
buffer.prepend_byte(INIT_MESSAGE_FIRST_BYTE);
|
||||||
|
}
|
||||||
|
match result {
|
||||||
|
InitResult::Continue => Ok(MessageResult::Reply),
|
||||||
|
InitResult::Success { peer_payload, is_initiator } => {
|
||||||
|
self.core = self.get_init()?.take_core();
|
||||||
|
if self.core.is_none() {
|
||||||
|
self.unencrypted = true;
|
||||||
|
}
|
||||||
|
if self.get_init()?.stage() == init::CLOSING {
|
||||||
|
self.init = None
|
||||||
|
}
|
||||||
|
if self.core.is_some() {
|
||||||
|
self.rotation = Some(RotationState::new(!is_initiator, buffer));
|
||||||
|
}
|
||||||
|
if !is_initiator {
|
||||||
|
if self.unencrypted {
|
||||||
|
return Ok(MessageResult::Initialized(peer_payload))
|
||||||
|
}
|
||||||
|
assert!(!buffer.is_empty());
|
||||||
|
buffer.prepend_byte(MESSAGE_TYPE_ROTATION);
|
||||||
|
self.encrypt_message(buffer)?;
|
||||||
|
}
|
||||||
|
Ok(MessageResult::InitializedWithReply(peer_payload))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_rotate_message(&mut self, data: &[u8]) -> Result<(), Error> {
|
||||||
|
if self.unencrypted {
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
if let Some(rot) = self.get_rotation()?.handle_message(data)? {
|
||||||
|
let core = self.get_core()?;
|
||||||
|
let algo = core.algorithm();
|
||||||
|
let key = LessSafeKey::new(UnboundKey::new(algo, &rot.key[..algo.key_len()]).unwrap());
|
||||||
|
core.rotate_key(key, rot.id, rot.use_for_sending);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encrypt_message(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
||||||
|
if self.unencrypted {
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
self.get_core()?.encrypt(buffer);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decrypt_message(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
||||||
|
// HOT PATH
|
||||||
|
if self.unencrypted {
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
self.get_core()?.decrypt(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_message(&mut self, buffer: &mut MsgBuffer) -> Result<MessageResult<P>, Error> {
|
||||||
|
// HOT PATH
|
||||||
|
if buffer.is_empty() {
|
||||||
|
return Err(Error::InvalidCryptoState("No message in buffer"))
|
||||||
|
}
|
||||||
|
if is_init_message(buffer.buffer()) {
|
||||||
|
// COLD PATH
|
||||||
|
debug!("Received init message");
|
||||||
|
buffer.take_prefix();
|
||||||
|
self.handle_init_message(buffer)
|
||||||
|
} else {
|
||||||
|
// HOT PATH
|
||||||
|
debug!("Received encrypted message");
|
||||||
|
self.decrypt_message(buffer)?;
|
||||||
|
let msg_type = buffer.take_prefix();
|
||||||
|
if msg_type == MESSAGE_TYPE_ROTATION {
|
||||||
|
// COLD PATH
|
||||||
|
debug!("Received rotation message");
|
||||||
|
self.handle_rotate_message(buffer.buffer())?;
|
||||||
|
buffer.clear();
|
||||||
|
Ok(MessageResult::None)
|
||||||
|
} else {
|
||||||
|
Ok(MessageResult::Message(msg_type))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_message(&mut self, type_: u8, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
||||||
|
// HOT PATH
|
||||||
|
assert_ne!(type_, MESSAGE_TYPE_ROTATION);
|
||||||
|
buffer.prepend_byte(type_);
|
||||||
|
self.encrypt_message(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn every_second(&mut self, out: &mut MsgBuffer) -> Result<MessageResult<P>, Error> {
|
||||||
|
out.clear();
|
||||||
|
if let Some(ref mut core) = self.core {
|
||||||
|
core.every_second()
|
||||||
|
}
|
||||||
|
if let Some(ref mut init) = self.init {
|
||||||
|
init.every_second(out)?;
|
||||||
|
}
|
||||||
|
if self.init.as_ref().map(|i| i.stage()).unwrap_or(CLOSING) == CLOSING {
|
||||||
|
self.init = None
|
||||||
|
}
|
||||||
|
if !out.is_empty() {
|
||||||
|
out.prepend_byte(INIT_MESSAGE_FIRST_BYTE);
|
||||||
|
return Ok(MessageResult::Reply)
|
||||||
|
}
|
||||||
|
if let Some(ref mut rotate) = self.rotation {
|
||||||
|
self.rotate_counter += 1;
|
||||||
|
if self.rotate_counter >= ROTATE_INTERVAL {
|
||||||
|
self.rotate_counter = 0;
|
||||||
|
if let Some(rot) = rotate.cycle(out) {
|
||||||
|
let core = self.get_core()?;
|
||||||
|
let algo = core.algorithm();
|
||||||
|
let key = LessSafeKey::new(UnboundKey::new(algo, &rot.key[..algo.key_len()]).unwrap());
|
||||||
|
core.rotate_key(key, rot.id, rot.use_for_sending);
|
||||||
|
}
|
||||||
|
if !out.is_empty() {
|
||||||
|
out.prepend_byte(MESSAGE_TYPE_ROTATION);
|
||||||
|
self.encrypt_message(out)?;
|
||||||
|
return Ok(MessageResult::Reply)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(MessageResult::None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_init_message(msg: &[u8]) -> bool {
|
||||||
|
// HOT PATH
|
||||||
|
!msg.is_empty() && msg[0] == INIT_MESSAGE_FIRST_BYTE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use crate::types::NODE_ID_BYTES;
|
||||||
|
|
||||||
|
fn create_node(config: &Config) -> PeerCrypto<Vec<u8>> {
|
||||||
|
let rng = SystemRandom::new();
|
||||||
|
let mut node_id = [0; NODE_ID_BYTES];
|
||||||
|
rng.fill(&mut node_id).unwrap();
|
||||||
|
let crypto = Crypto::new(node_id, config).unwrap();
|
||||||
|
crypto.peer_instance(vec![])
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn normal() {
|
||||||
|
let config = Config { password: Some("test".to_string()), ..Default::default() };
|
||||||
|
let mut node1 = create_node(&config);
|
||||||
|
let mut node2 = create_node(&config);
|
||||||
|
let mut msg = MsgBuffer::new(16);
|
||||||
|
|
||||||
|
node1.initialize(&mut msg).unwrap();
|
||||||
|
assert!(!msg.is_empty());
|
||||||
|
|
||||||
|
debug!("Node1 -> Node2");
|
||||||
|
let res = node2.handle_message(&mut msg).unwrap();
|
||||||
|
assert_eq!(res, MessageResult::Reply);
|
||||||
|
assert!(!msg.is_empty());
|
||||||
|
|
||||||
|
debug!("Node1 <- Node2");
|
||||||
|
let res = node1.handle_message(&mut msg).unwrap();
|
||||||
|
assert_eq!(res, MessageResult::InitializedWithReply(vec![]));
|
||||||
|
assert!(!msg.is_empty());
|
||||||
|
|
||||||
|
debug!("Node1 -> Node2");
|
||||||
|
let res = node2.handle_message(&mut msg).unwrap();
|
||||||
|
assert_eq!(res, MessageResult::InitializedWithReply(vec![]));
|
||||||
|
assert!(!msg.is_empty());
|
||||||
|
|
||||||
|
debug!("Node1 <- Node2");
|
||||||
|
let res = node1.handle_message(&mut msg).unwrap();
|
||||||
|
assert_eq!(res, MessageResult::None);
|
||||||
|
assert!(msg.is_empty());
|
||||||
|
|
||||||
|
let mut buffer = MsgBuffer::new(16);
|
||||||
|
let rng = SystemRandom::new();
|
||||||
|
buffer.set_length(1000);
|
||||||
|
rng.fill(buffer.message_mut()).unwrap();
|
||||||
|
for _ in 0..1000 {
|
||||||
|
node1.send_message(1, &mut buffer).unwrap();
|
||||||
|
let res = node2.handle_message(&mut buffer).unwrap();
|
||||||
|
assert_eq!(res, MessageResult::Message(1));
|
||||||
|
|
||||||
|
match node1.every_second(&mut msg).unwrap() {
|
||||||
|
MessageResult::None => (),
|
||||||
|
MessageResult::Reply => {
|
||||||
|
let res = node2.handle_message(&mut msg).unwrap();
|
||||||
|
assert_eq!(res, MessageResult::None);
|
||||||
|
}
|
||||||
|
other => assert_eq!(other, MessageResult::None)
|
||||||
|
}
|
||||||
|
match node2.every_second(&mut msg).unwrap() {
|
||||||
|
MessageResult::None => (),
|
||||||
|
MessageResult::Reply => {
|
||||||
|
let res = node1.handle_message(&mut msg).unwrap();
|
||||||
|
assert_eq!(res, MessageResult::None);
|
||||||
|
}
|
||||||
|
other => assert_eq!(other, MessageResult::None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,7 @@
|
||||||
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
// This module implements a crypto core for encrypting and decrypting message streams
|
// This module implements a crypto core for encrypting and decrypting message streams
|
||||||
//
|
//
|
||||||
// The crypto core only encrypts and decrypts messages, using given keys. Negotiating and rotating the keys is out of
|
// The crypto core only encrypts and decrypts messages, using given keys. Negotiating and rotating the keys is out of
|
||||||
|
@ -51,7 +55,7 @@ use std::{
|
||||||
time::{Duration, Instant}
|
time::{Duration, Instant}
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{Error, MsgBuffer};
|
use crate::{error::Error, util::MsgBuffer};
|
||||||
|
|
||||||
|
|
||||||
const NONCE_LEN: usize = 12;
|
const NONCE_LEN: usize = 12;
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
// This module implements a 3-way handshake to initialize an authenticated and encrypted connection.
|
// This module implements a 3-way handshake to initialize an authenticated and encrypted connection.
|
||||||
//
|
//
|
||||||
// The handshake assumes that each node has a asymmetric Curve 25519 key pair as well as a list of trusted public keys
|
// The handshake assumes that each node has a asymmetric Curve 25519 key pair as well as a list of trusted public keys
|
||||||
|
@ -57,7 +61,7 @@ use super::{
|
||||||
Algorithms, EcdhPrivateKey, EcdhPublicKey, Ed25519PublicKey, Error, MsgBuffer, Payload, PeerCrypto,
|
Algorithms, EcdhPrivateKey, EcdhPublicKey, Ed25519PublicKey, Error, MsgBuffer, Payload, PeerCrypto,
|
||||||
MESSAGE_TYPE_ROTATION
|
MESSAGE_TYPE_ROTATION
|
||||||
};
|
};
|
||||||
use crate::types::NodeId;
|
use crate::{error::Error, types::NodeId, util::MsgBuffer};
|
||||||
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use ring::{
|
use ring::{
|
||||||
aead::{Algorithm, LessSafeKey, UnboundKey, AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305},
|
aead::{Algorithm, LessSafeKey, UnboundKey, AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305},
|
||||||
|
@ -403,6 +407,7 @@ pub struct InitState<P: Payload> {
|
||||||
last_message: Option<Vec<u8>>,
|
last_message: Option<Vec<u8>>,
|
||||||
crypto: Option<Arc<CryptoCore>>,
|
crypto: Option<Arc<CryptoCore>>,
|
||||||
algorithms: Algorithms,
|
algorithms: Algorithms,
|
||||||
|
#[allow(dead_code)] // Used in tests
|
||||||
selected_algorithm: Option<&'static Algorithm>,
|
selected_algorithm: Option<&'static Algorithm>,
|
||||||
failed_retries: usize
|
failed_retries: usize
|
||||||
}
|
}
|
||||||
|
@ -411,8 +416,7 @@ impl<P: Payload> InitState<P> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
node_id: NodeId, payload: P, key_pair: Arc<Ed25519KeyPair>, trusted_keys: Arc<[Ed25519PublicKey]>,
|
node_id: NodeId, payload: P, key_pair: Arc<Ed25519KeyPair>, trusted_keys: Arc<[Ed25519PublicKey]>,
|
||||||
algorithms: Algorithms
|
algorithms: Algorithms
|
||||||
) -> Self
|
) -> Self {
|
||||||
{
|
|
||||||
let mut hash = [0; SALTED_NODE_ID_HASH_LEN];
|
let mut hash = [0; SALTED_NODE_ID_HASH_LEN];
|
||||||
let rng = SystemRandom::new();
|
let rng = SystemRandom::new();
|
||||||
rng.fill(&mut hash[0..4]).unwrap();
|
rng.fill(&mut hash[0..4]).unwrap();
|
||||||
|
@ -502,7 +506,7 @@ impl<P: Payload> InitState<P> {
|
||||||
if let Some(crypto) = &mut self.crypto {
|
if let Some(crypto) = &mut self.crypto {
|
||||||
crypto.decrypt(data)?;
|
crypto.decrypt(data)?;
|
||||||
}
|
}
|
||||||
Ok(P::read_from(Cursor::new(data.message()))?)
|
P::read_from(Cursor::new(data.message()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_salted_node_id_hash(&self, hash: &SaltedNodeIdHash, node_id: NodeId) -> bool {
|
fn check_salted_node_id_hash(&self, hash: &SaltedNodeIdHash, node_id: NodeId) -> bool {
|
||||||
|
|
|
@ -1,393 +1,11 @@
|
||||||
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
|
mod common;
|
||||||
mod core;
|
mod core;
|
||||||
mod init;
|
mod init;
|
||||||
mod rotate;
|
mod rotate;
|
||||||
|
|
||||||
use self::{core::test_speed, init::InitState, rotate::RotationState};
|
pub use common::*;
|
||||||
pub use self::{
|
pub use self::core::{EXTRA_LEN, TAG_LEN};
|
||||||
core::{CryptoCore, EXTRA_LEN, TAG_LEN},
|
|
||||||
init::{is_init_message, INIT_MESSAGE_FIRST_BYTE}
|
|
||||||
};
|
|
||||||
use crate::{
|
|
||||||
error::Error,
|
|
||||||
types::NodeId,
|
|
||||||
util::{from_base62, to_base62, MsgBuffer}
|
|
||||||
};
|
|
||||||
use ring::{
|
|
||||||
aead::{self, Algorithm, LessSafeKey, UnboundKey},
|
|
||||||
agreement::{EphemeralPrivateKey, UnparsedPublicKey},
|
|
||||||
pbkdf2,
|
|
||||||
rand::{SecureRandom, SystemRandom},
|
|
||||||
signature::{Ed25519KeyPair, KeyPair, ED25519_PUBLIC_KEY_LEN}
|
|
||||||
};
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
|
||||||
use std::{fmt::Debug, io::Read, num::NonZeroU32, sync::Arc, time::Duration};
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
|
|
||||||
const SALT: &[u8; 32] = b"vpncloudVPNCLOUDvpncl0udVpnCloud";
|
|
||||||
|
|
||||||
const MESSAGE_TYPE_ROTATION: u8 = 0x10;
|
|
||||||
|
|
||||||
pub type Ed25519PublicKey = [u8; ED25519_PUBLIC_KEY_LEN];
|
|
||||||
pub type EcdhPublicKey = UnparsedPublicKey<SmallVec<[u8; 96]>>;
|
|
||||||
pub type EcdhPrivateKey = EphemeralPrivateKey;
|
|
||||||
pub type Key = SmallVec<[u8; 32]>;
|
|
||||||
|
|
||||||
|
|
||||||
const DEFAULT_ALGORITHMS: [&str; 3] = ["AES128", "AES256", "CHACHA20"];
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
const SPEED_TEST_TIME: f32 = 0.02;
|
|
||||||
#[cfg(not(test))]
|
|
||||||
const SPEED_TEST_TIME: f32 = 0.1;
|
|
||||||
|
|
||||||
const ROTATE_INTERVAL: usize = 120;
|
|
||||||
|
|
||||||
|
|
||||||
pub trait Payload: Debug + PartialEq + Sized {
|
|
||||||
fn write_to(&self, buffer: &mut MsgBuffer);
|
|
||||||
fn read_from<R: Read>(r: R) -> Result<Self, Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Algorithms {
|
|
||||||
pub algorithm_speeds: SmallVec<[(&'static Algorithm, f32); 3]>,
|
|
||||||
pub allow_unencrypted: bool
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
|
|
||||||
#[serde(rename_all = "kebab-case", deny_unknown_fields, default)]
|
|
||||||
pub struct Config {
|
|
||||||
pub password: Option<String>,
|
|
||||||
pub private_key: Option<String>,
|
|
||||||
pub public_key: Option<String>,
|
|
||||||
pub trusted_keys: Vec<String>,
|
|
||||||
pub algorithms: Vec<String>
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Crypto {
|
|
||||||
node_id: NodeId,
|
|
||||||
key_pair: Arc<Ed25519KeyPair>,
|
|
||||||
trusted_keys: Arc<[Ed25519PublicKey]>,
|
|
||||||
algorithms: Algorithms
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Crypto {
|
|
||||||
pub fn new(node_id: NodeId, config: &Config) -> Result<Self, Error> {
|
|
||||||
let key_pair = if let Some(priv_key) = &config.private_key {
|
|
||||||
if let Some(pub_key) = &config.public_key {
|
|
||||||
Self::parse_keypair(priv_key, pub_key)?
|
|
||||||
} else {
|
|
||||||
Self::parse_private_key(priv_key)?
|
|
||||||
}
|
|
||||||
} else if let Some(password) = &config.password {
|
|
||||||
Self::keypair_from_password(password)
|
|
||||||
} else {
|
|
||||||
return Err(Error::InvalidConfig("Either private_key or password must be set"))
|
|
||||||
};
|
|
||||||
let mut trusted_keys = vec![];
|
|
||||||
for tn in &config.trusted_keys {
|
|
||||||
trusted_keys.push(Self::parse_public_key(tn)?);
|
|
||||||
}
|
|
||||||
if trusted_keys.is_empty() {
|
|
||||||
info!("Trusted keys not set, trusting only own public key");
|
|
||||||
let mut key = [0; ED25519_PUBLIC_KEY_LEN];
|
|
||||||
key.clone_from_slice(key_pair.public_key().as_ref());
|
|
||||||
trusted_keys.push(key);
|
|
||||||
}
|
|
||||||
let mut algos = Algorithms { algorithm_speeds: smallvec![], allow_unencrypted: false };
|
|
||||||
let algorithms = config.algorithms.iter().map(|a| a as &str).collect::<Vec<_>>();
|
|
||||||
let allowed = if algorithms.is_empty() { &DEFAULT_ALGORITHMS } else { &algorithms as &[&str] };
|
|
||||||
let duration = Duration::from_secs_f32(SPEED_TEST_TIME);
|
|
||||||
let mut speeds = Vec::new();
|
|
||||||
for name in allowed {
|
|
||||||
let algo = match &name.to_uppercase() as &str {
|
|
||||||
"UNENCRYPTED" | "NONE" | "PLAIN" => {
|
|
||||||
algos.allow_unencrypted = true;
|
|
||||||
warn!("Crypto settings allow unencrypted connections");
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
"AES128" | "AES128_GCM" | "AES_128" | "AES_128_GCM" => &aead::AES_128_GCM,
|
|
||||||
"AES256" | "AES256_GCM" | "AES_256" | "AES_256_GCM" => &aead::AES_256_GCM,
|
|
||||||
"CHACHA" | "CHACHA20" | "CHACHA20_POLY1305" => &aead::CHACHA20_POLY1305,
|
|
||||||
_ => return Err(Error::InvalidConfig("Unknown crypto method"))
|
|
||||||
};
|
|
||||||
let speed = test_speed(algo, &duration);
|
|
||||||
algos.algorithm_speeds.push((algo, speed as f32));
|
|
||||||
speeds.push((name, speed as f32));
|
|
||||||
}
|
|
||||||
if !speeds.is_empty() {
|
|
||||||
info!(
|
|
||||||
"Crypto speeds: {}",
|
|
||||||
speeds.into_iter().map(|(a, s)| format!("{}: {:.1} MiB/s", a, s)).collect::<Vec<_>>().join(", ")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Ok(Self {
|
|
||||||
node_id,
|
|
||||||
key_pair: Arc::new(key_pair),
|
|
||||||
trusted_keys: trusted_keys.into_boxed_slice().into(),
|
|
||||||
algorithms: algos
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate_keypair(password: Option<&str>) -> (String, String) {
|
|
||||||
let mut bytes = [0; 32];
|
|
||||||
match password {
|
|
||||||
None => {
|
|
||||||
let rng = SystemRandom::new();
|
|
||||||
rng.fill(&mut bytes).unwrap();
|
|
||||||
}
|
|
||||||
Some(password) => {
|
|
||||||
pbkdf2::derive(
|
|
||||||
pbkdf2::PBKDF2_HMAC_SHA256,
|
|
||||||
NonZeroU32::new(4096).unwrap(),
|
|
||||||
SALT,
|
|
||||||
password.as_bytes(),
|
|
||||||
&mut bytes
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let keypair = Ed25519KeyPair::from_seed_unchecked(&bytes).unwrap();
|
|
||||||
let privkey = to_base62(&bytes);
|
|
||||||
let pubkey = to_base62(keypair.public_key().as_ref());
|
|
||||||
(privkey, pubkey)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn keypair_from_password(password: &str) -> Ed25519KeyPair {
|
|
||||||
let mut key = [0; 32];
|
|
||||||
pbkdf2::derive(pbkdf2::PBKDF2_HMAC_SHA256, NonZeroU32::new(4096).unwrap(), SALT, password.as_bytes(), &mut key);
|
|
||||||
Ed25519KeyPair::from_seed_unchecked(&key).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_keypair(privkey: &str, pubkey: &str) -> Result<Ed25519KeyPair, Error> {
|
|
||||||
let privkey = from_base62(privkey).map_err(|_| Error::InvalidConfig("Failed to parse private key"))?;
|
|
||||||
let pubkey = from_base62(pubkey).map_err(|_| Error::InvalidConfig("Failed to parse public key"))?;
|
|
||||||
let keypair = Ed25519KeyPair::from_seed_and_public_key(&privkey, &pubkey)
|
|
||||||
.map_err(|_| Error::InvalidConfig("Keys rejected by crypto library"))?;
|
|
||||||
Ok(keypair)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_private_key(privkey: &str) -> Result<Ed25519KeyPair, Error> {
|
|
||||||
let privkey = from_base62(privkey).map_err(|_| Error::InvalidConfig("Failed to parse private key"))?;
|
|
||||||
let keypair = Ed25519KeyPair::from_seed_unchecked(&privkey)
|
|
||||||
.map_err(|_| Error::InvalidConfig("Key rejected by crypto library"))?;
|
|
||||||
Ok(keypair)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_public_key(pubkey: &str) -> Result<Ed25519PublicKey, Error> {
|
|
||||||
let pubkey = from_base62(pubkey).map_err(|_| Error::InvalidConfig("Failed to parse public key"))?;
|
|
||||||
if pubkey.len() != ED25519_PUBLIC_KEY_LEN {
|
|
||||||
return Err(Error::InvalidConfig("Failed to parse public key"))
|
|
||||||
}
|
|
||||||
let mut result = [0; ED25519_PUBLIC_KEY_LEN];
|
|
||||||
result.clone_from_slice(&pubkey);
|
|
||||||
Ok(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn peer_instance<P: Payload>(&self, payload: P) -> InitState<P> {
|
|
||||||
InitState::new(self.node_id, payload, self.key_pair.clone(), self.trusted_keys.clone(), self.algorithms.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub enum MessageResult {
|
|
||||||
Message(u8),
|
|
||||||
Reply,
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: completely rewrite
|
|
||||||
// PeerCrypto is only for initialized crypto
|
|
||||||
// Init is consumed and generates PeerCrypto
|
|
||||||
pub struct PeerCrypto {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
last_init_message: Option<Vec<u8>>,
|
|
||||||
algorithm: Option<&'static Algorithm>,
|
|
||||||
rotation: Option<RotationState>,
|
|
||||||
core: Option<Arc<CryptoCore>>,
|
|
||||||
rotate_counter: usize
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PeerCrypto {
|
|
||||||
pub fn algorithm_name(&self) -> &'static str {
|
|
||||||
if let Some(algo) = self.algorithm {
|
|
||||||
if algo == &aead::CHACHA20_POLY1305 {
|
|
||||||
"CHACHA20"
|
|
||||||
} else if algo == &aead::AES_128_GCM {
|
|
||||||
"AES128"
|
|
||||||
} else if algo == &aead::AES_256_GCM {
|
|
||||||
"AES256"
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
"PLAIN"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_init_message(&mut self, buffer: &mut MsgBuffer) -> Result<MessageResult, Error> {
|
|
||||||
// TODO: parse message stage
|
|
||||||
// TODO: depending on stage resend last message
|
|
||||||
Ok(MessageResult::None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_rotate_message(&mut self, data: &[u8]) -> Result<(), Error> {
|
|
||||||
if let Some(rotation) = &mut self.rotation {
|
|
||||||
if let Some(rot) = rotation.handle_message(data)? {
|
|
||||||
let algo = self.algorithm.unwrap();
|
|
||||||
let key = LessSafeKey::new(UnboundKey::new(algo, &rot.key[..algo.key_len()]).unwrap());
|
|
||||||
self.core.unwrap().rotate_key(key, rot.id, rot.use_for_sending);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn encrypt_message(&mut self, buffer: &mut MsgBuffer) {
|
|
||||||
if let Some(core) = &mut self.core {
|
|
||||||
core.encrypt(buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn decrypt_message(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
|
||||||
// HOT PATH
|
|
||||||
if let Some(core) = &mut self.core {
|
|
||||||
core.decrypt(buffer)
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle_message(&mut self, buffer: &mut MsgBuffer) -> Result<MessageResult, Error> {
|
|
||||||
// HOT PATH
|
|
||||||
if buffer.is_empty() {
|
|
||||||
return Err(Error::InvalidCryptoState("No message in buffer"))
|
|
||||||
}
|
|
||||||
if is_init_message(buffer.buffer()) {
|
|
||||||
// COLD PATH
|
|
||||||
debug!("Received init message");
|
|
||||||
self.handle_init_message(buffer)
|
|
||||||
} else {
|
|
||||||
// HOT PATH
|
|
||||||
debug!("Received encrypted message");
|
|
||||||
self.decrypt_message(buffer)?;
|
|
||||||
let msg_type = buffer.take_prefix();
|
|
||||||
if msg_type == MESSAGE_TYPE_ROTATION {
|
|
||||||
// COLD PATH
|
|
||||||
debug!("Received rotation message");
|
|
||||||
self.handle_rotate_message(buffer.buffer())?;
|
|
||||||
buffer.clear();
|
|
||||||
Ok(MessageResult::None)
|
|
||||||
} else {
|
|
||||||
Ok(MessageResult::Message(msg_type))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn send_message(&mut self, type_: u8, buffer: &mut MsgBuffer) {
|
|
||||||
// HOT PATH
|
|
||||||
assert_ne!(type_, MESSAGE_TYPE_ROTATION);
|
|
||||||
buffer.prepend_byte(type_);
|
|
||||||
self.encrypt_message(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn every_second(&mut self, out: &mut MsgBuffer) -> MessageResult {
|
|
||||||
out.clear();
|
|
||||||
if let Some(ref mut core) = self.core {
|
|
||||||
core.every_second()
|
|
||||||
}
|
|
||||||
if let Some(ref mut rotate) = self.rotation {
|
|
||||||
self.rotate_counter += 1;
|
|
||||||
if self.rotate_counter >= ROTATE_INTERVAL {
|
|
||||||
self.rotate_counter = 0;
|
|
||||||
if let Some(rot) = rotate.cycle(out) {
|
|
||||||
let algo = self.algorithm.unwrap();
|
|
||||||
let key = LessSafeKey::new(UnboundKey::new(algo, &rot.key[..algo.key_len()]).unwrap());
|
|
||||||
self.core.unwrap().rotate_key(key, rot.id, rot.use_for_sending);
|
|
||||||
}
|
|
||||||
if !out.is_empty() {
|
|
||||||
out.prepend_byte(MESSAGE_TYPE_ROTATION);
|
|
||||||
self.encrypt_message(out);
|
|
||||||
return MessageResult::Reply
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MessageResult::None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use crate::types::NODE_ID_BYTES;
|
|
||||||
|
|
||||||
fn create_node(config: &Config) -> PeerCrypto<Vec<u8>> {
|
|
||||||
let rng = SystemRandom::new();
|
|
||||||
let mut node_id = [0; NODE_ID_BYTES];
|
|
||||||
rng.fill(&mut node_id).unwrap();
|
|
||||||
let crypto = Crypto::new(node_id, config).unwrap();
|
|
||||||
crypto.peer_instance(vec![])
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn normal() {
|
|
||||||
let config = Config { password: Some("test".to_string()), ..Default::default() };
|
|
||||||
let mut node1 = create_node(&config);
|
|
||||||
let mut node2 = create_node(&config);
|
|
||||||
let mut msg = MsgBuffer::new(16);
|
|
||||||
|
|
||||||
node1.initialize(&mut msg).unwrap();
|
|
||||||
assert!(!msg.is_empty());
|
|
||||||
|
|
||||||
debug!("Node1 -> Node2");
|
|
||||||
let res = node2.handle_message(&mut msg).unwrap();
|
|
||||||
assert_eq!(res, MessageResult::Reply);
|
|
||||||
assert!(!msg.is_empty());
|
|
||||||
|
|
||||||
debug!("Node1 <- Node2");
|
|
||||||
let res = node1.handle_message(&mut msg).unwrap();
|
|
||||||
assert_eq!(res, MessageResult::InitializedWithReply(vec![]));
|
|
||||||
assert!(!msg.is_empty());
|
|
||||||
|
|
||||||
debug!("Node1 -> Node2");
|
|
||||||
let res = node2.handle_message(&mut msg).unwrap();
|
|
||||||
assert_eq!(res, MessageResult::InitializedWithReply(vec![]));
|
|
||||||
assert!(!msg.is_empty());
|
|
||||||
|
|
||||||
debug!("Node1 <- Node2");
|
|
||||||
let res = node1.handle_message(&mut msg).unwrap();
|
|
||||||
assert_eq!(res, MessageResult::None);
|
|
||||||
assert!(msg.is_empty());
|
|
||||||
|
|
||||||
let mut buffer = MsgBuffer::new(16);
|
|
||||||
let rng = SystemRandom::new();
|
|
||||||
buffer.set_length(1000);
|
|
||||||
rng.fill(buffer.message_mut()).unwrap();
|
|
||||||
for _ in 0..1000 {
|
|
||||||
node1.send_message(1, &mut buffer).unwrap();
|
|
||||||
let res = node2.handle_message(&mut buffer).unwrap();
|
|
||||||
assert_eq!(res, MessageResult::Message(1));
|
|
||||||
|
|
||||||
match node1.every_second(&mut msg).unwrap() {
|
|
||||||
MessageResult::None => (),
|
|
||||||
MessageResult::Reply => {
|
|
||||||
let res = node2.handle_message(&mut msg).unwrap();
|
|
||||||
assert_eq!(res, MessageResult::None);
|
|
||||||
}
|
|
||||||
other => assert_eq!(other, MessageResult::None)
|
|
||||||
}
|
|
||||||
match node2.every_second(&mut msg).unwrap() {
|
|
||||||
MessageResult::None => (),
|
|
||||||
MessageResult::Reply => {
|
|
||||||
let res = node1.handle_message(&mut msg).unwrap();
|
|
||||||
assert_eq!(res, MessageResult::None);
|
|
||||||
}
|
|
||||||
other => assert_eq!(other, MessageResult::None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
// This module implements a turn based key rotation.
|
// This module implements a turn based key rotation.
|
||||||
//
|
//
|
||||||
// The main idea is that both peers periodically create ecdh key pairs and exchange their public keys to create
|
// The main idea is that both peers periodically create ecdh key pairs and exchange their public keys to create
|
||||||
|
@ -25,7 +29,8 @@
|
||||||
//
|
//
|
||||||
// The whole communication is sent via the crypto stream and is therefore encrypted and protected against tampering.
|
// The whole communication is sent via the crypto stream and is therefore encrypted and protected against tampering.
|
||||||
|
|
||||||
use super::{Error, Key, MsgBuffer};
|
use super::Key;
|
||||||
|
use crate::{error::Error, util::MsgBuffer};
|
||||||
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use ring::{
|
use ring::{
|
||||||
agreement::{agree_ephemeral, EphemeralPrivateKey, UnparsedPublicKey, X25519},
|
agreement::{agree_ephemeral, EphemeralPrivateKey, UnparsedPublicKey, X25519},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -344,7 +344,7 @@ impl Device for MockDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
fn write(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
||||||
self.outbound.push_back(buffer.message().to_owned());
|
self.outbound.push_back(buffer.message().into());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ impl Device for MockDevice {
|
||||||
|
|
||||||
impl Default for MockDevice {
|
impl Default for MockDevice {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { outbound: VecDeque::new(), inbound: VecDeque::new() }
|
Self { outbound: VecDeque::with_capacity(10), inbound: VecDeque::with_capacity(10) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
mod device_thread;
|
mod device_thread;
|
||||||
|
@ -53,6 +53,7 @@ const SPACE_BEFORE: usize = 100;
|
||||||
|
|
||||||
struct PeerData {
|
struct PeerData {
|
||||||
addrs: AddrList,
|
addrs: AddrList,
|
||||||
|
#[allow(dead_code)] //TODO: export in status
|
||||||
last_seen: Time,
|
last_seen: Time,
|
||||||
timeout: Time,
|
timeout: Time,
|
||||||
peer_timeout: u16,
|
peer_timeout: u16,
|
||||||
|
@ -103,11 +104,7 @@ pub struct GenericCloud<D: Device, P: Protocol, S: Socket, TS: TimeSource> {
|
||||||
|
|
||||||
impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS> {
|
impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS> {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(config: &Config, device: D, port_forwarding: Option<PortForwarding>, stats_file: Option<File>) -> Self {
|
pub fn new(config: &Config, socket: S, device: D, port_forwarding: Option<PortForwarding>, stats_file: Option<File>) -> Self {
|
||||||
let socket = match S::listen(config.listen) {
|
|
||||||
Ok(socket) => socket,
|
|
||||||
Err(err) => fail!("Failed to open socket {}: {}", config.listen, err)
|
|
||||||
};
|
|
||||||
let (learning, broadcast) = match config.mode {
|
let (learning, broadcast) = match config.mode {
|
||||||
Mode::Normal => {
|
Mode::Normal => {
|
||||||
match config.device_type {
|
match config.device_type {
|
||||||
|
@ -235,6 +232,7 @@ impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS
|
||||||
self.own_addresses.push(pfw.get_internal_ip().into());
|
self.own_addresses.push(pfw.get_internal_ip().into());
|
||||||
self.own_addresses.push(pfw.get_external_ip().into());
|
self.own_addresses.push(pfw.get_external_ip().into());
|
||||||
}
|
}
|
||||||
|
debug!("Own addresses: {:?}", self.own_addresses);
|
||||||
// TODO: detect address changes and call event
|
// TODO: detect address changes and call event
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -249,12 +247,8 @@ impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS
|
||||||
///
|
///
|
||||||
/// This method adds a peer to the list of nodes to reconnect to. A periodic task will try to
|
/// This method adds a peer to the list of nodes to reconnect to. A periodic task will try to
|
||||||
/// connect to the peer if it is not already connected.
|
/// connect to the peer if it is not already connected.
|
||||||
pub fn add_reconnect_peer(&mut self, mut add: String) {
|
pub fn add_reconnect_peer(&mut self, add: String) {
|
||||||
let now = TS::now();
|
let now = TS::now();
|
||||||
if add.find(':').unwrap_or(0) <= add.find(']').unwrap_or(0) {
|
|
||||||
// : not present or only in IPv6 address
|
|
||||||
add = format!("{}:{}", add, DEFAULT_PORT)
|
|
||||||
}
|
|
||||||
let resolved = match resolve(&add as &str) {
|
let resolved = match resolve(&add as &str) {
|
||||||
Ok(addrs) => addrs,
|
Ok(addrs) => addrs,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -472,7 +466,6 @@ impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS
|
||||||
self.next_stats_out = now + STATS_INTERVAL;
|
self.next_stats_out = now + STATS_INTERVAL;
|
||||||
self.traffic.period(Some(5));
|
self.traffic.period(Some(5));
|
||||||
}
|
}
|
||||||
// TODO: every 5 minutes: EVENT periodic
|
|
||||||
if let Some(peers) = self.beacon_serializer.get_cmd_results() {
|
if let Some(peers) = self.beacon_serializer.get_cmd_results() {
|
||||||
debug!("Loaded beacon with peers: {:?}", peers);
|
debug!("Loaded beacon with peers: {:?}", peers);
|
||||||
for peer in peers {
|
for peer in peers {
|
||||||
|
@ -921,7 +914,7 @@ impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS
|
||||||
/// Also, this method will call `housekeep` every second.
|
/// Also, this method will call `housekeep` every second.
|
||||||
pub fn run(&mut self) {
|
pub fn run(&mut self) {
|
||||||
let ctrlc = CtrlC::new();
|
let ctrlc = CtrlC::new();
|
||||||
let waiter = try_fail!(WaitImpl::new(&self.socket, &self.device, 1000), "Failed to setup poll: {}");
|
let waiter = try_fail!(WaitImpl::new(self.socket.as_raw_fd(), self.device.as_raw_fd(), 1000), "Failed to setup poll: {}");
|
||||||
let mut buffer = MsgBuffer::new(SPACE_BEFORE);
|
let mut buffer = MsgBuffer::new(SPACE_BEFORE);
|
||||||
let mut poll_error = false;
|
let mut poll_error = false;
|
||||||
self.config.call_hook("vpn_started", vec![("IFNAME", self.device.ifname())], true);
|
self.config.call_hook("vpn_started", vec![("IFNAME", self.device.ifname())], true);
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
95
src/main.rs
95
src/main.rs
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
@ -27,6 +27,7 @@ pub mod port_forwarding;
|
||||||
pub mod table;
|
pub mod table;
|
||||||
pub mod traffic;
|
pub mod traffic;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
#[cfg(feature = "websocket")] pub mod wsproxy;
|
||||||
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ use std::{
|
||||||
net::{Ipv4Addr, UdpSocket},
|
net::{Ipv4Addr, UdpSocket},
|
||||||
os::unix::fs::PermissionsExt,
|
os::unix::fs::PermissionsExt,
|
||||||
path::Path,
|
path::Path,
|
||||||
process::Command,
|
process,
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
thread
|
thread
|
||||||
|
@ -44,15 +45,17 @@ use std::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
engine::GenericCloud,
|
engine::GenericCloud,
|
||||||
config::{Args, Config},
|
config::{Args, Command, Config, DEFAULT_PORT},
|
||||||
crypto::Crypto,
|
crypto::Crypto,
|
||||||
device::{Device, TunTapDevice, Type},
|
device::{Device, TunTapDevice, Type},
|
||||||
|
net::Socket,
|
||||||
oldconfig::OldConfigFile,
|
oldconfig::OldConfigFile,
|
||||||
payload::Protocol,
|
payload::Protocol,
|
||||||
port_forwarding::PortForwarding,
|
util::SystemTimeSource,
|
||||||
util::SystemTimeSource
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "websocket")]
|
||||||
|
use crate::wsproxy::ProxyConnection;
|
||||||
|
|
||||||
struct DualLogger {
|
struct DualLogger {
|
||||||
file: Option<Mutex<File>>
|
file: Option<Mutex<File>>
|
||||||
|
@ -102,7 +105,7 @@ impl log::Log for DualLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_script(script: &str, ifname: &str) {
|
fn run_script(script: &str, ifname: &str) {
|
||||||
let mut cmd = Command::new("sh");
|
let mut cmd = process::Command::new("sh");
|
||||||
cmd.arg("-c").arg(&script).env("IFNAME", ifname);
|
cmd.arg("-c").arg(&script).env("IFNAME", ifname);
|
||||||
debug!("Running script: {:?}", cmd);
|
debug!("Running script: {:?}", cmd);
|
||||||
match cmd.status() {
|
match cmd.status() {
|
||||||
|
@ -161,11 +164,10 @@ fn setup_device(config: &Config) -> TunTapDevice {
|
||||||
device
|
device
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
fn run<P: Protocol>(config: Config) {
|
fn run<P: Protocol, S: Socket>(config: Config, socket: S) {
|
||||||
let device = setup_device(&config);
|
let device = setup_device(&config);
|
||||||
let port_forwarding = if config.port_forwarding { PortForwarding::new(config.listen.port()) } else { None };
|
let port_forwarding = if config.port_forwarding { socket.create_port_forwarding() } else { None };
|
||||||
let stats_file = match config.stats_file {
|
let stats_file = match config.stats_file {
|
||||||
None => None,
|
None => None,
|
||||||
Some(ref name) => {
|
Some(ref name) => {
|
||||||
|
@ -182,8 +184,12 @@ fn run<P: Protocol>(config: Config) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut cloud =
|
let mut cloud =
|
||||||
GenericCloud::<TunTapDevice, P, UdpSocket, SystemTimeSource>::new(&config, device, port_forwarding, stats_file);
|
GenericCloud::<TunTapDevice, P, S, SystemTimeSource>::new(&config, socket, device, port_forwarding, stats_file);
|
||||||
for addr in config.peers {
|
for mut addr in config.peers {
|
||||||
|
if addr.find(':').unwrap_or(0) <= addr.find(']').unwrap_or(0) {
|
||||||
|
// : not present or only in IPv6 address
|
||||||
|
addr = format!("{}:{}", addr, DEFAULT_PORT)
|
||||||
|
}
|
||||||
try_fail!(cloud.connect(&addr as &str), "Failed to send message to {}: {}", &addr);
|
try_fail!(cloud.connect(&addr as &str), "Failed to send message to {}: {}", &addr);
|
||||||
cloud.add_reconnect_peer(addr);
|
cloud.add_reconnect_peer(addr);
|
||||||
}
|
}
|
||||||
|
@ -225,18 +231,6 @@ fn main() {
|
||||||
println!("VpnCloud v{}", env!("CARGO_PKG_VERSION"));
|
println!("VpnCloud v{}", env!("CARGO_PKG_VERSION"));
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if args.genkey {
|
|
||||||
let (privkey, pubkey) = Crypto::generate_keypair(args.password.as_deref());
|
|
||||||
println!("Private key: {}\nPublic key: {}\n", privkey, pubkey);
|
|
||||||
println!(
|
|
||||||
"Attention: Keep the private key secret and use only the public key on other nodes to establish trust."
|
|
||||||
);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if let Some(shell) = args.completion {
|
|
||||||
Args::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut io::stdout());
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let logger = try_fail!(DualLogger::new(args.log_file.as_ref()), "Failed to open logfile: {}");
|
let logger = try_fail!(DualLogger::new(args.log_file.as_ref()), "Failed to open logfile: {}");
|
||||||
log::set_boxed_logger(Box::new(logger)).unwrap();
|
log::set_boxed_logger(Box::new(logger)).unwrap();
|
||||||
assert!(!args.verbose || !args.quiet);
|
assert!(!args.verbose || !args.quiet);
|
||||||
|
@ -247,23 +241,44 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
log::LevelFilter::Info
|
log::LevelFilter::Info
|
||||||
});
|
});
|
||||||
if args.migrate_config {
|
if let Some(cmd) = args.cmd {
|
||||||
let file = args.config.unwrap();
|
match cmd {
|
||||||
|
Command::GenKey { password } => {
|
||||||
|
let (privkey, pubkey) = Crypto::generate_keypair(password.as_deref());
|
||||||
|
println!("Private key: {}\nPublic key: {}\n", privkey, pubkey);
|
||||||
|
println!(
|
||||||
|
"Attention: Keep the private key secret and use only the public key on other nodes to establish trust."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Command::MigrateConfig { config_file } => {
|
||||||
info!("Trying to convert from old config format");
|
info!("Trying to convert from old config format");
|
||||||
let f = try_fail!(File::open(&file), "Failed to open config file: {:?}");
|
let f = try_fail!(File::open(&config_file), "Failed to open config file: {:?}");
|
||||||
let config_file_old: OldConfigFile =
|
let config_file_old: OldConfigFile =
|
||||||
try_fail!(serde_yaml::from_reader(f), "Config file not valid for version 1: {:?}");
|
try_fail!(serde_yaml::from_reader(f), "Config file not valid for version 1: {:?}");
|
||||||
let new_config = config_file_old.convert();
|
let new_config = config_file_old.convert();
|
||||||
info!("Successfully converted from old format");
|
info!("Successfully converted from old format");
|
||||||
info!("Renaming original file to {}.orig", file);
|
info!("Renaming original file to {}.orig", config_file);
|
||||||
try_fail!(fs::rename(&file, format!("{}.orig", file)), "Failed to rename original file: {:?}");
|
|
||||||
info!("Writing new config back into {}", file);
|
|
||||||
let f = try_fail!(File::create(&file), "Failed to open config file: {:?}");
|
|
||||||
try_fail!(
|
try_fail!(
|
||||||
fs::set_permissions(&file, fs::Permissions::from_mode(0o600)),
|
fs::rename(&config_file, format!("{}.orig", config_file)),
|
||||||
|
"Failed to rename original file: {:?}"
|
||||||
|
);
|
||||||
|
info!("Writing new config back into {}", config_file);
|
||||||
|
let f = try_fail!(File::create(&config_file), "Failed to open config file: {:?}");
|
||||||
|
try_fail!(
|
||||||
|
fs::set_permissions(&config_file, fs::Permissions::from_mode(0o600)),
|
||||||
"Failed to set permissions on file: {:?}"
|
"Failed to set permissions on file: {:?}"
|
||||||
);
|
);
|
||||||
try_fail!(serde_yaml::to_writer(f, &new_config), "Failed to write converted config: {:?}");
|
try_fail!(serde_yaml::to_writer(f, &new_config), "Failed to write converted config: {:?}");
|
||||||
|
}
|
||||||
|
Command::Completion { shell } => {
|
||||||
|
Args::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut io::stdout());
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#[cfg(feature = "websocket")]
|
||||||
|
Command::WsProxy { listen } => {
|
||||||
|
try_fail!(wsproxy::run_proxy(&listen), "Failed to run websocket proxy: {:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
|
@ -287,8 +302,22 @@ fn main() {
|
||||||
}
|
}
|
||||||
config.merge_args(args);
|
config.merge_args(args);
|
||||||
debug!("Config: {:?}", config);
|
debug!("Config: {:?}", config);
|
||||||
|
if config.crypto.password.is_none() && config.crypto.private_key.is_none() {
|
||||||
|
error!("Either password or private key must be set in config or given as parameter");
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#[cfg(feature = "websocket")]
|
||||||
|
if config.listen.starts_with("ws://") {
|
||||||
|
let socket = try_fail!(ProxyConnection::listen(&config.listen), "Failed to open socket {}: {}", config.listen);
|
||||||
match config.device_type {
|
match config.device_type {
|
||||||
Type::Tap => run::<payload::Frame>(config),
|
Type::Tap => run::<payload::Frame, _>(config, socket),
|
||||||
Type::Tun => run::<payload::Packet>(config)
|
Type::Tun => run::<payload::Packet, _>(config, socket)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let socket = try_fail!(UdpSocket::listen(&config.listen), "Failed to open socket {}: {}", config.listen);
|
||||||
|
match config.device_type {
|
||||||
|
Type::Tap => run::<payload::Frame, _>(config, socket),
|
||||||
|
Type::Tun => run::<payload::Packet, _>(config, socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
65
src/net.rs
65
src/net.rs
|
@ -1,16 +1,17 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
io::{self, ErrorKind},
|
io::{self, ErrorKind},
|
||||||
net::{IpAddr, SocketAddr, UdpSocket},
|
net::{IpAddr, SocketAddr, UdpSocket, Ipv6Addr},
|
||||||
os::unix::io::{AsRawFd, RawFd},
|
os::unix::io::{AsRawFd, RawFd},
|
||||||
sync::atomic::{AtomicBool, Ordering}
|
sync::atomic::{AtomicBool, Ordering}
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::util::{MockTimeSource, MsgBuffer, Time, TimeSource};
|
use super::util::{MockTimeSource, MsgBuffer, Time, TimeSource};
|
||||||
|
use crate::port_forwarding::PortForwarding;
|
||||||
|
|
||||||
pub fn mapped_addr(addr: SocketAddr) -> SocketAddr {
|
pub fn mapped_addr(addr: SocketAddr) -> SocketAddr {
|
||||||
// HOT PATH
|
// HOT PATH
|
||||||
|
@ -20,16 +21,35 @@ pub fn mapped_addr(addr: SocketAddr) -> SocketAddr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_ip() -> IpAddr {
|
||||||
|
let s = UdpSocket::bind("[::]:0").unwrap();
|
||||||
|
s.connect("8.8.8.8:0").unwrap();
|
||||||
|
s.local_addr().unwrap().ip()
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Socket: AsRawFd + Sized {
|
pub trait Socket: AsRawFd + Sized {
|
||||||
fn listen(addr: SocketAddr) -> Result<Self, io::Error>;
|
fn listen(addr: &str) -> Result<Self, io::Error>;
|
||||||
fn receive(&mut self, buffer: &mut MsgBuffer) -> Result<SocketAddr, io::Error>;
|
fn receive(&mut self, buffer: &mut MsgBuffer) -> Result<SocketAddr, io::Error>;
|
||||||
fn send(&mut self, data: &[u8], addr: SocketAddr) -> Result<usize, io::Error>;
|
fn send(&mut self, data: &[u8], addr: SocketAddr) -> Result<usize, io::Error>;
|
||||||
fn address(&self) -> Result<SocketAddr, io::Error>;
|
fn address(&self) -> Result<SocketAddr, io::Error>;
|
||||||
|
fn create_port_forwarding(&self) -> Option<PortForwarding>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_listen(addr: &str) -> SocketAddr {
|
||||||
|
if let Some(addr) = addr.strip_prefix("*:") {
|
||||||
|
let port = try_fail!(addr.parse::<u16>(), "Invalid port: {}");
|
||||||
|
SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), port)
|
||||||
|
} else if addr.contains(':') {
|
||||||
|
try_fail!(addr.parse::<SocketAddr>(), "Invalid address: {}: {}", addr)
|
||||||
|
} else {
|
||||||
|
let port = try_fail!(addr.parse::<u16>(), "Invalid port: {}");
|
||||||
|
SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), port)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Socket for UdpSocket {
|
impl Socket for UdpSocket {
|
||||||
fn listen(addr: SocketAddr) -> Result<Self, io::Error> {
|
fn listen(addr: &str) -> Result<Self, io::Error> {
|
||||||
|
let addr = parse_listen(addr);
|
||||||
UdpSocket::bind(addr)
|
UdpSocket::bind(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +65,13 @@ impl Socket for UdpSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn address(&self) -> Result<SocketAddr, io::Error> {
|
fn address(&self) -> Result<SocketAddr, io::Error> {
|
||||||
self.local_addr()
|
let mut addr = self.local_addr()?;
|
||||||
|
addr.set_ip(get_ip());
|
||||||
|
Ok(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_port_forwarding(&self) -> Option<PortForwarding> {
|
||||||
|
PortForwarding::new(self.address().unwrap().port())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +93,8 @@ impl MockSocket {
|
||||||
nat: Self::get_nat(),
|
nat: Self::get_nat(),
|
||||||
nat_peers: HashMap::new(),
|
nat_peers: HashMap::new(),
|
||||||
address,
|
address,
|
||||||
outbound: VecDeque::new(),
|
outbound: VecDeque::with_capacity(10),
|
||||||
inbound: VecDeque::new()
|
inbound: VecDeque::with_capacity(10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +133,8 @@ impl AsRawFd for MockSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Socket for MockSocket {
|
impl Socket for MockSocket {
|
||||||
fn listen(addr: SocketAddr) -> Result<Self, io::Error> {
|
fn listen(addr: &str) -> Result<Self, io::Error> {
|
||||||
Ok(Self::new(addr))
|
Ok(Self::new(parse_listen(addr)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn receive(&mut self, buffer: &mut MsgBuffer) -> Result<SocketAddr, io::Error> {
|
fn receive(&mut self, buffer: &mut MsgBuffer) -> Result<SocketAddr, io::Error> {
|
||||||
|
@ -123,7 +149,7 @@ impl Socket for MockSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(&mut self, data: &[u8], addr: SocketAddr) -> Result<usize, io::Error> {
|
fn send(&mut self, data: &[u8], addr: SocketAddr) -> Result<usize, io::Error> {
|
||||||
self.outbound.push_back((addr, data.to_owned()));
|
self.outbound.push_back((addr, data.into()));
|
||||||
if self.nat {
|
if self.nat {
|
||||||
self.nat_peers.insert(addr, MockTimeSource::now() + 300);
|
self.nat_peers.insert(addr, MockTimeSource::now() + 300);
|
||||||
}
|
}
|
||||||
|
@ -133,4 +159,23 @@ impl Socket for MockSocket {
|
||||||
fn address(&self) -> Result<SocketAddr, io::Error> {
|
fn address(&self) -> Result<SocketAddr, io::Error> {
|
||||||
Ok(self.address)
|
Ok(self.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_port_forwarding(&self) -> Option<PortForwarding> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "bench")]
|
||||||
|
mod bench {
|
||||||
|
use std::net::{Ipv4Addr, SocketAddrV4, UdpSocket};
|
||||||
|
use test::Bencher;
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn udp_send(b: &mut Bencher) {
|
||||||
|
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||||
|
let data = [0; 1400];
|
||||||
|
let addr = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 1);
|
||||||
|
b.iter(|| sock.send_to(&data, &addr).unwrap());
|
||||||
|
b.bytes = 1400;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,7 @@
|
||||||
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use super::{device::Type, types::Mode, util::Duration};
|
use super::{device::Type, types::Mode, util::Duration};
|
||||||
use crate::config::{ConfigFile, ConfigFileBeacon, ConfigFileDevice, ConfigFileStatsd, CryptoConfig};
|
use crate::config::{ConfigFile, ConfigFileBeacon, ConfigFileDevice, ConfigFileStatsd, CryptoConfig};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use crate::{error::Error, types::Address};
|
use crate::{error::Error, types::Address};
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use crate::device::Device;
|
|
||||||
use std::{io, os::unix::io::RawFd};
|
use std::{io, os::unix::io::RawFd};
|
||||||
|
|
||||||
use super::WaitResult;
|
use super::WaitResult;
|
||||||
use crate::net::Socket;
|
|
||||||
|
|
||||||
pub struct EpollWait {
|
pub struct EpollWait {
|
||||||
poll_fd: RawFd,
|
poll_fd: RawFd,
|
||||||
|
@ -17,21 +15,21 @@ pub struct EpollWait {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EpollWait {
|
impl EpollWait {
|
||||||
pub fn new<S: Socket>(socket: &S, device: &dyn Device, timeout: u32) -> io::Result<Self> {
|
pub fn new(socket: RawFd, device: RawFd, timeout: u32) -> io::Result<Self> {
|
||||||
Self::create(socket, device, timeout, libc::EPOLLIN as u32)
|
Self::create(socket, device, timeout, libc::EPOLLIN as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn testing<S: Socket>(socket: &S, device: &dyn Device, timeout: u32) -> io::Result<Self> {
|
pub fn testing(socket: RawFd, device: RawFd, timeout: u32) -> io::Result<Self> {
|
||||||
Self::create(socket, device, timeout, (libc::EPOLLIN | libc::EPOLLOUT) as u32)
|
Self::create(socket, device, timeout, (libc::EPOLLIN | libc::EPOLLOUT) as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create<S: Socket>(socket: &S, device: &dyn Device, timeout: u32, flags: u32) -> io::Result<Self> {
|
fn create(socket: RawFd, device: RawFd, timeout: u32, flags: u32) -> io::Result<Self> {
|
||||||
let mut event = libc::epoll_event { u64: 0, events: 0 };
|
let mut event = libc::epoll_event { u64: 0, events: 0 };
|
||||||
let poll_fd = unsafe { libc::epoll_create(3) };
|
let poll_fd = unsafe { libc::epoll_create(3) };
|
||||||
if poll_fd == -1 {
|
if poll_fd == -1 {
|
||||||
return Err(io::Error::last_os_error())
|
return Err(io::Error::last_os_error())
|
||||||
}
|
}
|
||||||
for fd in &[socket.as_raw_fd(), device.as_raw_fd()] {
|
for fd in &[socket, device] {
|
||||||
event.u64 = *fd as u64;
|
event.u64 = *fd as u64;
|
||||||
event.events = flags;
|
event.events = flags;
|
||||||
let res = unsafe { libc::epoll_ctl(poll_fd, libc::EPOLL_CTL_ADD, *fd, &mut event) };
|
let res = unsafe { libc::epoll_ctl(poll_fd, libc::EPOLL_CTL_ADD, *fd, &mut event) };
|
||||||
|
@ -39,7 +37,7 @@ impl EpollWait {
|
||||||
return Err(io::Error::last_os_error())
|
return Err(io::Error::last_os_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Self { poll_fd, event, socket: socket.as_raw_fd(), device: device.as_raw_fd(), timeout })
|
Ok(Self { poll_fd, event, socket, device, timeout })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
#[cfg(feature = "nat")]
|
#[cfg(feature = "nat")]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
|
|
|
@ -0,0 +1,214 @@
|
||||||
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
collections::{HashMap, VecDeque},
|
||||||
|
io::Write,
|
||||||
|
net::SocketAddr,
|
||||||
|
sync::{
|
||||||
|
atomic::{AtomicUsize, Ordering},
|
||||||
|
Once
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub use crate::{
|
||||||
|
cloud::GenericCloud,
|
||||||
|
config::{Config, CryptoConfig},
|
||||||
|
device::{MockDevice, Type},
|
||||||
|
net::MockSocket,
|
||||||
|
payload::{Frame, Packet, Protocol},
|
||||||
|
types::Range,
|
||||||
|
util::{MockTimeSource, Time, TimeSource}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static INIT_LOGGER: Once = Once::new();
|
||||||
|
|
||||||
|
pub fn init_debug_logger() {
|
||||||
|
INIT_LOGGER.call_once(|| {
|
||||||
|
log::set_boxed_logger(Box::new(DebugLogger)).unwrap();
|
||||||
|
log::set_max_level(log::LevelFilter::Debug);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static CURRENT_NODE: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
|
struct DebugLogger;
|
||||||
|
|
||||||
|
impl DebugLogger {
|
||||||
|
pub fn set_node(node: usize) {
|
||||||
|
CURRENT_NODE.store(node, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl log::Log for DebugLogger {
|
||||||
|
#[inline]
|
||||||
|
fn enabled(&self, metadata: &log::Metadata) -> bool {
|
||||||
|
log::max_level() > metadata.level()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn log(&self, record: &log::Record) {
|
||||||
|
if self.enabled(record.metadata()) {
|
||||||
|
eprintln!("Node {} - {} - {}", CURRENT_NODE.load(Ordering::SeqCst), record.level(), record.args());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn flush(&self) {
|
||||||
|
std::io::stderr().flush().expect("Failed to flush")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type TestNode<P> = GenericCloud<MockDevice, P, MockSocket, MockTimeSource>;
|
||||||
|
|
||||||
|
pub struct Simulator<P: Protocol> {
|
||||||
|
next_port: u16,
|
||||||
|
nodes: HashMap<SocketAddr, TestNode<P>>,
|
||||||
|
messages: VecDeque<(SocketAddr, SocketAddr, Vec<u8>)>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type TapSimulator = Simulator<Frame>;
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub type TunSimulator = Simulator<Packet>;
|
||||||
|
|
||||||
|
|
||||||
|
impl<P: Protocol> Simulator<P> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
init_debug_logger();
|
||||||
|
MockTimeSource::set_time(0);
|
||||||
|
Self { next_port: 1, nodes: HashMap::default(), messages: VecDeque::with_capacity(10) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_node(&mut self, nat: bool, config: &Config) -> SocketAddr {
|
||||||
|
let mut config = config.clone();
|
||||||
|
MockSocket::set_nat(nat);
|
||||||
|
config.listen = format!("[::]:{}", self.next_port);
|
||||||
|
let addr = config.listen.parse::<SocketAddr>().unwrap();
|
||||||
|
if config.crypto.password.is_none() && config.crypto.private_key.is_none() {
|
||||||
|
config.crypto.password = Some("test123".to_string())
|
||||||
|
}
|
||||||
|
DebugLogger::set_node(self.next_port as usize);
|
||||||
|
self.next_port += 1;
|
||||||
|
let node = TestNode::new(&config, MockSocket::new(addr), MockDevice::new(), None, None);
|
||||||
|
DebugLogger::set_node(0);
|
||||||
|
self.nodes.insert(addr, node);
|
||||||
|
addr
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn get_node(&mut self, addr: SocketAddr) -> &mut TestNode<P> {
|
||||||
|
let node = self.nodes.get_mut(&addr).unwrap();
|
||||||
|
DebugLogger::set_node(node.get_num());
|
||||||
|
node
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn simulate_next_message(&mut self) {
|
||||||
|
if let Some((src, dst, data)) = self.messages.pop_front() {
|
||||||
|
if let Some(node) = self.nodes.get_mut(&dst) {
|
||||||
|
if node.socket().put_inbound(src, data) {
|
||||||
|
DebugLogger::set_node(node.get_num());
|
||||||
|
node.trigger_socket_event();
|
||||||
|
DebugLogger::set_node(0);
|
||||||
|
let sock = node.socket();
|
||||||
|
let src = dst;
|
||||||
|
while let Some((dst, data)) = sock.pop_outbound() {
|
||||||
|
self.messages.push_back((src, dst, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn!("Message to unknown node {}", dst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn simulate_all_messages(&mut self) {
|
||||||
|
while !self.messages.is_empty() {
|
||||||
|
self.simulate_next_message()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn trigger_node_housekeep(&mut self, addr: SocketAddr) {
|
||||||
|
let node = self.nodes.get_mut(&addr).unwrap();
|
||||||
|
DebugLogger::set_node(node.get_num());
|
||||||
|
node.trigger_housekeep();
|
||||||
|
DebugLogger::set_node(0);
|
||||||
|
let sock = node.socket();
|
||||||
|
while let Some((dst, data)) = sock.pop_outbound() {
|
||||||
|
self.messages.push_back((addr, dst, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn trigger_housekeep(&mut self) {
|
||||||
|
for (src, node) in &mut self.nodes {
|
||||||
|
DebugLogger::set_node(node.get_num());
|
||||||
|
node.trigger_housekeep();
|
||||||
|
DebugLogger::set_node(0);
|
||||||
|
let sock = node.socket();
|
||||||
|
while let Some((dst, data)) = sock.pop_outbound() {
|
||||||
|
self.messages.push_back((*src, dst, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_time(&mut self, time: Time) {
|
||||||
|
MockTimeSource::set_time(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn simulate_time(&mut self, time: Time) {
|
||||||
|
let mut t = MockTimeSource::now();
|
||||||
|
while t < time {
|
||||||
|
t += 1;
|
||||||
|
self.set_time(t);
|
||||||
|
self.trigger_housekeep();
|
||||||
|
self.simulate_all_messages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn connect(&mut self, src: SocketAddr, dst: SocketAddr) {
|
||||||
|
let node = self.nodes.get_mut(&src).unwrap();
|
||||||
|
DebugLogger::set_node(node.get_num());
|
||||||
|
node.connect(dst).unwrap();
|
||||||
|
DebugLogger::set_node(0);
|
||||||
|
let sock = node.socket();
|
||||||
|
while let Some((dst, data)) = sock.pop_outbound() {
|
||||||
|
self.messages.push_back((src, dst, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_connected(&self, src: SocketAddr, dst: SocketAddr) -> bool {
|
||||||
|
self.nodes.get(&src).unwrap().is_connected(&dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn node_addresses(&self) -> Vec<SocketAddr> {
|
||||||
|
self.nodes.keys().copied().collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn message_count(&self) -> usize {
|
||||||
|
self.messages.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn put_payload(&mut self, addr: SocketAddr, data: Vec<u8>) {
|
||||||
|
let node = self.nodes.get_mut(&addr).unwrap();
|
||||||
|
node.device().put_inbound(data);
|
||||||
|
DebugLogger::set_node(node.get_num());
|
||||||
|
node.trigger_device_event();
|
||||||
|
DebugLogger::set_node(0);
|
||||||
|
let sock = node.socket();
|
||||||
|
while let Some((dst, data)) = sock.pop_outbound() {
|
||||||
|
self.messages.push_back((addr, dst, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pop_payload(&mut self, node: SocketAddr) -> Option<Vec<u8>> {
|
||||||
|
self.nodes.get_mut(&node).unwrap().device().pop_outbound()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn drop_message(&mut self) {
|
||||||
|
self.messages.pop_front();
|
||||||
|
}
|
||||||
|
}
|
213
src/tests/mod.rs
213
src/tests/mod.rs
|
@ -1,217 +1,8 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
|
mod common;
|
||||||
mod nat;
|
mod nat;
|
||||||
mod payload;
|
mod payload;
|
||||||
mod peers;
|
mod peers;
|
||||||
|
|
||||||
use std::{
|
|
||||||
collections::{HashMap, VecDeque},
|
|
||||||
io::Write,
|
|
||||||
net::{IpAddr, Ipv6Addr, SocketAddr},
|
|
||||||
sync::{
|
|
||||||
atomic::{AtomicUsize, Ordering},
|
|
||||||
Once
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub use super::{
|
|
||||||
engine::GenericCloud,
|
|
||||||
config::{Config, CryptoConfig},
|
|
||||||
device::{MockDevice, Type},
|
|
||||||
net::MockSocket,
|
|
||||||
payload::{Frame, Packet, Protocol},
|
|
||||||
types::Range,
|
|
||||||
util::{MockTimeSource, Time, TimeSource}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static INIT_LOGGER: Once = Once::new();
|
|
||||||
|
|
||||||
pub fn init_debug_logger() {
|
|
||||||
INIT_LOGGER.call_once(|| {
|
|
||||||
log::set_boxed_logger(Box::new(DebugLogger)).unwrap();
|
|
||||||
log::set_max_level(log::LevelFilter::Debug);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static CURRENT_NODE: AtomicUsize = AtomicUsize::new(0);
|
|
||||||
|
|
||||||
struct DebugLogger;
|
|
||||||
|
|
||||||
impl DebugLogger {
|
|
||||||
pub fn set_node(node: usize) {
|
|
||||||
CURRENT_NODE.store(node, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl log::Log for DebugLogger {
|
|
||||||
#[inline]
|
|
||||||
fn enabled(&self, _metadata: &log::Metadata) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn log(&self, record: &log::Record) {
|
|
||||||
if self.enabled(record.metadata()) {
|
|
||||||
eprintln!("Node {} - {} - {}", CURRENT_NODE.load(Ordering::SeqCst), record.level(), record.args());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn flush(&self) {
|
|
||||||
std::io::stderr().flush().expect("Failed to flush")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type TestNode<P> = GenericCloud<MockDevice, P, MockSocket, MockTimeSource>;
|
|
||||||
|
|
||||||
pub struct Simulator<P: Protocol> {
|
|
||||||
next_port: u16,
|
|
||||||
nodes: HashMap<SocketAddr, TestNode<P>>,
|
|
||||||
messages: VecDeque<(SocketAddr, SocketAddr, Vec<u8>)>
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type TapSimulator = Simulator<Frame>;
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub type TunSimulator = Simulator<Packet>;
|
|
||||||
|
|
||||||
|
|
||||||
impl<P: Protocol> Simulator<P> {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
init_debug_logger();
|
|
||||||
MockTimeSource::set_time(0);
|
|
||||||
Self { next_port: 1, nodes: HashMap::default(), messages: VecDeque::default() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_node(&mut self, nat: bool, config: &Config) -> SocketAddr {
|
|
||||||
let mut config = config.clone();
|
|
||||||
MockSocket::set_nat(nat);
|
|
||||||
config.listen = SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), self.next_port);
|
|
||||||
if config.crypto.password.is_none() && config.crypto.private_key.is_none() {
|
|
||||||
config.crypto.password = Some("test123".to_string())
|
|
||||||
}
|
|
||||||
DebugLogger::set_node(self.next_port as usize);
|
|
||||||
self.next_port += 1;
|
|
||||||
let node = TestNode::new(&config, MockDevice::new(), None, None);
|
|
||||||
DebugLogger::set_node(0);
|
|
||||||
self.nodes.insert(config.listen, node);
|
|
||||||
config.listen
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn get_node(&mut self, addr: SocketAddr) -> &mut TestNode<P> {
|
|
||||||
let node = self.nodes.get_mut(&addr).unwrap();
|
|
||||||
DebugLogger::set_node(node.get_num());
|
|
||||||
node
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn simulate_next_message(&mut self) {
|
|
||||||
if let Some((src, dst, data)) = self.messages.pop_front() {
|
|
||||||
if let Some(node) = self.nodes.get_mut(&dst) {
|
|
||||||
if node.socket().put_inbound(src, data) {
|
|
||||||
DebugLogger::set_node(node.get_num());
|
|
||||||
node.trigger_socket_event();
|
|
||||||
DebugLogger::set_node(0);
|
|
||||||
let sock = node.socket();
|
|
||||||
let src = dst;
|
|
||||||
while let Some((dst, data)) = sock.pop_outbound() {
|
|
||||||
self.messages.push_back((src, dst, data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
warn!("Message to unknown node {}", dst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn simulate_all_messages(&mut self) {
|
|
||||||
while !self.messages.is_empty() {
|
|
||||||
self.simulate_next_message()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn trigger_node_housekeep(&mut self, addr: SocketAddr) {
|
|
||||||
let node = self.nodes.get_mut(&addr).unwrap();
|
|
||||||
DebugLogger::set_node(node.get_num());
|
|
||||||
node.trigger_housekeep();
|
|
||||||
DebugLogger::set_node(0);
|
|
||||||
let sock = node.socket();
|
|
||||||
while let Some((dst, data)) = sock.pop_outbound() {
|
|
||||||
self.messages.push_back((addr, dst, data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn trigger_housekeep(&mut self) {
|
|
||||||
for (src, node) in &mut self.nodes {
|
|
||||||
DebugLogger::set_node(node.get_num());
|
|
||||||
node.trigger_housekeep();
|
|
||||||
DebugLogger::set_node(0);
|
|
||||||
let sock = node.socket();
|
|
||||||
while let Some((dst, data)) = sock.pop_outbound() {
|
|
||||||
self.messages.push_back((*src, dst, data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_time(&mut self, time: Time) {
|
|
||||||
MockTimeSource::set_time(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn simulate_time(&mut self, time: Time) {
|
|
||||||
let mut t = MockTimeSource::now();
|
|
||||||
while t < time {
|
|
||||||
t += 1;
|
|
||||||
self.set_time(t);
|
|
||||||
self.trigger_housekeep();
|
|
||||||
self.simulate_all_messages();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn connect(&mut self, src: SocketAddr, dst: SocketAddr) {
|
|
||||||
let node = self.nodes.get_mut(&src).unwrap();
|
|
||||||
DebugLogger::set_node(node.get_num());
|
|
||||||
node.connect(dst).unwrap();
|
|
||||||
DebugLogger::set_node(0);
|
|
||||||
let sock = node.socket();
|
|
||||||
while let Some((dst, data)) = sock.pop_outbound() {
|
|
||||||
self.messages.push_back((src, dst, data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_connected(&self, src: SocketAddr, dst: SocketAddr) -> bool {
|
|
||||||
self.nodes.get(&src).unwrap().is_connected(&dst)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn node_addresses(&self) -> Vec<SocketAddr> {
|
|
||||||
self.nodes.keys().copied().collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn message_count(&self) -> usize {
|
|
||||||
self.messages.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn put_payload(&mut self, addr: SocketAddr, data: Vec<u8>) {
|
|
||||||
let node = self.nodes.get_mut(&addr).unwrap();
|
|
||||||
node.device().put_inbound(data);
|
|
||||||
DebugLogger::set_node(node.get_num());
|
|
||||||
node.trigger_device_event();
|
|
||||||
DebugLogger::set_node(0);
|
|
||||||
let sock = node.socket();
|
|
||||||
while let Some((dst, data)) = sock.pop_outbound() {
|
|
||||||
self.messages.push_back((addr, dst, data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pop_payload(&mut self, node: SocketAddr) -> Option<Vec<u8>> {
|
|
||||||
self.nodes.get_mut(&node).unwrap().device().pop_outbound()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn drop_message(&mut self) {
|
|
||||||
self.messages.pop_front();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use super::*;
|
use super::common::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn connect_nat_2_peers() {
|
fn connect_nat_2_peers() {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use super::*;
|
use super::common::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn switch_delivers() {
|
fn switch_delivers() {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use super::*;
|
use super::common::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn direct_connect() {
|
fn direct_connect() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2018-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// VpnCloud - Peer-to-Peer VPN
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
// Copyright (C) 2015-2020 Dennis Schwerdel
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
|
@ -0,0 +1,167 @@
|
||||||
|
// VpnCloud - Peer-to-Peer VPN
|
||||||
|
// Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
|
// This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
net::{get_ip, mapped_addr, parse_listen, Socket},
|
||||||
|
poll::{WaitImpl, WaitResult},
|
||||||
|
port_forwarding::PortForwarding,
|
||||||
|
util::MsgBuffer
|
||||||
|
};
|
||||||
|
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
|
||||||
|
use std::{
|
||||||
|
io::{self, Cursor, Read, Write},
|
||||||
|
net::{Ipv6Addr, SocketAddr, SocketAddrV6, TcpListener, TcpStream, UdpSocket},
|
||||||
|
os::unix::io::{AsRawFd, RawFd},
|
||||||
|
thread::spawn
|
||||||
|
};
|
||||||
|
use tungstenite::{client::AutoStream, connect, protocol::WebSocket, server::accept, Message};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
|
||||||
|
macro_rules! io_error {
|
||||||
|
($val:expr, $format:expr) => ( {
|
||||||
|
$val.map_err(|err| io::Error::new(io::ErrorKind::Other, format!($format, err)))
|
||||||
|
} );
|
||||||
|
($val:expr, $format:expr, $( $arg:expr ),+) => ( {
|
||||||
|
$val.map_err(|err| io::Error::new(io::ErrorKind::Other, format!($format, $( $arg ),+, err)))
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_addr<W: Write>(addr: SocketAddr, mut out: W) -> Result<(), io::Error> {
|
||||||
|
let addr = mapped_addr(addr);
|
||||||
|
match mapped_addr(addr) {
|
||||||
|
SocketAddr::V6(addr) => {
|
||||||
|
out.write_all(&addr.ip().octets())?;
|
||||||
|
out.write_u16::<NetworkEndian>(addr.port())?;
|
||||||
|
}
|
||||||
|
_ => unreachable!()
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_addr<R: Read>(mut r: R) -> Result<SocketAddr, io::Error> {
|
||||||
|
let mut ip = [0u8; 16];
|
||||||
|
r.read_exact(&mut ip)?;
|
||||||
|
let port = r.read_u16::<NetworkEndian>()?;
|
||||||
|
let addr = SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::from(ip), port, 0, 0));
|
||||||
|
Ok(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn serve_proxy_connection(stream: TcpStream) -> Result<(), io::Error> {
|
||||||
|
let peer = stream.peer_addr()?;
|
||||||
|
info!("WS client {} connected", peer);
|
||||||
|
stream.set_nodelay(true)?;
|
||||||
|
let mut websocket = io_error!(accept(stream), "Failed to initialize websocket with {}: {}", peer)?;
|
||||||
|
let udpsocket = UdpSocket::bind("[::]:0")?;
|
||||||
|
let mut msg = Vec::with_capacity(18);
|
||||||
|
let mut addr = udpsocket.local_addr()?;
|
||||||
|
info!("Listening on {} for peer {}", addr, peer);
|
||||||
|
addr.set_ip(get_ip());
|
||||||
|
write_addr(addr, &mut msg)?;
|
||||||
|
io_error!(websocket.write_message(Message::Binary(msg)), "Failed to write to ws connection: {}")?;
|
||||||
|
let websocketfd = websocket.get_ref().as_raw_fd();
|
||||||
|
let poll = WaitImpl::new(websocketfd, udpsocket.as_raw_fd(), 60 * 1000)?;
|
||||||
|
let mut buffer = [0; 65535];
|
||||||
|
for evt in poll {
|
||||||
|
match evt {
|
||||||
|
WaitResult::Socket => {
|
||||||
|
let msg = io_error!(websocket.read_message(), "Failed to read message on websocket {}: {}", peer)?;
|
||||||
|
match msg {
|
||||||
|
Message::Binary(data) => {
|
||||||
|
let dst = read_addr(Cursor::new(&data))?;
|
||||||
|
udpsocket.send_to(&data[18..], dst)?;
|
||||||
|
}
|
||||||
|
Message::Close(_) => return Ok(()),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WaitResult::Device => {
|
||||||
|
let (size, addr) = udpsocket.recv_from(&mut buffer)?;
|
||||||
|
let mut data = Vec::with_capacity(18 + size);
|
||||||
|
write_addr(addr, &mut data)?;
|
||||||
|
data.write_all(&buffer[..size])?;
|
||||||
|
io_error!(websocket.write_message(Message::Binary(data)), "Failed to write to {}: {}", peer)?;
|
||||||
|
}
|
||||||
|
WaitResult::Timeout => {
|
||||||
|
io_error!(websocket.write_message(Message::Ping(vec![])), "Failed to send ping: {}")?;
|
||||||
|
}
|
||||||
|
WaitResult::Error(err) => return Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_proxy(listen: &str) -> Result<(), io::Error> {
|
||||||
|
let addr = parse_listen(listen);
|
||||||
|
let server = TcpListener::bind(addr)?;
|
||||||
|
info!("Listening on ws://{}", server.local_addr()?);
|
||||||
|
for stream in server.incoming() {
|
||||||
|
let stream = stream?;
|
||||||
|
let peer = stream.peer_addr()?;
|
||||||
|
spawn(move || {
|
||||||
|
if let Err(err) = serve_proxy_connection(stream) {
|
||||||
|
error!("Error on connection {}: {}", peer, err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ProxyConnection {
|
||||||
|
addr: SocketAddr,
|
||||||
|
socket: WebSocket<AutoStream>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProxyConnection {
|
||||||
|
fn read_message(&mut self) -> Result<Vec<u8>, io::Error> {
|
||||||
|
loop {
|
||||||
|
if let Message::Binary(data) = io_error!(self.socket.read_message(), "Failed to read from ws proxy: {}")? {
|
||||||
|
return Ok(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRawFd for ProxyConnection {
|
||||||
|
fn as_raw_fd(&self) -> RawFd {
|
||||||
|
self.socket.get_ref().as_raw_fd()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Socket for ProxyConnection {
|
||||||
|
fn listen(url: &str) -> Result<Self, io::Error> {
|
||||||
|
let parsed_url = io_error!(Url::parse(url), "Invalid URL {}: {}", url)?;
|
||||||
|
let (mut socket, _) = io_error!(connect(parsed_url), "Failed to connect to URL {}: {}", url)?;
|
||||||
|
socket.get_mut().set_nodelay(true)?;
|
||||||
|
let addr = "0.0.0.0:0".parse::<SocketAddr>().unwrap();
|
||||||
|
let mut con = ProxyConnection { addr, socket };
|
||||||
|
let addr_data = con.read_message()?;
|
||||||
|
con.addr = read_addr(Cursor::new(&addr_data))?;
|
||||||
|
Ok(con)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn receive(&mut self, buffer: &mut MsgBuffer) -> Result<SocketAddr, io::Error> {
|
||||||
|
buffer.clear();
|
||||||
|
let data = self.read_message()?;
|
||||||
|
let addr = read_addr(Cursor::new(&data))?;
|
||||||
|
buffer.clone_from(&data[18..]);
|
||||||
|
Ok(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send(&mut self, data: &[u8], addr: SocketAddr) -> Result<usize, io::Error> {
|
||||||
|
let mut msg = Vec::with_capacity(data.len() + 18);
|
||||||
|
write_addr(addr, &mut msg)?;
|
||||||
|
msg.write_all(data)?;
|
||||||
|
io_error!(self.socket.write_message(Message::Binary(msg)), "Failed to write to ws proxy: {}")?;
|
||||||
|
Ok(data.len())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn address(&self) -> Result<SocketAddr, io::Error> {
|
||||||
|
Ok(self.addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_port_forwarding(&self) -> Option<PortForwarding> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
180
vpncloud.adoc
180
vpncloud.adoc
|
@ -45,7 +45,10 @@ vpncloud - Peer-to-peer VPN
|
||||||
The address on which to listen for data. This can be simply a port number
|
The address on which to listen for data. This can be simply a port number
|
||||||
or a full address in form IP:PORT. If the IP is specified as \'\*' or only
|
or a full address in form IP:PORT. If the IP is specified as \'\*' or only
|
||||||
a port number is given, then the socket will listen on all IPs (v4 and v6),
|
a port number is given, then the socket will listen on all IPs (v4 and v6),
|
||||||
otherwise the socket will only listen on the given IP. [default: **3210**]
|
otherwise the socket will only listen on the given IP.
|
||||||
|
Alternatively, a websocket proxy URL (starting with ws://) can be given
|
||||||
|
here. Please see the section *WEBSOCKET PROXY* for more info.
|
||||||
|
[default: **3210**]
|
||||||
|
|
||||||
*-c <addr>*, *--peer <addr>*, *--connect <addr>*::
|
*-c <addr>*, *--peer <addr>*, *--connect <addr>*::
|
||||||
Address of a peer to connect to. The address should be in the form
|
Address of a peer to connect to. The address should be in the form
|
||||||
|
@ -62,31 +65,27 @@ vpncloud - Peer-to-peer VPN
|
||||||
Do not automatically claim the IP set on the virtual interface (on TUN
|
Do not automatically claim the IP set on the virtual interface (on TUN
|
||||||
devices).
|
devices).
|
||||||
|
|
||||||
*-p <key>*, *--password <key>*::
|
*-p <password>*, *--password <password>*::
|
||||||
A password to encrypt the VPN data. This parameter must be set unless a
|
A password to encrypt the VPN data. This parameter must be set unless a
|
||||||
password is given in a config file or a private key is set.
|
password is given in a config file or a private key is set.
|
||||||
See *SECURITY* for more info.
|
See *SECURITY* for more info.
|
||||||
|
|
||||||
*--key <key>*, *--private-key <key>*::
|
*--key <key>*, *--private-key <key>*::
|
||||||
A private key to use for encryption. The key must be given as base62 as
|
A private key to use for encryption. The key must be given as base62 as
|
||||||
generated by *--genkey*. See *SECURITY* for more info.
|
generated by *genkey*. See *SECURITY* for more info.
|
||||||
|
|
||||||
*--public-key <key>*::
|
*--public-key <key>*::
|
||||||
A public key matching the given private key. The key must be given as base62
|
A public key matching the given private key. The key must be given as base62
|
||||||
as generated by *--genkey*. This argument is purely optional. See *SECURITY*
|
as generated by *genkey*. This argument is purely optional. See *SECURITY*
|
||||||
for more info.
|
for more info.
|
||||||
|
|
||||||
*--trust <key>*, **--trusted-key <key>*::
|
*--trust <key>*, **--trusted-key <key>*::
|
||||||
A public key to trust. Any peer must have a key pair that is trusted by this
|
A public key to trust. Any peer must have a key pair that is trusted by this
|
||||||
node, otherwise it will be rejected. The key must be given as base62 as
|
node, otherwise it will be rejected. The key must be given as base62 as
|
||||||
generated by *--genkey*. This argument can be given multiple times. If it is
|
generated by *genkey*. This argument can be given multiple times. If it is
|
||||||
not set, only the own public key will be trusted. See *SECURITY* for more
|
not set, only the own public key will be trusted. See *SECURITY* for more
|
||||||
info.
|
info.
|
||||||
|
|
||||||
*--genkey*::
|
|
||||||
Generate and print a random key pair and exit. The key pair is printed as
|
|
||||||
base62 and can be used as private-key, public-key and trusted-key options.
|
|
||||||
|
|
||||||
*--algo <method>*, *--algorithm <method>*::
|
*--algo <method>*, *--algorithm <method>*::
|
||||||
Supported encryption algorithms ("plain", "aes128", "aes256", or "chacha20").
|
Supported encryption algorithms ("plain", "aes128", "aes256", or "chacha20").
|
||||||
Nodes exchange the supported algorithms and select the one that is fastest on
|
Nodes exchange the supported algorithms and select the one that is fastest on
|
||||||
|
@ -179,9 +178,11 @@ vpncloud - Peer-to-peer VPN
|
||||||
*--statsd-server <server>*::
|
*--statsd-server <server>*::
|
||||||
If set, periodically send statistics on current traffic and some important
|
If set, periodically send statistics on current traffic and some important
|
||||||
events to the given statsd server (host:port).
|
events to the given statsd server (host:port).
|
||||||
|
Please see *STATSD SUPPORT* for more info.
|
||||||
|
|
||||||
*--statsd-prefix <prefix>*::
|
*--statsd-prefix <prefix>*::
|
||||||
Sets the prefix to use for all statsd entries. [default: **vpncloud**]
|
Sets the prefix to use for all statsd entries. [default: **vpncloud**]
|
||||||
|
Please see *STATSD SUPPORT* for more info.
|
||||||
|
|
||||||
*--daemon*::
|
*--daemon*::
|
||||||
Spawn a background process instead of running the process in the foreground.
|
Spawn a background process instead of running the process in the foreground.
|
||||||
|
@ -196,6 +197,12 @@ vpncloud - Peer-to-peer VPN
|
||||||
Disable automatic port forward. If this option is not set, VpnCloud tries to
|
Disable automatic port forward. If this option is not set, VpnCloud tries to
|
||||||
detect a NAT router and automatically add a port forwarding to it.
|
detect a NAT router and automatically add a port forwarding to it.
|
||||||
|
|
||||||
|
*--hook <script>*::
|
||||||
|
Call the given script on an event. If the script is in the format *event:script*,
|
||||||
|
it will only be called for the specified event type, otherwise it will be called
|
||||||
|
for all events. This parameter can be given multiple times.
|
||||||
|
Please see the section *HOOK SCRIPTS* for more info.
|
||||||
|
|
||||||
*-v*, *--verbose*::
|
*-v*, *--verbose*::
|
||||||
Print debug information, including information for data being received and
|
Print debug information, including information for data being received and
|
||||||
sent.
|
sent.
|
||||||
|
@ -207,6 +214,41 @@ vpncloud - Peer-to-peer VPN
|
||||||
Display the help.
|
Display the help.
|
||||||
|
|
||||||
|
|
||||||
|
== SUBCOMMANDS
|
||||||
|
|
||||||
|
The following subcommands can be given to run some special action instead of
|
||||||
|
running a VpnCloud instance. Any parameters must be given after the subcommand
|
||||||
|
name (except for -v -q and -h). Only the listed parameters are accepted for the
|
||||||
|
subcommands.
|
||||||
|
|
||||||
|
*genkey*::
|
||||||
|
Generate and print a random key pair and exit. The key pair is printed as
|
||||||
|
base62 and can be used as private-key, public-key and trusted-key options.
|
||||||
|
See *SECURITY* for more info.
|
||||||
|
|
||||||
|
*-p <password>*, *--password <password>*:::
|
||||||
|
Derive the key pair from the given password instead of creating randomly.
|
||||||
|
|
||||||
|
*ws-proxy*::
|
||||||
|
Run a websocket proxy instead of the normal VpnCloud instance.
|
||||||
|
See *WEBSOCKET PROXY* for more info.
|
||||||
|
|
||||||
|
*-l <addr>*, *--listen <addr>*:::
|
||||||
|
Listen on the given TCP address (IP:PORT or PORT). [default: **3210**]
|
||||||
|
|
||||||
|
*migrate-config*::
|
||||||
|
Migrate an old config to the current config format.
|
||||||
|
|
||||||
|
*--config-file*:::
|
||||||
|
The path of the config file to convert.
|
||||||
|
|
||||||
|
*completion*::
|
||||||
|
Output shell completions for the VpnCloud command.
|
||||||
|
|
||||||
|
*--shell*:::
|
||||||
|
The shell type to create completions for. [default: **bash**]
|
||||||
|
|
||||||
|
|
||||||
== DESCRIPTION
|
== DESCRIPTION
|
||||||
|
|
||||||
*VpnCloud* is a peer-to-peer VPN over UDP. It creates a virtual network
|
*VpnCloud* is a peer-to-peer VPN over UDP. It creates a virtual network
|
||||||
|
@ -302,28 +344,28 @@ are optional and override the defaults. Please see the section *OPTIONS* for
|
||||||
detailed descriptions of the options.
|
detailed descriptions of the options.
|
||||||
|
|
||||||
*device*:: A key-value map with device settings
|
*device*:: A key-value map with device settings
|
||||||
*type*:: Set the type of network. Same as *--type*
|
*type*::: Set the type of network. Same as *--type*
|
||||||
*name*:: Name of the virtual device. Same as *--device*
|
*name*::: Name of the virtual device. Same as *--device*
|
||||||
*path*:: Set the path of the base device. Same as *--device-path*
|
*path*::: Set the path of the base device. Same as *--device-path*
|
||||||
*fix-rp-filter*:: Fix the rp_filter settings on the host. Same as *--fix-rp-filter*
|
*fix-rp-filter*::: Fix the rp_filter settings on the host. Same as *--fix-rp-filter*
|
||||||
*ip*:: An IP address (plus optional prefix length) for the interface. Same as *--ip*
|
*ip*:: An IP address (plus optional prefix length) for the interface. Same as *--ip*
|
||||||
*ifup*:: A command to setup the network interface. Same as *--ifup*
|
*ifup*:: A command to setup the network interface. Same as *--ifup*
|
||||||
*ifdown*:: A command to bring down the network interface. Same as *--ifdown*
|
*ifdown*:: A command to bring down the network interface. Same as *--ifdown*
|
||||||
*crypto*:: A key-value map with crypto settings
|
*crypto*:: A key-value map with crypto settings
|
||||||
*algorithms*:: The encryption algorithms to support. See *--algorithm*
|
*algorithms*::: The encryption algorithms to support. See *--algorithm*
|
||||||
*password*:: The password to use for encryption. Same as *--password*
|
*password*::: The password to use for encryption. Same as *--password*
|
||||||
*private-key*:: The private key to use. Same as *--private-key*
|
*private-key*::: The private key to use. Same as *--private-key*
|
||||||
*public-key*:: The public key to use. Same as *--public-key*
|
*public-key*::: The public key to use. Same as *--public-key*
|
||||||
*trusted-keys*:: Other public keys to trust. See *--trusted-key*
|
*trusted-keys*::: Other public keys to trust. See *--trusted-key*
|
||||||
*listen*:: The address on which to listen for data. Same as *--listen*
|
*listen*:: The address on which to listen for data. Same as *--listen*
|
||||||
*peers*:: A list of addresses to connect to. See *--connect*
|
*peers*:: A list of addresses to connect to. See *--connect*
|
||||||
*peer_timeout*:: Peer timeout in seconds. Same as *--peer-timeout*
|
*peer_timeout*:: Peer timeout in seconds. Same as *--peer-timeout*
|
||||||
*keepalive*:: Periodically send message to keep connections alive. Same as *--keepalive*
|
*keepalive*:: Periodically send message to keep connections alive. Same as *--keepalive*
|
||||||
*beacon*:: A key-value map with beacon settings
|
*beacon*:: A key-value map with beacon settings
|
||||||
*store*:: Path or command to store beacons. Same as *--beacon-store*
|
*store*::: Path or command to store beacons. Same as *--beacon-store*
|
||||||
*load*:: Path or command to load beacons. Same as *--beacon-load*
|
*load*::: Path or command to load beacons. Same as *--beacon-load*
|
||||||
*interval*:: Interval for loading and storing beacons in seconds. Same as *--beacon-interval*
|
*interval*::: Interval for loading and storing beacons in seconds. Same as *--beacon-interval*
|
||||||
*password*:: Password to encrypt the beacon with. Same as *--beacon-password*
|
*password*::: Password to encrypt the beacon with. Same as *--beacon-password*
|
||||||
*mode*:: The mode of the VPN. Same as *--mode*
|
*mode*:: The mode of the VPN. Same as *--mode*
|
||||||
*switch_timeout*:: Switch table entry timeout in seconds. Same as *--switch-timeout*
|
*switch_timeout*:: Switch table entry timeout in seconds. Same as *--switch-timeout*
|
||||||
*claims*:: A list of local subnets to claim. See *--claim*
|
*claims*:: A list of local subnets to claim. See *--claim*
|
||||||
|
@ -334,8 +376,10 @@ detailed descriptions of the options.
|
||||||
*pid_file*:: The path of the pid file to create. Same as *--pid-file*
|
*pid_file*:: The path of the pid file to create. Same as *--pid-file*
|
||||||
*stats_file*:: The path of the statistics file. Same as *--stats-file*
|
*stats_file*:: The path of the statistics file. Same as *--stats-file*
|
||||||
*statsd*:: A key-value map with statsd settings
|
*statsd*:: A key-value map with statsd settings
|
||||||
*server*:: Server to report statistics to. Same as *--statsd-server*
|
*server*::: Server to report statistics to. Same as *--statsd-server*
|
||||||
*prefix*:: Prefix to use when reporting to statsd. Same as *--statsd-prefix*
|
*prefix*::: Prefix to use when reporting to statsd. Same as *--statsd-prefix*
|
||||||
|
*hook*:: A hook script to be called for every event type. See *HOOK SCRIPTS* for info.
|
||||||
|
*hooks*:: A map of event type to script for scripts that only fire for one event type. See *HOOK SCRIPTS* for info.
|
||||||
|
|
||||||
=== Example
|
=== Example
|
||||||
|
|
||||||
|
@ -366,7 +410,7 @@ VpnCloud uses strong cryptography based on modern cryptographic primitives.
|
||||||
Before exchanging any payload data with peers a secure connection is
|
Before exchanging any payload data with peers a secure connection is
|
||||||
initialized based on key pairs. Each node has a key pair consisting of a
|
initialized based on key pairs. Each node has a key pair consisting of a
|
||||||
private and a public key (*--private-key* and *--public-key*). Those key pairs
|
private and a public key (*--private-key* and *--public-key*). Those key pairs
|
||||||
can be generated via *--genkey*.
|
can be generated via *genkey*.
|
||||||
To allow connections, nodes need to list the public keys of all other nodes as
|
To allow connections, nodes need to list the public keys of all other nodes as
|
||||||
trusted keys (*--trusted-key*). To simplify the key exchange, key pairs can be
|
trusted keys (*--trusted-key*). To simplify the key exchange, key pairs can be
|
||||||
derived from passwords (*--password*). If no trusted keys are configured, nodes
|
derived from passwords (*--password*). If no trusted keys are configured, nodes
|
||||||
|
@ -461,6 +505,90 @@ All keys are prefixed by a common prefix. The prefix defaults to *vpncloud* but
|
||||||
can be changed via **--statsd-prefix** or the config option **statsd_prefix**.
|
can be changed via **--statsd-prefix** or the config option **statsd_prefix**.
|
||||||
|
|
||||||
|
|
||||||
|
== WEBSOCKET PROXY
|
||||||
|
|
||||||
|
The websocket proxy mode replaces the local UDP port by a websocket proxy to allow
|
||||||
|
connectivity even in very restricted environments.
|
||||||
|
|
||||||
|
This means that instead of listening on a local port for incoming messages and
|
||||||
|
sending outgoing messages via this port, all UDP traffic will be forwarded to and
|
||||||
|
received from a remote proxy via the websocket protocol. This proxy opens a UDP
|
||||||
|
port for each VpnCloud instance that connects to it. The instance can use this port
|
||||||
|
remotely just like it would use a real local UDP port.
|
||||||
|
|
||||||
|
The proxy is transparent, it does not manipulate or even decrypt the messages it
|
||||||
|
forwards. Trust relations are still created between VpnCloud instances, not between
|
||||||
|
an instance and the proxy. The proxy only ever sees encrypted messages. Therefore,
|
||||||
|
the connection to it uses plain HTTP.
|
||||||
|
|
||||||
|
A websocket proxy can be stared by using the *ws-proxy* subcommand. A custom port
|
||||||
|
can be set using the *--listen* parameter. (Note that this port never conflicts
|
||||||
|
with a VpnCloud port on the same machine since VpnCloud uses UDP and the proxy uses
|
||||||
|
TCP.)
|
||||||
|
|
||||||
|
A VpnCloud instance can use a websocket proxy instead of opening a local port by
|
||||||
|
specifying the websocket proxy via its *--listen* parameter
|
||||||
|
(e.g. *--listen ws://example.com:3210*). Note that the websocket URL must start with
|
||||||
|
*ws:\/\/*, not *http:\/\/*.
|
||||||
|
|
||||||
|
|
||||||
|
== HOOK SCRIPTS
|
||||||
|
|
||||||
|
VpnCloud supports calling hook scripts on certain events. The scripts can either be
|
||||||
|
configured on the command line or in the config file. Hook scripts can either be
|
||||||
|
configured per event type or globally.
|
||||||
|
|
||||||
|
When an event occurs, the specified hook script is executed using
|
||||||
|
the current permissions of the user that started the instance. Note that this means
|
||||||
|
that if VpnCloud is configured to drop permissions, only the events *device_setup*
|
||||||
|
and *device_configured* will be executed using root permissions.
|
||||||
|
|
||||||
|
Hook scripts are executed using *sh -c*, so either binaries, shell scripts and even
|
||||||
|
shell commands can be used. The script will be executed in parallel to the VpnCloud
|
||||||
|
instance. Its output will be printed to the stdout of VpnCloud and the return code
|
||||||
|
is ignored.
|
||||||
|
|
||||||
|
The hook script will receive information on the event using environment variables.
|
||||||
|
The variable *EVENT* will contain the name of the event. Other variables depend on
|
||||||
|
the event type.
|
||||||
|
|
||||||
|
The following event types
|
||||||
|
|
||||||
|
*peer_connecting*::
|
||||||
|
A new peer connection is in the process of being established. The variable
|
||||||
|
*PEER* contains the address of the peer but no other information is known at
|
||||||
|
that point in time.
|
||||||
|
Variables: *IFNAME*, *PEER*
|
||||||
|
|
||||||
|
*peer_connected*::
|
||||||
|
A new peer successfully connected to this instance. Besides the peer address,
|
||||||
|
also a list of claims (*CLAIMS*, space separated) and the node id of the new
|
||||||
|
peer (*NODE_ID*) are given to the script.
|
||||||
|
Variables: *IFNAME*, *PEER*, *CLAIMS*, *NODE_ID*
|
||||||
|
|
||||||
|
*peer_disconnected*::
|
||||||
|
A peer connection has been closed. If the peer has been fully connected, the
|
||||||
|
node id is given (*NODE_ID*).
|
||||||
|
Variables: *IFNAME*, *PEER*, (*NODE_ID*)
|
||||||
|
|
||||||
|
*device_setup*::
|
||||||
|
This event is fired when the virtual device has been created but not yet
|
||||||
|
configured.
|
||||||
|
Variables: *IFNAME*
|
||||||
|
|
||||||
|
*device_configured*::
|
||||||
|
This event is fired when the virtual device is fully configured.
|
||||||
|
Variables: *IFNAME*
|
||||||
|
|
||||||
|
*vpn_started*::
|
||||||
|
This event is fired when the VPN is ready to be used.
|
||||||
|
Variables: *IFNAME*
|
||||||
|
|
||||||
|
*vpn_shutdown*::
|
||||||
|
This event is fired when the VPN s shutting down.
|
||||||
|
Variables: *IFNAME*
|
||||||
|
|
||||||
|
|
||||||
== DEVICE SETUP
|
== DEVICE SETUP
|
||||||
|
|
||||||
The device is setup using the following steps:
|
The device is setup using the following steps:
|
||||||
|
@ -486,5 +614,5 @@ given.
|
||||||
|
|
||||||
== COPYRIGHT
|
== COPYRIGHT
|
||||||
|
|
||||||
Copyright (C) 2015-2020 Dennis Schwerdel
|
Copyright (C) 2015-2021 Dennis Schwerdel
|
||||||
This software is licensed under GPL-3 or newer (see LICENSE.md)
|
This software is licensed under GPL-3 or newer (see LICENSE.md)
|
||||||
|
|
Loading…
Reference in New Issue