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:
vince0656 2018-09-04 15:21:31 +01:00
parent 801f6b274f
commit da74180884
5 changed files with 57 additions and 18 deletions

View File

@ -10,6 +10,7 @@ Dependencies can be found in 'package.json' and installed using 'npm install'
var port = 8080;
var Buffer = require('buffer').Buffer;
var atob = require("atob");
var CTX = require('milagro-crypto-js');
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
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
{
console.log('Combining ' + partials.length + " public keys into one...");
for (var i = partials.length - 1; i >= 0; i--) {
console.log('PK' + i + ': ' + partials[i]);
var bytes = Buffer.from(partials[i].split(','), 'hex');
var pk = new ctx.ECP.fromBytes(bytes);
parsed.push(pk);
for (let i = partials.length - 1; i >= 0; i--) {
console.log('PK' + i + ': ' + partials[i]);
let rawBytes = [];
getKeyBytes(partials[i], rawBytes);
parsed.push(new ctx.ECP.fromBytes(Buffer.from(rawBytes, 'hex')));
}
}
else if(partials.length === 1)
{
console.log("Combining just one public key...");
var bytes = Buffer.from(partials[0].split(','), 'hex');
var pk = new ctx.ECP.fromBytes(bytes);
parsed.push(pk);
let PKStr = partials[0];
console.log("PK: " + PKStr);
let rawBytes = [];
getKeyBytes(PKStr, rawBytes);
parsed.push(new ctx.ECP.fromBytes(Buffer.from(rawBytes, 'hex')));
}
response.json(combine_pks(parsed));

View File

@ -17,6 +17,7 @@
"author": "Bingsheng Zang, Thomas Smith, Vincent de Almeida",
"license": "ISC",
"dependencies": {
"atob": "^2.1.2",
"body-parser": "^1.18.3",
"express": "^4.16.3",
"milagro-crypto-js": "git+https://github.com/milagro-crypto/milagro-crypto-js.git"

View File

@ -145,7 +145,7 @@ class Event(models.Model):
class TrusteeKey(models.Model):
event = models.ForeignKey(Event, 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):

View File

@ -108,11 +108,21 @@
keypair.PK.toBytes(PKbytes);
keypair.SK.toBytes(SKbytes);
$('input#public-key').val(PKbytes.toString());
$('input#secret-key').val(SKbytes.toString());
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);
//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 url = URL.createObjectURL(blob);

View File

@ -15,6 +15,14 @@ function csrfSafeMethod(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) {
var modalDialog = $('#modalDialog');
var title = modalDialog.find('.modal-title');
@ -37,7 +45,14 @@ function validateSKFromString(SKStr) {
// Re-create the SK from the string byte definition
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);
// Re-create the params
@ -56,10 +71,8 @@ function validateSKFromString(SKStr) {
};
// Re-create the trustee PK from the string byte definition
let pkBytes = trustee_pk.split(',').map(function(byteStr) {
return parseInt(byteStr)
});
let pkBytes = [];
getKeyBytes(trustee_pk, pkBytes);
let pk = new ctx.ECP.fromBytes(pkBytes);
// Check that the SK supplies generates the PK we know about
@ -75,7 +88,8 @@ function decryptSubmitCiphers() {
else {
// Rebuild the trustee's secret key
var ctx = new CTX("BN254CX");
var skBytes = skString.split(",");
var skBytes = [];
getKeyBytes(skString, skBytes);
var sk = new ctx.BIG.fromBytes(skBytes);
var inputs = $("form input[type=text]");