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
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"
|
tera = "0.11"
|
||||||
validator = "0.7"
|
validator = "0.7"
|
||||||
validator_derive = "0.7"
|
validator_derive = "0.7"
|
||||||
webfinger = "0.3"
|
webfinger = "0.3.1"
|
||||||
workerpool = "1.1"
|
workerpool = "1.1"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
@ -16,7 +16,7 @@ heck = "0.3.0"
|
|||||||
hex = "0.3"
|
hex = "0.3"
|
||||||
hyper = "0.11.27"
|
hyper = "0.11.27"
|
||||||
openssl = "0.10.11"
|
openssl = "0.10.11"
|
||||||
reqwest = "0.8"
|
reqwest = "0.9"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "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 {
|
for inbox in boxes {
|
||||||
// TODO: run it in Sidekiq or something like that
|
// TODO: run it in Sidekiq or something like that
|
||||||
let mut headers = request::headers();
|
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()
|
let res = Client::new()
|
||||||
.post(&inbox[..])
|
.post(&inbox[..])
|
||||||
.headers(headers.clone())
|
.headers(headers.clone())
|
||||||
.header(request::signature(sender, headers))
|
.header("Signature", request::signature(sender, headers))
|
||||||
.body(signed.to_string())
|
.body(signed.to_string())
|
||||||
.send();
|
.send();
|
||||||
match res {
|
match res {
|
||||||
|
@ -1,31 +1,23 @@
|
|||||||
use base64;
|
use base64;
|
||||||
|
use chrono::{DateTime, offset::Utc};
|
||||||
use openssl::hash::{Hasher, MessageDigest};
|
use openssl::hash::{Hasher, MessageDigest};
|
||||||
use reqwest::{
|
use reqwest::header::{ACCEPT, DATE, HeaderMap, HeaderValue, USER_AGENT};
|
||||||
mime::Mime,
|
|
||||||
header::{Accept, Date, Headers, UserAgent, qitem}
|
|
||||||
};
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use activity_pub::ap_accept_header;
|
use activity_pub::ap_accept_header;
|
||||||
use activity_pub::sign::Signer;
|
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! {
|
pub struct Digest(String);
|
||||||
(Signature, "Signature") => [String]
|
|
||||||
}
|
|
||||||
|
|
||||||
header! {
|
|
||||||
(Digest, "Digest") => [String]
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Digest {
|
impl Digest {
|
||||||
pub fn digest(body: String) -> Self {
|
pub fn digest(body: String) -> HeaderValue {
|
||||||
let mut hasher = Hasher::new(MessageDigest::sha256()).unwrap();
|
let mut hasher = Hasher::new(MessageDigest::sha256()).unwrap();
|
||||||
hasher.update(&body.into_bytes()[..]).unwrap();
|
hasher.update(&body.into_bytes()[..]).unwrap();
|
||||||
let res = base64::encode(&hasher.finish().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 {
|
pub fn verify(&self, body: String) -> bool {
|
||||||
@ -62,25 +54,28 @@ impl Digest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn headers() -> Headers {
|
pub fn headers() -> HeaderMap {
|
||||||
let mut headers = Headers::new();
|
let date: DateTime<Utc> = SystemTime::now().into();
|
||||||
headers.set(UserAgent::new(USER_AGENT));
|
let date = format!("{}", date.format("%a, %d %b %Y %T %Z"));
|
||||||
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()));
|
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
|
headers
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn signature<S: Signer>(signer: &S, headers: Headers) -> Signature {
|
pub fn signature<S: Signer>(signer: &S, headers: HeaderMap) -> HeaderValue {
|
||||||
let signed_string = headers.iter().map(|h| format!("{}: {}", h.name().to_lowercase(), h.value_string())).collect::<Vec<String>>().join("\n");
|
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.name().to_string()).collect::<Vec<String>>().join(" ").to_lowercase();
|
let signed_headers = headers.iter().map(|(h,_)| h.as_str()).collect::<Vec<&str>>().join(" ").to_lowercase();
|
||||||
|
|
||||||
let data = signer.sign(signed_string);
|
let data = signer.sign(signed_string);
|
||||||
let sign = base64::encode(&data[..]);
|
let sign = base64::encode(&data[..]);
|
||||||
|
|
||||||
Signature(format!(
|
HeaderValue::from_str(&format!(
|
||||||
"keyId=\"{key_id}\",algorithm=\"rsa-sha256\",headers=\"{signed_headers}\",signature=\"{signature}\"",
|
"keyId=\"{key_id}\",algorithm=\"rsa-sha256\",headers=\"{signed_headers}\",signature=\"{signature}\"",
|
||||||
key_id = signer.get_key_id(),
|
key_id = signer.get_key_id(),
|
||||||
signed_headers = signed_headers,
|
signed_headers = signed_headers,
|
||||||
signature = sign
|
signature = sign
|
||||||
))
|
)).unwrap()
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ extern crate failure_derive;
|
|||||||
extern crate gettextrs;
|
extern crate gettextrs;
|
||||||
extern crate hex;
|
extern crate hex;
|
||||||
extern crate heck;
|
extern crate heck;
|
||||||
#[macro_use]
|
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate openssl;
|
extern crate openssl;
|
||||||
extern crate pulldown_cmark;
|
extern crate pulldown_cmark;
|
||||||
|
@ -11,12 +11,12 @@ canapi = "0.1"
|
|||||||
heck = "0.3.0"
|
heck = "0.3.0"
|
||||||
lazy_static = "*"
|
lazy_static = "*"
|
||||||
openssl = "0.10.11"
|
openssl = "0.10.11"
|
||||||
reqwest = "0.8"
|
reqwest = "0.9"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
url = "1.7"
|
url = "1.7"
|
||||||
webfinger = "0.3"
|
webfinger = "0.3.1"
|
||||||
|
|
||||||
[dependencies.chrono]
|
[dependencies.chrono]
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
use activitypub::{Actor, Object, CustomObject, actor::Group, collection::OrderedCollection};
|
use activitypub::{Actor, Object, CustomObject, actor::Group, collection::OrderedCollection};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use reqwest::{
|
use reqwest::{Client,
|
||||||
Client,
|
header::{ACCEPT, HeaderValue}
|
||||||
header::{Accept, qitem},
|
|
||||||
mime::Mime
|
|
||||||
};
|
};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@ -120,7 +118,7 @@ impl Blog {
|
|||||||
fn fetch_from_url(conn: &Connection, url: String) -> Option<Blog> {
|
fn fetch_from_url(conn: &Connection, url: String) -> Option<Blog> {
|
||||||
let req = Client::new()
|
let req = Client::new()
|
||||||
.get(&url[..])
|
.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();
|
.send();
|
||||||
match req {
|
match req {
|
||||||
Ok(mut res) => {
|
Ok(mut res) => {
|
||||||
|
@ -20,8 +20,7 @@ use plume_common::activity_pub::{
|
|||||||
};
|
};
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
Client,
|
Client,
|
||||||
header::{Accept, qitem},
|
header::{ACCEPT, HeaderValue}
|
||||||
mime::Mime
|
|
||||||
};
|
};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
request::{self, FromRequest, Request},
|
request::{self, FromRequest, Request},
|
||||||
@ -192,7 +191,7 @@ impl User {
|
|||||||
fn fetch(url: String) -> Option<CustomPerson> {
|
fn fetch(url: String) -> Option<CustomPerson> {
|
||||||
let req = Client::new()
|
let req = Client::new()
|
||||||
.get(&url[..])
|
.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();
|
.send();
|
||||||
match req {
|
match req {
|
||||||
Ok(mut res) => {
|
Ok(mut res) => {
|
||||||
@ -348,7 +347,7 @@ impl User {
|
|||||||
pub fn fetch_outbox<T: Activity>(&self) -> Vec<T> {
|
pub fn fetch_outbox<T: Activity>(&self) -> Vec<T> {
|
||||||
let req = Client::new()
|
let req = Client::new()
|
||||||
.get(&self.outbox_url[..])
|
.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();
|
.send();
|
||||||
match req {
|
match req {
|
||||||
Ok(mut res) => {
|
Ok(mut res) => {
|
||||||
@ -370,7 +369,7 @@ impl User {
|
|||||||
pub fn fetch_followers_ids(&self) -> Vec<String> {
|
pub fn fetch_followers_ids(&self) -> Vec<String> {
|
||||||
let req = Client::new()
|
let req = Client::new()
|
||||||
.get(&self.followers_endpoint[..])
|
.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();
|
.send();
|
||||||
match req {
|
match req {
|
||||||
Ok(mut res) => {
|
Ok(mut res) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user