From ae6e3594d9548d9338e607eab371c4b675b391db Mon Sep 17 00:00:00 2001 From: Paulo Matias <matias@ufscar.br> Date: Sat, 25 Jul 2020 09:28:40 -0300 Subject: [PATCH] EncryptedVote JSON should not contain whitespace Otherwise the hash displayed in the audited-ballots page will not match the hash displayed to the user when they prepared their vote. --- helios/crypto/electionalgs.py | 2 +- helios/crypto/utils.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/helios/crypto/electionalgs.py b/helios/crypto/electionalgs.py index c677140..a17ff6a 100644 --- a/helios/crypto/electionalgs.py +++ b/helios/crypto/electionalgs.py @@ -340,7 +340,7 @@ class EncryptedVote(HeliosObject): return True def get_hash(self): - return utils.hash_b64(utils.to_json(self.toJSONDict())) + return utils.hash_b64(utils.to_json(self.toJSONDict(), no_whitespace=True)) def toJSONDict(self, with_randomness=False): return { diff --git a/helios/crypto/utils.py b/helios/crypto/utils.py index 258f413..9953bdc 100644 --- a/helios/crypto/utils.py +++ b/helios/crypto/utils.py @@ -15,8 +15,11 @@ def hash_b64(s): result= base64.b64encode(hasher.digest())[:-1] return result -def to_json(d): - return json.dumps(d, sort_keys=True) +def to_json(d, no_whitespace=False): + if no_whitespace: + return json.dumps(d, sort_keys=True, separators=(',',':')) + else: + return json.dumps(d, sort_keys=True) def from_json(json_str): if not json_str: return None -- GitLab