-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Murashkevich
committed
Oct 1, 2023
1 parent
7a7299e
commit aec3fdc
Showing
8 changed files
with
401 additions
and
133 deletions.
There are no files selected for viewing
217 changes: 166 additions & 51 deletions
217
SSH.CommandSender/Dialogs/HostEditorDialog.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace SSH.CommandSender.Domain | ||
{ | ||
public class AuthJsonConverter : JsonConverter<SshHostDetails.Auth> | ||
{ | ||
public override void WriteJson(JsonWriter writer, SshHostDetails.Auth value, JsonSerializer serializer) | ||
{ | ||
serializer.Serialize(writer, value); | ||
} | ||
|
||
public override SshHostDetails.Auth ReadJson(JsonReader reader, Type objectType, SshHostDetails.Auth existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
var jObject = JObject.Load(reader); | ||
if (jObject["PathToKeyFile"] == null) | ||
{ | ||
return new SshHostDetails.PasswordAuth(jObject["Username"].Value<string>(), | ||
jObject["Password"].Value<string>()); | ||
} | ||
else | ||
{ | ||
return new SshHostDetails.PrivateKeyFileAuth(jObject["Username"].Value<string>(), | ||
jObject["PathToKeyFile"].Value<string>(), jObject["PassPhrase"].Value<string>()); | ||
|
||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,100 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Renci.SshNet; | ||
|
||
namespace SSH.CommandSender.Domain | ||
{ | ||
public class SshHostDetails : ICloneable | ||
{ | ||
public abstract class Auth | ||
{ | ||
public string Username { get; set; } | ||
|
||
public Auth(string username) | ||
{ | ||
Username = username; | ||
} | ||
|
||
public abstract SshClient CreateSshClient(string host, ushort port); | ||
|
||
public abstract bool Validate(); | ||
} | ||
|
||
public class PrivateKeyFileAuth : Auth | ||
{ | ||
public string PathToKeyFile { get; set; } | ||
public string PassPhrase { get; set; } | ||
|
||
public PrivateKeyFileAuth(string username, string pathToKeyFile, string passPhrase) : base(username) | ||
{ | ||
PathToKeyFile = pathToKeyFile; | ||
PassPhrase = passPhrase; | ||
} | ||
|
||
public override SshClient CreateSshClient(string host, ushort port) | ||
{ | ||
return new SshClient(host, port, Username, new PrivateKeyFile(this.PathToKeyFile, this.PassPhrase)); | ||
|
||
} | ||
|
||
public override bool Validate() | ||
{ | ||
return string.IsNullOrWhiteSpace(this.Username) == false && | ||
string.IsNullOrWhiteSpace(this.PathToKeyFile) == false; | ||
} | ||
} | ||
|
||
public class PasswordAuth : Auth | ||
{ | ||
public string Password { get; set; } | ||
|
||
public PasswordAuth(string username, string password) : base(username) | ||
{ | ||
Password = password; | ||
} | ||
|
||
public override SshClient CreateSshClient(string host, ushort port) | ||
{ | ||
return new SshClient(host, port, Username, Password); | ||
} | ||
|
||
public override bool Validate() | ||
{ | ||
return string.IsNullOrWhiteSpace(this.Username) == false; | ||
} | ||
} | ||
public string Name { get; set; } | ||
public string Host { get; set; } | ||
public ushort Port { get; } | ||
public string Username { get; set; } | ||
public string Password { get; set; } | ||
public ushort Port { get; set; } | ||
|
||
public SshHostDetails(string name = "", string host = "",string username = "", string password = "", ushort port = 22) | ||
[JsonConverter(typeof(AuthJsonConverter))] | ||
public Auth AuthenticationDetails { get; set; } | ||
|
||
public SshHostDetails(string name = "", string host = "", ushort port = 22, Auth authenticationDetails = null) | ||
{ | ||
Name = name; | ||
Host = host; | ||
Port = port; | ||
Username = username; | ||
Password = password; | ||
|
||
if (authenticationDetails == null) | ||
{ | ||
AuthenticationDetails = new PasswordAuth(string.Empty, string.Empty); | ||
} | ||
else | ||
{ | ||
AuthenticationDetails = authenticationDetails; | ||
} | ||
} | ||
|
||
public SshClient CreateSshClient() | ||
{ | ||
return AuthenticationDetails.CreateSshClient(Host,Port); | ||
|
||
} | ||
|
||
public object Clone() | ||
{ | ||
return new SshHostDetails(this.Name, this.Host, this.Username, this.Password, this.Port); | ||
return new SshHostDetails(this.Name, this.Host, this.Port, AuthenticationDetails); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.