steelbrain / node-ssh

SSH2 with Promises
MIT License
947 stars 94 forks source link

PuTTY 3 (PPK) file throws fs file not found error #435

Closed aditya81070 closed 2 years ago

aditya81070 commented 2 years ago

Hey Team, thanks for the great library 🎉 .

Context

I am using this library for connecting to SFTP server with PEM, PPK files with private key authentication. When using some PPK files, the library started to throw following fs error:

AssertionError [ERR_ASSERTION]: config.privateKey does not exist at given fs path
      at new AssertionError (internal/assert/assertion_error.js:467:5)
      at NodeSSH.connect (/var/task/node_modules/node-ssh/lib/cjs/index.js:147:31)
  }

Cause

As per documentation, I got to know that the library accepts the primary key as a file path or raw content. I am passing the row content so this error shouldn't come at all. After quick google search and looking into the validation/assertion code, I found following issue (check the code)

  1. The code check if config has privateKey.
  2. If it exists then it checks whether it includes BEGIN + KEY OR PuTTY-User-Key-File-2 . If none of them exists in the content then it assumes that provided string is a file path and try to read the file using fs and it eventually throws above mentioned error.

I checked PPK files that I am using and it has PuTTY-User-Key-File-3. This implies that it is new version of PuTTY.

Are there any plans to add support of PuTTY 3 or are there any workarounds for this issue? I am directly getting the content of file from S3 so it won't be possible to copy the content of the private file into local system and then passing the path to library.

steelbrain commented 2 years ago

This should be fixed with https://github.com/steelbrain/node-ssh/pull/436. Will be part of next semver-major, which is going out shortly

steelbrain commented 2 years ago

Fix is out in v13.0.0