AuthorPrivateKeyValidator: support old serialization method of RSA keys

This commit is contained in:
cmrd Senya 2019-04-27 19:17:54 +03:00
parent ee0c3e9865
commit 3c94c1bd29
3 changed files with 35 additions and 5 deletions

View file

@ -6,7 +6,7 @@ class ArchiveValidator
def validate def validate
return if person.nil? return if person.nil?
return if person.serialized_public_key == private_key.public_key.export return if person.public_key.export == private_key.public_key.export
messages.push("Private key in the archive doesn't match the known key of #{person.diaspora_handle}") messages.push("Private key in the archive doesn't match the known key of #{person.diaspora_handle}")
rescue DiasporaFederation::Discovery::DiscoveryError rescue DiasporaFederation::Discovery::DiscoveryError

View file

@ -15,11 +15,41 @@ describe ArchiveValidator::AuthorPrivateKeyValidator do
end end
context "when private key matches the key in the archive" do context "when private key matches the key in the archive" do
context "with the default key format" do
let(:author_pkey) { OpenSSL::PKey::RSA.generate(512) }
let(:archive_private_key) { author_pkey.export }
let(:author) { FactoryGirl.create(:person, serialized_public_key: author_pkey.public_key.export) } let(:author) { FactoryGirl.create(:person, serialized_public_key: author_pkey.public_key.export) }
include_examples "validation result is valid" include_examples "validation result is valid"
end end
context "when key is serialized in pub1 in the DB" do
let(:archive_private_key) { <<~RSA }
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBANswwmiaCy9vleC5L5StCe8+urb/UKQwYpheWA+BFSKf9VLBTbgL
wWMcgoGUqLaS6RrhcGVxml6vKe20lLFpxOECAwEAAQJBAM6RdjXkLvRmgeZGP/wq
03kAMjDyDsqdut2D1BPQf92fCUCh8N000rsiWqZLKf6qz2X6qVeRRnU4JdpHrC03
2z0CIQD3x6hhwGWUjnqEQm/pBtRNrrat0h/LpTNx55wn4JhNswIhAOJ2TCzb5GX0
mQQooR1WJ2OqoUxM66C/XdJRL5r/lKEbAiB0Er8Jk+TCNACm5qygQEfCYF9JjE7C
ypAQAwz/DVKrywIgL0//wi9+nD5p6ZCDeJmTSSNQ55v6bm8Mru//Pia/apkCID3y
m/nJS0EGyGd2SV0gfnawS5llnX9psqIKvBa8mOQ/
-----END RSA PRIVATE KEY-----
RSA
let(:author) {
FactoryGirl.create(:person, serialized_public_key: <<~RSA)
-----BEGIN RSA PUBLIC KEY-----
MEgCQQDbMMJomgsvb5XguS+UrQnvPrq2/1CkMGKYXlgPgRUin/VSwU24C8FjHIKB
lKi2kuka4XBlcZperynttJSxacThAgMBAAE=
-----END RSA PUBLIC KEY-----
RSA
}
include_examples "validation result is valid"
end
end
context "with non-fetchable author" do context "with non-fetchable author" do
let(:author_id) { "old_id@old_pod.nowhere" } let(:author_id) { "old_id@old_pod.nowhere" }

View file

@ -4,7 +4,7 @@ require "integration/federation/federation_helper"
shared_context "validators shared context" do shared_context "validators shared context" do
let(:author_id) { author.diaspora_handle } let(:author_id) { author.diaspora_handle }
let(:author_pkey) { OpenSSL::PKey::RSA.generate(512) } let(:archive_private_key) { OpenSSL::PKey::RSA.generate(512).export }
let(:archive_hash) { base_archive_hash } let(:archive_hash) { base_archive_hash }
let(:validator) { described_class.new(input_hash) } let(:validator) { described_class.new(input_hash) }
@ -31,7 +31,7 @@ shared_context "validators shared context" do
}, },
username: "aaaa", username: "aaaa",
email: "aaaa@aa.com", email: "aaaa@aa.com",
private_key: author_pkey.export, private_key: archive_private_key,
contacts: [], contact_groups: [], posts: [], relayables: [], followed_tags: [], post_subscriptions: [] contacts: [], contact_groups: [], posts: [], relayables: [], followed_tags: [], post_subscriptions: []
}, },
others_data: {relayables: []}, others_data: {relayables: []},