@@ -22,63 +22,46 @@ public void TearDown()
2222 {
2323 _remoteSshdConfig ? . Reset ( ) ;
2424 }
25-
25+
2626 [ TestMethod ]
2727 [ Ignore ] // No longer supported in recent versions of OpenSSH
28+ // TODO: We should be able to enable some legacy settings to make it work
29+ // https://www.openssh.com/legacy.html e.g. PubkeyAcceptedKeyTypes / HostbasedAcceptedKeyTypes ?
2830 public void SshDsa ( )
2931 {
30- _remoteSshdConfig . ClearHostKeyAlgorithms ( )
31- . AddHostKeyAlgorithm ( HostKeyAlgorithm . SshDsa )
32- . ClearHostKeyFiles ( )
33- . AddHostKeyFile ( HostKeyFile . Dsa . FilePath )
34- . Update ( )
35- . Restart ( ) ;
36-
37- HostKeyEventArgs hostKeyEventsArgs = null ;
38-
39- using ( var client = new SshClient ( _connectionInfoFactory . Create ( ) ) )
40- {
41- client . HostKeyReceived += ( sender , e ) => hostKeyEventsArgs = e ;
42- client . Connect ( ) ;
43- client . Disconnect ( ) ;
44- }
45-
46- Assert . IsNotNull ( hostKeyEventsArgs ) ;
47- Assert . AreEqual ( HostKeyFile . Dsa . KeyName , hostKeyEventsArgs . HostKeyName ) ;
48- Assert . AreEqual ( 1024 , hostKeyEventsArgs . KeyLength ) ;
49- Assert . IsTrue ( hostKeyEventsArgs . FingerPrint . SequenceEqual ( HostKeyFile . Dsa . FingerPrint ) ) ;
32+ DoTest ( HostKeyAlgorithm . SshDsa , HostKeyFile . Dsa , 1024 ) ;
5033 }
5134
5235 [ TestMethod ]
5336 public void SshRsa ( )
5437 {
55- _remoteSshdConfig . ClearHostKeyAlgorithms ( )
56- . AddHostKeyAlgorithm ( HostKeyAlgorithm . SshRsa )
57- . Update ( )
58- . Restart ( ) ;
59-
60- HostKeyEventArgs hostKeyEventsArgs = null ;
38+ DoTest ( HostKeyAlgorithm . SshRsa , HostKeyFile . Rsa , 3072 ) ;
39+ }
6140
62- using ( var client = new SshClient ( _connectionInfoFactory . Create ( ) ) )
63- {
64- client . HostKeyReceived += ( sender , e ) => hostKeyEventsArgs = e ;
65- client . Connect ( ) ;
66- client . Disconnect ( ) ;
67- }
41+ [ TestMethod ]
42+ public void SshRsaSha256 ( )
43+ {
44+ DoTest ( HostKeyAlgorithm . RsaSha2256 , HostKeyFile . Rsa , 3072 ) ;
45+ }
6846
69- Assert . IsNotNull ( hostKeyEventsArgs ) ;
70- Assert . AreEqual ( HostKeyFile . Rsa . KeyName , hostKeyEventsArgs . HostKeyName ) ;
71- Assert . AreEqual ( 3072 , hostKeyEventsArgs . KeyLength ) ;
72- Assert . IsTrue ( hostKeyEventsArgs . FingerPrint . SequenceEqual ( HostKeyFile . Rsa . FingerPrint ) ) ;
47+ [ TestMethod ]
48+ public void SshRsaSha512 ( )
49+ {
50+ DoTest ( HostKeyAlgorithm . RsaSha2512 , HostKeyFile . Rsa , 3072 ) ;
7351 }
7452
7553 [ TestMethod ]
7654 public void SshEd25519 ( )
55+ {
56+ DoTest ( HostKeyAlgorithm . SshEd25519 , HostKeyFile . Ed25519 , 256 ) ;
57+ }
58+
59+ private void DoTest ( HostKeyAlgorithm hostKeyAlgorithm , HostKeyFile hostKeyFile , int keyLength )
7760 {
7861 _remoteSshdConfig . ClearHostKeyAlgorithms ( )
79- . AddHostKeyAlgorithm ( HostKeyAlgorithm . SshEd25519 )
62+ . AddHostKeyAlgorithm ( hostKeyAlgorithm )
8063 . ClearHostKeyFiles ( )
81- . AddHostKeyFile ( HostKeyFile . Ed25519 . FilePath )
64+ . AddHostKeyFile ( hostKeyFile . FilePath )
8265 . Update ( )
8366 . Restart ( ) ;
8467
@@ -92,14 +75,9 @@ public void SshEd25519()
9275 }
9376
9477 Assert . IsNotNull ( hostKeyEventsArgs ) ;
95- Assert . AreEqual ( HostKeyFile . Ed25519 . KeyName , hostKeyEventsArgs . HostKeyName ) ;
96- Assert . AreEqual ( 256 , hostKeyEventsArgs . KeyLength ) ;
97- Assert . IsTrue ( hostKeyEventsArgs . FingerPrint . SequenceEqual ( HostKeyFile . Ed25519 . FingerPrint ) ) ;
98- }
99-
100- private void Client_HostKeyReceived ( object sender , HostKeyEventArgs e )
101- {
102- throw new NotImplementedException ( ) ;
78+ Assert . AreEqual ( hostKeyAlgorithm . Name , hostKeyEventsArgs . HostKeyName ) ;
79+ Assert . AreEqual ( keyLength , hostKeyEventsArgs . KeyLength ) ;
80+ CollectionAssert . AreEqual ( hostKeyFile . FingerPrint , hostKeyEventsArgs . FingerPrint ) ;
10381 }
10482 }
10583}
0 commit comments