diff --git a/Changelog.md b/Changelog.md index cd78e1cd0853dd59d59991d43d04b47a37e7a27a..b4ee9094353dd396e04c77c01a89c9da30da911f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ * Make photo upload button hover text translatable [#7429](https://github.com/diaspora/diaspora/pull/7429) * Fix first comment in mobile view with french locale [#7441](https://github.com/diaspora/diaspora/pull/7441) * Use post page title and post author in atom feed [#7420](https://github.com/diaspora/diaspora/pull/7420) +* Handle broken public keys when receiving posts [#7448](https://github.com/diaspora/diaspora/pull/7448) ## Features diff --git a/app/models/person.rb b/app/models/person.rb index 1f86c28bcd580e649dbfa1bf4f66da3ee4531072..f4a5202adeebbe33d6b03a46aa90ad7c01d26250 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -229,6 +229,8 @@ class Person < ActiveRecord::Base def public_key OpenSSL::PKey::RSA.new(serialized_public_key) + rescue OpenSSL::PKey::RSAError + nil end def exported_key diff --git a/config/initializers/diaspora_federation.rb b/config/initializers/diaspora_federation.rb index 49ff3da6cd0533cc114c3a4997c49078b895f3d6..aff729ec4bec31b17512a00aa72807e2900ff239 100644 --- a/config/initializers/diaspora_federation.rb +++ b/config/initializers/diaspora_federation.rb @@ -72,8 +72,7 @@ DiasporaFederation.configure do |config| end on :fetch_public_key do |diaspora_id| - key = Person.find_or_fetch_by_identifier(diaspora_id).serialized_public_key - OpenSSL::PKey::RSA.new(key) unless key.nil? + Person.find_or_fetch_by_identifier(diaspora_id).public_key end on :fetch_related_entity do |entity_type, guid| diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index bb2bb7d6b9481e41773a71b3a3d103367329efda..f9e76db5129ca8cee26fad920b127223d07bd8ec 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -479,6 +479,19 @@ describe Person, :type => :model do end end + describe "#public_key" do + it "returns the public key for the person" do + key = @person.public_key + expect(key).to be_a(OpenSSL::PKey::RSA) + expect(key.to_s).to eq(@person.serialized_public_key) + end + + it "handles broken keys and returns nil" do + @person.update_attributes(serialized_public_key: "broken") + expect(@person.public_key).to be_nil + end + end + context 'people finders for webfinger' do let(:user) { FactoryGirl.create(:user) } let(:person) { FactoryGirl.create(:person) }