Skip to content
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

Cross-platform SqlColumnEncryptionCertificateStoreProvider support #3014

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ steps:
TestResults/*.trx
TestResults/**/*.coverage
testRunTitle: 'Linux Tests'
condition: succeededOrFailed()

- powershell: |
cd TestResults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlCollation.cs">
<Link>Microsoft\Data\SqlClient\SqlCollation.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.cs">
<Link>Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlColumnEncryptionEnclaveProvider.cs">
<Link>Microsoft\Data\SqlClient\SqlColumnEncryptionEnclaveProvider.cs</Link>
</Compile>
Expand Down Expand Up @@ -779,9 +782,6 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs">
<Link>Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.Windows.cs">
<Link>Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.Windows.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserSafeHandles.Windows.cs">
<Link>Microsoft\Data\SqlClient\TdsParserSafeHandles.Windows.cs</Link>
</Compile>
Expand Down Expand Up @@ -815,7 +815,6 @@
<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SessionHandle.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCngProvider.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCspProvider.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlFileStream.Unsupported.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlCollation.cs">
<Link>Microsoft\Data\SqlClient\SqlCollation.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.Windows.cs">
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.cs">
<Link>Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlColumnEncryptionCngProvider.Windows.cs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ private void ValidateCertificatePathLength(string masterKeyPath, bool isSystemOp
/// </summary>
private string[] GetValidCertificateLocations()
{
return new string[2] { CertLocationLocalMachine, CertLocationCurrentUser };
return Environment.OSVersion.Platform == PlatformID.Win32NT
? new string[2] { CertLocationLocalMachine, CertLocationCurrentUser }
: new string[1] { CertLocationCurrentUser };
}

/// <summary>
Expand Down Expand Up @@ -372,7 +374,8 @@ private X509Certificate2 GetCertificateByPath(string keyPath, bool isSystemOp)
// Extract the store location where the cert is stored
if (certParts.Length > 2)
{
if (string.Equals(certParts[0], CertLocationLocalMachine, StringComparison.OrdinalIgnoreCase) == true)
if (string.Equals(certParts[0], CertLocationLocalMachine, StringComparison.OrdinalIgnoreCase) == true
&& Environment.OSVersion.Platform == PlatformID.Win32NT)
{
storeLocation = StoreLocation.LocalMachine;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1696,14 +1696,29 @@ internal static Exception LargeCertificatePathLength(int actualLength, int maxLe

internal static Exception NullCertificatePath(string[] validLocations, bool isSystemOp)
{
Debug.Assert(2 == validLocations.Length);
if (isSystemOp)
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
return ADP.ArgumentNull(TdsEnums.TCE_PARAM_MASTERKEY_PATH, StringsHelper.GetString(Strings.TCE_NullCertificatePathSysErr, validLocations[0], validLocations[1], @"/"));
Debug.Assert(validLocations.Length == 2);
if (isSystemOp)
{
return ADP.ArgumentNull(TdsEnums.TCE_PARAM_MASTERKEY_PATH, StringsHelper.GetString(Strings.TCE_NullCertificatePathSysErr, validLocations[0], validLocations[1], @"/"));
}
else
{
return ADP.ArgumentNull(TdsEnums.TCE_PARAM_MASTERKEY_PATH, StringsHelper.GetString(Strings.TCE_NullCertificatePath, validLocations[0], validLocations[1], @"/"));
}
}
else
{
return ADP.ArgumentNull(TdsEnums.TCE_PARAM_MASTERKEY_PATH, StringsHelper.GetString(Strings.TCE_NullCertificatePath, validLocations[0], validLocations[1], @"/"));
Debug.Assert(validLocations.Length == 1);
if (isSystemOp)
{
return ADP.ArgumentNull(TdsEnums.TCE_PARAM_MASTERKEY_PATH, StringsHelper.GetString(Strings.TCE_NullCertificatePathSysErr_Unix, validLocations[0], @"/"));
}
else
{
return ADP.ArgumentNull(TdsEnums.TCE_PARAM_MASTERKEY_PATH, StringsHelper.GetString(Strings.TCE_NullCertificatePath_Unix, validLocations[0], @"/"));
}
}
}

Expand Down Expand Up @@ -1733,14 +1748,29 @@ internal static Exception NullCngKeyPath(bool isSystemOp)

internal static Exception InvalidCertificatePath(string actualCertificatePath, string[] validLocations, bool isSystemOp)
{
Debug.Assert(2 == validLocations.Length);
if (isSystemOp)
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificatePathSysErr, actualCertificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
Debug.Assert(validLocations.Length == 2);
if (isSystemOp)
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificatePathSysErr, actualCertificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
}
else
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificatePath, actualCertificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
}
}
else
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificatePath, actualCertificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
Debug.Assert(validLocations.Length == 1);
if (isSystemOp)
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificatePathSysErr_Unix, actualCertificatePath, validLocations[0], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
}
else
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificatePath_Unix, actualCertificatePath, validLocations[0], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
}
}
}

Expand Down Expand Up @@ -1854,17 +1884,29 @@ internal static Exception InvalidCngKey(string masterKeyPath, string cngProvider

internal static Exception InvalidCertificateLocation(string certificateLocation, string certificatePath, string[] validLocations, bool isSystemOp)
{

#if NETFRAMEWORK
Debug.Assert(2 == validLocations.Length);
#endif
if (isSystemOp)
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocationSysErr, certificateLocation, certificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
Debug.Assert(validLocations.Length == 2);
if (isSystemOp)
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocationSysErr, certificateLocation, certificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
}
else
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocation, certificateLocation, certificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
}
}
else
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocation, certificateLocation, certificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
Debug.Assert(validLocations.Length == 1);
if (isSystemOp)
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocationSysErr_Unix, certificateLocation, certificatePath, validLocations[0], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
}
else
{
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocation_Unix, certificateLocation, certificatePath, validLocations[0], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
}
}
}

Expand Down
Loading
Loading