2024-06-27 20:00:10 -06:00
|
|
|
defmodule Pleroma.Web.Plugs.EnsureUserPublicKeyPlug do
|
|
|
|
@moduledoc """
|
|
|
|
This plug will attempt to pull in a user's public key if we do not have it.
|
|
|
|
We _should_ be able to request the URL from the key URL...
|
|
|
|
"""
|
|
|
|
|
|
|
|
import Plug.Conn
|
|
|
|
|
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
def init(options), do: options
|
|
|
|
|
|
|
|
def call(conn, _opts) do
|
|
|
|
key_id = key_id_from_conn(conn)
|
2024-06-27 20:22:11 -06:00
|
|
|
|
2024-06-27 20:00:10 -06:00
|
|
|
unless is_nil(key_id) do
|
2024-06-29 21:25:55 -06:00
|
|
|
User.SigningKey.fetch_remote_key(key_id)
|
2024-06-27 20:00:10 -06:00
|
|
|
# now we SHOULD have the user that owns the key locally. maybe.
|
|
|
|
# if we don't, we'll error out when we try to validate.
|
|
|
|
end
|
|
|
|
|
|
|
|
conn
|
|
|
|
end
|
|
|
|
|
|
|
|
defp key_id_from_conn(conn) do
|
|
|
|
case HTTPSignatures.signature_for_conn(conn) do
|
|
|
|
%{"keyId" => key_id} when is_binary(key_id) ->
|
|
|
|
key_id
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|