This commit is contained in:
Tom Alexander 2024-07-20 12:22:10 -04:00
parent 4555bb6894
commit b91f63884a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 4 additions and 1 deletions

1
Cargo.lock generated
View File

@ -1900,6 +1900,7 @@ name = "webhook_bridge"
version = "0.0.1"
dependencies = [
"axum",
"base64 0.22.1",
"hmac",
"http-body-util",
"k8s-openapi",

View File

@ -20,6 +20,7 @@ include = [
[dependencies]
# default form, http1, json, matched-path, original-uri, query, tokio, tower-log, tracing
axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "http2", "json"] }
base64 = "0.22.1"
hmac = "0.12.1"
http-body-util = "0.1.2"
k8s-openapi = { version = "0.22.0", default-features = false, features = ["v1_30"] }

View File

@ -12,6 +12,7 @@ use axum::response::IntoResponse;
use axum::response::Response;
use axum::Json;
use axum::RequestExt;
use base64::{engine::general_purpose, Engine as _};
use hmac::Hmac;
use hmac::Mac;
use http_body_util::BodyExt;
@ -126,7 +127,7 @@ where
async fn check_hash(body: Bytes, secret: String, signature: Vec<u8>) -> Result<Bytes, Response> {
tracing::info!("Checking signature {:02x?}", signature.as_slice());
tracing::info!("Using secret {:?}", secret);
tracing::info!("and body {:02x?}", body);
tracing::info!("and body {}", general_purpose::STANDARD.encode(&body));
let mut mac = HmacSha256::new_from_slice(secret.as_bytes())
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response())?;
mac.update(&body);