[INCOMPLETE] Wrote tests for message linkage, but there is a problem

Observe the messages below:

=== BEGIN SAMPLE
	author @sqTnBVTpnkzptZ2Ek7U7IfBKbQdWfe4HfsBd-9fcyDg=.ed25519
	kind unit_test
	prev NONE
	depth 0

	description:"Message number 1"

	signature oBZcedW6JFqWVVqVHSjKeJWzd2uQtkBi2ATtF9meLzwrgf59DcjFQ5n0W6ZcCQkCSCpXECoBwF8BdnPej9XCBw==.sig.ed25519
	author @sqTnBVTpnkzptZ2Ek7U7IfBKbQdWfe4HfsBd-9fcyDg=.ed25519
	kind unit_test
	prev oBZcedW6JFqWVVqVHSjKeJWzd2uQtkBi2ATtF9meLzwrgf59DcjFQ5n0W6ZcCQkCSCpXECoBwF8BdnPej9XCBw==.sig.ed25519
	depth 1

	description:"Message number 2"

	signature MB52WQfouTRP_cKHnaMR8iL0EEXFDWrKghBbC8DQ_QxKzS8PFDSXCxbZFr2bfEbCzBrd_bCxP1q9uK4ndQwkCQ==.sig.ed25519
	author @sqTnBVTpnkzptZ2Ek7U7IfBKbQdWfe4HfsBd-9fcyDg=.ed25519
	kind unit_test
	prev MB52WQfouTRP_cKHnaMR8iL0EEXFDWrKghBbC8DQ_QxKzS8PFDSXCxbZFr2bfEbCzBrd_bCxP1q9uK4ndQwkCQ==.sig.ed25519
	depth 2

	description:"Message number 3"

	signature jEIN2yYSWmg-fnontgoZQS3Cw7KJIzhxuH6Gz-bE5pRat9zjP6vFJOlbNjADif_sPTxdye-kZdy52gTspDmdBw==.sig.ed25519
=== END EXAMPLE

Notice that the `signature` is identical to the `prev` value.
This is wrong.
The signature value is fine as it is, but the `prev` value needs to be a traditional message.
That is to say it should be a URL safe base64 string that starts with a "%" character.
You can't just copy/paste the signature like that.

For more info visit:
  https://spec.scuttlebutt.nz/feed/datatypes.html#multihash-encoding
  https://spec.scuttlebutt.nz/print.html#json-encoding
This commit is contained in:
Netscape Navigator 2020-03-08 11:35:09 -05:00
parent c621e5c070
commit a14089143a
3 changed files with 10 additions and 6 deletions

View File

@ -30,7 +30,7 @@ module Pigeon
store = Pigeon::Storage.current
@signature = calculate_signature
@depth = store.message_count
@prev = store.get_message_by_depth(@depth - 1)
@prev = store.get_message_by_depth(@author, @depth - 1)
self.freeze
store.save_message(self)
end

View File

@ -11,10 +11,10 @@ module Pigeon
@current ||= self.new
end
def get_message_by_depth(depth)
def get_message_by_depth(author, depth)
store.transaction do
# Map<Integer, Signature>
store[DEPTH_INDEX_NS][depth]
# Map<[author(str), depth(int)], Signature>
store[DEPTH_INDEX_NS][[author.public_key, depth]]
end
end
@ -27,6 +27,7 @@ module Pigeon
def save_message(msg)
store.transaction do
store[MESG_NS][msg.signature] = msg
update_indices(msg)
end
end
@ -123,7 +124,10 @@ module Pigeon
end
def update_indices(message)
puts "TODO: Finish this!!"
# SECURITY AUDIT: How can we be certain the message is
# not lying about its depth?
key = [message.author.public_key, message.depth]
store[DEPTH_INDEX_NS][key] = message.signature
end
end
end

View File

@ -49,7 +49,6 @@ RSpec.describe Pigeon::Message do
it "creates a chain of messages" do
all = []
1.upto(5) do |n|
print "Begin message chain #{n} / 3"
expected_depth = n - 1
draft1 = Pigeon::Draft.create(kind: "unit_test")
draft1["description"] = "Message number #{n}"
@ -62,5 +61,6 @@ RSpec.describe Pigeon::Message do
expect(message.prev).to be nil
end
end
binding.pry
end
end