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