Merge branch 'feature/emoji-in-local-users' into 'develop'
[akkoma] / lib / pleroma / web / activity_pub / activity_pub.ex
index 93219d76ab6e0cce29f93cefd2c25ebfcc658a15..cb14f6a577dc1ffb3ef8d5c47809f54e5597c62b 100644 (file)
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   end
 
   def insert(map, local \\ true) when is_map(map) do
-    with nil <- Activity.get_by_ap_id(map["id"]),
+    with nil <- Activity.normalize(map),
          map <- lazy_put_activity_defaults(map),
          :ok <- check_actor_is_active(map["actor"]),
          {:ok, map} <- MRF.filter(map),
@@ -565,7 +565,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   def fetch_and_prepare_user_from_ap_id(ap_id) do
     with {:ok, %{status_code: 200, body: body}} <-
-           @httpoison.get(ap_id, Accept: "application/activity+json"),
+           @httpoison.get(ap_id, [Accept: "application/activity+json"], follow_redirect: true),
          {:ok, data} <- Jason.decode(body) do
       user_data_from_user_object(data)
     else
@@ -641,13 +641,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     Logger.info("Federating #{id} to #{inbox}")
     host = URI.parse(inbox).host
 
+    digest = "SHA-256=" <> (:crypto.hash(:sha256, json) |> Base.encode64())
+
     signature =
-      Pleroma.Web.HTTPSignatures.sign(actor, %{host: host, "content-length": byte_size(json)})
+      Pleroma.Web.HTTPSignatures.sign(actor, %{
+        host: host,
+        "content-length": byte_size(json),
+        digest: digest
+      })
 
     @httpoison.post(
       inbox,
       json,
-      [{"Content-Type", "application/activity+json"}, {"signature", signature}],
+      [
+        {"Content-Type", "application/activity+json"},
+        {"signature", signature},
+        {"digest", digest}
+      ],
       hackney: [pool: :default]
     )
   end