fix: try setting digest always

aode relay complains that digest is missing on fetches? idk, let's try
putting an empty digest, will aode work? will mastodon/akkoma still
work? will this fix some *keys too???
This commit is contained in:
əlemi 2024-04-22 04:11:59 +02:00
parent 4d0fb9b684
commit 1d8b69dda7
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 19 additions and 27 deletions

View file

@ -14,7 +14,6 @@ use clap::{Parser, Subcommand};
use sea_orm::{ConnectOptions, Database, EntityTrait, IntoActiveModel}; use sea_orm::{ConnectOptions, Database, EntityTrait, IntoActiveModel};
pub use errors::UpubResult as Result; pub use errors::UpubResult as Result;
use server::fetcher::Fetcher;
use tower_http::{cors::CorsLayer, trace::TraceLayer}; use tower_http::{cors::CorsLayer, trace::TraceLayer};
use crate::server::fetcher::Fetchable; use crate::server::fetcher::Fetchable;

View file

@ -39,31 +39,16 @@ impl Fetcher for Context {
let host = Context::server(url); let host = Context::server(url);
let date = chrono::Utc::now().format("%a, %d %b %Y %H:%M:%S GMT").to_string(); // lmao @ "GMT" let date = chrono::Utc::now().format("%a, %d %b %Y %H:%M:%S GMT").to_string(); // lmao @ "GMT"
let path = url.replace("https://", "").replace("http://", "").replace(&host, ""); let path = url.replace("https://", "").replace("http://", "").replace(&host, "");
let payload_buf = payload.unwrap_or("").as_bytes();
let digest = format!("sha-256={}", base64::prelude::BASE64_STANDARD.encode(openssl::sha::sha256(payload_buf)));
let mut headers = vec!["(request-target)", "host", "date"]; let headers = vec!["(request-target)", "host", "date", "digest"];
let mut headers_map : BTreeMap<String, String> = [ let headers_map : BTreeMap<String, String> = [
("host".to_string(), host.clone()), ("host".to_string(), host.clone()),
("date".to_string(), date.clone()), ("date".to_string(), date.clone()),
("digest".to_string(), digest.clone()),
].into(); ].into();
let mut client = reqwest::Client::new()
.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());
if let Some(payload) = payload {
let digest = format!("sha-256={}", base64::prelude::BASE64_STANDARD.encode(openssl::sha::sha256(payload.as_bytes())));
headers_map.insert("digest".to_string(), digest.clone());
headers.push("digest");
client = client
.header("Digest", digest)
.body(payload.to_string());
}
let mut signer = HttpSignature::new( let mut signer = HttpSignature::new(
format!("{from}#main-key"), // TODO don't hardcode #main-key format!("{from}#main-key"), // TODO don't hardcode #main-key
"rsa-sha256".to_string(), "rsa-sha256".to_string(),
@ -74,12 +59,20 @@ impl Fetcher for Context {
.build_manually(&method.to_string().to_lowercase(), &path, headers_map) .build_manually(&method.to_string().to_lowercase(), &path, headers_map)
.sign(key)?; .sign(key)?;
let res = client Ok(reqwest::Client::new()
.header("Signature", signer.header()) .request(method.clone(), url)
.send() .header(ACCEPT, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
.await?; .header(CONTENT_TYPE, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
.header(USER_AGENT, format!("upub+{VERSION} ({domain})"))
Ok(res.error_for_status()?) .header("Host", host.clone())
.header("Date", date.clone())
.header("Digest", digest)
.header("Signature", signer.header())
.body(payload.unwrap_or("").to_string())
.send()
.await?
.error_for_status()?
)
} }
async fn fetch_user(&self, id: &str) -> crate::Result<model::user::Model> { async fn fetch_user(&self, id: &str) -> crate::Result<model::user::Model> {