Skip to content

Commit 571cab0

Browse files
committed
Compare hash of base64 decoded authorization header
Signed-off-by: Eloi DEMOLIS <[email protected]>
1 parent e77e822 commit 571cab0

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

Cargo.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

command/src/config.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -853,17 +853,17 @@ impl FileClusterConfig {
853853
let http_frontend = frontend.to_http_front(cluster_id)?;
854854
frontends.push(http_frontend);
855855
}
856-
self.authorized_hashes
857-
.iter()
858-
.map(|hash| {
859-
hex::decode(hash)
860-
.map_err(|_| ConfigError::InvalidHash(hash.clone()))
861-
.and_then(|v| {
862-
v.try_into()
863-
.map_err(|_| ConfigError::InvalidHash(hash.clone()))
864-
})
865-
})
866-
.collect::<Result<Vec<[u8; 32]>, ConfigError>>()?;
856+
// self.authorized_hashes
857+
// .iter()
858+
// .map(|hash| {
859+
// hex::decode(hash)
860+
// .map_err(|_| ConfigError::InvalidHash(hash.clone()))
861+
// .and_then(|v| {
862+
// v.try_into()
863+
// .map_err(|_| ConfigError::InvalidHash(hash.clone()))
864+
// })
865+
// })
866+
// .collect::<Result<Vec<[u8; 32]>, ConfigError>>()?;
867867

868868
Ok(ClusterConfig::Http(HttpClusterConfig {
869869
cluster_id: cluster_id.to_string(),

lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ include = [
2929

3030
[dependencies]
3131
anyhow = "^1.0.89"
32+
base64 = "0.22.1"
3233
cookie-factory = "^0.3.3"
3334
hdrhistogram = "^7.5.4"
3435
hex = "^0.4.3"

lib/src/protocol/kawa_h1/editor.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
str::{from_utf8, from_utf8_unchecked},
55
};
66

7+
use base64::Engine;
78
use rusty_ulid::Ulid;
89
use sha2::{Digest, Sha256};
910
use sozu_command::logging::CachedTags;
@@ -209,9 +210,20 @@ impl HttpContext {
209210
}
210211
}
211212

212-
self.authorization_found = auth
213-
.and_then(|header| header.val.data_opt(buf))
214-
.map(|auth| hex::encode(Sha256::digest(auth)));
213+
self.authorization_found =
214+
auth.and_then(|header| header.val.data_opt(buf))
215+
.and_then(|auth| {
216+
let (kind, token) = auth.trim_ascii_start().split_at("Basic ".len());
217+
compare_no_case(kind, b"Basic ").then_some(())?;
218+
let token = base64::prelude::BASE64_STANDARD.decode(token).ok()?;
219+
let (name, pwd) = token
220+
.iter()
221+
.position(|c| *c == b':')
222+
.map(|i| token.split_at(i+1))?;
223+
let mut auth = String::from_utf8(name.to_vec()).ok()?;
224+
auth.push_str(&hex::encode(Sha256::digest(pwd)));
225+
Some(auth)
226+
});
215227

216228
// If session_address is set:
217229
// - append its ip address to the list of "X-Forwarded-For" if it was found, creates it if not

0 commit comments

Comments
 (0)