-
Couldn't load subscription status.
- Fork 316
Fix | Enhance certificate validation #2487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DavoudEshtehari
merged 14 commits into
dotnet:main
from
arellegue:EnhancedCertificateValidation
May 30, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b8f8a18
Initial commit after porting changes from FixedCertificateValidation …
arellegue eaeeaea
Store the client certificate it its own folder.
arellegue 25baada
Removed unnecessary changes in TDSServerParser.cs.
arellegue d550fe6
Resolved conflict.
arellegue c12dcd7
Updated NET7_0_OR_GREATER to NET8_0_OR_GREATER.
arellegue acb26a1
Applied suggested changes from review.
arellegue 5c02e93
Update removecert.ps1 date.
arellegue 8f85d45
Put initial value of s_sQLServerVersion back to string.Empty.
arellegue d0b453a
Set s_sQLServerVersion initial value to null again but fix the functi…
arellegue 74affa3
Revert changes to DataTestUtility.
arellegue d493004
Removed ForceEncryptionRegistryPath.
arellegue 2c5257d
Use ConditionalTheory to prevent running certificate validation test …
arellegue 79cc245
Update removecert.ps1 script comment.
arellegue 64178f5
Added instance name prefix so can get instance name service.
arellegue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
256 changes: 107 additions & 149 deletions
256
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/ConnectionTestParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.SqlServer.TDS.PreLogin; | ||
|
|
||
| namespace Microsoft.Data.SqlClient.ManualTesting.Tests.DataCommon | ||
| { | ||
| public class ConnectionTestParameters | ||
| { | ||
| private SqlConnectionEncryptOption _encryptionOption; | ||
| private TDSPreLoginTokenEncryptionType _encryptionType; | ||
| private string _hnic; | ||
| private string _cert; | ||
| private bool _result; | ||
| private bool _trustServerCert; | ||
|
|
||
| public SqlConnectionEncryptOption Encrypt => _encryptionOption; | ||
| public bool TrustServerCertificate => _trustServerCert; | ||
| public string Certificate => _cert; | ||
| public string HostNameInCertificate => _hnic; | ||
| public bool TestResult => _result; | ||
| public TDSPreLoginTokenEncryptionType TdsEncryptionType => _encryptionType; | ||
|
|
||
| public ConnectionTestParameters(TDSPreLoginTokenEncryptionType tdsEncryptionType, SqlConnectionEncryptOption encryptOption, bool trustServerCert, string cert, string hnic, bool result) | ||
| { | ||
| _encryptionOption = encryptOption; | ||
| _trustServerCert = trustServerCert; | ||
| _cert = cert; | ||
| _hnic = hnic; | ||
| _result = result; | ||
| _encryptionType = tdsEncryptionType; | ||
| } | ||
| } | ||
| } | ||
85 changes: 85 additions & 0 deletions
85
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/ConnectionTestParametersData.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using Microsoft.SqlServer.TDS.PreLogin; | ||
|
|
||
| namespace Microsoft.Data.SqlClient.ManualTesting.Tests.DataCommon | ||
| { | ||
| public class ConnectionTestParametersData | ||
| { | ||
| private const int CASES = 30; | ||
| private string _empty = string.Empty; | ||
| // It was advised to store the client certificate in its own folder. | ||
| private static readonly string s_fullPathToCer = Path.Combine(Directory.GetCurrentDirectory(), "clientcert", "localhostcert.cer"); | ||
| private static readonly string s_mismatchedcert = Path.Combine(Directory.GetCurrentDirectory(), "clientcert", "mismatchedcert.cer"); | ||
|
|
||
| private static readonly string s_hostName = System.Net.Dns.GetHostName(); | ||
| public static ConnectionTestParametersData Data { get; } = new ConnectionTestParametersData(); | ||
| public List<ConnectionTestParameters> ConnectionTestParametersList { get; set; } | ||
|
|
||
| public static IEnumerable<object[]> GetConnectionTestParameters() | ||
| { | ||
| for (int i = 0; i < CASES; i++) | ||
| { | ||
| yield return new object[] { Data.ConnectionTestParametersList[i] }; | ||
| } | ||
| } | ||
|
|
||
| public ConnectionTestParametersData() | ||
| { | ||
| // Test cases possible field values for connection parameters: | ||
| // These combinations are based on the possible values of Encrypt, TrustServerCertificate, Certificate, HostNameInCertificate | ||
arellegue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /* | ||
| * TDSEncryption | Encrypt | TrustServerCertificate | Certificate | HNIC | TestResults | ||
| * ---------------------------------------------------------------------------------------------- | ||
| * Off | Optional | true | valid | valid name | true | ||
| * On | Mandatory | false | mismatched | empty | false | ||
| * Required | | x | ChainError? | wrong name? | | ||
| */ | ||
| ConnectionTestParametersList = new List<ConnectionTestParameters> | ||
| { | ||
| // TDSPreLoginTokenEncryptionType.Off | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Optional, false, _empty, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, false, _empty, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Optional, true, _empty, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, _empty, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, false, s_fullPathToCer, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, s_fullPathToCer, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, false, _empty, s_hostName, false), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, _empty, s_hostName, true), | ||
|
|
||
| // TDSPreLoginTokenEncryptionType.On | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Optional, false, _empty, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, false, _empty, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Optional, true, _empty, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, true, _empty, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, false, s_fullPathToCer, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, true, s_fullPathToCer, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, false, _empty, s_hostName, false), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, true, _empty, s_hostName, true), | ||
|
|
||
| // TDSPreLoginTokenEncryptionType.Required | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Optional, false, _empty, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, false, _empty, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Optional, true, _empty, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, true, _empty, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, false, s_fullPathToCer, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, true, s_fullPathToCer, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, false, _empty, s_hostName, false), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, true, _empty, s_hostName, true), | ||
|
|
||
| // Mismatched certificate test | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, false, s_mismatchedcert, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, s_mismatchedcert, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, s_mismatchedcert, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, false, s_mismatchedcert, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, true, s_mismatchedcert, _empty, true), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, false, s_mismatchedcert, _empty, false), | ||
| new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, true, s_mismatchedcert, _empty, true), | ||
| }; | ||
| } | ||
| } | ||
| } | ||
arellegue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.