X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fplugs%2Fmapped_signature_to_identity_plug.ex;h=84b7c5d83b1e84e9c6b865efa33171335fbd95e4;hb=918a8094fc175ed71ccb7305d606fb0b221163f6;hp=ae933959541eece36ad7a05a01d7fb109c902925;hpb=184fa61fb3a1bc8c5d5515bb7748c12816b11ebf;p=akkoma
diff --git a/lib/pleroma/plugs/mapped_signature_to_identity_plug.ex b/lib/pleroma/plugs/mapped_signature_to_identity_plug.ex
index ae9339595..84b7c5d83 100644
--- a/lib/pleroma/plugs/mapped_signature_to_identity_plug.ex
+++ b/lib/pleroma/plugs/mapped_signature_to_identity_plug.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlug do
@@ -23,7 +23,7 @@ defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlug do
defp user_from_key_id(conn) do
with key_actor_id when is_binary(key_actor_id) <- key_id_from_conn(conn),
- %User{} = user <- User.get_or_fetch_by_ap_id(key_actor_id) do
+ {:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(key_actor_id) do
user
else
_ ->
@@ -31,18 +31,24 @@ defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlug do
end
end
- def call(%{assigns: %{mapped_identity: _}} = conn, _opts), do: conn
+ def call(%{assigns: %{user: _}} = conn, _opts), do: conn
# if this has payload make sure it is signed by the same actor that made it
def call(%{assigns: %{valid_signature: true}, params: %{"actor" => actor}} = conn, _opts) do
with actor_id <- Utils.get_ap_id(actor),
- %User{} = user <- user_from_key_id(conn),
- true <- user.ap_id == actor_id do
- assign(conn, :mapped_identity, user)
+ {:user, %User{} = user} <- {:user, user_from_key_id(conn)},
+ {:user_match, true} <- {:user_match, user.ap_id == actor_id} do
+ assign(conn, :user, user)
else
- _ ->
- Logger.debug("Failed to map identity from signature (payload actor mismatch?)")
- Logger.debug("key_id=#{key_id_from_conn(conn)}, actor=#{actor}")
+ {:user_match, false} ->
+ Logger.debug("Failed to map identity from signature (payload actor mismatch)")
+ Logger.debug("key_id=#{inspect(key_id_from_conn(conn))}, actor=#{inspect(actor)}")
+ assign(conn, :valid_signature, false)
+
+ # remove me once testsuite uses mapped capabilities instead of what we do now
+ {:user, nil} ->
+ Logger.debug("Failed to map identity from signature (lookup failure)")
+ Logger.debug("key_id=#{inspect(key_id_from_conn(conn))}, actor=#{actor}")
conn
end
end
@@ -50,12 +56,12 @@ defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlug do
# no payload, probably a signed fetch
def call(%{assigns: %{valid_signature: true}} = conn, _opts) do
with %User{} = user <- user_from_key_id(conn) do
- assign(conn, :mapped_identity, user)
+ assign(conn, :user, user)
else
_ ->
Logger.debug("Failed to map identity from signature (no payload actor mismatch)")
- Logger.debug("key_id=#{key_id_from_conn(conn)}")
- conn
+ Logger.debug("key_id=#{inspect(key_id_from_conn(conn))}")
+ assign(conn, :valid_signature, false)
end
end