use shorter callback keys for key-callbacks

This commit is contained in:
Benjamin Neff 2016-03-29 02:42:19 +02:00
parent 2db0931ce5
commit 1d4d3d732d
19 changed files with 69 additions and 73 deletions

View file

@ -29,7 +29,7 @@ module DiasporaFederation
end end
def create_magic_envelope(entity) def create_magic_envelope(entity)
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, entity.author) privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, entity.author)
Salmon::MagicEnvelope.new(entity, entity.author).envelop(privkey) if privkey Salmon::MagicEnvelope.new(entity, entity.author).envelop(privkey) if privkey
end end
end end

View file

@ -23,8 +23,8 @@ module DiasporaFederation
fetch_person_for_webfinger fetch_person_for_webfinger
fetch_person_for_hcard fetch_person_for_hcard
save_person_after_webfinger save_person_after_webfinger
fetch_private_key_by_diaspora_id fetch_private_key
fetch_public_key_by_diaspora_id fetch_public_key
fetch_related_entity fetch_related_entity
queue_public_receive queue_public_receive
queue_private_receive queue_private_receive
@ -143,12 +143,12 @@ module DiasporaFederation
# so the application saves the person data # so the application saves the person data
# @param [DiasporaFederation::Entities::Person] person data # @param [DiasporaFederation::Entities::Person] person data
# #
# fetch_private_key_by_diaspora_id # fetch_private_key
# Fetches a private key of a person by her Diaspora ID from the application # Fetches a private key of a person by her Diaspora ID from the application
# @param [String] Diaspora ID of the person # @param [String] Diaspora ID of the person
# @return [OpenSSL::PKey::RSA] key # @return [OpenSSL::PKey::RSA] key
# #
# fetch_public_key_by_diaspora_id # fetch_public_key
# Fetches a public key of a person by her Diaspora ID from the application # Fetches a public key of a person by her Diaspora ID from the application
# @param [String] Diaspora ID of the person # @param [String] Diaspora ID of the person
# @return [OpenSSL::PKey::RSA] key # @return [OpenSSL::PKey::RSA] key

View file

@ -82,7 +82,7 @@ module DiasporaFederation
# verifies the signatures (+author_signature+ and +parent_author_signature+ if needed) # verifies the signatures (+author_signature+ and +parent_author_signature+ if needed)
# @raise [SignatureVerificationFailed] if the signature is not valid or no public key is found # @raise [SignatureVerificationFailed] if the signature is not valid or no public key is found
def verify_signatures def verify_signatures
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key_by_diaspora_id, author) pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, author)
raise PublicKeyNotFound, "author_signature author=#{author} guid=#{guid}" if pubkey.nil? raise PublicKeyNotFound, "author_signature author=#{author} guid=#{guid}" if pubkey.nil?
raise SignatureVerificationFailed, "wrong author_signature" unless verify_signature(pubkey, author_signature) raise SignatureVerificationFailed, "wrong author_signature" unless verify_signature(pubkey, author_signature)
@ -93,7 +93,7 @@ module DiasporaFederation
# this happens only on downstream federation # this happens only on downstream federation
def verify_parent_author_signature def verify_parent_author_signature
pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key_by_diaspora_id, parent.author) pubkey = DiasporaFederation.callbacks.trigger(:fetch_public_key, parent.author)
raise PublicKeyNotFound, "parent_author_signature parent_author=#{parent.author} guid=#{guid}" if pubkey.nil? raise PublicKeyNotFound, "parent_author_signature parent_author=#{parent.author} guid=#{guid}" if pubkey.nil?
unless verify_signature(pubkey, parent_author_signature) unless verify_signature(pubkey, parent_author_signature)
raise SignatureVerificationFailed, "wrong parent_author_signature parent_guid=#{parent_guid}" raise SignatureVerificationFailed, "wrong parent_author_signature parent_guid=#{parent_guid}"
@ -120,7 +120,7 @@ module DiasporaFederation
# @raise [AuthorPrivateKeyNotFound] if the author private key is not found # @raise [AuthorPrivateKeyNotFound] if the author private key is not found
# @return [String] A Base64 encoded signature of #signature_data with key # @return [String] A Base64 encoded signature of #signature_data with key
def sign_with_author def sign_with_author
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, author) privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
raise AuthorPrivateKeyNotFound, "author=#{author} guid=#{guid}" if privkey.nil? raise AuthorPrivateKeyNotFound, "author=#{author} guid=#{guid}" if privkey.nil?
sign_with_key(privkey).tap do sign_with_key(privkey).tap do
logger.info "event=sign status=complete signature=author_signature author=#{author} guid=#{guid}" logger.info "event=sign status=complete signature=author_signature author=#{author} guid=#{guid}"
@ -130,7 +130,7 @@ module DiasporaFederation
# sign with parent author key, if the parent author is local (if the private key is found) # sign with parent author key, if the parent author is local (if the private key is found)
# @return [String] A Base64 encoded signature of #signature_data with key # @return [String] A Base64 encoded signature of #signature_data with key
def sign_with_parent_author_if_available def sign_with_parent_author_if_available
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, parent.author) privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, parent.author)
if privkey if privkey
sign_with_key(privkey).tap do sign_with_key(privkey).tap do
logger.info "event=sign status=complete signature=parent_author_signature guid=#{guid}" logger.info "event=sign status=complete signature=parent_author_signature guid=#{guid}"

View file

@ -88,7 +88,7 @@ module DiasporaFederation
# #
# @return [Hash] xml elements with updated signatures # @return [Hash] xml elements with updated signatures
def xml_elements def xml_elements
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, author) privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
super.tap do |xml_elements| super.tap do |xml_elements|
fill_required_signature(privkey, xml_elements) unless privkey.nil? fill_required_signature(privkey, xml_elements) unless privkey.nil?

View file

@ -79,7 +79,7 @@ module DiasporaFederation
end end
def sign_with_author def sign_with_author
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, author) privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
SignedRetraction.sign_with_key(privkey, self) unless privkey.nil? SignedRetraction.sign_with_key(privkey, self) unless privkey.nil?
end end
end end

View file

@ -176,7 +176,7 @@ module DiasporaFederation
env.at_xpath("me:encoding").content, env.at_xpath("me:encoding").content,
env.at_xpath("me:alg").content]) env.at_xpath("me:alg").content])
sender_key = DiasporaFederation.callbacks.trigger(:fetch_public_key_by_diaspora_id, sender) sender_key = DiasporaFederation.callbacks.trigger(:fetch_public_key, sender)
raise SenderKeyNotFound unless sender_key raise SenderKeyNotFound unless sender_key
sig = Base64.urlsafe_decode64(env.at_xpath("me:sig").content) sig = Base64.urlsafe_decode64(env.at_xpath("me:sig").content)

View file

@ -11,13 +11,13 @@ module DiasporaFederation
:fetch_public_entity, "StatusMessage", guid :fetch_public_entity, "StatusMessage", guid
).and_return(post) ).and_return(post)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, alice.diaspora_id :fetch_private_key, alice.diaspora_id
).and_return(alice.private_key) ).and_return(alice.private_key)
get :fetch, type: "status_message", guid: guid get :fetch, type: "status_message", guid: guid
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, alice.diaspora_id :fetch_public_key, alice.diaspora_id
).and_return(alice.public_key) ).and_return(alice.public_key)
magic_env_xml = Nokogiri::XML::Document.parse(response.body).root magic_env_xml = Nokogiri::XML::Document.parse(response.body).root
@ -36,13 +36,13 @@ module DiasporaFederation
:fetch_public_entity, "Post", guid :fetch_public_entity, "Post", guid
).and_return(post) ).and_return(post)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, alice.diaspora_id :fetch_private_key, alice.diaspora_id
).and_return(alice.private_key) ).and_return(alice.private_key)
get :fetch, type: "post", guid: guid get :fetch, type: "post", guid: guid
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, alice.diaspora_id :fetch_public_key, alice.diaspora_id
).and_return(alice.public_key) ).and_return(alice.public_key)
magic_env_xml = Nokogiri::XML::Document.parse(response.body).root magic_env_xml = Nokogiri::XML::Document.parse(response.body).root
@ -61,7 +61,7 @@ module DiasporaFederation
:fetch_public_entity, "Post", guid :fetch_public_entity, "Post", guid
).and_return(post) ).and_return(post)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, alice.diaspora_id :fetch_private_key, alice.diaspora_id
).and_return(nil) ).and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_person_url_to, alice.diaspora_id, "/fetch/post/#{guid}" :fetch_person_url_to, alice.diaspora_id, "/fetch/post/#{guid}"

View file

@ -188,10 +188,10 @@ XML
context "test-data creation" do context "test-data creation" do
it "creates comment xml" do it "creates comment xml" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, author :fetch_private_key, author
).and_return(author_key) ).and_return(author_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, parent.author :fetch_private_key, parent.author
).and_return(nil) ).and_return(nil)
comment.to_xml comment.to_xml
@ -199,10 +199,10 @@ XML
it "creates relayed comment xml" do it "creates relayed comment xml" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_key.public_key) ).and_return(author_key.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, parent.author :fetch_private_key, parent.author
).and_return(parent_key) ).and_return(parent_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_related_entity, "Post", parent_guid :fetch_related_entity, "Post", parent_guid
@ -216,10 +216,10 @@ XML
context "relaying on bobs pod" do context "relaying on bobs pod" do
before do before do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_key.public_key) ).and_return(author_key.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, parent.author :fetch_private_key, parent.author
).and_return(parent_key) ).and_return(parent_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_related_entity, "Post", parent_guid :fetch_related_entity, "Post", parent_guid
@ -250,10 +250,10 @@ XML
before do before do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_key.public_key) ).and_return(author_key.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, parent.author :fetch_public_key, parent.author
).and_return(parent_key.public_key) ).and_return(parent_key.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_related_entity, "Post", parent_guid :fetch_related_entity, "Post", parent_guid

View file

@ -45,7 +45,7 @@ XML
it "updates author signature when it was nil and key was supplied" do it "updates author signature when it was nil and key was supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:author] :fetch_private_key, hash[:author]
).and_return(author_pkey) ).and_return(author_pkey)
signed_string = "#{hash[:target_guid]};#{hash[:target_type]}" signed_string = "#{hash[:target_guid]};#{hash[:target_type]}"
@ -61,7 +61,7 @@ XML
hash[:target] = FactoryGirl.build(:related_entity, author: bob.diaspora_id, parent: parent) hash[:target] = FactoryGirl.build(:related_entity, author: bob.diaspora_id, parent: parent)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:author] :fetch_private_key, hash[:author]
).and_return(author_pkey) ).and_return(author_pkey)
signed_string = "#{hash[:target_guid]};#{hash[:target_type]}" signed_string = "#{hash[:target_guid]};#{hash[:target_type]}"
@ -83,7 +83,7 @@ XML
it "doesn't change signatures if keys weren't supplied" do it "doesn't change signatures if keys weren't supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:author] :fetch_private_key, hash[:author]
).and_return(nil) ).and_return(nil)
xml = Entities::RelayableRetraction.new(hash).to_xml xml = Entities::RelayableRetraction.new(hash).to_xml

View file

@ -43,10 +43,10 @@ module DiasporaFederation
hash[:parent] = remote_parent hash[:parent] = remote_parent
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, remote_parent.author :fetch_public_key, remote_parent.author
).and_return(parent_pkey.public_key) ).and_return(parent_pkey.public_key)
expect { SomeRelayable.new(hash).verify_signatures }.not_to raise_error expect { SomeRelayable.new(hash).verify_signatures }.not_to raise_error
@ -54,7 +54,7 @@ module DiasporaFederation
it "raises when no public key for author was fetched" do it "raises when no public key for author was fetched" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, anything :fetch_public_key, anything
).and_return(nil) ).and_return(nil)
expect { expect {
@ -66,7 +66,7 @@ module DiasporaFederation
hash[:author_signature] = nil hash[:author_signature] = nil
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect { expect {
@ -79,10 +79,10 @@ module DiasporaFederation
hash[:parent] = remote_parent hash[:parent] = remote_parent
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, remote_parent.author :fetch_public_key, remote_parent.author
).and_return(nil) ).and_return(nil)
expect { expect {
@ -96,10 +96,10 @@ module DiasporaFederation
hash[:parent] = remote_parent hash[:parent] = remote_parent
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, remote_parent.author :fetch_public_key, remote_parent.author
).and_return(parent_pkey.public_key) ).and_return(parent_pkey.public_key)
expect { expect {
@ -113,7 +113,7 @@ module DiasporaFederation
hash[:parent] = local_parent hash[:parent] = local_parent
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect { SomeRelayable.new(hash).verify_signatures }.not_to raise_error expect { SomeRelayable.new(hash).verify_signatures }.not_to raise_error
@ -129,10 +129,10 @@ module DiasporaFederation
hash[:parent] = remote_parent hash[:parent] = remote_parent
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, remote_parent.author :fetch_public_key, remote_parent.author
).and_return(parent_pkey.public_key) ).and_return(parent_pkey.public_key)
expect { SomeRelayable.new(hash, xml_order).verify_signatures }.not_to raise_error expect { SomeRelayable.new(hash, xml_order).verify_signatures }.not_to raise_error
@ -147,10 +147,10 @@ module DiasporaFederation
hash[:parent] = remote_parent hash[:parent] = remote_parent
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, remote_parent.author :fetch_public_key, remote_parent.author
).and_return(parent_pkey.public_key) ).and_return(parent_pkey.public_key)
expect { expect {
@ -162,7 +162,7 @@ module DiasporaFederation
hash[:author_signature] = sign_with_key(author_pkey, legacy_signature_data) hash[:author_signature] = sign_with_key(author_pkey, legacy_signature_data)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
xml_order = [:author, :guid, :parent_guid, :property, "new_property"] xml_order = [:author, :guid, :parent_guid, :property, "new_property"]
@ -196,10 +196,10 @@ XML
it "computes correct signatures for the entity" do it "computes correct signatures for the entity" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, author :fetch_private_key, author
).and_return(author_pkey) ).and_return(author_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, local_parent.author :fetch_private_key, local_parent.author
).and_return(parent_pkey) ).and_return(parent_pkey)
xml = SomeRelayable.new(hash).to_xml xml = SomeRelayable.new(hash).to_xml
@ -213,10 +213,10 @@ XML
it "computes correct signatures for the entity with new unknown xml elements" do it "computes correct signatures for the entity with new unknown xml elements" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, author :fetch_private_key, author
).and_return(author_pkey) ).and_return(author_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, local_parent.author :fetch_private_key, local_parent.author
).and_return(parent_pkey) ).and_return(parent_pkey)
xml_order = [:author, :guid, :parent_guid, "new_property", :property] xml_order = [:author, :guid, :parent_guid, "new_property", :property]
@ -242,7 +242,7 @@ XML
it "raises when author_signature not set and key isn't supplied" do it "raises when author_signature not set and key isn't supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, author :fetch_private_key, author
).and_return(nil) ).and_return(nil)
expect { expect {
@ -252,10 +252,10 @@ XML
it "doesn't set parent_author_signature if key isn't supplied" do it "doesn't set parent_author_signature if key isn't supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, author :fetch_private_key, author
).and_return(author_pkey) ).and_return(author_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, local_parent.author :fetch_private_key, local_parent.author
).and_return(nil) ).and_return(nil)
xml = SomeRelayable.new(hash).to_xml xml = SomeRelayable.new(hash).to_xml
@ -274,10 +274,10 @@ XML
context "parsing" do context "parsing" do
before do before do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, remote_parent.author :fetch_public_key, remote_parent.author
).and_return(parent_pkey.public_key) ).and_return(parent_pkey.public_key)
end end
@ -335,7 +335,7 @@ XML
xml = SomeRelayable.new(hash).to_xml xml = SomeRelayable.new(hash).to_xml
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, author :fetch_public_key, author
).and_return(author_pkey.public_key) ).and_return(author_pkey.public_key)
expect { expect {

View file

@ -35,7 +35,7 @@ XML
it "updates author signature when it was nil and key was supplied" do it "updates author signature when it was nil and key was supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:author] :fetch_private_key, hash[:author]
).and_return(author_pkey) ).and_return(author_pkey)
signed_string = "#{hash[:target_guid]};#{hash[:target_type]}" signed_string = "#{hash[:target_guid]};#{hash[:target_type]}"
@ -56,7 +56,7 @@ XML
it "doesn't change signature if a key wasn't supplied" do it "doesn't change signature if a key wasn't supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:author] :fetch_private_key, hash[:author]
).and_return(nil) ).and_return(nil)
xml = Entities::SignedRetraction.new(hash).to_xml xml = Entities::SignedRetraction.new(hash).to_xml

View file

@ -12,7 +12,7 @@ module DiasporaFederation
:fetch_person_url_to, post.author, "/fetch/post/#{post.guid}" :fetch_person_url_to, post.author, "/fetch/post/#{post.guid}"
).and_return("https://example.org/fetch/post/#{post.guid}") ).and_return("https://example.org/fetch/post/#{post.guid}")
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, post.author :fetch_public_key, post.author
).and_return(alice.public_key) ).and_return(alice.public_key)
receiver = double receiver = double
@ -40,7 +40,7 @@ module DiasporaFederation
:fetch_person_url_to, post.author, "/fetch/post/#{post.guid}" :fetch_person_url_to, post.author, "/fetch/post/#{post.guid}"
).and_return("https://example.org/fetch/post/#{post.guid}") ).and_return("https://example.org/fetch/post/#{post.guid}")
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, post.author :fetch_public_key, post.author
).and_return(alice.public_key) ).and_return(alice.public_key)
receiver = double receiver = double

View file

@ -8,7 +8,7 @@ module DiasporaFederation
it "parses the entity with magic envelope receiver" do it "parses the entity with magic envelope receiver" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, post.author :fetch_public_key, post.author
).and_return(sender_key) ).and_return(sender_key)
data = Salmon::MagicEnvelope.new(post, post.author).envelop(sender_key).to_xml data = Salmon::MagicEnvelope.new(post, post.author).envelop(sender_key).to_xml
@ -27,7 +27,7 @@ module DiasporaFederation
it "parses the entity with legacy slap receiver" do it "parses the entity with legacy slap receiver" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, post.author :fetch_public_key, post.author
).and_return(sender_key) ).and_return(sender_key)
data = DiasporaFederation::Salmon::Slap.generate_xml(post.author, sender_key, post) data = DiasporaFederation::Salmon::Slap.generate_xml(post.author, sender_key, post)
@ -50,7 +50,7 @@ module DiasporaFederation
it "parses the entity with magic envelope receiver" do it "parses the entity with magic envelope receiver" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, post.author :fetch_public_key, post.author
).and_return(sender_key) ).and_return(sender_key)
magic_env = Salmon::MagicEnvelope.new(post, post.author).envelop(sender_key) magic_env = Salmon::MagicEnvelope.new(post, post.author).envelop(sender_key)
@ -70,7 +70,7 @@ module DiasporaFederation
it "parses the entity with legacy slap receiver" do it "parses the entity with legacy slap receiver" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, post.author :fetch_public_key, post.author
).and_return(sender_key) ).and_return(sender_key)
data = DiasporaFederation::Salmon::EncryptedSlap.prepare(post.author, sender_key, post) data = DiasporaFederation::Salmon::EncryptedSlap.prepare(post.author, sender_key, post)

View file

@ -140,7 +140,7 @@ module DiasporaFederation
context "sanity" do context "sanity" do
it "accepts correct params" do it "accepts correct params" do
allow(DiasporaFederation.callbacks).to receive(:trigger).with( allow(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender :fetch_public_key, sender
).and_return(privkey.public_key) ).and_return(privkey.public_key)
expect { expect {

View file

@ -106,7 +106,7 @@ module DiasporaFederation
context "sanity" do context "sanity" do
before do before do
allow(DiasporaFederation.callbacks).to receive(:trigger).with( allow(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender :fetch_public_key, sender
).and_return(privkey.public_key) ).and_return(privkey.public_key)
end end
@ -140,7 +140,7 @@ module DiasporaFederation
other_key = OpenSSL::PKey::RSA.generate(512) other_key = OpenSSL::PKey::RSA.generate(512)
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, other_sender :fetch_public_key, other_sender
).and_return(other_key) ).and_return(other_key)
expect { expect {
@ -175,7 +175,7 @@ module DiasporaFederation
it "decrypts on the fly, when cipher params are present" do it "decrypts on the fly, when cipher params are present" do
allow(DiasporaFederation.callbacks).to receive(:trigger).with( allow(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender :fetch_public_key, sender
).and_return(privkey.public_key) ).and_return(privkey.public_key)
env = Salmon::MagicEnvelope.new(payload) env = Salmon::MagicEnvelope.new(payload)
@ -206,7 +206,7 @@ module DiasporaFederation
it "raises if the sender key is not found" do it "raises if the sender key is not found" do
expect(DiasporaFederation.callbacks).to receive(:trigger).with( expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender :fetch_public_key, sender
).and_return(nil) ).and_return(nil)
expect { expect {

View file

@ -51,7 +51,7 @@ module DiasporaFederation
context "sanity" do context "sanity" do
it "accepts salmon xml as param" do it "accepts salmon xml as param" do
allow(DiasporaFederation.callbacks).to receive(:trigger).with( allow(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender :fetch_public_key, sender
).and_return(privkey.public_key) ).and_return(privkey.public_key)
expect { expect {

View file

@ -37,10 +37,6 @@ def bob
@bob ||= Person.find_by(diaspora_id: "bob@localhost:3000") @bob ||= Person.find_by(diaspora_id: "bob@localhost:3000")
end end
def test_pkey
DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id)
end
# Requires supporting files with custom matchers and macros, etc, # Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories. # in ./support/ and its subdirectories.
fixture_builder_file = "#{File.dirname(__FILE__)}/support/fixture_builder.rb" fixture_builder_file = "#{File.dirname(__FILE__)}/support/fixture_builder.rb"

View file

@ -1,7 +1,7 @@
shared_examples "a MagicEnvelope instance" do shared_examples "a MagicEnvelope instance" do
before do before do
allow(DiasporaFederation.callbacks).to receive(:trigger).with( allow(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender :fetch_public_key, sender
).and_return(privkey.public_key) ).and_return(privkey.public_key)
end end

View file

@ -60,12 +60,12 @@ DiasporaFederation.configure do |config|
end end
end end
on :fetch_private_key_by_diaspora_id do |diaspora_id| on :fetch_private_key do |diaspora_id|
key = Person.where(diaspora_id: diaspora_id).pluck(:serialized_private_key).first key = Person.where(diaspora_id: diaspora_id).pluck(:serialized_private_key).first
OpenSSL::PKey::RSA.new(key) unless key.nil? OpenSSL::PKey::RSA.new(key) unless key.nil?
end end
on :fetch_public_key_by_diaspora_id do |diaspora_id| on :fetch_public_key do |diaspora_id|
key = Person.where(diaspora_id: diaspora_id).pluck(:serialized_public_key).first key = Person.where(diaspora_id: diaspora_id).pluck(:serialized_public_key).first
key = DiasporaFederation::Discovery::Discovery.new(diaspora_id).fetch_and_save.exported_key if key.nil? key = DiasporaFederation::Discovery::Discovery.new(diaspora_id).fetch_and_save.exported_key if key.nil?
OpenSSL::PKey::RSA.new(key) unless key.nil? OpenSSL::PKey::RSA.new(key) unless key.nil?