Skip to content

Commit f7d2ac1

Browse files
authored
Trim the leading zero from PuTTY ECDSA private keys (#1827)
Fixes #1825
1 parent 2257640 commit f7d2ac1

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/Renci.SshNet/PrivateKeyFile.PuTTY.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public Key Parse()
175175
var curve = publicKeyReader.ReadString(Encoding.ASCII);
176176
var pub = publicKeyReader.ReadBinary();
177177
var prv = privateKeyReader.ReadBinary();
178-
parsedKey = new EcdsaKey(curve, pub, prv);
178+
parsedKey = new EcdsaKey(curve, pub, prv.TrimLeadingZeros());
179179
break;
180180
case "ssh-rsa":
181181
var exponent = publicKeyReader.ReadBigInt();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PuTTY-User-Key-File-3: ecdsa-sha2-nistp256
2+
Encryption: none
3+
Comment: imported-openssh-key
4+
Public-Lines: 3
5+
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNhE4rS0CTev
6+
/VEC6BJ/142eE3dU88t1rpzrSJ3iEcyp+3itM0+182eXSswmunZo/TNyvFE1sXKK
7+
1x0COQJl6hU=
8+
Private-Lines: 1
9+
AAAAIQDTj7+GAKceovRR6/NV8TFi+Mc5cHl555sVVokgFkofYA==
10+
Private-MAC: 71bc2b8cbe9f209ff693afb9b217f060f5dc4d4ae73e136e28fa1034b0fdd982

test/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ public void ConstructorWithFileNameAndPassPhraseShouldBeAbleToReadFileThatIsShar
346346
[DataRow("Key.PuTTY2.RSA.Encrypted.12345.ppk", "12345", typeof(RsaKey))]
347347
[DataRow("Key.PuTTY2.RSA.ppk", null, typeof(RsaKey))]
348348
[DataRow("Key.PuTTY3.ECDSA.Encrypted.Argon2id.12345.ppk", "12345", typeof(EcdsaKey))]
349+
[DataRow("Key.PuTTY3.ECDSA.LeadingZero.ppk", null, typeof(EcdsaKey))]
349350
[DataRow("Key.PuTTY3.ECDSA.ppk", null, typeof(EcdsaKey))]
350351
[DataRow("Key.PuTTY3.Ed25519.Encrypted.Argon2i.12345.ppk", "12345", typeof(ED25519Key))]
351352
[DataRow("Key.PuTTY3.Ed25519.Encrypted.Argon2d.12345.ppk", "12345", typeof(ED25519Key))]

0 commit comments

Comments
 (0)