Add host to signatures

This commit is contained in:
asonix 2020-09-07 13:34:29 -05:00
parent 1d0a1d7cfd
commit b6e25df717
4 changed files with 260 additions and 235 deletions

458
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -33,7 +33,7 @@ env_logger = "0.7.1"
futures = "0.3.4"
http-signature-normalization-actix = { version = "0.4.0-alpha.1", default-features = false, features = ["sha-2"] }
log = "0.4"
lru = "0.5.1"
lru = "0.6.0"
mime = "0.3.16"
num_cpus = "1.12"
pretty_env_logger = "0.4.0"
@ -54,7 +54,7 @@ uuid = { version = "0.8", features = ["v4", "serde"] }
[build-dependencies]
anyhow = "1.0"
dotenv = "0.15.0"
ructe = { version = "0.11.0", features = ["sass", "mime03"] }
ructe = { version = "0.12.0", features = ["sass", "mime03"] }
[profile.dev.package.rsa]
opt-level = 3

View file

@ -96,6 +96,9 @@ pub enum MyError {
#[error("Response from {0} has invalid status code, {1}")]
Status(String, StatusCode),
#[error("Uri {0} is missing host")]
Host(String),
#[error("Expected an Object, found something else")]
ObjectFormat,

View file

@ -77,8 +77,14 @@ impl Requests {
let signer = self.signer();
let client: Client = self.client.borrow().clone();
let res = client
.get(url)
let req = client.get(url);
let host = req
.get_uri()
.host()
.ok_or(MyError::Host(url.to_string()))?
.to_string();
let res = req
.header("Host", host)
.header("Accept", accept)
.set(Date(SystemTime::now().into()))
.signature(
@ -123,8 +129,14 @@ impl Requests {
let signer = self.signer();
let client: Client = self.client.borrow().clone();
let res = client
.get(url)
let req = client.get(url);
let host = req
.get_uri()
.host()
.ok_or(MyError::Host(url.to_string()))?
.to_string();
let res = req
.header("Host", host)
.header("Accept", "*/*")
.set(Date(SystemTime::now().into()))
.signature(
@ -184,8 +196,14 @@ impl Requests {
let item_string = serde_json::to_string(item)?;
let client: Client = self.client.borrow().clone();
let res = client
.post(inbox.as_str())
let req = client.post(inbox.as_str());
let host = req
.get_uri()
.host()
.ok_or(MyError::Host(inbox.to_string()))?
.to_string();
let res = req
.header("Host", host)
.header("Accept", "application/activity+json")
.header("Content-Type", "application/activity+json")
.set(Date(SystemTime::now().into()))