diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 6b7cd6b2cbc8a2..ebb4a427f2896f 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -670,22 +670,22 @@ if (CLR_CMAKE_HOST_UNIX) set(DISABLE_OVERRIDING_MIN_VERSION_ERROR -Wno-overriding-t-option) add_link_options(-Wno-overriding-t-option) if(CLR_CMAKE_HOST_ARCH_ARM64) - set(MACOS_VERSION_MIN_FLAGS "-target arm64-apple-ios15.0-macabi") - add_link_options(-target arm64-apple-ios15.0-macabi) + set(CLR_CMAKE_MACCATALYST_COMPILER_TARGET "arm64-apple-ios15.0-macabi") + add_link_options(-target ${CLR_CMAKE_MACCATALYST_COMPILER_TARGET}) elseif(CLR_CMAKE_HOST_ARCH_AMD64) - set(MACOS_VERSION_MIN_FLAGS "-target x86_64-apple-ios15.0-macabi") - add_link_options(-target x86_64-apple-ios15.0-macabi) + set(CLR_CMAKE_MACCATALYST_COMPILER_TARGET "x86_64-apple-ios15.0-macabi") + add_link_options(-target ${CLR_CMAKE_MACCATALYST_COMPILER_TARGET}) else() clr_unknown_arch() endif() # These options are intentionally set using the CMAKE_XXX_FLAGS instead of # add_compile_options so that they take effect on the configuration functions # in various configure.cmake files. - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") - set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") - set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") - set(CMAKE_OBJCXX_FLAGS "${CMAKE_OBJCXX_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target ${CLR_CMAKE_MACCATALYST_COMPILER_TARGET} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target ${CLR_CMAKE_MACCATALYST_COMPILER_TARGET} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") + set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -target ${CLR_CMAKE_MACCATALYST_COMPILER_TARGET} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") + set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS}-target ${CLR_CMAKE_MACCATALYST_COMPILER_TARGET} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") + set(CMAKE_OBJCXX_FLAGS "${CMAKE_OBJCXX_FLAGS} -target ${CLR_CMAKE_MACCATALYST_COMPILER_TARGET} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}") elseif(CLR_CMAKE_HOST_OSX) set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0") if(CLR_CMAKE_HOST_ARCH_ARM64) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 07fba4c26ee897..2725fc7c669201 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -177,7 +177,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -188,8 +188,8 @@ The .NET Foundation licenses this file to you under the MIT license. - - + + @@ -214,7 +214,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Aead.cs b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Aead.cs index c833b71c8eade6..2216415d618731 100644 --- a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Aead.cs +++ b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Aead.cs @@ -6,6 +6,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.InteropServices.Swift; +using System.Runtime.Versioning; using System.Security.Cryptography; using System.Security.Cryptography.Apple; using Swift.Runtime; @@ -27,6 +28,11 @@ private static ref readonly byte GetSwiftRef(ReadOnlySpan b) : ref MemoryMarshal.GetReference(b)); } + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + [SupportedOSPlatform("maccatalyst")] + [SupportedOSPlatform("ios13.0")] + [SupportedOSPlatform("tvos13.0")] internal static unsafe void ChaCha20Poly1305Encrypt( ReadOnlySpan key, ReadOnlySpan nonce, @@ -60,6 +66,11 @@ internal static unsafe void ChaCha20Poly1305Encrypt( } } + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + [SupportedOSPlatform("maccatalyst")] + [SupportedOSPlatform("ios13.0")] + [SupportedOSPlatform("tvos13.0")] internal static unsafe void ChaCha20Poly1305Decrypt( ReadOnlySpan key, ReadOnlySpan nonce, @@ -100,6 +111,11 @@ internal static unsafe void ChaCha20Poly1305Decrypt( } } + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + [SupportedOSPlatform("maccatalyst")] + [SupportedOSPlatform("ios13.0")] + [SupportedOSPlatform("tvos13.0")] internal static unsafe void AesGcmEncrypt( ReadOnlySpan key, ReadOnlySpan nonce, @@ -133,6 +149,11 @@ internal static unsafe void AesGcmEncrypt( } } + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + [SupportedOSPlatform("maccatalyst")] + [SupportedOSPlatform("ios13.0")] + [SupportedOSPlatform("tvos13.0")] internal static unsafe void AesGcmDecrypt( ReadOnlySpan key, ReadOnlySpan nonce, diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs index 78782efd46b154..7a98ea4754ac95 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs @@ -188,7 +188,6 @@ public void KeySizeProp() } [Theory, MemberData(nameof(TestNewCurves))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public void TestRegenKeyExplicit(CurveDef curveDef) { ECParameters param, param2; diff --git a/src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs b/src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs index c19cedc9ff4519..c544ffc50f1b3b 100644 --- a/src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs +++ b/src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs @@ -121,6 +121,9 @@ public override void GenerateKey() { } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] + [System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")] + [System.Runtime.Versioning.SupportedOSPlatform("ios13.0")] + [System.Runtime.Versioning.SupportedOSPlatform("tvos13.0")] public sealed partial class AesGcm : System.IDisposable { [System.ObsoleteAttribute("AesGcm should indicate the required tag size for encryption and decryption. Use a constructor that accepts the tag size.", DiagnosticId="SYSLIB0053", UrlFormat="https://aka.ms/dotnet-warnings/{0}")] @@ -284,6 +287,9 @@ public AuthenticationTagMismatchException(string? message, System.Exception? inn [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] + [System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")] + [System.Runtime.Versioning.SupportedOSPlatform("ios13.0")] + [System.Runtime.Versioning.SupportedOSPlatform("tvos13.0")] public sealed partial class ChaCha20Poly1305 : System.IDisposable { public ChaCha20Poly1305(byte[] key) { } diff --git a/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj b/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj index b9f0ce5317f7f9..9a6869cae10c70 100644 --- a/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj +++ b/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj @@ -1077,6 +1077,10 @@ Link="Common\Interop\OSX\Interop.CoreFoundation.CFString.cs" /> + + + + @@ -1219,10 +1225,6 @@ Link="Common\Interop\Unix\System.Security.Cryptography.Native\Interop.EvpPkey.Rsa.cs" /> - - - - @@ -1285,8 +1285,6 @@ - - diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.macOS.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.Apple.cs similarity index 90% rename from src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.macOS.cs rename to src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.Apple.cs index d9f036f61ca5d7..d09e55eafb89eb 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.macOS.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.Apple.cs @@ -11,8 +11,8 @@ public sealed partial class AesGcm { private FixedMemoryKeyBox _keyBox; - // CryptoKit added AES.GCM in macOS 10.15, which is lower than our minimum target for macOS. - public static bool IsSupported => true; + // CryptoKit added AES.GCM in macOS 10.15, which is lower than our minimum target for macOS/MacCatalyst. On iOS/tvOS, it was added in 13.0. + public static bool IsSupported => OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13); // CryptoKit only supports 16 byte tags. public static KeySizes TagByteSizes { get; } = new KeySizes(16, 16, 1); diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.cs index 476b9917e5557d..0a17baea87156b 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesGcm.cs @@ -10,6 +10,9 @@ namespace System.Security.Cryptography [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] + [SupportedOSPlatform("maccatalyst")] + [SupportedOSPlatform("ios13.0")] + [SupportedOSPlatform("tvos13.0")] public sealed partial class AesGcm : IDisposable { private const int NonceSize = 12; diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.macOS.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.Apple.cs similarity index 89% rename from src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.macOS.cs rename to src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.Apple.cs index 7e45061f971a6e..55d8dee2c7c1e7 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.macOS.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.Apple.cs @@ -8,8 +8,8 @@ namespace System.Security.Cryptography { public sealed partial class ChaCha20Poly1305 { - // CryptoKit added ChaCha20Poly1305 in macOS 10.15, which is lower than our minimum target for macOS. - public static bool IsSupported => true; + // CryptoKit added ChaCha20Poly1305 in macOS 10.15, which is lower than our minimum target for macOS/MacCatalyst. On iOS/tvOS, it was added in 13.0. + public static bool IsSupported => OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13); private FixedMemoryKeyBox _keyBox; [MemberNotNull(nameof(_keyBox))] diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.cs index 63ac0a3f7eca2e..7e16d9a7aeebb7 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.cs @@ -9,6 +9,9 @@ namespace System.Security.Cryptography [UnsupportedOSPlatform("browser")] [UnsupportedOSPlatform("ios")] [UnsupportedOSPlatform("tvos")] + [SupportedOSPlatform("maccatalyst")] + [SupportedOSPlatform("ios13.0")] + [SupportedOSPlatform("tvos13.0")] public sealed partial class ChaCha20Poly1305 : IDisposable { // Per https://tools.ietf.org/html/rfc7539, ChaCha20Poly1305 AEAD requires a 256-bit key and 96-bit nonce, diff --git a/src/libraries/System.Security.Cryptography/tests/AesCcmTests.cs b/src/libraries/System.Security.Cryptography/tests/AesCcmTests.cs index d47e0dea5ad340..0e6b6c8af1f239 100644 --- a/src/libraries/System.Security.Cryptography/tests/AesCcmTests.cs +++ b/src/libraries/System.Security.Cryptography/tests/AesCcmTests.cs @@ -12,7 +12,6 @@ namespace System.Security.Cryptography.Tests public class AesCcmTests : CommonAEADTests { [Theory] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] [MemberData(nameof(EncryptTamperAADDecryptTestInputs))] public static void EncryptTamperAADDecrypt(int dataLength, int additionalDataLength) { @@ -73,7 +72,6 @@ public static void InvalidNonceSize(int nonceSize) [Theory] [MemberData(nameof(GetValidNonceSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void ValidNonceSize(int nonceSize) { const int dataLength = 35; @@ -116,7 +114,6 @@ public static void InvalidTagSize(int tagSize) [Theory] [MemberData(nameof(GetValidTagSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void ValidTagSize(int tagSize) { const int dataLength = 35; @@ -139,7 +136,6 @@ public static void ValidTagSize(int tagSize) } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void TwoEncryptionsAndDecryptionsUsingOneInstance() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -267,7 +263,6 @@ public static void EncryptDecryptNullTag() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void InplaceEncryptDecrypt() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -288,7 +283,6 @@ public static void InplaceEncryptDecrypt() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void InplaceEncryptTamperTagDecrypt() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -313,7 +307,6 @@ public static void InplaceEncryptTamperTagDecrypt() [Theory] [MemberData(nameof(GetNistCcmTestCases))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void AesCcmNistTests(AEADTest testCase) { using (var aesCcm = new AesCcm(testCase.Key)) @@ -332,7 +325,6 @@ public static void AesCcmNistTests(AEADTest testCase) [Theory] [MemberData(nameof(GetNistCcmTestCases))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void AesCcmNistTestsTamperTag(AEADTest testCase) { using (var aesCcm = new AesCcm(testCase.Key)) @@ -355,7 +347,6 @@ public static void AesCcmNistTestsTamperTag(AEADTest testCase) [Theory] [MemberData(nameof(GetNistCcmTestCasesWithNonEmptyPT))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void AesCcmNistTestsTamperCiphertext(AEADTest testCase) { using (var aesCcm = new AesCcm(testCase.Key)) diff --git a/src/libraries/System.Security.Cryptography/tests/AesGcmTests.cs b/src/libraries/System.Security.Cryptography/tests/AesGcmTests.cs index 46e70b2e993a33..d8fe8367106fc7 100644 --- a/src/libraries/System.Security.Cryptography/tests/AesGcmTests.cs +++ b/src/libraries/System.Security.Cryptography/tests/AesGcmTests.cs @@ -14,7 +14,6 @@ public class AesGcmTests : CommonAEADTests private const int CryptoKitSupportedTagSizeInBytes = 16; [Theory] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] [MemberData(nameof(EncryptTamperAADDecryptTestInputs))] public static void EncryptTamperAADDecrypt(int dataLength, int additionalDataLength) { @@ -61,7 +60,6 @@ public static void InvalidKeyLength(int keyLength) [Theory] [MemberData(nameof(GetInvalidNonceSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void InvalidNonceSize(int nonceSize) { int dataLength = 30; @@ -81,7 +79,6 @@ public static void InvalidNonceSize(int nonceSize) [Theory] [MemberData(nameof(GetValidNonceSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void ValidNonceSize(int nonceSize) { const int dataLength = 35; @@ -105,7 +102,6 @@ public static void ValidNonceSize(int nonceSize) [Theory] [MemberData(nameof(GetInvalidTagSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void InvalidTagSizeForUnspecifiedRequiredTag(int tagSize) { int dataLength = 30; @@ -128,7 +124,6 @@ public static void InvalidTagSizeForUnspecifiedRequiredTag(int tagSize) [Theory] [MemberData(nameof(GetInvalidTagSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void InvalidTagSizeForRequiredTag(int tagSize) { byte[] key = new byte[32]; @@ -138,7 +133,6 @@ public static void InvalidTagSizeForRequiredTag(int tagSize) [Theory] [MemberData(nameof(GetValidTagSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void ValidTagSize(int tagSize) { const int dataLength = 35; @@ -192,7 +186,6 @@ public static void TagSizeDoesNotMatchConstructorRequirement(int wrongTagSize) } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void TwoEncryptionsAndDecryptionsUsingOneInstance() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -203,7 +196,7 @@ public static void TwoEncryptionsAndDecryptionsUsingOneInstance() byte[] nonce2 = "8ba10892e8b87d031196bf99".HexToByteArray(); byte[] expectedCiphertext1 = "f1af1fb2d4485cc536d618475d52ff".HexToByteArray(); - byte[] expectedTag1 = PlatformDetection.IsOSX ? + byte[] expectedTag1 = (PlatformDetection.IsOSX || PlatformDetection.UsesMobileAppleCrypto) ? "5ab65624c46b8160f34e81f51fee6cd9".HexToByteArray() : "5ab65624c46b8160f34e81f5".HexToByteArray(); @@ -242,7 +235,6 @@ public static void TwoEncryptionsAndDecryptionsUsingOneInstance() } [Theory] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] [MemberData(nameof(PlaintextAndCiphertextSizeDifferTestInputs))] public static void PlaintextAndCiphertextSizeDiffer(int ptLen, int ctLen) { @@ -269,7 +261,6 @@ public static void NullKey() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void EncryptDecryptNullNonce() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -285,7 +276,6 @@ public static void EncryptDecryptNullNonce() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void EncryptDecryptNullPlaintext() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -301,7 +291,6 @@ public static void EncryptDecryptNullPlaintext() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void EncryptDecryptNullCiphertext() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -317,7 +306,6 @@ public static void EncryptDecryptNullCiphertext() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void EncryptDecryptNullTag() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -333,7 +321,6 @@ public static void EncryptDecryptNullTag() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void InplaceEncryptDecrypt() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -354,7 +341,6 @@ public static void InplaceEncryptDecrypt() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void InplaceEncryptTamperTagDecrypt() { byte[] key = "d5a194ed90cfe08abecd4691997ceb2c".HexToByteArray(); @@ -379,7 +365,6 @@ public static void InplaceEncryptTamperTagDecrypt() [Theory] [MemberData(nameof(GetNistGcmTestCases))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void AesGcmNistTestsUnspecifiedTagSize(AEADTest testCase) { #pragma warning disable SYSLIB0053 @@ -389,7 +374,7 @@ public static void AesGcmNistTestsUnspecifiedTagSize(AEADTest testCase) byte[] ciphertext = new byte[testCase.Plaintext.Length]; byte[] tag = new byte[testCase.Tag.Length]; - if (PlatformDetection.IsOSX && testCase.Tag.Length != CryptoKitSupportedTagSizeInBytes) + if ((PlatformDetection.IsOSX || PlatformDetection.UsesMobileAppleCrypto) && testCase.Tag.Length != CryptoKitSupportedTagSizeInBytes) { Assert.Throws("tag", () => { @@ -416,10 +401,9 @@ public static void AesGcmNistTestsUnspecifiedTagSize(AEADTest testCase) [Theory] [MemberData(nameof(GetNistGcmTestCases))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void AesGcmNistTestsSpecifiedTagSize(AEADTest testCase) { - if (PlatformDetection.IsOSX && testCase.Tag.Length != CryptoKitSupportedTagSizeInBytes) + if ((PlatformDetection.IsOSX || PlatformDetection.UsesMobileAppleCrypto) && testCase.Tag.Length != CryptoKitSupportedTagSizeInBytes) { Assert.Throws("tagSizeInBytes", () => new AesGcm(testCase.Key, testCase.Tag.Length)); } @@ -443,10 +427,9 @@ public static void AesGcmNistTestsSpecifiedTagSize(AEADTest testCase) [Theory] [MemberData(nameof(GetNistGcmTestCases))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void AesGcmNistTestsTamperTag(AEADTest testCase) { - if (PlatformDetection.IsOSX && testCase.Tag.Length != CryptoKitSupportedTagSizeInBytes) + if ((PlatformDetection.IsOSX || PlatformDetection.UsesMobileAppleCrypto) && testCase.Tag.Length != CryptoKitSupportedTagSizeInBytes) { return; } @@ -471,10 +454,9 @@ public static void AesGcmNistTestsTamperTag(AEADTest testCase) [Theory] [MemberData(nameof(GetNistGcmTestCasesWithNonEmptyPT))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/51332", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] public static void AesGcmNistTestsTamperCiphertext(AEADTest testCase) { - if (PlatformDetection.IsOSX && testCase.Tag.Length != CryptoKitSupportedTagSizeInBytes) + if ((PlatformDetection.IsOSX || PlatformDetection.UsesMobileAppleCrypto) && testCase.Tag.Length != CryptoKitSupportedTagSizeInBytes) { return; } @@ -1005,15 +987,6 @@ public static void CheckIsSupported() { bool expectedIsSupported = !PlatformDetection.IsBrowser; - if (PlatformDetection.IsOSX) - { - expectedIsSupported = true; - } - else if (PlatformDetection.UsesMobileAppleCrypto) - { - expectedIsSupported = false; - } - Assert.Equal(expectedIsSupported, AesGcm.IsSupported); } } diff --git a/src/libraries/System.Security.Cryptography/tests/ChaCha20Poly1305Tests.cs b/src/libraries/System.Security.Cryptography/tests/ChaCha20Poly1305Tests.cs index 00ae5286b25a92..8ec4f3bc059cac 100644 --- a/src/libraries/System.Security.Cryptography/tests/ChaCha20Poly1305Tests.cs +++ b/src/libraries/System.Security.Cryptography/tests/ChaCha20Poly1305Tests.cs @@ -473,9 +473,9 @@ public static void CheckIsSupported() // OpenSSL is present, and a high enough version, // but the distro build options turned off ChaCha/Poly. } - else if (PlatformDetection.IsOSX) + else if (PlatformDetection.IsOSX || PlatformDetection.UsesMobileAppleCrypto) { - // CryptoKit is supported on macOS 10.15+, which is lower than our minimum target. + // CryptoKit is supported on macOS 10.15+, which is our minimum target. On iOS/tvOS, it was added in 13.0 but we can expect that version in our testing environments. expectedIsSupported = true; } else if (PlatformDetection.OpenSslPresentOnSystem && PlatformDetection.IsOpenSslSupported) diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 483ae04924a728..463bcac8622e98 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -75,8 +75,12 @@ <_CommonLinkerArgs Include="-lc++" /> <_CommonLinkerArgs Include="-liconv" /> <_CommonLinkerArgs Include="-licucore" /> + <_CommonLinkerArgs Include="-L/usr/lib/swift" /> + <_CommonLinkerArgs Include="-lswiftCore" /> + <_CommonLinkerArgs Include="-lswiftFoundation" /> <_CommonLinkerArgs Include="-framework Foundation" /> <_CommonLinkerArgs Include="-framework Security" /> + <_CommonLinkerArgs Include="-framework CryptoKit" /> <_CommonLinkerArgs Include="-framework UIKit" /> diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt index a50ade7e86317e..84615493f4495c 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/CMakeLists.txt @@ -20,6 +20,7 @@ set(NATIVECRYPTO_SOURCES pal_symmetric.c pal_x509.c pal_x509chain.c + pal_swiftbindings.o ) if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) @@ -31,7 +32,6 @@ if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVO else() set(NATIVECRYPTO_SOURCES ${NATIVECRYPTO_SOURCES} - pal_swiftbindings.o pal_keychain_macos.c pal_seckey_macos.c pal_trust_macos.c @@ -42,16 +42,44 @@ endif() # As of CMake 3.20.2 support for Swift only works with the Ninja and XCode # generators so we cannot rely on it. Even with the Ninja generator it doesn't # work in combination with other languages within the same library. -if (NOT SWIFT_COMPILER_TARGET AND CLR_CMAKE_TARGET_OSX) - set(SWIFT_PLATFORM "macosx") - set(SWIFT_PLATFORM_SUFFIX "") - set(SWIFT_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET}) - set(SWIFT_COMPILER_TARGET "${CMAKE_OSX_ARCHITECTURES}-apple-${SWIFT_PLATFORM}${SWIFT_DEPLOYMENT_TARGET}${SWIFT_PLATFORM_SUFFIX}") +if (NOT SWIFT_COMPILER_TARGET) + + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(SWIFT_OPTIMIZATION_FLAG "-Onone") + elseif (CMAKE_BUILD_TYPE STREQUAL "Release") + set(SWIFT_OPTIMIZATION_FLAG "-O") + endif() + + if (CLR_CMAKE_TARGET_MACCATALYST) + # this is set in configurecompiler.cmake + set(SWIFT_COMPILER_TARGET ${CLR_CMAKE_MACCATALYST_COMPILER_TARGET}) + else() + set(SWIFT_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET}) + set(SWIFT_PLATFORM_SUFFIX "") + + if (CLR_CMAKE_TARGET_OSX) + set(SWIFT_PLATFORM "macosx") + elseif (CLR_CMAKE_TARGET_IOS) + set(SWIFT_PLATFORM "ios") + if (CMAKE_OSX_SYSROOT MATCHES iPhoneSimulator) + set(SWIFT_PLATFORM_SUFFIX "-simulator") + endif() + elseif (CLR_CMAKE_TARGET_TVOS) + set(SWIFT_PLATFORM "tvos") + if (CMAKE_OSX_SYSROOT MATCHES AppleTVSimulator) + set(SWIFT_PLATFORM_SUFFIX "-simulator") + endif() + else() + message(FATAL_ERROR "Unknown platform") + endif() + + set(SWIFT_COMPILER_TARGET "${CMAKE_OSX_ARCHITECTURES}-apple-${SWIFT_PLATFORM}${SWIFT_DEPLOYMENT_TARGET}${SWIFT_PLATFORM_SUFFIX}") + endif() endif() add_custom_command( OUTPUT pal_swiftbindings.o - COMMAND xcrun swiftc -emit-object -static -parse-as-library -enable-library-evolution -g -runtime-compatibility-version none -sdk ${CMAKE_OSX_SYSROOT} -target ${SWIFT_COMPILER_TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/pal_swiftbindings.swift -o pal_swiftbindings.o + COMMAND xcrun swiftc -emit-object -static -parse-as-library -enable-library-evolution -g ${SWIFT_OPTIMIZATION_FLAG} -runtime-compatibility-version none -sdk ${CMAKE_OSX_SYSROOT} -target ${SWIFT_COMPILER_TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/pal_swiftbindings.swift -o pal_swiftbindings.o MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/pal_swiftbindings.swift COMMENT "Compiling Swift file pal_swiftbindings.swift" ) diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/extra_libs.cmake b/src/native/libs/System.Security.Cryptography.Native.Apple/extra_libs.cmake index 07b595bd6e4c2b..d220db67479ac5 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/extra_libs.cmake +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/extra_libs.cmake @@ -2,12 +2,7 @@ macro(append_extra_cryptography_apple_libs NativeLibsExtra) find_library(COREFOUNDATION_LIBRARY CoreFoundation) find_library(SECURITY_LIBRARY Security) + find_library(CRYPTOKIT_LIBRARY CryptoKit) - list(APPEND ${NativeLibsExtra} ${COREFOUNDATION_LIBRARY} ${SECURITY_LIBRARY}) - - if (CLR_CMAKE_TARGET_OSX) - find_library(CRYPTOKIT_LIBRARY CryptoKit) - - list(APPEND ${NativeLibsExtra} ${CRYPTOKIT_LIBRARY} -L/usr/lib/swift -lobjc -lswiftCore -lswiftFoundation) - endif() + list(APPEND ${NativeLibsExtra} ${COREFOUNDATION_LIBRARY} ${SECURITY_LIBRARY} ${CRYPTOKIT_LIBRARY} -L/usr/lib/swift -lobjc -lswiftCore -lswiftFoundation) endmacro() diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift index 92d461886730bb..70a7176c7d7790 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift @@ -21,6 +21,7 @@ protocol SealedBoxProtocol { ) throws where C : DataProtocol, T : DataProtocol } +@available(iOS 13, tvOS 13, *) protocol AEADSymmetricAlgorithm { associatedtype SealedBox : SealedBoxProtocol @@ -30,18 +31,29 @@ protocol AEADSymmetricAlgorithm { static func open(_ sealedBox: SealedBox, using key: SymmetricKey) throws -> Data } +@available(iOS 13, tvOS 13, *) extension AES.GCM.Nonce: NonceProtocol {} + +@available(iOS 13, tvOS 13, *) extension AES.GCM.SealedBox: SealedBoxProtocol { typealias Nonce = AES.GCM.Nonce } + +@available(iOS 13, tvOS 13, *) extension AES.GCM: AEADSymmetricAlgorithm {} +@available(iOS 13, tvOS 13, *) extension ChaChaPoly.Nonce: NonceProtocol {} + +@available(iOS 13, tvOS 13, *) extension ChaChaPoly.SealedBox: SealedBoxProtocol { typealias Nonce = ChaChaPoly.Nonce } + +@available(iOS 13, tvOS 13, *) extension ChaChaPoly: AEADSymmetricAlgorithm {} +@available(iOS 13, tvOS 13, *) func encrypt( _ algorithm: Algorithm.Type, key: UnsafeBufferPointer, @@ -67,6 +79,7 @@ func encrypt( _ = resultTag.copyBytes(to: tag) } +@available(iOS 13, tvOS 13, *) func decrypt( _ algorithm: Algorithm.Type, key: UnsafeBufferPointer, @@ -88,6 +101,7 @@ func decrypt( } @_silgen_name("AppleCryptoNative_ChaCha20Poly1305Encrypt") +@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_ChaCha20Poly1305Encrypt( key: UnsafeBufferPointer, nonceData: UnsafeBufferPointer, @@ -107,6 +121,7 @@ public func AppleCryptoNative_ChaCha20Poly1305Encrypt( } @_silgen_name("AppleCryptoNative_ChaCha20Poly1305Decrypt") +@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_ChaCha20Poly1305Decrypt( key: UnsafeBufferPointer, nonceData: UnsafeBufferPointer, @@ -126,6 +141,7 @@ public func AppleCryptoNative_ChaCha20Poly1305Decrypt( } @_silgen_name("AppleCryptoNative_AesGcmEncrypt") +@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_AesGcmEncrypt( key: UnsafeBufferPointer, nonceData: UnsafeBufferPointer, @@ -145,6 +161,7 @@ public func AppleCryptoNative_AesGcmEncrypt( } @_silgen_name("AppleCryptoNative_AesGcmDecrypt") +@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_AesGcmDecrypt( key: UnsafeBufferPointer, nonceData: UnsafeBufferPointer, @@ -164,6 +181,7 @@ public func AppleCryptoNative_AesGcmDecrypt( } @_silgen_name("AppleCryptoNative_IsAuthenticationFailure") +@available(iOS 13, tvOS 13, *) public func AppleCryptoNative_IsAuthenticationFailure(error: Error) -> Bool { if let error = error as? CryptoKitError { switch error { diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template index 2b40c6dd1b4efc..782674abfea90a 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template @@ -62,11 +62,15 @@ target_link_libraries( PRIVATE "-framework Foundation" "-framework Security" + "-framework CryptoKit" "-framework UIKit" "-lz" "-lc++" "-liconv" "-licucore" + "-L/usr/lib/swift" + "-lswiftCore" + "-lswiftFoundation" %NativeLibrariesToLink% %APP_LINK_LIBRARIES% ) diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template index 614d9a7cf64fbe..f34ee5d1b15ae7 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template @@ -71,11 +71,15 @@ target_link_libraries( PRIVATE "-framework Foundation" "-framework Security" + "-framework CryptoKit" "-framework UIKit" "-lz" "-lc++" "-liconv" "-licucore" + "-L/usr/lib/swift" + "-lswiftCore" + "-lswiftFoundation" %NativeLibrariesToLink% %APP_LINK_LIBRARIES% ) diff --git a/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template b/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template index 51c00ad72a9164..028288a8ee41a9 100644 --- a/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template @@ -43,11 +43,15 @@ elseif(TARGETS_APPLE_MOBILE) set(MOBILE_SYSTEM_LIBS "-framework Foundation" "-framework Security" + "-framework CryptoKit" "-framework UIKit" "-lz" "-lc++" "-licucore" "-liconv" + "-L/usr/lib/swift" + "-lswiftCore" + "-lswiftFoundation" ) add_definitions(-DHOST_APPLE_MOBILE=1) add_definitions(-fPIC)