diff --git a/Cargo.lock b/Cargo.lock index cd17228..18920dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -70,34 +85,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "anyhow" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - -[[package]] -name = "async-stream" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" -dependencies = [ - "async-stream-impl", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "atty" version = "0.2.14" @@ -136,38 +123,6 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bindgen" -version = "0.69.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" -dependencies = [ - "bitflags 2.6.0", - "cexpr", - "clang-sys", - "itertools", - "lazy_static", - "lazycell", - "log", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 2.0.72", - "which", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -196,6 +151,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byteorder" version = "1.5.0" @@ -234,15 +195,6 @@ version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "504bdec147f2cc13c8b57ed9401fd8a147cc66b67ad5cb241394244f2c947549" -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -255,6 +207,20 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + [[package]] name = "cipher" version = "0.3.0" @@ -274,17 +240,6 @@ dependencies = [ "inout", ] -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "2.34.0" @@ -300,6 +255,12 @@ dependencies = [ "vec_map", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.12" @@ -370,12 +331,6 @@ dependencies = [ "syn 2.0.72", ] -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - [[package]] name = "env_logger" version = "0.9.3" @@ -395,16 +350,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "fiat-crypto" version = "0.2.9" @@ -537,12 +482,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - [[package]] name = "hashbrown" version = "0.14.5" @@ -570,15 +509,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "humantime" version = "2.1.0" @@ -594,6 +524,29 @@ dependencies = [ "phf", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "indexmap" version = "2.4.0" @@ -619,24 +572,6 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" -[[package]] -name = "ipnetwork" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e" -dependencies = [ - "serde", -] - -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" @@ -644,16 +579,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] -name = "lazy_static" -version = "1.5.0" +name = "js-sys" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] [[package]] name = "libc" @@ -671,12 +603,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "lock_api" version = "0.4.12" @@ -699,12 +625,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.7.4" @@ -726,99 +646,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "net-route" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b9c8e9fc939c670a3e68756d9a3c83f336dacec28cda45448ea65f8243d6cb3" -dependencies = [ - "async-stream", - "bindgen", - "futures", - "netlink-packet-core", - "netlink-packet-route", - "netlink-sys", - "rtnetlink", - "tokio", - "winapi", -] - -[[package]] -name = "netlink-packet-core" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72724faf704479d67b388da142b186f916188505e7e0b26719019c525882eda4" -dependencies = [ - "anyhow", - "byteorder", - "netlink-packet-utils", -] - -[[package]] -name = "netlink-packet-route" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74c171cd77b4ee8c7708da746ce392440cb7bcf618d122ec9ecc607b12938bf4" -dependencies = [ - "anyhow", - "byteorder", - "libc", - "log", - "netlink-packet-core", - "netlink-packet-utils", -] - -[[package]] -name = "netlink-packet-utils" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" -dependencies = [ - "anyhow", - "byteorder", - "paste", - "thiserror", -] - -[[package]] -name = "netlink-proto" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b33524dc0968bfad349684447bfce6db937a9ac3332a1fe60c0c5a5ce63f21" -dependencies = [ - "bytes", - "futures", - "log", - "netlink-packet-core", - "netlink-sys", - "thiserror", - "tokio", -] - -[[package]] -name = "netlink-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416060d346fbaf1f23f9512963e3e878f1a78e707cb699ba9215761754244307" -dependencies = [ - "bytes", - "futures", - "libc", - "log", - "tokio", -] - -[[package]] -name = "nix" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" -dependencies = [ - "bitflags 2.6.0", - "cfg-if", - "libc", -] - [[package]] name = "nix" version = "0.29.0" @@ -832,19 +659,12 @@ dependencies = [ ] [[package]] -name = "no-std-net" -version = "0.6.0" +name = "num-traits" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ - "memchr", - "minimal-lexical", + "autocfg", ] [[package]] @@ -903,12 +723,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - [[package]] name = "phf" version = "0.8.0" @@ -939,97 +753,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pnet" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "682396b533413cc2e009fbb48aadf93619a149d3e57defba19ff50ce0201bd0d" -dependencies = [ - "ipnetwork", - "pnet_base", - "pnet_datalink", - "pnet_packet", - "pnet_sys", - "pnet_transport", -] - -[[package]] -name = "pnet_base" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc190d4067df16af3aba49b3b74c469e611cad6314676eaf1157f31aa0fb2f7" -dependencies = [ - "no-std-net", -] - -[[package]] -name = "pnet_datalink" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79e70ec0be163102a332e1d2d5586d362ad76b01cec86f830241f2b6452a7b7" -dependencies = [ - "ipnetwork", - "libc", - "pnet_base", - "pnet_sys", - "winapi", -] - -[[package]] -name = "pnet_macros" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13325ac86ee1a80a480b0bc8e3d30c25d133616112bb16e86f712dcf8a71c863" -dependencies = [ - "proc-macro2", - "quote", - "regex", - "syn 2.0.72", -] - -[[package]] -name = "pnet_macros_support" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eed67a952585d509dd0003049b1fc56b982ac665c8299b124b90ea2bdb3134ab" -dependencies = [ - "pnet_base", -] - -[[package]] -name = "pnet_packet" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c96ebadfab635fcc23036ba30a7d33a80c39e8461b8bd7dc7bb186acb96560f" -dependencies = [ - "glob", - "pnet_base", - "pnet_macros", - "pnet_macros_support", -] - -[[package]] -name = "pnet_sys" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d4643d3d4db6b08741050c2f3afa9a892c4244c085a72fcda93c9c2c9a00f4b" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "pnet_transport" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f604d98bc2a6591cf719b58d3203fd882bdd6bf1db696c4ac97978e9f4776bf" -dependencies = [ - "libc", - "pnet_base", - "pnet_packet", - "pnet_sys", -] - [[package]] name = "polyval" version = "0.6.2" @@ -1051,16 +774,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "prettyplease" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" -dependencies = [ - "proc-macro2", - "syn 2.0.72", -] - [[package]] name = "proc-macro2" version = "1.0.86" @@ -1147,36 +860,12 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" -[[package]] -name = "rtnetlink" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b684475344d8df1859ddb2d395dd3dac4f8f3422a1aa0725993cb375fc5caba5" -dependencies = [ - "futures", - "log", - "netlink-packet-core", - "netlink-packet-route", - "netlink-packet-utils", - "netlink-proto", - "netlink-sys", - "nix 0.27.1", - "thiserror", - "tokio", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc_version" version = "0.4.0" @@ -1186,29 +875,15 @@ dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags 2.6.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - [[package]] name = "rustvpn" version = "0.1.2" dependencies = [ "aes-gcm", - "anyhow", "base64", - "bincode", "block-modes", "block-padding", + "chrono", "clap", "crossbeam-channel", "env_logger", @@ -1216,9 +891,7 @@ dependencies = [ "generic-array", "hex", "log", - "net-route", "packet", - "pnet", "rand", "serde", "serde_derive", @@ -1280,12 +953,6 @@ dependencies = [ "unsafe-libyaml", ] -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -1449,7 +1116,7 @@ dependencies = [ "libc", "libloading", "log", - "nix 0.29.0", + "nix", "thiserror", "windows-sys 0.52.0", "wintun", @@ -1508,17 +1175,60 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "which" -version = "4.4.2" +name = "wasm-bindgen" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ - "either", - "home", + "cfg-if", "once_cell", - "rustix", + "wasm-bindgen-macro", ] +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.72", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + [[package]] name = "winapi" version = "0.3.9" @@ -1550,6 +1260,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index abcf1ca..ba7ee2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,7 @@ aes-gcm = "0.10.3" tokio = { version = "1", features = ["full", "signal"] } serde = "1.0" serde_derive = "1.0.190" -bincode = "1.3" rand = { version = "0.8.5", features = ["small_rng", "getrandom", "std_rng"] } -anyhow = "1.0" block-modes = "0.8" block-padding = "0.2" generic-array = "0.14" @@ -24,9 +22,8 @@ futures = "0.3.30" tun2 = "2.0.5" packet = "0.1.4" crossbeam-channel = "0.5.13" -pnet = "0.35.0" -net-route = "0.4.4" hex = "0.4" serde_yaml = "0.9.34" x25519-dalek = { version = "2.0.1", features = ["getrandom", "static_secrets"] } base64 = "0.22.1" +chrono = "0.4.38" \ No newline at end of file diff --git a/src/client.rs b/src/client.rs index f5af13b..a762094 100644 --- a/src/client.rs +++ b/src/client.rs @@ -139,6 +139,7 @@ pub async fn client_mode(client_config: ClientConfiguration) { warn!("There is no static_secret"); } }, // payload + 2 => info!("Got keepalive packet"), _ => error!("Unexpected header value.") } }, diff --git a/src/config.rs b/src/config.rs index 42b8f06..329eee6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,9 +24,10 @@ pub struct ServerPeer { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub enum ObfsProtocol { - DNSMask, - ICMPMask, - XOR + FakeDNS, + VEIL, + XOR, + NONE } #[derive(Serialize, Deserialize, PartialEq, Debug)] diff --git a/src/main.rs b/src/main.rs index d1a90be..02aa080 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use log::{error, LevelFilter}; use crate::config::{ ServerConfiguration, ClientConfiguration, ObfsProtocol, ServerPeer }; - +mod obfs; mod server; mod client; mod udp; @@ -24,9 +24,10 @@ fn generate_server_config(matches: &ArgMatches, config_path: &str) { let broadcast_mode = matches.value_of("broadcast-mode").is_some(); let keepalive: u8 = matches.value_of("keepalive").unwrap().parse().expect("Keepalive argument should be a number"); let obfs_type = match matches.value_of("obfs-type").expect("Obfs type should be specified") { - "dns" => ObfsProtocol::DNSMask, - "icmp" => ObfsProtocol::ICMPMask, - _ => ObfsProtocol::XOR + "dns" => ObfsProtocol::FakeDNS, + "veil" => ObfsProtocol::VEIL, + "xor" => ObfsProtocol::XOR, + _ => ObfsProtocol::NONE }; let _ = fs::write(config_path, serde_yaml::to_string(&ServerConfiguration::default(bind_address, internal_address, broadcast_mode, keepalive, obfs_type)).unwrap()); diff --git a/src/obfs.rs b/src/obfs.rs index e69de29..99d3492 100644 --- a/src/obfs.rs +++ b/src/obfs.rs @@ -0,0 +1,55 @@ +use chrono::{Timelike, Utc}; +use rand::{rngs::OsRng, RngCore}; + +pub struct VEIL { +} + +pub struct XOR { + +} + +pub struct DNS { + rng: OsRng +} + +impl Obfuscator for DNS { + fn obfuscate(&mut self, plain: Vec) -> Vec { + let mut result = Vec::::new(); + let mut tr_id = [0u8; 2]; + self.rng.fill_bytes(&mut tr_id); + result.extend(tr_id); + let flags = [01u8, 00]; + result.extend(flags); + let mut questions = [0u8; 2]; + self.rng.fill_bytes(&mut questions); + result.extend(questions); + let rr = [0u8,0,0,0,0,0]; + result.extend(rr); + result.extend(&plain[..]); + let end = [0u8, 1, 0, 1]; + result.extend(end); + result + } + + fn deobfuscate(&mut self, obfs: Vec) -> Vec { + let s = &mut obfs[11..].to_vec(); + s.truncate(s.len()-4); + s.to_vec() + } +} + +impl Obfuscator for XOR { + fn obfuscate(&mut self, plain: Vec) -> Vec { + let t: u8 = Utc::now().minute() as u8; + plain.iter().map(|i| i ^ t).collect::>() + } + + fn deobfuscate(&mut self, obfs: Vec) -> Vec { + self.obfuscate(obfs) + } +} + +pub trait Obfuscator { + fn obfuscate(&mut self, plain: Vec) -> Vec; + fn deobfuscate(&mut self, obfs: Vec) -> Vec; +} \ No newline at end of file diff --git a/src/server.rs b/src/server.rs index ce04ab5..bd8b2f7 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,7 +1,9 @@ use crossbeam_channel::unbounded; use tokio::{net::UdpSocket, sync::Mutex}; use x25519_dalek::{PublicKey, StaticSecret}; +use core::time; use std::io::{Read, Write}; +use std::thread; use base64::prelude::*; use log::{error, info}; use std::sync::Arc; @@ -11,7 +13,7 @@ use aes_gcm::{ aead::{Aead, AeadCore, KeyInit, OsRng}, Aes256Gcm, Nonce }; use crate::config::{ ServerConfiguration, ServerPeer}; -use crate::udp::{UDPSerializable, UDPVpnHandshake, UDPVpnPacket}; +use crate::udp::{UDPKeepAlive, UDPSerializable, UDPVpnHandshake, UDPVpnPacket}; pub async fn server_mode(server_config: ServerConfiguration) { info!("Starting server..."); @@ -34,7 +36,7 @@ pub async fn server_mode(server_config: ServerConfiguration) { let (send2tun, recv2tun) = unbounded::>(); - let (send2hnd, recv2hnd) = unbounded::<(UDPVpnHandshake, SocketAddr)>(); + let (send2hnd, recv2hnd) = unbounded::<(Vec, SocketAddr)>(); tokio::spawn(async move { loop { @@ -44,10 +46,26 @@ pub async fn server_mode(server_config: ServerConfiguration) { } }); + let keepalive_sec = server_config.interface.keepalive; + let send2hnd_cl = send2hnd.clone(); + let addrs_lcl = addresses.clone(); + if keepalive_sec > 0 { + tokio::spawn(async move { + loop { + thread::sleep(time::Duration::from_secs(keepalive_sec.into())); + let mp = addrs_lcl.lock().await; + mp.values().for_each(|p| { + let _ = send2hnd_cl.send((UDPKeepAlive{}.serialize(), p.addr)); + }); + drop(mp); + } + }); + } + tokio::spawn(async move { loop { if let Ok((handshake, addr)) = recv2hnd.recv() { - let _ = sock_hnd.send_to(&handshake.serialize(), addr).await; + let _ = sock_hnd.send_to(&handshake, addr).await; } } }); @@ -119,7 +137,7 @@ pub async fn server_mode(server_config: ServerConfiguration) { let handshake_response = UDPVpnHandshake{ public_key: BASE64_STANDARD.decode(&server_config.interface.public_key).unwrap(), request_ip: handshake.request_ip }; - let _ = send2hnd.send((handshake_response, addr)); + let _ = send2hnd.send((handshake_response.serialize(), addr)); } else { info!("Bad handshake"); plp.iter().for_each(|c| info!("ip: {:?}; pkey: {:?}", c.ip, c.public_key)); diff --git a/src/udp.rs b/src/udp.rs index 663817d..0248784 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -1,11 +1,23 @@ use std::net::Ipv4Addr; +use chrono::{Timelike, Utc}; pub struct UDPVpnPacket { pub nonce: Vec, // [u8; 12] pub data: Vec } +pub struct UDPKeepAlive { + +} + +impl UDPSerializable for UDPKeepAlive { + fn serialize(&self) -> Vec { + let h: &[u8] = &[2]; + [h, &[Utc::now().second() as u8]].concat() + } +} + impl UDPSerializable for UDPVpnPacket { fn serialize(&self) -> Vec { let h: &[u8] = &[1];