From 873d191569985737ccc815dbb031bbbc18e7e15e Mon Sep 17 00:00:00 2001 From: timokoesters Date: Wed, 22 Apr 2020 21:14:40 +0200 Subject: [PATCH] fix: http body as content when signing --- src/client_server.rs | 2 +- src/server_server.rs | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/client_server.rs b/src/client_server.rs index a2cc5754..dd609f2b 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -756,7 +756,7 @@ pub async fn get_public_rooms_filtered_route( chunk.extend_from_slice( &server_server::send_request( &data, - "https://matrix.koesters.xyz".to_owned(), + "matrix.koesters.xyz".to_owned(), ruma_federation_api::v1::get_public_rooms::Request { limit: None, since: None, diff --git a/src/server_server.rs b/src/server_server.rs index cbdcb6ad..f0fdf655 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -32,24 +32,26 @@ where T::Error: std::fmt::Debug, { let mut http_request: http::Request<_> = request.try_into().unwrap(); - let uri = destination.clone() + T::METADATA.path; - *http_request.uri_mut() = uri.parse().unwrap(); + + *http_request.uri_mut() = ("https://".to_owned() + &destination.clone() + T::METADATA.path).parse().unwrap(); - let body = http_request.body(); - let mut request_json = if !body.is_empty() { - serde_json::to_value(http_request.body()).unwrap() - } else { - serde_json::Map::new().into() + let mut request_map = serde_json::Map::new(); + + if !http_request.body().is_empty() { + request_map.insert("content".to_owned(), + serde_json::to_value(http_request.body()).unwrap()); }; - let request_map = request_json.as_object_mut().unwrap(); - request_map.insert("method".to_owned(), T::METADATA.method.to_string().into()); - request_map.insert("uri".to_owned(), uri.into()); + request_map.insert("uri".to_owned(), T::METADATA.path.into()); request_map.insert("origin".to_owned(), data.hostname().into()); request_map.insert("destination".to_owned(), destination.to_string().into()); + //request_map.insert("signatures".to_owned(), json!({})); + + let mut request_json = request_map.into(); + ruma_signatures::sign_json(data.hostname(), data.keypair(), dbg!(&mut request_json)).unwrap(); + dbg!(&request_json); - ruma_signatures::sign_json(data.hostname(), data.keypair(), &mut request_json).unwrap(); let signatures = request_json["signatures"] .as_object() .unwrap()