1 defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
2 alias Pleroma.Web.HTTPSignatures
3 alias Pleroma.Web.ActivityPub.Utils
11 def call(%{assigns: %{valid_signature: true}} = conn, _opts) do
15 def call(conn, _opts) do
16 user = Utils.get_ap_id(conn.params["actor"])
17 Logger.debug("Checking sig for #{user}")
18 [signature | _] = get_req_header(conn, "signature")
21 signature && String.contains?(signature, user) ->
22 # set (request-target) header to the appropriate value
23 # we also replace the digest header with the one we computed
28 String.downcase("#{conn.method}") <> " #{conn.request_path}"
32 if conn.assigns[:digest] do
34 |> put_req_header("digest", conn.assigns[:digest])
39 assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn))
42 Logger.debug("Signature not from actor")
43 assign(conn, :valid_signature, false)
46 Logger.debug("No signature header!")