forked from alemi/upub
fix: mastodon compat
This commit is contained in:
parent
46bbeea3ab
commit
ff55d2fea4
3 changed files with 9 additions and 16 deletions
|
@ -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 axum::{extract::{Query, State}, http::StatusCode, Json};
|
||||||
use sea_orm::{Order, QueryFilter, QueryOrder, QuerySelect};
|
use sea_orm::{Order, QueryFilter, QueryOrder, QuerySelect};
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,7 @@ where
|
||||||
.get("Signature")
|
.get("Signature")
|
||||||
.map(|v| v.to_str().unwrap_or(""))
|
.map(|v| v.to_str().unwrap_or(""))
|
||||||
{
|
{
|
||||||
let mut signature_cfg = Config::new()
|
let mut signature_cfg = Config::new().mastodon_compat();
|
||||||
.dont_use_created_field()
|
|
||||||
.require_header("host")
|
|
||||||
.require_header("date");
|
|
||||||
let mut headers : BTreeMap<String, String> = [
|
let mut headers : BTreeMap<String, String> = [
|
||||||
("Signature".to_string(), sig.to_string()),
|
("Signature".to_string(), sig.to_string()),
|
||||||
("Host".to_string(), header_get(&parts.headers, "Host")),
|
("Host".to_string(), header_get(&parts.headers, "Host")),
|
||||||
|
|
|
@ -38,9 +38,10 @@ impl Fetcher {
|
||||||
("Date".to_string(), date.clone()),
|
("Date".to_string(), date.clone()),
|
||||||
].into();
|
].into();
|
||||||
|
|
||||||
let mut client =
|
let mut client = reqwest::Client::new()
|
||||||
reqwest::Client::new()
|
|
||||||
.request(method, url)
|
.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("Host", host)
|
||||||
.header("Date", date);
|
.header("Date", date);
|
||||||
|
|
||||||
|
@ -56,13 +57,10 @@ impl Fetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
let signature_header = signature_cfg
|
let signature_header = signature_cfg
|
||||||
.dont_use_created_field()
|
.mastodon_compat()
|
||||||
.require_header("host")
|
|
||||||
.require_header("date")
|
|
||||||
.begin_sign("POST", &path, headers)
|
.begin_sign("POST", &path, headers)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.sign(format!("{from}#main-key"), |to_sign| {
|
.sign(format!("{from}#main-key"), |to_sign| {
|
||||||
tracing::info!("signing '{to_sign}'");
|
|
||||||
let mut signer = Signer::new(MessageDigest::sha256(), key)?;
|
let mut signer = Signer::new(MessageDigest::sha256(), key)?;
|
||||||
signer.update(to_sign.as_bytes())?;
|
signer.update(to_sign.as_bytes())?;
|
||||||
let signature = base64::prelude::BASE64_URL_SAFE.encode(signer.sign_to_vec()?);
|
let signature = base64::prelude::BASE64_URL_SAFE.encode(signer.sign_to_vec()?);
|
||||||
|
@ -73,8 +71,6 @@ impl Fetcher {
|
||||||
|
|
||||||
client
|
client
|
||||||
.header("Signature", signature_header)
|
.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()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
.error_for_status()?
|
.error_for_status()?
|
||||||
|
|
Loading…
Reference in a new issue