fix: mastodon compat

This commit is contained in:
əlemi 2024-04-13 02:35:18 +02:00
parent 46bbeea3ab
commit ff55d2fea4
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 9 additions and 16 deletions

View file

@ -1,4 +1,4 @@
use apb::{server::Inbox, target::Addressed, Activity, ActivityType, Base, BaseType, ObjectType};
use apb::{server::Inbox, ActivityType, Base, BaseType, ObjectType};
use axum::{extract::{Query, State}, http::StatusCode, Json};
use sea_orm::{Order, QueryFilter, QueryOrder, QuerySelect};

View file

@ -68,10 +68,7 @@ where
.get("Signature")
.map(|v| v.to_str().unwrap_or(""))
{
let mut signature_cfg = Config::new()
.dont_use_created_field()
.require_header("host")
.require_header("date");
let mut signature_cfg = Config::new().mastodon_compat();
let mut headers : BTreeMap<String, String> = [
("Signature".to_string(), sig.to_string()),
("Host".to_string(), header_get(&parts.headers, "Host")),

View file

@ -38,9 +38,10 @@ impl Fetcher {
("Date".to_string(), date.clone()),
].into();
let mut client =
reqwest::Client::new()
let mut client = reqwest::Client::new()
.request(method, url)
.header(CONTENT_TYPE, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
.header(USER_AGENT, format!("upub+{VERSION} ({domain})"))
.header("Host", host)
.header("Date", date);
@ -56,13 +57,10 @@ impl Fetcher {
}
let signature_header = signature_cfg
.dont_use_created_field()
.require_header("host")
.require_header("date")
.mastodon_compat()
.begin_sign("POST", &path, headers)
.unwrap()
.sign(format!("{from}#main-key"), |to_sign| {
tracing::info!("signing '{to_sign}'");
let mut signer = Signer::new(MessageDigest::sha256(), key)?;
signer.update(to_sign.as_bytes())?;
let signature = base64::prelude::BASE64_URL_SAFE.encode(signer.sign_to_vec()?);
@ -73,8 +71,6 @@ impl Fetcher {
client
.header("Signature", signature_header)
.header(CONTENT_TYPE, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
.header(USER_AGENT, format!("upub+{VERSION} ({domain})")) // TODO put instance admin email
.send()
.await?
.error_for_status()?