aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-05-01 16:48:31 +0000
committerrinpatch <rinpatch@sdf.org>2020-05-01 16:48:31 +0000
commited8282c0910e5a07b87a6efbf4eb34208a8f39e1 (patch)
tree74ac34a1f24e98c7f3f2d94fe564cf9ab18c9816 /lib
parented4e9e6435cdc4740cf12464f01ffdb5a6a96583 (diff)
parent3453e54e6b00ca2aced07746ad4cfc22ebc404fb (diff)
downloadpleroma-ed8282c0910e5a07b87a6efbf4eb34208a8f39e1.tar.gz
Merge branch 'bugfix/1727-fix-signature-decoding' into 'develop'
Bugfix/1727 fix signature decoding Closes #1727 See merge request pleroma/pleroma!2454
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/plugs/mapped_signature_to_identity_plug.ex5
-rw-r--r--lib/pleroma/signature.ex18
2 files changed, 18 insertions, 5 deletions
diff --git a/lib/pleroma/plugs/mapped_signature_to_identity_plug.ex b/lib/pleroma/plugs/mapped_signature_to_identity_plug.ex
index 84b7c5d83..f44d4dee5 100644
--- a/lib/pleroma/plugs/mapped_signature_to_identity_plug.ex
+++ b/lib/pleroma/plugs/mapped_signature_to_identity_plug.ex
@@ -13,8 +13,9 @@ defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlug do
def init(options), do: options
defp key_id_from_conn(conn) do
- with %{"keyId" => key_id} <- HTTPSignatures.signature_for_conn(conn) do
- Signature.key_id_to_actor_id(key_id)
+ with %{"keyId" => key_id} <- HTTPSignatures.signature_for_conn(conn),
+ {:ok, ap_id} <- Signature.key_id_to_actor_id(key_id) do
+ ap_id
else
_ ->
nil
diff --git a/lib/pleroma/signature.ex b/lib/pleroma/signature.ex
index 6b0b2c969..d01728361 100644
--- a/lib/pleroma/signature.ex
+++ b/lib/pleroma/signature.ex
@@ -8,6 +8,7 @@ defmodule Pleroma.Signature do
alias Pleroma.Keys
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.ObjectValidators.Types
def key_id_to_actor_id(key_id) do
uri =
@@ -21,12 +22,23 @@ defmodule Pleroma.Signature do
uri
end
- URI.to_string(uri)
+ maybe_ap_id = URI.to_string(uri)
+
+ case Types.ObjectID.cast(maybe_ap_id) do
+ {:ok, ap_id} ->
+ {:ok, ap_id}
+
+ _ ->
+ case Pleroma.Web.WebFinger.finger(maybe_ap_id) do
+ %{"ap_id" => ap_id} -> {:ok, ap_id}
+ _ -> {:error, maybe_ap_id}
+ end
+ end
end
def fetch_public_key(conn) do
with %{"keyId" => kid} <- HTTPSignatures.signature_for_conn(conn),
- actor_id <- key_id_to_actor_id(kid),
+ {:ok, actor_id} <- key_id_to_actor_id(kid),
{:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do
{:ok, public_key}
else
@@ -37,7 +49,7 @@ defmodule Pleroma.Signature do
def refetch_public_key(conn) do
with %{"keyId" => kid} <- HTTPSignatures.signature_for_conn(conn),
- actor_id <- key_id_to_actor_id(kid),
+ {:ok, actor_id} <- key_id_to_actor_id(kid),
{:ok, _user} <- ActivityPub.make_user_from_ap_id(actor_id),
{:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do
{:ok, public_key}