From 72774d01ed838d2ca7158d236783a25f9dd084d4 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 13 Apr 2024 04:31:50 +0200 Subject: [PATCH] fix: also in case of digest --- src/server/fetcher.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/server/fetcher.rs b/src/server/fetcher.rs index c7fd68dc..3dbb7e60 100644 --- a/src/server/fetcher.rs +++ b/src/server/fetcher.rs @@ -35,21 +35,21 @@ impl Fetcher { // ("Date".to_string(), date.clone()), // ].into(); - // let mut signature_cfg = Config::new().mastodon_compat(); - let mut to_sign_raw = format!("(request-target): {} {path}\nhost: {host}\ndate: {date}", method.to_string().to_lowercase()); - let mut headers_to_inspect = "(request-target) host date"; - let mut client = reqwest::Client::new() - .request(method, url) + .request(method.clone(), url) .header(ACCEPT, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") .header(CONTENT_TYPE, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") .header(USER_AGENT, format!("upub+{VERSION} ({domain})")) .header("Host", host.clone()) .header("Date", date.clone()); + // let mut signature_cfg = Config::new().mastodon_compat(); + let mut to_sign_raw = format!("(request-target): {} {path}\nhost: {host}\ndate: {date}", method.to_string().to_lowercase()); + let mut headers_to_inspect = "(request-target) host date"; + if let Some(payload) = payload { let digest = format!("sha-256={}", base64::prelude::BASE64_STANDARD.encode(openssl::sha::sha256(payload.as_bytes()))); - to_sign_raw = format!("(request-target): post {path}\nhost: {host}\ndate: {date}\ndigest: {digest}"); + to_sign_raw = format!("(request-target): {} {path}\nhost: {host}\ndate: {date}\ndigest: {digest}", method.to_string().to_lowercase()); headers_to_inspect = "(request-target) host date digest"; // headers.insert("Digest".to_string(), digest.clone()); // signature_cfg = signature_cfg.require_header("digest");