Commit 2b067ded authored by Cédric Moreau's avatar Cédric Moreau

Allow to select zero members while making new block

parent 23b58c2f
......@@ -716,52 +716,65 @@ function KeyService (conn, conf, PublicKeyService) {
},
], callback);
}, function(err){
var block = new KeyBlock();
block.version = 1;
block.currency = joinData[fingerprints[0]].ms.currency;
block.number = 0;
// Members merkle
fingerprints.sort();
var tree = merkle(fingerprints, 'sha1').process();
block.membersCount = fingerprints.length;
block.membersRoot = tree.root();
block.membersChanges = [];
fingerprints.forEach(function(fpr){
block.membersChanges.push('+' + fpr);
});
// Public keys
block.publicKeys = [];
_(joinData).values().forEach(function(join){
var pkData = {
fingerprint: join.pubkey.fingerprint,
packets: base64.encode(join.pubkey.getWritablePacketsWithoutOtherCertifications().write())
};
block.publicKeys.push(pkData);
});
// Memberships
block.memberships = [];
_(joinData).values().forEach(function(join){
var ms = join.ms;
var shortMS = [1, join.pubkey.fingerprint, 'IN', ms.date.timestamp(), ms.userid].join(':');
block.memberships.push(shortMS);
});
// Memberships signatures
block.membershipsSigs = [];
_(joinData).values().forEach(function(join){
var ms = join.ms;
var splits = dos2unix(ms.signature).split('\n');
var signature = "";
var keep = false;
splits.forEach(function(line){
if (keep && !line.match('-----END PGP') && line != '') signature += line + '\n';
if (line == "") keep = true;
});
block.membershipsSigs.push({
fingerprint: join.pubkey.fingerprint,
packets: signature
});
});
done(null, block);
async.waterfall([
function (next){
KeyBlock.current(function (err, current){
if (!current && uids.length == 0) {
next('Cannot create root block without members');
return;
}
else next();
});
},
function (next){
var block = new KeyBlock();
block.version = 1;
block.currency = joinData[fingerprints[0]].ms.currency;
block.number = 0;
// Members merkle
fingerprints.sort();
var tree = merkle(fingerprints, 'sha1').process();
block.membersCount = fingerprints.length;
block.membersRoot = tree.root();
block.membersChanges = [];
fingerprints.forEach(function(fpr){
block.membersChanges.push('+' + fpr);
});
// Public keys
block.publicKeys = [];
_(joinData).values().forEach(function(join){
var pkData = {
fingerprint: join.pubkey.fingerprint,
packets: base64.encode(join.pubkey.getWritablePacketsWithoutOtherCertifications().write())
};
block.publicKeys.push(pkData);
});
// Memberships
block.memberships = [];
_(joinData).values().forEach(function(join){
var ms = join.ms;
var shortMS = [1, join.pubkey.fingerprint, 'IN', ms.date.timestamp(), ms.userid].join(':');
block.memberships.push(shortMS);
});
// Memberships signatures
block.membershipsSigs = [];
_(joinData).values().forEach(function(join){
var ms = join.ms;
var splits = dos2unix(ms.signature).split('\n');
var signature = "";
var keep = false;
splits.forEach(function(line){
if (keep && !line.match('-----END PGP') && line != '') signature += line + '\n';
if (line == "") keep = true;
});
block.membershipsSigs.push({
fingerprint: join.pubkey.fingerprint,
packets: signature
});
next(null, block);
});
},
], done);
});
};
......
......@@ -244,21 +244,22 @@ program
mss.forEach(function(ms){
uids.push(ms.userid);
});
inquirer.prompt([{
type: "checkbox",
name: "uids",
message: "Initial members of the Web of Trust",
choices: uids,
default: uids[0]
}], function (answers) {
next(null, answers.uids);
});
if (mss.length > 0) {
inquirer.prompt([{
type: "checkbox",
name: "uids",
message: "Initial members of the Web of Trust",
choices: uids,
default: uids[0]
}], function (answers) {
next(null, answers.uids);
});
} else {
logger.info('No membership were found, trying to write an empty block');
next(null, []);
}
},
function (uids, next){
if (uids.length == 0) {
next('You must select at least 1 user');
return;
}
KeychainService.generateRoot(uids, next);
},
function (root, next){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment