[3/3] testbot/TestAgent: Automatically use the id_dsa and id_rsa keys for Net:SSH2.

Francois Gouget fgouget at codeweavers.com
Tue Dec 11 10:55:09 CST 2012

Newer Net:SSH2 versions will automatically detect and use the id_dsa keys but older ones don't autodetect anything.

This is somewhat redundant with patch 1/3:
* Without this patch one can still get things working by setting the
  publickey and privatekey fields in $TunnelDefaults in the 
  configuration file.
* But this patch simplifies the setup by automatically detecting the 
  id_dsa and id_rsa keys.
* The id_rsa keys seem to be considered slightly less secure than the 
  id_dsa ones and while recent Net::SSH2 versions automatically pick up 
  id_dsa keys they don't pick up the id_rsa ones. That could be a hint 
  that we should not either. But I'm really not convinced that much 
  thought was put in that part of Net::SSH2.
* One could also decide that patch 1/3 makes things too configurable and
  that really all one needs is for WineTestBot to pick the id_dsa/id_rsa 
  keys and that's it. Then one could skip patch 1 and only apply this 
  one (and end up fixing a bunch of conflicts though). I could resubmit 
  this one separately in any case.

 testbot/lib/WineTestBot/TestAgent.pm |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/testbot/lib/WineTestBot/TestAgent.pm b/testbot/lib/WineTestBot/TestAgent.pm
index e04827a..cb63cfd 100644
--- a/testbot/lib/WineTestBot/TestAgent.pm
+++ b/testbot/lib/WineTestBot/TestAgent.pm
@@ -802,6 +802,21 @@ sub _Connect($)
       $AuthOptions{$Key} = $Tunnel->{$Key} if (defined $Tunnel->{$Key});
+    # Old versions of Net::SSH2 won't automatically find DSA keys, and new ones
+    # still won't automatically find RSA ones.
+    if (defined $ENV{HOME} and !exists $AuthOptions{"privatekey"} and
+        !exists $AuthOptions{"publickey"})
+    {
+      foreach my $key ("dsa", "rsa")
+      {
+        if (-f "$ENV{HOME}/.ssh/$key" and -f "$ENV{HOME}/.ssh/$key.pub")
+        {
+          $AuthOptions{"privatekey"} = "$ENV{HOME}/.ssh/$key";
+          $AuthOptions{"publickey"} = "$ENV{HOME}/.ssh/$key.pub";
+          last;
+        }
+      }
+    }
     # Interactive authentication makes no sense with automatic reconnects
     $AuthOptions{interact} = 0;
     if (!$self->{ssh}->auth(%AuthOptions))

More information about the wine-patches mailing list