From d330c57cda8d5d714688ef9dd677fa5b0d228867 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Sat, 26 Oct 2024 08:42:07 +0100 Subject: [PATCH] make sure we correctly match key objects --- lib/pleroma/user/signing_key.ex | 17 +++++++++++++++-- .../20240625220752_move_signing_keys.exs | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/user/signing_key.ex b/lib/pleroma/user/signing_key.ex index 709ee2593..f88faf70f 100644 --- a/lib/pleroma/user/signing_key.ex +++ b/lib/pleroma/user/signing_key.ex @@ -2,6 +2,7 @@ defmodule Pleroma.User.SigningKey do use Ecto.Schema import Ecto.Query import Ecto.Changeset + require Pleroma.Constants alias Pleroma.User alias Pleroma.Repo @@ -185,7 +186,6 @@ def get_or_fetch_by_key_id(key_id) do """ def fetch_remote_key(key_id) do Logger.debug("Fetching remote key: #{key_id}") - # we should probably sign this, just in case resp = Pleroma.Object.Fetcher.fetch_and_contain_remote_object_from_id(key_id) case resp do @@ -228,7 +228,20 @@ defp extract_key_details(%{"id" => ap_id, "publicKey" => public_key}) do defp handle_signature_response({:ok, body}) do case body do - %{"id" => _user_id, "publicKey" => _public_key} -> + %{ + "type" => "CryptographicKey", + "publicKeyPem" => public_key_pem, + "owner" => ap_id + } -> + {:ok, ap_id, public_key_pem} + + # for when we get a subset of the user object + %{ + "id" => _user_id, + "publicKey" => _public_key, + "type" => actor_type + } + when actor_type in Pleroma.Constants.actor_types() -> extract_key_details(body) %{"error" => error} -> diff --git a/priv/repo/migrations/20240625220752_move_signing_keys.exs b/priv/repo/migrations/20240625220752_move_signing_keys.exs index 9531ceed8..4e8eef6c9 100644 --- a/priv/repo/migrations/20240625220752_move_signing_keys.exs +++ b/priv/repo/migrations/20240625220752_move_signing_keys.exs @@ -23,7 +23,7 @@ def up do key = %User.SigningKey{ user_id: user_id, public_key: public_key, - key_id: "#{ap_id}#main-key", + key_id: "#{ap_id}#main-key", private_key: private_key }