Skip to content

Commit a735ee4

Browse files
Perform Certificate Validation when Force Encryption enabled on Server (#391)
1 parent 31c2365 commit a735ee4

File tree

1 file changed

+3
-3
lines changed
  • src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient

1 file changed

+3
-3
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ private PreLoginHandshakeStatus ConsumePreLoginHandshake(bool encrypt, bool trus
824824
_encryptionOption == EncryptionOptions.LOGIN)
825825
{
826826
uint error = 0;
827-
// If we're using legacy server certificate validation behavior (not using access token), then validate if Encrypt=true and Trust Sever Certificate = false.
828-
// If using access token, validate if Trust Server Certificate=false.
829-
bool shouldValidateServerCert = (encrypt && !trustServerCert) || (_connHandler._accessTokenInBytes != null && !trustServerCert);
827+
828+
// Validate Certificate if Trust Server Certificate=false and Encryption forced (EncryptionOptions.ON) from Server.
829+
bool shouldValidateServerCert = (_encryptionOption == EncryptionOptions.ON && !trustServerCert) || (_connHandler._accessTokenInBytes != null && !trustServerCert);
830830
uint info = (shouldValidateServerCert ? TdsEnums.SNI_SSL_VALIDATE_CERTIFICATE : 0)
831831
| (isYukonOrLater ? TdsEnums.SNI_SSL_USE_SCHANNEL_CACHE : 0);
832832

0 commit comments

Comments
 (0)