diff --git a/eos/core/hashing/__init__.py b/eos/core/hashing/__init__.py index ea378ab..b7b47ce 100644 --- a/eos/core/hashing/__init__.py +++ b/eos/core/hashing/__init__.py @@ -1,5 +1,5 @@ # Eos - Verifiable elections -# Copyright © 2017 RunasSudo (Yingtong Li) +# Copyright © 2017-18 RunasSudo (Yingtong Li) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -79,11 +79,14 @@ class SHA256: self.update_text(EosObject.to_json(EosObject.serialise_and_wrap(value, None, SerialiseOptions(for_hash=False)))) return self - def hash_as_b64(self): + def hash_as_b64(self, short=False): if is_python: - return base64.b64encode(self.impl.digest()).decode('utf-8') + b64 = base64.b64encode(self.impl.digest()).decode('utf-8') else: - return self.impl.getHash('B64') + b64 = self.impl.getHash('B64') + if short: + return b64[:8] + return b64 def hash_as_hex(self): if is_python: diff --git a/eosweb/core/static/nunjucks/booth/audit.html b/eosweb/core/static/nunjucks/booth/audit.html index 979b012..228cbb4 100644 --- a/eosweb/core/static/nunjucks/booth/audit.html +++ b/eosweb/core/static/nunjucks/booth/audit.html @@ -2,7 +2,7 @@ {# Eos - Verifiable elections - Copyright © 2017 RunasSudo (Yingtong Li) + Copyright © 2017-18 RunasSudo (Yingtong Li) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -25,7 +25,7 @@

Your vote has not yet been cast. Please follow the instructions to continue.

-

The following is your ballot with fingerprint {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64() }}, decrypted and ready for auditing.

+

The following is your ballot with fingerprint {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64(true) }}, decrypted and ready for auditing.

{# For some reason nunjucks doesn't like calling this the normal way #} diff --git a/eosweb/core/static/nunjucks/booth/cast.html b/eosweb/core/static/nunjucks/booth/cast.html index 19552a8..ae9bf8b 100644 --- a/eosweb/core/static/nunjucks/booth/cast.html +++ b/eosweb/core/static/nunjucks/booth/cast.html @@ -20,7 +20,7 @@ {% block content %}
-

Your vote has not yet been cast. If you have not already done so, please make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64() }}.

+

Your vote has not yet been cast. If you have not already done so, please make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64(true) }}.

Your vote has not yet been cast. Please follow the instructions to continue.

diff --git a/eosweb/core/static/nunjucks/booth/cast_prepoll.html b/eosweb/core/static/nunjucks/booth/cast_prepoll.html index 269b2a2..73f629c 100644 --- a/eosweb/core/static/nunjucks/booth/cast_prepoll.html +++ b/eosweb/core/static/nunjucks/booth/cast_prepoll.html @@ -2,7 +2,7 @@ {# Eos - Verifiable elections - Copyright © 2017 RunasSudo (Yingtong Li) + Copyright © 2017-18 RunasSudo (Yingtong Li) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -25,7 +25,7 @@

Your vote has not yet been cast. Please follow the instructions to continue.

-

If you have not already done so, please make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64() }}. Please retain a copy of your ballot fingerprint – you can use it to verify that your vote has been counted correctly. You may print this page as a receipt if you wish.

+

If you have not already done so, please make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64(true) }}. Please retain a copy of your ballot fingerprint – you can use it to verify that your vote has been counted correctly. You may print this page as a receipt if you wish.

To continue, copy and paste the ballot below and provide it to the election administrator.

diff --git a/eosweb/core/static/nunjucks/booth/complete.html b/eosweb/core/static/nunjucks/booth/complete.html index 6450212..47637cb 100644 --- a/eosweb/core/static/nunjucks/booth/complete.html +++ b/eosweb/core/static/nunjucks/booth/complete.html @@ -2,7 +2,7 @@ {# Eos - Verifiable elections - Copyright © 2017 RunasSudo (Yingtong Li) + Copyright © 2017-18 RunasSudo (Yingtong Li) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -21,10 +21,13 @@ {% block content %}

Your vote has been successfully cast. The following is your ‘smart ballot tracker’. Please retain a copy of your smart ballot tracker – you can use it to verify that your vote has been counted correctly. You may print this page as a receipt if you wish.

-
-
Smart ballot tracker
-

This smart ballot tracker confirms that {{ voter.py_name }} cast a vote in the election {{ election.py_name }} at {{ vote.cast_at }}.

-

Ballot fingerprint: {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(vote.ballot).hash_as_b64() }}

+
+ +
+
Smart ballot tracker
+

This smart ballot tracker confirms that {{ voter.py_name }} cast a vote in the election {{ election.py_name }} at {{ vote.cast_at }}.

+

Ballot fingerprint: {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(vote.ballot).hash_as_b64(true) }}

+

Please check that the ballot fingerprint above matches the ballot fingerprint you recorded earlier.

diff --git a/eosweb/core/static/nunjucks/booth/review.html b/eosweb/core/static/nunjucks/booth/review.html index 16a6994..3b845f4 100644 --- a/eosweb/core/static/nunjucks/booth/review.html +++ b/eosweb/core/static/nunjucks/booth/review.html @@ -30,7 +30,7 @@ {% include templates[selection_model_view_map[election.questions.__getitem__(loop.index0)._name]["selections_review"]] %} {% endfor %} -

If you are happy with your selections, then make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64() }}.

+

If you are happy with your selections, then make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64(true) }}.

Click ‘Continue’, and you will be able to log in to cast your vote.

{% endblock %} diff --git a/eosweb/core/static/nunjucks/booth/review_prepoll.html b/eosweb/core/static/nunjucks/booth/review_prepoll.html index f2879d7..80a9b8d 100644 --- a/eosweb/core/static/nunjucks/booth/review_prepoll.html +++ b/eosweb/core/static/nunjucks/booth/review_prepoll.html @@ -2,7 +2,7 @@ {# Eos - Verifiable elections - Copyright © 2017 RunasSudo (Yingtong Li) + Copyright © 2017-18 RunasSudo (Yingtong Li) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -30,7 +30,7 @@ {% include templates[selection_model_view_map[election.questions.__getitem__(loop.index0)._name]["selections_review"]] %} {% endfor %} -

If you are happy with your selections, then make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64() }}.

+

If you are happy with your selections, then make a note of your ballot fingerprint, {{ eosjs.eos.core.hashing.__all__.SHA256().update_obj(ballot).hash_as_b64(true) }}.

Click ‘Continue’, and you will be able to copy your pre-poll ballot to provide to the election administrator.

{% endblock %} diff --git a/eosweb/core/templates/election/auditor.html b/eosweb/core/templates/election/auditor.html index c1cbdde..4a9a18b 100644 --- a/eosweb/core/templates/election/auditor.html +++ b/eosweb/core/templates/election/auditor.html @@ -2,7 +2,7 @@ {# Eos - Verifiable elections - Copyright © 2017 RunasSudo (Yingtong Li) + Copyright © 2017-18 RunasSudo (Yingtong Li) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -195,7 +195,7 @@ auditContentsInner.innerHTML += '

Question ' + (questionNum + 1) + ': ' + election.questions.__getitem__(questionNum).pretty_answer(auditBallot.answers.__getitem__(questionNum)) + '

'; } - auditContentsInner.innerHTML += '

Please check that the ballot fingerprint you recorded matches the following computed ballot fingerprint: ' + eosjs.eos.core.hashing.__all__.SHA256().update_obj(auditBallot).hash_as_b64() + '.

'; + auditContentsInner.innerHTML += '

Please check that the ballot fingerprint you recorded matches the following computed ballot fingerprint: ' + eosjs.eos.core.hashing.__all__.SHA256().update_obj(auditBallot).hash_as_b64(true) + '.

'; auditContentsInner.innerHTML += '

If the selections are correct, and the ballot fingerprint matches, then the ballot has been prepared correctly.

'; return true; diff --git a/eosweb/core/templates/election/view/ballots.html b/eosweb/core/templates/election/view/ballots.html index a331047..7515946 100644 --- a/eosweb/core/templates/election/view/ballots.html +++ b/eosweb/core/templates/election/view/ballots.html @@ -2,7 +2,7 @@ {# Eos - Verifiable elections - Copyright © 2017 RunasSudo (Yingtong Li) + Copyright © 2017-18 RunasSudo (Yingtong Li) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -32,7 +32,7 @@ {{ voter.name }} {% set votes = voter.votes.get_all() %} {% if votes|length > 0 %} - {{ SHA256().update_obj(votes[-1].ballot).hash_as_b64() }} + {{ SHA256().update_obj(votes[-1].ballot).hash_as_b64(True) }} {% else %} {% endif %}