Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
rel/1.0.0: Fix ECDsa ExportParameters segfault (#24458)
Browse files Browse the repository at this point in the history
* Fix ECDsa ExportParameters segfault

ECDSa.Export(Explicit)Parameters(includePrivateParameters:true) on an EC object containing only a public key will currently segfault on Linux. It is supposed to throw a CryptographicException, so this commit changes it to do so.

* Update packaging for native package

* Temporarily remove new ecdsa tests

* Update baseine crypto native package

* Update stable crypto native package to correct version

* Update managed crypto ecdsa packages

* Remote Openssl crypto suppress validation

* Update openssl ref version
  • Loading branch information
Ian Hays committed Oct 10, 2017
1 parent d4e9cb7 commit 686812c
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Packaging.props
Expand Up @@ -16,7 +16,7 @@
<XmlDocFileRoot>$(PackagesDir)Microsoft.Private.Intellisense/1.0.0-rc4-24206-00/xmldocs</XmlDocFileRoot>
<!-- We're currently not building a "live" baseline, instead we're using .NETCore 1.0 RTM stable versions as the baseline -->
<SkipBaseLineCheck>true</SkipBaseLineCheck>
<LineupPackageVersion Condition="'$(LineupPackageVersion)' == ''">1.0.4</LineupPackageVersion>
<LineupPackageVersion Condition="'$(LineupPackageVersion)' == ''">1.0.5</LineupPackageVersion>
<PlatformPackageVersion Condition="'$(PlatformPackageVersion)' == ''">1.0.2</PlatformPackageVersion>
</PropertyGroup>

Expand Down
Expand Up @@ -421,7 +421,7 @@
<Version>4.0.1</Version>
</BaseLinePackage>
<BaseLinePackage Include="runtime.native.System.Security.Cryptography">
<Version>4.0.2</Version>
<Version>4.0.3</Version>
</BaseLinePackage>
<BaseLinePackage Include="System.Private.DataContractSerialization">
<Version>4.1.2</Version>
Expand Down
Expand Up @@ -1424,7 +1424,7 @@
<Version>1.0.3</Version>
</StablePackage>
<StablePackage Include="runtime.native.System.Security.Cryptography">
<Version>4.0.3</Version>
<Version>4.0.2</Version>
</StablePackage>
<StablePackage Include="runtime.opensuse.13.2-x64.runtime.native.System.Security.Cryptography">
<Version>1.0.3</Version>
Expand Down
Expand Up @@ -97,7 +97,7 @@ internal static SafeEcKeyHandle EcKeyCreateByExplicitCurve(ECCurve curve)


[DllImport(Libraries.CryptoNative)]
private static extern bool CryptoNative_GetECKeyParameters(
private static extern int CryptoNative_GetECKeyParameters(
SafeEcKeyHandle key,
bool includePrivate,
out SafeBignumHandle qx_bn, out int x_cb,
Expand All @@ -117,12 +117,18 @@ internal static SafeEcKeyHandle EcKeyCreateByExplicitCurve(ECCurve curve)
try
{
key.DangerousAddRef(ref refAdded); // Protect access to d_bn_not_owned
if (!CryptoNative_GetECKeyParameters(
int rc = CryptoNative_GetECKeyParameters(
key,
includePrivate,
out qx_bn, out qx_cb,
out qy_bn, out qy_cb,
out d_bn_not_owned, out d_cb))
out d_bn_not_owned, out d_cb);

if (rc == -1)
{
throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey);
}
else if (rc != 1)
{
throw Interop.Crypto.CreateOpenSslCryptographicException();
}
Expand Down Expand Up @@ -152,7 +158,7 @@ internal static SafeEcKeyHandle EcKeyCreateByExplicitCurve(ECCurve curve)
}

[DllImport(Libraries.CryptoNative)]
private static extern bool CryptoNative_GetECCurveParameters(
private static extern int CryptoNative_GetECCurveParameters(
SafeEcKeyHandle key,
bool includePrivate,
out ECCurve.ECCurveType curveType,
Expand Down Expand Up @@ -181,7 +187,7 @@ internal static SafeEcKeyHandle EcKeyCreateByExplicitCurve(ECCurve curve)
try
{
key.DangerousAddRef(ref refAdded); // Protect access to d_bn_not_owned
if (!CryptoNative_GetECCurveParameters(
int rc = CryptoNative_GetECCurveParameters(
key,
includePrivate,
out curveType,
Expand All @@ -195,7 +201,13 @@ internal static SafeEcKeyHandle EcKeyCreateByExplicitCurve(ECCurve curve)
out gy_bn, out gy_cb,
out order_bn, out order_cb,
out cofactor_bn, out cofactor_cb,
out seed_bn, out seed_cb))
out seed_bn, out seed_cb);

if (rc == -1)
{
throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey);
}
else if (rc != 1)
{
throw Interop.Crypto.CreateOpenSslCryptographicException();
}
Expand Down
Expand Up @@ -111,8 +111,17 @@ extern "C" int32_t CryptoNative_GetECKeyParameters(

if (includePrivate)
{
*d = const_cast<BIGNUM*>(EC_KEY_get0_private_key(key));
*cbD = BN_num_bytes(*d);
const BIGNUM* const_bignum_privateKey = EC_KEY_get0_private_key(key);
if (const_bignum_privateKey != nullptr)
{
*d = const_cast<BIGNUM*>(const_bignum_privateKey);
*cbD = BN_num_bytes(*d);
}
else
{
rc = -1;
goto error;
}
}
else
{
Expand Down
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<PackageTargetRuntime>debian.8-$(PackagePlatform)</PackageTargetRuntime>
<!-- only build for x64 -->
<PackagePlatforms>x64;</PackagePlatforms>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<PackageTargetRuntime>fedora.23-$(PackagePlatform)</PackageTargetRuntime>
<!-- only build for x64 -->
<PackagePlatforms>x64;</PackagePlatforms>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<PackageTargetRuntime>opensuse.13.2-$(PackagePlatform)</PackageTargetRuntime>
<!-- only build for x64 -->
<PackagePlatforms>x64;</PackagePlatforms>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<PackageTargetRuntime>osx.10.10-$(PackagePlatform)</PackageTargetRuntime>
<!-- only build for x64 -->
<PackagePlatforms>x64;</PackagePlatforms>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<PackageTargetRuntime>rhel.7-$(PackagePlatform)</PackageTargetRuntime>
<!-- only build for x64 -->
<PackagePlatforms>x64;</PackagePlatforms>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>4.0.2</Version>
<Version>4.0.3</Version>
<SkipPackageFileCheck>true</SkipPackageFileCheck>
<SkipValidatePackage>true</SkipValidatePackage>
</PropertyGroup>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<PackageTargetRuntime>ubuntu.14.04-$(PackagePlatform)</PackageTargetRuntime>
<!-- only build for x64 -->
<PackagePlatforms>x64;</PackagePlatforms>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<PackageTargetRuntime>ubuntu.16.04-$(PackagePlatform)</PackageTargetRuntime>
<!-- only build for x64 -->
<PackagePlatforms>x64;</PackagePlatforms>
Expand Down
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Version>4.2.1</Version>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ref\4.0\System.Security.Cryptography.Algorithms.csproj">
<SupportedFramework>net46</SupportedFramework>
Expand Down
@@ -0,0 +1,6 @@
// The netfx facades have their versions locked, but we should
// permit the netcoreapp implementations to use a higher runtime assembly
// version than the ref assembly.
// The refs shouldn't get bumped because that could push the 1.0 assembly to
// a higher version than the 1.1 assembly.
PermitHigherCompatibleImplementationVersion
Expand Up @@ -10,9 +10,10 @@
<ProjectGuid>{81A05E2E-E3AE-4246-B4E6-DD5F31FB71F9}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>System.Security.Cryptography.Algorithms</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.1</AssemblyVersion>
<AssemblyVersion Condition="'$(TargetGroup)'=='net46'">4.0.0.0</AssemblyVersion>
<AssemblyVersion Condition="'$(TargetGroup)'=='net461' or '$(TargetGroup)' == 'netcore50'">4.1.0.0</AssemblyVersion>
<AssemblyVersion Condition="'$(TargetGroup)'=='net463'">4.2.0.0</AssemblyVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLSCompliant>false</CLSCompliant>
<DefineConstants>INTERNAL_ASYMMETRIC_IMPLEMENTATIONS</DefineConstants>
Expand Down
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />

<PropertyGroup>
<Version>4.0.1</Version>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ref\System.Security.Cryptography.OpenSsl.csproj">
<SupportedFramework>net463;netcoreapp1.0</SupportedFramework>
Expand Down
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.1</AssemblyVersion>
<OutputType>Library</OutputType>
<PackageTargetFramework>netstandard1.6</PackageTargetFramework>
<NuGetTargetMoniker>.NETStandard,Version=v1.6</NuGetTargetMoniker>
Expand Down
Expand Up @@ -8,7 +8,7 @@
<ProjectGuid>{78452F3E-BA91-47E7-BB0F-02E8A5C116C4}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>System.Security.Cryptography.OpenSsl</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.1</AssemblyVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLSCompliant>false</CLSCompliant>
<PackageTargetFramework>netstandard1.6</PackageTargetFramework>
Expand Down
15 changes: 14 additions & 1 deletion src/packages.builds
Expand Up @@ -27,11 +27,24 @@
<AdditionalProperties>$(AdditionalProperties)</AdditionalProperties>
</Project>
<!-- add specific builds / pkgproj's here to include in servicing builds -->
<Project Include="..\pkg\Microsoft.NETCore.Targets\Microsoft.NETCore.Targets.builds">
<AdditionalProperties>$(AdditionalProperties)</AdditionalProperties>
</Project>
<Project Include="System.Security.Cryptography.Algorithms\pkg\System.Security.Cryptography.Algorithms.builds">
<AdditionalProperties>$(AdditionalProperties)</AdditionalProperties>
</Project>
<Project Include="System.Security.Cryptography.OpenSsl\pkg\System.Security.Cryptography.OpenSsl.builds">
<AdditionalProperties>$(AdditionalProperties)</AdditionalProperties>
</Project>
</ItemGroup>

<ItemGroup Condition="'$(BuildAllPackages)' == 'false' AND '$(SkipNativePackageBuild)' != 'true'" >
<!-- add specific native builds / pkgproj's here to include in servicing builds -->
</ItemGroup>
<Project Include="Native\pkg\runtime.native.System.Security.Cryptography\runtime.native.System.Security.Cryptography.builds">
<AdditionalProperties>$(AdditionalProperties);SkipCreatePackageOnMissingFiles=true</AdditionalProperties>
<BuildAllOSGroups>$(BuildAllOSGroups)</BuildAllOSGroups>
</Project>
</ItemGroup>

<UsingTask TaskName="GenerateNetStandardSupportTable" AssemblyFile="$(PackagingTaskDir)Microsoft.DotNet.Build.Tasks.Packaging.dll" />
<Target Name="GenerateNETStandardDocs">
Expand Down

0 comments on commit 686812c

Please sign in to comment.