Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't output whole timers map; hash headers in rust #1411

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ serde_yaml = "0.9.34"
toml = "0.8.19"
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
tempfile = "3.14.0"
hex = "0.4.3"

[workspace.dependencies.git2]
default-features = false
Expand Down
2 changes: 1 addition & 1 deletion josh-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ git-version = "0.3.9"
git2 = { workspace = true }
gix-object = "0.46.0"
glob = "0.3.1"
hex = "0.4.3"
hex = { workspace = true }
indoc = "2.0.5"
itertools = "0.13.0"
lazy_static = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions josh-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ repository = "https://github.com/josh-project/josh"
version = "22.4.15"

[dependencies]
sha2 = "0.10.8"
hex = { workspace = true }
base64 = { workspace = true }
clap = { workspace = true }
futures = { workspace = true }
Expand Down
33 changes: 20 additions & 13 deletions josh-proxy/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,25 @@ impl Handle {
}
}

fn hash_header(header: &hyper::http::HeaderValue) -> String {
use sha2::{Digest, Sha256};

let mut hasher = Sha256::new();
hasher.update(header.as_bytes());
let result = hasher.finalize();
hex::encode(result)
}

pub fn add_auth(token: &str) -> josh::JoshResult<Handle> {
let header = hyper::header::HeaderValue::from_str(&format!("Basic {}", BASE64.encode(token)))?;
let hp = Handle {
hash: Some(git2::Oid::hash_object(git2::ObjectType::Blob, header.as_bytes())?.to_string()),
let handle = Handle {
hash: Some(hash_header(&header)),
};
let p = Header {
let header_wrapper = Header {
header: Some(header),
};
AUTH.lock()?.insert(hp.clone(), p);
Ok(hp)
AUTH.lock()?.insert(handle.clone(), header_wrapper);
Ok(handle)
}

#[tracing::instrument()]
Expand Down Expand Up @@ -180,7 +189,7 @@ pub async fn check_http_auth(url: &str, auth: &Handle, required: bool) -> josh::
}

tracing::info!(
auth_timers = ?auth_timers,
auth_timers_count = auth_timers.len(),
"check_http_auth: no valid cached auth"
);

Expand Down Expand Up @@ -237,16 +246,14 @@ pub fn strip_auth(
req.headers_mut().remove(hyper::header::AUTHORIZATION);

if let Some(header) = header {
let hp = Handle {
hash: Some(
git2::Oid::hash_object(git2::ObjectType::Blob, header.as_bytes())?.to_string(),
),
let handle = Handle {
hash: Some(hash_header(&header)),
};
let p = Header {
let header_wrapper = Header {
header: Some(header),
};
AUTH.lock()?.insert(hp.clone(), p);
return Ok((hp, req));
AUTH.lock()?.insert(handle.clone(), header_wrapper);
return Ok((handle, req));
}

Ok((Handle { hash: None }, req))
Expand Down
Loading