Skip to content

Commit 6facb43

Browse files
Perform Certificate Validation when Force Encryption enabled on Server (NetFx) (#482)
1 parent d23c644 commit 6facb43

File tree

1 file changed

+2
-4
lines changed
  • src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient

1 file changed

+2
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,8 @@ private PreLoginHandshakeStatus ConsumePreLoginHandshake(SqlAuthenticationMethod
11341134

11351135
UInt32 error = 0;
11361136

1137-
// If we're using legacy server certificate validation behavior (Authentication keyword not provided and not using access token), then validate if
1138-
// Encrypt=true and Trust Sever Certificate = false.
1139-
// If using Authentication keyword or access token, validate if Trust Server Certificate=false.
1140-
bool shouldValidateServerCert = (encrypt && !trustServerCert) || ((authType != SqlAuthenticationMethod.NotSpecified || _connHandler._accessTokenInBytes != null) && !trustServerCert);
1137+
// Validate Certificate if Trust Server Certificate=false and Encryption forced (EncryptionOptions.ON) from Server.
1138+
bool shouldValidateServerCert = (_encryptionOption == EncryptionOptions.ON && !trustServerCert) || ((authType != SqlAuthenticationMethod.NotSpecified || _connHandler._accessTokenInBytes != null) && !trustServerCert);
11411139

11421140
UInt32 info = (shouldValidateServerCert ? TdsEnums.SNI_SSL_VALIDATE_CERTIFICATE : 0)
11431141
| (isYukonOrLater && (_encryptionOption & EncryptionOptions.CLIENT_CERT) == 0 ? TdsEnums.SNI_SSL_USE_SCHANNEL_CACHE : 0);

0 commit comments

Comments
 (0)