diff --git a/Cargo.lock b/Cargo.lock index ef289776e1..ac53fc3662 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,12 +119,6 @@ dependencies = [ "rustc-demangle", ] -[[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" @@ -260,7 +254,7 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time", + "time 0.1.44", "winapi", ] @@ -1163,12 +1157,12 @@ dependencies = [ [[package]] name = "jsonwebtoken" -version = "7.2.0" +version = "8.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afabcc15e437a6484fc4f12d0fd63068fe457bf93f1c148d3d9649c60b103f32" +checksum = "cc9051c17f81bae79440afa041b3a278e1de71bfb96d32454b477fd4703ccb6f" dependencies = [ - "base64 0.12.3", - "pem 0.8.3", + "base64", + "pem", "ring", "serde", "serde_json", @@ -1382,9 +1376,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.2.6" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ "autocfg", "num-integer", @@ -1420,6 +1414,15 @@ dependencies = [ "libc", ] +[[package]] +name = "num_threads" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aba1801fb138d8e85e11d0fc70baf4fe1cdfffda7c6cd34a854905df588e5ed0" +dependencies = [ + "libc", +] + [[package]] name = "object" version = "0.27.1" @@ -1572,24 +1575,13 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "pem" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" -dependencies = [ - "base64 0.13.0", - "once_cell", - "regex", -] - [[package]] name = "pem" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9a3b09a20e374558580a4914d3b7d89bd61b954a5a5e1dcbea98753addb1947" dependencies = [ - "base64 0.13.0", + "base64", ] [[package]] @@ -1711,7 +1703,7 @@ name = "postgres-protocol" version = "0.6.1" source = "git+https://github.com/zenithdb/rust-postgres.git?rev=2949d98df52587d562986aad155dd4e889e408b7#2949d98df52587d562986aad155dd4e889e408b7" dependencies = [ - "base64 0.13.0", + "base64", "byteorder", "bytes", "fallible-iterator", @@ -1850,7 +1842,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "base64 0.13.0", + "base64", "bytes", "clap 3.0.14", "fail", @@ -1885,6 +1877,15 @@ dependencies = [ "zenith_utils", ] +[[package]] +name = "quickcheck" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" +dependencies = [ + "rand", +] + [[package]] name = "quote" version = "1.0.15" @@ -1966,7 +1967,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5911d1403f4143c9d56a702069d593e8d0f3fab880a85e103604d0893ea31ba7" dependencies = [ "chrono", - "pem 1.0.2", + "pem", "ring", "yasna", ] @@ -2031,7 +2032,7 @@ version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f242f1488a539a79bac6dbe7c8609ae43b7914b7736210f239a37cccb32525" dependencies = [ - "base64 0.13.0", + "base64", "bytes", "encoding_rs", "futures-core", @@ -2124,7 +2125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b4f000e8934c1b4f70adde180056812e7ea6b1a247952db8ee98c94cd3116cc" dependencies = [ "async-trait", - "base64 0.13.0", + "base64", "bytes", "crc32fast", "futures", @@ -2179,7 +2180,7 @@ version = "0.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6264e93384b90a747758bcc82079711eacf2e755c3a8b5091687b5349d870bcc" dependencies = [ - "base64 0.13.0", + "base64", "bytes", "chrono", "digest", @@ -2238,7 +2239,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" dependencies = [ - "base64 0.13.0", + "base64", ] [[package]] @@ -2490,13 +2491,14 @@ dependencies = [ [[package]] name = "simple_asn1" -version = "0.4.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692ca13de57ce0613a363c8c2f1de925adebc81b04c923ac60c5488bb44abe4b" +checksum = "4a762b1c38b9b990c694b9c2f8abe3372ce6a9ceaae6bca39cfc46e054f45745" dependencies = [ - "chrono", "num-bigint", "num-traits", + "thiserror", + "time 0.3.9", ] [[package]] @@ -2661,6 +2663,25 @@ dependencies = [ "winapi", ] +[[package]] +name = "time" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd" +dependencies = [ + "itoa 1.0.1", + "libc", + "num_threads", + "quickcheck", + "time-macros", +] + +[[package]] +name = "time-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" + [[package]] name = "tinytemplate" version = "1.2.1" @@ -2852,7 +2873,7 @@ checksum = "ff08f4649d10a70ffa3522ca559031285d8e421d727ac85c60825761818f5d0a" dependencies = [ "async-stream", "async-trait", - "base64 0.13.0", + "base64", "bytes", "futures-core", "futures-util", diff --git a/zenith_utils/Cargo.toml b/zenith_utils/Cargo.toml index 2b1caa9be2..ca98c8a2e2 100644 --- a/zenith_utils/Cargo.toml +++ b/zenith_utils/Cargo.toml @@ -22,7 +22,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } nix = "0.23.0" signal-hook = "0.3.10" rand = "0.8.3" -jsonwebtoken = "7" +jsonwebtoken = "8" hex = { version = "0.4.3", features = ["serde"] } rustls = "0.20.2" rustls-split = "0.3.0" diff --git a/zenith_utils/src/auth.rs b/zenith_utils/src/auth.rs index 8271121c63..3bdabacad4 100644 --- a/zenith_utils/src/auth.rs +++ b/zenith_utils/src/auth.rs @@ -1,8 +1,6 @@ // For details about authentication see docs/authentication.md -// TODO there are two issues for our use case in jsonwebtoken library which will be resolved in next release -// The first one is that there is no way to disable expiration claim, but it can be excluded from validation, so use this as a workaround for now. -// Relevant issue: https://github.com/Keats/jsonwebtoken/issues/190 -// The second one is that we wanted to use ed25519 keys, but they are also not supported until next version. So we go with RSA keys for now. +// +// TODO: use ed25519 keys // Relevant issue: https://github.com/Keats/jsonwebtoken/issues/162 use serde; @@ -59,19 +57,19 @@ pub fn check_permission(claims: &Claims, tenantid: Option) -> Result< } pub struct JwtAuth { - decoding_key: DecodingKey<'static>, + decoding_key: DecodingKey, validation: Validation, } impl JwtAuth { - pub fn new(decoding_key: DecodingKey<'_>) -> Self { + pub fn new(decoding_key: DecodingKey) -> Self { + let mut validation = Validation::new(JWT_ALGORITHM); + // The default 'required_spec_claims' is 'exp'. But we don't want to require + // expiration. + validation.required_spec_claims = [].into(); Self { - decoding_key: decoding_key.into_static(), - validation: Validation { - algorithms: vec![JWT_ALGORITHM], - validate_exp: false, - ..Default::default() - }, + decoding_key, + validation, } }