Compare commits
5 Commits
2e08a3093e
...
0235de2896
Author | SHA1 | Date | |
---|---|---|---|
0235de2896 | |||
49e3aa1a3a | |||
e17ded8db0 | |||
e1d5a34e82 | |||
3bcccc7620 |
589
Cargo.lock
generated
589
Cargo.lock
generated
@ -2,6 +2,32 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aes"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cipher",
|
||||
"cpufeatures",
|
||||
]
|
||||
|
||||
[[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 = "anstream"
|
||||
version = "0.6.19"
|
||||
@ -177,12 +203,36 @@ version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-padding"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blocking"
|
||||
version = "1.6.2"
|
||||
@ -196,12 +246,60 @@ dependencies = [
|
||||
"piper",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
|
||||
|
||||
[[package]]
|
||||
name = "cbc"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6"
|
||||
dependencies = [
|
||||
"cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cipher"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
|
||||
dependencies = [
|
||||
"crypto-common",
|
||||
"inout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.41"
|
||||
@ -257,12 +355,73 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[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.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.13"
|
||||
@ -326,13 +485,24 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.16"
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
@ -348,12 +518,65 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"log",
|
||||
"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 = "inout"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
|
||||
dependencies = [
|
||||
"block-padding",
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.174"
|
||||
@ -366,6 +589,21 @@ version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
@ -378,18 +616,135 @@ version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||
|
||||
[[package]]
|
||||
name = "orx-concurrent-iter"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9c7567a3f51c144ea6e55e0c7e4a26039d22d8948c268f5244c539aa84d2e67"
|
||||
dependencies = [
|
||||
"orx-iterable",
|
||||
"orx-pseudo-default",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orx-concurrent-option"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "842a5c05d6f02368d1cdfebec87ae6e2277ca0cf544ab3778e6f2e6c5c947da3"
|
||||
|
||||
[[package]]
|
||||
name = "orx-concurrent-vec"
|
||||
version = "3.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "384cd6cd25e3cf031091ca7cfe947a59be14e62e1a28480a5e92d46b792b6303"
|
||||
dependencies = [
|
||||
"orx-concurrent-option",
|
||||
"orx-fixed-vec",
|
||||
"orx-pinned-concurrent-col",
|
||||
"orx-pinned-vec",
|
||||
"orx-pseudo-default",
|
||||
"orx-split-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orx-fixed-vec"
|
||||
version = "3.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf1694c28d604fe9139aeeec1ce20e091c1e7a58beb0e444f23b2cd95ed781e0"
|
||||
dependencies = [
|
||||
"orx-concurrent-iter",
|
||||
"orx-iterable",
|
||||
"orx-pinned-vec",
|
||||
"orx-pseudo-default",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orx-iterable"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfa2cb3f82a187c68835faac9cf03faaee70b93f4da3b85515ac1b4c6f8a432d"
|
||||
dependencies = [
|
||||
"orx-self-or",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orx-pinned-concurrent-col"
|
||||
version = "2.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "54a78c53b0f313be2663e525cf8cdba2e66e58b755247dc920bd8eb324071432"
|
||||
dependencies = [
|
||||
"orx-fixed-vec",
|
||||
"orx-pinned-vec",
|
||||
"orx-pseudo-default",
|
||||
"orx-split-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orx-pinned-vec"
|
||||
version = "3.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2707ef8045673419bec5b92a3073b0066fed6d42b1f1be07aa50201fd3cb4e92"
|
||||
dependencies = [
|
||||
"orx-iterable",
|
||||
"orx-pseudo-default",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orx-pseudo-default"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34eaace9ae01f7025804fbca40ec45b87c19ba0328d97195e01c6135897762a8"
|
||||
|
||||
[[package]]
|
||||
name = "orx-self-or"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67a8e35dfe18921e475b9861266fd58a5ecfd681161f242d24a9e2d1e07fbc28"
|
||||
|
||||
[[package]]
|
||||
name = "orx-split-vec"
|
||||
version = "3.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20887c6f134a4346e96db3c0235576b6a7ff3b10030f3a64a0d306235ee9adfe"
|
||||
dependencies = [
|
||||
"orx-concurrent-iter",
|
||||
"orx-iterable",
|
||||
"orx-pinned-vec",
|
||||
"orx-pseudo-default",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
|
||||
|
||||
[[package]]
|
||||
name = "pbkdf2"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"hmac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pea_2_pea"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"cbc",
|
||||
"chrono",
|
||||
"cipher",
|
||||
"clap",
|
||||
"hmac",
|
||||
"orx-concurrent-vec",
|
||||
"pbkdf2",
|
||||
"rand",
|
||||
"rayon",
|
||||
"readonly",
|
||||
"sha2",
|
||||
"smol",
|
||||
"tappers",
|
||||
]
|
||||
@ -453,21 +808,26 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
name = "r-efi"
|
||||
version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
@ -475,13 +835,44 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
|
||||
dependencies = [
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "readonly"
|
||||
version = "0.2.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2a62d85ed81ca5305dc544bd42c8804c5060b78ffa5ad3c64b0fb6a8c13d062"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.0.8"
|
||||
@ -495,6 +886,29 @@ dependencies = [
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[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.5"
|
||||
@ -533,6 +947,12 @@ version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.104"
|
||||
@ -555,6 +975,12 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
@ -568,10 +994,136 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.1+wasi-snapshot-preview1"
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.14.2+wasi-0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||
dependencies = [
|
||||
"wit-bindgen-rt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-link",
|
||||
"windows-result",
|
||||
"windows-strings",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.60.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.59.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
@ -719,6 +1271,15 @@ version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rt"
|
||||
version = "0.39.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.26"
|
||||
|
12
Cargo.toml
12
Cargo.toml
@ -13,7 +13,17 @@ path = "src/client/main.rs"
|
||||
|
||||
|
||||
[dependencies]
|
||||
aes = "0.8.4"
|
||||
cbc = "0.1.2"
|
||||
chrono = "0.4.41"
|
||||
cipher = { version = "0.4.4", features = ["block-padding", "alloc"] }
|
||||
clap = { version = "4.5.41", features = ["derive"] }
|
||||
rand = "0.8.5"
|
||||
hmac = "0.12.1"
|
||||
orx-concurrent-vec = "3.6.0"
|
||||
pbkdf2 = "0.12.2"
|
||||
rand = "0.9.2"
|
||||
rayon = "1.10.0"
|
||||
readonly = "0.2.13"
|
||||
sha2 = "0.10.9"
|
||||
smol = "2.0.2"
|
||||
tappers = "0.4.2"
|
||||
|
@ -1,7 +1,9 @@
|
||||
use pea_2_pea::SERVER_PORT;
|
||||
mod net;
|
||||
use pea_2_pea::*;
|
||||
use rand::RngCore;
|
||||
|
||||
use std::{
|
||||
io::{ErrorKind, Read, Write},
|
||||
io::{Error, ErrorKind, Read, Write},
|
||||
net::UdpSocket,
|
||||
process::exit,
|
||||
time::Duration,
|
||||
@ -15,82 +17,66 @@ struct Cli {
|
||||
#[arg(help = "registrar ip address or hostname")]
|
||||
registrar: String,
|
||||
|
||||
#[arg(short = 'p', long = "registrar-port")]
|
||||
#[arg(help = format!("optional Port number for the registrar service (1-65535) Default: {}", SERVER_PORT))]
|
||||
registrar_port: Option<u16>,
|
||||
|
||||
#[arg(short = 'n', long = "network-id")]
|
||||
#[arg(help = "your virtual network id that allows other people to connect to you")]
|
||||
network_id: String,
|
||||
|
||||
#[arg(short = 'P', long = "password")]
|
||||
#[arg(
|
||||
help = "encryption password for your virtual network if not provided transmitions will be unencrypted"
|
||||
)]
|
||||
password: Option<String>,
|
||||
|
||||
#[arg(short = 'v', long = "verbose")]
|
||||
verbose: bool,
|
||||
|
||||
#[arg(short = 'V', long = "version")]
|
||||
version: bool,
|
||||
|
||||
#[arg(short = 'p', long = "registrar-port")]
|
||||
#[arg(help = format!("Port number for the registrar service (1-65535) Default: {}", SERVER_PORT))]
|
||||
registrar_port: Option<u16>,
|
||||
|
||||
#[arg(short = 'P', long = "bind-port")]
|
||||
bind_port: Option<u16>,
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let cli = <Cli as clap::Parser>::parse();
|
||||
if cli.network_id.len() > 0xff {
|
||||
eprintln!("network id cannot have more then 255 charactes");
|
||||
exit(7); // posix for E2BIG
|
||||
}
|
||||
{
|
||||
let socket: UdpSocket = (|| -> std::io::Result<UdpSocket> {
|
||||
let mut port: u16;
|
||||
match cli.bind_port {
|
||||
Some(port_proveded) => port = port_proveded,
|
||||
None => port = 59999, // Magic number
|
||||
}
|
||||
loop {
|
||||
port += 1;
|
||||
match UdpSocket::bind(format!("0.0.0.0:{}", port)) {
|
||||
Ok(socket) => return Ok(socket),
|
||||
Err(_) => continue, // Retry on error
|
||||
}
|
||||
match UdpSocket::bind("0.0.0.0:0") {
|
||||
// bind to OS assigned random port
|
||||
Ok(socket) => return Ok(socket),
|
||||
Err(e) => Err(e), // exit on error
|
||||
}
|
||||
})()
|
||||
.expect("Failed to bind to any available port");
|
||||
|
||||
socket.set_read_timeout(Some(Duration::new(10, 0)))?; // set timeout to 10 seconds
|
||||
|
||||
// send query request to get server public key
|
||||
let server_port: u16 = (|| -> u16 {
|
||||
match cli.bind_port {
|
||||
match cli.registrar_port {
|
||||
Some(port_proveded) => return port_proveded,
|
||||
None => return pea_2_pea::SERVER_PORT,
|
||||
None => return SERVER_PORT,
|
||||
}
|
||||
})();
|
||||
|
||||
#[allow(non_snake_case)] // i think this is valid snake case but rustc doesnt think so
|
||||
let server_SocketAddr: core::net::SocketAddr = format!("{}:{}", cli.registrar, server_port)
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
let mut query_byte: [u8; 1] = [0; 1];
|
||||
query_byte[0] = pea_2_pea::ServerMethods::QUERY as u8;
|
||||
match socket.send_to(&query_byte, &server_SocketAddr) {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error snding data: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut buf: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
|
||||
// query here
|
||||
let mut data_lenght: usize = net::query_request(&mut buf, &server_SocketAddr, socket)?;
|
||||
|
||||
let mut buf: [u8; pea_2_pea::BUFFER_SIZE] = [0; pea_2_pea::BUFFER_SIZE];
|
||||
loop {
|
||||
match socket.recv_from(&mut buf) {
|
||||
Ok((data_length, src)) => {}
|
||||
Err(e) if e.kind() == ErrorKind::WouldBlock || e.kind() == ErrorKind::TimedOut => {
|
||||
// timedout
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error receiving data: {}", e);
|
||||
std::process::exit(-4);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
let mut public_sock_addr: Vec<u8> = buf[1..data_lenght].to_vec();
|
||||
|
||||
// register network
|
||||
|
||||
let mut salt: Option<[u8; SALT_AND_IV_SIZE as usize]>;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
144
src/client/net.rs
Normal file
144
src/client/net.rs
Normal file
@ -0,0 +1,144 @@
|
||||
use std::{
|
||||
io::ErrorKind,
|
||||
net::{SocketAddr, UdpSocket},
|
||||
};
|
||||
|
||||
use pea_2_pea::*;
|
||||
use rand::RngCore;
|
||||
|
||||
// return data_lenght and number of retryes
|
||||
pub fn send_and_recv_with_retry(
|
||||
buf: &mut [u8; BUFFER_SIZE],
|
||||
dst: &SocketAddr,
|
||||
socket: UdpSocket,
|
||||
retry_max: usize,
|
||||
) -> Result<(usize, usize), ServerErrorResponses> {
|
||||
let mut send_buf = *buf;
|
||||
let mut retry_count: usize = 0;
|
||||
loop {
|
||||
match socket.send_to(&mut send_buf, dst) {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
panic!("Error sending data: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
match socket.recv_from(buf) {
|
||||
Ok((data_lenght, src)) => {
|
||||
if src != *dst {
|
||||
continue;
|
||||
}
|
||||
match buf[0] {
|
||||
x if x == send_buf[0] as u8 => {
|
||||
return Ok((data_lenght, retry_count));
|
||||
}
|
||||
x if x == ServerResponse::GENERAL_ERROR as u8 => {
|
||||
return Err(ServerErrorResponses::IO(std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidData,
|
||||
match std::str::from_utf8(&buf[1..data_lenght]) {
|
||||
// the firts byte is compensated for sice this is len not index
|
||||
Ok(s) => s.to_string(),
|
||||
Err(e) => format!("invalid error string: {}", e).to_string(),
|
||||
},
|
||||
)));
|
||||
}
|
||||
x if x == ServerResponse::ID_DOESNT_EXIST as u8 => {
|
||||
return Err(ServerErrorResponses::ID_DOESNT_EXIST);
|
||||
}
|
||||
x if x == ServerResponse::ID_EXISTS as u8 => {
|
||||
return Err(ServerErrorResponses::ID_EXISTS);
|
||||
}
|
||||
_ => {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) if e.kind() == ErrorKind::WouldBlock || e.kind() == ErrorKind::TimedOut => {
|
||||
// timedout
|
||||
if retry_count >= retry_max {
|
||||
return Err(ServerErrorResponses::IO(std::io::Error::new(
|
||||
ErrorKind::TimedOut,
|
||||
"max retry count reached without responce",
|
||||
)));
|
||||
}
|
||||
retry_count += 1;
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(ServerErrorResponses::IO(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn query_request(
|
||||
buf: &mut [u8; BUFFER_SIZE],
|
||||
dst: &SocketAddr,
|
||||
socket: UdpSocket,
|
||||
) -> Result<usize, ServerErrorResponses> {
|
||||
match send_and_recv_with_retry(buf, dst, socket, STANDARD_RETRY_MAX) {
|
||||
Ok((data_lenght, _)) => return Ok(data_lenght),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_request(
|
||||
buf: &mut [u8; BUFFER_SIZE],
|
||||
dst: &SocketAddr,
|
||||
socket: UdpSocket,
|
||||
encryption_key: Option<[u8; 32]>,
|
||||
salt_opt: Option<[u8; SALT_AND_IV_SIZE as usize]>,
|
||||
mut public_sock_addr: Vec<u8>,
|
||||
network_id: String,
|
||||
) -> Result<usize, ServerErrorResponses> {
|
||||
buf[0] = ServerMethods::REGISTER as u8; // set metod identification byte
|
||||
buf[RegisterRequestDataPositions::ENCRYPTED as usize] = match encryption_key {
|
||||
// stor encryption flag byte
|
||||
Some(_) => true as u8,
|
||||
None => false as u8,
|
||||
};
|
||||
buf[RegisterRequestDataPositions::ID_LEN as usize] = network_id.len() as u8;
|
||||
|
||||
buf[RegisterRequestDataPositions::DATA as usize
|
||||
..RegisterRequestDataPositions::DATA as usize + network_id.len()]
|
||||
.copy_from_slice(network_id.as_bytes()); // store network id
|
||||
|
||||
let mut iv: [u8; SALT_AND_IV_SIZE as usize] = [0; SALT_AND_IV_SIZE as usize];
|
||||
let salt: [u8; SALT_AND_IV_SIZE as usize];
|
||||
match salt_opt {
|
||||
Some(s) => salt = s,
|
||||
None => salt = [0; SALT_AND_IV_SIZE as usize],
|
||||
}
|
||||
match encryption_key {
|
||||
Some(encryption_key) => {
|
||||
let mut rng = rand::rng();
|
||||
rng.fill_bytes(&mut iv);
|
||||
public_sock_addr =
|
||||
shared::crypto::encrypt(&encryption_key, &iv, public_sock_addr.as_slice()).unwrap();
|
||||
}
|
||||
None => {
|
||||
iv = [0; SALT_AND_IV_SIZE as usize];
|
||||
}
|
||||
};
|
||||
|
||||
buf[RegisterRequestDataPositions::IV as usize
|
||||
..RegisterRequestDataPositions::IV as usize + SALT_AND_IV_SIZE as usize]
|
||||
.copy_from_slice(&iv); // copy iv ad salt do the request
|
||||
buf[RegisterRequestDataPositions::SALT as usize
|
||||
..RegisterRequestDataPositions::SALT as usize + SALT_AND_IV_SIZE as usize]
|
||||
.copy_from_slice(&salt);
|
||||
|
||||
buf[RegisterRequestDataPositions::SOCKADDR_LEN as usize] = public_sock_addr.len() as u8;
|
||||
|
||||
buf[RegisterRequestDataPositions::DATA as usize + network_id.len()
|
||||
..RegisterRequestDataPositions::DATA as usize + network_id.len() + public_sock_addr.len()]
|
||||
.copy_from_slice(&public_sock_addr);
|
||||
|
||||
match send_and_recv_with_retry(buf, dst, socket, STANDARD_RETRY_MAX) {
|
||||
Ok((data_lenght, _)) => return Ok(data_lenght),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
67
src/lib.rs
67
src/lib.rs
@ -1,15 +1,78 @@
|
||||
use core::fmt;
|
||||
|
||||
pub const SERVER_PORT: u16 = 3543;
|
||||
pub const BUFFER_SIZE: usize = 65535;
|
||||
pub const DEFAULT_TIMEOUT: u64 = 30;
|
||||
pub const VERSION: &str = "v0.1";
|
||||
pub const RSA_SIZE: usize = 2048;
|
||||
pub const SALT_AND_IV_SIZE: u8 = 16;
|
||||
pub const STANDARD_RETRY_MAX: usize = 10;
|
||||
|
||||
#[repr(u8)]
|
||||
pub enum ServerMethods {
|
||||
QUERY = 0,
|
||||
QUERY = 0, // return IP and port of the client
|
||||
REGISTER = 1,
|
||||
GET = 2,
|
||||
HEARTBEAT = 3,
|
||||
}
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum ServerResponse {
|
||||
GENERAL_ERROR = 255,
|
||||
ID_EXISTS = 254,
|
||||
ID_DOESNT_EXIST = 253, // both error since sometimes it is the problem that the id exist and somethimes problem is that is doesn't
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug)]
|
||||
pub enum ServerErrorResponses {
|
||||
GENERAL_ERROR(String),
|
||||
ID_EXISTS,
|
||||
ID_DOESNT_EXIST,
|
||||
IO(std::io::Error), // IO errors wraper
|
||||
}
|
||||
|
||||
impl fmt::Display for ServerErrorResponses {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
ServerErrorResponses::GENERAL_ERROR(msg) => write!(f, "General error: {}", msg),
|
||||
ServerErrorResponses::ID_EXISTS => write!(f, "ID is already registered"),
|
||||
ServerErrorResponses::ID_DOESNT_EXIST => write!(f, "ID isn't yet registered"),
|
||||
ServerErrorResponses::IO(err) => write!(f, "IO error: {}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ServerErrorResponses {}
|
||||
impl From<std::io::Error> for ServerErrorResponses {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
ServerErrorResponses::IO(error)
|
||||
}
|
||||
}
|
||||
impl ServerErrorResponses {
|
||||
pub fn into_io_error(self) -> std::io::Error {
|
||||
match self {
|
||||
ServerErrorResponses::IO(io_err) => io_err,
|
||||
other => std::io::Error::new(std::io::ErrorKind::Other, other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum RegisterRequestDataPositions {
|
||||
ENCRYPTED = 1, // this feeld should be 0 if not encrypted
|
||||
ID_LEN = 2,
|
||||
SOCKADDR_LEN = 3,
|
||||
SALT = 4,
|
||||
IV = (SALT_AND_IV_SIZE + RegisterRequestDataPositions::SALT as u8) as isize,
|
||||
DATA = (SALT_AND_IV_SIZE + RegisterRequestDataPositions::IV as u8) as isize, // after this there will be id and sockaddr in string or encrypted form after
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum GetResponseDataPositions {
|
||||
ENCRYPTED = 1, // this feeld should be 0 if not encrypted
|
||||
ID_LEN = 2,
|
||||
NUM_OF_CLIENTS = 3,
|
||||
SALT = 4,
|
||||
CLIENTS = (SALT_AND_IV_SIZE + RegisterRequestDataPositions::SALT as u8) as isize,
|
||||
// after this there will be blocks of this sturcture: one byte size of sockaddr than there will be IV that is SALT_AND_IV_SIZE long and after that there will be sockaddr this repeats until the end of packet
|
||||
}
|
||||
|
||||
pub mod shared;
|
||||
|
@ -1,6 +1,13 @@
|
||||
mod net;
|
||||
use std::{net::UdpSocket, process::exit, sync::Arc};
|
||||
mod types;
|
||||
mod utils;
|
||||
use std::{
|
||||
net::UdpSocket,
|
||||
process::exit,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
use orx_concurrent_vec::ConcurrentVec;
|
||||
fn main() -> std::io::Result<()> {
|
||||
{
|
||||
let socket: Arc<UdpSocket> = Arc::new(
|
||||
@ -14,13 +21,22 @@ fn main() -> std::io::Result<()> {
|
||||
.expect("Failed to bind to any available port"),
|
||||
);
|
||||
|
||||
let registration_vector: Arc<ConcurrentVec<types::Registration>> =
|
||||
Arc::new(orx_concurrent_vec::ConcurrentVec::new());
|
||||
|
||||
let mut buf: [u8; pea_2_pea::BUFFER_SIZE] = [0; pea_2_pea::BUFFER_SIZE];
|
||||
smol::block_on(async {
|
||||
loop {
|
||||
match socket.recv_from(&mut buf) {
|
||||
Ok((data_length, src)) => {
|
||||
smol::spawn(net::handle_request(buf, socket.clone(), src, data_length))
|
||||
.detach();
|
||||
smol::spawn(net::handle_request(
|
||||
buf,
|
||||
socket.clone(),
|
||||
src,
|
||||
data_length,
|
||||
registration_vector.clone(),
|
||||
))
|
||||
.detach();
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error receiving data: {}", e);
|
||||
|
@ -1,19 +1,28 @@
|
||||
use crate::utils::send_general_error_to_client;
|
||||
|
||||
use super::types;
|
||||
use super::utils;
|
||||
use orx_concurrent_vec::ConcurrentVec;
|
||||
use pea_2_pea::*;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::u8;
|
||||
pub async fn handle_request(
|
||||
buf: [u8; pea_2_pea::BUFFER_SIZE],
|
||||
buf: [u8; BUFFER_SIZE],
|
||||
socket: std::sync::Arc<std::net::UdpSocket>,
|
||||
src: core::net::SocketAddr,
|
||||
data_len: usize,
|
||||
registration_vector: Arc<ConcurrentVec<types::Registration>>,
|
||||
) {
|
||||
let mut rng: rand::prelude::ThreadRng = rand::thread_rng();
|
||||
|
||||
match buf[0] {
|
||||
x if x == pea_2_pea::ServerMethods::QUERY as u8 => {
|
||||
x if x == ServerMethods::QUERY as u8 => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("QUERY method");
|
||||
|
||||
let client_sock_addr_str: String = src.to_string();
|
||||
let mut send_vec: Vec<u8> = client_sock_addr_str.into();
|
||||
send_vec.insert(0, pea_2_pea::ServerMethods::QUERY as u8);
|
||||
send_vec.insert(0, ServerMethods::QUERY as u8);
|
||||
|
||||
match socket.send_to(&send_vec, &src) {
|
||||
Ok(s) => {
|
||||
@ -26,15 +35,182 @@ pub async fn handle_request(
|
||||
}
|
||||
}
|
||||
|
||||
x if x == pea_2_pea::ServerMethods::GET as u8 => {
|
||||
x if x == ServerMethods::GET as u8 => {
|
||||
#[cfg(debug_assertions)]
|
||||
println!("GET method");
|
||||
|
||||
if data_len > u8::MAX as usize + 1 {
|
||||
send_general_error_to_client(
|
||||
src,
|
||||
std::io::Error::new(std::io::ErrorKind::InvalidData, "Network ID is too long"),
|
||||
socket,
|
||||
);
|
||||
return; // drop packet if id lenght is biger than posible
|
||||
}
|
||||
|
||||
let net_id: String = match std::str::from_utf8(&buf[1..]) {
|
||||
Ok(s) => s.to_string(),
|
||||
Err(e) => {
|
||||
eprint!("id to utf-8 failed: {}", e);
|
||||
utils::send_general_error_to_client(src, e, socket);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let registration = match registration_vector
|
||||
.iter()
|
||||
.find(|elem| elem.map(|s| &s.net_id == &net_id)) // find if id exists
|
||||
{
|
||||
Some(registration) => registration,
|
||||
None => {let _ = socket.send_to(&[ServerResponse::ID_DOESNT_EXIST as u8], src);
|
||||
return;
|
||||
},
|
||||
}
|
||||
.cloned();
|
||||
let mut send_vec: Vec<u8> = Vec::with_capacity(
|
||||
GetResponseDataPositions::SALT as usize + /*2 times one for SALT and other for first IV*/ 2*SALT_AND_IV_SIZE as usize + 20, /*magic number guess for how long is encrypted residencial ipv4 with port long */
|
||||
); // use vector to handle many clients
|
||||
|
||||
// lets start serializing
|
||||
send_vec.push(registration.encrypted as u8);
|
||||
send_vec.push(registration.net_id.len() as u8);
|
||||
send_vec.push(registration.clients.len() as u8);
|
||||
// todo!("make sure it allows only 255 client per network max");
|
||||
send_vec.extend_from_slice(®istration.salt);
|
||||
|
||||
registration.clients.iter().for_each(|client| {
|
||||
let sock_addr_len: u8 = client.client_sock_addr.len() as u8;
|
||||
|
||||
send_vec.push(sock_addr_len);
|
||||
|
||||
send_vec.extend_from_slice(&client.iv);
|
||||
|
||||
send_vec.extend_from_slice(&client.client_sock_addr);
|
||||
});
|
||||
|
||||
if (send_vec.len() > BUFFER_SIZE) {
|
||||
send_general_error_to_client(
|
||||
src,
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::FileTooLarge,
|
||||
format!(
|
||||
"Max number of clients reached count: {}",
|
||||
registration.clients.len()
|
||||
),
|
||||
),
|
||||
socket,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
match socket.send_to(&send_vec, &src) {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error snding data: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
x if x == pea_2_pea::ServerMethods::REGISTER as u8 => {
|
||||
x if x == ServerMethods::REGISTER as u8 => {
|
||||
#[cfg(debug_assertions)]
|
||||
println!("REGISTER method");
|
||||
let encrypted: bool = buf[RegisterRequestDataPositions::ENCRYPTED as usize] != 0;
|
||||
|
||||
//read lenght of sockaddr
|
||||
// rustc be like RUST HAS NO TERNARY OPERATON USE if-else
|
||||
let len_id: u8 = if buf[RegisterRequestDataPositions::ID_LEN as usize] != 0 {
|
||||
buf[RegisterRequestDataPositions::ID_LEN as usize]
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
let sock_addr_len: u8 = if buf[RegisterRequestDataPositions::SOCKADDR_LEN as usize] != 0
|
||||
{
|
||||
buf[RegisterRequestDataPositions::SOCKADDR_LEN as usize]
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
let net_id: String = match std::str::from_utf8(
|
||||
&buf[(RegisterRequestDataPositions::DATA as usize)
|
||||
..(len_id as usize) + (RegisterRequestDataPositions::DATA as usize)],
|
||||
) {
|
||||
Ok(s) => s.to_string(),
|
||||
Err(e) => {
|
||||
eprint!("id to utf-8 failed: {}", e);
|
||||
utils::send_general_error_to_client(src, e, socket);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match registration_vector
|
||||
.iter()
|
||||
.find(|elem| elem.map(|s| &s.net_id == &net_id)) // find if id exists
|
||||
{
|
||||
Some(_) => {
|
||||
match socket.send_to(&[ServerResponse::ID_EXISTS as u8], src) {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error sending data: {}", e);
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
let salt: Option<[u8; SALT_AND_IV_SIZE as usize]>;
|
||||
let iv: Option<[u8; SALT_AND_IV_SIZE as usize]>;
|
||||
|
||||
if encrypted {
|
||||
salt = Some(
|
||||
buf[(RegisterRequestDataPositions::SALT as usize)
|
||||
..(RegisterRequestDataPositions::SALT as usize)
|
||||
+ (SALT_AND_IV_SIZE as usize)]
|
||||
.try_into()
|
||||
.expect("this should never happen"),
|
||||
);
|
||||
iv = Some(
|
||||
buf[(RegisterRequestDataPositions::IV as usize)
|
||||
..(RegisterRequestDataPositions::IV as usize)
|
||||
+ (SALT_AND_IV_SIZE as usize)]
|
||||
.try_into()
|
||||
.expect("this should never happen"),
|
||||
)
|
||||
} else {
|
||||
salt = None;
|
||||
iv = None;
|
||||
}
|
||||
|
||||
registration_vector.push(types::Registration::new(
|
||||
net_id,
|
||||
buf[(RegisterRequestDataPositions::DATA as usize)
|
||||
..(RegisterRequestDataPositions::DATA as usize) + (sock_addr_len as usize)]
|
||||
.to_vec(),
|
||||
encrypted,
|
||||
chrono::Utc::now().timestamp(),
|
||||
salt,
|
||||
iv,
|
||||
));
|
||||
match socket.send_to(&[ServerMethods::REGISTER as u8], src) {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error sending data: {}", e);
|
||||
}
|
||||
}
|
||||
#[cfg(debug_assertions)]
|
||||
println!("network registered");
|
||||
}
|
||||
x if x == pea_2_pea::ServerMethods::HEARTBEAT as u8 => {
|
||||
|
||||
x if x == ServerMethods::HEARTBEAT as u8 => {
|
||||
#[cfg(debug_assertions)]
|
||||
println!("HEARTBEAT method");
|
||||
}
|
||||
|
118
src/server/types.rs
Normal file
118
src/server/types.rs
Normal file
@ -0,0 +1,118 @@
|
||||
use pea_2_pea::*;
|
||||
use std::sync::{Arc, atomic::Ordering};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[readonly::make]
|
||||
pub struct Client {
|
||||
#[readonly]
|
||||
pub client_sock_addr: Vec<u8>,
|
||||
pub last_heart_beat: i64,
|
||||
#[readonly]
|
||||
pub iv: [u8; SALT_AND_IV_SIZE as usize],
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn new(client_addr: Vec<u8>, heart_beat: i64, iv: [u8; SALT_AND_IV_SIZE as usize]) -> Self {
|
||||
Client {
|
||||
client_sock_addr: client_addr,
|
||||
last_heart_beat: heart_beat,
|
||||
iv,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone)]
|
||||
#[readonly::make]
|
||||
pub struct Registration {
|
||||
#[readonly]
|
||||
pub net_id: String,
|
||||
#[readonly]
|
||||
pub clients: Vec<Client>,
|
||||
|
||||
pub last_heart_beat: i64,
|
||||
|
||||
#[readonly]
|
||||
pub encrypted: bool,
|
||||
#[readonly]
|
||||
pub salt: [u8; SALT_AND_IV_SIZE as usize],
|
||||
}
|
||||
|
||||
impl Registration {
|
||||
pub fn new(
|
||||
net_id: String,
|
||||
client_addr: Vec<u8>,
|
||||
encrypted: bool,
|
||||
heart_beat: i64,
|
||||
salt: Option<[u8; SALT_AND_IV_SIZE as usize]>,
|
||||
iv: Option<[u8; SALT_AND_IV_SIZE as usize]>,
|
||||
) -> Self {
|
||||
Registration {
|
||||
net_id,
|
||||
clients: vec![Client::new(
|
||||
client_addr,
|
||||
heart_beat,
|
||||
iv.unwrap_or([0; SALT_AND_IV_SIZE as usize]),
|
||||
)],
|
||||
encrypted,
|
||||
last_heart_beat: heart_beat,
|
||||
salt: salt.unwrap_or([0; SALT_AND_IV_SIZE as usize]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BatchLock {
|
||||
inner: std::sync::Mutex<bool>, // true = blocking new locks
|
||||
condvar: std::sync::Condvar,
|
||||
active_count: std::sync::atomic::AtomicUsize,
|
||||
}
|
||||
|
||||
pub struct LockGuard {
|
||||
lock: Arc<BatchLock>,
|
||||
}
|
||||
|
||||
impl BatchLock {
|
||||
pub fn new() -> Arc<Self> {
|
||||
Arc::new(BatchLock {
|
||||
inner: std::sync::Mutex::new(false),
|
||||
condvar: std::sync::Condvar::new(),
|
||||
active_count: std::sync::atomic::AtomicUsize::new(0),
|
||||
})
|
||||
}
|
||||
|
||||
// Acquire a lock (blocks if waiting for all to unlock)
|
||||
pub fn lock(self: &Arc<Self>) -> LockGuard {
|
||||
let mut blocking = self.inner.lock().unwrap();
|
||||
|
||||
// Wait while new locks are blocked
|
||||
while *blocking {
|
||||
blocking = self.condvar.wait(blocking).unwrap();
|
||||
}
|
||||
|
||||
self.active_count.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
LockGuard {
|
||||
lock: Arc::clone(self),
|
||||
}
|
||||
}
|
||||
|
||||
// Block new locks and wait for all current locks to finish
|
||||
pub fn wait_all_unlock(self: &Arc<Self>) {
|
||||
// Block new locks
|
||||
*self.inner.lock().unwrap() = true;
|
||||
|
||||
// Wait for all active locks to finish
|
||||
while self.active_count.load(Ordering::SeqCst) > 0 {
|
||||
std::thread::sleep(std::time::Duration::from_millis(1));
|
||||
}
|
||||
|
||||
// Allow new locks again
|
||||
*self.inner.lock().unwrap() = false;
|
||||
self.condvar.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for LockGuard {
|
||||
fn drop(&mut self) {
|
||||
// Automatically release lock when guard is dropped
|
||||
self.lock.active_count.fetch_sub(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
13
src/server/utils.rs
Normal file
13
src/server/utils.rs
Normal file
@ -0,0 +1,13 @@
|
||||
use pea_2_pea::*;
|
||||
pub fn send_general_error_to_client<T: std::error::Error>(
|
||||
dst: core::net::SocketAddr,
|
||||
e: T,
|
||||
socket: std::sync::Arc<std::net::UdpSocket>,
|
||||
) {
|
||||
let mut resp_buf: Box<[u8]> = vec![0; e.to_string().len() + 1].into_boxed_slice();
|
||||
|
||||
resp_buf[0] = ServerResponse::GENERAL_ERROR as u8; // set 1st byte to ERROR
|
||||
resp_buf[1..1 + e.to_string().len()].copy_from_slice(e.to_string().as_bytes()); // send error text to client
|
||||
|
||||
let _ = socket.send_to(&[ServerResponse::GENERAL_ERROR as u8], dst);
|
||||
}
|
@ -1 +1,34 @@
|
||||
use aes::Aes256;
|
||||
use cbc::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit, block_padding::Pkcs7};
|
||||
use cbc::{Decryptor, Encryptor};
|
||||
use hmac::Hmac;
|
||||
use pbkdf2::pbkdf2;
|
||||
use sha2::Sha256;
|
||||
|
||||
// they are used
|
||||
#[allow(dead_code)]
|
||||
type Aes256CbcEnc = Encryptor<Aes256>;
|
||||
#[allow(dead_code)]
|
||||
type Aes256CbcDec = Decryptor<Aes256>;
|
||||
|
||||
pub fn derive_key_from_password(password: &[u8], salt: &[u8]) -> [u8; 32] {
|
||||
let mut key = [0u8; 32];
|
||||
let _ = pbkdf2::<Hmac<Sha256>>(password, salt, 10000, &mut key);
|
||||
key
|
||||
}
|
||||
|
||||
/// Encrypt using AES-256-CBC
|
||||
pub fn encrypt(key: &[u8], iv: &[u8], data: &[u8]) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
||||
let cipher = Aes256CbcEnc::new_from_slices(key, iv)?;
|
||||
Ok(cipher.encrypt_padded_vec_mut::<Pkcs7>(data))
|
||||
}
|
||||
|
||||
/// Decrypt using AES-256-CBC
|
||||
pub fn decrypt(
|
||||
key: &[u8],
|
||||
iv: &[u8],
|
||||
ciphertext: &[u8],
|
||||
) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
||||
let cipher = Aes256CbcDec::new_from_slices(key, iv)?;
|
||||
Ok(cipher.decrypt_padded_vec_mut::<Pkcs7>(ciphertext).unwrap())
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
|
||||
pub mod crypto;
|
||||
|
Loading…
x
Reference in New Issue
Block a user