Refactor ActivityPub handling to prepare for non-Account actors (#19212)
* Move ActivityPub::FetchRemoteAccountService to ActivityPub::FetchRemoteActorService ActivityPub::FetchRemoteAccountService is kept as a wrapper for when the actor is specifically required to be an Account * Refactor SignatureVerification to allow non-Account actors * fixup! Move ActivityPub::FetchRemoteAccountService to ActivityPub::FetchRemoteActorService * Refactor ActivityPub::FetchRemoteKeyService to potentially return non-Account actors * Refactor inbound ActivityPub payload processing to accept non-Account actors * Refactor inbound ActivityPub processing to accept activities relayed through non-Account * Refactor how Account key URIs are built * Refactor Request and drop unused key_id_format parameter * Rename ActivityPub::Dereferencer `signature_account` to `signature_actor`
This commit is contained in:
parent
84aff598ea
commit
8cf7006d4e
41 changed files with 436 additions and 180 deletions
|
@ -5,7 +5,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService
|
|||
|
||||
class Error < StandardError; end
|
||||
|
||||
# Returns account that owns the key
|
||||
# Returns actor that owns the key
|
||||
def call(uri, id: true, prefetched_body: nil, suppress_errors: true)
|
||||
raise Error, 'No key URI given' if uri.blank?
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService
|
|||
raise Error, "Unable to fetch key JSON at #{uri}" if @json.nil?
|
||||
raise Error, "Unsupported JSON-LD context for document #{uri}" unless supported_context?(@json)
|
||||
raise Error, "Unexpected object type for key #{uri}" unless expected_type?
|
||||
return find_account(@json['id'], @json, suppress_errors) if person?
|
||||
return find_actor(@json['id'], @json, suppress_errors) if person?
|
||||
|
||||
@owner = fetch_resource(owner_uri, true)
|
||||
|
||||
|
@ -36,7 +36,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService
|
|||
raise Error, "Unexpected object type for actor #{owner_uri} (expected any of: #{SUPPORTED_TYPES})" unless expected_owner_type?
|
||||
raise Error, "publicKey id for #{owner_uri} does not correspond to #{@json['id']}" unless confirmed_owner?
|
||||
|
||||
find_account(owner_uri, @owner, suppress_errors)
|
||||
find_actor(owner_uri, @owner, suppress_errors)
|
||||
rescue Error => e
|
||||
Rails.logger.debug "Fetching key #{uri} failed: #{e.message}"
|
||||
raise unless suppress_errors
|
||||
|
@ -44,18 +44,18 @@ class ActivityPub::FetchRemoteKeyService < BaseService
|
|||
|
||||
private
|
||||
|
||||
def find_account(uri, prefetched_body, suppress_errors)
|
||||
account = ActivityPub::TagManager.instance.uri_to_resource(uri, Account)
|
||||
account ||= ActivityPub::FetchRemoteAccountService.new.call(uri, prefetched_body: prefetched_body, suppress_errors: suppress_errors)
|
||||
account
|
||||
def find_actor(uri, prefetched_body, suppress_errors)
|
||||
actor = ActivityPub::TagManager.instance.uri_to_actor(uri)
|
||||
actor ||= ActivityPub::FetchRemoteActorService.new.call(uri, prefetched_body: prefetched_body, suppress_errors: suppress_errors)
|
||||
actor
|
||||
end
|
||||
|
||||
def expected_type?
|
||||
person? || public_key?
|
||||
actor? || public_key?
|
||||
end
|
||||
|
||||
def person?
|
||||
equals_or_includes_any?(@json['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES)
|
||||
def actor?
|
||||
equals_or_includes_any?(@json['type'], ActivityPub::FetchRemoteActorService::SUPPORTED_TYPES)
|
||||
end
|
||||
|
||||
def public_key?
|
||||
|
@ -67,7 +67,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService
|
|||
end
|
||||
|
||||
def expected_owner_type?
|
||||
equals_or_includes_any?(@owner['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES)
|
||||
equals_or_includes_any?(@owner['type'], ActivityPub::FetchRemoteActorService::SUPPORTED_TYPES)
|
||||
end
|
||||
|
||||
def confirmed_owner?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue