Skip to content

Commit 1270a92

Browse files
committed
Use new .NET 5.0 API to load a client certificate.
1 parent d40c944 commit 1270a92

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,9 @@ await sslStream.AuthenticateAsClientAsync(clientAuthenticationOptions.TargetHost
13321332
// Returns a X509CertificateCollection containing the single certificate contained in 'sslKeyFile' (PEM private key) and 'sslCertificateFile' (PEM certificate).
13331333
X509CertificateCollection LoadCertificate(string sslKeyFile, string sslCertificateFile)
13341334
{
1335-
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
1335+
#if NETSTANDARD1_3 || NETSTANDARD2_0
1336+
throw new NotSupportedException("SslCert and SslKey connection string options are not supported in netstandard1.3 or netstandard2.0.");
1337+
#elif NET45 || NET461 || NET471 || NETSTANDARD2_1 || NETCOREAPP2_1 || NETCOREAPP3_1
13361338
m_logArguments[1] = sslKeyFile;
13371339
Log.Debug("Session{0} loading client key from KeyFile '{1}'", m_logArguments);
13381340
string keyPem;
@@ -1402,7 +1404,8 @@ X509CertificateCollection LoadCertificate(string sslKeyFile, string sslCertifica
14021404
throw new MySqlException("Could not load the client key from " + sslKeyFile, ex);
14031405
}
14041406
#else
1405-
throw new NotSupportedException("SslCert and SslKey connection string options are not supported in netstandard1.3 or netstandard2.0.");
1407+
m_clientCertificate = X509Certificate2.CreateFromPemFile(sslCertificateFile, sslKeyFile);
1408+
return new() { m_clientCertificate };
14061409
#endif
14071410
}
14081411
}

0 commit comments

Comments
 (0)