diff --git a/docs/federation/relayable.md b/docs/federation/relayable.md index 158e687..742b5ae 100644 --- a/docs/federation/relayable.md +++ b/docs/federation/relayable.md @@ -24,14 +24,17 @@ All relayables have the following properties: ## Relaying -The author of the relayable sends the entity to the parent author. The author must include the `author_signature`. +If the author is not the same as the parent author, the author of the relayable sends the entity to the parent author +and the author must include the `author_signature`. The parent author then must envelop it in a new [Magic Envelope][magicsig] and send the entity to all the recipients of the parent entity. If the author and the parent author are on the same server, the author must sign the `author_signature` and the parent author needs to sign the Magic Envelope. If someone other then the parent author receives a relayable without a valid Magic Envelope signed from -the parent author, it must be ignored. If the `author_signature` is missing or invalid, it also must be ignored. +the parent author, it must be ignored. If the author is not the same as the parent author and the `author_signature` +is missing or invalid, it also must be ignored. If the author is the same as the parent author, the `author_signature` +can be missing, because a valid signature in the Magic Envelope from the author is enough in that case. ## Signatures diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index 7366287..97c61a1 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -70,13 +70,13 @@ module DiasporaFederation super(data) end - # Verifies the +author_signature+. + # Verifies the +author_signature+ if needed. # @see DiasporaFederation::Entities::Signable#verify_signature # # @raise [SignatureVerificationFailed] if the signature is not valid # @raise [PublicKeyNotFound] if no public key is found def verify_signature - super(author, :author_signature) + super(author, :author_signature) unless author == parent.author end def sender_valid?(sender) diff --git a/spec/lib/diaspora_federation/entities/relayable_spec.rb b/spec/lib/diaspora_federation/entities/relayable_spec.rb index 4b02a6a..86ecc36 100644 --- a/spec/lib/diaspora_federation/entities/relayable_spec.rb +++ b/spec/lib/diaspora_federation/entities/relayable_spec.rb @@ -69,6 +69,15 @@ module DiasporaFederation }.to raise_error Entities::Relayable::SignatureVerificationFailed end + it "doesn't raise when no author signature was passed, but the author is also the parent author" do + hash[:author_signature] = nil + hash[:parent] = Fabricate(:related_entity, author: author, local: false) + + expect { + Entities::SomeRelayable.new(hash, signature_order).verify_signature + }.not_to raise_error + end + it "raises when bad author signature was passed" do hash[:author_signature] = sign_with_key(author_pkey, "bad signed string")