@@ -528,7 +528,7 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
528
528
}
529
529
530
530
var ok = OkPayload . Create ( payload . Span , this ) ;
531
- if ( m_rcbPolicyErrors != SslPolicyErrors . None )
531
+ if ( m_sslPolicyErrors != SslPolicyErrors . None )
532
532
{
533
533
// SSL would normally have thrown error, so connector need to ensure server certificates
534
534
// pass only if :
@@ -538,29 +538,15 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
538
538
{
539
539
if ( string . IsNullOrEmpty ( password ) || ! ValidateFingerprint ( ok . StatusInfo , initialHandshake . AuthPluginData . AsSpan ( 0 , 20 ) , password ! ) )
540
540
{
541
- // fingerprint validation fail.
542
- // now throwing SSL exception depending on m_rcbPolicyErrors
543
541
ShutdownSocket ( ) ;
544
542
HostName = "" ;
545
- lock ( m_lock ) m_state = State . Failed ;
546
- MySqlException ex ;
547
- switch ( m_rcbPolicyErrors )
548
- {
549
- case SslPolicyErrors . RemoteCertificateNotAvailable :
550
- // impossible
551
- ex = new MySqlException ( MySqlErrorCode . UnableToConnectToHost , "SSL not validated, no remote certificate available" ) ;
552
- break ;
553
-
554
- case SslPolicyErrors . RemoteCertificateNameMismatch :
555
- ex = new MySqlException ( MySqlErrorCode . UnableToConnectToHost , "SSL not validated, certificate name mismatch" ) ;
556
- break ;
557
-
558
- default :
559
- ex = new MySqlException ( MySqlErrorCode . UnableToConnectToHost , "SSL not validated, certificate chain validation fail" ) ;
560
- break ;
561
- }
562
- Log . CouldNotInitializeTlsConnection ( m_logger , ex , Id ) ;
563
- throw ex ;
543
+ lock ( m_lock )
544
+ m_state = State . Failed ;
545
+
546
+ // throw a MySqlException with an AuthenticationException InnerException to mimic what would have happened if ValidateRemoteCertificate returned false
547
+ var innerException = new AuthenticationException ( $ "The remote certificate was rejected due to the following error: { m_sslPolicyErrors } ") ;
548
+ Log . CouldNotInitializeTlsConnection ( m_logger , innerException , Id ) ;
549
+ throw new MySqlException ( MySqlErrorCode . UnableToConnectToHost , "SSL Authentication Error" , innerException ) ;
564
550
}
565
551
}
566
552
}
@@ -1601,7 +1587,7 @@ caCertificateChain is not null &&
1601
1587
using var sha256 = SHA256 . Create ( ) ;
1602
1588
m_remoteCertificateSha2Thumbprint = sha256 . ComputeHash ( cert2 . RawData ) ;
1603
1589
#endif
1604
- m_rcbPolicyErrors = rcbPolicyErrors ;
1590
+ m_sslPolicyErrors = rcbPolicyErrors ;
1605
1591
return true ;
1606
1592
}
1607
1593
@@ -2128,5 +2114,5 @@ protected override void OnStatementBegin(int index)
2128
2114
private Dictionary < string , PreparedStatements > ? m_preparedStatements ;
2129
2115
private string m_pluginName = "mysql_native_password" ;
2130
2116
private byte [ ] ? m_remoteCertificateSha2Thumbprint ;
2131
- private SslPolicyErrors m_rcbPolicyErrors ;
2117
+ private SslPolicyErrors m_sslPolicyErrors ;
2132
2118
}
0 commit comments