Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: if no --pass, then no key management
Browse files Browse the repository at this point in the history
Helps #1135
  • Loading branch information
richardschneider committed Dec 24, 2017
1 parent 791000c commit 211c73c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/core/components/no-keychain.js
Original file line number Diff line number Diff line change
@@ -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() }
Expand Down
15 changes: 10 additions & 5 deletions src/core/components/pre-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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) => {
Expand Down
9 changes: 5 additions & 4 deletions test/cli/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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}`)
})
Expand All @@ -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)
})
Expand All @@ -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}`)
})
Expand All @@ -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)
})
Expand Down
1 change: 1 addition & 0 deletions test/utils/ipfs-factory-instance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function Factory () {
const repo = createTempRepo(repoPath)
const node = new IPFS({
repo: repo,
pass: hat(),
init: { bits: 1024 },
config: config,
EXPERIMENTAL: {
Expand Down

0 comments on commit 211c73c

Please sign in to comment.