From 211c73c322232cb4d6e5897898fe9c3341375e5f Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Sun, 24 Dec 2017 16:21:38 +1300 Subject: [PATCH] fix: if no --pass, then no key management Helps #1135 --- src/core/components/no-keychain.js | 6 ++++-- src/core/components/pre-start.js | 15 ++++++++++----- test/cli/key.js | 9 +++++---- test/utils/ipfs-factory-instance/index.js | 1 + 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/core/components/no-keychain.js b/src/core/components/no-keychain.js index bae80d21c4..ced2f142dc 100644 --- a/src/core/components/no-keychain.js +++ b/src/core/components/no-keychain.js @@ -1,17 +1,19 @@ 'use strict' function fail () { - throw new Error('Key management is not yet implemented') + throw new Error('Key management requires the daemon to run with \'--pass ...\'') } class NoKeychain { - static get options () { return {} } + static get options () { fail() } + static generateOptions () { fail() } createKey () { fail() } listKeys () { fail() } findKeyById () { fail() } findKeyByName () { fail() } renameKey () { fail() } + removeKey () { fail() } exportKey () { fail() } importKey () { fail() } importPeer () { fail() } diff --git a/src/core/components/pre-start.js b/src/core/components/pre-start.js index 738949edd8..76f94cf052 100644 --- a/src/core/components/pre-start.js +++ b/src/core/components/pre-start.js @@ -5,7 +5,7 @@ const PeerInfo = require('peer-info') const multiaddr = require('multiaddr') const waterfall = require('async/waterfall') const Keychain = require('libp2p-keychain') - +const NoKeychain = require('./no-keychain') /* * Load stuff from Repo into memory */ @@ -16,10 +16,15 @@ module.exports = function preStart (self) { waterfall([ (cb) => self._repo.config.get(cb), (config, cb) => { - const pass = self._options.pass || 'todo do not hardcode the pass phrase' - const keychainOptions = Object.assign({passPhrase: pass}, config.Keychain) - self._keychain = new Keychain(self._repo.keys, keychainOptions) - self.log('keychain constructed') + const pass = self._options.pass + if (pass) { + const keychainOptions = Object.assign({passPhrase: pass}, config.Keychain) + self._keychain = new Keychain(self._repo.keys, keychainOptions) + self.log('keychain constructed') + } else { + self._keychain = new NoKeychain() + self.log('no keychain, use --pass') + } cb(null, config) }, (config, cb) => { diff --git a/test/cli/key.js b/test/cli/key.js index 076225ab7e..e2eb6e53aa 100644 --- a/test/cli/key.js +++ b/test/cli/key.js @@ -8,6 +8,7 @@ const hat = require('hat') describe('key', () => runOnAndOff.off((thing) => { const name = 'test-key-' + hat() const newName = 'test-key-' + hat() + const pass = '--pass ' + hat() let ipfs before(() => { @@ -17,7 +18,7 @@ describe('key', () => runOnAndOff.off((thing) => { it('gen', function () { this.timeout(40 * 1000) - return ipfs(`key gen ${name} --type rsa --size 2048`) + return ipfs(`${pass} key gen ${name} --type rsa --size 2048`) .then((out) => { expect(out).to.include(`generated ${name}`) }) @@ -26,7 +27,7 @@ describe('key', () => runOnAndOff.off((thing) => { it('list', function () { this.timeout(20 * 1000) - return ipfs('key list') + return ipfs(`${pass} key list`) .then((out) => { expect(out).to.include(name) }) @@ -35,7 +36,7 @@ describe('key', () => runOnAndOff.off((thing) => { it('rename', function () { this.timeout(20 * 1000) - return ipfs(`key rename ${name} ${newName}`) + return ipfs(`${pass} key rename ${name} ${newName}`) .then((out) => { expect(out).to.include(`renamed to ${newName}`) }) @@ -44,7 +45,7 @@ describe('key', () => runOnAndOff.off((thing) => { it('rm', function () { this.timeout(20 * 1000) - return ipfs(`key rm ${newName}`) + return ipfs(`${pass} key rm ${newName}`) .then((out) => { expect(out).to.include(newName) }) diff --git a/test/utils/ipfs-factory-instance/index.js b/test/utils/ipfs-factory-instance/index.js index 568a1710a7..e5d0e8839c 100644 --- a/test/utils/ipfs-factory-instance/index.js +++ b/test/utils/ipfs-factory-instance/index.js @@ -40,6 +40,7 @@ function Factory () { const repo = createTempRepo(repoPath) const node = new IPFS({ repo: repo, + pass: hat(), init: { bits: 1024 }, config: config, EXPERIMENTAL: {