diff --git a/SparkleShare/Common/BaseController.cs b/SparkleShare/Common/BaseController.cs index 138142231..6591461d9 100644 --- a/SparkleShare/Common/BaseController.cs +++ b/SparkleShare/Common/BaseController.cs @@ -224,6 +224,9 @@ public virtual void Initialize () Logger.LogInfo ("Environment", "SparkleShare " + version); Logger.LogInfo ("Environment", "Git LFS " + Sparkles.Git.GitCommand.GitLFSVersion); Logger.LogInfo ("Environment", "Git " + Sparkles.Git.GitCommand.GitVersion); + Logger.LogInfo ("Environment", "SSH " + Sparkles.SSHCommand.SSHVersion); + Logger.LogInfo ("Environment", "SSH-KeyGen " + Sparkles.SSHCommand.KeygenVersion); + Logger.LogInfo ("Environment", "SSH-KeyScan " + Sparkles.SSHCommand.KeyscanVersion); Logger.LogInfo ("Environment", InstallationInfo.OperatingSystem + " " + InstallationInfo.OperatingSystemVersion); UserAuthenticationInfo = new SSHAuthenticationInfo (); diff --git a/Sparkles/Git/Git.Command.cs b/Sparkles/Git/Git.Command.cs index ffec4f603..b98b7bc88 100644 --- a/Sparkles/Git/Git.Command.cs +++ b/Sparkles/Git/Git.Command.cs @@ -221,9 +221,10 @@ static ErrorStatus FindError (string line) public static string FormatGitSSHCommand (SSHAuthenticationInfo auth_info) { - return SSHCommandPath + " " + - "-i " + auth_info.PrivateKeyFilePath.Replace ("\\", "/").Replace (" ", "\\ ") + " " + - "-o UserKnownHostsFile=" + auth_info.KnownHostsFilePath.Replace ("\\", "/").Replace (" ", "\\ ") + " " + + return "\""+SSHCommandPath + "\" " + + "-i \"" + auth_info.PrivateKeyFilePath.Replace ("\\", "/").Replace (" ", "\\ ") + "\" " + + "-o UserKnownHostsFile=\"" + auth_info.KnownHostsFilePath.Replace ("\\", "/").Replace (" ", "\\ ") + "\" " + + "-o IdentitiesOnly=yes" + " " + // Don't fall back to other keys on the system "-o PasswordAuthentication=no" + " " + // Don't hang on possible password prompts "-F /dev/null"; // Ignore the system's SSH config file diff --git a/Sparkles/Git/Git.Repository.cs b/Sparkles/Git/Git.Repository.cs index ac19964cf..71ed16c10 100644 --- a/Sparkles/Git/Git.Repository.cs +++ b/Sparkles/Git/Git.Repository.cs @@ -79,7 +79,7 @@ public GitRepository (string path, Configuration config, SSHAuthenticationInfo a git_config = new GitCommand (LocalPath, "config remote.origin.url \"" + RemoteUrl + "\""); git_config.StartAndWaitForExit (); - git_config = new GitCommand (LocalPath, "config core.sshCommand " + GitCommand.FormatGitSSHCommand (auth_info)); + git_config = new GitCommand (LocalPath, "config core.sshCommand \"" + GitCommand.FormatGitSSHCommand (auth_info).Replace("\"", "\\\"") + "\""); git_config.StartAndWaitForExit(); PrepareGitLFS (); diff --git a/Sparkles/SSHAuthenticationInfo.cs b/Sparkles/SSHAuthenticationInfo.cs index 0724a241d..6c51e71cc 100644 --- a/Sparkles/SSHAuthenticationInfo.cs +++ b/Sparkles/SSHAuthenticationInfo.cs @@ -100,7 +100,7 @@ bool CreateKeyPair () "-C \"" + computer_name + " (SparkleShare)\" " + // Key comment "-f \"" + key_file_name + "\""; - var ssh_keygen = new SSHCommand ("ssh-keygen", arguments); + var ssh_keygen = new SSHCommand (SSHCommand.SSHKeyGenCommandPath, arguments); ssh_keygen.StartInfo.WorkingDirectory = Path; ssh_keygen.StartAndWaitForExit (); diff --git a/Sparkles/SSHCommand.cs b/Sparkles/SSHCommand.cs index 3dd2f24b4..8425c7764 100644 --- a/Sparkles/SSHCommand.cs +++ b/Sparkles/SSHCommand.cs @@ -21,11 +21,25 @@ namespace Sparkles { public class SSHCommand : Command { - public static string SSHPath = ""; + public static string SSHPath = Path.GetDirectoryName(LocateCommand("ssh")).Replace("\\", "/"); public static string SSHCommandPath { get { - return Path.Combine (SSHPath, "ssh").Replace ("\\", "/"); + return LocateCommand("ssh").Replace ("\\", "/"); + } + } + public static string SSHKeyScanCommandPath + { + get + { + return LocateCommand("ssh-keyscan").Replace("\\", "/"); + } + } + public static string SSHKeyGenCommandPath + { + get + { + return LocateCommand("ssh-keygen").Replace("\\", "/"); } } @@ -36,8 +50,51 @@ public SSHCommand (string command, string args) : this (command, args, null) public SSHCommand (string command, string args, SSHAuthenticationInfo auth_info) : - base (Path.Combine (SSHPath, command), args) + base (command, args) + { + } + public static string SSHVersion { + get + { + var ssh_version = new Command(SSHCommandPath, "-V", false); + string version = ssh_version.StartAndReadStandardError(); //the version is written to StandardError instead of StanderdOutput! + return version.Replace("SSH ", "").Split(',')[0]; + } + } + public static string KeyscanVersion + { + get + { + var ssh_version = new Command(SSHKeyScanCommandPath, "",false); + ssh_version.StartAndWaitForExit(); // call to check if exists + return "found"; + } } + public static string KeygenVersion + { + get + { + // since keygen has no version output try to create testkey, if keygen is not found Comand will exit + string arguments = + "-t rsa " + // Crypto type + "-b 4096 " + // Key size + "-P \"\" " + // No password + "-C \"test\" " + // Key comment + "-f \"" + System.IO.Path.Combine(Configuration.DefaultConfiguration.DirectoryPath, "tmp", "testkey") + "\""; + var ssh_version = new Command(SSHKeyGenCommandPath, arguments,false); + ssh_version.StartAndWaitForExit(); // call to check if exists + if (File.Exists(System.IO.Path.Combine(Configuration.DefaultConfiguration.DirectoryPath, "tmp", "testkey"))) + { + File.Delete(System.IO.Path.Combine(Configuration.DefaultConfiguration.DirectoryPath, "tmp", "testkey")); + } + if (File.Exists(System.IO.Path.Combine(Configuration.DefaultConfiguration.DirectoryPath, "tmp", "testkey.pub"))) + { + File.Delete(System.IO.Path.Combine(Configuration.DefaultConfiguration.DirectoryPath, "tmp", "testkey.pub")); + } + return "found"; + } + } + } } diff --git a/Sparkles/SSHFetcher.cs b/Sparkles/SSHFetcher.cs index d7950b357..f7a96f475 100644 --- a/Sparkles/SSHFetcher.cs +++ b/Sparkles/SSHFetcher.cs @@ -23,9 +23,6 @@ namespace Sparkles { public abstract class SSHFetcher : BaseFetcher { - public static string SSHKeyScan = "ssh-keyscan"; - - protected SSHFetcher (SparkleFetcherInfo info) : base (info) { } @@ -68,7 +65,7 @@ public override bool Fetch () string FetchHostKey () { Logger.LogInfo ("Auth", string.Format ("Fetching host key for {0}", RemoteUrl.Host)); - var ssh_keyscan = new Command (SSHKeyScan, string.Format ("-t rsa -p 22 {0}", RemoteUrl.Host)); + var ssh_keyscan = new SSHCommand (SSHCommand.SSHKeyScanCommandPath, string.Format ("-t rsa -p 22 {0}", RemoteUrl.Host)); if (RemoteUrl.Port > 0) ssh_keyscan.StartInfo.Arguments = string.Format ("-t rsa -p {0} {1}", RemoteUrl.Port, RemoteUrl.Host);