fix: http body as content when signing

This commit is contained in:
timokoesters 2020-04-22 21:14:40 +02:00
parent 1af6dd984a
commit 873d191569
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
2 changed files with 14 additions and 12 deletions

View file

@ -756,7 +756,7 @@ pub async fn get_public_rooms_filtered_route(
chunk.extend_from_slice( chunk.extend_from_slice(
&server_server::send_request( &server_server::send_request(
&data, &data,
"https://matrix.koesters.xyz".to_owned(), "matrix.koesters.xyz".to_owned(),
ruma_federation_api::v1::get_public_rooms::Request { ruma_federation_api::v1::get_public_rooms::Request {
limit: None, limit: None,
since: None, since: None,

View file

@ -32,24 +32,26 @@ where
T::Error: std::fmt::Debug, T::Error: std::fmt::Debug,
{ {
let mut http_request: http::Request<_> = request.try_into().unwrap(); 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_map = serde_json::Map::new();
let mut request_json = if !body.is_empty() {
serde_json::to_value(http_request.body()).unwrap() if !http_request.body().is_empty() {
} else { request_map.insert("content".to_owned(),
serde_json::Map::new().into() 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("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("origin".to_owned(), data.hostname().into());
request_map.insert("destination".to_owned(), destination.to_string().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"] let signatures = request_json["signatures"]
.as_object() .as_object()
.unwrap() .unwrap()