[WiP] Change keypair generation for new local users to use the `keypairs` table

pull/37931/head
Claire 15 hours ago
parent d62e75100c
commit 7dda4d7fbf

@ -459,11 +459,11 @@ class Account < ApplicationRecord
end
before_validation :prepare_contents, if: :local?
before_create :generate_keys
after_create_commit :generate_keys
before_destroy :clean_feed_manager
def ensure_keys!
return unless local? && private_key.blank? && public_key.blank?
return unless local? && private_key.blank? && public_key.blank? && keypairs.empty?
generate_keys
save!
@ -481,11 +481,10 @@ class Account < ApplicationRecord
end
def generate_keys
return unless local? && private_key.blank? && public_key.blank?
return unless local? && private_key.blank? && public_key.blank? && keypairs.empty?
keypair = OpenSSL::PKey::RSA.new(2048)
self.private_key = keypair.to_pem
self.public_key = keypair.public_key.to_pem
keypairs.create!(uri: ActivityPub::TagManager.instance.key_uri_for(self), type: :rsa, public_key: keypair.public_key.to_pem, private_key: keypair.to_pem)
end
def normalize_domain

@ -752,9 +752,8 @@ RSpec.describe Account do
it 'generates keys' do
account = described_class.create!(domain: nil, username: 'user_without_keys')
expect(account)
.to be_private_key
.and be_public_key
expect(account.private_key).to be_nil
expect(account.public_key).to eq ''
expect(account.keypair.keypair)
.to be_private
.and be_public

Loading…
Cancel
Save