Skip to content

Commit

Permalink
fix: Override system default cipher list
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Apr 17, 2024
1 parent 399fd8b commit 240dfb3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/GZCTF/Services/MailSender.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Net.Security;
using System.Text;
using GZCTF.Models.Internal;
using GZCTF.Services.Interface;
Expand Down Expand Up @@ -33,6 +34,18 @@ public sealed class MailSender : IMailSender, IDisposable
{
_smtpClient = new();
_smtpClient.AuthenticationMechanisms.Remove("XOAUTH2");
if (!OperatingSystem.IsWindows())
{
// Some systems may not enable old (non-recommend) ciphers in SSL configuration and lead to failures when
// connecting to some SMTP servers, override the default policy to include all ciphers except MD5, SHA1, and NULL
_smtpClient.SslCipherSuitesPolicy = new CipherSuitesPolicy(Enum.GetValues<TlsCipherSuite>()
.Where(cipher =>
{
var cipherName = cipher.ToString();
// Exclude MD5, SHA1, and NULL ciphers for security reasons
return !cipherName.EndsWith("MD5") && !cipherName.EndsWith("SHA") && !cipherName.EndsWith("NULL");
}));
}
Task.Factory.StartNew(MailSenderWorker, _cancellationToken, TaskCreationOptions.LongRunning,
TaskScheduler.Default);
}
Expand Down

0 comments on commit 240dfb3

Please sign in to comment.