diff options
author | KunoiSayami <[email protected]> | 2021-07-22 00:31:18 +0800 |
---|---|---|
committer | KunoiSayami <[email protected]> | 2021-07-22 00:31:18 +0800 |
commit | 840a5e9e6f077d0c7cf42d6e8a7089f41fb1ab0e (patch) | |
tree | 29b3cd20a98b48243f70f1704029aef4113c93ac | |
parent | 0108133876702e21203d9e02eb282b0ba93c43b4 (diff) |
feat(core): Update cookie ttl while visit websitev3.0.2
* chore: Bump version
-rw-r--r-- | Cargo.lock | 40 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/datastructures.rs | 9 | ||||
-rw-r--r-- | src/main.rs | 16 |
4 files changed, 32 insertions, 35 deletions
@@ -9,7 +9,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc7d7cd957c9ed92288a7c3c96af81fa5291f65247a76a34dac7b6af74e52ba0" dependencies = [ "futures-core", - "tokio 1.8.1", + "tokio 1.8.2", ] [[package]] @@ -55,9 +55,9 @@ checksum = "dabe5a181f83789739c194cbe5a897dde195078fac08568d09221fd6137a7ba8" [[package]] name = "argon2" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d60f5f3113c903294dc81dd8cf0012963ed4dda8bc931c864e12e175356ff98b" +checksum = "2ab8b02347b6f46e0287e74f75c611c7e3a350a1e7df449b7fc8c16f1e8d238e" dependencies = [ "blake2", "password-hash", @@ -370,7 +370,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cgit-simple-authentication" -version = "3.0.1" +version = "3.0.2" dependencies = [ "anyhow", "argon2", @@ -390,7 +390,7 @@ dependencies = [ "serde_json", "sqlx", "tempdir", - "tokio 1.8.1", + "tokio 1.8.2", "tokio-stream", "toml", "url", @@ -606,9 +606,9 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" [[package]] name = "fastrand" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b705829d1e87f762c2df6da140b26af5839e1033aa84aa5f56bb688e4e1bdb" +checksum = "b394ed3d285a429378d3b384b9eb1285267e7df4b166df24b7a6939a04dc392e" dependencies = [ "instant", ] @@ -1290,9 +1290,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dea6388d3d5498ec651701f14edbaf463c924b5d8829fb2848ccf0bcc7b3c69" +checksum = "039f02eb0f69271f26abe3202189275d7aa2258b903cb0281b5de710a2570ff3" dependencies = [ "num-traits", ] @@ -1330,9 +1330,9 @@ dependencies = [ [[package]] name = "password-hash" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1a5d4e9c205d2c1ae73b84aab6240e98218c0e72e63b50422cfb2d1ca952282" +checksum = "fd482dfb8cfba5a93ec0f91e1c0f66967cb2fdc1a8dba646c4f9202c5d05d785" dependencies = [ "base64ct", "rand_core 0.6.3", @@ -1909,7 +1909,7 @@ dependencies = [ "actix-rt", "native-tls", "once_cell", - "tokio 1.8.1", + "tokio 1.8.2", "tokio-native-tls", ] @@ -1937,9 +1937,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "subtle" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" @@ -2043,9 +2043,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +checksum = "4ac2e1d4bd0f75279cfd5a076e0d578bbf02c22b7c39e766c437dd49b3ec43e0" dependencies = [ "tinyvec_macros", ] @@ -2076,9 +2076,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.8.1" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c8b05dc14c75ea83d63dd391100353789f5f24b8b3866542a5e85c8be8e985" +checksum = "c2602b8af3767c285202012822834005f596c811042315fa7e9f5b12b2a43207" dependencies = [ "autocfg", "bytes 1.0.1", @@ -2112,7 +2112,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", - "tokio 1.8.1", + "tokio 1.8.2", ] [[package]] @@ -2123,7 +2123,7 @@ checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" dependencies = [ "futures-core", "pin-project-lite 0.2.7", - "tokio 1.8.1", + "tokio 1.8.2", ] [[package]] @@ -1,6 +1,6 @@ [package] name = "cgit-simple-authentication" -version = "3.0.1" +version = "3.0.2" authors = ["KunoiSayami <[email protected]>"] edition = "2018" diff --git a/src/datastructures.rs b/src/datastructures.rs index e004514..0551fcf 100644 --- a/src/datastructures.rs +++ b/src/datastructures.rs @@ -372,12 +372,7 @@ impl ProtectSettings { if !self.protect_enabled { return false; } - let ret = self.repos.iter().any(|x| x.eq(repo)); - if self.protect_white_list_mode { - !ret - } else { - ret - } + self.protect_white_list_mode != self.repos.iter().any(|x| x.eq(repo)) } #[cfg(test)] @@ -415,7 +410,7 @@ impl FormData { } } - pub fn get_string_argon2_hash(s: &str) -> Result<String> { + pub fn gen_string_argon2_hash(s: &str) -> Result<String> { let passwd = s.as_bytes(); let salt = SaltString::generate(&mut OsRng); diff --git a/src/main.rs b/src/main.rs index 00b52a6..46f088f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,7 @@ impl<R: BufRead, W: Write> IOModule<R, W> { writeln!( &mut self.writer, "Set-Cookie: cgit_auth={}; Domain={}; Max-Age={}; HttpOnly{}", - cookie_value, domain, cfg.cookie_ttl, cookie_suffix + cookie_value, domain, cfg.cookie_ttl * 10, cookie_suffix )?; } else { writeln!(&mut self.writer, "Status: 403 Forbidden")?; @@ -105,12 +105,11 @@ impl<R: BufRead, W: Write> IOModule<R, W> { async fn cmd_authenticate_cookie(matches: &ArgMatches<'_>, cfg: Config) -> Result<bool> { let cookies = matches.value_of("http-cookie").unwrap_or(""); let repo = matches.value_of("repo").unwrap_or(""); - let current_url = matches.value_of("current-url").unwrap_or(""); + /*let current_url = matches.value_of("current-url").unwrap_or("");*/ let mut bypass = false; - // TODO: bypass root not working properly if we select sort mode - if cfg.bypass_root && current_url.eq("/") && repo.is_empty() { + if cfg.bypass_root /*&& current_url.eq("/")*/ && repo.is_empty() { bypass = true; } @@ -148,8 +147,11 @@ async fn cmd_authenticate_cookie(matches: &ArgMatches<'_>, cfg: Config) -> Resul .get::<_, String>(format!("cgit_auth_{}", cookie.get_key())) .await { - // TODO: Extend cookie ttl in each authenticate request - //log::debug!("Cookie is valid"); + conn.expire::<_, bool>( + format!("cgit_auth_{}", cookie.get_key()), + cfg.cookie_ttl as usize, + ) + .await?; if cookie.eq_body(r.as_str()) { if repo.is_empty() { return Ok(true); @@ -282,7 +284,7 @@ async fn cmd_add_user(matches: &ArgMatches<'_>, cfg: Config) -> Result<()> { sqlx::query(r#"INSERT INTO "accounts" VALUES (?, ?, ?) "#) .bind(user) - .bind(FormData::get_string_argon2_hash(&passwd)?) + .bind(FormData::gen_string_argon2_hash(&passwd)?) .bind(&uid) .execute(&mut conn) .await?; |