Skip to content

Commit

Permalink
Added extra Unix-specific exceptions
Browse files Browse the repository at this point in the history
Converting more unusually-embedded PFX files into embedded resources
  • Loading branch information
edwardneal committed Nov 19, 2024
1 parent d932272 commit c199ddd
Show file tree
Hide file tree
Showing 14 changed files with 369 additions and 29 deletions.
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 @@ -1856,6 +1886,7 @@ internal static Exception InvalidCertificateLocation(string certificateLocation,
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
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);
Expand All @@ -1867,6 +1898,7 @@ internal static Exception InvalidCertificateLocation(string certificateLocation,
}
else
{
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);
Expand Down
52 changes: 48 additions & 4 deletions 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.

12 changes: 12 additions & 0 deletions src/Microsoft.Data.SqlClient/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4035,9 +4035,15 @@
<data name="TCE_NullCertificatePath" xml:space="preserve">
<value>Certificate path cannot be null. Use the following format: &lt;certificate location&gt;{2}&lt;certificate store&gt;{2}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is either '{0}' or '{1}'.</value>
</data>
<data name="TCE_NullCertificatePath_Unix" xml:space="preserve">
<value>Certificate path cannot be null. Use the following format: &lt;certificate location&gt;{1}&lt;certificate store&gt;{1}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is '{0}'.</value>
</data>
<data name="TCE_NullCertificatePathSysErr" xml:space="preserve">
<value>Internal error. Certificate path cannot be null. Use the following format: &lt;certificate location&gt;{2}&lt;certificate store&gt;{2}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is either '{0}' or '{1}'.</value>
</data>
<data name="TCE_NullCertificatePathSysErr_Unix" xml:space="preserve">
<value>Internal error. Certificate path cannot be null. Use the following format: &lt;certificate location&gt;{1}&lt;certificate store&gt;{1}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is '{0}'.</value>
</data>
<data name="TCE_NullCspPath" xml:space="preserve">
<value>Column master key path cannot be null. Use the following format for a key stored in a Microsoft cryptographic service provider (CSP): &lt;CSP Provider Name&gt;{0}&lt;Key Identifier&gt;.</value>
</data>
Expand All @@ -4053,9 +4059,15 @@
<data name="TCE_InvalidCertificatePath" xml:space="preserve">
<value>Invalid certificate path: '{0}'. Use the following format: &lt;certificate location&gt;{3}&lt;certificate store&gt;{3}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is either '{1}' or '{2}'.</value>
</data>
<data name="TCE_InvalidCertificatePath_Unix" xml:space="preserve">
<value>Invalid certificate path: '{0}'. Use the following format: &lt;certificate location&gt;{2}&lt;certificate store&gt;{2}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is '{1}'.</value>
</data>
<data name="TCE_InvalidCertificatePathSysErr" xml:space="preserve">
<value>Internal error. Invalid certificate path: '{0}'. Use the following format: &lt;certificate location&gt;{3}&lt;certificate store&gt;{3}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is either '{1}' or '{2}'.</value>
</data>
<data name="TCE_InvalidCertificatePathSysErr_Unix" xml:space="preserve">
<value>Internal error. Invalid certificate path: '{0}'. Use the following format: &lt;certificate location&gt;{2}&lt;certificate store&gt;{2}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is '{1}'.</value>
</data>
<data name="TCE_InvalidCspPath" xml:space="preserve">
<value>Invalid column master key path: '{0}'. Use the following format for a key stored in a Microsoft cryptographic service provider (CSP): &lt;CSP Provider Name&gt;{1}&lt;Key Identifier&gt;.</value>
</data>
Expand Down
Loading

0 comments on commit c199ddd

Please sign in to comment.