Skip to content

Commit af6ccc2

Browse files
committed
Use X509CertificateLoader in .NET 10
1 parent bb1960a commit af6ccc2

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

MailKit/Security/SslHandshakeException.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,20 @@ internal static SslHandshakeException Create (ref SslCertificateValidationInfo v
205205
if (validationInfo != null) {
206206
try {
207207
int rootIndex = validationInfo.ChainElements.Count - 1;
208-
if (rootIndex > 0)
208+
209+
if (rootIndex > 0) {
210+
#if NET10_0_OR_GREATER
211+
root = X509CertificateLoader.LoadCertificate (validationInfo.ChainElements[rootIndex].Certificate.RawData);
212+
#else
209213
root = new X509Certificate2 (validationInfo.ChainElements[rootIndex].Certificate.RawData);
214+
#endif
215+
}
216+
217+
#if NET10_0_OR_GREATER
218+
certificate = X509CertificateLoader.LoadCertificate (validationInfo.Certificate.RawData);
219+
#else
210220
certificate = new X509Certificate2 (validationInfo.Certificate.RawData);
221+
#endif
211222

212223
if ((validationInfo.SslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) != 0) {
213224
message.AppendLine ("The SSL certificate for the server was not available.");
@@ -338,7 +349,11 @@ sealed class SslChainElement : IDisposable
338349

339350
public SslChainElement (X509ChainElement element)
340351
{
352+
#if NET10_0_OR_GREATER
353+
Certificate = X509CertificateLoader.LoadCertificate (element.Certificate.RawData);
354+
#else
341355
Certificate = new X509Certificate2 (element.Certificate.RawData);
356+
#endif
342357
ChainElementStatus = element.ChainElementStatus;
343358
Information = element.Information;
344359
}
@@ -359,7 +374,11 @@ sealed class SslCertificateValidationInfo : IDisposable
359374

360375
public SslCertificateValidationInfo (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
361376
{
377+
#if NET10_0_OR_GREATER
378+
Certificate = X509CertificateLoader.LoadCertificate (certificate.Export (X509ContentType.Cert));
379+
#else
362380
Certificate = new X509Certificate2 (certificate.Export (X509ContentType.Cert));
381+
#endif
363382
ChainElements = new List<SslChainElement> ();
364383
SslPolicyErrors = sslPolicyErrors;
365384
ChainStatus = chain.ChainStatus;

0 commit comments

Comments
 (0)