-
Notifications
You must be signed in to change notification settings - Fork 2
/
single-ballot-verify.html
190 lines (158 loc) · 6.35 KB
/
single-ballot-verify.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" />
<title>Helios Voting System</title>
<link rel="stylesheet" type="text/css" href="css/booth.css" />
<link rel="stylesheet" type="text/css" href="css/forms.css" />
<script language="javascript" src="js/jquery-1.2.2.min.js"></script>
<script language="javascript" src="js/jquery-jtemplates.js"></script>
<script language="javascript" src="js/jquery.json.min.js"></script>
<script language="javascript" src="js/jquery.query-2.1.5.js"></script>
<script language="javascript">
// required for jscrypto library
var JSCRYPTO_HOME = document.location.pathname.replace("single-ballot-verify.html", "js/jscrypto");
</script>
<script language="javascript" src="js/jscrypto/class.js"></script>
<script language="javascript" src="js/jscrypto/bigint.js"></script>
<script language="javascript" src="js/jscrypto/random.js"></script>
<script language="javascript" src="js/jscrypto/elgamal.js"></script>
<script language="javascript" src="js/jscrypto/sha1.js"></script>
<script language="javascript" src="js/jscrypto/sha2.js"></script>
<script language="javascript" src="js/jscrypto/helios.js"></script>
</head>
<body>
<script language="javascript">
$(document).ready(function() {
BigInt.setup(function() {
$('#verifier_loading').hide();
if (BigInt.is_dummy) {
$('#dummy_bigint').show();
return;
}
$('#verifier').show();
var election_url = $.query.get('election_url');
$('#election_url').val(election_url);
}, function() {
$('#dummy_bigint').show();
});
});
function result_append(str) {
$('#results').append(str).append("<br />");
}
function verify_single_ballot(election_url, audit_trail) {
var encrypted_vote_json = jQuery.secureEvalJSON(audit_trail);
result_append("loading election...");
// quick and dirty detection of cast ballot
if (encrypted_vote_json['cast_at']) {
result_append("\n\nIt looks like you are trying to verify a cast ballot. That can't be done, only audited ballots can be verified.");
return;
}
$('#loading').show();
// the hash will be computed within the setup function call now
$.ajax({url: election_url, success: function(raw_json) {
var overall_result = true;
try {
election = HELIOS.Election.fromJSONString(raw_json);
var election_hash = election.get_hash();
result_append("election fingerprint is " + election_hash);
// check if the election ballot_type is homomorphic
// no longer the way this is done
// display ballot fingerprint
encrypted_vote = HELIOS.EncryptedVote.fromJSONObject(encrypted_vote_json, election);
BigInt.patchForChrome(function() {
return $.toJSON(encrypted_vote.toJSONObject());
});
result_append("smart ballot tracker is " + encrypted_vote.get_hash());
// check the hash
if (election_hash == encrypted_vote.election_hash) {
result_append("election fingerprint matches ballot");
} else {
overall_result = false;
result_append("PROBLEM = election fingerprint does not match");
}
// display the ballot as it is claimed to be
result_append("Ballot Contents:")
$(election.questions).each(function(qnum, q) {
if (q.tally_type != "homomorphic") {
result_append("WARNING: the tally type for this question is not homomorphic. Verification may fail because this verifier is only set up to handle homomorphic ballots.");
}
var answer_pretty_list = jQuery.map(encrypted_vote.encrypted_answers[qnum].answer, function(aindex, anum) {
return q.answers[aindex];
});
result_append("Question #" + (qnum+1) + " - " + q.short_name + " : " + answer_pretty_list.join(", "));
});
// verify the encryption
if (encrypted_vote.verifyEncryption(election.questions, election.public_key)) {
result_append("Encryption Verified");
} else {
overall_result = false;
result_append("PROBLEM = Encryption doesn't match.");
}
// verify the proofs
if (encrypted_vote.verifyProofs(election.public_key, function(ea_num, choice_num, result) {
})) {
result_append("Proofs ok.");
} else {
overall_result = false;
result_append("PROBLEM = Proofs don't work.");
}
} catch (e) {
alert(e);
result_append('problem parsing election or ballot data structures, malformed inputs.');
overall_result=false;
}
result_append("<br />");
$('#loading').hide();
if (overall_result) {
result_append('SUCCESSFUL VERIFICATION, DONE!');
} else {
result_append('PROBLEM - THIS BALLOT DOES NOT VERIFY.');
}
}, error: function() {
result_append('PROBLEM LOADING election. Are you sure you have the right election URL?<br />');
$('#loading').hide();
result_append('PROBLEM - THIS BALLOT DOES NOT VERIFY.');
}
});
}
</script>
</head>
<body>
<div id="wrapper">
<div id="banner">
Helios Single-Ballot Verifier
</div>
<div id="content">
<div id="verifier_loading">
Loading verifier...
</div>
<div id="dummy_bigint" style="display:none;">
Your browser does not have the Java plugin installed.<br /><br />
At this time, the Java plugin is required for browser-based ballot auditing, although it is not required for ballot preparation.
</div>
<div id="verifier" style="display:none;">
<p style="font-size: 16pt;">
This single-ballot verifier lets you enter an audited ballot<br />and verify that it was prepared correctly.
</p>
<form onsubmit="try {verify_single_ballot(this.election_url.value, this.audit_trail.value);} catch (e) {E = e;} return false;">
Enter the Election URL:
<input type="text" size="50" name="election_url" id="election_url" /><br />
<p>
Your Ballot:
</p>
<textarea name="audit_trail" cols="80" rows="7">
</textarea><br /><br />
<input type="submit" class="pretty" value="Verify" />
</form>
<br /><br />
<div id="results">
</div>
<img id="loading" src="loading.gif" style="display:none;" />
</div>
</div>
</div>
<div id="applet_div">
</div>
</body>
</html>