ssh: Fix whitespace

This commit is contained in:
Hylke Bons 2018-03-10 12:26:24 +00:00
parent dd0e3d36f7
commit 45f91bbacd
2 changed files with 18 additions and 16 deletions

View file

@ -25,17 +25,17 @@ namespace Sparkles {
public static string SSHCommandPath { public static string SSHCommandPath {
get { get {
return Path.Combine(SSHPath, "ssh").Replace("\\", "/"); return Path.Combine (SSHPath, "ssh").Replace ("\\", "/");
} }
} }
public SSHCommand(string command, string args) : this (command, args, null) public SSHCommand (string command, string args) : this (command, args, null)
{ {
} }
public SSHCommand(string command, string args, SSHAuthenticationInfo auth_info) : public SSHCommand (string command, string args, SSHAuthenticationInfo auth_info) :
base (Path.Combine (SSHPath, command), args) base (Path.Combine (SSHPath, command), args)
{ {
} }

View file

@ -25,6 +25,7 @@ namespace Sparkles {
public static string SSHKeyScan = "ssh-keyscan"; public static string SSHKeyScan = "ssh-keyscan";
protected SSHFetcher (SparkleFetcherInfo info) : base (info) protected SSHFetcher (SparkleFetcherInfo info) : base (info)
{ {
} }
@ -105,7 +106,7 @@ namespace Sparkles {
return null; return null;
} }
string DeriveFingerprint (string public_key) string DeriveFingerprint (string public_key)
{ {
try { try {
@ -116,44 +117,45 @@ namespace Sparkles {
byte [] sha256_bytes = sha256.ComputeHash (base64_bytes); byte [] sha256_bytes = sha256.ComputeHash (base64_bytes);
string fingerprint = BitConverter.ToString (sha256_bytes); string fingerprint = BitConverter.ToString (sha256_bytes);
Console.WriteLine( fingerprint.ToLower ().Replace ("-", ":")); fingerprint = fingerprint.ToLower ().Replace ("-", ":");
return fingerprint.ToLower ().Replace ("-", ":");
return fingerprint;
} catch (Exception e) { } catch (Exception e) {
Logger.LogInfo ("Fetcher", "Failed to create fingerprint: " + e.Message + " " + e.StackTrace); Logger.LogInfo ("Fetcher", "Failed to create fingerprint: ", e);
return null; return null;
} }
} }
void AcceptHostKey (string host_key, bool warn) void AcceptHostKey (string host_key, bool warn)
{ {
string ssh_config_path = Path.Combine (Configuration.DefaultConfiguration.DirectoryPath, "ssh"); string ssh_config_path = Path.Combine (Configuration.DefaultConfiguration.DirectoryPath, "ssh");
string known_hosts_file_path = Path.Combine (ssh_config_path, "known_hosts"); string known_hosts_file_path = Path.Combine (ssh_config_path, "known_hosts");
if (!File.Exists (known_hosts_file_path)) { if (!File.Exists (known_hosts_file_path)) {
if (!Directory.Exists (ssh_config_path)) if (!Directory.Exists (ssh_config_path))
Directory.CreateDirectory (ssh_config_path); Directory.CreateDirectory (ssh_config_path);
File.Create (known_hosts_file_path).Close (); File.Create (known_hosts_file_path).Close ();
} }
string host = RemoteUrl.Host; string host = RemoteUrl.Host;
string known_hosts = File.ReadAllText (known_hosts_file_path); string known_hosts = File.ReadAllText (known_hosts_file_path);
string [] known_hosts_lines = File.ReadAllLines (known_hosts_file_path); string [] known_hosts_lines = File.ReadAllLines (known_hosts_file_path);
foreach (string line in known_hosts_lines) { foreach (string line in known_hosts_lines) {
if (line.StartsWith (host + " ", StringComparison.InvariantCulture)) if (line.StartsWith (host + " ", StringComparison.InvariantCulture))
return; return;
} }
if (known_hosts.EndsWith ("\n", StringComparison.InvariantCulture)) if (known_hosts.EndsWith ("\n", StringComparison.InvariantCulture))
File.AppendAllText (known_hosts_file_path, host_key + "\n"); File.AppendAllText (known_hosts_file_path, host_key + "\n");
else else
File.AppendAllText (known_hosts_file_path, "\n" + host_key + "\n"); File.AppendAllText (known_hosts_file_path, "\n" + host_key + "\n");
Logger.LogInfo ("Auth", "Accepted host key for " + host); Logger.LogInfo ("Auth", "Accepted host key for " + host);
if (warn) if (warn)
warnings.Add ("The following host key has been accepted:\n" + DeriveFingerprint (host_key)); warnings.Add ("The following host key has been accepted:\n" + DeriveFingerprint (host_key));
} }