2018-06-12 12:31:38 +00:00
|
|
|
{% extends "bases/bootstrap.html" %}
|
|
|
|
{% load staticfiles %}
|
|
|
|
|
|
|
|
{% block tail_js %}
|
|
|
|
<script>
|
|
|
|
Module = {};
|
|
|
|
Module.memoryInitializerPrefixURL = "{% static 'js/' %}";
|
|
|
|
</script>
|
|
|
|
<script src="//code.jquery.com/jquery-2.2.4.min.js"></script>
|
|
|
|
<!-- <script>window.jQuery || document.write('<script src="js/jquery-1.10.1.min.js"><\/script>')</script> -->
|
|
|
|
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
|
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
|
|
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
|
2018-08-16 21:17:16 +00:00
|
|
|
<script src="https://bitwiseshiftleft.github.io/sjcl/sjcl.js"></script>
|
2018-06-12 12:31:38 +00:00
|
|
|
<script src='https://www.google.com/recaptcha/api.js'></script>
|
2018-08-16 21:17:16 +00:00
|
|
|
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
|
|
|
|
|
2018-06-12 12:31:38 +00:00
|
|
|
<script src="{% static 'js/papaparse.min.js' %}" type="text/javascript"></script>
|
2018-07-23 13:08:17 +00:00
|
|
|
<script src="{% static 'js/qrcode.min.js' %}" type="text/javascript"></script>
|
2018-06-12 12:31:38 +00:00
|
|
|
<script src="{% static 'js/create-event-poll.js' %}" type="text/javascript"></script>
|
2018-07-07 08:52:47 +00:00
|
|
|
<script src="{% static 'js/decrypt_event.js' %}" type="text/javascript"></script>
|
2018-07-13 16:19:35 +00:00
|
|
|
<script src="{% static 'js/event_vote.js' %}" type="text/javascript"></script>
|
2018-08-16 21:17:16 +00:00
|
|
|
<script src="{% static 'js/vote_audit.js' %}" type="text/javascript"></script>
|
2018-06-12 12:31:38 +00:00
|
|
|
<script src="{% static 'js/encrypt.js' %}" type="text/javascript"></script>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/rand.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/rom_curve.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/rom_field.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/uint64.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/aes.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/big.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/gcm.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/hash256.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/hash384.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/hash512.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/sha3.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/newhope.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/nhs.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/fp.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/fp2.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/fp4.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/fp12.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/ff.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/rsa.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/ecp.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/ecp2.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/ecdh.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/pair.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/mpin.js' %}"></script>
|
|
|
|
<script type="text/javascript" src="{% static 'js/core/ctx.js' %}"></script>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="{% static 'js/demos2-booth.js' %}"></script>
|
|
|
|
|
|
|
|
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.js" type="text/javascript"></script>
|
|
|
|
|
|
|
|
{% block app_js %}
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
{% block app_js_vars %}
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
Module.memoryInitializerPrefixURL = "LOL";
|
|
|
|
var demosEncrypt = {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:25:36 +00:00
|
|
|
function getBytes(arr) {
|
|
|
|
for(var i = 0; i < arr.length; i++) {
|
|
|
|
arr[i] = parseInt(arr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Uint8Array(arr);
|
|
|
|
}
|
2018-06-12 12:31:38 +00:00
|
|
|
|
|
|
|
//new function
|
2018-07-11 13:25:36 +00:00
|
|
|
demosEncrypt.decryptSubmitCiphers = function() {
|
2018-09-03 14:39:42 +00:00
|
|
|
|
2018-07-11 13:25:36 +00:00
|
|
|
};
|
2018-06-12 12:31:38 +00:00
|
|
|
|
|
|
|
//new function
|
|
|
|
demosEncrypt.generateKeys = function() {
|
2018-07-07 08:52:47 +00:00
|
|
|
var parameter = $("#event-param").val();
|
2018-07-02 09:06:05 +00:00
|
|
|
var tempParams = JSON.parse(JSON.parse(parameter).crypto);
|
2018-06-12 12:31:38 +00:00
|
|
|
//the full objects need to be initalised as per the library, then copy the values we need into it
|
|
|
|
//I follow Bingsheng's code as to what objects are used in the parameter object
|
|
|
|
var ctx = new CTX("BN254CX"); //new context we can use
|
|
|
|
var n = new ctx.BIG();
|
|
|
|
var g1 = new ctx.ECP();
|
|
|
|
var g2 = new ctx.ECP2();
|
|
|
|
|
|
|
|
//copying the values
|
|
|
|
n.copy(tempParams.n);
|
|
|
|
g1.copy(tempParams.g1);
|
|
|
|
g2.copy(tempParams.g2);
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
n:n,
|
|
|
|
g1:g1,
|
|
|
|
g2:g2
|
|
|
|
}
|
|
|
|
|
|
|
|
var PKbytes = [];
|
|
|
|
var SKbytes = [];
|
|
|
|
|
|
|
|
var keypair = keyGen(params);
|
|
|
|
keypair.PK.toBytes(PKbytes);
|
|
|
|
keypair.SK.toBytes(SKbytes);
|
|
|
|
|
2018-09-04 14:21:31 +00:00
|
|
|
var PKB64Encoded = "";
|
|
|
|
for(let i = 0; i < PKbytes.length; i++) {
|
|
|
|
PKB64Encoded += btoa(PKbytes[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var SKB64Encoded = "";
|
|
|
|
for(let j = 0; j < SKbytes.length; j++) {
|
|
|
|
SKB64Encoded += btoa(SKbytes[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$('input#public-key').val(PKB64Encoded);
|
|
|
|
$('input#secret-key').val(SKB64Encoded);
|
2018-06-12 12:31:38 +00:00
|
|
|
|
|
|
|
//mostly code from before here
|
2018-09-04 14:21:31 +00:00
|
|
|
var blob = new Blob([SKB64Encoded], {type : 'text/plain'});
|
2018-06-12 12:31:38 +00:00
|
|
|
|
|
|
|
var dlBtn = $('a#download-btn');
|
|
|
|
var url = URL.createObjectURL(blob);
|
|
|
|
var fileName = $(dlBtn).attr("href", url);
|
|
|
|
|
|
|
|
$(dlBtn).attr("download", "sk-{% block sk-file-name %}{% endblock %}".replace(/[\W]/g, "-"));
|
|
|
|
$(dlBtn).attr("disabled", false);
|
|
|
|
$("#public-submit").attr("disabled", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//these other functions might not be used
|
|
|
|
//I don't think this is used
|
|
|
|
demosEncrypt.downloadSecretKey = function() {
|
|
|
|
var blob = new Blob([sk], {type : 'text/plain'});
|
|
|
|
var dlBtn = $('a#download-btn');
|
|
|
|
$(dlBtn).attr("disabled", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFormsetPrefix(id) {
|
|
|
|
id = id.replace(/(?:id_)?formset_/, ""); // strip generic part
|
|
|
|
return id.replace(/([A-Za-z0-9]+)[\w-]*/, "$1"); // return prefix
|
|
|
|
}
|
|
|
|
|
|
|
|
function setFormsetIndex(ele, prefix, index) {
|
|
|
|
ele = $(ele).find("div[id^='id_formset'], input[id^='id_formset']").each(function (i, el) {
|
|
|
|
var id = $(el).attr("id");
|
|
|
|
id = "id_formset_" + prefix + '-' + index + id.match(/-\w+$/);
|
|
|
|
$(el).attr("id", id);
|
|
|
|
if ($(el).is("input")) {
|
|
|
|
$(el).attr("name", id.replace(/^id_/, ""));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.formset').sortable({handle:".input-group-addon", items:".formset_object",
|
|
|
|
start: function(event, ui) {
|
|
|
|
ui.item.prevPos = ui.item.index();
|
|
|
|
console.log(ui.item.prevPos);
|
|
|
|
},
|
|
|
|
update: function(event, ui) {
|
|
|
|
ui.item.prevPos = null;
|
|
|
|
},
|
|
|
|
beforeStop: function(event, ui) {
|
|
|
|
$(ui.item).css("animation", "none"); // prevents firing of entry keyframe
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//$('.glyphicon.glyphicon-trash').parent().hide();
|
|
|
|
$('.formset').find
|
|
|
|
$('.formset').on('click', '.input-group-addon', function() { // this makes the label a delete btn too :(
|
|
|
|
var ele = $(this).closest(".formset_object");
|
|
|
|
var prefix = $(this).closest(".formset_object").data("prefix") || getFormsetPrefix($(this).closest(".formset_object").find('input:first').attr("id"));
|
|
|
|
var current_total = parseInt($("#id_formset_" + prefix + "-TOTAL_FORMS").val());
|
|
|
|
if (current_total <= $("#id_formset_" + prefix + "-MIN_NUM_FORMS").val()) {
|
|
|
|
return; // don't allow removal of last element
|
|
|
|
}
|
|
|
|
ele.remove();
|
|
|
|
$("#id_formset_" + prefix + "-TOTAL_FORMS").val(current_total - 1);
|
|
|
|
$(".formset").sortable( "refresh" );
|
|
|
|
$(".formset").sortable( "refreshPositions" );
|
|
|
|
});
|
|
|
|
$('.add-another-btn').on('click',function() {
|
|
|
|
var new_formset_item = $(this).prevAll(".formset_object:first").clone();
|
|
|
|
var prefix = getFormsetPrefix(new_formset_item.find("input:first").attr("id"));
|
|
|
|
var current_total = parseInt($("#id_formset_" + prefix + "-TOTAL_FORMS").val());
|
|
|
|
if (current_total >= $("#id_formset_" + prefix + "-MAX_NUM_FORMS").val()) {
|
|
|
|
return; // don't allow more than max forms
|
|
|
|
}
|
|
|
|
new_formset_item.data("prefix", prefix);
|
|
|
|
$(this).before(new_formset_item);
|
|
|
|
new_formset_item.find("input").val("");
|
|
|
|
setFormsetIndex(new_formset_item, prefix, parseInt($("#id_formset_" + prefix + "-TOTAL_FORMS").val()));
|
|
|
|
$("#id_formset_" + prefix + "-TOTAL_FORMS").val(parseInt($("#id_formset_" + prefix + "-TOTAL_FORMS").val()) +1);
|
|
|
|
$(".formset").sortable( "refresh" );
|
|
|
|
$(".formset").sortable( "refreshPositions" );
|
|
|
|
});
|
|
|
|
|
|
|
|
// rudimentary accordion error handling
|
|
|
|
$('.has-error').closest('.panel').find('.panel-heading').addClass("error");
|
|
|
|
$('.alert.alert-block.alert-danger').closest('.panel').find('.panel-heading').addClass("error");
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% endblock %}
|