mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-22 19:41:03 +00:00
Update webfinger and reqwest
Update webfinger to 0.3.1 Update reqwest to 0.9 Fix #257
This commit is contained in:
parent
8fdb55a501
commit
ed5bafbbc4
9 changed files with 623 additions and 386 deletions
936
Cargo.lock
generated
936
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -21,7 +21,7 @@ serde_qs = "0.4"
|
|||
tera = "0.11"
|
||||
validator = "0.7"
|
||||
validator_derive = "0.7"
|
||||
webfinger = "0.3"
|
||||
webfinger = "0.3.1"
|
||||
workerpool = "1.1"
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -16,7 +16,7 @@ heck = "0.3.0"
|
|||
hex = "0.3"
|
||||
hyper = "0.11.27"
|
||||
openssl = "0.10.11"
|
||||
reqwest = "0.8"
|
||||
reqwest = "0.9"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
|
|
|
@ -104,11 +104,11 @@ pub fn broadcast<S: sign::Signer, A: Activity, T: inbox::WithInbox + Actor>(send
|
|||
for inbox in boxes {
|
||||
// TODO: run it in Sidekiq or something like that
|
||||
let mut headers = request::headers();
|
||||
headers.set(request::Digest::digest(signed.to_string()));
|
||||
headers.insert("Digest", request::Digest::digest(signed.to_string()));
|
||||
let res = Client::new()
|
||||
.post(&inbox[..])
|
||||
.headers(headers.clone())
|
||||
.header(request::signature(sender, headers))
|
||||
.header("Signature", request::signature(sender, headers))
|
||||
.body(signed.to_string())
|
||||
.send();
|
||||
match res {
|
||||
|
|
|
@ -1,31 +1,23 @@
|
|||
use base64;
|
||||
use chrono::{DateTime, offset::Utc};
|
||||
use openssl::hash::{Hasher, MessageDigest};
|
||||
use reqwest::{
|
||||
mime::Mime,
|
||||
header::{Accept, Date, Headers, UserAgent, qitem}
|
||||
};
|
||||
use reqwest::header::{ACCEPT, DATE, HeaderMap, HeaderValue, USER_AGENT};
|
||||
use std::ops::Deref;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use activity_pub::ap_accept_header;
|
||||
use activity_pub::sign::Signer;
|
||||
|
||||
const USER_AGENT: &'static str = concat!("Plume/", env!("CARGO_PKG_VERSION"));
|
||||
const PLUME_USER_AGENT: &'static str = concat!("Plume/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
header! {
|
||||
(Signature, "Signature") => [String]
|
||||
}
|
||||
|
||||
header! {
|
||||
(Digest, "Digest") => [String]
|
||||
}
|
||||
pub struct Digest(String);
|
||||
|
||||
impl Digest {
|
||||
pub fn digest(body: String) -> Self {
|
||||
pub fn digest(body: String) -> HeaderValue {
|
||||
let mut hasher = Hasher::new(MessageDigest::sha256()).unwrap();
|
||||
hasher.update(&body.into_bytes()[..]).unwrap();
|
||||
let res = base64::encode(&hasher.finish().unwrap());
|
||||
Digest(format!("SHA-256={}", res))
|
||||
HeaderValue::from_str(&format!("SHA-256={}", res)).unwrap()
|
||||
}
|
||||
|
||||
pub fn verify(&self, body: String) -> bool {
|
||||
|
@ -62,25 +54,28 @@ impl Digest {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn headers() -> Headers {
|
||||
let mut headers = Headers::new();
|
||||
headers.set(UserAgent::new(USER_AGENT));
|
||||
headers.set(Date(SystemTime::now().into()));
|
||||
headers.set(Accept(ap_accept_header().into_iter().map(|h| qitem(h.parse::<Mime>().expect("Invalid Content-Type"))).collect()));
|
||||
pub fn headers() -> HeaderMap {
|
||||
let date: DateTime<Utc> = SystemTime::now().into();
|
||||
let date = format!("{}", date.format("%a, %d %b %Y %T %Z"));
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(USER_AGENT, HeaderValue::from_static(PLUME_USER_AGENT));
|
||||
headers.insert(DATE, HeaderValue::from_str(&date).unwrap());
|
||||
headers.insert(ACCEPT, HeaderValue::from_str(&ap_accept_header().into_iter().collect::<Vec<_>>().join(", ")).unwrap());
|
||||
headers
|
||||
}
|
||||
|
||||
pub fn signature<S: Signer>(signer: &S, headers: Headers) -> Signature {
|
||||
let signed_string = headers.iter().map(|h| format!("{}: {}", h.name().to_lowercase(), h.value_string())).collect::<Vec<String>>().join("\n");
|
||||
let signed_headers = headers.iter().map(|h| h.name().to_string()).collect::<Vec<String>>().join(" ").to_lowercase();
|
||||
pub fn signature<S: Signer>(signer: &S, headers: HeaderMap) -> HeaderValue {
|
||||
let signed_string = headers.iter().map(|(h,v)| format!("{}: {}", h.as_str().to_lowercase(), v.to_str().unwrap())).collect::<Vec<String>>().join("\n");
|
||||
let signed_headers = headers.iter().map(|(h,_)| h.as_str()).collect::<Vec<&str>>().join(" ").to_lowercase();
|
||||
|
||||
let data = signer.sign(signed_string);
|
||||
let sign = base64::encode(&data[..]);
|
||||
|
||||
Signature(format!(
|
||||
HeaderValue::from_str(&format!(
|
||||
"keyId=\"{key_id}\",algorithm=\"rsa-sha256\",headers=\"{signed_headers}\",signature=\"{signature}\"",
|
||||
key_id = signer.get_key_id(),
|
||||
signed_headers = signed_headers,
|
||||
signature = sign
|
||||
))
|
||||
)).unwrap()
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ extern crate failure_derive;
|
|||
extern crate gettextrs;
|
||||
extern crate hex;
|
||||
extern crate heck;
|
||||
#[macro_use]
|
||||
extern crate hyper;
|
||||
extern crate openssl;
|
||||
extern crate pulldown_cmark;
|
||||
|
|
|
@ -11,12 +11,12 @@ canapi = "0.1"
|
|||
heck = "0.3.0"
|
||||
lazy_static = "*"
|
||||
openssl = "0.10.11"
|
||||
reqwest = "0.8"
|
||||
reqwest = "0.9"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
url = "1.7"
|
||||
webfinger = "0.3"
|
||||
webfinger = "0.3.1"
|
||||
|
||||
[dependencies.chrono]
|
||||
features = ["serde"]
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
use activitypub::{Actor, Object, CustomObject, actor::Group, collection::OrderedCollection};
|
||||
use chrono::NaiveDateTime;
|
||||
use reqwest::{
|
||||
Client,
|
||||
header::{Accept, qitem},
|
||||
mime::Mime
|
||||
use reqwest::{Client,
|
||||
header::{ACCEPT, HeaderValue}
|
||||
};
|
||||
use serde_json;
|
||||
use url::Url;
|
||||
|
@ -120,7 +118,7 @@ impl Blog {
|
|||
fn fetch_from_url(conn: &Connection, url: String) -> Option<Blog> {
|
||||
let req = Client::new()
|
||||
.get(&url[..])
|
||||
.header(Accept(ap_accept_header().into_iter().map(|h| qitem(h.parse::<Mime>().expect("Invalid Content-Type"))).collect()))
|
||||
.header(ACCEPT, HeaderValue::from_str(&ap_accept_header().into_iter().collect::<Vec<_>>().join(", ")).unwrap())
|
||||
.send();
|
||||
match req {
|
||||
Ok(mut res) => {
|
||||
|
|
|
@ -20,8 +20,7 @@ use plume_common::activity_pub::{
|
|||
};
|
||||
use reqwest::{
|
||||
Client,
|
||||
header::{Accept, qitem},
|
||||
mime::Mime
|
||||
header::{ACCEPT, HeaderValue}
|
||||
};
|
||||
use rocket::{
|
||||
request::{self, FromRequest, Request},
|
||||
|
@ -192,7 +191,7 @@ impl User {
|
|||
fn fetch(url: String) -> Option<CustomPerson> {
|
||||
let req = Client::new()
|
||||
.get(&url[..])
|
||||
.header(Accept(ap_accept_header().into_iter().map(|h| qitem(h.parse::<Mime>().expect("Invalid Content-Type"))).collect()))
|
||||
.header(ACCEPT, HeaderValue::from_str(&ap_accept_header().into_iter().collect::<Vec<_>>().join(", ")).unwrap())
|
||||
.send();
|
||||
match req {
|
||||
Ok(mut res) => {
|
||||
|
@ -348,7 +347,7 @@ impl User {
|
|||
pub fn fetch_outbox<T: Activity>(&self) -> Vec<T> {
|
||||
let req = Client::new()
|
||||
.get(&self.outbox_url[..])
|
||||
.header(Accept(ap_accept_header().into_iter().map(|h| qitem(h.parse::<Mime>().expect("Invalid Content-Type"))).collect()))
|
||||
.header(ACCEPT, HeaderValue::from_str(&ap_accept_header().into_iter().collect::<Vec<_>>().join(", ")).unwrap())
|
||||
.send();
|
||||
match req {
|
||||
Ok(mut res) => {
|
||||
|
@ -370,7 +369,7 @@ impl User {
|
|||
pub fn fetch_followers_ids(&self) -> Vec<String> {
|
||||
let req = Client::new()
|
||||
.get(&self.followers_endpoint[..])
|
||||
.header(Accept(ap_accept_header().into_iter().map(|h| qitem(h.parse::<Mime>().expect("Invalid Content-Type"))).collect()))
|
||||
.header(ACCEPT, HeaderValue::from_str(&ap_accept_header().into_iter().collect::<Vec<_>>().join(", ")).unwrap())
|
||||
.send();
|
||||
match req {
|
||||
Ok(mut res) => {
|
||||
|
|
Loading…
Reference in a new issue