cleanup
This commit is contained in:
parent
7bc76058a6
commit
60456cc0ba
|
@ -5,7 +5,9 @@ defmodule Vonbraun.ActivityPub.Handler.Accept do
|
|||
alias Vonbraun.Ecto.Schema.Actor
|
||||
alias Vonbraun.ActivityPub.Object
|
||||
|
||||
def type, do: "Accept"
|
||||
@verb "Accept"
|
||||
|
||||
def type, do: @verb
|
||||
|
||||
def extract_follow_object_actor(%{"type" => "Follow", "actor" => actor_id})
|
||||
when is_binary(actor_id) do
|
||||
|
@ -32,7 +34,7 @@ defmodule Vonbraun.ActivityPub.Handler.Accept do
|
|||
# Lots of kinds of things can be accepted but for right now only follows.
|
||||
def handle(
|
||||
%{
|
||||
"type" => "Accept",
|
||||
"type" => @verb,
|
||||
"actor" => actor_id,
|
||||
"object" => object = %{"type" => "Follow"}
|
||||
},
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
defmodule Vonbraun.ActivityPub.Handler.Delete do
|
||||
@behaviour Vonbraun.ActivityPub.HandlerBehaviour
|
||||
|
||||
@verb "Delete"
|
||||
|
||||
def type, do: @verb
|
||||
|
||||
# Lots of different kinds of things can be undone.
|
||||
def handle(%{"type" => @verb}, %{}) do
|
||||
{:ok, :ignore}
|
||||
end
|
||||
end
|
|
@ -6,10 +6,12 @@ defmodule Vonbraun.ActivityPub.Handler.Follow do
|
|||
alias Vonbraun.Ecto.Schema.Actor
|
||||
alias Vonbraun.ActivityPub.Object
|
||||
|
||||
def type, do: "Follow"
|
||||
@verb "Follow"
|
||||
|
||||
def type, do: @verb
|
||||
|
||||
def handle(
|
||||
%{"type" => "Follow", "actor" => follow_requester_id, "object" => follow_target},
|
||||
%{"type" => @verb, "actor" => follow_requester_id, "object" => follow_target},
|
||||
actor = %{}
|
||||
)
|
||||
when is_binary(follow_requester_id) and is_binary(follow_target) do
|
||||
|
|
|
@ -6,11 +6,12 @@ defmodule Vonbraun.ActivityPub.Handler.Reject do
|
|||
alias Vonbraun.ActivityPub.Object
|
||||
import Vonbraun.ActivityPub.Handler.Accept, only: [extract_follow_object_actor: 1]
|
||||
|
||||
def type, do: "Reject"
|
||||
@verb "Reject"
|
||||
def type, do: @verb
|
||||
|
||||
# Lots of kinds of things can be rejected but for right now only follows.
|
||||
def handle(%{
|
||||
"type" => "Reject",
|
||||
"type" => @verb,
|
||||
"actor" => actor_id,
|
||||
"object" => object = %{"type" => "Follow"}
|
||||
}) do
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
defmodule Vonbraun.ActivityPub.Handler.Undo do
|
||||
@behaviour Vonbraun.ActivityPub.HandlerBehaviour
|
||||
|
||||
def type, do: "Undo"
|
||||
@verb "Undo"
|
||||
|
||||
def type, do: @verb
|
||||
|
||||
# Lots of different kinds of things can be undone.
|
||||
def handle(%{"type" => "Undo"}, %{}) do
|
||||
def handle(%{"type" => @verb}, %{}) do
|
||||
{:ok, :unknown}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,6 +73,6 @@ defmodule Vonbraun.ActivityPub.Object do
|
|||
accept_activity_id =
|
||||
"https://#{Application.fetch_env!(:vonbraun, :domain)}/id/follow-reply:#{URI.encode(followee_id)}"
|
||||
|
||||
activity(activity_type, accept_activity_id, object)
|
||||
activity(activity_type, accept_activity_id, object, to: followee_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,7 +51,7 @@ defmodule Vonbraun.HTTPSignature do
|
|||
Map.put(headers, "signature", signature_header) |> Map.delete("(request-target)")
|
||||
end
|
||||
|
||||
def verify_post_signature(conn = %Conn{}, public_key) do
|
||||
def verify_post_signature(conn = %Conn{}, raw_body, public_key) when is_binary(raw_body) do
|
||||
target =
|
||||
if conn.query_string && conn.query_string != "" do
|
||||
"#{conn.request_path}?#{conn.query_string}"
|
||||
|
@ -61,8 +61,7 @@ defmodule Vonbraun.HTTPSignature do
|
|||
|
||||
valid_request_target = "post #{target}"
|
||||
|
||||
with {:raw_body, {:ok, raw_body, _}} <- {:raw_body, Conn.read_body(conn)},
|
||||
{:signature_header, [signature_header]} <-
|
||||
with {:signature_header, [signature_header]} <-
|
||||
{:signature_header, Conn.get_req_header(conn, "signature")},
|
||||
{:parse,
|
||||
{:ok,
|
||||
|
|
|
@ -24,12 +24,14 @@ defmodule Vonbraun.InboxRouter do
|
|||
|
||||
cond do
|
||||
conn.params["user"] in [nil, Application.fetch_env!(:vonbraun, :nickname)] ->
|
||||
with {:actor_url, {:ok, activity = %{"actor" => actor_url}}} <-
|
||||
with {:actor_url, {:ok, activity = %{"actor" => actor_url, "type" => activity_type}}}
|
||||
when activity_type != "Delete" <-
|
||||
{:actor_url, Jason.decode(body)},
|
||||
{:actor, {:ok, actor = %{"publicKey" => %{"publicKeyPem" => public_key_pem}}}} <-
|
||||
{:actor, ActivityPubReq.get_cached_actor(actor_url)},
|
||||
{:load, {:ok, public_key}} <- {:load, ExPublicKey.loads(public_key_pem)},
|
||||
{:verify, true} <- {:verify, HTTPSignature.verify_post_signature(conn, public_key)},
|
||||
{:verify, true} <-
|
||||
{:verify, HTTPSignature.verify_post_signature(conn, body, public_key)},
|
||||
{:send, {:ok, response}} <- {:send, handle(activity, actor)} do
|
||||
status_code =
|
||||
case response do
|
||||
|
@ -51,6 +53,10 @@ defmodule Vonbraun.InboxRouter do
|
|||
|
||||
send_resp(conn, status_code, "boop")
|
||||
else
|
||||
{:actor_url, {:ok, %{"type" => "Delete"}}} ->
|
||||
Logger.debug("Ignoring deletes right now.")
|
||||
send_resp(conn, 200, "boop")
|
||||
|
||||
error ->
|
||||
Logger.warning("Some kind of failure: #{inspect(error)}")
|
||||
send_resp(conn, 500, "I fucked up")
|
||||
|
|
Loading…
Reference in New Issue