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

Openssh-format private keys exported from putty fail to parse #316

Open
quexten opened this issue Nov 18, 2024 · 5 comments · May be fixed by #321
Open

Openssh-format private keys exported from putty fail to parse #316

quexten opened this issue Nov 18, 2024 · 5 comments · May be fixed by #321

Comments

@quexten
Copy link

quexten commented Nov 18, 2024

Hi,

putty (putty-gen) apparently encodes keys (somehow) differently to openssh when exporting to the openssh format. These keys fail to parse with the ssh-key crate with Encoding(Pem(Base64(InvalidEncoding))), but parse fine with openssh:

RSA:

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdz
c2gtcnNhAAAAAwEAAQAAAQEAootgTLcKjSgPLS2+RT3ZElhktL1CwIyM/+3IqEq0
0fl/rRHBT8otklV3Ld7DOR50HVZSoV0u9qs0WOdxcjEJlJACDClmxZmFr0BQ/E2y
V5xzuMZj3Mj+fL26jTmM3ueRHZ0tU5ubSFvINIFyDGG70F7VgkpBA8zsviineMSU
t1iIPi/6feL6h7QAFUk6JdQJpPTs9Nb2+DAQ9lMS2614cxLXkfUIXA4NvHMfZGdU
dq1mBJIAWZ4PPJ6naUcu0lVYjuVEAOE4UoHxr6YlW4yyAF/I1YXBFpcHG7P0egvg
neTPli5Wzum0XDsOPivqr6z2E5k7nzyGXUaP5MjRfDDVLwAAA9D6lTpR+pU6UQAA
AAdzc2gtcnNhAAABAQCii2BMtwqNKA8tLb5FPdkSWGS0vULAjIz/7cioSrTR+X+t
EcFPyi2SVXct3sM5HnQdVlKhXS72qzRY53FyMQmUkAIMKWbFmYWvQFD8TbJXnHO4
xmPcyP58vbqNOYze55EdnS1Tm5tIW8g0gXIMYbvQXtWCSkEDzOy+KKd4xJS3WIg+
L/p94vqHtAAVSTol1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rZXktMjAyNDExMTgBAgME
BQYHCAkK
-----END OPENSSH PRIVATE KEY-----

Ed25519:

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtz
c2gtZWQyNTUxOQAAACDp0/9zFBCyZs5BFqXCJN5i1DTanzPGHpUeo2LP8FmQ9wAA
AKCyIXPqsiFz6gAAAAtzc2gtZWQyNTUxOQAAACDp0/9zFBCyZs5BFqXCJN5i1DTa
nzPGHpUeo2LP8FmQ9wAAAEDQioomhjmD+sh2nsxfQLJ5YYGASNUAlUZHe9Jx0p47
H+nT/3MUELJmzkEWpcIk3mLUNNqfM8YelR6jYs/wWZD3AAAAEmVkZHNhLWtleS0y
MDI0MTExOAECAwQFBgcICQoL
-----END OPENSSH PRIVATE KEY-----

One notable difference is that these keys have a linewidth of 64 whereas openssh uses 70.
Re-formatting the keys to be linewidth 70 in a text editor leads to an "Encoding(Length)" error.

@tarcieri
Copy link
Member

This appears to be a dup of #195 which was fixed in #252

@tarcieri tarcieri closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
@tarcieri tarcieri reopened this Nov 19, 2024
@tarcieri
Copy link
Member

Reopening because:

Re-formatting the keys to be linewidth 70 in a text editor leads to an "Encoding(Length)" error.

@Eugeny
Copy link
Contributor

Eugeny commented Dec 27, 2024

This is due to the padding length being over 8 bytes ("block size" for no-encryption cipher??) for unencrypted keys that PuTTY generates for some reason

@Eugeny
Copy link
Contributor

Eugeny commented Dec 27, 2024

The padding seems to correctly contain a number seq as per format ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) - just too many of them

@Eugeny
Copy link
Contributor

Eugeny commented Dec 27, 2024

After bruteforcing through possible padding lengths with puttygen by changing the comment length, it appears that puttygen is using 16 as "block size" for unencrypted keys.

Eugeny added a commit to Eugeny/RustCrypto-SSH that referenced this issue Dec 27, 2024
Eugeny added a commit to Eugeny/RustCrypto-SSH that referenced this issue Dec 27, 2024
Eugeny added a commit to Eugeny/RustCrypto-SSH that referenced this issue Dec 27, 2024
Eugeny added a commit to Eugeny/RustCrypto-SSH that referenced this issue Dec 27, 2024
Eugeny added a commit to Eugeny/RustCrypto-SSH that referenced this issue Dec 27, 2024
Eugeny added a commit to Eugeny/RustCrypto-SSH that referenced this issue Dec 27, 2024
Eugeny added a commit to Eugeny/RustCrypto-SSH that referenced this issue Dec 27, 2024
Eugeny added a commit to Eugeny/RustCrypto-SSH that referenced this issue Dec 29, 2024
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

Successfully merging a pull request may close this issue.

3 participants