@@ -438,13 +438,13 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
438
438
var initialHandshake = InitialHandshakePayload . Create ( payload . Span ) ;
439
439
440
440
// 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 ! :
442
442
( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . SecureConnection ) == 0 ? "mysql_old_password" :
443
443
"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" )
446
446
{
447
- Log . UnsupportedAuthenticationMethod ( m_logger , Id , authPluginName ) ;
447
+ Log . UnsupportedAuthenticationMethod ( m_logger , Id , m_currentAuthenticationMethod ) ;
448
448
throw new NotSupportedException ( $ "Authentication method '{ initialHandshake . AuthPluginName } ' is not supported.") ;
449
449
}
450
450
@@ -608,30 +608,27 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
608
608
}
609
609
610
610
/// <summary>
611
- /// Validate SSL validation has
611
+ /// Validate SSL validation hash (from OK packet).
612
612
/// </summary>
613
- /// <param name="validationHash">received validation hash</param>
614
- /// <param name="challenge">initial seed </param>
615
- /// <param name="password">password</param>
616
- /// <returns>true if validated </returns>
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
617
private bool ValidateFingerprint ( byte [ ] ? validationHash , ReadOnlySpan < byte > challenge , string password )
618
618
{
619
- if ( validationHash ? . Length != 65 )
619
+ // expect 0x01 followed by 64 hex characters giving a SHA2 hash
620
+ if ( validationHash ? . Length != 65 || validationHash [ 0 ] != 1 )
620
621
return false ;
621
622
622
- // ensure using SHA256 encryption
623
- if ( validationHash [ 0 ] != 0x01 )
624
- throw new FormatException ( $ "Unexpected validation hash format. expected 0x01 but got 0x{ validationHash [ 0 ] : X2} ") ;
625
-
626
623
byte [ ] ? passwordHashResult = null ;
627
- switch ( m_pluginName )
624
+ switch ( m_currentAuthenticationMethod )
628
625
{
629
626
case "mysql_native_password" :
630
627
passwordHashResult = AuthenticationUtility . HashPassword ( [ ] , password , onlyHashPassword : true ) ;
631
628
break ;
632
629
633
630
case "client_ed25519" :
634
- AuthenticationPlugins . TryGetPlugin ( m_pluginName , out var ed25519Plugin ) ;
631
+ AuthenticationPlugins . TryGetPlugin ( m_currentAuthenticationMethod , out var ed25519Plugin ) ;
635
632
if ( ed25519Plugin is IAuthenticationPlugin2 plugin2 )
636
633
passwordHashResult = plugin2 . CreatePasswordHash ( password , challenge ) ;
637
634
break ;
@@ -836,7 +833,7 @@ private async Task<PayloadData> SwitchAuthenticationAsync(ConnectionSettings cs,
836
833
// if the server didn't support the hashed password; rehash with the new challenge
837
834
var switchRequest = AuthenticationMethodSwitchRequestPayload . Create ( payload . Span ) ;
838
835
Log . SwitchingToAuthenticationMethod ( m_logger , Id , switchRequest . Name ) ;
839
- m_pluginName = switchRequest . Name ;
836
+ m_currentAuthenticationMethod = switchRequest . Name ;
840
837
switch ( switchRequest . Name )
841
838
{
842
839
case "mysql_native_password" :
@@ -2140,7 +2137,7 @@ protected override void OnStatementBegin(int index)
2140
2137
private PayloadData m_setNamesPayload ;
2141
2138
private byte [ ] ? m_pipelinedResetConnectionBytes ;
2142
2139
private Dictionary < string , PreparedStatements > ? m_preparedStatements ;
2143
- private string m_pluginName = "mysql_native_password" ;
2140
+ private string ? m_currentAuthenticationMethod ;
2144
2141
private byte [ ] ? m_remoteCertificateSha2Thumbprint ;
2145
2142
private SslPolicyErrors m_sslPolicyErrors ;
2146
2143
}
0 commit comments