|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Signature do
|
|
|
|
alias Pleroma.Keys
|
|
|
|
alias Pleroma.Keys
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
|
|
|
|
alias Pleroma.Web.ActivityPub.ObjectValidators.Types
|
|
|
|
|
|
|
|
|
|
|
|
def key_id_to_actor_id(key_id) do
|
|
|
|
def key_id_to_actor_id(key_id) do
|
|
|
|
uri =
|
|
|
|
uri =
|
|
|
@ -21,12 +22,23 @@ defmodule Pleroma.Signature do
|
|
|
|
uri
|
|
|
|
uri
|
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_public_key(conn) do
|
|
|
|
def fetch_public_key(conn) do
|
|
|
|
with %{"keyId" => kid} <- HTTPSignatures.signature_for_conn(conn),
|
|
|
|
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} <- User.get_public_key_for_ap_id(actor_id) do
|
|
|
|
{:ok, public_key}
|
|
|
|
{:ok, public_key}
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -37,7 +49,7 @@ defmodule Pleroma.Signature do
|
|
|
|
|
|
|
|
|
|
|
|
def refetch_public_key(conn) do
|
|
|
|
def refetch_public_key(conn) do
|
|
|
|
with %{"keyId" => kid} <- HTTPSignatures.signature_for_conn(conn),
|
|
|
|
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, _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} <- User.get_public_key_for_ap_id(actor_id) do
|
|
|
|
{:ok, public_key}
|
|
|
|
{:ok, public_key}
|
|
|
|