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.ActivityPub.Utils
14 def call(%{assigns: %{valid_signature: true}} = conn, _opts) do
18 def call(conn, _opts) do
19 user = Utils.get_ap_id(conn.params["actor"])
20 Logger.debug("Checking sig for #{user}")
21 [signature | _] = get_req_header(conn, "signature")
24 signature && String.contains?(signature, user) ->
25 # set (request-target) header to the appropriate value
26 # we also replace the digest header with the one we computed
31 String.downcase("#{conn.method}") <> " #{conn.request_path}"
35 if conn.assigns[:digest] do
37 |> put_req_header("digest", conn.assigns[:digest])
42 assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn))
45 Logger.debug("Signature not from actor")
46 assign(conn, :valid_signature, false)
49 Logger.debug("No signature header!")