Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse Private Keys from PuttyGen? #191

Closed
rclai opened this issue Nov 19, 2014 · 19 comments
Closed

Cannot parse Private Keys from PuttyGen? #191

rclai opened this issue Nov 19, 2014 · 19 comments

Comments

@rclai
Copy link

rclai commented Nov 19, 2014

Are the private keys generated from PuttyGen not compatible with ssh2?

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

The private keys that are generated (SSH-2 RSA) look like this:

PuTTY-User-Key-File-2: ssh-dss
Encryption: none
Comment: dsa-key-20141119
Public-Lines: 18
AAAAB3NzaC1kc3MAAAEBALRAc0iurfC9QcN8svhWZ696BsMwCSqlh4lB7SgUfhsI
7qClbw+5Lf4xUHjy0/851/a/iL4wPa5pEpN35cql8JTOfVdukhOPUqyiZzdxNdWC
IY9xu0DDQjRmkKQ5QSumbVggWyTe/Td1nbQlMT4RcQBDut1viKLueWkWsecj0vLJ
wGI1P80Vwz+FgMY/9mRJjPZl0nZAhi791/Ig3N6Nyq8ecAA+Z+KNa6Dj6g96GslU
H9hZbviuPaoFnaaq150rZBo6owe2CI7ITofS30jNL8LuFeaQg9P51/39YLi6RNS4
0zyiSWhFw+S/m9GayzwGGQQyCUoaxSCRo7//WxxMPCEAAAAVAO6ae6AgEuerk0Wa
/HfbwxbsPOHzAAABAHPoUUfiIl16qFb9SzpTDPuo0ZxChX9zbkL8Y+vDo1k4664P
--- redacted ---
Private-Lines: 1
AAAAFHhl3RpT/xmScMoRL2RcA5z6gGO3
Private-MAC: 3617639b950751ab5149bdbf8b88044b6af394f1

I get this error message:

[Error: Cannot parse privateKey: Unsupported key format]
@rclai rclai changed the title Windows using Private Keys from PuttyGen Cannot parse Private Keys from PuttyGen? Nov 19, 2014
@unknownbrackets
Copy link

You want it to start like this:

-----BEGIN RSA PRIVATE KEY-----

Using PuTTYgen, load the existing key, and then select Conversions -> Export OpenSSH key. This file should work fine. You'll want this version for other tools as well.

That being said, supporting PuTTY style keys might be a useful feature request for some, I suppose. In fact, there's a TODO for it.

-[Unknown]

@mscdex
Copy link
Owner

mscdex commented Dec 2, 2014

FWIW PPKs are now supported in the rewrite branch.

@mscdex mscdex closed this as completed Dec 7, 2014
@btz1211
Copy link

btz1211 commented May 21, 2015

I am attempting to write a Restful style File Service that allows you to grab files from servers. I am getting the following error: ERROR::Error: All configured authentication methods failed. I use the same exact .ppk file that I use for putty and that works.

this is my code for making the connection:

this.client.connect({
    host: hostInfo['host'],
    port: hostInfo['port'],
    username: hostInfo['username'],
    password: hostInfo['password'],
    publicKey: fs.readFileSync(hostInfo['key']['path']).toString('utf8').trim()
});

@mscdex
Copy link
Owner

mscdex commented May 21, 2015

@btz1211 You should be using privateKey and not publicKey

@btz1211
Copy link

btz1211 commented May 21, 2015

@mscdex, thank you for replying so promptly. I've updated my code to use 'privateKey' instead:

this.client.connect({
host: hostInfo['host'],
port: hostInfo['port'],
username: hostInfo['username'],
password: hostInfo['password'],
privateKey: fs.readFileSync(hostInfo['key']['path']).toString('utf8').trim()
});

now I am getting: Error: Malformed private key (expected sequence) at genPublicKey

@mscdex
Copy link
Owner

mscdex commented May 21, 2015

@btz1211 Is your key encrypted? Either way, are you able to generate a new and unused PPK that reproduces the same error?

@btz1211
Copy link

btz1211 commented May 21, 2015

My key is not encrypted. Just used PuttyGen to generate another private key. I got the same error. This is what my ppk file look like:

PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQDXnAkBSiMnU8r/M8s/qjqFqqivwcuq2tqR
...
Private-Lines: 14
AAABADIaCymmjaas3QYShg9kQjcfYhV9ZhNsyc+LMdvonN2KdauMniuJD+2QK6Kq

...

@mscdex
Copy link
Owner

mscdex commented May 21, 2015

Can you provide the actual literal file contents somewhere? I'd like to add it as a test so I can duplicate it on my end as well.

@btz1211
Copy link

btz1211 commented May 22, 2015

@mscdex , sure. Here is the full file content:

PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQDXnAkBSiMnU8r/M8s/qjqFqqivwcuq2tqR
PaepSzxYX91xaEy3Gk8uiBGmfIlUgNXF0JUDSe6zQOkGgJg7etO/tYdSYXOuZRt3
0772tkRz+lasNPJnO/xpxTf5hClsOGs2MVSGeWAxuoAH7filtPZcxhA34f/ai13x
Kh3pVjKLQvaeyc4fC1a+7JVuKpbOs+QAZaAqtPzJtKm/2qKJodfkqe6eVrcI5gMT
YQ82C/++BbnSLj5VAzBg07NQYIpUUwNp7KUyhHa/eS8gGQPPAmr8+VETs8Bsvfx9
IUL3uhXJhc8PfcLkccIvq0j7mV565BdVOHLCIePdSao2q3hItnoX
Private-Lines: 14
AAABADIaCymmjaas3QYShg9kQjcfYhV9ZhNsyc+LMdvonN2KdauMniuJD+2QK6Kq
qGmCbr9oFSkueUD1Ap1VGit/cqQ6Tjh+JtMlAY52ckhvuDUdCbs5rmH6Fh5M9jUG
yW6+hW5zOr1J59L1qXCeX0GrGBt7Vle5V4VV71zwh4TaR+J+HtqXkkwIgkCIMPrs
fV6fLWG3Xf36uYpAdmufpw0n3JEAAACBAOuxs8C9E9wXyOX25WVkijLKpENgudRU
NHdROpDIyK+RRQ9uVtistt0u9Sm/MAOOmpM/2jr9bG+mKe5qCalMZgqIsSDf+YMG
lrncr9ONIH2oyw7RfRxk//DrLGjItaXeIRrIG6T0B2fU8Vas8BMyQkbhCiHv1hLS
Zo6LcDIaAcEQuBG7/zDL3NAtCnd/Vp526jcKO5q8V9XVfrGYuo6UF4Wgrh3W7wAA
LspY7tDAQBMbn2JFCcdF+vj2C2c00jB0YhWoKsAGqxlv3FE6dl2L6lRDBI0h6NJ2
PGzGKxwSuU2aFxNR0fbTEo881MSQxuiUyZgh8kv8YeUQqH+FAscTHg1/UG5GCDsM
ggWYkMJtLU9ZAAAAgQDqL1xndR3aA/lIKpRt0jjbWj54vPiKvE2jcL7gkHuiLa1O
l9LPODpojlZjhP1VksNtglDUpLw/3TrI7ewHOL5R2i+4iXvxWYz6VKYr0UeHdVKG
AIEAwC7b1bHn0a0l8xw0aiPj7vGj5R0jG2ARXJlkCrEptu42247iD59ZjxYzPnqz
FkkVg6jdeEYqndR0hvY4oj5uJihTPeOuVPAPu/tW2sSkl8aUZVB8bW/8MI8DfYcn
4PpH0k3cMI7nI2M6Pyh71iSD9p0qfXKs4if/hygUKrc0Avs=
Private-MAC: 74991ab5b9e5adbae8e0fa0c6781b1db8ba1240c

Just a quick question, I see in the genPublicKey method your first check is:

if (privKey[0] === 0x30)

Why is that? I think that's the issue here. My file starts with 'A'

@mscdex
Copy link
Owner

mscdex commented May 22, 2015

@btz1211 Try re-installing ssh2 and it should pick up the fix that I just pushed to ssh2-streams. Let me know if it does or doesn't work for you.

@btz1211
Copy link

btz1211 commented May 23, 2015

I am still getting the same error:

Error: Malformed private key (expected sequence) at genPublicKey (E:\NodeJS\NodeJS-SSH-Service\node_modules\ssh2\node_modules\ssh2-streams\lib\utils.js:307:13) at Client.connect

@ganna-shmatova
Copy link

+1 getting this too =[

PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQDY3ZZzql+hnn8TpOHUk96KiX2pk8ND5p+c
EqLbFnpi5+5iqx1hdJbZo0oW69Gx3wcWD3RVT8fVJDPmtsXlZkRhjGAOiz8VFpKJ
u2i2dyLZiX3xLzDI76aHIVW7Xehf3NE3ugHFjBiV41XaN6MSE+xeP3U7Mp16Ee3l
QZ8BJ5ujC5ZGhEgd27GIyV+yndee/T9YHms0tpYh6AC039QFWot5LlHnz2FlvTqU
mIvdn99KZSERlZ1sATceHxFHauJN6M0tFmN1h/KfNBTflI5IUevOwpbEWnSBXOVM
3pCFyftu9j7oQydtozE4G5T5GoxiJJ5DbznnEcdW8lKAX7lMznvR
Private-Lines: 14
AAABADpl8U3UY0wyUiYIEIgeCZ9kxuITWFHAmNp+ajx1IR/hNOB9E7w+l6CjyB/E
AQPU+yOFpd4TTcynoxJNxZywnVlnY7aG6MXU/kD4pon8KvZJgBCilJCHeGCLKXr7
HsgxvmUzQabgwv4Z6dSJhvAnTU9T5025o45rpZRGx3qYH+EXjrG17tIog45xp3pk
9qWo46ZdCMKNfa2LwNcibbVUPMvgLZah6b/atPI3qXAqnoE4PWrVnNbgwP2vNnaY
j/QK2gESc4nNkr0QEDZaLiYlUGJYmOKi7TzVUVIRirwK4jAmFXyHcBiRNAwBonnI
dIQKNgnZkdVuFKWjNvKPROTycQEAAACBAPTa7XG7ko6aWE334HGGLLGRdtsgqePJ
fMl8hIm1wOsLkVZ7gLJH6T0fhyR32oWnYNcvpgp/xVMpDdSp+tIJhTSlAAz+1jQA
C5aNr/CXu6vQow6zFSnoQIYtnr619JzRITs2kZlm8Sp/i709f+FXj47RJXGBTkOU
fBtfgaVbIxsVAAAAgQDivIXjCCbv4sLpomvrKjp8YTgrlmVadCIhIRsLxVwXQkFm
UdsYdjD9gH1kCN/UAsYba0qs99+ih4QQM2KBz30nj5DREFMZrjQjPvFQ3KJ0zI6K
sIxQZ2fUOPhhg2SY8brwKQjfBuieFj7dI5kXBBoi4inQ/+Al8IjVGdCCIK2czQAA
AIB++WLFsz1J/zqskCM4Dyf927m00pmL99KuyaDK5Gad2Vmuj9Ky4i9+TSVusm52
h0HA6GHt0s2wLbdLJszVZwhB7sTIYI8unAhgN4mC9Z7zObvijFX3Z/h5gne771r0
UAWUmFSU4g5Sd+kz4is5i8Ig1/Q5vR/sdWV/ROcHkhUlCA==
Private-MAC: 91b6b2cd0050a2d8c5cf9920b9baf568c28cb16b

@btz1211
Copy link

btz1211 commented Jun 10, 2015

Ganna,
In the mean while, you can try to import your *.pem file in Puttygen and under "Conversions" pick "Export OpenSSH key", that should provide you with a key file that works with ssh2. Hope this helps

@mscdex
Copy link
Owner

mscdex commented Jun 20, 2015

@ganna-shmatova @btz1211 What version of PuTTYGen did you use to create those keys? I get a MAC error when trying to load either of your keys (via PuTTYGen).

@ganna-shmatova
Copy link

@mscdex it was generated with 0.9.52 beta filezilla

@mscdex
Copy link
Owner

mscdex commented Jun 22, 2015

@ganna-shmatova How did you generate a PPK with FileZilla?

@ganna-shmatova
Copy link

@mscdex Open FileZilla server, connect,
edit > settings > FTP over TLS > generate new certificate

@mscdex
Copy link
Owner

mscdex commented Jun 22, 2015

@ganna-shmatova That's not for generating PuTTY keys, that's for generating a TLS certificate (for the server). Those are two different things. As far as I know the only way to generate PuTTY keys is to use PuTTYGen, which can save out to the .PPK key format.

@DevStarlight
Copy link

@btz1211 that worked like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants