Skip to content

Commit 025fdac

Browse files
authored
feature: support both password and PKI
* add PKIandPassword for auth * added global option PKIandPassword
1 parent 1ac83f7 commit 025fdac

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

src/ES.SFTP/Configuration/ConfigurationService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private Task UpdateConfiguration()
6868
config.Global.Directories ??= new List<string>();
6969
config.Global.Logging ??= new LoggingDefinition();
7070
config.Global.Chroot ??= new ChrootDefinition();
71+
config.Global.PKIandPassword ??= new string("");
7172
config.Global.HostKeys ??= new HostKeysDefinition();
7273
config.Global.Hooks ??= new HooksDefinition();
7374

src/ES.SFTP/Configuration/Elements/GlobalConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class GlobalConfiguration
77
public LoggingDefinition Logging { get; set; } = new();
88
public HostKeysDefinition HostKeys { get; set; } = new();
99
public HooksDefinition Hooks { get; set; } = new();
10+
public string PKIandPassword { get; set; }
1011

1112
public string Ciphers { get; set; }
1213
public string HostKeyAlgorithms { get; set; }

src/ES.SFTP/SSH/Configuration/SSHConfiguration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class SSHConfiguration
1212
public string HostKeyAlgorithms { get; set; }
1313
public string KexAlgorithms { get; set; }
1414
public string MACs { get; set; }
15+
public string PKIandPassword { get; set; }
1516

1617
public override string ToString()
1718
{
@@ -44,6 +45,8 @@ public override string ToString()
4445
builder.AppendLine("# Allowed users");
4546
builder.AppendLine($"AllowUsers {string.Join(" ", AllowUsers)}");
4647
builder.AppendLine();
48+
if (PKIandPassword == "true") builder.AppendLine("AuthenticationMethods \"publickey,password\"");
49+
builder.AppendLine();
4750
builder.AppendLine("# Match blocks");
4851
foreach (var matchBlock in MatchBlocks)
4952
{

src/ES.SFTP/SSH/SSHService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ private async Task UpdateConfiguration()
6464
Ciphers = sftpConfig.Global.Ciphers,
6565
HostKeyAlgorithms = sftpConfig.Global.HostKeyAlgorithms,
6666
KexAlgorithms = sftpConfig.Global.KexAlgorithms,
67-
MACs = sftpConfig.Global.MACs
67+
MACs = sftpConfig.Global.MACs,
68+
PKIandPassword = sftpConfig.Global.PKIandPassword
6869
};
6970

7071
var exceptionalUsers = sftpConfig.Users.Where(s => s.Chroot != null).ToList();

0 commit comments

Comments
 (0)