Skip to content

Commit

Permalink
🚑 Parse revoked tokens from hexadecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBardon committed Aug 10, 2024
1 parent 34f4817 commit f120777
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ resolver = "2"
base64 = "0.22"
biscuit-auth = "5"
chrono = "0.4"
hex = "0.4"
iso8601-duration = "0.2"
lazy_static = "1"
rocket = "0.5"
Expand Down
1 change: 1 addition & 0 deletions src/helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
biscuit-auth = { workspace = true }
hex = { workspace = true }
lazy_static = { workspace = true }
rocket = { workspace = true }
serde_json = { workspace = true }
Expand Down
11 changes: 7 additions & 4 deletions src/helpers/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
};

use lazy_static::lazy_static;
use tracing::{debug, info, trace};
use tracing::{debug, error, info, trace};

use crate::{config::*, copy_directory, website_id::*};

Expand Down Expand Up @@ -141,15 +141,18 @@ fn _update_submodules() -> Result<(), Error> {
}
}

fn read_file_to_set_(file: File) -> io::Result<HashSet<Vec<u8>>> {
fn read_file_lines_as_hex_(file: File) -> io::Result<HashSet<Vec<u8>>> {
let reader = BufReader::new(file);

let mut set = HashSet::new();

for line in reader.lines() {
let line = line?;
if !line.is_empty() {
set.insert(line.into_bytes());
set.insert(hex::decode(&line).unwrap_or_else(|err| {
error!("Could not parse `{line}` as hexadecimal: {err}");
line.into_bytes()
}));
}
}

Expand All @@ -166,7 +169,7 @@ pub fn read_revoked_tokens() -> Result<HashSet<Vec<u8>>, Error> {
);
return Ok(HashSet::new());
};
let revoked_tokens = read_file_to_set_(revoked_tokens_file)?;
let revoked_tokens = read_file_lines_as_hex_(revoked_tokens_file)?;
info!("Found {} revoked token(s).", revoked_tokens.len());
Ok(revoked_tokens)
}
Expand Down
3 changes: 2 additions & 1 deletion src/orangutan-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orangutan-server"
version = "0.4.12"
version = "0.4.13"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,6 +9,7 @@ edition = "2021"
base64 = { workspace = true }
biscuit-auth = { workspace = true }
chrono = { workspace = true }
hex = { workspace = true }
lazy_static = { workspace = true }
orangutan-helpers = { path = "../helpers" }
orangutan-refresh-token = { path = "../orangutan-refresh-token" }
Expand Down
11 changes: 10 additions & 1 deletion src/orangutan-server/src/routes/auth_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ fn handle_refresh_token(
};

// NOTE: This is just a hotfix. I had to quickly revoke a token. I'll improve this one day.
trace!("Checking if refresh token is revoked");
trace!("Checking if refresh token is revoked…");
trace!(
"Revocation identifiers: {}",
refresh_biscuit
.revocation_identifiers()
.into_iter()
.map(hex::encode)
.collect::<Vec<_>>()
.join(", "),
);
let revoked_id = refresh_biscuit
.revocation_identifiers()
.into_iter()
Expand Down

0 comments on commit f120777

Please sign in to comment.