Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find ssh commands via locate #1983

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SparkleShare/Common/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
7 changes: 4 additions & 3 deletions Sparkles/Git/Git.Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sparkles/Git/Git.Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
2 changes: 1 addition & 1 deletion Sparkles/SSHAuthenticationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand Down
63 changes: 60 additions & 3 deletions Sparkles/SSHCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("\\", "/");
}
}

Expand All @@ -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";
}
}

}
}
5 changes: 1 addition & 4 deletions Sparkles/SSHFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ namespace Sparkles {

public abstract class SSHFetcher : BaseFetcher {

public static string SSHKeyScan = "ssh-keyscan";


protected SSHFetcher (SparkleFetcherInfo info) : base (info)
{
}
Expand Down Expand Up @@ -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);
Expand Down