@@ -231,6 +231,7 @@ public async Task ConnectAsync(ConnectionSettings cs, IOBehavior ioBehavior, Can
231
231
if ( ! serverSupportsSsl )
232
232
throw new MySqlException ( "Server does not support SSL" ) ;
233
233
await InitSslAsync ( initialHandshake . ProtocolCapabilities , cs , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
234
+ cs = cs . WithSecureConnection ( true ) ;
234
235
}
235
236
236
237
var response = HandshakeResponse41Packet . Create ( initialHandshake , cs ) ;
@@ -286,12 +287,25 @@ private async Task SwitchAuthenticationAsync(PayloadData payload, ConnectionSett
286
287
{
287
288
// if the server didn't support the hashed password; rehash with the new challenge
288
289
var switchRequest = AuthenticationMethodSwitchRequestPayload . Create ( payload ) ;
289
- if ( switchRequest . Name != "mysql_native_password" )
290
+ switch ( switchRequest . Name )
291
+ {
292
+ case "mysql_native_password" :
293
+ AuthPluginData = switchRequest . Data ;
294
+ var hashedPassword = AuthenticationUtility . CreateAuthenticationResponse ( AuthPluginData , 0 , cs . Password ) ;
295
+ payload = new PayloadData ( new ArraySegment < byte > ( hashedPassword ) ) ;
296
+ await SendReplyAsync ( payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
297
+ break ;
298
+
299
+ case "mysql_clear_password" :
300
+ if ( ! cs . IsSecureConnection )
301
+ throw new MySqlException ( "Authentication method '{0}' requires a secure connection." . FormatInvariant ( switchRequest . Name ) ) ;
302
+ payload = new PayloadData ( new ArraySegment < byte > ( Encoding . UTF8 . GetBytes ( cs . Password ) ) ) ;
303
+ await SendReplyAsync ( payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
304
+ break ;
305
+
306
+ default :
290
307
throw new NotSupportedException ( "Authentication method '{0}' is not supported." . FormatInvariant ( switchRequest . Name ) ) ;
291
- AuthPluginData = switchRequest . Data ;
292
- var hashedPassword = AuthenticationUtility . CreateAuthenticationResponse ( AuthPluginData , 0 , cs . Password ) ;
293
- payload = new PayloadData ( new ArraySegment < byte > ( hashedPassword ) ) ;
294
- await SendReplyAsync ( payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
308
+ }
295
309
}
296
310
297
311
public async Task < bool > TryPingAsync ( IOBehavior ioBehavior , CancellationToken cancellationToken )
0 commit comments