Skip to content

Commit

Permalink
OPENSSH KeyReader for more keys
Browse files Browse the repository at this point in the history
Add support to parse OpenSSH Keys with ECDSA 256/384/521 and RSA.

Change-Id: Iaa9cce0f2522e5fee377a82cb252f81f0b7cc563
  • Loading branch information
darinkes committed Jan 2, 2021
1 parent d62594c commit 4b11594
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 46 deletions.
98 changes: 90 additions & 8 deletions src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,34 +545,116 @@ public void ConstructorWithFileNameAndPassPhraseShouldBeAbleToReadFileThatIsShar
}
}

/// <summary>
/// A test for opening an openssh v1 keyfile where there is no passphrase.
///</summary>
[TestMethod()]
[Owner("bhalbright")]
[TestCategory("PrivateKey")]
public void TestOpenSshV1KeyFileNoPassphrase()
public void Test_PrivateKey_OPENSSH_ED25519()
{
using (var stream = GetData("Key.OPENSSH.ED25519.txt"))
{
new PrivateKeyFile(stream);
}
}

/// <summary>
/// A test for opening an openssh v1 keyfile where there is a passphrase.
///</summary>
[TestMethod()]
[Owner("bhalbright")]
[TestCategory("PrivateKey")]
public void TestOpenSshV1KeyFileWithPassphrase()
public void Test_PrivateKey_OPENSSH_ED25519_ENCRYPTED()
{
using (var stream = GetData("Key.OPENSSH.ED25519.Encrypted.txt"))
{
new PrivateKeyFile(stream, "password");
}
}

[TestMethod()]
[Owner("darinkes")]
[TestCategory("PrivateKey")]
public void Test_PrivateKey_OPENSSH_RSA()
{
using (var stream = GetData("Key.OPENSSH.RSA.txt"))
{
new PrivateKeyFile(stream);
}
}

[TestMethod()]
[Owner("darinkes")]
[TestCategory("PrivateKey")]
public void Test_PrivateKey_OPENSSH_RSA_ENCRYPTED()
{
using (var stream = GetData("Key.OPENSSH.RSA.Encrypted.txt"))
{
new PrivateKeyFile(stream, "12345");
}
}

[TestMethod()]
[Owner("darinkes")]
[TestCategory("PrivateKey")]
public void Test_PrivateKey_OPENSSH_ECDSA()
{
using (var stream = GetData("Key.OPENSSH.ECDSA.txt"))
{
new PrivateKeyFile(stream);
}
}

[TestMethod()]
[Owner("darinkes")]
[TestCategory("PrivateKey")]
public void Test_PrivateKey_OPENSSH_ECDSA_ENCRYPTED()
{
using (var stream = GetData("Key.OPENSSH.ECDSA.Encrypted.txt"))
{
new PrivateKeyFile(stream, "12345");
}
}

[TestMethod()]
[Owner("darinkes")]
[TestCategory("PrivateKey")]
public void Test_PrivateKey_OPENSSH_ECDSA384()
{
using (var stream = GetData("Key.OPENSSH.ECDSA384.txt"))
{
new PrivateKeyFile(stream);
}
}

[TestMethod()]
[Owner("darinkes")]
[TestCategory("PrivateKey")]
public void Test_PrivateKey_OPENSSH_ECDSA384_ENCRYPTED()
{
using (var stream = GetData("Key.OPENSSH.ECDSA384.Encrypted.txt"))
{
new PrivateKeyFile(stream, "12345");
}
}

[TestMethod()]
[Owner("darinkes")]
[TestCategory("PrivateKey")]
public void Test_PrivateKey_OPENSSH_ECDSA521()
{
using (var stream = GetData("Key.OPENSSH.ECDSA521.txt"))
{
new PrivateKeyFile(stream);
}
}

[TestMethod()]
[Owner("darinkes")]
[TestCategory("PrivateKey")]
public void Test_PrivateKey_OPENSSH_ECDSA521_ENCRYPTED()
{
using (var stream = GetData("Key.OPENSSH.ECDSA521.Encrypted.txt"))
{
new PrivateKeyFile(stream, "12345");
}
}

private void SaveStreamToFile(Stream stream, string fileName)
{
var buffer = new byte[4000];
Expand Down
9 changes: 9 additions & 0 deletions src/Renci.SshNet.Tests/Data/Key.OPENSSH.ECDSA.Encrypted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABCPSPglZ3
w/7DmCJxYohONLAAAAEAAAAAEAAABoAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlz
dHAyNTYAAABBBK6YY2NwwLDSMnJTD+a4OfitCDuG/MnY/AstPgh54xMrZF6Qr0U1H6kRMK
Y6JJsj31CI97qDYrnTA00Sx5Jy6ywAAACwq4qisorVCP6yvrmf/fcPacX4+FVEmrHNn3fW
TiYsat7oKoItqTiDaHkIloSX93ue3fzcKXpGPR/qnpu4SezkhL9Uk6ntiwO4coB/kbEnjk
IFY6ZK0HENRXkdIuDG9qmoB0wjVPJ6L9e5RWZwiCPvNI2O60bpKOUs+tUSah1W7eTWy5Ss
ttdTgmwqS84c5+uitK1DJh2jsDqfdGm7h1XpDJsRmIEXxTVu/EdtD0hZ/x4=
-----END OPENSSH PRIVATE KEY-----
9 changes: 9 additions & 0 deletions src/Renci.SshNet.Tests/Data/Key.OPENSSH.ECDSA.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS
1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQSP3ZTb37LFvSmKweu03A5s/cwcw3+3
jL1LqQK6D929xY1J2J6S91LXOBpBfz4l+8Ng7sWhu9P/hF/wmB2QRygrAAAAqMq583bKuf
N2AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI/dlNvfssW9KYrB
67TcDmz9zBzDf7eMvUupAroP3b3FjUnYnpL3Utc4GkF/PiX7w2DuxaG70/+EX/CYHZBHKC
sAAAAhALVqID3K/N7IazKNbhrg09r7rLLtjy81RLV+VDxloQnxAAAAC3NyaW5rZXNATkVP
AQIDBA==
-----END OPENSSH PRIVATE KEY-----
11 changes: 11 additions & 0 deletions src/Renci.SshNet.Tests/Data/Key.OPENSSH.ECDSA384.Encrypted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAMZphcrt
UKJMlSabtzt2GdAAAAEAAAAAEAAACIAAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlz
dHAzODQAAABhBFL5NEL9uRhgkF2q+8m58EvtZq4mDGgcVEzafPRuNIn1018m9KuqNpOQ6d
+435n+MRYThe4MUdijSIDuopX2i14Z35oKZ9x2LsV+RxQczjmbnoWZdvgcvdOo6jiJdY7X
JwAAAOBvXOaTq8vPRy7y5BBzr26QAYouJfGprYOqpywiIAZaICu0FJ8EXmmen6310CTG6Z
CZ4VhC5MWCWRYTaOnPNn8FvGqo2bxEqWZmyZfVvv1Z35MtSAZEfwgfXaOZKJ/lPKsRndg5
okpqNU1aG2u+4J7eZ7QyCD/1RCCEL5wwVcrDeuMkTDPpnJc1NEGz8HbfcZ5xZavrz6Wa9t
tX7pFICqK9IIeOGMJ2WRXR6sQGyag+jNn9KmsIya7hkNJVeZeY2GKAk2s/0vxfYx9RFD55
ewB34oHyTdxAQT3L+FZT6XfRHw==
-----END OPENSSH PRIVATE KEY-----
10 changes: 10 additions & 0 deletions src/Renci.SshNet.Tests/Data/Key.OPENSSH.ECDSA384.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAiAAAABNlY2RzYS
1zaGEyLW5pc3RwMzg0AAAACG5pc3RwMzg0AAAAYQRTP1DMXoHgW+RX+S/NxUEElou1cmLD
6CEiR+zpzaGG6mzl6LhUY+Z3f2M3u4u7tcM8TgB/jiHbnI9TaeN5QK4HX1D9DXkH5RhfnL
frm3kCTNoCFKd0Wa/QAvKrlNKiRi8AAADYlABjHJQAYxwAAAATZWNkc2Etc2hhMi1uaXN0
cDM4NAAAAAhuaXN0cDM4NAAAAGEEUz9QzF6B4FvkV/kvzcVBBJaLtXJiw+ghIkfs6c2hhu
ps5ei4VGPmd39jN7uLu7XDPE4Af44h25yPU2njeUCuB19Q/Q15B+UYX5y365t5AkzaAhSn
dFmv0ALyq5TSokYvAAAAMAXLUgK32yWzUrpeLzpdFB2/eiNnkxQlu5OneTPukKcZYclfgo
jv0YHK5LCvAtF8lwAAAAtzcmlua2VzQE5FTwECAwQF
-----END OPENSSH PRIVATE KEY-----
12 changes: 12 additions & 0 deletions src/Renci.SshNet.Tests/Data/Key.OPENSSH.ECDSA521.Encrypted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABBWjIyzbM
MQ3UPE8BiQ0n4LAAAAEAAAAAEAAACsAAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlz
dHA1MjEAAACFBAH9BVM6bRhbELtgdMGsin5lM42R2EWoT+6Akakl5rQy2tHHLIYGLEfaqI
+0iUo2V6MxEf9w0hVz6SEsF+yDgyrYPQCIieaB1oBvIl+PZmL1XsuAXs2uMRsNJb4myGU/
DiekxqzIPa0LMrBZ4xmErcn5Gazkw1EA0B3HoaW5wj+geI/efQAAARDi+GGTYH1T+5Dd8N
EVCiL+J7fm8uP8yAcvQNh3JBYIf1g/GZ0hJDuA47fcTzXEfTGZLGWdgaE8cxIUICpjBoak
EpNS1HyhqYZAt2J8o/14t2GbXczJfoQLOIQl2S1zXQ9shof12odu9DGcBhSAz9hswlndBE
d99uCz/ymzwQ0i2Pp+urUXo7+YXB6HMh9YTMeGQAiDJFO3NPDqDczfUECtTUkQMhy8r06m
hAp/oZ6K1KBbZzdc0xyqDePKAqqyHnN4FD7Wfv11SWoOhlUcEVg2ZvNj/O+CsoWzMpN+dt
DPKZHmH/kegWKBsdtAC9f5Hg3b2oQAK0pKghms1+/J9iilnIMwv80CPzGdv0YAG9Vx5w==
-----END OPENSSH PRIVATE KEY-----
12 changes: 12 additions & 0 deletions src/Renci.SshNet.Tests/Data/Key.OPENSSH.ECDSA521.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAArAAAABNlY2RzYS
1zaGEyLW5pc3RwNTIxAAAACG5pc3RwNTIxAAAAhQQAa7p4WVga+08qu160BrdzKyRNJMQC
eGhFluNdq73/uaW3qlqoEiaNtc5uB7HHyjCWQTmfzrSRLRZ7YBwUancwyh4Aq6gBgGsXVz
wNvY3kxRDlGrSfMmsHlXz41dgw9wm1fBcf97niexRQ/xGlhkyf7IYlQ/s5BpXF2lS9l0H5
hBippRgAAAEI/9prf//aa38AAAATZWNkc2Etc2hhMi1uaXN0cDUyMQAAAAhuaXN0cDUyMQ
AAAIUEAGu6eFlYGvtPKrtetAa3cyskTSTEAnhoRZbjXau9/7mlt6paqBImjbXObgexx8ow
lkE5n860kS0We2AcFGp3MMoeAKuoAYBrF1c8Db2N5MUQ5Rq0nzJrB5V8+NXYMPcJtXwXH/
e54nsUUP8RpYZMn+yGJUP7OQaVxdpUvZdB+YQYqaUYAAAAQXwQnI20tNxwLKHPMDmumblD
b0sBqW5Y9248L//x4sWFrkjk6k1LcZno9KLqz8+tIFMJ5sji+axRoUZCXb3cIPzPAAAAC3
NyaW5rZXNATkVP
-----END OPENSSH PRIVATE KEY-----
28 changes: 28 additions & 0 deletions src/Renci.SshNet.Tests/Data/Key.OPENSSH.RSA.Encrypted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABCoWhCSaG
psKT80oPIOAlqJAAAAEAAAAAEAAAEXAAAAB3NzaC1yc2EAAAADAQABAAABAQCxOfnmxC1g
mmX18LCBG/X73BoCXQEBEAJz3V9w0FMTgUBebK3fkfOMLNzWn5aMR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PbFxT3
W8zwRd90Msr3LXgPaN0V4RJeBX38e0EvVbArL2MgSs/BC5aID0N0Sqiu+13AqqNYxj6RH2
FA7FN+BBa16fvdi5h5kNnZUrQUKOAImjEE494O8uGKQImviGqB5PY6DJqHPTtn7RSwFx9E
rR7nbAZPTucIN/OIfURxTedhROk0PXjWnwpjuz+UpaMRWqgWTv3bLOuqorqMLibAFLRQEQ
6pR0wbmTpTfEW1jNmAohxB4N14YdSfhThzkCAgpQW6UCLc83y3EDzQFi5862a+2ixULKhK
220tZRk2GU7OFAPRpgQ/sxptGqZbNdOV80wk1MgykoFkoptRkm7bfJcdLHZnP7E6yU0ssP
rCbQlfD0/dD2QE/7HqxHsipNNuEagULjK6WUYXkpx1Siq2vecjZw8dNp7EBh+KlujEm+Dr
R7KFdFCw8DUwrzXwfMIogeRVbW8H0/fQEqsX5oPLTEOnNBjzf8pHush7CCrprbo0ZK3xFp
Vr3LUCoA==
-----END OPENSSH PRIVATE KEY-----
27 changes: 27 additions & 0 deletions src/Renci.SshNet.Tests/Data/Key.OPENSSH.RSA.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEA7W7Oigi7Hj1msa2l8HimLPzagVmE/CseMKCRxPMTtWTvoZdMt7hf
kthWA7h20a7oSSeH2t7FqeOpVNGFYvRV3BVWsKZJMRcdJiTCZAjH38rYk90XvZ3mKrKN/3
fcQsh4OiPnWqT6HSqg14oiV8UPtUwnE65skWSxvxt+ELlVpCqG5vE2O/GNDKQE7FzYt6vQ
ihMFSABBqjvau0mjX002KYiCMr6vgl8XYkDA4n5+JyQSQxznnfrL93ZoaqujRP2bT5UhXg
bzr8HFwuqQGvURECZTTI8Biv/6tOIn9x2hEaN6vxDLtXc99E2d6NW6cdriwaGFJ4jgVWDE
5mU006XdPQ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r35mGfdbyJIFAwFZF4Xs8WnQF+vHEadrAAAAgQDu329eCwVFf9g0
zNHfZu31p0WtErcsRv57fq+UoPtov8nxUF71oOWe5KSGnGtMICI31kBtPhUbvfOmuqNrgJ
BjgjbPQmi0xSAE5L3QuEKRNjlaE3/WadKBwzhJDtauuYk1ifkrdAVp67XyQ5puyuGgVaQB
NPbrxA9g1IbyeL4/9wAAAAtzcmlua2VzQE5FTwECAwQFBg==
-----END OPENSSH PRIVATE KEY-----
8 changes: 8 additions & 0 deletions src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
<EmbeddedResource Include="Data\Key.ECDSA521.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.ED25519.Encrypted.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.ED25519.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.RSA.Encrypted.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.RSA.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.ECDSA.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.ECDSA.Encrypted.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.ECDSA384.Encrypted.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.ECDSA521.Encrypted.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.ECDSA384.txt" />
<EmbeddedResource Include="Data\Key.OPENSSH.ECDSA521.txt" />
<EmbeddedResource Include="Data\Key.RSA.Encrypted.Aes.128.CBC.12345.txt" />
<EmbeddedResource Include="Data\Key.RSA.Encrypted.Aes.192.CBC.12345.txt" />
<EmbeddedResource Include="Data\Key.RSA.Encrypted.Aes.256.CBC.12345.txt" />
Expand Down
Loading

0 comments on commit 4b11594

Please sign in to comment.