From b9cf5bb41dbf40e1b9484da13bd78a438ef01aef Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 9 Feb 2011 20:02:13 +0000 Subject: [PATCH] [controller] Ignore host key checking --- SparkleShare/SparkleController.cs | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index d73bbb98..ee2e0364 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -905,11 +905,78 @@ namespace SparkleShare { } + private void DisableHostKeyCheckingForHost (string host) + { + + string ssh_config_file_path = Path.Combine (SparklePaths.HomePath, ".ssh", "config"); + string ssh_config = "Host " + host + "\n\tStrictHostKeyChecking no"; + + if (File.Exists (ssh_config_file_path)) { + + TextWriter writer = File.AppendText (ssh_config_file_path); + writer.WriteLine ("\n" + ssh_config); + writer.Close (); + + } else { + + TextWriter writer = new StreamWriter (ssh_config_file_path); + writer.WriteLine (ssh_config); + writer.Close (); + + } + + } + + + private void EnableHostKeyCheckingForHost (string host) + { + + string ssh_config_file_path = Path.Combine (SparklePaths.HomePath, ".ssh", "config"); + string ssh_config = "Host " + host + "\n\tStrictHostKeyChecking no"; + + if (File.Exists (ssh_config_file_path)) { + + StreamReader reader = new StreamReader (ssh_config_file_path); + string current_ssh_config = reader.ReadToEnd (); + reader.Close (); + + if (current_ssh_config.Equals (ssh_config)) { + + File.Delete (ssh_config_file_path); + + } else { + + current_ssh_config = current_ssh_config.Remove (current_ssh_config.IndexOf (ssh_config), + ssh_config.Length); + + TextWriter writer = new StreamWriter (ssh_config_file_path); + writer.WriteLine (current_ssh_config); + writer.Close (); + + } + + } + + } + + public void FetchFolder (string url, string name) { SparkleHelpers.DebugInfo ("Controller", "Formed URL: " + url); + + string host = url.Substring (url.IndexOf ("@") + 1); + + if (host.Contains (":")) + host = host.Substring (0, host.IndexOf (":")); + else + host = host.Substring (0, host.IndexOf ("/")); + + + DisableHostKeyCheckingForHost (host); + + // Strip the '.git' from the name string canonical_name = System.IO.Path.GetFileNameWithoutExtension (name); string tmp_folder = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, canonical_name); @@ -939,6 +1006,8 @@ namespace SparkleShare { fetcher.CloningFinished += delegate { + EnableHostKeyCheckingForHost (host); + SparkleHelpers.ClearAttributes (tmp_folder); try { @@ -966,6 +1035,8 @@ namespace SparkleShare { fetcher.CloningFailed += delegate { + EnableHostKeyCheckingForHost (host); + if (Directory.Exists (tmp_folder)) { SparkleHelpers.ClearAttributes (tmp_folder); @@ -980,6 +1051,7 @@ namespace SparkleShare { FolderFetchError (); }; + fetcher.Start ();