Sign body contents for federation request if present

This commit is contained in:
Pim Kunis 2021-08-14 17:15:02 +02:00
parent be9860f7d0
commit 46231b9b09

View file

@ -12,7 +12,7 @@ defmodule MatrixServerWeb.Federation.Middleware.SignRequest do
defp sign_request(env, false), do: env
defp sign_request(%Tesla.Env{method: method, url: path, opts: opts} = env, true) do
defp sign_request(%Tesla.Env{method: method, url: path, opts: opts, body: body} = env, true) do
origin = MatrixServer.server_name()
object_to_sign = %{
@ -22,6 +22,9 @@ defmodule MatrixServerWeb.Federation.Middleware.SignRequest do
destination: Keyword.fetch!(opts, :server_name)
}
object_to_sign =
if not is_nil(body), do: Map.put(object_to_sign, :content, body), else: object_to_sign
with {:ok, sig, key_id} <- MatrixServer.KeyServer.sign_object(object_to_sign) do
sigs = %{origin => %{key_id => sig}}
auth_headers = create_signature_authorization_headers(sigs, origin)