diff --git a/Cargo.lock b/Cargo.lock index c246bc5..a32ee75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,12 +125,6 @@ dependencies = [ "serde_yml", ] -[[package]] -name = "base64ct" -version = "1.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" - [[package]] name = "bindgen" version = "0.69.5" @@ -175,6 +169,12 @@ version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + [[package]] name = "cc" version = "1.2.19" @@ -275,18 +275,6 @@ dependencies = [ "cc", ] -[[package]] -name = "cms" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b77c319abfd5219629c45c34c89ba945ed3c5e49fcde9d16b6c3885f118a730" -dependencies = [ - "const-oid", - "der", - "spki", - "x509-cert", -] - [[package]] name = "colorchoice" version = "1.0.3" @@ -302,18 +290,21 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[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 = "crypto-common" version = "0.1.6" @@ -325,28 +316,10 @@ dependencies = [ ] [[package]] -name = "der" -version = "0.7.10" +name = "data-encoding" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" -dependencies = [ - "const-oid", - "der_derive", - "flagset", - "pem-rfc7468", - "zeroize", -] - -[[package]] -name = "der_derive" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8034092389675178f570469e6c3b0465d3d30b4505c294a6550db47f3c17ad18" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" [[package]] name = "digest" @@ -387,10 +360,10 @@ dependencies = [ ] [[package]] -name = "flagset" -version = "0.4.7" +name = "fnv" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7ac824320a75a52197e8f2d787f6a38b6718bb6897a35142d749af3c0e8f4fe" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fs_extra" @@ -458,6 +431,23 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "http" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + [[package]] name = "iana-time-zone" version = "0.1.63" @@ -630,29 +620,6 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "pem-rfc7468" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] - -[[package]] -name = "pkcs12" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "695b3df3d3cc1015f12d70235e35b6b79befc5fa7a9b95b951eab1dd07c9efc2" -dependencies = [ - "cms", - "const-oid", - "der", - "spki", - "x509-cert", - "zeroize", -] - [[package]] name = "ppv-lite86" version = "0.2.21" @@ -841,9 +808,9 @@ dependencies = [ "chrono", "clap", "md-5", - "pkcs12", "rand", "rustls", + "tungstenite", ] [[package]] @@ -881,22 +848,23 @@ dependencies = [ "version_check", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +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 = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - [[package]] name = "strsim" version = "0.11.1" @@ -920,6 +888,43 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tungstenite" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4793cb5e56680ecbb1d843515b23b6de9a75eb04b66643e256a396d43be33c13" +dependencies = [ + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand", + "sha1", + "thiserror", + "utf-8", +] + [[package]] name = "typenum" version = "1.18.0" @@ -938,6 +943,12 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "utf8parse" version = "0.2.2" @@ -1185,17 +1196,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "x509-cert" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1301e935010a701ae5f8655edc0ad17c44bad3ac5ce8c39185f75453b720ae94" -dependencies = [ - "const-oid", - "der", - "spki", -] - [[package]] name = "zerocopy" version = "0.8.24" diff --git a/Cargo.toml b/Cargo.toml index 892084d..ba6a1a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ md-5 = "0.10.6" rand = "0.9.0" clap = { version = "4.5.36", features = ["derive"] } rustls = "0.23.25" -pkcs12 = "=0.1.0" \ No newline at end of file +tungstenite = "0.26.2" \ No newline at end of file diff --git a/PROTOCOL.md b/PROTOCOL.md index 83655bd..2090a19 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -13,6 +13,8 @@ Client sends: ## Reading messages +### Getting message length + Client sends: - Byte `0x00` @@ -23,6 +25,8 @@ Server sends: ### Normal reading +*Firstly, process getting message length packet* + Client sends: - Byte `0x01` @@ -33,6 +37,8 @@ Server sends: ### Chunked reading +*Firstly, process getting message length packet* + Client sends: - Byte `0x02` @@ -73,4 +79,45 @@ Client sends: Server sends: - nothing if user was registered successfully -- `0x01` if the username is already taken \ No newline at end of file +- `0x01` if the username is already taken + +# WRAC Protocol + +Default port - 42666 + +Uses websocket for connections, and sends binary data only + +Totally inherits all packets except reading messages packets writed here + +## Reading messages + +### Normal reading + +~~*Firstly, process getting message length packet*~~ + +This packet is independent from getting message length packet. + +Client sends: + +- **Byte `0x00`** +- Byte `0x01` + +Server sends: + +- All messages + +### Chunked reading + +~~*Firstly, process getting message length packet*~~ + +This packet is independent from getting message length packet. + +Client sends: + +- **Byte `0x00`** +- Byte `0x02` +- Size of messages you have in ASCII (last_size) + +Server sends: + +- All new messages diff --git a/src/main.rs b/src/main.rs index 71fd3bc..97cfdba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,7 +181,7 @@ fn add_message( fn accept_stream( args: Arc, - stream: &mut (impl Read + Write), + mut stream: impl Read + Write, addr: SocketAddr, messages: Arc>>, accounts: Arc>> @@ -294,14 +294,14 @@ fn accept_stream( .append(true) .create(true) .open(accounts_file)?; - + file.write_all(&account.to_bytes())?; file.write_all(b"\n")?; file.flush()?; } println!("user registered: {name}"); - + accounts.write().unwrap().push(account); } @@ -312,7 +312,7 @@ fn run_normal_listener(messages: Arc>>, accounts: Arc>>, accounts: Arc + ssl_cert: Option, + + /// Enable WRAC + #[arg(short='w', long)] + enable_wrac: bool, } fn main() {