diff --git a/Cargo.lock b/Cargo.lock index f896643..b4e4710 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "anyhow" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" + [[package]] name = "async-attributes" version = "1.1.2" @@ -140,18 +146,56 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64ct" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2b2456fd614d856680dcd9fcc660a51a820fa09daef2e49772b56a193c8474" + +[[package]] +name = "binstring" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e0d60973d9320722cb1206f412740e162a33b8547ea8d6be75d7cff237c7a85" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + [[package]] name = "blocking" version = "1.2.0" @@ -172,6 +216,12 @@ version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.2.1" @@ -196,6 +246,57 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "3.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "coarsetime" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "454038500439e141804c655b4cd1bc6a70bcb95cd2bc9463af5661b6956f0e46" +dependencies = [ + "libc", + "once_cell", + "wasi", + "wasm-bindgen", +] + [[package]] name = "concurrent-queue" version = "1.2.4" @@ -206,15 +307,82 @@ dependencies = [ ] [[package]] -name = "crossbeam-utils" -version = "0.8.11" +name = "configparser" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "5458d9d1a587efaf5091602c59d299696a3877a439c8f6d461a2d3cce11df87a" +dependencies = [ + "indexmap", +] + +[[package]] +name = "const-oid" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" + +[[package]] +name = "const-oid" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "722e23542a15cea1f65d4a1419c4cfd7a26706c70871a13a04238ca3f40f1661" + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if", - "once_cell", ] +[[package]] +name = "crypto-bigint" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "crypto-bigint" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "ct-codecs" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3b7eb4404b8195a9abb6356f4ac07d8ba267045c8d6d220ac4dc992e6cc75df" + [[package]] name = "ctor" version = "0.1.23" @@ -225,6 +393,83 @@ dependencies = [ "syn", ] +[[package]] +name = "der" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" +dependencies = [ + "const-oid 0.7.1", + "crypto-bigint 0.3.2", + "pem-rfc7468 0.3.1", +] + +[[package]] +name = "der" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dd2ae565c0a381dde7fade45fce95984c568bdcb4700a4fdbe3175e0380b2f" +dependencies = [ + "const-oid 0.9.0", + "pem-rfc7468 0.6.0", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" +dependencies = [ + "der 0.6.0", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519-compact" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e18997d4604542d0736fae2c5ad6de987f0a50530cbcc14a7ce5a685328a252d" +dependencies = [ + "ct-codecs", + "getrandom", +] + +[[package]] +name = "elliptic-curve" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +dependencies = [ + "base16ct", + "crypto-bigint 0.4.9", + "der 0.6.0", + "digest", + "ff", + "generic-array", + "group", + "hkdf", + "pem-rfc7468 0.6.0", + "pkcs8 0.9.0", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -240,6 +485,16 @@ dependencies = [ "instant", ] +[[package]] +name = "ff" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df689201f395c6b90dfe87127685f8dbfc083a5e779e613575d8bd7314300c3e" +dependencies = [ + "rand_core", + "subtle", +] + [[package]] name = "futures-channel" version = "0.3.24" @@ -276,6 +531,27 @@ dependencies = [ "waker-fn", ] +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gloo-timers" version = "0.2.4" @@ -288,6 +564,29 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "group" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7391856def869c1c81063a03457c676fbcd419709c3dfb33d8d319de484b154d" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -297,6 +596,58 @@ dependencies = [ "libc", ] +[[package]] +name = "hkdf" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "hmac-sha1-compact" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d103cfecf6edf3f7d1dc7c5ab64e99488c0f8d11786e43b40873e66e8489d014" + +[[package]] +name = "hmac-sha256" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd29dbba58ee5314f3ec570066d78a3f4772bf45b322efcf2ce2a43af69a4d85" +dependencies = [ + "digest", +] + +[[package]] +name = "hmac-sha512" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a928b002dff1780b7fa21056991d395770ab9359154b8c1724c4d0511dad0a65" +dependencies = [ + "digest", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "instant" version = "0.1.12" @@ -307,10 +658,16 @@ dependencies = [ ] [[package]] -name = "js-sys" -version = "0.3.59" +name = "itoa" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -321,6 +678,44 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" +[[package]] +name = "jwt-simple" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7fe9aa2d76d0ec88af6f9c993dc369ab3a2773ffef50916dfc7453e875f336a" +dependencies = [ + "anyhow", + "binstring", + "coarsetime", + "ct-codecs", + "ed25519-compact", + "hmac-sha1-compact", + "hmac-sha256", + "hmac-sha512", + "k256", + "p256", + "p384", + "rand", + "rsa", + "serde", + "serde_json", + "spki 0.5.4", + "thiserror", + "zeroize", +] + +[[package]] +name = "k256" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sha2", +] + [[package]] name = "kv-log-macro" version = "1.0.7" @@ -335,18 +730,27 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "libc" -version = "0.2.132" +version = "0.2.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" + +[[package]] +name = "libm" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" [[package]] name = "lock_api" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -380,6 +784,54 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "566d173b2f9406afbc5510a90925d5a2cd80cae4605631f1212303df265de011" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", + "libm", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -392,9 +844,37 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" + +[[package]] +name = "os_str_bytes" +version = "6.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" + +[[package]] +name = "p256" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51f44edd08f51e2ade572f141051021c5af22677e42b7dd28a88155151c33594" +dependencies = [ + "ecdsa", + "elliptic-curve", + "sha2", +] + +[[package]] +name = "p384" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc8c5bf642dde52bb9e87c0ecd8ca5a76faac2eeed98dedb7c717997e1080aa" +dependencies = [ + "ecdsa", + "elliptic-curve", + "sha2", +] [[package]] name = "parking" @@ -425,6 +905,24 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "pem-rfc7468" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01de5d978f34aa4b2296576379fcc416034702fd94117c56ffd8a1a767cefb30" +dependencies = [ + "base64ct", +] + +[[package]] +name = "pem-rfc7468" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d159833a9105500e0398934e205e0773f0b27529557134ecfc51c27646adac" +dependencies = [ + "base64ct", +] + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -437,6 +935,38 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a78f66c04ccc83dd4486fd46c33896f4e17b24a7a3a6400dedc48ed0ddd72320" +dependencies = [ + "der 0.5.1", + "pkcs8 0.8.0", + "zeroize", +] + +[[package]] +name = "pkcs8" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" +dependencies = [ + "der 0.5.1", + "spki 0.5.4", + "zeroize", +] + +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der 0.6.0", + "spki 0.6.0", +] + [[package]] name = "polling" version = "2.3.0" @@ -452,10 +982,40 @@ dependencies = [ ] [[package]] -name = "proc-macro2" -version = "1.0.43" +name = "ppv-lite86" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] @@ -469,6 +1029,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -495,12 +1085,105 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +[[package]] +name = "rfc6979" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88c86280f057430a52f4861551b092a01b419b8eacefc7c995eacb9dc132fe32" +dependencies = [ + "crypto-bigint 0.4.9", + "hmac", + "zeroize", +] + +[[package]] +name = "rsa" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cf22754c49613d2b3b119f0e5d46e34a2c628a937e3024b8762de4e7d8c710b" +dependencies = [ + "byteorder", + "digest", + "num-bigint-dig", + "num-integer", + "num-iter", + "num-traits", + "pkcs1", + "pkcs8 0.8.0", + "rand_core", + "smallvec", + "subtle", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sec1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +dependencies = [ + "base16ct", + "der 0.6.0", + "generic-array", + "pkcs8 0.9.0", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -510,13 +1193,26 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +dependencies = [ + "digest", + "rand_core", +] + [[package]] name = "simple-auth" version = "0.1.0" dependencies = [ "async-std", "async-trait", + "clap", + "configparser", "json", + "jwt-simple", "lazy_static", "regex", "tokio", @@ -533,9 +1229,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "socket2" @@ -548,10 +1244,48 @@ dependencies = [ ] [[package]] -name = "syn" -version = "1.0.99" +name = "spin" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spki" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" +dependencies = [ + "base64ct", + "der 0.5.1", +] + +[[package]] +name = "spki" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der 0.6.0", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" dependencies = [ "proc-macro2", "quote", @@ -559,10 +1293,45 @@ dependencies = [ ] [[package]] -name = "tokio" -version = "1.21.1" +name = "termcolor" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0020c875007ad96677dcc890298f4b942882c5d4eb7cc8f439fc3bf813dc9c95" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" + +[[package]] +name = "thiserror" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio" +version = "1.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", @@ -570,7 +1339,6 @@ dependencies = [ "memchr", "mio", "num_cpus", - "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -591,10 +1359,16 @@ dependencies = [ ] [[package]] -name = "unicode-ident" -version = "1.0.3" +name = "typenum" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "value-bag" @@ -626,9 +1400,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -636,9 +1410,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -651,9 +1425,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -663,9 +1437,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -673,9 +1447,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -686,15 +1460,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -725,6 +1499,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -773,3 +1556,9 @@ name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "zeroize" +version = "1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" diff --git a/Cargo.toml b/Cargo.toml index 8dfcac0..95e5ae6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,19 @@ lazy_static = "1.4.0" regex = "1" tokio = { version = "1.21.1", features = ["full"] } async-trait = "0.1.57" +jwt-simple = "0.11.1" # useful for tests (embedded files should be delete in release ?) #rust-embed="6.4.1" +[dependencies.configparser] +version = "3.0.2" +features = ["indexmap"] + +[dependencies.clap] +version = "3.2" +features = ["derive"] + [dependencies.async-std] version = "1.6" features = ["attributes"] diff --git a/README.md b/README.md index b43427c..43810ba 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,52 @@ A little web server providing JWT token for auth auser. -**NOTE**: for now, the server is listening on port **9000**. Change it, in the src if needed. - ## Build - ```bash cargo build --release +``` -# run the server -./target/release/simple-auth +## Configuration + +### Store +The store represents the credentials. For now, this a `.txt` file with plain passwords. You have to create one like: +```txt +# acts as a comment (only on a start line) +: +``` +**WARN**: the file should have a chmod to **600**. + +### RSA key pair creation +The server uses **RS384** signature algorithm (asymmetric). You have to create a private key to sign the token and a public key for the validation: +```bash +openssl genrsa -out priv.pem 2048 +openssl rsa -in priv.pem -outform PEM -pubout -out pub.pem +``` +**WARN**: those files must be readable be the server user. + +### INI file +To start the server correctly, you need to create an `.ini` file as below: +```ini +[server] +url = : + +[store] +path = + +[jwt] +issuer = +private_key = +public_key = +expiration_time = 2 # in hours +``` + +## Run +```bash +./simple-auth + +curl http://:/get/ -d '{"username":"", "password":""}' +# should returned +{"token":"
.."} ``` ## Test diff --git a/src/http/mod.rs b/src/http/mod.rs index f9dbf7c..38d58b0 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -6,4 +6,4 @@ pub mod router; pub use request::HTTPRequest; pub use response::{HTTPResponse, HTTPStatusCode}; -pub use router::ROUTER; +pub use router::{Config, ROUTER}; diff --git a/src/http/request.rs b/src/http/request.rs index 113459f..d80471e 100644 --- a/src/http/request.rs +++ b/src/http/request.rs @@ -206,6 +206,7 @@ impl HTTPRequest { } } + #[allow(dead_code)] pub fn is_valid(&self) -> bool { return self.start_line.is_valid(); } diff --git a/src/http/response.rs b/src/http/response.rs index 0f0b436..fcf7fc0 100644 --- a/src/http/response.rs +++ b/src/http/response.rs @@ -11,6 +11,7 @@ pub enum HTTPStatusCode { Http400, Http403, Http404, + Http500, } impl Into for HTTPStatusCode { @@ -20,6 +21,7 @@ impl Into for HTTPStatusCode { Self::Http400 => "400".to_string(), Self::Http404 => "404".to_string(), Self::Http403 => "403".to_string(), + Self::Http500 => "500".to_string(), } } } @@ -51,6 +53,7 @@ impl HTTPStatusLine { self.status_code = code; } + #[allow(dead_code)] pub fn get_status_code(&self) -> HTTPStatusCode { self.status_code.clone() } @@ -89,6 +92,17 @@ impl Into for HTTPResponse { } impl HTTPResponse { + pub fn as_500() -> Self { + let mut response = Self::default(); + + response + .status_line + .set_status_code(HTTPStatusCode::Http500); + response.body = json::parse(r#"{"error": "unexpected error occurred"}"#).unwrap(); + + response + } + pub fn as_404() -> Self { let mut response = Self::default(); @@ -117,16 +131,14 @@ impl HTTPResponse { } // TODO: need to be adjust to accept `json::JsonValue` - pub fn as_200() -> Self { + pub fn as_200(token: String) -> Self { let mut response = Self::default(); response .status_line .set_status_code(HTTPStatusCode::Http200); - response.body = json::parse( - r#"{"token": "header.payload.signature", "refresh": "header.payload.signature"}"#, - ) - .unwrap(); + + response.body = json::parse(format!(r#"{{"token": "{}"}}"#, token).as_str()).unwrap(); response } diff --git a/src/http/router.rs b/src/http/router.rs index 50a61ca..c242fc7 100644 --- a/src/http/router.rs +++ b/src/http/router.rs @@ -1,28 +1,146 @@ //! router aims to handle correctly the request corresponding to the target //! it implements all the logic to build an `HTTPResponse` -use super::{HTTPRequest, HTTPResponse, HTTPStatusCode}; +use super::{HTTPRequest, HTTPResponse}; use crate::stores::FileStore; use crate::stores::Store; +use configparser::ini::Ini; +use jwt_simple::prelude::*; use lazy_static::lazy_static; use std::collections::HashMap; use std::future::Future; use std::pin::Pin; +use std::str::FromStr; type FuturePinned = Pin>>; -type Handler = fn(HTTPRequest) -> FuturePinned; +type Handler = fn(HTTPRequest, Config) -> FuturePinned; -fn handle_get(request: HTTPRequest) -> FuturePinned { +#[derive(Clone)] +pub struct Config { + jwt_exp_time: u64, + jwt_issuer: String, + jwt_priv_key: String, + jwt_pub_key: String, + filestore_path: String, +} + +impl Default for Config { + fn default() -> Self { + Config { + jwt_exp_time: 0, + jwt_issuer: "".to_string(), + jwt_priv_key: "".to_string(), + jwt_pub_key: "".to_string(), + filestore_path: "".to_string(), + } + } +} + +impl TryFrom for Config { + type Error = String; + fn try_from(config: Ini) -> Result { + let exp_time = config + .get("jwt", "expiration_time") + .unwrap_or("".to_string()); + let jwt_exp_time = { + match u64::from_str(&exp_time) { + Ok(v) => v, + Err(e) => { + eprintln!("unable to convert JWT expiration time into u64 err={}", e); + 0 + } + } + }; + let config = Config { + jwt_exp_time, + jwt_issuer: config.get("jwt", "issuer").unwrap_or("".to_string()), + jwt_pub_key: config.get("jwt", "public_key").unwrap_or("".to_string()), + jwt_priv_key: config.get("jwt", "private_key").unwrap_or("".to_string()), + filestore_path: config.get("store", "path").unwrap_or("".to_string()), + }; + + if !config.validate() { + return Err("ini file configuration validation failed".to_string()); + } + + Ok(config) + } +} + +impl Config { + /// validates config ini file + fn validate(&self) -> bool { + if self.jwt_exp_time <= 0 { + eprintln!("invalid config parameter: JWT expiration time is negative or equals to 0"); + return false; + } + + if self.jwt_issuer == "" { + eprintln!("invalid config parameter: JWT issuer is empty"); + return false; + } + + // TODO: check if the file exists and rights are ok + if self.jwt_pub_key == "" { + eprintln!("invalid config parameter: JWT public key file path is empty"); + return false; + } + + // TODO: check if the file exists and rights are ok + if self.jwt_priv_key == "" { + eprintln!("invalid config parameter: JWT private key file path is empty"); + return false; + } + + if self.filestore_path == "" { + eprintln!("invalid config parameter: filestore path is empty"); + return false; + } + + true + } +} + +fn handle_get(request: HTTPRequest, config: Config) -> FuturePinned { Box::pin(async move { - // TODO: path to `store.txt` must not be hardcoded, should be in a config file and load at runtime - let mut store = FileStore::new("tests/data/store.txt".to_string()); + let mut store = FileStore::new(config.filestore_path); match &request.body { Some(ref b) => { let is_auth = store.is_auth(&b.get_data()).await; if !is_auth { return HTTPResponse::as_403(); } - HTTPResponse::as_200() + + let priv_key_content = { + match std::fs::read_to_string(config.jwt_priv_key) { + Ok(c) => c, + Err(e) => { + eprintln!("error while reading JWT priv key content err={}", e); + "".to_string() + } + } + }; + let jwt_key = { + match RS384KeyPair::from_pem(priv_key_content.as_str()) { + Ok(k) => k, + // TODO: set error in the message body + Err(e) => { + eprintln!("error occurred while getting private key err={}", e); + return HTTPResponse::as_500(); + } + } + }; + let mut claims = Claims::create(Duration::from_hours(config.jwt_exp_time)); + claims.issuer = Some(config.jwt_issuer); + + match jwt_key.sign(claims) { + Ok(token) => HTTPResponse::as_200(token), + // TODO: set the error in the message body + Err(e) => { + eprintln!("error occurred while signing the token err={}", e); + return HTTPResponse::as_500(); + } + } } None => HTTPResponse::as_400(), } @@ -31,12 +149,12 @@ fn handle_get(request: HTTPRequest) -> FuturePinned { /// validates the token by checking: /// * expiration time -fn handle_validate(request: HTTPRequest) -> FuturePinned { +fn handle_validate(request: HTTPRequest, _config: Config) -> FuturePinned { Box::pin(async move { match &request.body { Some(ref _b) => { // TODO: impl the JWT validation - HTTPResponse::as_200() + HTTPResponse::as_200("header.payload.signature".to_string()) } None => HTTPResponse::as_400(), } @@ -59,12 +177,12 @@ lazy_static! { pub struct Router; impl Router { - pub async fn route(&self, request_str: &str) -> HTTPResponse { + pub async fn route(&self, request_str: &str, config: Config) -> HTTPResponse { let request = HTTPRequest::from(request_str); let target = request.start_line.get_target(); match HTTP_METHODS.get(target.as_str()) { - Some(f) => f(request).await, + Some(f) => f(request, config).await, None => HTTPResponse::as_404(), } } @@ -75,12 +193,59 @@ pub const ROUTER: Router = Router {}; #[tokio::test] async fn test_route() { + use super::HTTPStatusCode; + let router: &Router = &ROUTER; + let config: Config = Config::default(); let request_str = "POST /get/ HTTP/1.1\r\n\r\n"; - let response: HTTPResponse = router.route(request_str).await; + let response: HTTPResponse = router.route(request_str, config).await; assert_eq!( HTTPStatusCode::Http400, response.status_line.get_status_code() ); } + +#[test] +fn test_config() { + use std::env; + + let root_path = env::var("CARGO_MANIFEST_DIR").unwrap(); + + // TODO: path::Path should be better + let config_path = format!("{}/{}/{}/{}", root_path, "tests", "data", "config.ini"); + let mut config = Ini::new(); + let _r = config.load(config_path); + + let router_config = Config::try_from(config); + assert!(router_config.is_ok()); +} + +#[test] +fn test_bad_config() { + use std::env; + + let root_path = env::var("CARGO_MANIFEST_DIR").unwrap(); + + // TODO: path::Path should be better + let config_path = format!("{}/{}/{}/{}", root_path, "tests", "data", "bad_config.ini"); + let mut config = Ini::new(); + let _r = config.load(config_path); + + let router_config = Config::try_from(config); + assert!(router_config.is_err()); +} + +#[test] +fn test_bad_config_path() { + use std::env; + + let root_path = env::var("CARGO_MANIFEST_DIR").unwrap(); + + // TODO: path::Path should be better + let config_path = format!("{}/{}/{}/{}", root_path, "tests", "data", "con.ini"); + let mut config = Ini::new(); + + let result = config.load(config_path); + assert!(result.is_err()); +} diff --git a/src/main.rs b/src/main.rs index 5b58bda..cb91c62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,33 +1,68 @@ mod http; mod stores; +use clap::Parser; +use configparser::ini::Ini; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::{TcpListener, TcpStream}, }; -use http::ROUTER; +use http::{Config, ROUTER}; -const SERVER_URL: &str = "127.0.0.1:9000"; +#[derive(Parser)] +#[clap(author, version, about, long_about = None)] +struct Cli { + /// config filepath (.ini) + config: String, +} #[tokio::main] async fn main() { - let listener = TcpListener::bind(SERVER_URL).await.unwrap(); - println!("server is listening on '{}'", SERVER_URL); + let args = Cli::parse(); + + let mut config = Ini::new(); + match config.load(args.config) { + Ok(c) => c, + Err(e) => { + eprintln!("error while loading the config file, err={}", e); + std::process::exit(1); + } + }; + + let server_url = config.get("server", "url").unwrap_or("".to_string()); + let listener = { + match TcpListener::bind(&server_url).await { + Ok(t) => { + println!("server is listening on '{}'", server_url); + t + } + Err(e) => { + eprintln!("error occurred while initializing tcp listener err={}", e); + std::process::exit(1); + } + } + }; + + let router_config: Config = if let Ok(c) = Config::try_from(config) { + c + } else { + std::process::exit(1); + }; loop { let (stream, _) = listener.accept().await.unwrap(); - handle_connection(stream).await; + handle_connection(stream, router_config.clone()).await; } } /// parses the incoming request (partial spec implementation) and build an HTTP response -async fn handle_connection(mut stream: TcpStream) { +async fn handle_connection(mut stream: TcpStream, config: Config) { let mut buffer: [u8; 1024] = [0; 1024]; let n = stream.read(&mut buffer).await.unwrap(); let request_string = std::str::from_utf8(&buffer[0..n]).unwrap(); - let response = ROUTER.route(request_string).await; + let response = ROUTER.route(request_string, config).await; let response_str: String = response.into(); stream.write(response_str.as_bytes()).await.unwrap(); diff --git a/tests/python/test_requests.py b/tests/python/test_requests.py index 20e8409..19a88c2 100644 --- a/tests/python/test_requests.py +++ b/tests/python/test_requests.py @@ -1,5 +1,8 @@ +import jwt import requests +from datetime import datetime + from unittest import TestCase URL = "https://dev.thegux.fr" @@ -12,9 +15,15 @@ class TestResponse(TestCase): ) self.assertEqual(resp.status_code, 200, "bad status code returned") self.assertIsNotNone(resp.json(), "response data can't be empty") - self.assertEqual( - resp.json()["token"], "header.payload.signature", "bad status returned" - ) + + token = resp.json()["token"] + jwt_decoded = jwt.decode(token, options={"verify_signature": False}) + self.assertEqual("thegux.fr", jwt_decoded["iss"]) + + jwt_exp = datetime.fromtimestamp(jwt_decoded["exp"]) + jwt_iat = datetime.fromtimestamp(jwt_decoded["iat"]) + date_exp = datetime.strptime(str(jwt_exp - jwt_iat), "%H:%M:%S") + self.assertEqual(2, date_exp.hour) def test_validate_target(self): resp = requests.post(