Skip to content

Commit 1e009ea

Browse files
rusherbgrainger
andauthored
Support zero-configuration TLS. (#1500)
Implements the client side of https://jira.mariadb.org/browse/MDEV-31855. Since MariaDB 11.4.1, TLS use has greatly been simplified. Connector side doesn't require TLS configuration anymore, even with self-signed certificates. Clients now validate SSL certificates using client password (using seed and server certificate SHA256 thumbprint). Limitations: * only possible when using mysql_native_password/client_ed25519 authentication * password is required See https://mariadb.org/mission-impossible-zero-configuration-ssl/. Make Ed25519AuthenticationPlugin.Install threadsafe. Signed-off-by: rusher <[email protected]> Signed-off-by: Bradley Grainger <[email protected]> Co-authored-by: Bradley Grainger <[email protected]>
1 parent 6e45dcd commit 1e009ea

File tree

16 files changed

+269
-35
lines changed

16 files changed

+269
-35
lines changed

.ci/config/config.compression+ssl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"SocketPath": "./../../../../.ci/run/mysql/mysqld.sock",
55
"PasswordlessUser": "no_password",
66
"SecondaryDatabase": "testdb2",
7-
"UnsupportedFeatures": "CachingSha2Password,Redirection,RsaEncryption,Tls12,Tls13,UuidToBin",
7+
"UnsupportedFeatures": "CachingSha2Password,Redirection,RsaEncryption,Tls12,Tls13,TlsFingerprintValidation,UuidToBin",
88
"MySqlBulkLoaderLocalCsvFile": "../../../TestData/LoadData_UTF8_BOM_Unix.CSV",
99
"MySqlBulkLoaderLocalTsvFile": "../../../TestData/LoadData_UTF8_BOM_Unix.TSV",
1010
"CertificatesPath": "../../../../.ci/server/certs"

.ci/config/config.compression.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"SocketPath": "./../../../../.ci/run/mysql/mysqld.sock",
55
"PasswordlessUser": "no_password",
66
"SecondaryDatabase": "testdb2",
7-
"UnsupportedFeatures": "Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,UnixDomainSocket,ZeroDateTime",
7+
"UnsupportedFeatures": "Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,UnixDomainSocket,ZeroDateTime",
88
"MySqlBulkLoaderLocalCsvFile": "../../../../tests/TestData/LoadData_UTF8_BOM_Unix.CSV",
99
"MySqlBulkLoaderLocalTsvFile": "../../../../tests/TestData/LoadData_UTF8_BOM_Unix.TSV"
1010
}

.ci/config/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"SocketPath": "./../../../../.ci/run/mysql/mysqld.sock",
55
"PasswordlessUser": "no_password",
66
"SecondaryDatabase": "testdb2",
7-
"UnsupportedFeatures": "Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,UnixDomainSocket,ZeroDateTime",
7+
"UnsupportedFeatures": "Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,UnixDomainSocket,ZeroDateTime",
88
"MySqlBulkLoaderLocalCsvFile": "../../../../tests/TestData/LoadData_UTF8_BOM_Unix.CSV",
99
"MySqlBulkLoaderLocalTsvFile": "../../../../tests/TestData/LoadData_UTF8_BOM_Unix.TSV"
1010
}

.ci/config/config.ssl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"SocketPath": "./../../../../.ci/run/mysql/mysqld.sock",
55
"PasswordlessUser": "no_password",
66
"SecondaryDatabase": "testdb2",
7-
"UnsupportedFeatures": "CachingSha2Password,Redirection,RsaEncryption,Tls12,Tls13,UuidToBin",
7+
"UnsupportedFeatures": "CachingSha2Password,Redirection,RsaEncryption,Tls12,Tls13,TlsFingerprintValidation,UuidToBin",
88
"MySqlBulkLoaderLocalCsvFile": "../../../../tests/TestData/LoadData_UTF8_BOM_Unix.CSV",
99
"MySqlBulkLoaderLocalTsvFile": "../../../../tests/TestData/LoadData_UTF8_BOM_Unix.TSV",
1010
"CertificatesPath": "../../../../.ci/server/certs"

azure-pipelines.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
arguments: 'tests\IntegrationTests\IntegrationTests.csproj -c MySqlData'
6363
testRunTitle: 'MySql.Data integration tests'
6464
env:
65-
DATA__UNSUPPORTEDFEATURES: 'Ed25519,QueryAttributes,StreamingResults,UnixDomainSocket'
65+
DATA__UNSUPPORTEDFEATURES: 'Ed25519,QueryAttributes,StreamingResults,TlsFingerprintValidation,UnixDomainSocket'
6666
DATA__CONNECTIONSTRING: 'server=localhost;port=3306;user id=root;password=test;database=mysqltest;ssl mode=none;DefaultCommandTimeout=3600'
6767
DATA__CERTIFICATESPATH: '$(Build.Repository.LocalPath)\.ci\server\certs\'
6868
DATA__MYSQLBULKLOADERLOCALCSVFILE: '$(Build.Repository.LocalPath)\tests\TestData\LoadData_UTF8_BOM_Unix.CSV'
@@ -136,7 +136,7 @@ jobs:
136136
arguments: '-c Release --no-restore'
137137
testRunTitle: ${{ format('{0}, $(Agent.OS), {1}, {2}', 'mysql:8.0', 'net472/net8.0', 'No SSL') }}
138138
env:
139-
DATA__UNSUPPORTEDFEATURES: 'Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,UnixDomainSocket'
139+
DATA__UNSUPPORTEDFEATURES: 'Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,UnixDomainSocket'
140140
DATA__CONNECTIONSTRING: 'server=localhost;port=3306;user id=mysqltest;password=test;database=mysqltest;ssl mode=none;DefaultCommandTimeout=3600;AllowPublicKeyRetrieval=True;UseCompression=True'
141141

142142
- job: windows_integration_tests_2
@@ -174,7 +174,7 @@ jobs:
174174
arguments: '-c Release --no-restore'
175175
testRunTitle: ${{ format('{0}, $(Agent.OS), {1}, {2}', 'mysql:8.0', 'net6.0', 'No SSL') }}
176176
env:
177-
DATA__UNSUPPORTEDFEATURES: 'Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,UnixDomainSocket'
177+
DATA__UNSUPPORTEDFEATURES: 'Ed25519,QueryAttributes,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,UnixDomainSocket'
178178
DATA__CONNECTIONSTRING: 'server=localhost;port=3306;user id=mysqltest;password=test;database=mysqltest;ssl mode=none;DefaultCommandTimeout=3600;AllowPublicKeyRetrieval=True'
179179

180180
- job: linux_integration_tests
@@ -187,23 +187,23 @@ jobs:
187187
'MySQL 8.0':
188188
image: 'mysql:8.0'
189189
connectionStringExtra: 'AllowPublicKeyRetrieval=True'
190-
unsupportedFeatures: 'Ed25519,Redirection,StreamingResults,Tls11,ZeroDateTime'
190+
unsupportedFeatures: 'Ed25519,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,ZeroDateTime'
191191
'MySQL 8.4':
192192
image: 'mysql:8.4'
193193
connectionStringExtra: 'AllowPublicKeyRetrieval=True'
194-
unsupportedFeatures: 'Ed25519,Redirection,StreamingResults,Tls11,ZeroDateTime'
194+
unsupportedFeatures: 'Ed25519,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,ZeroDateTime'
195195
'MySQL 9.0':
196196
image: 'mysql:9.0'
197197
connectionStringExtra: 'AllowPublicKeyRetrieval=True'
198-
unsupportedFeatures: 'Ed25519,Redirection,StreamingResults,Tls11,ZeroDateTime'
198+
unsupportedFeatures: 'Ed25519,Redirection,StreamingResults,Tls11,TlsFingerprintValidation,ZeroDateTime'
199199
'MariaDB 10.6':
200200
image: 'mariadb:10.6'
201201
connectionStringExtra: ''
202-
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Sha256Password,Tls11,UuidToBin,Redirection'
202+
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Redirection,Sha256Password,Tls11,TlsFingerprintValidation,UuidToBin'
203203
'MariaDB 10.11':
204204
image: 'mariadb:10.11'
205205
connectionStringExtra: ''
206-
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Sha256Password,Tls11,UuidToBin,Redirection'
206+
unsupportedFeatures: 'CachingSha2Password,CancelSleepSuccessfully,Json,RoundDateTime,QueryAttributes,Redirection,Sha256Password,Tls11,TlsFingerprintValidation,UuidToBin'
207207
'MariaDB 11.4':
208208
image: 'mariadb:11.4'
209209
connectionStringExtra: ''

src/MySqlConnector.Authentication.Ed25519/Ed25519AuthenticationPlugin.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Security.Cryptography;
33
using System.Text;
4+
using System.Threading;
45
using Chaos.NaCl.Internal.Ed25519Ref10;
56

67
namespace MySqlConnector.Authentication.Ed25519;
@@ -9,19 +10,16 @@ namespace MySqlConnector.Authentication.Ed25519;
910
/// Provides an implementation of the <c>client_ed25519</c> authentication plugin for MariaDB.
1011
/// </summary>
1112
/// <remarks>See <a href="https://mariadb.com/kb/en/library/authentication-plugin-ed25519/">Authentication Plugin - ed25519</a>.</remarks>
12-
public sealed class Ed25519AuthenticationPlugin : IAuthenticationPlugin
13+
public sealed class Ed25519AuthenticationPlugin : IAuthenticationPlugin2
1314
{
1415
/// <summary>
1516
/// Registers the Ed25519 authentication plugin with MySqlConnector. You must call this method once before
1617
/// opening a connection that uses Ed25519 authentication.
1718
/// </summary>
1819
public static void Install()
1920
{
20-
if (!s_isInstalled)
21-
{
21+
if (Interlocked.CompareExchange(ref s_isInstalled, 1, 0) == 0)
2222
AuthenticationPlugins.Register(new Ed25519AuthenticationPlugin());
23-
s_isInstalled = true;
24-
}
2523
}
2624

2725
/// <summary>
@@ -33,6 +31,21 @@ public static void Install()
3331
/// Creates the authentication response.
3432
/// </summary>
3533
public byte[] CreateResponse(string password, ReadOnlySpan<byte> authenticationData)
34+
{
35+
CreateResponseAndHash(password, authenticationData, out _, out var authenticationResponse);
36+
return authenticationResponse;
37+
}
38+
39+
/// <summary>
40+
/// Creates the Ed25519 password hash.
41+
/// </summary>
42+
public byte[] CreatePasswordHash(string password, ReadOnlySpan<byte> authenticationData)
43+
{
44+
CreateResponseAndHash(password, authenticationData, out var passwordHash, out _);
45+
return passwordHash;
46+
}
47+
48+
private static void CreateResponseAndHash(string password, ReadOnlySpan<byte> authenticationData, out byte[] passwordHash, out byte[] authenticationResponse)
3649
{
3750
// Java reference: https://github.com/MariaDB/mariadb-connector-j/blob/master/src/main/java/org/mariadb/jdbc/internal/com/send/authentication/Ed25519PasswordPlugin.java
3851
// C reference: https://github.com/MariaDB/server/blob/592fe954ef82be1bc08b29a8e54f7729eb1e1343/plugin/auth_ed25519/ref10/sign.c#L7
@@ -111,6 +124,9 @@ public byte[] CreateResponse(string password, ReadOnlySpan<byte> authenticationD
111124
GroupOperations.ge_scalarmult_base(out var A, az, 0);
112125
GroupOperations.ge_p3_tobytes(sm, 32, ref A);
113126

127+
passwordHash = new byte[32];
128+
Array.Copy(sm, 32, passwordHash, 0, 32);
129+
114130
/*** Java
115131
nonce = scalar.reduce(nonce);
116132
GroupElement elementRvalue = spec.getB().scalarMultiply(nonce);
@@ -154,12 +170,12 @@ public byte[] CreateResponse(string password, ReadOnlySpan<byte> authenticationD
154170

155171
var result = new byte[64];
156172
Buffer.BlockCopy(sm, 0, result, 0, result.Length);
157-
return result;
173+
authenticationResponse = result;
158174
}
159175

160176
private Ed25519AuthenticationPlugin()
161177
{
162178
}
163179

164-
private static bool s_isInstalled;
180+
private static int s_isInstalled;
165181
}

src/MySqlConnector/Authentication/IAuthenticationPlugin.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,19 @@ public interface IAuthenticationPlugin
2020
/// <returns>The authentication response.</returns>
2121
byte[] CreateResponse(string password, ReadOnlySpan<byte> authenticationData);
2222
}
23+
24+
/// <summary>
25+
/// <see cref="IAuthenticationPlugin2"/> is an extension to <see cref="IAuthenticationPlugin"/> that returns a hash of the client's password.
26+
/// </summary>
27+
public interface IAuthenticationPlugin2 : IAuthenticationPlugin
28+
{
29+
/// <summary>
30+
/// Hashes the client's password (e.g., for TLS certificate fingerprint verification).
31+
/// </summary>
32+
/// <param name="password">The client's password.</param>
33+
/// <param name="authenticationData">The authentication data supplied by the server; this is the <code>auth method data</code>
34+
/// from the <a href="https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchRequest">Authentication
35+
/// Method Switch Request Packet</a>.</param>
36+
/// <returns>The authentication-method-specific hash of the client's password.</returns>
37+
byte[] CreatePasswordHash(string password, ReadOnlySpan<byte> authenticationData);
38+
}

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 140 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,13 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
438438
var initialHandshake = InitialHandshakePayload.Create(payload.Span);
439439

440440
// if PluginAuth is supported, then use the specified auth plugin; else, fall back to protocol capabilities to determine the auth type to use
441-
var authPluginName = (initialHandshake.ProtocolCapabilities & ProtocolCapabilities.PluginAuth) != 0 ? initialHandshake.AuthPluginName! :
441+
m_currentAuthenticationMethod = (initialHandshake.ProtocolCapabilities & ProtocolCapabilities.PluginAuth) != 0 ? initialHandshake.AuthPluginName! :
442442
(initialHandshake.ProtocolCapabilities & ProtocolCapabilities.SecureConnection) == 0 ? "mysql_old_password" :
443443
"mysql_native_password";
444-
Log.ServerSentAuthPluginName(m_logger, Id, authPluginName);
445-
if (authPluginName is not "mysql_native_password" and not "sha256_password" and not "caching_sha2_password")
444+
Log.ServerSentAuthPluginName(m_logger, Id, m_currentAuthenticationMethod);
445+
if (m_currentAuthenticationMethod is not "mysql_native_password" and not "sha256_password" and not "caching_sha2_password")
446446
{
447-
Log.UnsupportedAuthenticationMethod(m_logger, Id, authPluginName);
447+
Log.UnsupportedAuthenticationMethod(m_logger, Id, m_currentAuthenticationMethod);
448448
throw new NotSupportedException($"Authentication method '{initialHandshake.AuthPluginName}' is not supported.");
449449
}
450450

@@ -528,6 +528,46 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
528528
}
529529

530530
var ok = OkPayload.Create(payload.Span, this);
531+
532+
if (m_sslPolicyErrors != SslPolicyErrors.None)
533+
{
534+
// SSL would normally have thrown error, but this was suppressed in ValidateRemoteCertificate; now we need to verify the server certificate
535+
// pass only if :
536+
// * connection method is MitM-proof (e.g. unix socket)
537+
// * auth plugin is MitM-proof and check SHA2(user's hashed password, scramble, certificate fingerprint)
538+
// see https://mariadb.org/mission-impossible-zero-configuration-ssl/
539+
var ignoreCertificateError = false;
540+
541+
if (cs.ConnectionProtocol == MySqlConnectionProtocol.UnixSocket)
542+
{
543+
Log.CertificateErrorUnixSocket(m_logger, Id, m_sslPolicyErrors);
544+
ignoreCertificateError = true;
545+
}
546+
else if (string.IsNullOrEmpty(password))
547+
{
548+
// there is no shared secret that can be used to validate the certificate
549+
Log.CertificateErrorNoPassword(m_logger, Id, m_sslPolicyErrors);
550+
}
551+
else if (ValidateFingerprint(ok.StatusInfo, initialHandshake.AuthPluginData.AsSpan(0, 20), password))
552+
{
553+
Log.CertificateErrorValidThumbprint(m_logger, Id, m_sslPolicyErrors);
554+
ignoreCertificateError = true;
555+
}
556+
557+
if (!ignoreCertificateError)
558+
{
559+
ShutdownSocket();
560+
HostName = "";
561+
lock (m_lock)
562+
m_state = State.Failed;
563+
564+
// throw a MySqlException with an AuthenticationException InnerException to mimic what would have happened if ValidateRemoteCertificate returned false
565+
var innerException = new AuthenticationException($"The remote certificate was rejected due to the following error: {m_sslPolicyErrors}");
566+
Log.CouldNotInitializeTlsConnection(m_logger, innerException, Id);
567+
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "SSL Authentication Error", innerException);
568+
}
569+
}
570+
531571
var redirectionUrl = ok.RedirectionUrl;
532572

533573
if (m_useCompression)
@@ -567,6 +607,70 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
567607
}
568608
}
569609

610+
/// <summary>
611+
/// Validate SSL validation hash (from OK packet).
612+
/// </summary>
613+
/// <param name="validationHash">The validation hash received from the server.</param>
614+
/// <param name="challenge">The auth plugin data from the initial handshake.</param>
615+
/// <param name="password">The user's password.</param>
616+
/// <returns><c>true</c> if the validation hash matches the locally-computed value; otherwise, <c>false</c>.</returns>
617+
private bool ValidateFingerprint(byte[]? validationHash, ReadOnlySpan<byte> challenge, string password)
618+
{
619+
// expect 0x01 followed by 64 hex characters giving a SHA2 hash
620+
if (validationHash?.Length != 65 || validationHash[0] != 1)
621+
return false;
622+
623+
byte[]? passwordHashResult = null;
624+
switch (m_currentAuthenticationMethod)
625+
{
626+
case "mysql_native_password":
627+
passwordHashResult = AuthenticationUtility.HashPassword([], password, onlyHashPassword: true);
628+
break;
629+
630+
case "client_ed25519":
631+
AuthenticationPlugins.TryGetPlugin(m_currentAuthenticationMethod, out var ed25519Plugin);
632+
if (ed25519Plugin is IAuthenticationPlugin2 plugin2)
633+
passwordHashResult = plugin2.CreatePasswordHash(password, challenge);
634+
break;
635+
}
636+
if (passwordHashResult is null)
637+
return false;
638+
639+
Span<byte> combined = stackalloc byte[32 + challenge.Length + passwordHashResult.Length];
640+
passwordHashResult.CopyTo(combined);
641+
challenge.CopyTo(combined[passwordHashResult.Length..]);
642+
m_remoteCertificateSha2Thumbprint!.CopyTo(combined[(passwordHashResult.Length + challenge.Length)..]);
643+
644+
Span<byte> hashBytes = stackalloc byte[32];
645+
#if NET5_0_OR_GREATER
646+
SHA256.TryHashData(combined, hashBytes, out _);
647+
#else
648+
using var sha256 = SHA256.Create();
649+
sha256.TryComputeHash(combined, hashBytes, out _);
650+
#endif
651+
652+
Span<byte> serverHash = combined[0..32];
653+
return TryConvertFromHexString(validationHash.AsSpan(1), serverHash) && serverHash.SequenceEqual(hashBytes);
654+
655+
static bool TryConvertFromHexString(ReadOnlySpan<byte> hexChars, Span<byte> data)
656+
{
657+
ReadOnlySpan<byte> hexDigits = "0123456789ABCDEFabcdef"u8;
658+
for (var i = 0; i < hexChars.Length; i += 2)
659+
{
660+
var high = hexDigits.IndexOf(hexChars[i]);
661+
var low = hexDigits.IndexOf(hexChars[i + 1]);
662+
if (high == -1 || low == -1)
663+
return false;
664+
if (high > 15)
665+
high -= 6;
666+
if (low > 15)
667+
low -= 6;
668+
data[i / 2] = (byte) ((high << 4) | low);
669+
}
670+
return true;
671+
}
672+
}
673+
570674
public static async ValueTask<ServerSession> ConnectAndRedirectAsync(ILogger connectionLogger, ILogger poolLogger, IConnectionPoolMetadata pool, ConnectionSettings cs, ILoadBalancer? loadBalancer, MySqlConnection connection, Action<ILogger, int, string, Exception?>? logMessage, long startingTimestamp, Activity? activity, IOBehavior ioBehavior, CancellationToken cancellationToken)
571675
{
572676
var session = new ServerSession(connectionLogger, pool);
@@ -729,6 +833,7 @@ private async Task<PayloadData> SwitchAuthenticationAsync(ConnectionSettings cs,
729833
// if the server didn't support the hashed password; rehash with the new challenge
730834
var switchRequest = AuthenticationMethodSwitchRequestPayload.Create(payload.Span);
731835
Log.SwitchingToAuthenticationMethod(m_logger, Id, switchRequest.Name);
836+
m_currentAuthenticationMethod = switchRequest.Name;
732837
switch (switchRequest.Name)
733838
{
734839
case "mysql_native_password":
@@ -1485,6 +1590,21 @@ caCertificateChain is not null &&
14851590
if (cs.SslMode == MySqlSslMode.VerifyCA)
14861591
rcbPolicyErrors &= ~SslPolicyErrors.RemoteCertificateNameMismatch;
14871592

1593+
if (rcbCertificate is X509Certificate2 cert2)
1594+
{
1595+
// saving sha256 thumbprint and SSL errors until thumbprint validation
1596+
#if NET7_0_OR_GREATER
1597+
m_remoteCertificateSha2Thumbprint = SHA256.HashData(cert2.RawDataMemory.Span);
1598+
#elif NET5_0_OR_GREATER
1599+
m_remoteCertificateSha2Thumbprint = SHA256.HashData(cert2.RawData);
1600+
#else
1601+
using var sha256 = SHA256.Create();
1602+
m_remoteCertificateSha2Thumbprint = sha256.ComputeHash(cert2.RawData);
1603+
#endif
1604+
m_sslPolicyErrors = rcbPolicyErrors;
1605+
return true;
1606+
}
1607+
14881608
return rcbPolicyErrors == SslPolicyErrors.None;
14891609
}
14901610

@@ -1558,11 +1678,22 @@ await sslStream.AuthenticateAsClientAsync(clientAuthenticationOptions.TargetHost
15581678
m_payloadHandler!.ByteHandler = sslByteHandler;
15591679
m_isSecureConnection = true;
15601680
m_sslStream = sslStream;
1681+
if (m_sslPolicyErrors != SslPolicyErrors.None)
1682+
{
15611683
#if NETCOREAPP3_0_OR_GREATER
1562-
Log.ConnectedTlsBasic(m_logger, Id, sslStream.SslProtocol, sslStream.NegotiatedCipherSuite);
1684+
Log.ConnectedTlsBasicPreliminary(m_logger, Id, m_sslPolicyErrors, sslStream.SslProtocol, sslStream.NegotiatedCipherSuite);
15631685
#else
1564-
Log.ConnectedTlsDetailed(m_logger, Id, sslStream.SslProtocol, sslStream.CipherAlgorithm, sslStream.HashAlgorithm, sslStream.KeyExchangeAlgorithm, sslStream.KeyExchangeStrength);
1686+
Log.ConnectedTlsDetailedPreliminary(m_logger, Id, m_sslPolicyErrors, sslStream.SslProtocol, sslStream.CipherAlgorithm, sslStream.HashAlgorithm, sslStream.KeyExchangeAlgorithm, sslStream.KeyExchangeStrength);
15651687
#endif
1688+
}
1689+
else
1690+
{
1691+
#if NETCOREAPP3_0_OR_GREATER
1692+
Log.ConnectedTlsBasic(m_logger, Id, sslStream.SslProtocol, sslStream.NegotiatedCipherSuite);
1693+
#else
1694+
Log.ConnectedTlsDetailed(m_logger, Id, sslStream.SslProtocol, sslStream.CipherAlgorithm, sslStream.HashAlgorithm, sslStream.KeyExchangeAlgorithm, sslStream.KeyExchangeStrength);
1695+
#endif
1696+
}
15661697
}
15671698
catch (Exception ex)
15681699
{
@@ -2006,4 +2137,7 @@ protected override void OnStatementBegin(int index)
20062137
private PayloadData m_setNamesPayload;
20072138
private byte[]? m_pipelinedResetConnectionBytes;
20082139
private Dictionary<string, PreparedStatements>? m_preparedStatements;
2140+
private string? m_currentAuthenticationMethod;
2141+
private byte[]? m_remoteCertificateSha2Thumbprint;
2142+
private SslPolicyErrors m_sslPolicyErrors;
20092143
}

0 commit comments

Comments
 (0)