Update last few projects to target `netcoreapp3.0` (#5128)
- #3754 - remove `#if`'s for multi-targeting where source is never multi-targeted - left `StreamPipeReader`, `StreamPipeWriter` and their test classes alone because they're moving to CoreFx
This commit is contained in:
parent
443b1449ff
commit
e717a8443e
|
|
@ -1,9 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
#if NETCOREAPP3_0
|
|
||||||
// Rfc2898DeriveBytes in .NET Standard 2.0 only supports SHA1
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
@ -64,8 +61,3 @@ namespace Microsoft.AspNetCore.Cryptography.KeyDerivation.PBKDF2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif NETSTANDARD2_0
|
|
||||||
#else
|
|
||||||
#error Update target frameworks
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
|
|
@ -25,22 +25,12 @@ namespace Microsoft.AspNetCore.Cryptography.KeyDerivation.PBKDF2
|
||||||
// acceptable implementation
|
// acceptable implementation
|
||||||
return new Win7Pbkdf2Provider();
|
return new Win7Pbkdf2Provider();
|
||||||
}
|
}
|
||||||
#if NETCOREAPP3_0
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fastest implementation on .NET Core for Linux/macOS.
|
// fastest implementation on .NET Core for Linux/macOS.
|
||||||
// Not supported on .NET Framework
|
// Not supported on .NET Framework
|
||||||
return new NetCorePbkdf2Provider();
|
return new NetCorePbkdf2Provider();
|
||||||
}
|
}
|
||||||
#elif NETSTANDARD2_0
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// slowest implementation
|
|
||||||
return new ManagedPbkdf2Provider();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error Update target frameworks
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,6 @@ namespace Microsoft.AspNetCore.Cryptography.KeyDerivation
|
||||||
{
|
{
|
||||||
public class Pbkdf2Tests
|
public class Pbkdf2Tests
|
||||||
{
|
{
|
||||||
|
|
||||||
#if NET461
|
|
||||||
#elif NETCOREAPP3_0
|
|
||||||
// The 'numBytesRequested' parameters below are chosen to exercise code paths where
|
// The 'numBytesRequested' parameters below are chosen to exercise code paths where
|
||||||
// this value straddles the digest length of the PRF. We only use 5 iterations so
|
// this value straddles the digest length of the PRF. We only use 5 iterations so
|
||||||
// that our unit tests are fast.
|
// that our unit tests are fast.
|
||||||
|
|
@ -60,9 +57,6 @@ namespace Microsoft.AspNetCore.Cryptography.KeyDerivation
|
||||||
var salt = Encoding.UTF8.GetBytes("abcdefghijkl");
|
var salt = Encoding.UTF8.GetBytes("abcdefghijkl");
|
||||||
RunTest_WithLongPassword_Impl<NetCorePbkdf2Provider>(salt, "NGJtFzYUaaSxu+3ZsMeZO5d/qPJDUYW4caLkFlaY0cLSYdh1PN4+nHUVp4pUUubJWu3UeXNMnHKNDfnn8GMfnDVrAGTv1lldszsvUJ0JQ6p4+daQEYBc//Tj/ejuB3luwW0IinyE7U/ViOQKbfi5pCZFMQ0FFx9I+eXRlyT+I74=");
|
RunTest_WithLongPassword_Impl<NetCorePbkdf2Provider>(salt, "NGJtFzYUaaSxu+3ZsMeZO5d/qPJDUYW4caLkFlaY0cLSYdh1PN4+nHUVp4pUUubJWu3UeXNMnHKNDfnn8GMfnDVrAGTv1lldszsvUJ0JQ6p4+daQEYBc//Tj/ejuB3luwW0IinyE7U/ViOQKbfi5pCZFMQ0FFx9I+eXRlyT+I74=");
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#error Update target framework
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// The 'numBytesRequested' parameters below are chosen to exercise code paths where
|
// The 'numBytesRequested' parameters below are chosen to exercise code paths where
|
||||||
// this value straddles the digest length of the PRF. We only use 5 iterations so
|
// this value straddles the digest length of the PRF. We only use 5 iterations so
|
||||||
|
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
#if NET461
|
|
||||||
using System;
|
|
||||||
using System.Runtime.ConstrainedExecution;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using Microsoft.AspNetCore.Cryptography;
|
|
||||||
using Microsoft.Win32.SafeHandles;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.DataProtection
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Helpers for working with the anonymous Windows identity.
|
|
||||||
/// </summary>
|
|
||||||
internal static class AnonymousImpersonation
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Performs an action while impersonated under the anonymous user (NT AUTHORITY\ANONYMOUS LOGIN).
|
|
||||||
/// </summary>
|
|
||||||
public static void Run(Action callback)
|
|
||||||
{
|
|
||||||
using (var threadHandle = ThreadHandle.OpenCurrentThreadHandle())
|
|
||||||
{
|
|
||||||
bool impersonated = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
impersonated = ImpersonateAnonymousToken(threadHandle);
|
|
||||||
if (!impersonated)
|
|
||||||
{
|
|
||||||
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (impersonated && !RevertToSelf())
|
|
||||||
{
|
|
||||||
Environment.FailFast("RevertToSelf() returned false!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport("advapi32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
|
||||||
private static extern bool ImpersonateAnonymousToken([In] ThreadHandle ThreadHandle);
|
|
||||||
|
|
||||||
[DllImport("advapi32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
|
||||||
private static extern bool RevertToSelf();
|
|
||||||
|
|
||||||
private sealed class ThreadHandle : SafeHandleZeroOrMinusOneIsInvalid
|
|
||||||
{
|
|
||||||
private ThreadHandle()
|
|
||||||
: base(ownsHandle: true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ThreadHandle OpenCurrentThreadHandle()
|
|
||||||
{
|
|
||||||
const int THREAD_ALL_ACCESS = 0x1FFFFF;
|
|
||||||
var handle = OpenThread(
|
|
||||||
dwDesiredAccess: THREAD_ALL_ACCESS,
|
|
||||||
bInheritHandle: false,
|
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
|
||||||
dwThreadId: (uint)AppDomain.GetCurrentThreadId());
|
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
CryptoUtil.AssertSafeHandleIsValid(handle);
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool ReleaseHandle()
|
|
||||||
{
|
|
||||||
return CloseHandle(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
|
||||||
[DllImport("kernel32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
|
||||||
private static extern bool CloseHandle(
|
|
||||||
[In] IntPtr hObject);
|
|
||||||
|
|
||||||
[DllImport("kernel32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
|
||||||
private static extern ThreadHandle OpenThread(
|
|
||||||
[In] uint dwDesiredAccess,
|
|
||||||
[In] bool bInheritHandle,
|
|
||||||
[In] uint dwThreadId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#elif NETCOREAPP3_0
|
|
||||||
#else
|
|
||||||
#error Target framework needs to be updated
|
|
||||||
#endif
|
|
||||||
|
|
@ -103,21 +103,7 @@ namespace Microsoft.AspNetCore.DataProtection
|
||||||
[MemberData(nameof(AssemblyVersions))]
|
[MemberData(nameof(AssemblyVersions))]
|
||||||
public void CreateInstance_ForwardsAcrossVersionChanges(Version version)
|
public void CreateInstance_ForwardsAcrossVersionChanges(Version version)
|
||||||
{
|
{
|
||||||
#if NET461
|
|
||||||
// run this test in an appdomain without testhost's custom assembly resolution hooks
|
|
||||||
var setupInfo = new AppDomainSetup
|
|
||||||
{
|
|
||||||
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
|
|
||||||
ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
|
|
||||||
};
|
|
||||||
var domain = AppDomain.CreateDomain("TestDomain", null, setupInfo);
|
|
||||||
var wrappedTestClass = (TypeForwardingActivatorTests)domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName, typeof(TypeForwardingActivatorTests).FullName);
|
|
||||||
wrappedTestClass.CreateInstance_ForwardsAcrossVersionChangesImpl(version);
|
|
||||||
#elif NETCOREAPP3_0
|
|
||||||
CreateInstance_ForwardsAcrossVersionChangesImpl(version);
|
CreateInstance_ForwardsAcrossVersionChangesImpl(version);
|
||||||
#else
|
|
||||||
#error Target framework should be updated
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateInstance_ForwardsAcrossVersionChangesImpl(Version newVersion)
|
private void CreateInstance_ForwardsAcrossVersionChangesImpl(Version newVersion)
|
||||||
|
|
|
||||||
|
|
@ -33,29 +33,5 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
||||||
var roundTrippedElement = decryptor.Decrypt(encryptedXmlInfo.EncryptedElement);
|
var roundTrippedElement = decryptor.Decrypt(encryptedXmlInfo.EncryptedElement);
|
||||||
XmlAssert.Equal(originalXml, roundTrippedElement);
|
XmlAssert.Equal(originalXml, roundTrippedElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NET461
|
|
||||||
[ConditionalFact]
|
|
||||||
[ConditionalRunTestOnlyOnWindows]
|
|
||||||
public void Encrypt_CurrentUser_Decrypt_ImpersonatedAsAnonymous_Fails()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var originalXml = XElement.Parse(@"<mySecret value='265ee4ea-ade2-43b1-b706-09b259e58b6b' />");
|
|
||||||
var encryptor = new DpapiXmlEncryptor(protectToLocalMachine: false, loggerFactory: NullLoggerFactory.Instance);
|
|
||||||
var decryptor = new DpapiXmlDecryptor();
|
|
||||||
|
|
||||||
// Act & assert - run through encryptor and make sure we get back an obfuscated element
|
|
||||||
var encryptedXmlInfo = encryptor.Encrypt(originalXml);
|
|
||||||
Assert.Equal(typeof(DpapiXmlDecryptor), encryptedXmlInfo.DecryptorType);
|
|
||||||
Assert.DoesNotContain("265ee4ea-ade2-43b1-b706-09b259e58b6b", encryptedXmlInfo.EncryptedElement.ToString(), StringComparison.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
// Act & assert - run through decryptor (while impersonated as anonymous) and verify failure
|
|
||||||
ExceptionAssert2.ThrowsCryptographicException(() =>
|
|
||||||
AnonymousImpersonation.Run(() => decryptor.Decrypt(encryptedXmlInfo.EncryptedElement)));
|
|
||||||
}
|
|
||||||
#elif NETCOREAPP3_0
|
|
||||||
#else
|
|
||||||
#error Target framework needs to be updated
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>ASP.NET Core support for JSON PATCH.</Description>
|
<Description>ASP.NET Core support for JSON PATCH.</Description>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<PackageTags>aspnetcore;json;jsonpatch</PackageTags>
|
<PackageTags>aspnetcore;json;jsonpatch</PackageTags>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
<TargetFrameworks>netcoreapp3.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>exe</OutputType>
|
<OutputType>exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||||
<SignAssembly>false</SignAssembly>
|
<SignAssembly>false</SignAssembly>
|
||||||
<LangVersion>7.1</LangVersion>
|
<LangVersion>7.1</LangVersion>
|
||||||
<DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>
|
<DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>
|
||||||
|
|
|
||||||
|
|
@ -32,18 +32,14 @@ namespace Microsoft.AspNetCore.Certificates.Generation
|
||||||
private const string MacOSSystemKeyChain = "/Library/Keychains/System.keychain";
|
private const string MacOSSystemKeyChain = "/Library/Keychains/System.keychain";
|
||||||
private static readonly string MacOSUserKeyChain = Environment.GetEnvironmentVariable("HOME") + "/Library/Keychains/login.keychain-db";
|
private static readonly string MacOSUserKeyChain = Environment.GetEnvironmentVariable("HOME") + "/Library/Keychains/login.keychain-db";
|
||||||
private const string MacOSFindCertificateCommandLine = "security";
|
private const string MacOSFindCertificateCommandLine = "security";
|
||||||
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0
|
|
||||||
private static readonly string MacOSFindCertificateCommandLineArgumentsFormat = "find-certificate -c {0} -a -Z -p " + MacOSSystemKeyChain;
|
private static readonly string MacOSFindCertificateCommandLineArgumentsFormat = "find-certificate -c {0} -a -Z -p " + MacOSSystemKeyChain;
|
||||||
#endif
|
|
||||||
private const string MacOSFindCertificateOutputRegex = "SHA-1 hash: ([0-9A-Z]+)";
|
private const string MacOSFindCertificateOutputRegex = "SHA-1 hash: ([0-9A-Z]+)";
|
||||||
private const string MacOSRemoveCertificateTrustCommandLine = "sudo";
|
private const string MacOSRemoveCertificateTrustCommandLine = "sudo";
|
||||||
private const string MacOSRemoveCertificateTrustCommandLineArgumentsFormat = "security remove-trusted-cert -d {0}";
|
private const string MacOSRemoveCertificateTrustCommandLineArgumentsFormat = "security remove-trusted-cert -d {0}";
|
||||||
private const string MacOSDeleteCertificateCommandLine = "sudo";
|
private const string MacOSDeleteCertificateCommandLine = "sudo";
|
||||||
private const string MacOSDeleteCertificateCommandLineArgumentsFormat = "security delete-certificate -Z {0} {1}";
|
private const string MacOSDeleteCertificateCommandLineArgumentsFormat = "security delete-certificate -Z {0} {1}";
|
||||||
private const string MacOSTrustCertificateCommandLine = "sudo";
|
private const string MacOSTrustCertificateCommandLine = "sudo";
|
||||||
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0
|
|
||||||
private static readonly string MacOSTrustCertificateCommandLineArguments = "security add-trusted-cert -d -r trustRoot -k " + MacOSSystemKeyChain + " ";
|
private static readonly string MacOSTrustCertificateCommandLineArguments = "security add-trusted-cert -d -r trustRoot -k " + MacOSSystemKeyChain + " ";
|
||||||
#endif
|
|
||||||
private const int UserCancelledErrorCode = 1223;
|
private const int UserCancelledErrorCode = 1223;
|
||||||
|
|
||||||
public IList<X509Certificate2> ListCertificates(
|
public IList<X509Certificate2> ListCertificates(
|
||||||
|
|
@ -153,8 +149,6 @@ namespace Microsoft.AspNetCore.Certificates.Generation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0
|
|
||||||
|
|
||||||
public X509Certificate2 CreateAspNetCoreHttpsDevelopmentCertificate(DateTimeOffset notBefore, DateTimeOffset notAfter, string subjectOverride, DiagnosticInformation diagnostics = null)
|
public X509Certificate2 CreateAspNetCoreHttpsDevelopmentCertificate(DateTimeOffset notBefore, DateTimeOffset notAfter, string subjectOverride, DiagnosticInformation diagnostics = null)
|
||||||
{
|
{
|
||||||
var subject = new X500DistinguishedName(subjectOverride ?? LocalhostHttpsDistinguishedName);
|
var subject = new X500DistinguishedName(subjectOverride ?? LocalhostHttpsDistinguishedName);
|
||||||
|
|
@ -739,7 +733,7 @@ namespace Microsoft.AspNetCore.Certificates.Generation
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is just to avoid breaking changes across repos.
|
// This is just to avoid breaking changes across repos.
|
||||||
// Will be renamed back to EnsureAspNetCoreHttpsDevelopmentCertificate once updates are made elsewhere.
|
// Will be renamed back to EnsureAspNetCoreHttpsDevelopmentCertificate once updates are made elsewhere.
|
||||||
public DetailedEnsureCertificateResult EnsureAspNetCoreHttpsDevelopmentCertificate2(
|
public DetailedEnsureCertificateResult EnsureAspNetCoreHttpsDevelopmentCertificate2(
|
||||||
DateTimeOffset notBefore,
|
DateTimeOffset notBefore,
|
||||||
|
|
@ -893,7 +887,6 @@ namespace Microsoft.AspNetCore.Certificates.Generation
|
||||||
public EnsureCertificateResult ResultCode { get; set; }
|
public EnsureCertificateResult ResultCode { get; set; }
|
||||||
public DiagnosticInformation Diagnostics { get; set; } = new DiagnosticInformation();
|
public DiagnosticInformation Diagnostics { get; set; } = new DiagnosticInformation();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
internal class DiagnosticInformation
|
internal class DiagnosticInformation
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Certificates.Generation
|
namespace Microsoft.AspNetCore.Certificates.Generation
|
||||||
{
|
{
|
||||||
internal enum EnsureCertificateResult
|
internal enum EnsureCertificateResult
|
||||||
|
|
@ -16,5 +14,3 @@ namespace Microsoft.AspNetCore.Certificates.Generation
|
||||||
UserCancelledTrustStep
|
UserCancelledTrustStep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
#if NETCOREAPP3_0
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -284,5 +282,3 @@ namespace Microsoft.AspNetCore.Certificates.Generation.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue