Skip to content

Commit

Permalink
Dead end S.Security.Cryptography.Cng package
Browse files Browse the repository at this point in the history
To reduce complexity of the cryptography cng library, dead ending its
package as most of the configurations are partial facades anyway and
adding Cng to the targeting pack. It's already part of the runtime and
exposed in aspnetcore's targeting pack.

.NET Standard libraries can continue to use the latest available package
which harvests for .NET Standard configurations.

Contributes to dotnet#47530
  • Loading branch information
ViktorHofer committed Apr 26, 2021
1 parent 207b03a commit c25b78d
Show file tree
Hide file tree
Showing 17 changed files with 9 additions and 159 deletions.
1 change: 0 additions & 1 deletion src/libraries/NetCoreAppLibrary.props
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
System.IO.FileSystem.AccessControl;
System.IO.Pipes.AccessControl;
System.Security.AccessControl;
System.Security.Cryptography.Cng;
System.Security.Cryptography.OpenSsl;
System.Security.Principal.Windows;
</NetCoreAppLibraryNoReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,5 @@
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides cryptographic algorithm implementations and key management with Windows Cryptographic Next Generation API (CNG).

Commonly Used Types:
System.Security.Cryptography.RSACng
System.Security.Cryptography.ECDsaCng
System.Security.Cryptography.CngKey</PackageDescription>
</PropertyGroup>
</Project>
12 changes: 0 additions & 12 deletions src/libraries/System.Security.Cryptography.Cng/NuGet.config

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,8 @@ public DSACng(System.Security.Cryptography.CngKey key) { }
public override byte[] CreateSignature(byte[] rgbHash) { throw null; }
protected override void Dispose(bool disposing) { }
public override System.Security.Cryptography.DSAParameters ExportParameters(bool includePrivateParameters) { throw null; }
#if FEATURE_DSA_HASHDATA
protected override byte[] HashData(byte[] data, int offset, int count, System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { throw null; }
protected override byte[] HashData(System.IO.Stream data, System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { throw null; }
#endif
public override void ImportParameters(System.Security.Cryptography.DSAParameters parameters) { }
public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature) { throw null; }
}
Expand All @@ -278,9 +276,7 @@ public sealed partial class ECDiffieHellmanCng : System.Security.Cryptography.EC
public ECDiffieHellmanCng() { }
public ECDiffieHellmanCng(int keySize) { }
public ECDiffieHellmanCng(System.Security.Cryptography.CngKey key) { }
#if FEATURE_ECPARAMETERS
public ECDiffieHellmanCng(System.Security.Cryptography.ECCurve curve) { }
#endif
public System.Security.Cryptography.CngAlgorithm HashAlgorithm { get { throw null; } set { } }
public byte[]? HmacKey { get { throw null; } set { } }
public System.Security.Cryptography.CngKey Key { get { throw null; } }
Expand All @@ -292,27 +288,19 @@ public ECDiffieHellmanCng(System.Security.Cryptography.ECCurve curve) { }
public byte[]? SecretPrepend { get { throw null; } set { } }
public byte[]? Seed { get { throw null; } set { } }
public bool UseSecretAgreementAsHmacKey { get { throw null; } }
#if FEATURE_ECDH_DERIVEFROM
public override byte[] DeriveKeyFromHash(System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[]? secretPrepend, byte[]? secretAppend) { throw null; }
public override byte[] DeriveKeyFromHmac(System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[]? hmacKey, byte[]? secretPrepend, byte[]? secretAppend) { throw null; }
#endif
public byte[] DeriveKeyMaterial(System.Security.Cryptography.CngKey otherPartyPublicKey) { throw null; }
public override byte[] DeriveKeyMaterial(System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey) { throw null; }
#if FEATURE_ECDH_DERIVEFROM
public override byte[] DeriveKeyTls(System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed) { throw null; }
#endif
public Microsoft.Win32.SafeHandles.SafeNCryptSecretHandle DeriveSecretAgreementHandle(System.Security.Cryptography.CngKey otherPartyPublicKey) { throw null; }
public Microsoft.Win32.SafeHandles.SafeNCryptSecretHandle DeriveSecretAgreementHandle(System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey) { throw null; }
protected override void Dispose(bool disposing) { }
#if FEATURE_ECPARAMETERS
public override System.Security.Cryptography.ECParameters ExportExplicitParameters(bool includePrivateParameters) { throw null; }
public override System.Security.Cryptography.ECParameters ExportParameters(bool includePrivateParameters) { throw null; }
#endif
public void FromXmlString(string xml, System.Security.Cryptography.ECKeyXmlFormat format) { }
#if FEATURE_ECPARAMETERS
public override void GenerateKey(System.Security.Cryptography.ECCurve curve) { }
public override void ImportParameters(System.Security.Cryptography.ECParameters parameters) { }
#endif
public string ToXmlString(System.Security.Cryptography.ECKeyXmlFormat format) { throw null; }
}
public sealed partial class ECDiffieHellmanCngPublicKey : System.Security.Cryptography.ECDiffieHellmanPublicKey
Expand All @@ -321,10 +309,8 @@ public sealed partial class ECDiffieHellmanCngPublicKey : System.Security.Crypto
private ECDiffieHellmanCngPublicKey() : base(null) { }
public System.Security.Cryptography.CngKeyBlobFormat BlobFormat { get { throw null; } }
protected override void Dispose(bool disposing) { }
#if FEATURE_ECPARAMETERS
public override System.Security.Cryptography.ECParameters ExportExplicitParameters() { throw null; }
public override System.Security.Cryptography.ECParameters ExportParameters() { throw null; }
#endif
public static System.Security.Cryptography.ECDiffieHellmanPublicKey FromByteArray(byte[] publicKeyBlob, System.Security.Cryptography.CngKeyBlobFormat format) { throw null; }
public static System.Security.Cryptography.ECDiffieHellmanCngPublicKey FromXmlString(string xml) { throw null; }
public System.Security.Cryptography.CngKey Import() { throw null; }
Expand All @@ -341,27 +327,19 @@ public sealed partial class ECDsaCng : System.Security.Cryptography.ECDsa
public ECDsaCng() { }
public ECDsaCng(int keySize) { }
public ECDsaCng(System.Security.Cryptography.CngKey key) { }
#if FEATURE_ECPARAMETERS // types missing from .NET Framework and net462 targeting pack
public ECDsaCng(System.Security.Cryptography.ECCurve curve) { }
#endif
public System.Security.Cryptography.CngAlgorithm HashAlgorithm { get { throw null; } set { } }
public System.Security.Cryptography.CngKey Key { get { throw null; } }
public override int KeySize { get { throw null; } set { } }
public override System.Security.Cryptography.KeySizes[] LegalKeySizes { get { throw null; } }
protected override void Dispose(bool disposing) { }
#if FEATURE_ECPARAMETERS // types missing from .NET Framework and net462 targeting pack
public override System.Security.Cryptography.ECParameters ExportExplicitParameters(bool includePrivateParameters) { throw null; }
public override System.Security.Cryptography.ECParameters ExportParameters(bool includePrivateParameters) { throw null; }
#endif
public void FromXmlString(string xml, System.Security.Cryptography.ECKeyXmlFormat format) { }
#if FEATURE_ECPARAMETERS // types missing from .NET Framework and net462 targeting pack
public override void GenerateKey(System.Security.Cryptography.ECCurve curve) { }
#endif
protected override byte[] HashData(byte[] data, int offset, int count, System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { throw null; }
protected override byte[] HashData(System.IO.Stream data, System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { throw null; }
#if FEATURE_ECPARAMETERS // types missing from .NET Framework and net462 targeting pack
public override void ImportParameters(System.Security.Cryptography.ECParameters parameters) { }
#endif
public byte[] SignData(byte[] data) { throw null; }
public byte[] SignData(byte[] data, int offset, int count) { throw null; }
public byte[] SignData(System.IO.Stream data) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.0;netstandard2.1;net461;net462;net47</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<!-- FEATURE_DSA_HASHDATA is technically also available on net462+, but it doesn't require being enabled since it is a facade -->
<DefineConstants Condition="!$(TargetFramework.StartsWith('net4'))">$(DefineConstants);FEATURE_DSA_HASHDATA</DefineConstants>
<!-- FEATURE_ECDH_DERIVEFROM is technically also available on net462+, but it doesn't require being enabled since it is a facade -->
<DefineConstants Condition="!$(TargetFramework.StartsWith('net4'))">$(DefineConstants);FEATURE_ECDH_DERIVEFROM</DefineConstants>
<DefineConstants Condition="!$(TargetFramework.StartsWith('net46'))">$(DefineConstants);FEATURE_ECPARAMETERS</DefineConstants>
<IsPartialFacadeAssembly Condition="$(TargetFramework.StartsWith('net4'))">true</IsPartialFacadeAssembly>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Security.Cryptography.Cng.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\ref\System.Runtime.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Security.Cryptography.Algorithms\ref\System.Security.Cryptography.Algorithms.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Security.Cryptography.Primitives\ref\System.Security.Cryptography.Primitives.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<Reference Include="System.IO" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Handles" />
<Reference Include="System.Security.Cryptography.Algorithms" />
<Reference Include="System.Security.Cryptography.Primitives" />
</ItemGroup>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenFacadesIgnoreMissingTypes Condition="'$(TargetFramework)' == 'net461'">true</GenFacadesIgnoreMissingTypes>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);netstandard2.1;net461-windows;netcoreapp3.0-windows;netcoreapp3.0;net462-windows;net47-windows</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<IsPartialFacadeAssembly Condition="$(TargetFramework.StartsWith('net4'))">true</IsPartialFacadeAssembly>
<OmitResources Condition="$(TargetFramework.StartsWith('net4'))">true</OmitResources>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsWindows)' != 'true'">
<GeneratePlatformNotSupportedAssemblyMessage>SR.PlatformNotSupported_CryptographyCng</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1\AsnXml.targets" Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'" />
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1Reader\System.Security.Cryptography.Asn1Reader.Shared.projitems" Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'" />
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'">
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1\AsnXml.targets" Condition="'$(TargetsWindows)' == 'true'" />
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1Reader\System.Security.Cryptography.Asn1Reader.Shared.projitems" Condition="'$(TargetsWindows)' == 'true'" />
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="System\Security\Cryptography\AesCng.cs" />
<Compile Include="System\Security\Cryptography\CngAlgorithm.cs" />
<Compile Include="System\Security\Cryptography\CngAlgorithmGroup.cs" />
Expand Down Expand Up @@ -353,11 +347,8 @@
<ItemGroup>
<None Include="@(AsnXml)" />
</ItemGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true'">
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Formats.Asn1\src\System.Formats.Asn1.csproj" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('$(NetCoreAppCurrent)')) or
$(TargetFramework.StartsWith('netcoreapp3.0'))">
<Reference Include="System.Buffers" />
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Concurrent" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ public ECDiffieHellman Create(int keySize)
return new ECDiffieHellmanCng(keySize);
}

#if NETCOREAPP
public ECDiffieHellman Create(ECCurve curve)
{
return new ECDiffieHellmanCng(curve);
}
#endif

public bool IsCurveValid(Oid oid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ private static ECDiffieHellmanCng NewDefaultECDHCng()
return new ECDiffieHellmanCng();
}

#if NETCOREAPP
[Fact]
public static void ECCurve_ctor()
{
Expand All @@ -35,7 +34,6 @@ public static void ECCurve_ctor()
ecdh.Exercise();
}
}
#endif

[Fact]
public static void CngKey_ReusesObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static void TestImportExportRoundTrip()
}
}

#if NETCOREAPP
[ConditionalTheory(nameof(ECExplicitCurvesSupported)), MemberData(nameof(TestCurves))]
public static void TestHashRoundTrip(CurveDef curveDef)
{
Expand All @@ -69,6 +68,5 @@ public static void TestHashRoundTrip(CurveDef curveDef)
Assert.Equal(0xFF, param2.Curve.Seed[0]);
}
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ public ECDsa Create(int keySize)
return new ECDsaCng(keySize);
}

#if NETCOREAPP
public ECDsa Create(ECCurve curve)
{
return new ECDsaCng(curve);
}
#endif

public bool IsCurveValid(Oid oid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public static void HashAlgorithm_DefaultsToSha256()
Assert.Equal(CngAlgorithm.Sha256, cng.HashAlgorithm);
}

#if NETCOREAPP
[Fact]
public static void TestPositive256WithBlob()
{
Expand Down Expand Up @@ -211,7 +210,6 @@ public static void TestSpecialNistKeys(int keySize, string curveName, CngAlgorit
Assert.Equal(algorithm, cng.Key.Algorithm);
}
}
#endif

public static IEnumerable<object[]> SpecialNistKeys
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public static void HandleDuplication()
}
}

#if NETCOREAPP
[Fact]
public static void SafeNCryptKeyHandle_ParentHandle_Invalid()
{
Expand Down Expand Up @@ -173,6 +172,5 @@ protected override bool ReleaseHandle()

public override bool IsInvalid => !_isOpen;
}
#endif
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DefineConstants>$(DefineConstants);TESTING_CNG_IMPLEMENTATION</DefineConstants>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;net47-windows</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="CreateTests.cs" />
Expand Down Expand Up @@ -75,8 +75,6 @@
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\RSA\TestData.cs" />
<Compile Include="$(CommonTestPath)System\IO\PositionValueStream.cs"
Link="CommonTest\System\IO\PositionValueStream.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('$(NetCoreAppCurrent)'))">
<Compile Include="CngPkcs8Tests.cs" />
<Compile Include="DSACngPkcs8Tests.cs" />
<Compile Include="DSACngProvider.cs" />
Expand Down Expand Up @@ -170,7 +168,7 @@
<Compile Include="$(CommonTestPath)System\Security\Cryptography\AlgorithmImplementations\ECDiffieHellman\ECDiffieHellmanTests.Xml.cs"
Link="CommonTest\System\Security\Cryptography\AlgorithmImplementations\ECDiffieHellman\ECDiffieHellmanTests.Xml.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('$(NetCoreAppCurrent)'))">
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Security.Cryptography.Cng\src\System.Security.Cryptography.Cng.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Security.Principal.Windows\src\System.Security.Principal.Windows.csproj" />
</ItemGroup>
Expand Down
Loading

0 comments on commit c25b78d

Please sign in to comment.