kth-tcs / trustfull-demonstrator

Code for the demonstrator of the Trustfull project based on the e-voting system verificatum
1 stars 4 forks source link

Adjust format of encrypted vote #42

Closed arolle closed 1 year ago

arolle commented 1 year ago

The verified and unverified back-ends need to accept vote submissions in the same format. A submission from the client is a json object with the keys vote and signature. The suggestion is to change the content of the signature field and the signed content to be based on the (binary) verificatum byte tree representation of the encrypted vote. This representation is more compact (than its current json serialisation) and independent of any other than the Javascript byte tree implementation.

The hash that is signed should be the hash of the of the binary byte tree. The vote field should contain a base64 encoding of the binary byte tree.

algomaster99 commented 1 year ago

Currently, the encoded vote is printed as JSON and then hashed which might be inconsistent because the first step could introduce formatting information and that would interfere with hashing. It is more desirable to directly hash the byte tree.

arolle commented 1 year ago

Here is some python code, that would print the suggested value, where first and second are the current first/second components of the json object currently in vote.

print("encrypted vote binary:")
enc_vote = ByteTree([ByteTree(first), ByteTree(second)]).to_byte_array()
pprint(enc_vote)

print("hash to sign:")
vote_hash = sha256(enc_vote).hexdigest()
print(vote_hash)

print("encrypted vote to submit:")
print(base64.b64encode(enc_vote).decode("ascii"))

Once received on the back-end, after base64 decoding the byte tree would have to be destructed to get back first and second.

algomaster99 commented 1 year ago

That is helpful. I can make the changes in the master soon.

algomaster99 commented 1 year ago
 enc_vote = ByteTree([ByteTree(first), ByteTree(second)]).to_byte_array()

This should happen on the client side.