mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-14 08:23:59 +00:00
Also sign the digest header
This commit is contained in:
parent
0aa0ea19fb
commit
c1db1042ad
1 changed files with 7 additions and 7 deletions
|
@ -27,13 +27,19 @@ lazy_static! {
|
||||||
/// Signs request headers with the given keypair.
|
/// Signs request headers with the given keypair.
|
||||||
pub async fn sign(
|
pub async fn sign(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
headers: BTreeMap<String, String>,
|
mut headers: BTreeMap<String, String>,
|
||||||
url: &Url,
|
url: &Url,
|
||||||
activity: String,
|
activity: String,
|
||||||
actor_id: &Url,
|
actor_id: &Url,
|
||||||
private_key: String,
|
private_key: String,
|
||||||
) -> Result<Request, LemmyError> {
|
) -> Result<Request, LemmyError> {
|
||||||
let signing_key_id = format!("{}#main-key", actor_id);
|
let signing_key_id = format!("{}#main-key", actor_id);
|
||||||
|
let digest = format!(
|
||||||
|
"{}={}",
|
||||||
|
Sha256::NAME,
|
||||||
|
Sha256::new().compute(activity.as_bytes())
|
||||||
|
);
|
||||||
|
headers.insert("Digest".into(), digest);
|
||||||
|
|
||||||
let mut path_and_query = url.path().to_string();
|
let mut path_and_query = url.path().to_string();
|
||||||
if let Some(query) = url.query() {
|
if let Some(query) = url.query() {
|
||||||
|
@ -49,11 +55,6 @@ pub async fn sign(
|
||||||
Ok(base64::encode(signer.sign_to_vec()?)) as Result<_, LemmyError>
|
Ok(base64::encode(signer.sign_to_vec()?)) as Result<_, LemmyError>
|
||||||
})?
|
})?
|
||||||
.signature_header();
|
.signature_header();
|
||||||
let digest = format!(
|
|
||||||
"{}={}",
|
|
||||||
Sha256::NAME,
|
|
||||||
Sha256::new().compute(activity.as_bytes())
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut header_map = HeaderMap::new();
|
let mut header_map = HeaderMap::new();
|
||||||
for h in headers {
|
for h in headers {
|
||||||
|
@ -66,7 +67,6 @@ pub async fn sign(
|
||||||
.post(&url.to_string())
|
.post(&url.to_string())
|
||||||
.headers(header_map)
|
.headers(header_map)
|
||||||
.header("Signature", signature_header_value)
|
.header("Signature", signature_header_value)
|
||||||
.header("Digest", digest)
|
|
||||||
.body(activity);
|
.body(activity);
|
||||||
|
|
||||||
Ok(signed_request.build()?)
|
Ok(signed_request.build()?)
|
||||||
|
|
Loading…
Reference in a new issue