From e8c4169b4fc4eb9a71f296b3bd2e96db16d32d35 Mon Sep 17 00:00:00 2001 From: Jeremy Barton Date: Thu, 23 Jul 2020 08:19:04 -0700 Subject: [PATCH] Fix CNG persisted symmetric key operations During a code cleanup the encoding changed from UTF-16LE to UTF-8, which is not valid for the P/Invoke. --- .../src/Internal/Cryptography/BasicSymmetricCipherNCrypt.cs | 4 ++-- src/libraries/System.Security.Cryptography.Cng/tests/AesCngTests.cs | 3 --- .../System.Security.Cryptography.Cng/tests/TripleDESCngTests.cs | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Security.Cryptography.Cng/src/Internal/Cryptography/BasicSymmetricCipherNCrypt.cs b/src/libraries/System.Security.Cryptography.Cng/src/Internal/Cryptography/BasicSymmetricCipherNCrypt.cs index 4775435..9b88e7e 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/Internal/Cryptography/BasicSymmetricCipherNCrypt.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/Internal/Cryptography/BasicSymmetricCipherNCrypt.cs @@ -112,8 +112,8 @@ namespace Internal.Cryptography private readonly bool _encrypting; private static readonly CngProperty s_ECBMode = - new CngProperty(Interop.NCrypt.NCRYPT_CHAINING_MODE_PROPERTY, Encoding.UTF8.GetBytes(Interop.BCrypt.BCRYPT_CHAIN_MODE_ECB + "\0"), CngPropertyOptions.None); + new CngProperty(Interop.NCrypt.NCRYPT_CHAINING_MODE_PROPERTY, Encoding.Unicode.GetBytes(Interop.BCrypt.BCRYPT_CHAIN_MODE_ECB + "\0"), CngPropertyOptions.None); private static readonly CngProperty s_CBCMode = - new CngProperty(Interop.NCrypt.NCRYPT_CHAINING_MODE_PROPERTY, Encoding.UTF8.GetBytes(Interop.BCrypt.BCRYPT_CHAIN_MODE_CBC + "\0"), CngPropertyOptions.None); + new CngProperty(Interop.NCrypt.NCRYPT_CHAINING_MODE_PROPERTY, Encoding.Unicode.GetBytes(Interop.BCrypt.BCRYPT_CHAIN_MODE_CBC + "\0"), CngPropertyOptions.None); } } diff --git a/src/libraries/System.Security.Cryptography.Cng/tests/AesCngTests.cs b/src/libraries/System.Security.Cryptography.Cng/tests/AesCngTests.cs index abd62a6..981242f 100644 --- a/src/libraries/System.Security.Cryptography.Cng/tests/AesCngTests.cs +++ b/src/libraries/System.Security.Cryptography.Cng/tests/AesCngTests.cs @@ -11,7 +11,6 @@ namespace System.Security.Cryptography.Cng.Tests private static readonly CngAlgorithm s_cngAlgorithm = new CngAlgorithm("AES"); - [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")] [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)] [ConditionalTheory(nameof(SupportsPersistedSymmetricKeys))] // AES128-ECB-NoPadding 2 blocks. @@ -48,7 +47,6 @@ namespace System.Security.Cryptography.Cng.Tests keyName => new AesCng(keyName)); } - [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")] [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)] [ConditionalFact(nameof(SupportsPersistedSymmetricKeys))] public static void SetKey_DetachesFromPersistedKey() @@ -75,7 +73,6 @@ namespace System.Security.Cryptography.Cng.Tests } } - [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")] [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)] [ConditionalFact(nameof(SupportsPersistedSymmetricKeys), nameof(IsAdministrator))] public static void VerifyMachineKey() diff --git a/src/libraries/System.Security.Cryptography.Cng/tests/TripleDESCngTests.cs b/src/libraries/System.Security.Cryptography.Cng/tests/TripleDESCngTests.cs index 6abee43..60934e5 100644 --- a/src/libraries/System.Security.Cryptography.Cng/tests/TripleDESCngTests.cs +++ b/src/libraries/System.Security.Cryptography.Cng/tests/TripleDESCngTests.cs @@ -11,7 +11,6 @@ namespace System.Security.Cryptography.Cng.Tests private static readonly CngAlgorithm s_cngAlgorithm = new CngAlgorithm("3DES"); - [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")] [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)] [ConditionalTheory(nameof(SupportsPersistedSymmetricKeys))] // 3DES192-ECB-NoPadding 2 blocks. @@ -46,7 +45,6 @@ namespace System.Security.Cryptography.Cng.Tests keyName => new TripleDESCng(keyName)); } - [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")] [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)] [ConditionalFact(nameof(SupportsPersistedSymmetricKeys))] public static void SetKey_DetachesFromPersistedKey() @@ -73,7 +71,6 @@ namespace System.Security.Cryptography.Cng.Tests } } - [ActiveIssue("https://github.com/dotnet/runtime/issues/31092")] [OuterLoop(/* Creates/Deletes a persisted key, limit exposure to key leaking */)] [ConditionalFact(nameof(SupportsPersistedSymmetricKeys), nameof(IsAdministrator))] public static void VerifyMachineKey() -- 2.7.4