Skip to content
Snippets Groups Projects
Commit 252148ee authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Now may choose which OpenPGP impl to use for signed requests

parent 7a611258
Branches
Tags
No related merge requests found
......@@ -484,17 +484,27 @@ This stuff should be refactorized elsewhere
function httpgp(app, conf, done) {
// PGP signature of requests
if(conf.pgpkey){
var privateKey = conf.pgpkey;
async.waterfall([
function (next) {
if (conf.openpgpjs) {
var pgp = jpgp();
var privateKey = openpgp.key.readArmored(conf.pgpkey).keys[0];
privateKey.decrypt(conf.pgppasswd);
var signingFunc = async.apply(pgp.sign.bind(pgp.sign), privateKey);
next(null, function (message, done) {
jpgp().sign(message, privateKey, done);
});
} else {
var asciiPrivateKey = conf.pgpkey;
var keyring = '~/.gnupg/ucoin_' + module.exports.fingerprint();
pgplogger.debug("Keyring = %s", keyring);
var gnupg = new (require('./gnupg'))(privateKey, conf.pgppasswd, module.exports.fingerprint(), keyring);
var gnupg = new (require('./gnupg'))(asciiPrivateKey, conf.pgppasswd, module.exports.fingerprint(), keyring);
gnupg.init(function (err) {
next(err, function (message, done) {
gnupg.sign(message, done);
});
});
}
},
function (signFunc, next){
module.exports.sign = signFunc;
......
......@@ -17,13 +17,17 @@ var IPV6_REGEXP = /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}
function Wizard () {
this.configAll = function (conf, done) {
doTasks(['currency', 'network', 'key', 'autovote'], conf, done);
doTasks(['currency', 'openpgp', 'network', 'key', 'autovote'], conf, done);
};
this.configCurrency = function (conf, done) {
doTasks(['currency'], conf, done);
};
this.configOpenpgp = function (conf, done) {
doTasks(['openpgp'], conf, done);
};
this.configNetwork = function (conf, done) {
doTasks(['network'], conf, done);
};
......@@ -60,6 +64,25 @@ var tasks = {
});
},
openpgp: function (conf, done) {
inquirer.prompt([{
type: "list",
name: "openpgp",
message: "Which OpenPGP implementation to use",
default: conf.openpgpjs != undefined ? (conf.openpgpjs ? 'embedded' : 'system') : 'system',
choices: [{
name: 'openpgp.js - Slow but multiplatform',
value: 'embedded'
},{
name: 'gpg - Fast but must be installed on your system',
value: 'system'
}]
}], function (answers) {
conf.openpgpjs = answers.openpgp == 'embedded';
done();
});
},
network: function (conf, done) {
var noInterfaceListened = true;
if (conf.ipv4 || conf.ipv6) {
......
......@@ -4,6 +4,7 @@ var logger = require('../lib/logger')();
var ConfigurationSchema = new Schema({
currency: {"type": String, "default": null},
openpgpjs: {"type": Boolean, "default": false},
port: {"type": Number, "default": 8033},
ipv4: {"type": String, "default": "127.0.0.1"},
ipv6: {"type": String, "default": null},
......
......@@ -45,6 +45,7 @@ program
.option('--consensus <float>', 'Percent of voters required to accept an amendment', parseFloat)
.option('--msvalidity <timestamp>', 'Duration of a valid membership, in seconds', parseInt)
.option('--vtvalidity <timestamp>', 'Duration of a valid voter, in seconds', parseInt)
.option('--openpgpjs', 'Prefer using embedded Openpgpjs implementation for signing requests')
;
program
......@@ -54,6 +55,7 @@ program
var wiz = wizard();
var task = {
'currency': wiz.configCurrency,
'openpgp': wiz.configOpenpgp,
'network': wiz.configNetwork,
'key': wiz.configKey,
'autovote': wiz.configAutovote
......@@ -265,7 +267,8 @@ function overrideConf(conf) {
ipv4: program.remote4,
ipv6: program.remote6,
port: program.remotep
}
},
openpgpjs: program.openpgpjs
},
db: {
host: program.mhost,
......@@ -292,6 +295,7 @@ function overrideConf(conf) {
// Update conf
if(cli.server.pgp.key) cli.server.pgp.key = fs.readFileSync(cli.server.pgp.key, 'utf8');
conf.currency = cli.currency || conf.currency;
conf.openpgpjs = cli.server.openpgpjs != undefined ? cli.server.openpgpjs : conf.openpgpjs;
conf.ipv4 = cli.server.ipv4address || conf.ipv4;
conf.ipv6 = cli.server.ipv6address || conf.ipv6;
conf.port = cli.server.port || conf.port;
......
......@@ -108,6 +108,7 @@ This will start a command prompt asking for parameters value & validate all of t
```bash
$ ucoind wizard
[?] Currency name: beta_brousouf
[?] Which OpenPGP implementation to use: gpg - Fast but must be installed on your system
[?] IPv4 interface: wlan1 192.168.1.14
[?] IPv6 interface: wlan1 2a01:e35:8a37:f2b0:dd48:5620:5d3c:ce2c
[?] Port: 8080
......@@ -130,7 +131,7 @@ $ ucoind wizard
### Target only few wizard's steps
Wizard is composed of 4 steps: `currency`, `network`, `key`, `autovote`. By adding one of those words to `wizard` command, you will only do the attached steps:
Wizard is composed of 4 steps: `currency`, `openpgp`, `network`, `key`, `autovote`. By adding one of those words to `wizard` command, you will only do the attached steps:
```bash
$ ucoind wizard network
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment