Skip to content

Commit 9252999

Browse files
sdellacornwoodCopilot
authored
feat: add option to configure available tls cipher suites for relay (#1914)
* feat: add option to configure available tls cipher suites for relay * feat: add option to control CheckCertificateRevocation flag of MailKit * Update Rnwood.Smtp4dev/Startup.cs Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Rob Wood <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 93f5788 commit 9252999

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Rnwood.Smtp4dev/Server/Settings/RelayOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public int SmtpPort
2424
}
2525

2626
public SecureSocketOptions TlsMode { get; set; } = SecureSocketOptions.Auto;
27+
28+
public string[] SslCipherSuitesPolicy { get; set; } = System.Array.Empty<string>();
2729

30+
public bool CheckCertificateRevocation { get; set; } = true;
31+
2832
public string[] AutomaticEmails { get; set; } = System.Array.Empty<string>();
2933

3034
public string AutomaticRelayExpression { get; set; }

Rnwood.Smtp4dev/Server/Settings/RelayOptionsSource.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public int? SmtpPort
1717

1818

1919
public SecureSocketOptions? TlsMode { get; set; }
20+
21+
public string[] SslCipherSuitesPolicy { get; set; } = System.Array.Empty<string>();
2022

23+
public bool CheckCertificateRevocation { get; set; } = true;
24+
2125
public string[] AutomaticEmails { get; set; } = System.Array.Empty<string>();
2226

2327
public string AutomaticRelayExpression { get; set; }

Rnwood.Smtp4dev/Startup.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Globalization;
34
using System.IO;
45
using System.Net;
@@ -22,6 +23,7 @@
2223
using Rnwood.Smtp4dev.Service;
2324
using Serilog;
2425
using System.Linq;
26+
using System.Net.Security;
2527
using Microsoft.Data.Sqlite;
2628
using Microsoft.EntityFrameworkCore.Infrastructure;
2729
using Microsoft.AspNetCore.Http;
@@ -235,6 +237,25 @@ public void ConfigureServices(IServiceCollection services)
235237
}
236238

237239
SmtpClient result = new SmtpClient();
240+
#if NET5_0_OR_GREATER
241+
if (relayOptions.SslCipherSuitesPolicy.Length > 0)
242+
{
243+
try
244+
{
245+
var suites = new List<TlsCipherSuite>(relayOptions.SslCipherSuitesPolicy.Length);
246+
foreach (var suite in relayOptions.SslCipherSuitesPolicy)
247+
{
248+
suites.Add(Enum.Parse<TlsCipherSuite>(suite, true));
249+
}
250+
251+
result.SslCipherSuitesPolicy = new CipherSuitesPolicy(suites.ToArray());
252+
} catch (PlatformNotSupportedException e)
253+
{
254+
Log.Logger.Warning("Ssl cipher suites policy is not supported on this platform: {exception}", e);
255+
}
256+
}
257+
#endif
258+
result.CheckCertificateRevocation = relayOptions.CheckCertificateRevocation;
238259
result.Connect(relayOptions.SmtpServer, relayOptions.SmtpPort, relayOptions.TlsMode);
239260

240261
if (!string.IsNullOrEmpty(relayOptions.Login))

0 commit comments

Comments
 (0)