diff --git a/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs b/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs index 9c1fcc1b5..4d78fa26f 100644 --- a/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs +++ b/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs @@ -175,7 +175,7 @@ public Key Parse() var curve = publicKeyReader.ReadString(Encoding.ASCII); var pub = publicKeyReader.ReadBinary(); var prv = privateKeyReader.ReadBinary(); - parsedKey = new EcdsaKey(curve, pub, prv); + parsedKey = new EcdsaKey(curve, pub, prv.TrimLeadingZeros()); break; case "ssh-rsa": var exponent = publicKeyReader.ReadBigInt(); diff --git a/test/Data/Key.PuTTY3.ECDSA.LeadingZero.ppk b/test/Data/Key.PuTTY3.ECDSA.LeadingZero.ppk new file mode 100644 index 000000000..921e89934 --- /dev/null +++ b/test/Data/Key.PuTTY3.ECDSA.LeadingZero.ppk @@ -0,0 +1,10 @@ +PuTTY-User-Key-File-3: ecdsa-sha2-nistp256 +Encryption: none +Comment: imported-openssh-key +Public-Lines: 3 +AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNhE4rS0CTev +/VEC6BJ/142eE3dU88t1rpzrSJ3iEcyp+3itM0+182eXSswmunZo/TNyvFE1sXKK +1x0COQJl6hU= +Private-Lines: 1 +AAAAIQDTj7+GAKceovRR6/NV8TFi+Mc5cHl555sVVokgFkofYA== +Private-MAC: 71bc2b8cbe9f209ff693afb9b217f060f5dc4d4ae73e136e28fa1034b0fdd982 diff --git a/test/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs b/test/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs index f18cef76e..8ac1e2056 100644 --- a/test/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs +++ b/test/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs @@ -346,6 +346,7 @@ public void ConstructorWithFileNameAndPassPhraseShouldBeAbleToReadFileThatIsShar [DataRow("Key.PuTTY2.RSA.Encrypted.12345.ppk", "12345", typeof(RsaKey))] [DataRow("Key.PuTTY2.RSA.ppk", null, typeof(RsaKey))] [DataRow("Key.PuTTY3.ECDSA.Encrypted.Argon2id.12345.ppk", "12345", typeof(EcdsaKey))] + [DataRow("Key.PuTTY3.ECDSA.LeadingZero.ppk", null, typeof(EcdsaKey))] [DataRow("Key.PuTTY3.ECDSA.ppk", null, typeof(EcdsaKey))] [DataRow("Key.PuTTY3.Ed25519.Encrypted.Argon2i.12345.ppk", "12345", typeof(ED25519Key))] [DataRow("Key.PuTTY3.Ed25519.Encrypted.Argon2d.12345.ppk", "12345", typeof(ED25519Key))]