2018-08-13 02:43:59 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using Renci.SshNet;
|
|
|
|
|
|
|
|
namespace BTCPayServer.SSH
|
|
|
|
{
|
|
|
|
public class SSHSettings
|
|
|
|
{
|
|
|
|
public string Server { get; set; }
|
|
|
|
public int Port { get; set; } = 22;
|
|
|
|
public string KeyFile { get; set; }
|
|
|
|
public string KeyFilePassword { get; set; }
|
2019-09-20 11:51:14 +02:00
|
|
|
public string AuthorizedKeysFile { get; set; }
|
2018-08-13 02:43:59 +02:00
|
|
|
public string Username { get; set; }
|
|
|
|
public string Password { get; set; }
|
2019-08-27 16:30:25 +02:00
|
|
|
public List<SSHFingerprint> TrustedFingerprints { get; set; } = new List<SSHFingerprint>();
|
|
|
|
internal bool IsTrustedFingerprint(byte[] fingerPrint, byte[] hostKey)
|
|
|
|
{
|
|
|
|
return TrustedFingerprints.Any(f => f.Match(fingerPrint, hostKey));
|
|
|
|
}
|
2018-08-13 02:43:59 +02:00
|
|
|
|
|
|
|
public ConnectionInfo CreateConnectionInfo()
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(KeyFile))
|
|
|
|
{
|
|
|
|
return new ConnectionInfo(Server, Port, Username, new[] { new PrivateKeyAuthenticationMethod(Username, new PrivateKeyFile(KeyFile, KeyFilePassword)) });
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new ConnectionInfo(Server, Port, Username, new[] { new PasswordAuthenticationMethod(Username, Password) });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|