keys: Start ssh-agent when there isn't one running
This commit is contained in:
parent
66485af890
commit
013a9b45fd
|
@ -46,41 +46,32 @@ namespace SparkleShare {
|
||||||
"-C \"" + computer_name + " (SparkleShare)\" " + // key comment
|
"-C \"" + computer_name + " (SparkleShare)\" " + // key comment
|
||||||
"-f \"" + key_name + "\""; // file name
|
"-f \"" + key_name + "\""; // file name
|
||||||
|
|
||||||
SparkleKeyProcess process = new SparkleKeyProcess ("ssh-keygen", arguments);
|
SparkleProcess process = new SparkleProcess ("ssh-keygen", arguments);
|
||||||
process.StartInfo.WorkingDirectory = output_path;
|
process.StartInfo.WorkingDirectory = output_path;
|
||||||
process.Start ();
|
process.Start ();
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
|
|
||||||
if (process.ExitCode == 0)
|
|
||||||
SparkleLogger.LogInfo ("Auth", "Created keypair '" + key_file_path + "'");
|
|
||||||
else
|
|
||||||
SparkleLogger.LogInfo ("Auth", "Could not create key pair '" + key_file_path + "'");
|
|
||||||
|
|
||||||
return new string [] { key_file_path, key_file_path + ".pub" };
|
return new string [] { key_file_path, key_file_path + ".pub" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void ImportPrivateKey (string key_file_path)
|
public static void ImportPrivateKey (string key_file_path)
|
||||||
{
|
{
|
||||||
|
StartKeyAgent ();
|
||||||
|
|
||||||
// Use forward slashes when dealing with Windows domain accounts
|
// Use forward slashes when dealing with Windows domain accounts
|
||||||
if (key_file_path.StartsWith ("\\\\"))
|
if (key_file_path.StartsWith ("\\\\"))
|
||||||
key_file_path = key_file_path.Replace ("\\", "/");
|
key_file_path = key_file_path.Replace ("\\", "/");
|
||||||
|
|
||||||
SparkleKeyProcess process = new SparkleKeyProcess ("ssh-add", "\"" + key_file_path + "\"");
|
SparkleProcess process = new SparkleProcess ("ssh-add", "\"" + key_file_path + "\"");
|
||||||
process.Start ();
|
process.Start ();
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
|
|
||||||
if (process.ExitCode == 0)
|
|
||||||
SparkleLogger.LogInfo ("Auth", "Imported key '" + key_file_path + "'");
|
|
||||||
else
|
|
||||||
SparkleLogger.LogInfo ("Auth", "Could not import key '" + key_file_path + "', " +
|
|
||||||
process.StandardError.ReadToEnd ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void ListPrivateKeys ()
|
public static void ListPrivateKeys ()
|
||||||
{
|
{
|
||||||
SparkleKeyProcess process = new SparkleKeyProcess ("ssh-add", "-l");
|
SparkleProcess process = new SparkleProcess ("ssh-add", "-l");
|
||||||
process.Start ();
|
process.Start ();
|
||||||
string keys_in_use = process.StandardOutput.ReadToEnd ();
|
string keys_in_use = process.StandardOutput.ReadToEnd ();
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
|
@ -89,16 +80,16 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class SparkleKeyProcess : Process {
|
private static void StartKeyAgent ()
|
||||||
|
|
||||||
public SparkleKeyProcess (string command, string arguments) : base ()
|
|
||||||
{
|
{
|
||||||
StartInfo.FileName = command;
|
Process [] processes = Process.GetProcessesByName ("ssh-agent");
|
||||||
StartInfo.Arguments = arguments;
|
|
||||||
StartInfo.UseShellExecute = false;
|
if (processes.Length == 0) {
|
||||||
StartInfo.RedirectStandardOutput = true;
|
SparkleLogger.LogInfo ("Auth", "No key agent running, starting one...");
|
||||||
StartInfo.RedirectStandardError = true;
|
|
||||||
StartInfo.CreateNoWindow = true;
|
SparkleProcess process = new SparkleProcess ("ssh-agent", "");
|
||||||
|
process.Start ();
|
||||||
|
process.WaitForExit ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue