diff --git a/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/NetCorePbkdf2Provider.cs b/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/NetCorePbkdf2Provider.cs index a8ce1772eb41..ace4fd2be1d0 100644 --- a/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/NetCorePbkdf2Provider.cs +++ b/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/NetCorePbkdf2Provider.cs @@ -1,9 +1,6 @@ // 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 NETCOREAPP3_0 -// Rfc2898DeriveBytes in .NET Standard 2.0 only supports SHA1 - using System; using System.Diagnostics; using System.Security.Cryptography; @@ -64,8 +61,3 @@ private static byte[] DeriveKeyImpl(string password, byte[] salt, KeyDerivationP } } } - -#elif NETSTANDARD2_0 -#else -#error Update target frameworks -#endif diff --git a/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/Pbkdf2Util.cs b/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/Pbkdf2Util.cs index d8139c92f752..7cbda18bdd53 100644 --- a/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/Pbkdf2Util.cs +++ b/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/Pbkdf2Util.cs @@ -25,22 +25,12 @@ private static IPbkdf2Provider GetPbkdf2Provider() // acceptable implementation return new Win7Pbkdf2Provider(); } -#if NETCOREAPP3_0 else { // fastest implementation on .NET Core for Linux/macOS. // Not supported on .NET Framework return new NetCorePbkdf2Provider(); } -#elif NETSTANDARD2_0 - else - { - // slowest implementation - return new ManagedPbkdf2Provider(); - } -#else -#error Update target frameworks -#endif } } } diff --git a/src/DataProtection/Cryptography.KeyDerivation/test/Pbkdf2Tests.cs b/src/DataProtection/Cryptography.KeyDerivation/test/Pbkdf2Tests.cs index a45f5e24ce28..295dc819c411 100644 --- a/src/DataProtection/Cryptography.KeyDerivation/test/Pbkdf2Tests.cs +++ b/src/DataProtection/Cryptography.KeyDerivation/test/Pbkdf2Tests.cs @@ -12,9 +12,6 @@ namespace Microsoft.AspNetCore.Cryptography.KeyDerivation { public class Pbkdf2Tests { - -#if NET461 -#elif NETCOREAPP3_0 // 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 // that our unit tests are fast. @@ -60,9 +57,6 @@ public void RunTest_WithLongPassword_NetCore() var salt = Encoding.UTF8.GetBytes("abcdefghijkl"); RunTest_WithLongPassword_Impl(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 // this value straddles the digest length of the PRF. We only use 5 iterations so diff --git a/src/DataProtection/DataProtection/test/AnonymousImpersonation.cs b/src/DataProtection/DataProtection/test/AnonymousImpersonation.cs deleted file mode 100644 index e142b698e7f0..000000000000 --- a/src/DataProtection/DataProtection/test/AnonymousImpersonation.cs +++ /dev/null @@ -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 -{ - /// - /// Helpers for working with the anonymous Windows identity. - /// - internal static class AnonymousImpersonation - { - /// - /// Performs an action while impersonated under the anonymous user (NT AUTHORITY\ANONYMOUS LOGIN). - /// - 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 diff --git a/src/DataProtection/DataProtection/test/TypeForwardingActivatorTests.cs b/src/DataProtection/DataProtection/test/TypeForwardingActivatorTests.cs index e7df5cfeae7a..d13593568146 100644 --- a/src/DataProtection/DataProtection/test/TypeForwardingActivatorTests.cs +++ b/src/DataProtection/DataProtection/test/TypeForwardingActivatorTests.cs @@ -103,21 +103,7 @@ public void CreateInstance_DoesNotForwardingTypesExternalTypes(Type type) [MemberData(nameof(AssemblyVersions))] 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); -#else -#error Target framework should be updated -#endif } private void CreateInstance_ForwardsAcrossVersionChangesImpl(Version newVersion) diff --git a/src/DataProtection/DataProtection/test/XmlEncryption/DpapiXmlEncryptionTests.cs b/src/DataProtection/DataProtection/test/XmlEncryption/DpapiXmlEncryptionTests.cs index 7274d846ad51..c6b4aa208af7 100644 --- a/src/DataProtection/DataProtection/test/XmlEncryption/DpapiXmlEncryptionTests.cs +++ b/src/DataProtection/DataProtection/test/XmlEncryption/DpapiXmlEncryptionTests.cs @@ -33,29 +33,5 @@ public void Encrypt_CurrentUserOrLocalMachine_Decrypt_RoundTrips(bool protectToL var roundTrippedElement = decryptor.Decrypt(encryptedXmlInfo.EncryptedElement); XmlAssert.Equal(originalXml, roundTrippedElement); } - -#if NET461 - [ConditionalFact] - [ConditionalRunTestOnlyOnWindows] - public void Encrypt_CurrentUser_Decrypt_ImpersonatedAsAnonymous_Fails() - { - // Arrange - var originalXml = XElement.Parse(@""); - 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 } } diff --git a/src/Features/JsonPatch/src/Microsoft.AspNetCore.JsonPatch.csproj b/src/Features/JsonPatch/src/Microsoft.AspNetCore.JsonPatch.csproj index f6f11fd3b3fc..b543615a880d 100644 --- a/src/Features/JsonPatch/src/Microsoft.AspNetCore.JsonPatch.csproj +++ b/src/Features/JsonPatch/src/Microsoft.AspNetCore.JsonPatch.csproj @@ -2,7 +2,7 @@ ASP.NET Core support for JSON PATCH. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;json;jsonpatch diff --git a/src/Features/JsonPatch/test/Microsoft.AspNetCore.JsonPatch.Tests.csproj b/src/Features/JsonPatch/test/Microsoft.AspNetCore.JsonPatch.Tests.csproj index 28d501111a4e..1a3c83556cf3 100644 --- a/src/Features/JsonPatch/test/Microsoft.AspNetCore.JsonPatch.Tests.csproj +++ b/src/Features/JsonPatch/test/Microsoft.AspNetCore.JsonPatch.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.0;net461 + netcoreapp3.0 diff --git a/src/PackageArchive/ZipManifestGenerator/ZipManifestGenerator.csproj b/src/PackageArchive/ZipManifestGenerator/ZipManifestGenerator.csproj index b7d3a43622ab..403e8cb58e6b 100644 --- a/src/PackageArchive/ZipManifestGenerator/ZipManifestGenerator.csproj +++ b/src/PackageArchive/ZipManifestGenerator/ZipManifestGenerator.csproj @@ -2,7 +2,7 @@ exe - netcoreapp2.1 + netcoreapp3.0 false 7.1 false diff --git a/src/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index 26639572e4e1..17e0d52e4d23 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -32,18 +32,14 @@ internal class CertificateManager private const string MacOSSystemKeyChain = "/Library/Keychains/System.keychain"; private static readonly string MacOSUserKeyChain = Environment.GetEnvironmentVariable("HOME") + "/Library/Keychains/login.keychain-db"; 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; -#endif private const string MacOSFindCertificateOutputRegex = "SHA-1 hash: ([0-9A-Z]+)"; private const string MacOSRemoveCertificateTrustCommandLine = "sudo"; private const string MacOSRemoveCertificateTrustCommandLineArgumentsFormat = "security remove-trusted-cert -d {0}"; private const string MacOSDeleteCertificateCommandLine = "sudo"; private const string MacOSDeleteCertificateCommandLineArgumentsFormat = "security delete-certificate -Z {0} {1}"; 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 + " "; -#endif private const int UserCancelledErrorCode = 1223; public IList ListCertificates( @@ -153,8 +149,6 @@ private static void DisposeCertificates(IEnumerable disposable } } -#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 - public X509Certificate2 CreateAspNetCoreHttpsDevelopmentCertificate(DateTimeOffset notBefore, DateTimeOffset notAfter, string subjectOverride, DiagnosticInformation diagnostics = null) { var subject = new X500DistinguishedName(subjectOverride ?? LocalhostHttpsDistinguishedName); @@ -739,7 +733,7 @@ public EnsureCertificateResult EnsureValidCertificateExists( 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. public DetailedEnsureCertificateResult EnsureAspNetCoreHttpsDevelopmentCertificate2( DateTimeOffset notBefore, @@ -893,7 +887,6 @@ internal class DetailedEnsureCertificateResult public EnsureCertificateResult ResultCode { get; set; } public DiagnosticInformation Diagnostics { get; set; } = new DiagnosticInformation(); } -#endif internal class DiagnosticInformation { diff --git a/src/Shared/CertificateGeneration/EnsureCertificateResult.cs b/src/Shared/CertificateGeneration/EnsureCertificateResult.cs index 2106297faed9..4676d7b3aa94 100644 --- a/src/Shared/CertificateGeneration/EnsureCertificateResult.cs +++ b/src/Shared/CertificateGeneration/EnsureCertificateResult.cs @@ -1,8 +1,6 @@ // 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 NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 - namespace Microsoft.AspNetCore.Certificates.Generation { internal enum EnsureCertificateResult @@ -16,5 +14,3 @@ internal enum EnsureCertificateResult UserCancelledTrustStep } } - -#endif diff --git a/src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs b/src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs index 0979eba21bc1..52caae046d1a 100644 --- a/src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs +++ b/src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs @@ -1,8 +1,6 @@ // 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 NETCOREAPP3_0 - using System; using System.IO; using System.Linq; @@ -284,5 +282,3 @@ public void EnsureAspNetCoreHttpsDevelopmentCertificate_CanRemoveCertificates() } } } - -#endif