vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit 54c78cf06daff8d9cc920825b38c8d9b711edbc9
parent 303eaabeea594951c52ed92312df4a387467d91a
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Fri, 20 May 2022 20:37:32 +0200

Migrate old ws crate to tungstenite, which is async and also removes over 20 old dependencies

Diffstat:
MCargo.lock | 702+++++++++++++++++++++----------------------------------------------------------
MCargo.toml | 12++++++------
Msrc/api/core/ciphers.rs | 20++++++++++----------
Msrc/api/core/folders.rs | 6+++---
Msrc/api/core/sends.rs | 10+++++-----
Msrc/api/notifications.rs | 370++++++++++++++++++++++++++++++++++++-------------------------------------------
Msrc/config.rs | 16+++++++---------
Msrc/error.rs | 2++
8 files changed, 388 insertions(+), 750 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -32,7 +32,7 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cipher", "cpufeatures", "opaque-debug 0.3.0", @@ -82,14 +82,14 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] name = "async-compression" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8589c784ff02ac80dafc5e4116c3a2a3743ac5e0c902483518a88eec6559cf99" +checksum = "345fd392ab01f746c717b1357165b76f0b67a60192007b234058c9045fdcf695" dependencies = [ "brotli", "flate2", @@ -154,7 +154,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -171,7 +171,7 @@ checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" dependencies = [ "addr2line", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "miniz_oxide", "object", @@ -216,15 +216,6 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array 0.14.5", -] - -[[package]] -name = "block-buffer" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" @@ -282,16 +273,6 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" -dependencies = [ - "byteorder", - "iovec", -] - -[[package]] -name = "bytes" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" @@ -340,27 +321,11 @@ checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" [[package]] name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "chashmap" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff41a3c2c1e39921b9003de14bf0439c7b63a9039637c291e1a64925d8ddfa45" -dependencies = [ - "owning_ref", - "parking_lot 0.4.8", -] - -[[package]] name = "chrono" version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -371,7 +336,7 @@ dependencies = [ "num-traits", "serde", "time 0.1.43", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -431,10 +396,10 @@ dependencies = [ "aes-gcm", "base64", "hkdf", - "hmac 0.12.1", + "hmac", "percent-encoding 2.1.0", - "rand 0.8.5", - "sha2 0.10.2", + "rand", + "sha2", "subtle", "time 0.3.9", "version_check", @@ -503,7 +468,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -523,7 +488,7 @@ version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "lazy_static", ] @@ -538,16 +503,6 @@ dependencies = [ ] [[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "generic-array 0.14.5", - "subtle", -] - -[[package]] name = "ctr" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -563,7 +518,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b37feaa84e6861e00a1f5e5aa8da3ee56d605c9992d33e082786754828e20865" dependencies = [ "nix", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -607,7 +562,7 @@ version = "5.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "391b56fbd302e585b7a9494fb70e40949567b1cf9003a8e4a6041a1687c26573" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "hashbrown 0.12.1", "lock_api", ] @@ -709,15 +664,6 @@ dependencies = [ [[package]] name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array 0.14.5", -] - -[[package]] -name = "digest" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" @@ -744,7 +690,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", "redox_users", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -790,7 +736,7 @@ version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -859,7 +805,7 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crc32fast", "libc", "miniz_oxide", @@ -897,28 +843,6 @@ dependencies = [ ] [[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - -[[package]] name = "futures" version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1023,7 +947,7 @@ dependencies = [ "libc", "log", "rustversion", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1047,22 +971,11 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - -[[package]] -name = "getrandom" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi 0.10.2+wasi-snapshot-preview1", ] @@ -1102,8 +1015,8 @@ dependencies = [ "nonzero_ext", "parking_lot 0.12.0", "quanta", - "rand 0.8.5", - "smallvec 1.8.0", + "rand", + "smallvec", ] [[package]] @@ -1112,7 +1025,7 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" dependencies = [ - "bytes 1.1.0", + "bytes", "fnv", "futures-core", "futures-sink", @@ -1121,7 +1034,7 @@ dependencies = [ "indexmap", "slab", "tokio", - "tokio-util 0.7.1", + "tokio-util 0.7.2", "tracing", ] @@ -1133,16 +1046,16 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "handlebars" -version = "4.2.2" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d6a30320f094710245150395bc763ad23128d6a1ebbad7594dc4164b62c56b" +checksum = "d113a9853e5accd30f43003560b5563ffbb007e3f325e8b103fa0d0029c6e6df" dependencies = [ "log", "pest", "pest_derive", - "quick-error 2.0.1", "serde", "serde_json", + "thiserror", "walkdir", ] @@ -1179,17 +1092,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" dependencies = [ - "hmac 0.12.1", -] - -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac", - "digest 0.9.0", + "hmac", ] [[package]] @@ -1209,7 +1112,7 @@ checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" dependencies = [ "libc", "match_cfg", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1227,7 +1130,7 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" dependencies = [ - "bytes 1.1.0", + "bytes", "fnv", "itoa", ] @@ -1238,7 +1141,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" dependencies = [ - "bytes 1.1.0", + "bytes", "http", "pin-project-lite", ] @@ -1261,7 +1164,7 @@ version = "0.14.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" dependencies = [ - "bytes 1.1.0", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -1285,7 +1188,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes 1.1.0", + "bytes", "hyper", "native-tls", "tokio", @@ -1343,16 +1246,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", + "cfg-if", ] [[package]] @@ -1363,7 +1257,7 @@ checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" dependencies = [ "socket2 0.3.19", "widestring", - "winapi 0.3.9", + "winapi", "winreg 0.6.2", ] @@ -1375,9 +1269,9 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itoa" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "jetscii" @@ -1419,28 +1313,12 @@ dependencies = [ ] [[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - -[[package]] name = "lettre" version = "0.10.0-rc.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1465,9 +1343,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.125" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libmimalloc-sys" @@ -1511,16 +1389,16 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] name = "loom" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc5c7d328e32cc4954e8e01193d7f0ef5ab257b5090b70a964e099a36034309" +checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "generator", "scoped-tls", "serde", @@ -1575,12 +1453,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - -[[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1639,25 +1511,6 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "mio" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" @@ -1669,36 +1522,12 @@ dependencies = [ ] [[package]] -name = "mio-extras" -version = "2.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" -dependencies = [ - "lazycell", - "log", - "mio 0.6.23", - "slab", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - -[[package]] name = "multer" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f8f35e687561d5c1667590911e6698a8cb714a134a7505718a182e7bc9d3836" dependencies = [ - "bytes 1.1.0", + "bytes", "encoding_rs", "futures-util", "http", @@ -1708,7 +1537,7 @@ dependencies = [ "mime", "spin 0.9.3", "tokio", - "tokio-util 0.6.9", + "tokio-util 0.6.10", "version_check", ] @@ -1741,24 +1570,13 @@ dependencies = [ ] [[package]] -name = "net2" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - -[[package]] name = "nix" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9" dependencies = [ "bitflags", - "cfg-if 1.0.0", + "cfg-if", "libc", ] @@ -1855,9 +1673,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" +checksum = "7b10983b38c53aebdf33f542c6275b0f58a238129d00c4ae0e6fb59738d783ca" [[package]] name = "opaque-debug" @@ -1878,7 +1696,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" dependencies = [ "bitflags", - "cfg-if 1.0.0", + "cfg-if", "foreign-types", "libc", "once_cell", @@ -1905,9 +1723,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "111.18.0+1.1.1n" +version = "111.20.0+1.1.1o" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7897a926e1e8d00219127dc020130eca4292e5ca666dd592480d72c3eca2ff6c" +checksum = "92892c4f87d56e376e469ace79f1128fdaded07646ddf73aa0be4706ff712dec" dependencies = [ "cc", ] @@ -1927,43 +1745,6 @@ dependencies = [ ] [[package]] -name = "owning_ref" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" -dependencies = [ - "stable_deref_trait", -] - -[[package]] -name = "parity-ws" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5983d3929ad50f12c3eb9a6743f19d691866ecd44da74c0a3308c3f8a56df0c6" -dependencies = [ - "byteorder", - "bytes 0.4.12", - "httparse", - "log", - "mio 0.6.23", - "mio-extras", - "rand 0.7.3", - "sha-1 0.8.2", - "slab", - "url 2.2.2", -] - -[[package]] -name = "parking_lot" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e" -dependencies = [ - "owning_ref", - "parking_lot_core 0.2.14", -] - -[[package]] name = "parking_lot" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1986,28 +1767,16 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" -dependencies = [ - "libc", - "rand 0.4.6", - "smallvec 0.6.14", - "winapi 0.3.9", -] - -[[package]] -name = "parking_lot_core" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "instant", "libc", "redox_syscall", - "smallvec 1.8.0", - "winapi 0.3.9", + "smallvec", + "winapi", ] [[package]] @@ -2016,10 +1785,10 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall", - "smallvec 1.8.0", + "smallvec", "windows-sys", ] @@ -2151,7 +1920,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ "phf_shared", - "rand 0.8.5", + "rand", ] [[package]] @@ -2194,7 +1963,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "opaque-debug 0.3.0", "universal-hash", @@ -2223,11 +1992,11 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9027b48e9d4c9175fa2218adf3557f91c1137021739951d4932f5f8268ac48aa" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -2274,7 +2043,7 @@ dependencies = [ "raw-cpuid", "wasi 0.10.2+wasi-snapshot-preview1", "web-sys", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2284,18 +2053,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] -name = "quick-error" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" - -[[package]] name = "quickcheck" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ - "rand 0.8.5", + "rand", ] [[package]] @@ -2326,49 +2089,13 @@ dependencies = [ [[package]] name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", -] - -[[package]] -name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", ] [[package]] @@ -2378,31 +2105,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -2411,16 +2114,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.6", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] @@ -2433,15 +2127,6 @@ dependencies = [ ] [[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] name = "redox_syscall" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2456,7 +2141,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.6", + "getrandom", "redox_syscall", "thiserror", ] @@ -2483,9 +2168,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.5" +version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" dependencies = [ "aho-corasick", "memchr", @@ -2503,9 +2188,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" [[package]] name = "remove_dir_all" @@ -2513,7 +2198,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2524,7 +2209,7 @@ checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" dependencies = [ "async-compression", "base64", - "bytes 1.1.0", + "bytes", "cookie 0.15.1", "cookie_store 0.15.1", "encoding_rs", @@ -2550,7 +2235,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-socks", - "tokio-util 0.6.9", + "tokio-util 0.6.10", "trust-dns-resolver", "url 2.2.2", "wasm-bindgen", @@ -2566,7 +2251,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" dependencies = [ "hostname", - "quick-error 1.2.3", + "quick-error", ] [[package]] @@ -2581,7 +2266,7 @@ dependencies = [ "spin 0.5.2", "untrusted", "web-sys", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2616,7 +2301,7 @@ dependencies = [ "atomic", "atty", "binascii", - "bytes 1.1.0", + "bytes", "either", "figment", "futures", @@ -2627,7 +2312,7 @@ dependencies = [ "num_cpus", "parking_lot 0.12.0", "pin-project-lite", - "rand 0.8.5", + "rand", "ref-cast", "rocket_codegen", "rocket_http", @@ -2638,7 +2323,7 @@ dependencies = [ "time 0.3.9", "tokio", "tokio-stream", - "tokio-util 0.7.1", + "tokio-util 0.7.2", "ubyte", "version_check", "yansi", @@ -2681,7 +2366,7 @@ dependencies = [ "rustls", "rustls-pemfile", "serde", - "smallvec 1.8.0", + "smallvec", "stable-pattern", "state", "time 0.3.9", @@ -2707,9 +2392,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.4" +version = "0.20.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbfeb8d0ddb84706bc597a5574ab8912817c52a397f819e5b614e2265206921" +checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" dependencies = [ "log", "ring", @@ -2734,9 +2419,9 @@ checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" [[package]] name = "same-file" @@ -2749,12 +2434,12 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "winapi 0.3.9", + "windows-sys", ] [[package]] @@ -2893,15 +2578,13 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.8" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", - "digest 0.9.0", - "opaque-debug 0.3.0", + "digest 0.10.3", ] [[package]] @@ -2919,7 +2602,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest 0.10.3", ] @@ -2932,24 +2615,11 @@ checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" [[package]] name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.9.0", - "opaque-debug 0.3.0", -] - -[[package]] -name = "sha2" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest 0.10.3", ] @@ -2998,15 +2668,6 @@ checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" [[package]] name = "smallvec" -version = "0.6.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" -dependencies = [ - "maybe-uninit", -] - -[[package]] -name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" @@ -3017,9 +2678,9 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3029,7 +2690,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3054,12 +2715,6 @@ dependencies = [ ] [[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - -[[package]] name = "standback" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3140,13 +2795,13 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.93" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04066589568b72ec65f42d65a1a52436e954b168773148893c020269563decf2" +checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -3168,12 +2823,12 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "fastrand", "libc", "redox_syscall", "remove_dir_all", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3221,7 +2876,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3236,7 +2891,7 @@ dependencies = [ "stdweb", "time-macros 0.1.1", "version_check", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3302,10 +2957,10 @@ version = "1.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395" dependencies = [ - "bytes 1.1.0", + "bytes", "libc", "memchr", - "mio 0.8.3", + "mio", "num_cpus", "once_cell", "parking_lot 0.12.0", @@ -3313,7 +2968,7 @@ dependencies = [ "signal-hook-registry", "socket2 0.4.4", "tokio-macros", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3372,12 +3027,24 @@ dependencies = [ ] [[package]] +name = "tokio-tungstenite" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06cda1232a49558c46f8a504d5b93101d42c0bf7f911f12a105ba48168f821ae" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + +[[package]] name = "tokio-util" -version = "0.6.9" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" +checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" dependencies = [ - "bytes 1.1.0", + "bytes", "futures-core", "futures-sink", "log", @@ -3387,11 +3054,11 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" +checksum = "f988a1a1adc2fb21f9c12aa96441da33a1728193ae0b95d2be22dbd17fcb4e5c" dependencies = [ - "bytes 1.1.0", + "bytes", "futures-core", "futures-sink", "pin-project-lite", @@ -3410,14 +3077,14 @@ dependencies = [ [[package]] name = "totp-lite" -version = "1.0.3" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b18009e8be74bfb2e2cc59a63d078d95c042858a1ca1128a294e1f9ce225148b" +checksum = "5cc496875d9c8fe9a0ce19e3ee8e8808c60376831a439543f0aac71c9dd129fa" dependencies = [ - "digest 0.9.0", - "hmac 0.11.0", - "sha-1 0.9.8", - "sha2 0.9.9", + "digest 0.10.3", + "hmac", + "sha-1 0.10.0", + "sha2", ] [[package]] @@ -3432,7 +3099,7 @@ version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -3482,7 +3149,7 @@ dependencies = [ "matchers", "regex", "sharded-slab", - "smallvec 1.8.0", + "smallvec", "thread_local", "tracing", "tracing-core", @@ -3496,7 +3163,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca94d4e9feb6a181c690c4040d7a24ef34018d8313ac5044a61d21222ae24e31" dependencies = [ "async-trait", - "cfg-if 1.0.0", + "cfg-if", "data-encoding", "enum-as-inner", "futures-channel", @@ -3506,8 +3173,8 @@ dependencies = [ "ipnet", "lazy_static", "log", - "rand 0.8.5", - "smallvec 1.8.0", + "rand", + "smallvec", "thiserror", "tinyvec", "tokio", @@ -3520,7 +3187,7 @@ version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ecae383baad9995efaa34ce8e57d12c3f305e545887472a492b838f4b5cfb77a" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "futures-util", "ipconfig", "lazy_static", @@ -3528,7 +3195,7 @@ dependencies = [ "lru-cache", "parking_lot 0.11.2", "resolv-conf", - "smallvec 1.8.0", + "smallvec", "thiserror", "tokio", "trust-dns-proto", @@ -3541,6 +3208,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] +name = "tungstenite" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96a2dea40e7570482f28eb57afbe42d97551905da6a9400acc5c328d24004f5" +dependencies = [ + "base64", + "byteorder", + "bytes", + "http", + "httparse", + "log", + "rand", + "sha-1 0.10.0", + "thiserror", + "url 2.2.2", + "utf-8", +] + +[[package]] name = "typenum" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3548,9 +3234,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "ubyte" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42756bb9e708855de2f8a98195643dff31a97f0485d90d8467b39dc24be9e8fe" +checksum = "a58e29f263341a29bb79e14ad7fda5f63b1c7e48929bad4c685d7876b1d04e94" dependencies = [ "serde", ] @@ -3563,9 +3249,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "uncased" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0" +checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" dependencies = [ "serde", "version_check", @@ -3578,6 +3264,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] name = "unicode-normalization" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3633,12 +3325,18 @@ dependencies = [ ] [[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] name = "uuid" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8cfcd319456c4d6ea10087ed423473267e1a071f3bc0aa89f80d60997843c6f0" dependencies = [ - "getrandom 0.2.6", + "getrandom", ] [[package]] @@ -3652,14 +3350,14 @@ name = "vaultwarden" version = "1.0.0" dependencies = [ "backtrace", - "bytes 1.1.0", + "bytes", "cached", - "chashmap", "chrono", "chrono-tz", "cookie 0.16.0", "cookie_store 0.16.0", "ctrlc", + "dashmap", "data-encoding", "data-url", "diesel", @@ -3680,11 +3378,10 @@ dependencies = [ "num-traits", "once_cell", "openssl", - "parity-ws", "paste", "percent-encoding 2.1.0", "pico-args", - "rand 0.8.5", + "rand", "regex", "reqwest", "ring", @@ -3695,6 +3392,7 @@ dependencies = [ "syslog", "time 0.3.9", "tokio", + "tokio-tungstenite", "totp-lite", "tracing", "url 2.2.2", @@ -3722,7 +3420,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -3738,12 +3436,6 @@ dependencies = [ [[package]] name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[package]] -name = "wasi" version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" @@ -3760,7 +3452,7 @@ version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] @@ -3785,7 +3477,7 @@ version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -3839,7 +3531,7 @@ dependencies = [ "base64", "nom", "openssl", - "rand 0.8.5", + "rand", "serde", "serde_cbor", "serde_derive", @@ -3867,12 +3559,6 @@ checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" [[package]] name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - -[[package]] -name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" @@ -3882,12 +3568,6 @@ dependencies = [ ] [[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - -[[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3899,7 +3579,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3957,7 +3637,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3966,17 +3646,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", + "winapi", ] [[package]] @@ -3994,8 +3664,8 @@ dependencies = [ "base64", "form_urlencoded", "futures", - "hmac 0.12.1", - "rand 0.8.5", + "hmac", + "rand", "reqwest", "sha1 0.10.1", "threadpool", diff --git a/Cargo.toml b/Cargo.toml @@ -45,7 +45,7 @@ backtrace = "0.3.65" # Logging panics to logfile instead stderr only dotenvy = { version = "0.15.1", default-features = false } # Lazy initialization -once_cell = "1.10.0" +once_cell = "1.11.0" # Numerical libraries num-traits = "0.2.15" @@ -55,9 +55,9 @@ num-derive = "0.3.3" rocket = { version = "0.5.0-rc.2", features = ["tls", "json"], default-features = false } # WebSockets libraries -ws = { version = "0.11.1", package = "parity-ws" } +tokio-tungstenite = "0.17.1" rmpv = "1.0.0" # MessagePack library -chashmap = "2.2.2" # Concurrent hashmap implementation +dashmap = "5.3.3" # Concurrent hashmap implementation # Async futures futures = "0.3.21" @@ -96,7 +96,7 @@ data-encoding = "2.3.2" jsonwebtoken = "8.1.0" # TOTP library -totp-lite = "1.0.3" +totp-lite = "2.0.0" # Yubico Library yubico = { version = "0.11.0", features = ["online-tokio"], default-features = false } @@ -112,14 +112,14 @@ lettre = { version = "0.10.0-rc.7", features = ["smtp-transport", "builder", "se percent-encoding = "2.1.0" # URL encoding library used for URL's in the emails # Template library -handlebars = { version = "4.2.2", features = ["dir_source"] } +handlebars = { version = "4.3.0", features = ["dir_source"] } # HTTP client reqwest = { version = "0.11.10", features = ["stream", "json", "gzip", "brotli", "socks", "cookies", "trust-dns"] } # For favicon extraction from main website html5gum = "0.4.0" -regex = { version = "1.5.5", features = ["std", "perf", "unicode-perl"], default-features = false } +regex = { version = "1.5.6", features = ["std", "perf", "unicode-perl"], default-features = false } data-url = "0.1.1" bytes = "1.1.0" cached = "0.34.0" diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs @@ -464,7 +464,7 @@ pub async fn update_cipher_from_data( cipher.set_favorite(data.Favorite, &headers.user.uuid, conn).await?; if ut != UpdateType::None { - nt.send_cipher_update(ut, cipher, &cipher.update_users_revision(conn).await); + nt.send_cipher_update(ut, cipher, &cipher.update_users_revision(conn).await).await; } Ok(()) @@ -527,7 +527,7 @@ async fn post_ciphers_import( let mut user = headers.user; user.update_revision(&conn).await?; - nt.send_user_update(UpdateType::Vault, &user); + nt.send_user_update(UpdateType::Vault, &user).await; Ok(()) } @@ -1000,7 +1000,7 @@ async fn save_attachment( data.data.persist_to(file_path).await?; - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn).await); + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn).await).await; Ok((cipher, conn)) } @@ -1266,7 +1266,7 @@ async fn move_cipher_selected( // Move cipher cipher.move_to_folder(data.FolderId.clone(), &user_uuid, &conn).await?; - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &[user_uuid.clone()]); + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &[user_uuid.clone()]).await; } Ok(()) @@ -1313,7 +1313,7 @@ async fn delete_all( Some(user_org) => { if user_org.atype == UserOrgType::Owner { Cipher::delete_all_by_organization(&org_data.org_id, &conn).await?; - nt.send_user_update(UpdateType::Vault, &user); + nt.send_user_update(UpdateType::Vault, &user).await; Ok(()) } else { err!("You don't have permission to purge the organization vault"); @@ -1334,7 +1334,7 @@ async fn delete_all( } user.update_revision(&conn).await?; - nt.send_user_update(UpdateType::Vault, &user); + nt.send_user_update(UpdateType::Vault, &user).await; Ok(()) } } @@ -1359,10 +1359,10 @@ async fn _delete_cipher_by_uuid( if soft_delete { cipher.deleted_at = Some(Utc::now().naive_utc()); cipher.save(conn).await?; - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn).await); + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn).await).await; } else { cipher.delete(conn).await?; - nt.send_cipher_update(UpdateType::CipherDelete, &cipher, &cipher.update_users_revision(conn).await); + nt.send_cipher_update(UpdateType::CipherDelete, &cipher, &cipher.update_users_revision(conn).await).await; } Ok(()) @@ -1407,7 +1407,7 @@ async fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &DbConn, n cipher.deleted_at = None; cipher.save(conn).await?; - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn).await); + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn).await).await; Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, None, conn).await)) } @@ -1469,7 +1469,7 @@ async fn _delete_cipher_attachment_by_id( // Delete attachment attachment.delete(conn).await?; - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn).await); + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn).await).await; Ok(()) } diff --git a/src/api/core/folders.rs b/src/api/core/folders.rs @@ -50,7 +50,7 @@ async fn post_folders(data: JsonUpcase<FolderData>, headers: Headers, conn: DbCo let mut folder = Folder::new(headers.user.uuid, data.Name); folder.save(&conn).await?; - nt.send_folder_update(UpdateType::FolderCreate, &folder); + nt.send_folder_update(UpdateType::FolderCreate, &folder).await; Ok(Json(folder.to_json())) } @@ -88,7 +88,7 @@ async fn put_folder( folder.name = data.Name; folder.save(&conn).await?; - nt.send_folder_update(UpdateType::FolderUpdate, &folder); + nt.send_folder_update(UpdateType::FolderUpdate, &folder).await; Ok(Json(folder.to_json())) } @@ -112,6 +112,6 @@ async fn delete_folder(uuid: String, headers: Headers, conn: DbConn, nt: Notify< // Delete the actual folder entry folder.delete(&conn).await?; - nt.send_folder_update(UpdateType::FolderDelete, &folder); + nt.send_folder_update(UpdateType::FolderDelete, &folder).await; Ok(()) } diff --git a/src/api/core/sends.rs b/src/api/core/sends.rs @@ -173,7 +173,7 @@ async fn post_send(data: JsonUpcase<SendData>, headers: Headers, conn: DbConn, n let mut send = create_send(data, headers.user.uuid).await?; send.save(&conn).await?; - nt.send_send_update(UpdateType::SyncSendCreate, &send, &send.update_users_revision(&conn).await); + nt.send_send_update(UpdateType::SyncSendCreate, &send, &send.update_users_revision(&conn).await).await; Ok(Json(send.to_json())) } @@ -237,7 +237,7 @@ async fn post_send_file(data: Form<UploadData<'_>>, headers: Headers, conn: DbCo // Save the changes in the database send.save(&conn).await?; - nt.send_send_update(UpdateType::SyncSendUpdate, &send, &send.update_users_revision(&conn).await); + nt.send_send_update(UpdateType::SyncSendUpdate, &send, &send.update_users_revision(&conn).await).await; Ok(Json(send.to_json())) } @@ -418,7 +418,7 @@ async fn put_send( } send.save(&conn).await?; - nt.send_send_update(UpdateType::SyncSendUpdate, &send, &send.update_users_revision(&conn).await); + nt.send_send_update(UpdateType::SyncSendUpdate, &send, &send.update_users_revision(&conn).await).await; Ok(Json(send.to_json())) } @@ -435,7 +435,7 @@ async fn delete_send(id: String, headers: Headers, conn: DbConn, nt: Notify<'_>) } send.delete(&conn).await?; - nt.send_send_update(UpdateType::SyncSendDelete, &send, &send.update_users_revision(&conn).await); + nt.send_send_update(UpdateType::SyncSendDelete, &send, &send.update_users_revision(&conn).await).await; Ok(()) } @@ -455,7 +455,7 @@ async fn put_remove_password(id: String, headers: Headers, conn: DbConn, nt: Not send.set_password(None); send.save(&conn).await?; - nt.send_send_update(UpdateType::SyncSendUpdate, &send, &send.update_users_revision(&conn).await); + nt.send_send_update(UpdateType::SyncSendUpdate, &send, &send.update_users_revision(&conn).await).await; Ok(Json(send.to_json())) } diff --git a/src/api/notifications.rs b/src/api/notifications.rs @@ -1,19 +1,41 @@ -use std::sync::atomic::{AtomicBool, Ordering}; +use std::{ + net::SocketAddr, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, + time::Duration, +}; -use rocket::serde::json::Json; -use rocket::Route; +use chrono::NaiveDateTime; +use futures::{SinkExt, StreamExt}; +use rmpv::Value; +use rocket::{serde::json::Json, Route}; use serde_json::Value as JsonValue; - -use crate::{api::EmptyResult, auth::Headers, Error, CONFIG}; +use tokio::{ + net::{TcpListener, TcpStream}, + sync::mpsc::Sender, +}; +use tokio_tungstenite::{ + accept_hdr_async, + tungstenite::{handshake, Message}, +}; + +use crate::{ + api::EmptyResult, + auth::Headers, + db::models::{Cipher, Folder, Send, User}, + Error, CONFIG, +}; pub fn routes() -> Vec<Route> { routes![negotiate, websockets_err] } -static SHOW_WEBSOCKETS_MSG: AtomicBool = AtomicBool::new(true); - #[get("/hub")] fn websockets_err() -> EmptyResult { + static SHOW_WEBSOCKETS_MSG: AtomicBool = AtomicBool::new(true); + if CONFIG.websocket_enabled() && SHOW_WEBSOCKETS_MSG.compare_exchange(true, false, Ordering::Relaxed, Ordering::Relaxed).is_ok() { @@ -55,19 +77,6 @@ fn negotiate(_headers: Headers) -> Json<JsonValue> { // // Websockets server // -use std::io; -use std::sync::Arc; -use std::thread; - -use ws::{self, util::Token, Factory, Handler, Handshake, Message, Sender}; - -use chashmap::CHashMap; -use chrono::NaiveDateTime; -use serde_json::from_str; - -use crate::db::models::{Cipher, Folder, Send, User}; - -use rmpv::Value; fn serialize(val: Value) -> Vec<u8> { use rmpv::encode::write_value; @@ -118,192 +127,49 @@ fn convert_option<T: Into<Value>>(option: Option<T>) -> Value { } } -// Server WebSocket handler -pub struct WsHandler { - out: Sender, - user_uuid: Option<String>, - users: WebSocketUsers, -} - const RECORD_SEPARATOR: u8 = 0x1e; const INITIAL_RESPONSE: [u8; 3] = [0x7b, 0x7d, RECORD_SEPARATOR]; // {, }, <RS> -#[derive(Deserialize)] -struct InitialMessage { - protocol: String, +#[derive(Deserialize, Copy, Clone, Eq, PartialEq)] +struct InitialMessage<'a> { + protocol: &'a str, version: i32, } -const PING_MS: u64 = 15_000; -const PING: Token = Token(1); - -const ACCESS_TOKEN_KEY: &str = "access_token="; - -impl WsHandler { - fn err(&self, msg: &'static str) -> ws::Result<()> { - self.out.close(ws::CloseCode::Invalid)?; - - // We need to specifically return an IO error so ws closes the connection - let io_error = io::Error::from(io::ErrorKind::InvalidData); - Err(ws::Error::new(ws::ErrorKind::Io(io_error), msg)) - } - - fn get_request_token(&self, hs: Handshake) -> Option<String> { - use std::str::from_utf8; - - // Verify we have a token header - if let Some(header_value) = hs.request.header("Authorization") { - if let Ok(converted) = from_utf8(header_value) { - if let Some(token_part) = converted.split("Bearer ").nth(1) { - return Some(token_part.into()); - } - } - }; - - // Otherwise verify the query parameter value - let path = hs.request.resource(); - if let Some(params) = path.split('?').nth(1) { - let params_iter = params.split('&').take(1); - for val in params_iter { - if let Some(stripped) = val.strip_prefix(ACCESS_TOKEN_KEY) { - return Some(stripped.into()); - } - } - }; - - None - } -} - -impl Handler for WsHandler { - fn on_open(&mut self, hs: Handshake) -> ws::Result<()> { - // Path == "/notifications/hub?id=<id>==&access_token=<access_token>" - // - // We don't use `id`, and as of around 2020-03-25, the official clients - // no longer seem to pass `id` (only `access_token`). - - // Get user token from header or query parameter - let access_token = match self.get_request_token(hs) { - Some(token) => token, - _ => return self.err("Missing access token"), - }; - - // Validate the user - use crate::auth; - let claims = match auth::decode_login(access_token.as_str()) { - Ok(claims) => claims, - Err(_) => return self.err("Invalid access token provided"), - }; - - // Assign the user to the handler - let user_uuid = claims.sub; - self.user_uuid = Some(user_uuid.clone()); - - // Add the current Sender to the user list - let handler_insert = self.out.clone(); - let handler_update = self.out.clone(); - - self.users.map.upsert(user_uuid, || vec![handler_insert], |ref mut v| v.push(handler_update)); - - // Schedule a ping to keep the connection alive - self.out.timeout(PING_MS, PING) - } - - fn on_message(&mut self, msg: Message) -> ws::Result<()> { - if let Message::Text(text) = msg.clone() { - let json = &text[..text.len() - 1]; // Remove last char - - if let Ok(InitialMessage { - protocol, - version, - }) = from_str::<InitialMessage>(json) - { - if &protocol == "messagepack" && version == 1 { - return self.out.send(&INITIAL_RESPONSE[..]); // Respond to initial message - } - } - } - - // If it's not the initial message, just echo the message - self.out.send(msg) - } - - fn on_timeout(&mut self, event: Token) -> ws::Result<()> { - if event == PING { - // send ping - self.out.send(create_ping())?; - - // reschedule the timeout - self.out.timeout(PING_MS, PING) - } else { - Ok(()) - } - } -} - -struct WsFactory { - pub users: WebSocketUsers, -} - -impl WsFactory { - pub fn init() -> Self { - WsFactory { - users: WebSocketUsers { - map: Arc::new(CHashMap::new()), - }, - } - } -} - -impl Factory for WsFactory { - type Handler = WsHandler; - - fn connection_made(&mut self, out: Sender) -> Self::Handler { - WsHandler { - out, - user_uuid: None, - users: self.users.clone(), - } - } - - fn connection_lost(&mut self, handler: Self::Handler) { - // Remove handler - if let Some(user_uuid) = &handler.user_uuid { - if let Some(mut user_conn) = self.users.map.get_mut(user_uuid) { - if let Some(pos) = user_conn.iter().position(|x| x == &handler.out) { - user_conn.remove(pos); - } - } - } - } -} +static INITIAL_MESSAGE: InitialMessage<'static> = InitialMessage { + protocol: "messagepack", + version: 1, +}; +// We attach the UUID to the sender so we can differentiate them when we need to remove them from the Vec +type UserSenders = (uuid::Uuid, Sender<Message>); #[derive(Clone)] pub struct WebSocketUsers { - map: Arc<CHashMap<String, Vec<Sender>>>, + map: Arc<dashmap::DashMap<String, Vec<UserSenders>>>, } impl WebSocketUsers { - fn send_update(&self, user_uuid: &str, data: &[u8]) -> ws::Result<()> { - if let Some(user) = self.map.get(user_uuid) { - for sender in user.iter() { - sender.send(data)?; + async fn send_update(&self, user_uuid: &str, data: &[u8]) { + if let Some(user) = self.map.get(user_uuid).map(|v| v.clone()) { + for (_, sender) in user.iter() { + if sender.send(Message::binary(data)).await.is_err() { + // TODO: Delete from map here too? + } } } - Ok(()) } // NOTE: The last modified date needs to be updated before calling these methods - pub fn send_user_update(&self, ut: UpdateType, user: &User) { + pub async fn send_user_update(&self, ut: UpdateType, user: &User) { let data = create_update( vec![("UserId".into(), user.uuid.clone().into()), ("Date".into(), serialize_date(user.updated_at))], ut, ); - self.send_update(&user.uuid, &data).ok(); + self.send_update(&user.uuid, &data).await; } - pub fn send_folder_update(&self, ut: UpdateType, folder: &Folder) { + pub async fn send_folder_update(&self, ut: UpdateType, folder: &Folder) { let data = create_update( vec![ ("Id".into(), folder.uuid.clone().into()), @@ -313,10 +179,10 @@ impl WebSocketUsers { ut, ); - self.send_update(&folder.user_uuid, &data).ok(); + self.send_update(&folder.user_uuid, &data).await; } - pub fn send_cipher_update(&self, ut: UpdateType, cipher: &Cipher, user_uuids: &[String]) { + pub async fn send_cipher_update(&self, ut: UpdateType, cipher: &Cipher, user_uuids: &[String]) { let user_uuid = convert_option(cipher.user_uuid.clone()); let org_uuid = convert_option(cipher.organization_uuid.clone()); @@ -332,11 +198,11 @@ impl WebSocketUsers { ); for uuid in user_uuids { - self.send_update(uuid, &data).ok(); + self.send_update(uuid, &data).await; } } - pub fn send_send_update(&self, ut: UpdateType, send: &Send, user_uuids: &[String]) { + pub async fn send_send_update(&self, ut: UpdateType, send: &Send, user_uuids: &[String]) { let user_uuid = convert_option(send.user_uuid.clone()); let data = create_update( @@ -349,7 +215,7 @@ impl WebSocketUsers { ); for uuid in user_uuids { - self.send_update(uuid, &data).ok(); + self.send_update(uuid, &data).await; } } } @@ -416,27 +282,129 @@ pub enum UpdateType { None = 100, } -use rocket::State; -pub type Notify<'a> = &'a State<WebSocketUsers>; +pub type Notify<'a> = &'a rocket::State<WebSocketUsers>; pub fn start_notification_server() -> WebSocketUsers { - let factory = WsFactory::init(); - let users = factory.users.clone(); + let users = WebSocketUsers { + map: Arc::new(dashmap::DashMap::new()), + }; if CONFIG.websocket_enabled() { - thread::spawn(move || { - let mut settings = ws::Settings::default(); - settings.max_connections = 500; - settings.queue_size = 2; - settings.panic_on_internal = false; - - let ws = ws::Builder::new().with_settings(settings).build(factory).unwrap(); - CONFIG.set_ws_shutdown_handle(ws.broadcaster()); - ws.listen((CONFIG.websocket_address().as_str(), CONFIG.websocket_port())).unwrap(); + let users2 = users.clone(); + tokio::spawn(async move { + let addr = (CONFIG.websocket_address(), CONFIG.websocket_port()); + let listener = TcpListener::bind(addr).await.expect("Can't listen on websocket port"); + + let (shutdown_tx, mut shutdown_rx) = tokio::sync::oneshot::channel::<()>(); + CONFIG.set_ws_shutdown_handle(shutdown_tx); + + loop { + tokio::select! { + Ok((stream, addr)) = listener.accept() => { + tokio::spawn(handle_connection(stream, users2.clone(), addr)); + } + + _ = &mut shutdown_rx => { + break; + } + } + } - warn!("WS Server stopped!"); + info!("Shutting down WebSockets server!") }); } users } + +async fn handle_connection(stream: TcpStream, users: WebSocketUsers, _addr: SocketAddr) -> Result<(), Error> { + let mut user_uuid: Option<String> = None; + + // Accept connection, do initial handshake, validate auth token and get the user ID + use handshake::server::{Request, Response}; + let mut stream = accept_hdr_async(stream, |req: &Request, res: Response| { + if let Some(token) = get_request_token(req) { + if let Ok(claims) = crate::auth::decode_login(&token) { + user_uuid = Some(claims.sub); + return Ok(res); + } + } + Err(Response::builder().status(401).body(None).unwrap()) + }) + .await?; + + let user_uuid = user_uuid.expect("User UUID should be set after the handshake"); + + // Add a channel to send messages to this client to the map + let entry_uuid = uuid::Uuid::new_v4(); + let (tx, mut rx) = tokio::sync::mpsc::channel(100); + users.map.entry(user_uuid.clone()).or_default().push((entry_uuid, tx)); + + let mut interval = tokio::time::interval(Duration::from_secs(15)); + loop { + tokio::select! { + res = stream.next() => { + match res { + Some(Ok(message)) => { + // We should receive an initial message with the protocol and version, and we will reply to it + if let Message::Text(ref message) = message { + let msg = message.strip_suffix('\u{1e}').unwrap_or(message); + + if serde_json::from_str(msg).ok() == Some(INITIAL_MESSAGE) { + stream.send(Message::binary(INITIAL_RESPONSE)).await?; + continue; + } + } + + // Just echo anything else the client sends + if stream.send(message).await.is_err() { + break; + } + } + _ => break, + } + } + + res = rx.recv() => { + match res { + Some(res) => { + if stream.send(res).await.is_err() { + break; + } + }, + None => break, + } + } + + _= interval.tick() => { + if stream.send(Message::Binary(create_ping())).await.is_err() { + break; + } + } + } + } + + // Delete from map + users.map.entry(user_uuid).or_default().retain(|(uuid, _)| uuid != &entry_uuid); + Ok(()) +} + +fn get_request_token(req: &handshake::server::Request) -> Option<String> { + const ACCESS_TOKEN_KEY: &str = "access_token="; + + if let Some(Ok(auth)) = req.headers().get("Authorization").map(|a| a.to_str()) { + if let Some(token_part) = auth.strip_prefix("Bearer ") { + return Some(token_part.to_owned()); + } + } + + if let Some(params) = req.uri().query() { + let params_iter = params.split('&').take(1); + for val in params_iter { + if let Some(stripped) = val.strip_prefix(ACCESS_TOKEN_KEY) { + return Some(stripped.to_owned()); + } + } + } + None +} diff --git a/src/config.rs b/src/config.rs @@ -37,7 +37,7 @@ macro_rules! make_config { struct Inner { rocket_shutdown_handle: Option<rocket::Shutdown>, - ws_shutdown_handle: Option<ws::Sender>, + ws_shutdown_handle: Option<tokio::sync::oneshot::Sender<()>>, templates: Handlebars<'static>, config: ConfigItems, @@ -948,19 +948,17 @@ impl Config { self.inner.write().unwrap().rocket_shutdown_handle = Some(handle); } - pub fn set_ws_shutdown_handle(&self, handle: ws::Sender) { + pub fn set_ws_shutdown_handle(&self, handle: tokio::sync::oneshot::Sender<()>) { self.inner.write().unwrap().ws_shutdown_handle = Some(handle); } pub fn shutdown(&self) { - if let Ok(c) = self.inner.read() { - if let Some(handle) = c.ws_shutdown_handle.clone() { - handle.shutdown().ok(); + if let Ok(mut c) = self.inner.write() { + if let Some(handle) = c.ws_shutdown_handle.take() { + handle.send(()).ok(); } - // Wait a bit before stopping the web server - tokio::runtime::Handle::current() - .block_on(async move { tokio::time::sleep(tokio::time::Duration::from_secs(1)).await }); - if let Some(handle) = c.rocket_shutdown_handle.clone() { + + if let Some(handle) = c.rocket_shutdown_handle.take() { handle.notify(); } } diff --git a/src/error.rs b/src/error.rs @@ -49,6 +49,7 @@ use rocket::error::Error as RocketErr; use serde_json::{Error as SerdeErr, Value}; use std::io::Error as IoErr; use std::time::SystemTimeError as TimeErr; +use tokio_tungstenite::tungstenite::Error as TungstError; use webauthn_rs::error::WebauthnError as WebauthnErr; use yubico::yubicoerror::YubicoError as YubiErr; @@ -88,6 +89,7 @@ make_error! { DieselCon(DieselConErr): _has_source, _api_error, DieselMig(DieselMigErr): _has_source, _api_error, Webauthn(WebauthnErr): _has_source, _api_error, + WebSocket(TungstError): _has_source, _api_error, } impl std::fmt::Debug for Error {