feat: #11 impl JWT + add associated tests
This commit is contained in:
		
							parent
							
								
									e22d289e0d
								
							
						
					
					
						commit
						72d1fba8f4
					
				
							
								
								
									
										648
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										648
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -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" | ||||
| @ -146,12 +152,39 @@ 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 +205,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 +235,18 @@ version = "1.0.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||||
| 
 | ||||
| [[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" | ||||
| @ -205,6 +256,27 @@ dependencies = [ | ||||
|  "cache-padded", | ||||
| ] | ||||
| 
 | ||||
| [[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.11" | ||||
| @ -215,6 +287,44 @@ dependencies = [ | ||||
|  "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.8" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "9f2b443d17d49dad5ef0ede301c3179cc923b8822f3393b4d2c28c269dd4a122" | ||||
| 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 +335,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.8", | ||||
|  "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 +427,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 +473,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 +506,17 @@ 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 = "hermit-abi" | ||||
| version = "0.1.19" | ||||
| @ -297,6 +526,48 @@ 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 = "instant" | ||||
| version = "0.1.12" | ||||
| @ -306,6 +577,12 @@ dependencies = [ | ||||
|  "cfg-if", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "itoa" | ||||
| version = "1.0.4" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "js-sys" | ||||
| version = "0.3.59" | ||||
| @ -321,6 +598,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,6 +650,9 @@ name = "lazy_static" | ||||
| version = "1.4.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" | ||||
| dependencies = [ | ||||
|  "spin", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "libc" | ||||
| @ -342,6 +660,12 @@ version = "0.2.132" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" | ||||
| 
 | ||||
| [[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" | ||||
| @ -380,6 +704,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" | ||||
| @ -396,6 +768,28 @@ version = "1.14.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" | ||||
| 
 | ||||
| [[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" | ||||
| version = "2.0.0" | ||||
| @ -425,6 +819,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 +849,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" | ||||
| @ -451,6 +895,12 @@ dependencies = [ | ||||
|  "winapi", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "ppv-lite86" | ||||
| version = "0.2.16" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "proc-macro2" | ||||
| version = "1.0.43" | ||||
| @ -469,6 +919,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 +975,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.8", | ||||
|  "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,6 +1083,16 @@ 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" | ||||
| @ -517,6 +1100,7 @@ dependencies = [ | ||||
|  "async-std", | ||||
|  "async-trait", | ||||
|  "json", | ||||
|  "jwt-simple", | ||||
|  "lazy_static", | ||||
|  "regex", | ||||
|  "tokio", | ||||
| @ -547,6 +1131,38 @@ dependencies = [ | ||||
|  "winapi", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "spin" | ||||
| version = "0.5.2" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| 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 = "subtle" | ||||
| version = "2.4.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "syn" | ||||
| version = "1.0.99" | ||||
| @ -558,6 +1174,26 @@ dependencies = [ | ||||
|  "unicode-ident", | ||||
| ] | ||||
| 
 | ||||
| [[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.1" | ||||
| @ -590,6 +1226,12 @@ dependencies = [ | ||||
|  "syn", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "typenum" | ||||
| version = "1.15.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "unicode-ident" | ||||
| version = "1.0.3" | ||||
| @ -773,3 +1415,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" | ||||
|  | ||||
| @ -11,6 +11,7 @@ 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" | ||||
|  | ||||
| @ -11,6 +11,7 @@ pub enum HTTPStatusCode { | ||||
|     Http400, | ||||
|     Http403, | ||||
|     Http404, | ||||
|     Http500, | ||||
| } | ||||
| 
 | ||||
| impl Into<String> for HTTPStatusCode { | ||||
| @ -20,6 +21,7 @@ impl Into<String> for HTTPStatusCode { | ||||
|             Self::Http400 => "400".to_string(), | ||||
|             Self::Http404 => "404".to_string(), | ||||
|             Self::Http403 => "403".to_string(), | ||||
|             Self::Http500 => "500".to_string(), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -89,6 +91,17 @@ impl Into<String> 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 +130,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 | ||||
|     } | ||||
|  | ||||
| @ -4,11 +4,15 @@ | ||||
| use super::{HTTPRequest, HTTPResponse, HTTPStatusCode}; | ||||
| use crate::stores::FileStore; | ||||
| use crate::stores::Store; | ||||
| use jwt_simple::prelude::*; | ||||
| use lazy_static::lazy_static; | ||||
| use std::collections::HashMap; | ||||
| use std::future::Future; | ||||
| use std::pin::Pin; | ||||
| 
 | ||||
| const JWT_EXPIRATION_TIME: u64 = 2; | ||||
| const ISSUER: &'static str = "thegux.fr"; | ||||
| 
 | ||||
| type FuturePinned<HTTPResponse> = Pin<Box<dyn Future<Output = HTTPResponse>>>; | ||||
| type Handler = fn(HTTPRequest) -> FuturePinned<HTTPResponse>; | ||||
| 
 | ||||
| @ -22,7 +26,15 @@ fn handle_get(request: HTTPRequest) -> FuturePinned<HTTPResponse> { | ||||
|                 if !is_auth { | ||||
|                     return HTTPResponse::as_403(); | ||||
|                 } | ||||
|                 HTTPResponse::as_200() | ||||
| 
 | ||||
|                 let mut claims = Claims::create(Duration::from_hours(JWT_EXPIRATION_TIME)); | ||||
|                 claims.issuer = Some(ISSUER.to_string()); | ||||
| 
 | ||||
|                 match JWT_KEY.authenticate(claims) { | ||||
|                     Ok(token) => HTTPResponse::as_200(token), | ||||
|                     // TODO: set the error in the message body
 | ||||
|                     Err(_e) => HTTPResponse::as_500(), | ||||
|                 } | ||||
|             } | ||||
|             None => HTTPResponse::as_400(), | ||||
|         } | ||||
| @ -36,7 +48,7 @@ fn handle_validate(request: HTTPRequest) -> FuturePinned<HTTPResponse> { | ||||
|         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(), | ||||
|         } | ||||
| @ -54,6 +66,8 @@ lazy_static! { | ||||
|                 ("/validate/", handle_validate as Handler) | ||||
|             ] | ||||
|         ); | ||||
| 
 | ||||
|     static ref JWT_KEY: jwt_simple::algorithms::HS256Key = HS256Key::generate(); | ||||
| } | ||||
| 
 | ||||
| pub struct Router; | ||||
|  | ||||
| @ -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( | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user