Merge branch 'stable' into mergeback/2.2.2
[akkoma] / lib / pleroma / signature.ex
index 7006eb2c05ec6db2d16eac147ea69e67f2636597..43ab569a4e70e19f0e4596898f15e0d4c19eb49c 100644 (file)
@@ -1,10 +1,11 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Signature do
   @behaviour HTTPSignatures.Adapter
 
+  alias Pleroma.EctoType.ActivityPub.ObjectValidators
   alias Pleroma.Keys
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
@@ -21,14 +22,16 @@ defmodule Pleroma.Signature do
         uri
       end
 
-    case uri do
-      %URI{scheme: scheme} when scheme in ["https", "http"] ->
-        {:ok, URI.to_string(uri)}
+    maybe_ap_id = URI.to_string(uri)
+
+    case ObjectValidators.ObjectID.cast(maybe_ap_id) do
+      {:ok, ap_id} ->
+        {:ok, ap_id}
 
       _ ->
-        case Pleroma.Web.WebFinger.finger(URI.to_string(uri)) do
+        case Pleroma.Web.WebFinger.finger(maybe_ap_id) do
           %{"ap_id" => ap_id} -> {:ok, ap_id}
-          _ -> {:error, URI.to_string(uri)}
+          _ -> {:error, maybe_ap_id}
         end
     end
   end