diff --git a/Changelog.md b/Changelog.md index cd78e1cd0..b4ee90943 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 1f86c28bc..f4a5202ad 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 49ff3da6c..aff729ec4 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 bb2bb7d6b..f9e76db51 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) }