From 33fa06a25c8823cd3f73185573831ed6f769fbd9 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 1 Apr 2015 11:54:24 -0700 Subject: [PATCH 1/2] Fixing dataprotection on IIS Fixes: https://github.com/aspnet/DataProtection/issues/73 On IIS where there is no user profile, the code tries to always read the 32bit registry view irrespective of the bitness of the worker process. So in case of 64 bit app pools the registry key is null so it falls back to in memory ephemeral repository. On 32 bit app pool it can find an appropriate registry key, but the keyRepositoryDescriptor is not populated resulting in a null reference exception. Current behavior: X86 throws X64 falls back to in memory ephemeral With fix: Both X86 and X64 will use DPAPI. --- src/Microsoft.AspNet.DataProtection/DataProtectionServices.cs | 1 + .../Repositories/RegistryXmlRepository.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.DataProtection/DataProtectionServices.cs b/src/Microsoft.AspNet.DataProtection/DataProtectionServices.cs index 7fd92d7c41..32b5d78d01 100644 --- a/src/Microsoft.AspNet.DataProtection/DataProtectionServices.cs +++ b/src/Microsoft.AspNet.DataProtection/DataProtectionServices.cs @@ -89,6 +89,7 @@ namespace Microsoft.Framework.DependencyInjection { // If the user profile isn't available, we can protect using DPAPI (to machine). keyEncryptorDescriptor = DataProtectionServiceDescriptors.IXmlEncryptor_Dpapi(protectToMachine: true); + keyRepositoryDescriptor = DataProtectionServiceDescriptors.IXmlRepository_Registry(regKeyStorageKey); if (log.IsInformationLevelEnabled()) { diff --git a/src/Microsoft.AspNet.DataProtection/Repositories/RegistryXmlRepository.cs b/src/Microsoft.AspNet.DataProtection/Repositories/RegistryXmlRepository.cs index 9e0d036ef7..be466325bd 100644 --- a/src/Microsoft.AspNet.DataProtection/Repositories/RegistryXmlRepository.cs +++ b/src/Microsoft.AspNet.DataProtection/Repositories/RegistryXmlRepository.cs @@ -91,8 +91,9 @@ namespace Microsoft.AspNet.DataProtection.Repositories { try { + var registryView = IntPtr.Size == 4 ? RegistryView.Registry32 : RegistryView.Registry64; // Try reading the auto-generated machine key from HKLM - using (var hklmBaseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) + using (var hklmBaseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView)) { // Even though this is in HKLM, WAS ensures that applications hosted in IIS are properly isolated. // See APP_POOL::EnsureSharedMachineKeyStorage in WAS source for more info. From 19567ad39d151461061303b1a4041619233faf74 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Thu, 2 Apr 2015 13:49:24 -0700 Subject: [PATCH 2/2] Update .xproj files for Microsoft.Web.AspNet.* -> Microsoft.DNX.* rename --- .../Microsoft.AspNet.Cryptography.Internal.xproj | 6 +++--- .../Microsoft.AspNet.Cryptography.KeyDerivation.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.Extensions.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.Interfaces.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.Shared.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.SystemWeb.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.xproj | 6 +++--- .../Microsoft.AspNet.Cryptography.Internal.Test.xproj | 6 +++--- .../Microsoft.AspNet.Cryptography.KeyDerivation.Test.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.Extensions.Test.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.Interfaces.Test.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.Test.Shared.xproj | 6 +++--- .../Microsoft.AspNet.DataProtection.Test.xproj | 6 +++--- 13 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Microsoft.AspNet.Cryptography.Internal/Microsoft.AspNet.Cryptography.Internal.xproj b/src/Microsoft.AspNet.Cryptography.Internal/Microsoft.AspNet.Cryptography.Internal.xproj index 37f5345c21..dc81e9f0a7 100644 --- a/src/Microsoft.AspNet.Cryptography.Internal/Microsoft.AspNet.Cryptography.Internal.xproj +++ b/src/Microsoft.AspNet.Cryptography.Internal/Microsoft.AspNet.Cryptography.Internal.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + E2779976-A28C-4365-A4BB-4AD854FAF23E ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Cryptography.KeyDerivation/Microsoft.AspNet.Cryptography.KeyDerivation.xproj b/src/Microsoft.AspNet.Cryptography.KeyDerivation/Microsoft.AspNet.Cryptography.KeyDerivation.xproj index 122f0410ea..be90ea0857 100644 --- a/src/Microsoft.AspNet.Cryptography.KeyDerivation/Microsoft.AspNet.Cryptography.KeyDerivation.xproj +++ b/src/Microsoft.AspNet.Cryptography.KeyDerivation/Microsoft.AspNet.Cryptography.KeyDerivation.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 421F0383-34B1-402D-807B-A94542513ABA ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.DataProtection.Extensions/Microsoft.AspNet.DataProtection.Extensions.xproj b/src/Microsoft.AspNet.DataProtection.Extensions/Microsoft.AspNet.DataProtection.Extensions.xproj index 5497c05b2f..772fd0d3ca 100644 --- a/src/Microsoft.AspNet.DataProtection.Extensions/Microsoft.AspNet.DataProtection.Extensions.xproj +++ b/src/Microsoft.AspNet.DataProtection.Extensions/Microsoft.AspNet.DataProtection.Extensions.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + bf8681db-c28b-441f-bd92-0dcfe9537a9f ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.DataProtection.Interfaces/Microsoft.AspNet.DataProtection.Interfaces.xproj b/src/Microsoft.AspNet.DataProtection.Interfaces/Microsoft.AspNet.DataProtection.Interfaces.xproj index 2937e9a8f7..6c3aba85d2 100644 --- a/src/Microsoft.AspNet.DataProtection.Interfaces/Microsoft.AspNet.DataProtection.Interfaces.xproj +++ b/src/Microsoft.AspNet.DataProtection.Interfaces/Microsoft.AspNet.DataProtection.Interfaces.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 4b115bde-b253-46a6-97bf-a8b37b344ff2 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.DataProtection.Shared/Microsoft.AspNet.DataProtection.Shared.xproj b/src/Microsoft.AspNet.DataProtection.Shared/Microsoft.AspNet.DataProtection.Shared.xproj index 081f013085..29f937796f 100644 --- a/src/Microsoft.AspNet.DataProtection.Shared/Microsoft.AspNet.DataProtection.Shared.xproj +++ b/src/Microsoft.AspNet.DataProtection.Shared/Microsoft.AspNet.DataProtection.Shared.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 3277bb22-033f-4010-8131-a515b910caad ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.DataProtection.SystemWeb/Microsoft.AspNet.DataProtection.SystemWeb.xproj b/src/Microsoft.AspNet.DataProtection.SystemWeb/Microsoft.AspNet.DataProtection.SystemWeb.xproj index 07283ae05e..8ac91a07c5 100644 --- a/src/Microsoft.AspNet.DataProtection.SystemWeb/Microsoft.AspNet.DataProtection.SystemWeb.xproj +++ b/src/Microsoft.AspNet.DataProtection.SystemWeb/Microsoft.AspNet.DataProtection.SystemWeb.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + e3552deb-4173-43ae-bf69-3c10dff3bab6 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.DataProtection/Microsoft.AspNet.DataProtection.xproj b/src/Microsoft.AspNet.DataProtection/Microsoft.AspNet.DataProtection.xproj index 885bbdd20e..4a0c8dd84d 100644 --- a/src/Microsoft.AspNet.DataProtection/Microsoft.AspNet.DataProtection.xproj +++ b/src/Microsoft.AspNet.DataProtection/Microsoft.AspNet.DataProtection.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 1e570cd4-6f12-44f4-961e-005ee2002bc2 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Cryptography.Internal.Test/Microsoft.AspNet.Cryptography.Internal.Test.xproj b/test/Microsoft.AspNet.Cryptography.Internal.Test/Microsoft.AspNet.Cryptography.Internal.Test.xproj index bf71fe331c..eff850ff50 100644 --- a/test/Microsoft.AspNet.Cryptography.Internal.Test/Microsoft.AspNet.Cryptography.Internal.Test.xproj +++ b/test/Microsoft.AspNet.Cryptography.Internal.Test/Microsoft.AspNet.Cryptography.Internal.Test.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 37053d5f-5b61-47ce-8b72-298ce007ffb0 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Cryptography.KeyDerivation.Test/Microsoft.AspNet.Cryptography.KeyDerivation.Test.xproj b/test/Microsoft.AspNet.Cryptography.KeyDerivation.Test/Microsoft.AspNet.Cryptography.KeyDerivation.Test.xproj index 02588fc1d9..e81126fdab 100644 --- a/test/Microsoft.AspNet.Cryptography.KeyDerivation.Test/Microsoft.AspNet.Cryptography.KeyDerivation.Test.xproj +++ b/test/Microsoft.AspNet.Cryptography.KeyDerivation.Test/Microsoft.AspNet.Cryptography.KeyDerivation.Test.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 42c97f52-8d56-46bd-a712-4f22bed157a7 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.DataProtection.Extensions.Test/Microsoft.AspNet.DataProtection.Extensions.Test.xproj b/test/Microsoft.AspNet.DataProtection.Extensions.Test/Microsoft.AspNet.DataProtection.Extensions.Test.xproj index 58119f15de..177bce8e44 100644 --- a/test/Microsoft.AspNet.DataProtection.Extensions.Test/Microsoft.AspNet.DataProtection.Extensions.Test.xproj +++ b/test/Microsoft.AspNet.DataProtection.Extensions.Test/Microsoft.AspNet.DataProtection.Extensions.Test.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 04aa8e60-a053-4d50-89fe-e76c3df45200 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.DataProtection.Interfaces.Test/Microsoft.AspNet.DataProtection.Interfaces.Test.xproj b/test/Microsoft.AspNet.DataProtection.Interfaces.Test/Microsoft.AspNet.DataProtection.Interfaces.Test.xproj index 85d49cd927..20fb10d4b3 100644 --- a/test/Microsoft.AspNet.DataProtection.Interfaces.Test/Microsoft.AspNet.DataProtection.Interfaces.Test.xproj +++ b/test/Microsoft.AspNet.DataProtection.Interfaces.Test/Microsoft.AspNet.DataProtection.Interfaces.Test.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + ff650a69-dee4-4b36-9e30-264ee7cfb478 ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.DataProtection.Test.Shared/Microsoft.AspNet.DataProtection.Test.Shared.xproj b/test/Microsoft.AspNet.DataProtection.Test.Shared/Microsoft.AspNet.DataProtection.Test.Shared.xproj index 35909b7c73..f67c2328f8 100644 --- a/test/Microsoft.AspNet.DataProtection.Test.Shared/Microsoft.AspNet.DataProtection.Test.Shared.xproj +++ b/test/Microsoft.AspNet.DataProtection.Test.Shared/Microsoft.AspNet.DataProtection.Test.Shared.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 4f14ba2a-4f04-4676-8586-ec380977ee2e ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.DataProtection.Test/Microsoft.AspNet.DataProtection.Test.xproj b/test/Microsoft.AspNet.DataProtection.Test/Microsoft.AspNet.DataProtection.Test.xproj index 66ecc0ff24..da168e5304 100644 --- a/test/Microsoft.AspNet.DataProtection.Test/Microsoft.AspNet.DataProtection.Test.xproj +++ b/test/Microsoft.AspNet.DataProtection.Test/Microsoft.AspNet.DataProtection.Test.xproj @@ -4,7 +4,7 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 7a637185-2ba1-437d-9d4c-7cc4f94cf7bf ..\..\artifacts\obj\$(MSBuildProjectName) @@ -13,5 +13,5 @@ 2.0 - - + + \ No newline at end of file