-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proxy): Customize session to assign fixed IP (#38)
* feat(auth): Enhance authorization security * Update README.md * Update * Update auth.rs * feat(proxy): Customize session to assign fixed IP * Update * Update * Update
- Loading branch information
Showing
11 changed files
with
410 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,48 @@ | ||
use super::murmur; | ||
use std::net::IpAddr; | ||
|
||
/// Trait for checking if an IP address is in the whitelist. | ||
pub trait Whitelist { | ||
/// Checks if the given IP address is in the whitelist. | ||
fn contains(&self, ip: IpAddr) -> bool; | ||
} | ||
|
||
/// Enum representing different types of extensions. | ||
#[derive(Clone, Copy)] | ||
pub enum Extensions { | ||
/// No extension. | ||
None, | ||
/// Session extension with a tuple of two 64-bit integers. | ||
Session((u64, u64)), | ||
} | ||
|
||
impl Default for Extensions { | ||
fn default() -> Self { | ||
Extensions::None | ||
} | ||
} | ||
|
||
impl From<(&str, &str)> for Extensions { | ||
// This function takes a tuple of two strings as input: a prefix (the username) | ||
// and a string `s` (the username-session-id). | ||
fn from((prefix, s): (&str, &str)) -> Self { | ||
// Check if the string `s` starts with the prefix (username). | ||
if s.starts_with(prefix) { | ||
// If it does, remove the prefix from `s`. | ||
if let Some(s) = s.strip_prefix(prefix) { | ||
// Then, remove the "-session-" character that follows the prefix. | ||
let s = s.trim_start_matches("-session-"); | ||
// If the remaining string is not empty, it is considered as the session ID. | ||
// Return it wrapped in the `Session` variant of `AuthExpand`. | ||
if !s.is_empty() { | ||
let (a, b) = murmur::murmurhash3_x64_128(s.as_bytes(), s.len() as u64); | ||
return Extensions::Session((a, b)); | ||
} | ||
} | ||
} | ||
// If the string `s` does not start with the prefix, or if the remaining string | ||
// after removing the prefix and "-" is empty, return the `None` variant | ||
// of `AuthExpand`. | ||
Extensions::None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.