jcoglan / vault

Generates safe passwords so you never need to remember them
https://getvau.lt
471 stars 64 forks source link

TypeError: Cannot read property 'filter' of undefined #30

Open trdarr opened 8 years ago

trdarr commented 8 years ago

I use Homebrew to install Node on OS X 10.10.5, then use npm 3.5.3 to install Vault 0.3.0.

$ brew install node
🍺  /usr/local/Cellar/node/5.4.1_1: 3,135 files, 35.5M
$ which node
/usr/local/bin/node
$ node --version
v5.4.1
$ which npm
/usr/local/bin/npm
$ npm --version
3.5.3
$ npm install -g vault
/usr/local/lib
`-- vault@0.3.0
  +-- posix-argv-parser@0.4.2
  | `-- when@1.3.0
  +-- pw@0.0.4
  +-- ssh-agent@0.2.4
  | +-- ctype@0.5.4
  | `-- posix-getopt@1.1.0
  `-- vault-cipher@0.3.1

When I try to generate a password with my SSH key, I get a TypeError.

$ vault --key github
/usr/local/lib/node_modules/vault/bin/vault:50
      keys = keys.filter(function(k) { return k.type === 'ssh-rsa' });
                 ^

TypeError: Cannot read property 'filter' of undefined
    at /usr/local/lib/node_modules/vault/bin/vault:50:18
    at Socket.<anonymous> (/usr/local/lib/node_modules/vault/node_modules/ssh-agent/lib/ssh_agent_client.js:294:12)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1255:8)
    at nextTickCallbackWith2Args (node.js:474:9)
    at process._tickCallback (node.js:388:17)

I realize now that this issue is caused by ssh-agent not starting as a result of my having tried to replace OS X’s built-in ssh-agent with the ssh-agent from Homebrew-installed OpenSSH—other people have had similar problems (Homebrew/homebrew-dupes#242).

While trying to reproduce this issue to submit it, I encountered a similar exception caused by a ~/.vault file left behind by a previous installation: when I tried to generate a password without the --key option, I got a TypeError.

$ vault github
/usr/local/lib/node_modules/vault/bin/vault:76
      var key = keys.filter(function(k) { return k.ssh_key === sshKey })[0];
                    ^

TypeError: Cannot read property 'filter' of undefined
    at /usr/local/lib/node_modules/vault/bin/vault:76:21
    at identitiesAnswer (/usr/local/lib/node_modules/vault/node_modules/ssh-agent/lib/ssh_agent_client.js:179:12)
    at Socket.<anonymous> (/usr/local/lib/node_modules/vault/node_modules/ssh-agent/lib/ssh_agent_client.js:280:12)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at Pipe.onread (net.js:523:20)
trdarr commented 8 years ago

I also now realize that this is almost identical to the other issue I opened in a few months ago (#29), and is partially fixed by the corresponding pull request (#27), so I’ll add a commit to that pull request that covers the other unguarded call to keys.filter.