diff --git a/Cargo.lock b/Cargo.lock index 787e9f8203..d39517614d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -278,9 +278,9 @@ dependencies = [ [[package]] name = "auth-common" version = "0.1.0" -source = "git+https://gitlab.com/veloren/auth.git?rev=bffb5181a35c19ddfd33ee0b4aedba741aafb68d#bffb5181a35c19ddfd33ee0b4aedba741aafb68d" +source = "git+https://gitlab.com/veloren/auth.git?rev=f3683798bc5ea656845010f9bae11b05dd671ece#f3683798bc5ea656845010f9bae11b05dd671ece" dependencies = [ - "rand 0.7.3", + "rand 0.8.3", "serde", "uuid", ] @@ -288,15 +288,17 @@ dependencies = [ [[package]] name = "authc" version = "1.0.0" -source = "git+https://gitlab.com/veloren/auth.git?rev=bffb5181a35c19ddfd33ee0b4aedba741aafb68d#bffb5181a35c19ddfd33ee0b4aedba741aafb68d" +source = "git+https://gitlab.com/veloren/auth.git?rev=f3683798bc5ea656845010f9bae11b05dd671ece#f3683798bc5ea656845010f9bae11b05dd671ece" dependencies = [ "auth-common", "fxhash", "hex", - "reqwest", + "http", + "hyper", + "hyper-rustls", "rust-argon2", "serde", - "url", + "serde_json", "uuid", ] @@ -326,12 +328,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "base64" version = "0.13.0" @@ -447,12 +443,6 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - [[package]] name = "bytes" version = "1.0.1" @@ -721,7 +711,7 @@ version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc4369b5e4c0cddf64ad8981c0111e7df4f7078f4d6ba98fb31f2e17c4c57b7e" dependencies = [ - "bytes 1.0.1", + "bytes", "memchr", ] @@ -1066,7 +1056,7 @@ dependencies = [ "serde_derive", "serde_json", "tinytemplate", - "tokio 1.3.0", + "tokio", "walkdir 2.3.1", ] @@ -1258,6 +1248,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "ct-logs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8" +dependencies = [ + "sct", +] + [[package]] name = "daggy" version = "0.5.0" @@ -1855,7 +1854,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -2199,11 +2198,11 @@ dependencies = [ [[package]] name = "h2" -version = "0.2.7" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" +checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" dependencies = [ - "bytes 0.5.6", + "bytes", "fnv", "futures-core", "futures-sink", @@ -2211,10 +2210,9 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 0.2.25", + "tokio", "tokio-util", "tracing", - "tracing-futures", ] [[package]] @@ -2301,28 +2299,18 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ - "bytes 1.0.1", + "bytes", "fnv", "itoa", ] -[[package]] -name = "http-body" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" -dependencies = [ - "bytes 0.5.6", - "http", -] - [[package]] name = "http-body" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" dependencies = [ - "bytes 1.0.1", + "bytes", "http", ] @@ -2340,46 +2328,23 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] name = "hyper" -version = "0.13.10" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ - "bytes 0.5.6", + "bytes", "futures-channel", "futures-core", "futures-util", "h2", "http", - "http-body 0.3.1", + "http-body", "httparse", "httpdate", "itoa", "pin-project", "socket2", - "tokio 0.2.25", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" -dependencies = [ - "bytes 1.0.1", - "futures-channel", - "futures-core", - "futures-util", - "http", - "http-body 0.4.0", - "httparse", - "httpdate", - "itoa", - "pin-project", - "socket2", - "tokio 1.3.0", + "tokio", "tower-service", "tracing", "want", @@ -2387,16 +2352,17 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.21.0" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37743cc83e8ee85eacfce90f2f4102030d9ff0a95244098d781e9bee4a90abb6" +checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" dependencies = [ - "bytes 0.5.6", + "ct-logs", "futures-util", - "hyper 0.13.10", + "hyper", "log", - "rustls 0.18.1", - "tokio 0.2.25", + "rustls", + "rustls-native-certs", + "tokio", "tokio-rustls", "webpki", ] @@ -2575,12 +2541,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ipnet" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" - [[package]] name = "itertools" version = "0.9.0" @@ -2986,22 +2946,6 @@ dependencies = [ "syn 1.0.63", ] -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "minifb" version = "0.19.1" @@ -3797,12 +3741,6 @@ dependencies = [ "syn 1.0.63", ] -[[package]] -name = "pin-project-lite" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" - [[package]] name = "pin-project-lite" version = "0.2.6" @@ -3985,9 +3923,9 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df5edaa7893393e195534aefb9ace447292d9fa0afcb70e114a4de05cd0a7d81" dependencies = [ - "hyper 0.14.4", + "hyper", "prometheus", - "tokio 1.3.0", + "tokio", "tracing", ] @@ -4243,43 +4181,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "reqwest" -version = "0.10.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" -dependencies = [ - "base64 0.13.0", - "bytes 0.5.6", - "encoding_rs", - "futures-core", - "futures-util", - "http", - "http-body 0.3.1", - "hyper 0.13.10", - "hyper-rustls", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "mime_guess", - "percent-encoding", - "pin-project-lite 0.2.6", - "rustls 0.18.1", - "serde", - "serde_json", - "serde_urlencoded", - "tokio 0.2.25", - "tokio-rustls", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "webpki-roots 0.20.0", - "winreg", -] - [[package]] name = "ring" version = "0.16.20" @@ -4318,7 +4219,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "064ea8613fb712a19faf920022ec8ddf134984f100090764a4e1d768f3827f1f" dependencies = [ - "base64 0.13.0", + "base64", "bitflags", "serde", ] @@ -4335,7 +4236,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" dependencies = [ - "base64 0.13.0", + "base64", "blake2b_simd", "constant_time_eq", ] @@ -4363,11 +4264,11 @@ dependencies = [ [[package]] name = "rustls" -version = "0.18.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" +checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" dependencies = [ - "base64 0.12.3", + "base64", "log", "ring", "sct", @@ -4375,16 +4276,15 @@ dependencies = [ ] [[package]] -name = "rustls" -version = "0.19.0" +name = "rustls-native-certs" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" +checksum = "5a07b7c1885bd8ed3831c289b7870b13ef46fe0e856d288c30d9cc17d75a2092" dependencies = [ - "base64 0.13.0", - "log", - "ring", - "sct", - "webpki", + "openssl-probe", + "rustls", + "schannel", + "security-framework", ] [[package]] @@ -4456,6 +4356,16 @@ dependencies = [ "regex", ] +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi 0.3.9", +] + [[package]] name = "scoped-tls" version = "1.0.0" @@ -4506,6 +4416,29 @@ dependencies = [ "version-compare", ] +[[package]] +name = "security-framework" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" +dependencies = [ + "bitflags", + "core-foundation 0.9.1", + "core-foundation-sys 0.8.2", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" +dependencies = [ + "core-foundation-sys 0.8.2", + "libc", +] + [[package]] name = "semver" version = "0.9.0" @@ -4582,18 +4515,6 @@ dependencies = [ "syn 1.0.63", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "sha1" version = "0.6.0" @@ -5135,24 +5056,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "iovec", - "lazy_static", - "memchr", - "mio 0.6.23", - "num_cpus", - "pin-project-lite 0.1.12", - "slab", -] - [[package]] name = "tokio" version = "1.3.0" @@ -5160,13 +5063,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d56477f6ed99e10225f38f9f75f872f29b8b8bd8c0b946f63345bb144e9eeda" dependencies = [ "autocfg", - "bytes 1.0.1", + "bytes", "libc", "memchr", "mio 0.7.9", "num_cpus", "once_cell", - "pin-project-lite 0.2.6", + "pin-project-lite", "signal-hook-registry", "tokio-macros", "winapi 0.3.9", @@ -5185,13 +5088,12 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.14.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12831b255bcfa39dc0436b01e19fea231a37db570686c06ee72c423479f889a" +checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" dependencies = [ - "futures-core", - "rustls 0.18.1", - "tokio 0.2.25", + "rustls", + "tokio", "webpki", ] @@ -5202,22 +5104,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c535f53c0cfa1acace62995a8994fc9cc1f12d202420da96ff306ee24d576469" dependencies = [ "futures-core", - "pin-project-lite 0.2.6", - "tokio 1.3.0", + "pin-project-lite", + "tokio", ] [[package]] name = "tokio-util" -version = "0.3.1" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +checksum = "ec31e5cc6b46e653cf57762f36f71d5e6386391d88a72fd6db4508f8f676fb29" dependencies = [ - "bytes 0.5.6", + "bytes", "futures-core", "futures-sink", "log", - "pin-project-lite 0.1.12", - "tokio 0.2.25", + "pin-project-lite", + "tokio", ] [[package]] @@ -5242,8 +5144,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ "cfg-if 1.0.0", - "log", - "pin-project-lite 0.2.6", + "pin-project-lite", "tracing-attributes", "tracing-core", ] @@ -5279,16 +5180,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-log" version = "0.1.2" @@ -5420,15 +5311,6 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check 0.9.2", -] - [[package]] name = "unicode-bidi" version = "0.3.4" @@ -5503,17 +5385,17 @@ version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "294b85ef5dbc3670a72e82a89971608a1fcc4ed5c7c5a2895230d31a95f0569b" dependencies = [ - "base64 0.13.0", + "base64", "chunked_transfer", "cookie", "cookie_store", "log", "once_cell", "qstring", - "rustls 0.19.0", + "rustls", "url", "webpki", - "webpki-roots 0.21.0", + "webpki-roots", ] [[package]] @@ -5588,7 +5470,7 @@ dependencies = [ "num 0.4.0", "rayon", "specs", - "tokio 1.3.0", + "tokio", "tracing", "tracing-subscriber", "vek 0.14.1", @@ -5704,7 +5586,7 @@ dependencies = [ "async-trait", "bincode", "bitflags", - "bytes 1.0.1", + "bytes", "clap", "criterion", "crossbeam-channel", @@ -5717,7 +5599,7 @@ dependencies = [ "rand 0.8.3", "serde", "shellexpand", - "tokio 1.3.0", + "tokio", "tokio-stream", "tracing", "tracing-subscriber", @@ -5731,11 +5613,11 @@ dependencies = [ "async-channel", "async-trait", "bitflags", - "bytes 1.0.1", + "bytes", "criterion", "prometheus", "rand 0.8.3", - "tokio 1.3.0", + "tokio", "tracing", ] @@ -5795,7 +5677,7 @@ dependencies = [ "slab", "specs", "specs-idvs", - "tokio 1.3.0", + "tokio", "tracing", "vek 0.14.1", "veloren-common", @@ -5820,7 +5702,7 @@ dependencies = [ "serde", "signal-hook 0.3.6", "termcolor", - "tokio 1.3.0", + "tokio", "tracing", "tracing-subscriber", "tracing-tracy", @@ -5879,7 +5761,7 @@ dependencies = [ "specs", "specs-idvs", "termcolor", - "tokio 1.3.0", + "tokio", "tracing", "tracing-appender", "tracing-log", @@ -6022,8 +5904,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" dependencies = [ "cfg-if 1.0.0", - "serde", - "serde_json", "wasm-bindgen-macro", ] @@ -6454,15 +6334,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "webpki-roots" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f" -dependencies = [ - "webpki", -] - [[package]] name = "webpki-roots" version = "0.21.0" @@ -6588,15 +6459,6 @@ dependencies = [ "x11-dl", ] -[[package]] -name = "winreg" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "winres" version = "0.1.11" diff --git a/assets/voxygen/i18n/en/main.ron b/assets/voxygen/i18n/en/main.ron index 85ebd34e9e..1fb5ce3520 100644 --- a/assets/voxygen/i18n/en/main.ron +++ b/assets/voxygen/i18n/en/main.ron @@ -41,6 +41,7 @@ You can create an account over at https://veloren.net/account/."#, "main.login.server_not_found": "Server not found", "main.login.authentication_error": "Auth error on server", + "main.login.failed_auth_server_url_invalid": "Failed to connect to auth server", "main.login.server_full": "Server is full", "main.login.untrusted_auth_server": "Auth server not trusted", "main.login.outdated_client_or_server": "ServerWentMad: Probably versions are incompatible, check for updates.", diff --git a/client/Cargo.toml b/client/Cargo.toml index d801017eec..d02f90b2e6 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -27,7 +27,7 @@ rayon = "1.5" specs = { git = "https://github.com/amethyst/specs.git", rev = "5a9b71035007be0e3574f35184acac1cd4530496" } vek = { version = "=0.14.1", features = ["serde"] } hashbrown = { version = "0.9", features = ["rayon", "serde", "nightly"] } -authc = { git = "https://gitlab.com/veloren/auth.git", rev = "bffb5181a35c19ddfd33ee0b4aedba741aafb68d" } +authc = { git = "https://gitlab.com/veloren/auth.git", rev = "f3683798bc5ea656845010f9bae11b05dd671ece" } [dev-dependencies] tracing-subscriber = { version = "0.2.3", default-features = false, features = ["fmt", "chrono", "ansi", "smallvec"] } diff --git a/client/examples/chat-cli/main.rs b/client/examples/chat-cli/main.rs index 37238de590..59e4eaf997 100644 --- a/client/examples/chat-cli/main.rs +++ b/client/examples/chat-cli/main.rs @@ -62,7 +62,7 @@ fn main() { runtime .block_on(client.register(username, password, |provider| { - provider == "https://auth.veloren.net" + provider == "auth.veloren.net" })) .unwrap(); diff --git a/client/src/error.rs b/client/src/error.rs index bf7770998a..02905f585d 100644 --- a/client/src/error.rs +++ b/client/src/error.rs @@ -16,6 +16,7 @@ pub enum Error { AlreadyLoggedIn, AuthErr(String), AuthClientError(AuthClientError), + AuthServerUrlInvalid(String), AuthServerNotTrusted, Banned(String), /// Persisted character data is invalid or missing diff --git a/client/src/lib.rs b/client/src/lib.rs index 8eddf0153b..cce805a3fe 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -485,16 +485,24 @@ impl Client { mut auth_trusted: impl FnMut(&str) -> bool, ) -> Result<(), Error> { // Authentication - let token_or_username = self.server_info.auth_provider.as_ref().map(|addr| + let token_or_username = match &self.server_info.auth_provider { + Some(addr) => { // Query whether this is a trusted auth server if auth_trusted(&addr) { - Ok(authc::AuthClient::new(addr)? - .sign_in(&username, &password)? - .serialize()) + use std::str::FromStr; + match authc::Authority::from_str(&addr) { + Ok(addr) => Ok(authc::AuthClient::new(addr) + .sign_in(&username, &password) + .await? + .serialize()), + Err(_) => Err(Error::AuthServerUrlInvalid(addr.to_string())), + } } else { Err(Error::AuthServerNotTrusted) } - ).unwrap_or(Ok(username))?; + }, + None => Ok(username), + }?; self.send_msg_err(ClientRegister { token_or_username })?; diff --git a/common/net/Cargo.toml b/common/net/Cargo.toml index 8d93c07b8a..4029ecbb94 100644 --- a/common/net/Cargo.toml +++ b/common/net/Cargo.toml @@ -21,7 +21,7 @@ tracing = { version = "0.1", default-features = false } hashbrown = { version = "0.9", features = ["rayon", "serde", "nightly"] } # Auth -authc = { git = "https://gitlab.com/veloren/auth.git", rev = "bffb5181a35c19ddfd33ee0b4aedba741aafb68d" } +authc = { git = "https://gitlab.com/veloren/auth.git", rev = "f3683798bc5ea656845010f9bae11b05dd671ece" } # ECS specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control"], rev = "5a9b71035007be0e3574f35184acac1cd4530496" } diff --git a/server-cli/src/admin.rs b/server-cli/src/admin.rs index 3fcbd6b35c..281bc83ca8 100644 --- a/server-cli/src/admin.rs +++ b/server-cli/src/admin.rs @@ -1,11 +1,17 @@ +use std::sync::Arc; +use tokio::runtime::Runtime; + pub fn admin_subcommand( + runtime: Arc, sub_m: &clap::ArgMatches, server_settings: &server::Settings, editable_settings: &mut server::EditableSettings, data_dir: &std::path::Path, ) { - let login_provider = - server::login_provider::LoginProvider::new(server_settings.auth_server_address.clone()); + let login_provider = server::login_provider::LoginProvider::new( + server_settings.auth_server_address.clone(), + runtime, + ); match sub_m.subcommand() { ("add", Some(sub_m)) => { diff --git a/server-cli/src/logging.rs b/server-cli/src/logging.rs index 1814eac83a..fb26085d0f 100644 --- a/server-cli/src/logging.rs +++ b/server-cli/src/logging.rs @@ -20,6 +20,9 @@ pub fn init(basic: bool) { .add_directive("prometheus_hyper=info".parse().unwrap()) .add_directive("mio::pool=info".parse().unwrap()) .add_directive("mio::sys::windows=debug".parse().unwrap()) + .add_directive("h2=info".parse().unwrap()) + .add_directive("tokio_util=info".parse().unwrap()) + .add_directive("rustls=debug".parse().unwrap()) .add_directive("veloren_network_protocol=info".parse().unwrap()) .add_directive( "veloren_server::persistence::character=info" diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index 06d41d86eb..9d8879d02c 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -92,6 +92,13 @@ fn main() -> io::Result<()> { path }; + let runtime = Arc::new( + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap(), + ); + // Load server settings let mut server_settings = server::Settings::load(&server_data_dir); let mut editable_settings = server::EditableSettings::load(&server_data_dir); @@ -99,6 +106,7 @@ fn main() -> io::Result<()> { match matches.subcommand() { ("admin", Some(sub_m)) => { admin::admin_subcommand( + runtime, sub_m, &server_settings, &mut editable_settings, @@ -130,12 +138,6 @@ fn main() -> io::Result<()> { let server_port = &server_settings.gameserver_address.port(); let metrics_port = &server_settings.metrics_address.port(); // Create server - let runtime = Arc::new( - tokio::runtime::Builder::new_multi_thread() - .enable_all() - .build() - .unwrap(), - ); let mut server = Server::new( server_settings, editable_settings, diff --git a/server/Cargo.toml b/server/Cargo.toml index 6a93f514ff..e1ebffe37c 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -42,7 +42,7 @@ rayon = "1.5" crossbeam-channel = "0.5" prometheus = { version = "0.12", default-features = false} portpicker = { git = "https://github.com/xMAC94x/portpicker-rs", rev = "df6b37872f3586ac3b21d08b56c8ec7cd92fb172" } -authc = { git = "https://gitlab.com/veloren/auth.git", rev = "bffb5181a35c19ddfd33ee0b4aedba741aafb68d" } +authc = { git = "https://gitlab.com/veloren/auth.git", rev = "f3683798bc5ea656845010f9bae11b05dd671ece" } libsqlite3-sys = { version = "0.18", features = ["bundled"] } diesel = { version = "1.4.3", features = ["sqlite"] } diesel_migrations = "1.4.0" diff --git a/server/src/lib.rs b/server/src/lib.rs index d90ed25531..6dbe1fe629 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -179,9 +179,10 @@ impl Server { path: data_dir.to_owned(), }); state.ecs_mut().insert(EventBus::::default()); - state - .ecs_mut() - .insert(LoginProvider::new(settings.auth_server_address.clone())); + state.ecs_mut().insert(LoginProvider::new( + settings.auth_server_address.clone(), + Arc::clone(&runtime), + )); state.ecs_mut().insert(HwStats { hardware_threads: num_cpus::get() as u32, rayon_threads: num_cpus::get() as u32, @@ -222,6 +223,7 @@ impl Server { state.ecs_mut().register::(); state.ecs_mut().register::(); state.ecs_mut().register::(); + state.ecs_mut().register::(); //Alias validator let banned_words_paths = &settings.banned_words_files; diff --git a/server/src/login_provider.rs b/server/src/login_provider.rs index b6fcb98bbf..4afc4a3385 100644 --- a/server/src/login_provider.rs +++ b/server/src/login_provider.rs @@ -1,17 +1,15 @@ use crate::settings::BanRecord; use authc::{AuthClient, AuthClientError, AuthToken, Uuid}; -use common::{comp::Player, uid::UidAllocator}; use common_net::msg::RegisterError; use common_sys::plugin::memory_manager::EcsWorld; #[cfg(feature = "plugins")] use common_sys::plugin::PluginMgr; use hashbrown::{HashMap, HashSet}; -use plugin_api::{ - event::{PlayerJoinEvent, PlayerJoinResult}, - Health, -}; -use specs::{Entities, Read, ReadStorage, WriteStorage}; -use std::str::FromStr; +use plugin_api::event::{PlayerJoinEvent, PlayerJoinResult}; +use specs::Component; +use specs_idvs::IdvStorage; +use std::{str::FromStr, sync::Arc}; +use tokio::{runtime::Runtime, sync::oneshot}; use tracing::{error, info}; fn derive_uuid(username: &str) -> Uuid { @@ -25,19 +23,31 @@ fn derive_uuid(username: &str) -> Uuid { Uuid::from_slice(&state.to_be_bytes()).unwrap() } +/// derive Uuid for "singleplayer" is a pub fn +pub fn derive_singleplayer_uuid() -> Uuid { derive_uuid("singleplayer") } + +pub struct PendingLogin { + pending_r: oneshot::Receiver>, +} + +impl Component for PendingLogin { + type Storage = IdvStorage; +} + pub struct LoginProvider { + runtime: Arc, accounts: HashMap, - auth_server: Option, + auth_server: Option>, } impl LoginProvider { - pub fn new(auth_addr: Option) -> Self { - let auth_server = match auth_addr { - Some(addr) => Some(AuthClient::new(&addr).unwrap()), - None => None, - }; + pub fn new(auth_addr: Option, runtime: Arc) -> Self { + tracing::trace!(?auth_addr, "Starting LoginProvider"); + let auth_server = auth_addr + .map(|addr| Arc::new(AuthClient::new(authc::Authority::from_str(&addr).unwrap()))); Self { + runtime, accounts: HashMap::new(), auth_server, } @@ -59,99 +69,107 @@ impl LoginProvider { }; } - #[allow(clippy::too_many_arguments)] - pub fn try_login<'a>( + pub fn verify(&self, username_or_token: &str) -> PendingLogin { + let (pending_s, pending_r) = oneshot::channel(); + + match &self.auth_server { + // Token from auth server expected + Some(srv) => { + let srv = Arc::clone(srv); + let username_or_token = username_or_token.to_string(); + self.runtime.spawn(async move { + let _ = pending_s.send(Self::query(srv, &username_or_token).await); + }); + }, + // Username is expected + None => { + let username = username_or_token; + let uuid = derive_uuid(username); + let _ = pending_s.send(Ok((username.to_string(), uuid))); + }, + } + + PendingLogin { pending_r } + } + + pub fn try_login( &mut self, - username_or_token: &str, - #[cfg(feature = "plugins")] entities: &Entities<'a>, - #[cfg(feature = "plugins")] health_comp: &ReadStorage<'a, Health>, - #[cfg(feature = "plugins")] uid_comp: &ReadStorage<'a, common::uid::Uid>, - #[cfg(feature = "plugins")] player_comp: &WriteStorage<'a, Player>, - #[cfg(feature = "plugins")] uids_res: &Read<'a, UidAllocator>, + pending: &mut PendingLogin, + #[cfg(feature = "plugins")] world: &EcsWorld, #[cfg(feature = "plugins")] plugin_manager: &PluginMgr, admins: &HashSet, whitelist: &HashSet, banlist: &HashMap, - ) -> Result<(String, Uuid), RegisterError> { - self - // resolve user information - .query(username_or_token) - // if found, check name against whitelist or if user is admin - .and_then(|(username, uuid)| { - // user cannot join if they are listed on the banlist + ) -> Option> { + match pending.pending_r.try_recv() { + Ok(Err(e)) => Some(Err(e)), + Ok(Ok((username, uuid))) => { if let Some(ban_record) = banlist.get(&uuid) { // Pull reason string out of ban record and send a copy of it - return Err(RegisterError::Banned(ban_record.reason.clone())); + return Some(Err(RegisterError::Banned(ban_record.reason.clone()))); } // user can only join if he is admin, the whitelist is empty (everyone can join) // or his name is in the whitelist if !whitelist.is_empty() && !whitelist.contains(&uuid) && !admins.contains(&uuid) { - return Err(RegisterError::NotOnWhitelist); + return Some(Err(RegisterError::NotOnWhitelist)); } #[cfg(feature = "plugins")] { - - let ecs_world = EcsWorld { - entities: &entities, - health: health_comp.into(), - uid: uid_comp.into(), - player: player_comp.into(), - uid_allocator: uids_res, - }; - match plugin_manager.execute_event(&ecs_world, &PlayerJoinEvent { - player_name: username.clone(), - player_id: *uuid.as_bytes(), - }) { - Ok(e) => { - for i in e.into_iter() { - if let PlayerJoinResult::Kick(a) = i { - return Err(RegisterError::Kicked(a)); - } + match plugin_manager.execute_event(&world, &PlayerJoinEvent { + player_name: username.clone(), + player_id: *uuid.as_bytes(), + }) { + Ok(e) => { + for i in e.into_iter() { + if let PlayerJoinResult::Kick(a) = i { + return Some(Err(RegisterError::Kicked(a))); } - }, - Err(e) => { - error!("Error occured while executing `on_join`: {:?}",e); - }, - }; + } + }, + Err(e) => { + error!("Error occured while executing `on_join`: {:?}", e); + }, + }; } // add the user to self.accounts - self.login(uuid, username.clone())?; - - Ok((username, uuid)) - }) - } - - pub fn query(&mut self, username_or_token: &str) -> Result<(String, Uuid), RegisterError> { - // Based on whether auth server is provided or not we expect an username or - // token - match &self.auth_server { - // Token from auth server expected - Some(srv) => { - info!(?username_or_token, "Validating token"); - // Parse token - let token = AuthToken::from_str(username_or_token) - .map_err(|e| RegisterError::AuthError(e.to_string()))?; - // Validate token - let uuid = srv.validate(token)?; - let username = srv.uuid_to_username(uuid)?; - Ok((username, uuid)) + match self.login(uuid, username.clone()) { + Ok(()) => Some(Ok((username, uuid))), + Err(e) => Some(Err(e)), + } }, - // Username is expected - None => { - // Assume username was provided - let username = username_or_token; - let uuid = derive_uuid(username); - Ok((username.to_string(), uuid)) + Err(tokio::sync::oneshot::error::TryRecvError::Closed) => { + error!("channel got closed to early, this shouldn't happen"); + Some(Err(RegisterError::AuthError( + "Internal Error verifying".to_string(), + ))) }, + Err(tokio::sync::oneshot::error::TryRecvError::Empty) => None, } } + async fn query( + srv: Arc, + username_or_token: &str, + ) -> Result<(String, Uuid), RegisterError> { + info!(?username_or_token, "Validating token"); + // Parse token + let token = AuthToken::from_str(username_or_token) + .map_err(|e| RegisterError::AuthError(e.to_string()))?; + // Validate token + let uuid = srv.validate(token).await?; + let username = srv.uuid_to_username(uuid).await?; + Ok((username, uuid)) + } + pub fn username_to_uuid(&self, username: &str) -> Result { - self.auth_server.as_ref().map_or_else( - || Ok(derive_uuid(username)), - |auth| auth.username_to_uuid(&username), - ) + match &self.auth_server { + Some(srv) => { + //TODO: optimize + self.runtime.block_on(srv.username_to_uuid(&username)) + }, + None => Ok(derive_uuid(username)), + } } } diff --git a/server/src/settings.rs b/server/src/settings.rs index 759773b62a..f1c425f87d 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -49,7 +49,7 @@ impl Default for Settings { Self { gameserver_address: SocketAddr::from(([0; 4], 14004)), metrics_address: SocketAddr::from(([0; 4], 14005)), - auth_server_address: Some("https://auth.veloren.net".into()), + auth_server_address: Some("auth.veloren.net".into()), world_seed: DEFAULT_WORLD_SEED, server_name: "Veloren Alpha".into(), max_players: 100, @@ -202,13 +202,7 @@ impl EditableSettings { server_description: ServerDescription("Who needs friends anyway?".into()), // TODO: Let the player choose if they want to use admin commands or not admins: Admins( - std::iter::once( - // TODO: hacky - crate::login_provider::LoginProvider::new(None) - .username_to_uuid("singleplayer") - .unwrap(), - ) - .collect(), + std::iter::once(crate::login_provider::derive_singleplayer_uuid()).collect(), ), ..load } diff --git a/server/src/sys/msg/register.rs b/server/src/sys/msg/register.rs index 0b6a34bdc0..f239086b75 100644 --- a/server/src/sys/msg/register.rs +++ b/server/src/sys/msg/register.rs @@ -1,5 +1,8 @@ use crate::{ - client::Client, login_provider::LoginProvider, metrics::PlayerMetrics, EditableSettings, + client::Client, + login_provider::{LoginProvider, PendingLogin}, + metrics::PlayerMetrics, + EditableSettings, }; use common::{ comp::{Admin, Player, Stats}, @@ -13,6 +16,9 @@ use common_net::msg::{ use hashbrown::HashMap; use plugin_api::Health; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, WriteExpect, WriteStorage}; +use tracing::trace; + +use common_sys::plugin::memory_manager::EcsWorld; #[cfg(feature = "plugins")] use common_sys::plugin::PluginMgr; @@ -29,6 +35,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Uid>, ReadStorage<'a, Client>, WriteStorage<'a, Player>, + WriteStorage<'a, PendingLogin>, Read<'a, UidAllocator>, Read<'a, PluginMgr>, ReadStorage<'a, Stats>, @@ -50,6 +57,7 @@ impl<'a> System<'a> for Sys { uids, clients, mut players, + mut pending_logins, uid_allocator, plugin_mgr, stats, @@ -75,31 +83,50 @@ impl<'a> System<'a> for Sys { // List of new players to update player lists of all clients. let mut new_players = Vec::new(); + // defer auth lockup for (entity, client) in (&entities, &clients).join() { - let _ = super::try_recv_all(client, 0, |client, msg: ClientRegister| { + let _ = super::try_recv_all(client, 0, |_, msg: ClientRegister| { + trace!(?msg.token_or_username, "defer auth lockup"); + let pending = login_provider.verify(&msg.token_or_username); + let _ = pending_logins.insert(entity, pending); + Ok(()) + }); + } + + let mut finished_pending = vec![]; + for (entity, client, mut pending) in (&entities, &clients, &mut pending_logins).join() { + if let Err(e) = || -> std::result::Result<(), crate::error::Error> { + #[cfg(feature = "plugins")] + let ecs_world = EcsWorld { + entities: &entities, + health: (&health_comp).into(), + uid: (&uids).into(), + player: (&players).into(), + uid_allocator: &uid_allocator, + }; + let (username, uuid) = match login_provider.try_login( - &msg.token_or_username, + &mut pending, #[cfg(feature = "plugins")] - &entities, - #[cfg(feature = "plugins")] - &health_comp, - #[cfg(feature = "plugins")] - &uids, - #[cfg(feature = "plugins")] - &players, - #[cfg(feature = "plugins")] - &uid_allocator, + &ecs_world, #[cfg(feature = "plugins")] &plugin_mgr, &*editable_settings.admins, &*editable_settings.whitelist, &*editable_settings.banlist, ) { - Err(err) => { - client.send(ServerRegisterAnswer::Err(err))?; - return Ok(()); + None => return Ok(()), + Some(r) => { + finished_pending.push(entity); + trace!(?r, "pending login returned"); + match r { + Err(e) => { + client.send(ServerRegisterAnswer::Err(e))?; + return Ok(()); + }, + Ok((username, uuid)) => (username, uuid), + } }, - Ok((username, uuid)) => (username, uuid), }; let player = Player::new(username, uuid); @@ -133,9 +160,13 @@ impl<'a> System<'a> for Sys { // Add to list to notify all clients of the new player new_players.push(entity); } - Ok(()) - }); + }() { + tracing::trace!(?e, "failed to process register") + }; + } + for e in finished_pending { + pending_logins.remove(e); } // Handle new players. diff --git a/voxygen/src/logging.rs b/voxygen/src/logging.rs index 2266b9c0cb..e8569be402 100644 --- a/voxygen/src/logging.rs +++ b/voxygen/src/logging.rs @@ -44,6 +44,9 @@ pub fn init(settings: &Settings) -> Vec { .add_directive("gfx_device_gl=warn".parse().unwrap()) .add_directive("prometheus_hyper=warn".parse().unwrap()) .add_directive("mio::sys::windows=debug".parse().unwrap()) + .add_directive("h2=info".parse().unwrap()) + .add_directive("tokio_util=info".parse().unwrap()) + .add_directive("rustls=debug".parse().unwrap()) .add_directive("veloren_network_protocol=info".parse().unwrap()) .add_directive( "veloren_server::persistence::character=info" diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 23e894f4bb..015df0f11b 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -186,18 +186,28 @@ impl PlayState for MainMenuState { format!("{}: {}", localized_strings.get("common.error"), e) }, client::Error::AuthClientError(e) => match e { - client::AuthClientError::InvalidUrl(e) => format!( - "{}: {}", - localized_strings.get("common.fatal_error"), - e - ), // TODO: remove parentheses client::AuthClientError::RequestError(e) => format!( "{}: {}", localized_strings.get("main.login.failed_sending_request"), e ), - client::AuthClientError::ServerError(_, e) => e, + client::AuthClientError::JsonError(e) => format!( + "{}: {}", + localized_strings.get("main.login.failed_sending_request"), + e + ), + client::AuthClientError::ServerError(_, e) => { + String::from_utf8_lossy(&e).to_string() + }, + }, + client::Error::AuthServerUrlInvalid(e) => { + format!( + "{}: https://{}", + localized_strings + .get("main.login.failed_auth_server_url_invalid"), + e + ) }, }, InitError::ClientCrashed => { diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 7e1806f377..ebf13b3fae 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -526,10 +526,7 @@ impl Default for NetworkingSettings { username: "".to_string(), servers: vec!["server.veloren.net".to_string()], default_server: "server.veloren.net".to_string(), - trusted_auth_servers: ["https://auth.veloren.net"] - .iter() - .map(|s| s.to_string()) - .collect(), + trusted_auth_servers: ["auth.veloren.net"].iter().map(|s| s.to_string()).collect(), } } }