Skip to content

Commit 0717fd5

Browse files
committed
Added support for custom cryptographic policy values
1 parent 172f8a5 commit 0717fd5

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ public class GlobalConfiguration
99
public LoggingDefinition Logging { get; set; } = new LoggingDefinition();
1010
public HostKeysDefinition HostKeys { get; set; } = new HostKeysDefinition();
1111
public HooksDefinition Hooks { get; set; } = new HooksDefinition();
12+
13+
public string Ciphers { get; set; }
14+
public string HostKeyAlgorithms { get; set; }
15+
public string KexAlgorithms { get; set; }
16+
public string MACs { get; set; }
1217
}
1318
}

src/ES.SFTP.Host/ES.SFTP.Host.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="6.0.0" />
20+
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.0.1" />
2121
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
22-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.6" />
22+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.8" />
2323
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
24-
<PackageReference Include="Serilog" Version="2.9.0" />
24+
<PackageReference Include="Serilog" Version="2.10.0" />
2525
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
2626
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.1.0" />
2727
</ItemGroup>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public class SSHConfiguration
99

1010
public List<string> AllowUsers { get; } = new List<string>();
1111

12+
public string Ciphers { get; set; }
13+
public string HostKeyAlgorithms { get; set; }
14+
public string KexAlgorithms { get; set; }
15+
public string MACs { get; set; }
16+
1217
public override string ToString()
1318
{
1419
var builder = new StringBuilder();
@@ -22,6 +27,12 @@ public override string ToString()
2227
builder.AppendLine("HostKey /etc/ssh/ssh_host_ed25519_key");
2328
builder.AppendLine("HostKey /etc/ssh/ssh_host_rsa_key");
2429
builder.AppendLine();
30+
builder.AppendLine("# Cryptographic policy");
31+
if (!string.IsNullOrWhiteSpace(Ciphers)) builder.AppendLine($"Ciphers {Ciphers}");
32+
if (!string.IsNullOrWhiteSpace(HostKeyAlgorithms)) builder.AppendLine($"HostKeyAlgorithms {HostKeyAlgorithms}");
33+
if (!string.IsNullOrWhiteSpace(KexAlgorithms)) builder.AppendLine($"KexAlgorithms {KexAlgorithms}");
34+
if (!string.IsNullOrWhiteSpace(MACs)) builder.AppendLine($"MACs {MACs }");
35+
builder.AppendLine();
2536
builder.AppendLine("# Disable DNS for fast connections");
2637
builder.AppendLine("UseDNS no");
2738
builder.AppendLine();

src/ES.SFTP.Host/SSH/SSHService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ private async Task UpdateConfiguration()
6262
var sftpConfig = await _mediator.Send(new SftpConfigurationRequest());
6363
_loggingIgnoreNoIdentificationString = sftpConfig.Global.Logging.IgnoreNoIdentificationString;
6464

65-
var sshdConfig = new SSHConfiguration();
65+
var sshdConfig = new SSHConfiguration
66+
{
67+
Ciphers = sftpConfig.Global.Ciphers,
68+
HostKeyAlgorithms = sftpConfig.Global.HostKeyAlgorithms,
69+
KexAlgorithms = sftpConfig.Global.KexAlgorithms,
70+
MACs = sftpConfig.Global.MACs,
71+
};
72+
6673
var exceptionalUsers = sftpConfig.Users.Where(s => s.Chroot != null).ToList();
6774

6875
var standardDeclarations = new[]

0 commit comments

Comments
 (0)