Public Keys and Secret Keys for Trustees are now Base64 encoded. I've tested this against 1 trustee and multiple trustees.
This commit is contained in:
parent
801f6b274f
commit
da74180884
5 changed files with 57 additions and 18 deletions
|
@ -10,6 +10,7 @@ Dependencies can be found in 'package.json' and installed using 'npm install'
|
||||||
var port = 8080;
|
var port = 8080;
|
||||||
|
|
||||||
var Buffer = require('buffer').Buffer;
|
var Buffer = require('buffer').Buffer;
|
||||||
|
var atob = require("atob");
|
||||||
var CTX = require('milagro-crypto-js');
|
var CTX = require('milagro-crypto-js');
|
||||||
|
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
|
@ -65,6 +66,13 @@ app.get('/combpk', function(request, response){
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getKeyBytes(key, byteArray) {
|
||||||
|
for(let i = 0; i < key.length; i += 4) {
|
||||||
|
let B64EncodedByte = key.substring(i, i + 4);
|
||||||
|
|
||||||
|
byteArray.push(atob(B64EncodedByte));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//byte array version
|
//byte array version
|
||||||
app.post('/cmpkstring', function(request, response){
|
app.post('/cmpkstring', function(request, response){
|
||||||
|
@ -77,19 +85,25 @@ app.post('/cmpkstring', function(request, response){
|
||||||
if(partials.length > 1)//if we're submitting more than one key
|
if(partials.length > 1)//if we're submitting more than one key
|
||||||
{
|
{
|
||||||
console.log('Combining ' + partials.length + " public keys into one...");
|
console.log('Combining ' + partials.length + " public keys into one...");
|
||||||
for (var i = partials.length - 1; i >= 0; i--) {
|
for (let i = partials.length - 1; i >= 0; i--) {
|
||||||
console.log('PK' + i + ': ' + partials[i]);
|
console.log('PK' + i + ': ' + partials[i]);
|
||||||
var bytes = Buffer.from(partials[i].split(','), 'hex');
|
|
||||||
var pk = new ctx.ECP.fromBytes(bytes);
|
let rawBytes = [];
|
||||||
parsed.push(pk);
|
getKeyBytes(partials[i], rawBytes);
|
||||||
|
|
||||||
|
parsed.push(new ctx.ECP.fromBytes(Buffer.from(rawBytes, 'hex')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(partials.length === 1)
|
else if(partials.length === 1)
|
||||||
{
|
{
|
||||||
console.log("Combining just one public key...");
|
console.log("Combining just one public key...");
|
||||||
var bytes = Buffer.from(partials[0].split(','), 'hex');
|
let PKStr = partials[0];
|
||||||
var pk = new ctx.ECP.fromBytes(bytes);
|
console.log("PK: " + PKStr);
|
||||||
parsed.push(pk);
|
|
||||||
|
let rawBytes = [];
|
||||||
|
getKeyBytes(PKStr, rawBytes);
|
||||||
|
|
||||||
|
parsed.push(new ctx.ECP.fromBytes(Buffer.from(rawBytes, 'hex')));
|
||||||
}
|
}
|
||||||
|
|
||||||
response.json(combine_pks(parsed));
|
response.json(combine_pks(parsed));
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
"author": "Bingsheng Zang, Thomas Smith, Vincent de Almeida",
|
"author": "Bingsheng Zang, Thomas Smith, Vincent de Almeida",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"atob": "^2.1.2",
|
||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
"express": "^4.16.3",
|
"express": "^4.16.3",
|
||||||
"milagro-crypto-js": "git+https://github.com/milagro-crypto/milagro-crypto-js.git"
|
"milagro-crypto-js": "git+https://github.com/milagro-crypto/milagro-crypto-js.git"
|
||||||
|
|
|
@ -145,7 +145,7 @@ class Event(models.Model):
|
||||||
class TrusteeKey(models.Model):
|
class TrusteeKey(models.Model):
|
||||||
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name="trustee_keys")
|
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name="trustee_keys")
|
||||||
user = models.ForeignKey(EmailUser, on_delete=models.CASCADE, related_name="trustee_keys")
|
user = models.ForeignKey(EmailUser, on_delete=models.CASCADE, related_name="trustee_keys")
|
||||||
key = models.CharField(max_length=255, unique=True)
|
key = models.CharField(max_length=260)
|
||||||
|
|
||||||
|
|
||||||
class AccessKey(models.Model):
|
class AccessKey(models.Model):
|
||||||
|
|
|
@ -108,11 +108,21 @@
|
||||||
keypair.PK.toBytes(PKbytes);
|
keypair.PK.toBytes(PKbytes);
|
||||||
keypair.SK.toBytes(SKbytes);
|
keypair.SK.toBytes(SKbytes);
|
||||||
|
|
||||||
$('input#public-key').val(PKbytes.toString());
|
var PKB64Encoded = "";
|
||||||
$('input#secret-key').val(SKbytes.toString());
|
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);
|
||||||
|
|
||||||
//mostly code from before here
|
//mostly code from before here
|
||||||
var blob = new Blob([SKbytes.toString()], {type : 'text/plain'});
|
var blob = new Blob([SKB64Encoded], {type : 'text/plain'});
|
||||||
|
|
||||||
var dlBtn = $('a#download-btn');
|
var dlBtn = $('a#download-btn');
|
||||||
var url = URL.createObjectURL(blob);
|
var url = URL.createObjectURL(blob);
|
||||||
|
|
|
@ -15,6 +15,14 @@ function csrfSafeMethod(method) {
|
||||||
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getKeyBytes(key, byteArray) {
|
||||||
|
for(let i = 0; i < key.length; i += 4) {
|
||||||
|
let B64EncodedByte = key.substring(i, i + 4);
|
||||||
|
|
||||||
|
byteArray.push(atob(B64EncodedByte));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function showDialog(titleTxt, bodyTxt) {
|
function showDialog(titleTxt, bodyTxt) {
|
||||||
var modalDialog = $('#modalDialog');
|
var modalDialog = $('#modalDialog');
|
||||||
var title = modalDialog.find('.modal-title');
|
var title = modalDialog.find('.modal-title');
|
||||||
|
@ -37,7 +45,14 @@ function validateSKFromString(SKStr) {
|
||||||
// Re-create the SK from the string byte definition
|
// Re-create the SK from the string byte definition
|
||||||
let ctx = new CTX("BN254CX");
|
let ctx = new CTX("BN254CX");
|
||||||
|
|
||||||
let skBytes = SKStr.split(",");
|
// Check that the length is valid, otherwise display an error
|
||||||
|
if(!(SKStr.length % 4 === 0)) {
|
||||||
|
showDialog('Error',
|
||||||
|
'The length of the supplied secret key appears to be invalid. Check and try again.');
|
||||||
|
}
|
||||||
|
|
||||||
|
let skBytes = [];
|
||||||
|
getKeyBytes(SKStr, skBytes);
|
||||||
let sk = new ctx.BIG.fromBytes(skBytes);
|
let sk = new ctx.BIG.fromBytes(skBytes);
|
||||||
|
|
||||||
// Re-create the params
|
// Re-create the params
|
||||||
|
@ -56,10 +71,8 @@ function validateSKFromString(SKStr) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Re-create the trustee PK from the string byte definition
|
// Re-create the trustee PK from the string byte definition
|
||||||
let pkBytes = trustee_pk.split(',').map(function(byteStr) {
|
let pkBytes = [];
|
||||||
return parseInt(byteStr)
|
getKeyBytes(trustee_pk, pkBytes);
|
||||||
});
|
|
||||||
|
|
||||||
let pk = new ctx.ECP.fromBytes(pkBytes);
|
let pk = new ctx.ECP.fromBytes(pkBytes);
|
||||||
|
|
||||||
// Check that the SK supplies generates the PK we know about
|
// Check that the SK supplies generates the PK we know about
|
||||||
|
@ -75,7 +88,8 @@ function decryptSubmitCiphers() {
|
||||||
else {
|
else {
|
||||||
// Rebuild the trustee's secret key
|
// Rebuild the trustee's secret key
|
||||||
var ctx = new CTX("BN254CX");
|
var ctx = new CTX("BN254CX");
|
||||||
var skBytes = skString.split(",");
|
var skBytes = [];
|
||||||
|
getKeyBytes(skString, skBytes);
|
||||||
var sk = new ctx.BIG.fromBytes(skBytes);
|
var sk = new ctx.BIG.fromBytes(skBytes);
|
||||||
|
|
||||||
var inputs = $("form input[type=text]");
|
var inputs = $("form input[type=text]");
|
||||||
|
|
Reference in a new issue