diff --git a/lib/archive_validator/author_private_key_validator.rb b/lib/archive_validator/author_private_key_validator.rb index 5d72d6f16..a751f1afd 100644 --- a/lib/archive_validator/author_private_key_validator.rb +++ b/lib/archive_validator/author_private_key_validator.rb @@ -6,7 +6,7 @@ class ArchiveValidator def validate 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}") rescue DiasporaFederation::Discovery::DiscoveryError diff --git a/spec/lib/archive_validator/author_private_key_validator_spec.rb b/spec/lib/archive_validator/author_private_key_validator_spec.rb index 5cf14468a..2c93f7520 100644 --- a/spec/lib/archive_validator/author_private_key_validator_spec.rb +++ b/spec/lib/archive_validator/author_private_key_validator_spec.rb @@ -15,9 +15,39 @@ describe ArchiveValidator::AuthorPrivateKeyValidator do end context "when private key matches the key in the archive" do - let(:author) { FactoryGirl.create(:person, serialized_public_key: author_pkey.public_key.export) } + context "with the default key format" do + let(:author_pkey) { OpenSSL::PKey::RSA.generate(512) } + let(:archive_private_key) { author_pkey.export } - include_examples "validation result is valid" + let(:author) { FactoryGirl.create(:person, serialized_public_key: author_pkey.public_key.export) } + + include_examples "validation result is valid" + 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 diff --git a/spec/lib/archive_validator/shared.rb b/spec/lib/archive_validator/shared.rb index 8479e4a45..b5ea74635 100644 --- a/spec/lib/archive_validator/shared.rb +++ b/spec/lib/archive_validator/shared.rb @@ -4,7 +4,7 @@ require "integration/federation/federation_helper" shared_context "validators shared context" do 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(:validator) { described_class.new(input_hash) } @@ -31,7 +31,7 @@ shared_context "validators shared context" do }, username: "aaaa", email: "aaaa@aa.com", - private_key: author_pkey.export, + private_key: archive_private_key, contacts: [], contact_groups: [], posts: [], relayables: [], followed_tags: [], post_subscriptions: [] }, others_data: {relayables: []},