From 79348eaf85bc54ec04d164ed25fded3eabf2a6e9 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 29 Mar 2021 21:07:01 +0530 Subject: [PATCH] rm actor temp --- Cargo.lock | 394 ++++++++++++--------------------- Cargo.toml | 10 +- src/api/v1/mcaptcha/domains.rs | 9 +- src/api/v1/mcaptcha/mod.rs | 1 + src/api/v1/mcaptcha/pow.rs | 59 +++++ src/api/v1/mod.rs | 3 + src/data.rs | 28 +-- src/errors.rs | 9 +- src/main.rs | 2 +- 9 files changed, 235 insertions(+), 280 deletions(-) create mode 100644 src/api/v1/mcaptcha/pow.rs diff --git a/Cargo.lock b/Cargo.lock index 8d02e14e..5cbc61fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,32 +40,16 @@ dependencies = [ "tokio-util 0.3.1", ] -[[package]] -name = "actix-codec" -version = "0.4.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90673465c6187bd0829116b02be465dc0195a74d7719f76ffff0effef934a92e" -dependencies = [ - "bitflags", - "bytes 1.0.1", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.2.6", - "tokio 1.4.0", - "tokio-util 0.6.5", -] - [[package]] name = "actix-connect" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "177837a10863f15ba8d3ae3ec12fac1099099529ed20083a27fdfe247381d0dc" dependencies = [ - "actix-codec 0.3.0", + "actix-codec", "actix-rt 1.1.1", - "actix-service 1.0.6", - "actix-utils 2.0.0", + "actix-service", + "actix-utils", "derive_more", "either", "futures-util", @@ -81,13 +65,13 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "452299e87817ae5673910e53c243484ca38be3828db819b6011736fc6982e874" dependencies = [ - "actix-codec 0.3.0", + "actix-codec", "actix-connect", "actix-rt 1.1.1", - "actix-service 1.0.6", + "actix-service", "actix-threadpool", - "actix-utils 2.0.0", - "base64", + "actix-utils", + "base64 0.13.0", "bitflags", "brotli2", "bytes 0.5.6", @@ -101,7 +85,7 @@ dependencies = [ "futures-core", "futures-util", "fxhash", - "h2 0.2.7", + "h2", "http", "httparse", "indexmap", @@ -111,7 +95,7 @@ dependencies = [ "log", "mime", "percent-encoding", - "pin-project 1.0.5", + "pin-project 1.0.6", "rand 0.7.3", "regex", "serde 1.0.125", @@ -122,58 +106,13 @@ dependencies = [ "time 0.2.26", ] -[[package]] -name = "actix-http" -version = "3.0.0-beta.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a01f9e0681608afa887d4269a0857ac4226f09ba5ceda25939e8391c9da610a" -dependencies = [ - "actix-codec 0.4.0-beta.1", - "actix-rt 2.1.0", - "actix-service 2.0.0-beta.5", - "actix-tls 3.0.0-beta.4", - "actix-utils 3.0.0-beta.2", - "ahash 0.7.2", - "base64", - "bitflags", - "brotli2", - "bytes 1.0.1", - "bytestring", - "cfg-if 1.0.0", - "cookie", - "derive_more", - "encoding_rs", - "flate2", - "futures-core", - "futures-util", - "h2 0.3.2", - "http", - "httparse", - "itoa", - "language-tags", - "log", - "mime", - "once_cell", - "percent-encoding", - "pin-project 1.0.5", - "rand 0.8.3", - "regex", - "serde 1.0.125", - "serde_json", - "serde_urlencoded", - "sha-1", - "smallvec", - "time 0.2.26", - "tokio 1.4.0", -] - [[package]] name = "actix-identity" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3263fe74cf505c6f9e18209c89fbdba5569cfd3905a7e907b42aa1c85c18fae5" dependencies = [ - "actix-service 1.0.6", + "actix-service", "actix-web", "futures-util", "serde 1.0.125", @@ -191,16 +130,6 @@ dependencies = [ "syn", ] -[[package]] -name = "actix-macros" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbcb2b608f0accc2f5bcf3dd872194ce13d94ee45b571487035864cf966b04ef" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "actix-router" version = "0.2.7" @@ -220,7 +149,7 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "143fcc2912e0d1de2bcf4e2f720d2a60c28652ab4179685a1ee159e0fb3db227" dependencies = [ - "actix-macros 0.1.3", + "actix-macros", "actix-threadpool", "copyless", "futures-channel", @@ -235,7 +164,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b4e57bc1a3915e71526d128baf4323700bd1580bc676239e2298a4c5b001f18" dependencies = [ - "actix-macros 0.2.0", "futures-core", "tokio 1.4.0", ] @@ -246,10 +174,10 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45407e6e672ca24784baa667c5d32ef109ccdd8d5e0b5ebb9ef8a67f4dfb708e" dependencies = [ - "actix-codec 0.3.0", + "actix-codec", "actix-rt 1.1.1", - "actix-service 1.0.6", - "actix-utils 2.0.0", + "actix-service", + "actix-utils", "futures-channel", "futures-util", "log", @@ -270,26 +198,16 @@ dependencies = [ "pin-project 0.4.27", ] -[[package]] -name = "actix-service" -version = "2.0.0-beta.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf82340ad9f4e4caf43737fd3bbc999778a268015cdc54675f60af6240bd2b05" -dependencies = [ - "futures-core", - "pin-project-lite 0.2.6", -] - [[package]] name = "actix-testing" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47239ca38799ab74ee6a8a94d1ce857014b2ac36f242f70f3f75a66f691e791c" dependencies = [ - "actix-macros 0.1.3", + "actix-macros", "actix-rt 1.1.1", "actix-server", - "actix-service 1.0.6", + "actix-service", "log", "socket2", ] @@ -315,38 +233,21 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24789b7d7361cf5503a504ebe1c10806896f61e96eca9a7350e23001aca715fb" dependencies = [ - "actix-codec 0.3.0", - "actix-service 1.0.6", - "actix-utils 2.0.0", + "actix-codec", + "actix-service", + "actix-utils", "futures-util", ] -[[package]] -name = "actix-tls" -version = "3.0.0-beta.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b1455e3f7a26d40cfc1080b571f41e8165e5a88e937ed579f7a4b3d55b0370" -dependencies = [ - "actix-codec 0.4.0-beta.1", - "actix-rt 2.1.0", - "actix-service 2.0.0-beta.5", - "actix-utils 3.0.0-beta.2", - "derive_more", - "futures-core", - "http", - "log", - "tokio-util 0.6.5", -] - [[package]] name = "actix-utils" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e9022dec56632d1d7979e59af14f0597a28a830a9c1c7fec8b2327eb9f16b5a" dependencies = [ - "actix-codec 0.3.0", + "actix-codec", "actix-rt 1.1.1", - "actix-service 1.0.6", + "actix-service", "bitflags", "bytes 0.5.6", "either", @@ -358,40 +259,25 @@ dependencies = [ "slab", ] -[[package]] -name = "actix-utils" -version = "3.0.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458795e09a29bc5557604f9ff6f32236fd0ee457d631672e4ec8f6a0103bb292" -dependencies = [ - "actix-codec 0.4.0-beta.1", - "actix-rt 2.1.0", - "actix-service 2.0.0-beta.5", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.2.6", -] - [[package]] name = "actix-web" version = "3.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e641d4a172e7faa0862241a20ff4f1f5ab0ab7c279f00c2d4587b77483477b86" dependencies = [ - "actix-codec 0.3.0", - "actix-http 2.2.0", - "actix-macros 0.1.3", + "actix-codec", + "actix-http", + "actix-macros", "actix-router", "actix-rt 1.1.1", "actix-server", - "actix-service 1.0.6", + "actix-service", "actix-testing", "actix-threadpool", - "actix-tls 2.0.0", - "actix-utils 2.0.0", + "actix-tls", + "actix-utils", "actix-web-codegen", - "awc 2.0.3", + "awc", "bytes 0.5.6", "derive_more", "encoding_rs", @@ -401,7 +287,7 @@ dependencies = [ "fxhash", "log", "mime", - "pin-project 1.0.5", + "pin-project 1.0.6", "regex", "serde 1.0.125", "serde_json", @@ -511,17 +397,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "ahash" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f200cbb1e856866d9eade941cf3aa0c5d7dd36f74311c4273b494f4ef036957" -dependencies = [ - "getrandom 0.2.2", - "once_cell", - "version_check", -] - [[package]] name = "aho-corasick" version = "0.7.15" @@ -617,11 +492,11 @@ version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b381e490e7b0cfc37ebc54079b0413d8093ef43d14a4e4747083f7fa47a9e691" dependencies = [ - "actix-codec 0.3.0", - "actix-http 2.2.0", + "actix-codec", + "actix-http", "actix-rt 1.1.1", - "actix-service 1.0.6", - "base64", + "actix-service", + "base64 0.13.0", "bytes 0.5.6", "cfg-if 1.0.0", "derive_more", @@ -635,38 +510,18 @@ dependencies = [ "serde_urlencoded", ] -[[package]] -name = "awc" -version = "3.0.0-beta.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09aecd8728f6491a62b27454ea4b36fb7e50faf32928b0369b644e402c651f4e" -dependencies = [ - "actix-codec 0.4.0-beta.1", - "actix-http 3.0.0-beta.4", - "actix-rt 2.1.0", - "actix-service 2.0.0-beta.5", - "base64", - "bytes 1.0.1", - "cfg-if 1.0.0", - "derive_more", - "futures-core", - "itoa", - "log", - "mime", - "percent-encoding", - "pin-project-lite 0.2.6", - "rand 0.8.3", - "serde 1.0.125", - "serde_json", - "serde_urlencoded", -] - [[package]] name = "base-x" 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" @@ -780,6 +635,28 @@ dependencies = [ "bytes 1.0.1", ] +[[package]] +name = "cargo-platform" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" +dependencies = [ + "serde 1.0.125", +] + +[[package]] +name = "cargo_metadata" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714a157da7991e23d90686b9524b9e12e0407a108647f52e9328f4b3d51ac7f" +dependencies = [ + "cargo-platform", + "semver 0.11.0", + "semver-parser 0.10.2", + "serde 1.0.125", + "serde_json", +] + [[package]] name = "cc" version = "1.0.67" @@ -825,9 +702,9 @@ dependencies = [ [[package]] name = "const_fn" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" +checksum = "076a6803b0dacd6a88cfe64deba628b01533ff5ef265687e6938280c1afd0a28" [[package]] name = "constant_time_eq" @@ -848,7 +725,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" dependencies = [ "aes-gcm", - "base64", + "base64 0.13.0", "hkdf", "hmac", "percent-encoding", @@ -1285,13 +1162,11 @@ name = "guard" version = "0.1.0" dependencies = [ "actix", - "actix-http 2.2.0", + "actix-http", "actix-identity", "actix-rt 1.1.1", - "actix-rt 2.1.0", "actix-web", "argon2-creds", - "awc 3.0.0-beta.3", "config", "derive_builder", "derive_more", @@ -1328,25 +1203,6 @@ dependencies = [ "tracing-futures", ] -[[package]] -name = "h2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc018e188373e2777d0ef2467ebff62a08e66c3f5857b23c8fbec3018210dc00" -dependencies = [ - "bytes 1.0.1", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio 1.4.0", - "tokio-util 0.6.5", - "tracing", -] - [[package]] name = "hashbrown" version = "0.9.1" @@ -1615,7 +1471,7 @@ dependencies = [ [[package]] name = "m_captcha" version = "0.1.2" -source = "git+https://github.com/mCaptcha/mCaptcha#765ec62e4d7a4a208da81817383f2683275641a9" +source = "git+https://github.com/mCaptcha/mCaptcha#ab2f418b571f41adb2c42414fed4415761a3fa52" dependencies = [ "actix", "derive_builder", @@ -1897,6 +1753,15 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + [[package]] name = "phf" version = "0.8.0" @@ -1946,11 +1811,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" +checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6" dependencies = [ - "pin-project-internal 1.0.5", + "pin-project-internal 1.0.6", ] [[package]] @@ -1966,9 +1831,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" +checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5" dependencies = [ "proc-macro2", "quote", @@ -2251,7 +2116,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" dependencies = [ - "base64", + "base64 0.13.0", "blake2b_simd", "constant_time_eq", "crossbeam-utils", @@ -2269,16 +2134,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", ] [[package]] name = "rustls" -version = "0.19.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" +checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" dependencies = [ - "base64", + "base64 0.12.3", "log", "ring", "sct", @@ -2313,7 +2178,17 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser 0.10.2", + "serde 1.0.125", ] [[package]] @@ -2322,6 +2197,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "serde" version = "0.8.23" @@ -2474,9 +2358,9 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.5.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2739d54a2ae9fdd0f545cb4e4b5574efb95e2ec71b7f921678e246fb20dcaaf" +checksum = "e1a98f9bf17b690f026b6fec565293a995b46dfbd6293debcb654dcffd2d1b34" dependencies = [ "sqlx-core", "sqlx-macros", @@ -2484,16 +2368,16 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.5.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1cad9cae4ca8947eba1a90e8ec7d3c59e7a768e2f120dc9013b669c34a90711" +checksum = "36bb6a2ca3345a86493bc3b71eabc2c6c16a8bb1aa476cf5303bee27f67627d7" dependencies = [ "ahash 0.6.3", "atoi", - "base64", + "base64 0.13.0", "bitflags", "byteorder", - "bytes 1.0.1", + "bytes 0.5.6", "crc", "crossbeam-channel", "crossbeam-queue", @@ -2515,8 +2399,6 @@ dependencies = [ "percent-encoding", "rand 0.7.3", "rustls", - "serde 1.0.125", - "serde_json", "sha-1", "sha2", "smallvec", @@ -2524,7 +2406,6 @@ dependencies = [ "sqlx-rt", "stringprep", "thiserror", - "tokio-stream", "url", "webpki", "webpki-roots", @@ -2533,14 +2414,16 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.5.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01caee2b3935b4efe152f3262afbe51546ce3b1fc27ad61014e1b3cf5f55366e" +checksum = "2b5ada8b3b565331275ce913368565a273a74faf2a34da58c4dc010ce3286844" dependencies = [ + "cargo_metadata", "dotenv", "either", "futures", "heck", + "lazy_static", "proc-macro2", "quote", "sha2", @@ -2552,13 +2435,14 @@ dependencies = [ [[package]] name = "sqlx-rt" -version = "0.3.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ce2e16b6774c671cc183e1d202386fdf9cde1e8468c1894a7f2a63eb671c4f4" +checksum = "63fc5454c9dd7aaea3a0eeeb65ca40d06d0d8e7413a8184f7c3a3ffa5056190b" dependencies = [ - "actix-rt 2.1.0", + "actix-rt 1.1.1", + "actix-threadpool", "once_cell", - "tokio 1.4.0", + "tokio 0.2.25", "tokio-rustls", ] @@ -2675,9 +2559,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f" +checksum = "f3a1d708c221c5a612956ef9f75b37e454e88d1f7b899fbd3a18d4252012d663" dependencies = [ "proc-macro2", "quote", @@ -2816,9 +2700,11 @@ dependencies = [ "memchr", "mio 0.6.23", "mio-uds", + "num_cpus", "pin-project-lite 0.1.12", "signal-hook-registry", "slab", + "tokio-macros", "winapi 0.3.9", ] @@ -2833,7 +2719,6 @@ dependencies = [ "libc", "memchr", "mio 0.7.11", - "num_cpus", "once_cell", "parking_lot", "pin-project-lite 0.2.6", @@ -2842,25 +2727,26 @@ dependencies = [ ] [[package]] -name = "tokio-rustls" -version = "0.22.0" +name = "tokio-macros" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" +checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" dependencies = [ - "rustls", - "tokio 1.4.0", - "webpki", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "tokio-stream" -version = "0.1.5" +name = "tokio-rustls" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e177a5d8c3bf36de9ebe6d58537d8879e964332f93fb3339e43f618c81361af0" +checksum = "e12831b255bcfa39dc0436b01e19fea231a37db570686c06ee72c423479f889a" dependencies = [ "futures-core", - "pin-project-lite 0.2.6", - "tokio 1.4.0", + "rustls", + "tokio 0.2.25", + "webpki", ] [[package]] @@ -2927,7 +2813,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" dependencies = [ - "pin-project 1.0.5", + "pin-project 1.0.6", "tracing", ] @@ -2976,6 +2862,12 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + [[package]] name = "unicode-bidi" version = "0.3.4" diff --git a/Cargo.toml b/Cargo.toml index 1c526cb6..522e678e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,16 +22,15 @@ name = "tests-migrate" path = "./src/tests-migrate.rs" [dependencies] -actix-web = "3" +actix-web = "3.3.2" actix = "0.11" actix-identity = "0.3" actix-http = "2.2" -actix-rt = "2" -awc = "3.0.0-beta.3" +actix-rt = "1" futures = "0.3" -sqlx = { version = "0.5.0", features = [ "runtime-actix-rustls", "postgres" ] } +sqlx = { version = "0.4.0", features = [ "runtime-actix-rustls", "postgres" ] } argon2-creds = { version = "0.2", git = "https://github.com/realaravinth/argon2-creds", commit = "61f2d1d" } config = "0.11" @@ -54,6 +53,3 @@ lazy_static = "1.4" m_captcha = { version = "0.1.2", git = "https://github.com/mCaptcha/mCaptcha" } rand = "0.8" - -[dev-dependencies] -rt = { package = "actix-rt", version = "1"} diff --git a/src/api/v1/mcaptcha/domains.rs b/src/api/v1/mcaptcha/domains.rs index e72ae9f7..f2b965b0 100644 --- a/src/api/v1/mcaptcha/domains.rs +++ b/src/api/v1/mcaptcha/domains.rs @@ -16,8 +16,8 @@ */ use actix_identity::Identity; -use actix_web::{post, web, HttpResponse, Responder}; -use awc::Client; +use actix_web::{client::Client, post, web, HttpResponse, Responder}; +//use awc::Client; use serde::{Deserialize, Serialize}; use url::Url; @@ -163,6 +163,8 @@ pub async fn delete_domain( ) .execute(&data.db) .await?; + // TODO check running actors and delete + // if domain(api_key) matches mcaptcha actor id Ok(HttpResponse::Ok()) } @@ -246,7 +248,6 @@ mod tests { #[actix_rt::test] async fn domain_verification_works() { use crate::api::v1::tests::*; - use awc::Client; use std::sync::mpsc; use std::thread; @@ -264,7 +265,7 @@ mod tests { let (tx, rx) = mpsc::channel(); thread::spawn(move || { - rt::System::new("").block_on(server(IP, tx)); + actix_rt::System::new("").block_on(server(IP, tx)); }); let srv = rx.recv().unwrap(); diff --git a/src/api/v1/mcaptcha/mod.rs b/src/api/v1/mcaptcha/mod.rs index 355b982d..5d5f981f 100644 --- a/src/api/v1/mcaptcha/mod.rs +++ b/src/api/v1/mcaptcha/mod.rs @@ -19,6 +19,7 @@ pub mod domains; pub mod duration; pub mod levels; pub mod mcaptcha; +pub mod pow; pub use super::auth::is_authenticated; diff --git a/src/api/v1/mcaptcha/pow.rs b/src/api/v1/mcaptcha/pow.rs new file mode 100644 index 00000000..22c074c5 --- /dev/null +++ b/src/api/v1/mcaptcha/pow.rs @@ -0,0 +1,59 @@ +/* +* Copyright (C) 2021 Aravinth Manivannan +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +use actix_identity::Identity; +use actix_web::{post, web, HttpResponse, Responder}; +use serde::{Deserialize, Serialize}; + +use super::{get_random, is_authenticated}; +use crate::errors::*; +use crate::Data; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct PoWConfig { + pub name: String, + pub domain: String, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct GetConfigPayload { + pub key: String, +} + +// API keys are mcaptcha actor names + +#[post("/api/v1/mcaptcha/pow/config")] +pub async fn get_config( + payload: web::Json, + data: web::Data, + id: Identity, +) -> ServiceResult { + is_authenticated(&id)?; + + let res = sqlx::query!( + "SELECT EXISTS (SELECT 1 from mcaptcha_config WHERE key = $1)", + &payload.key, + ) + .fetch_one(&data.db) + .await?; + + if let Some(x) = res.exists { + println!("{}", x); + } + + Ok(HttpResponse::Ok()) +} diff --git a/src/api/v1/mod.rs b/src/api/v1/mod.rs index b9b70c0c..99492777 100644 --- a/src/api/v1/mod.rs +++ b/src/api/v1/mod.rs @@ -51,6 +51,9 @@ pub fn services(cfg: &mut ServiceConfig) { cfg.service(mcaptcha::duration::update_duration); cfg.service(mcaptcha::duration::get_duration); + // pow + cfg.service(mcaptcha::pow::get_config); + // meta cfg.service(meta::build_details); cfg.service(meta::health); diff --git a/src/data.rs b/src/data.rs index 2513dad2..d9d6b482 100644 --- a/src/data.rs +++ b/src/data.rs @@ -32,7 +32,7 @@ use crate::SETTINGS; pub struct Data { pub db: PgPool, pub creds: Config, - pub captcha: System, + // pub captcha: System, } impl Data { @@ -52,20 +52,20 @@ impl Data { .build() .unwrap(); - let master = Master::new(SETTINGS.pow.gc).start(); - let cache = HashCache::default().start(); - let pow = PoWConfigBuilder::default() - .salt(SETTINGS.pow.salt.clone()) - .build() - .unwrap(); + // let master = Master::new(SETTINGS.pow.gc).start(); + // let cache = HashCache::default().start(); + // let pow = PoWConfigBuilder::default() + // .salt(SETTINGS.pow.salt.clone()) + // .build() + // .unwrap(); - let captcha = SystemBuilder::default() - .master(master) - .cache(cache) - .pow(pow) - .build() - .unwrap(); + // let captcha = SystemBuilder::default() + // .master(master) + // .cache(cache) + // .pow(pow) + // .build() + // .unwrap(); - Data { creds, db, captcha } + Data { creds, db } //captcha } } } diff --git a/src/errors.rs b/src/errors.rs index dc458aea..c1c2fff7 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -18,13 +18,14 @@ use std::convert::From; use actix_web::{ + client::SendRequestError, dev::HttpResponseBuilder, error::ResponseError, http::{header, StatusCode}, HttpResponse, }; use argon2_creds::errors::CredsError; -use awc::error::SendRequestError; +//use awc::error::SendRequestError; use derive_more::{Display, Error}; use log::debug; use m_captcha::errors::CaptchaError; @@ -78,6 +79,9 @@ pub enum ServiceError { /// when the a host name is already taken #[display(fmt = "host name not available")] HostnameTaken, + /// token not found + #[display(fmt = "Token not found. Is token registered?")] + TokenNotFound, #[display(fmt = "{}", _0)] CaptchaError(CaptchaError), @@ -109,7 +113,6 @@ impl ResponseError for ServiceError { #[cfg(not(tarpaulin_include))] fn status_code(&self) -> StatusCode { - println!("{:?}", &self); match self { ServiceError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR, ServiceError::NotAnEmail => StatusCode::BAD_REQUEST, @@ -124,6 +127,7 @@ impl ResponseError for ServiceError { ServiceError::UsernameCaseMappedError => StatusCode::BAD_REQUEST, ServiceError::UsernameTaken => StatusCode::BAD_REQUEST, ServiceError::TokenNameTaken => StatusCode::BAD_REQUEST, + ServiceError::TokenNotFound => StatusCode::NOT_FOUND, ServiceError::HostnameTaken => StatusCode::BAD_REQUEST, ServiceError::ClientServerUnreachable => StatusCode::SERVICE_UNAVAILABLE, ServiceError::ChallengeCourruption => StatusCode::BAD_REQUEST, @@ -203,7 +207,6 @@ impl From for ServiceError { pub fn dup_error(e: sqlx::Error, dup_error: ServiceError) -> ServiceError { use sqlx::error::Error; use std::borrow::Cow; - println!("database error: {:?}", &e); if let Error::Database(err) = e { if err.code() == Some(Cow::from("23505")) { dup_error diff --git a/src/main.rs b/src/main.rs index 5cac4d85..2c1b9ca3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ use actix_web::{ client::Client, error::InternalError, http::StatusCode, middleware, web::JsonConfig, App, HttpServer, }; +//use awc::Client; use lazy_static::lazy_static; use log::info; @@ -59,7 +60,6 @@ async fn main() -> std::io::Result<()> { ); let data = Data::new().await; - sqlx::migrate!("./migrations/").run(&data.db).await.unwrap(); HttpServer::new(move || {