1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
6 alias Pleroma.Web.HTTPSignatures
7 alias Pleroma.Web.ActivityPub.Utils
15 def call(%{assigns: %{valid_signature: true}} = conn, _opts) do
19 def call(conn, _opts) do
20 user = Utils.get_ap_id(conn.params["actor"])
21 Logger.debug("Checking sig for #{user}")
22 [signature | _] = get_req_header(conn, "signature")
25 signature && String.contains?(signature, user) ->
26 # set (request-target) header to the appropriate value
27 # we also replace the digest header with the one we computed
32 String.downcase("#{conn.method}") <> " #{conn.request_path}"
36 if conn.assigns[:digest] do
38 |> put_req_header("digest", conn.assigns[:digest])
43 assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn))
46 Logger.debug("Signature not from actor")
47 assign(conn, :valid_signature, false)
50 Logger.debug("No signature header!")