fix: also in case of digest

This commit is contained in:
əlemi 2024-04-13 04:31:50 +02:00
parent 5f66ca4946
commit 72774d01ed
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -35,21 +35,21 @@ impl Fetcher {
// ("Date".to_string(), date.clone()), // ("Date".to_string(), date.clone()),
// ].into(); // ].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() 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(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(CONTENT_TYPE, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
.header(USER_AGENT, format!("upub+{VERSION} ({domain})")) .header(USER_AGENT, format!("upub+{VERSION} ({domain})"))
.header("Host", host.clone()) .header("Host", host.clone())
.header("Date", date.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 { if let Some(payload) = payload {
let digest = format!("sha-256={}", base64::prelude::BASE64_STANDARD.encode(openssl::sha::sha256(payload.as_bytes()))); 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_to_inspect = "(request-target) host date digest";
// headers.insert("Digest".to_string(), digest.clone()); // headers.insert("Digest".to_string(), digest.clone());
// signature_cfg = signature_cfg.require_header("digest"); // signature_cfg = signature_cfg.require_header("digest");