Change code to use first usable keypairs record for local user for signing, if it exists (#39662)

This commit is contained in:
Claire authored and GitHub committed 2026-07-01 12:49:42 +00:00
1 parent 68627adff4
commit 7fc19f81aa
14 files changed
+115 -33

No files matched your search

+16 -2
View File
@@ -301,8 +301,22 @@ class Account < ApplicationRecord
strikes.where(overruled_at: nil).count
end
def keypair
@keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
def keypair(type: nil)
# Pick the first (oldest) keypair matching the expected type,
# as we can expect our key rotation code to add stand-by keys with higher IDs
# before pruning older keys with lower IDs after some time.
scope = keypairs.usable.order(id: :asc)
scope = scope.where(type: type) if type.present?
case type
when :rsa, nil
# The legacy key is always RSA, so only fallback
# when no other type is requested
scope.first || Keypair.from_legacy_account(self)
else
scope.first
end
end
def tags_as_strings=(tag_names)
+24
View File
@@ -50,6 +50,12 @@ class Keypair < ApplicationRecord
alias actor account
def full_uri
return ActivityPub::TagManager.instance.uri_for(account) + local_fragment if local_fragment.present?
uri
end
def keypair
@keypair ||= begin
case type
@@ -87,4 +93,22 @@ class Keypair < ApplicationRecord
type: :rsa
)
end
def self.from_worker_arg(account, private_key_pem_or_hash)
if private_key_pem_or_hash.is_a?(String)
account.keypairs.build(
private_key: private_key_pem_or_hash,
local_fragment: '#main-key',
type: :rsa
)
else
account.keypairs.build(
private_key: private_key_pem_or_hash['private_key'],
public_key: private_key_pem_or_hash['public_key'],
uri: private_key_pem_or_hash['uri'],
local_fragment: private_key_pem_or_hash['local_fragment'],
type: private_key_pem_or_hash['type']
)
end
end
end