-
Notifications
You must be signed in to change notification settings - Fork 2
/
single-ballot-verify.html
157 lines (129 loc) · 5.07 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
<!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/jscrypto/jsbn.js"></script>
<script language="javascript" src="js/jscrypto/jsbn2.js"></script>
<script language="javascript" src="js/jscrypto/sjcl.js"></script>
<script language="javascript" src="js/underscore-min.js"></script>
<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>
<script language="javascript" src="verifier.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();
var after_computation = function(overall_result) {
result_append("<br />");
$('#loading').hide();
if (overall_result) {
result_append('SUCCESSFUL VERIFICATION, DONE!');
} else {
result_append('PROBLEM - THIS BALLOT DOES NOT VERIFY.');
}
};
// the hash will be computed within the setup function call now
$.ajax({url: election_url, success: function(raw_json) {
if (window.Worker) {
var verifier_worker = new window.Worker("verifierworker.js");
verifier_worker.onmessage = function(event) {
if (event.data.type == 'log')
return console.log(event.data.msg);
if (event.data.type == 'status')
return result_append(event.data.msg);
if (event.data.type == 'result')
return after_computation(event.data.result);
};
verifier_worker.postMessage({'type':'verify', 'election':raw_json, 'vote':encrypted_vote_json});
} else {
var overall_result = verify_ballot(raw_json, encrypted_vote_json, result_append);
after_computation(overall_result);
}
}, 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>