Skip to content

Commit

Permalink
feature: support both password and PKI
Browse files Browse the repository at this point in the history
* add PKIandPassword for auth

* added global option PKIandPassword
  • Loading branch information
1ARdotNO authored Aug 25, 2023
1 parent 1ac83f7 commit 025fdac
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ES.SFTP/Configuration/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private Task UpdateConfiguration()
config.Global.Directories ??= new List<string>();
config.Global.Logging ??= new LoggingDefinition();
config.Global.Chroot ??= new ChrootDefinition();
config.Global.PKIandPassword ??= new string("");
config.Global.HostKeys ??= new HostKeysDefinition();
config.Global.Hooks ??= new HooksDefinition();

Expand Down
1 change: 1 addition & 0 deletions src/ES.SFTP/Configuration/Elements/GlobalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class GlobalConfiguration
public LoggingDefinition Logging { get; set; } = new();
public HostKeysDefinition HostKeys { get; set; } = new();
public HooksDefinition Hooks { get; set; } = new();
public string PKIandPassword { get; set; }

public string Ciphers { get; set; }
public string HostKeyAlgorithms { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/ES.SFTP/SSH/Configuration/SSHConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SSHConfiguration
public string HostKeyAlgorithms { get; set; }
public string KexAlgorithms { get; set; }
public string MACs { get; set; }
public string PKIandPassword { get; set; }

public override string ToString()
{
Expand Down Expand Up @@ -44,6 +45,8 @@ public override string ToString()
builder.AppendLine("# Allowed users");
builder.AppendLine($"AllowUsers {string.Join(" ", AllowUsers)}");
builder.AppendLine();
if (PKIandPassword == "true") builder.AppendLine("AuthenticationMethods \"publickey,password\"");
builder.AppendLine();
builder.AppendLine("# Match blocks");
foreach (var matchBlock in MatchBlocks)
{
Expand Down
3 changes: 2 additions & 1 deletion src/ES.SFTP/SSH/SSHService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ private async Task UpdateConfiguration()
Ciphers = sftpConfig.Global.Ciphers,
HostKeyAlgorithms = sftpConfig.Global.HostKeyAlgorithms,
KexAlgorithms = sftpConfig.Global.KexAlgorithms,
MACs = sftpConfig.Global.MACs
MACs = sftpConfig.Global.MACs,
PKIandPassword = sftpConfig.Global.PKIandPassword
};

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

0 comments on commit 025fdac

Please sign in to comment.