Target .NET Standard 2.0
This retargets all data protection libraries to ns2.0. This means .NET Framework applications will need to upgrade to .NET Framework 4.6.1. This upgrade makes available API to .NET Core that was previously only available on .NET Framework, such as encrypting keys at rest with certificates. New API for .NET Core users: - IDataProtectionBuilder.ProtectKeysWithCertificate(string thumbprint) - CertificateXmlEncryptor - ICertificateResolver - DataProtectionProvider - .Create(string applicationName, X509Certificate2 certificate) - .Create(DirectoryInfo keyDirectory, X509Certificate2 certificate) - .Create(DirectoryInfo keyDirectory, Action<IDataProtectionBuilder> setupAction, X509Certificate2 certificate Other minor changes in this commit: - Fixed samples that were using obsolete logging API - Remove calls to api-sets, instead using kernel32. .NET Core 2.0 no longer requires using api-sets as Nano Server now forwards kernel32 calls - Made minor improvements to the TypeForwardingActivator - Remove dead code an unused api baselines - Enable more tests on macOS/Linux that previously only ran on Windows
This commit is contained in:
parent
f70e17c138
commit
b706a75e03
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26228.4
|
||||
VisualStudioVersion = 15.0.26504.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5FCB2DA3-5395-47F5-BCEE-E0EA319448EA}"
|
||||
EndProject
|
||||
|
|
@ -11,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{5A3A
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E1D86B1B-41D8-43C9-97FD-C2BF65C414E2}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
build\common.props = build\common.props
|
||||
build\dependencies.props = build\dependencies.props
|
||||
NuGet.config = NuGet.config
|
||||
EndProjectSection
|
||||
EndProject
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(InternalAspNetCoreSdkVersion)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework' AND '$(OutputType)'=='library'">
|
||||
<PackageReference Include="NETStandard.Library" Version="$(BundledNETStandardPackageVersion)" />
|
||||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
|
||||
<CoreFxVersion>4.3.0</CoreFxVersion>
|
||||
<CoreFxVersion>4.4.0-*</CoreFxVersion>
|
||||
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
|
||||
<MoqVersion>4.7.1</MoqVersion>
|
||||
<NETStandardImplicitPackageVersion>$(BundledNETStandardPackageVersion)</NETStandardImplicitPackageVersion>
|
||||
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
|
||||
<RedisVersion>1.2.3</RedisVersion>
|
||||
<TestSdkVersion>15.3.0-*</TestSdkVersion>
|
||||
<XunitVersion>2.3.0-beta2-*</XunitVersion>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81</PackageTargetFallback>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ namespace AzureBlob
|
|||
.PersistKeysToAzureBlobStorage(container, "keys.xml");
|
||||
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
var loggerFactory = services.GetService<ILoggerFactory>();
|
||||
loggerFactory.AddConsole(Microsoft.Extensions.Logging.LogLevel.Trace);
|
||||
var loggerFactory = services.GetService<LoggerFactory>();
|
||||
loggerFactory.AddConsole();
|
||||
|
||||
// Run a sample payload
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\dependencies.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
|
||||
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -16,4 +16,8 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ namespace CustomEncryptorSample
|
|||
.UseXmlEncryptor(s => new CustomXmlEncryptor(s));
|
||||
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
var loggerFactory = services.GetRequiredService<ILoggerFactory>();
|
||||
var loggerFactory = services.GetRequiredService<LoggerFactory>();
|
||||
loggerFactory.AddConsole();
|
||||
|
||||
var protector = services.GetDataProtector("SamplePurpose");
|
||||
|
||||
|
||||
// protect the payload
|
||||
var protectedPayload = protector.Protect("Hello World!");
|
||||
Console.WriteLine($"Protect returned: {protectedPayload}");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\dependencies.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
|
||||
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -11,4 +11,8 @@
|
|||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection.Extensions\Microsoft.AspNetCore.DataProtection.Extensions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\dependencies.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
|
||||
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -11,4 +11,8 @@
|
|||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection.Extensions\Microsoft.AspNetCore.DataProtection.Extensions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ namespace Redis
|
|||
.PersistKeysToRedis(redis, "DataProtection-Keys");
|
||||
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
var loggerFactory = services.GetService<ILoggerFactory>();
|
||||
loggerFactory.AddConsole(LogLevel.Trace);
|
||||
var loggerFactory = services.GetService<LoggerFactory>();
|
||||
loggerFactory.AddConsole();
|
||||
|
||||
// Run a sample payload
|
||||
var protector = services.GetDataProtector("sample-purpose");
|
||||
|
|
@ -32,4 +32,4 @@ namespace Redis
|
|||
Console.WriteLine(protectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\dependencies.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -16,4 +16,8 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -4,15 +4,12 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.AspNetCore.Cryptography.Cng;
|
||||
using Microsoft.AspNetCore.Cryptography.Internal;
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.AspNetCore.Cryptography
|
||||
{
|
||||
internal unsafe static class CryptoUtil
|
||||
|
|
@ -73,12 +70,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
|
||||
#if NET46
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
public static bool TimeConstantBuffersAreEqual(byte* bufA, byte* bufB, uint count)
|
||||
{
|
||||
bool areEqual = true;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Infrastructure for ASP.NET Core cryptographic packages. Applications and libraries should not reference this package directly.</Description>
|
||||
<TargetFrameworks>net46;netstandard1.3</TargetFrameworks>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
|
|
|||
|
|
@ -1,30 +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.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
namespace Microsoft.Win32.SafeHandles
|
||||
{
|
||||
internal abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle
|
||||
{
|
||||
// Called by P/Invoke when returning SafeHandles
|
||||
protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle)
|
||||
: base(IntPtr.Zero, ownsHandle)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return (handle == IntPtr.Zero || handle == (IntPtr)(-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif NET46
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
|
@ -2,14 +2,11 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.AspNetCore.Cryptography.SafeHandles
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -127,31 +124,11 @@ namespace Microsoft.AspNetCore.Cryptography.SafeHandles
|
|||
return UnsafeNativeMethods.FreeLibrary(handle);
|
||||
}
|
||||
|
||||
#if NET46
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
private static class UnsafeNativeMethods
|
||||
{
|
||||
#if NETSTANDARD1_3
|
||||
private const string CORE_LIBRARY_LOADER_LIB = "api-ms-win-core-libraryloader-l1-1-0.dll";
|
||||
private const string CORE_LOCALIZATION_LIB = "api-ms-win-core-localization-l1-2-0.dll";
|
||||
#elif NET46
|
||||
private const string KERNEL32_LIB = "kernel32.dll";
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx
|
||||
#if NETSTANDARD1_3
|
||||
[DllImport(CORE_LOCALIZATION_LIB, EntryPoint = "FormatMessageW", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
#elif NET46
|
||||
[DllImport(KERNEL32_LIB, EntryPoint = "FormatMessageW", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
[DllImport("kernel32.dll", EntryPoint = "FormatMessageW", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern int FormatMessage(
|
||||
[In] uint dwFlags,
|
||||
[In] SafeLibraryHandle lpSource,
|
||||
|
|
@ -164,50 +141,26 @@ namespace Microsoft.AspNetCore.Cryptography.SafeHandles
|
|||
|
||||
// http://msdn.microsoft.com/en-us/library/ms683152(v=vs.85).aspx
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
#if NETSTANDARD1_3
|
||||
[DllImport(CORE_LIBRARY_LOADER_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
|
||||
#elif NET46
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
[DllImport("kernel32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
|
||||
internal static extern bool FreeLibrary(IntPtr hModule);
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/ms683200(v=vs.85).aspx
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
#if NETSTANDARD1_3
|
||||
[DllImport(CORE_LIBRARY_LOADER_LIB, EntryPoint = "GetModuleHandleExW", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
#elif NET46
|
||||
[DllImport(KERNEL32_LIB, EntryPoint = "GetModuleHandleExW", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
[DllImport("kernel32.dll", EntryPoint = "GetModuleHandleExW", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
internal static extern bool GetModuleHandleEx(
|
||||
[In] uint dwFlags,
|
||||
[In] SafeLibraryHandle lpModuleName, // can point to a location within the module if GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS is set
|
||||
[Out] out IntPtr phModule);
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx
|
||||
#if NETSTANDARD1_3
|
||||
[DllImport(CORE_LIBRARY_LOADER_LIB, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
#elif NET46
|
||||
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
[DllImport("kernel32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
internal static extern IntPtr GetProcAddress(
|
||||
[In] SafeLibraryHandle hModule,
|
||||
[In, MarshalAs(UnmanagedType.LPStr)] string lpProcName);
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx
|
||||
#if NETSTANDARD1_3
|
||||
[DllImport(CORE_LIBRARY_LOADER_LIB, EntryPoint = "LoadLibraryExW", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
#elif NET46
|
||||
[DllImport(KERNEL32_LIB, EntryPoint = "LoadLibraryExW", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
[DllImport("kernel32.dll", EntryPoint = "LoadLibraryExW", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
internal static extern SafeLibraryHandle LoadLibraryEx(
|
||||
[In, MarshalAs(UnmanagedType.LPWStr)] string lpFileName,
|
||||
[In] IntPtr hFile,
|
||||
|
|
|
|||
|
|
@ -3,10 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.AspNetCore.Cryptography.SafeHandles
|
||||
{
|
||||
|
|
@ -41,12 +38,7 @@ namespace Microsoft.AspNetCore.Cryptography.SafeHandles
|
|||
return newHandle;
|
||||
}
|
||||
|
||||
#if NET46
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
private void AllocateImpl(IntPtr cb)
|
||||
{
|
||||
handle = Marshal.AllocHGlobal(cb); // actually calls LocalAlloc
|
||||
|
|
|
|||
|
|
@ -3,30 +3,23 @@
|
|||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.Cryptography.SafeHandles;
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.AspNetCore.Cryptography
|
||||
{
|
||||
internal unsafe static class UnsafeBufferUtil
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#endif
|
||||
public static void BlockCopy(void* from, void* to, int byteCount)
|
||||
{
|
||||
BlockCopy(from, to, checked((uint)byteCount)); // will be checked before invoking the delegate
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#endif
|
||||
public static void BlockCopy(void* from, void* to, uint byteCount)
|
||||
{
|
||||
if (byteCount != 0)
|
||||
|
|
@ -35,9 +28,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
}
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
#endif
|
||||
public static void BlockCopy(LocalAllocHandle from, void* to, uint byteCount)
|
||||
{
|
||||
bool refAdded = false;
|
||||
|
|
@ -55,9 +46,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
}
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
#endif
|
||||
public static void BlockCopy(void* from, LocalAllocHandle to, uint byteCount)
|
||||
{
|
||||
bool refAdded = false;
|
||||
|
|
@ -75,9 +64,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
}
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
#endif
|
||||
public static void BlockCopy(LocalAllocHandle from, LocalAllocHandle to, IntPtr length)
|
||||
{
|
||||
if (length == IntPtr.Zero)
|
||||
|
|
@ -116,36 +103,20 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void BlockCopyCore(byte* from, byte* to, uint byteCount)
|
||||
{
|
||||
#if NETSTANDARD1_3
|
||||
Buffer.MemoryCopy(from, to, (ulong)byteCount, (ulong)byteCount);
|
||||
#else
|
||||
while (byteCount-- != 0)
|
||||
{
|
||||
to[byteCount] = from[byteCount];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void BlockCopyCore(byte* from, byte* to, ulong byteCount)
|
||||
{
|
||||
#if NETSTANDARD1_3
|
||||
Buffer.MemoryCopy(from, to, byteCount, byteCount);
|
||||
#else
|
||||
while (byteCount-- != 0)
|
||||
{
|
||||
to[byteCount] = from[byteCount];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Securely clears a memory buffer.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#endif
|
||||
public static void SecureZeroMemory(byte* buffer, int byteCount)
|
||||
{
|
||||
SecureZeroMemory(buffer, checked((uint)byteCount));
|
||||
|
|
@ -155,9 +126,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
/// Securely clears a memory buffer.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#endif
|
||||
public static void SecureZeroMemory(byte* buffer, uint byteCount)
|
||||
{
|
||||
if (byteCount != 0)
|
||||
|
|
@ -176,9 +145,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
/// Securely clears a memory buffer.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#endif
|
||||
public static void SecureZeroMemory(byte* buffer, ulong byteCount)
|
||||
{
|
||||
if (byteCount != 0)
|
||||
|
|
@ -196,9 +163,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
/// <summary>
|
||||
/// Securely clears a memory buffer.
|
||||
/// </summary>
|
||||
#if !NETSTANDARD1_3
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#endif
|
||||
public static void SecureZeroMemory(byte* buffer, IntPtr length)
|
||||
{
|
||||
if (sizeof(IntPtr) == 4)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
|
|
@ -12,18 +13,9 @@ using Microsoft.AspNetCore.Cryptography.Cng;
|
|||
using Microsoft.AspNetCore.Cryptography.SafeHandles;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
#if NET46
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.AspNetCore.Cryptography
|
||||
{
|
||||
#if NET46
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
internal unsafe static class UnsafeNativeMethods
|
||||
{
|
||||
private const string BCRYPT_LIB = "bcrypt.dll";
|
||||
|
|
@ -90,23 +82,13 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
[In] uint dwFlags);
|
||||
|
||||
[DllImport(BCRYPT_LIB, CallingConvention = CallingConvention.Winapi)]
|
||||
#if NET46
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa375399(v=vs.85).aspx
|
||||
internal static extern int BCryptDestroyHash(
|
||||
[In] IntPtr hHash);
|
||||
|
||||
[DllImport(BCRYPT_LIB, CallingConvention = CallingConvention.Winapi)]
|
||||
#if NET46
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa375404(v=vs.85).aspx
|
||||
internal static extern int BCryptDestroyKey(
|
||||
[In] IntPtr hKey);
|
||||
|
|
@ -209,7 +191,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
/*
|
||||
* CRYPT32.DLL
|
||||
*/
|
||||
|
||||
|
||||
[DllImport(CRYPT32_LIB, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa380261(v=vs.85).aspx
|
||||
internal static extern bool CryptProtectData(
|
||||
|
|
@ -258,12 +240,7 @@ namespace Microsoft.AspNetCore.Cryptography
|
|||
*/
|
||||
|
||||
[DllImport(NCRYPT_LIB, CallingConvention = CallingConvention.Winapi)]
|
||||
#if NET46
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/hh706799(v=vs.85).aspx
|
||||
internal static extern int NCryptCloseProtectionDescriptor(
|
||||
[In] IntPtr hDescriptor);
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"AssemblyIdentity": "Microsoft.AspNetCore.Cryptography.Internal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
|
||||
"Types": []
|
||||
}
|
||||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>ASP.NET Core utilities for key derivation.</Description>
|
||||
<TargetFramework>netstandard1.3</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection</PackageTags>
|
||||
|
|
|
|||
|
|
@ -1,78 +0,0 @@
|
|||
{
|
||||
"AssemblyIdentity": "Microsoft.AspNetCore.Cryptography.KeyDerivation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
|
||||
"Types": [
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.Cryptography.KeyDerivation.KeyDerivation",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Abstract": true,
|
||||
"Static": true,
|
||||
"Sealed": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Pbkdf2",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "password",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "salt",
|
||||
"Type": "System.Byte[]"
|
||||
},
|
||||
{
|
||||
"Name": "prf",
|
||||
"Type": "Microsoft.AspNetCore.Cryptography.KeyDerivation.KeyDerivationPrf"
|
||||
},
|
||||
{
|
||||
"Name": "iterationCount",
|
||||
"Type": "System.Int32"
|
||||
},
|
||||
{
|
||||
"Name": "numBytesRequested",
|
||||
"Type": "System.Int32"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.Cryptography.KeyDerivation.KeyDerivationPrf",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Enumeration",
|
||||
"Sealed": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Field",
|
||||
"Name": "HMACSHA1",
|
||||
"Parameters": [],
|
||||
"GenericParameter": [],
|
||||
"Literal": "0"
|
||||
},
|
||||
{
|
||||
"Kind": "Field",
|
||||
"Name": "HMACSHA256",
|
||||
"Parameters": [],
|
||||
"GenericParameter": [],
|
||||
"Literal": "1"
|
||||
},
|
||||
{
|
||||
"Kind": "Field",
|
||||
"Name": "HMACSHA512",
|
||||
"Parameters": [],
|
||||
"GenericParameter": [],
|
||||
"Literal": "2"
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -7,8 +7,7 @@
|
|||
Commonly used types:
|
||||
Microsoft.AspNetCore.DataProtection.IDataProtectionProvider
|
||||
Microsoft.AspNetCore.DataProtection.IDataProtector</Description>
|
||||
<TargetFramework>netstandard1.3</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
|
@ -21,8 +20,4 @@ Microsoft.AspNetCore.DataProtection.IDataProtector</Description>
|
|||
<PackageReference Include="Microsoft.Extensions.WebEncoders.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
||||
<PackageReference Include="System.ComponentModel" Version="$(CoreFxVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,231 +0,0 @@
|
|||
{
|
||||
"AssemblyIdentity": "Microsoft.AspNetCore.DataProtection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
|
||||
"Types": [
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.DataProtectionCommonExtensions",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Abstract": true,
|
||||
"Static": true,
|
||||
"Sealed": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "CreateProtector",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "provider",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider"
|
||||
},
|
||||
{
|
||||
"Name": "purposes",
|
||||
"Type": "System.Collections.Generic.IEnumerable<System.String>"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtector",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "CreateProtector",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "provider",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider"
|
||||
},
|
||||
{
|
||||
"Name": "purpose",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "subPurposes",
|
||||
"Type": "System.String[]",
|
||||
"IsParams": true
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtector",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "GetDataProtectionProvider",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "services",
|
||||
"Type": "System.IServiceProvider"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "GetDataProtector",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "services",
|
||||
"Type": "System.IServiceProvider"
|
||||
},
|
||||
{
|
||||
"Name": "purposes",
|
||||
"Type": "System.Collections.Generic.IEnumerable<System.String>"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtector",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "GetDataProtector",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "services",
|
||||
"Type": "System.IServiceProvider"
|
||||
},
|
||||
{
|
||||
"Name": "purpose",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "subPurposes",
|
||||
"Type": "System.String[]",
|
||||
"IsParams": true
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtector",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Protect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protector",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.IDataProtector"
|
||||
},
|
||||
{
|
||||
"Name": "plaintext",
|
||||
"Type": "System.String"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.String",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Unprotect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protector",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.IDataProtector"
|
||||
},
|
||||
{
|
||||
"Name": "protectedData",
|
||||
"Type": "System.String"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.String",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Interface",
|
||||
"Abstract": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "CreateProtector",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "purpose",
|
||||
"Type": "System.String"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtector",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.IDataProtector",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Interface",
|
||||
"Abstract": true,
|
||||
"ImplementedInterfaces": [
|
||||
"Microsoft.AspNetCore.DataProtection.IDataProtectionProvider"
|
||||
],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Protect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "plaintext",
|
||||
"Type": "System.Byte[]"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Unprotect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protectedData",
|
||||
"Type": "System.Byte[]"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.Infrastructure.IApplicationDiscriminator",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Interface",
|
||||
"Abstract": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "get_Discriminator",
|
||||
"Parameters": [],
|
||||
"ReturnType": "System.String",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -51,6 +51,7 @@ namespace Microsoft.AspNetCore.DataProtection.AzureStorage
|
|||
_random = new Random();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<XElement> GetAllElements()
|
||||
{
|
||||
var blobRef = CreateFreshBlobRef();
|
||||
|
|
@ -62,6 +63,7 @@ namespace Microsoft.AspNetCore.DataProtection.AzureStorage
|
|||
return new ReadOnlyCollection<XElement>(elements);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void StoreElement(XElement element, string friendlyName)
|
||||
{
|
||||
if (element == null)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Microsoft Azure Blob storrage support as key store.</Description>
|
||||
<VersionPrefix>2.0.0</VersionPrefix>
|
||||
<TargetFrameworks>net46;netstandard1.5</TargetFrameworks>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection;azure;blob</PackageTags>
|
||||
|
|
@ -14,6 +12,9 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.DataProtection\Microsoft.AspNetCore.DataProtection.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="WindowsAzure.Storage" Version="$(WindowsAzureStorageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ using System;
|
|||
|
||||
namespace Microsoft.AspNetCore.DataProtection
|
||||
{
|
||||
/// <summary>
|
||||
/// Helpful extension methods for data protection APIs.
|
||||
/// </summary>
|
||||
public static class DataProtectionAdvancedExtensions
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
return CreateProvider(keyDirectory, setupAction, certificate: null);
|
||||
}
|
||||
|
||||
#if NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
/// <summary>
|
||||
/// Creates a <see cref="DataProtectionProvider"/> that store keys in a location based on
|
||||
/// the platform and operating system and uses the given <see cref="X509Certificate2"/> to encrypt the keys.
|
||||
|
|
@ -150,10 +149,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
|
||||
return CreateProvider(keyDirectory, setupAction, certificate);
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
private static IDataProtectionProvider CreateProvider(
|
||||
DirectoryInfo keyDirectory,
|
||||
|
|
@ -169,15 +164,10 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
builder.PersistKeysToFileSystem(keyDirectory);
|
||||
}
|
||||
|
||||
#if NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
if (certificate != null)
|
||||
{
|
||||
builder.ProtectKeysWithCertificate(certificate);
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
setupAction(builder);
|
||||
|
||||
|
|
@ -185,4 +175,4 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
return serviceCollection.BuildServiceProvider().GetRequiredService<IDataProtectionProvider>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Additional APIs for ASP.NET Core data protection.</Description>
|
||||
<TargetFrameworks>net46;netstandard1.3</TargetFrameworks>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
|
@ -16,6 +15,9 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.DataProtection\Microsoft.AspNetCore.DataProtection.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCoreVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -175,6 +175,64 @@
|
|||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "applicationName",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "keyDirectory",
|
||||
"Type": "System.IO.DirectoryInfo"
|
||||
},
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "keyDirectory",
|
||||
"Type": "System.IO.DirectoryInfo"
|
||||
},
|
||||
{
|
||||
"Name": "setupAction",
|
||||
"Type": "System.Action<Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder>"
|
||||
},
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
|
|
|
|||
|
|
@ -1,298 +0,0 @@
|
|||
{
|
||||
"AssemblyIdentity": "Microsoft.AspNetCore.DataProtection.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
|
||||
"Types": [
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.DataProtectionAdvancedExtensions",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Abstract": true,
|
||||
"Static": true,
|
||||
"Sealed": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Protect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protector",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.ITimeLimitedDataProtector"
|
||||
},
|
||||
{
|
||||
"Name": "plaintext",
|
||||
"Type": "System.Byte[]"
|
||||
},
|
||||
{
|
||||
"Name": "lifetime",
|
||||
"Type": "System.TimeSpan"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Protect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protector",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.ITimeLimitedDataProtector"
|
||||
},
|
||||
{
|
||||
"Name": "plaintext",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "expiration",
|
||||
"Type": "System.DateTimeOffset"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.String",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Protect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protector",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.ITimeLimitedDataProtector"
|
||||
},
|
||||
{
|
||||
"Name": "plaintext",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "lifetime",
|
||||
"Type": "System.TimeSpan"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.String",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ToTimeLimitedDataProtector",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protector",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.IDataProtector"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.ITimeLimitedDataProtector",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Unprotect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protector",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.ITimeLimitedDataProtector"
|
||||
},
|
||||
{
|
||||
"Name": "protectedData",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "expiration",
|
||||
"Type": "System.DateTimeOffset",
|
||||
"Direction": "Out"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.String",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.DataProtectionProvider",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Abstract": true,
|
||||
"Static": true,
|
||||
"Sealed": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "applicationName",
|
||||
"Type": "System.String"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "keyDirectory",
|
||||
"Type": "System.IO.DirectoryInfo"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "keyDirectory",
|
||||
"Type": "System.IO.DirectoryInfo"
|
||||
},
|
||||
{
|
||||
"Name": "setupAction",
|
||||
"Type": "System.Action<Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder>"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "applicationName",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "keyDirectory",
|
||||
"Type": "System.IO.DirectoryInfo"
|
||||
},
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Create",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "keyDirectory",
|
||||
"Type": "System.IO.DirectoryInfo"
|
||||
},
|
||||
{
|
||||
"Name": "setupAction",
|
||||
"Type": "System.Action<Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder>"
|
||||
},
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.ITimeLimitedDataProtector",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Interface",
|
||||
"Abstract": true,
|
||||
"ImplementedInterfaces": [
|
||||
"Microsoft.AspNetCore.DataProtection.IDataProtector"
|
||||
],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "CreateProtector",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "purpose",
|
||||
"Type": "System.String"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.ITimeLimitedDataProtector",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Protect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "plaintext",
|
||||
"Type": "System.Byte[]"
|
||||
},
|
||||
{
|
||||
"Name": "expiration",
|
||||
"Type": "System.DateTimeOffset"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Unprotect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "protectedData",
|
||||
"Type": "System.Byte[]"
|
||||
},
|
||||
{
|
||||
"Name": "expiration",
|
||||
"Type": "System.DateTimeOffset",
|
||||
"Direction": "Out"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -5,8 +5,7 @@
|
|||
<PropertyGroup>
|
||||
<Description>Redis storage support as key store.</Description>
|
||||
<VersionPrefix>0.3.0</VersionPrefix>
|
||||
<TargetFrameworks>net46;netstandard1.5</TargetFrameworks>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection;redis</PackageTags>
|
||||
|
|
@ -14,6 +13,9 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.DataProtection\Microsoft.AspNetCore.DataProtection.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StackExchange.Redis.StrongName" Version="$(RedisVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>A component to allow the ASP.NET Core data protection stack to work with the ASP.NET 4.x <machineKey> element.</Description>
|
||||
<TargetFramework>net46</TargetFramework>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnet;aspnetcore;dataprotection</PackageTags>
|
||||
|
|
@ -16,9 +16,11 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.DataProtection\Microsoft.AspNetCore.DataProtection.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCoreVersion)" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.Web" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -78,12 +78,8 @@ namespace Microsoft.AspNetCore.DataProtection.Cng
|
|||
};
|
||||
var dataOut = default(DATA_BLOB);
|
||||
|
||||
#if NET46
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
var success = UnsafeNativeMethods.CryptProtectData(
|
||||
|
|
@ -171,12 +167,9 @@ namespace Microsoft.AspNetCore.DataProtection.Cng
|
|||
fixed (byte* pbRetVal = retVal)
|
||||
{
|
||||
var handleAcquired = false;
|
||||
#if NET46
|
||||
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
protectedData.DangerousAddRef(ref handleAcquired);
|
||||
|
|
@ -224,12 +217,8 @@ namespace Microsoft.AspNetCore.DataProtection.Cng
|
|||
};
|
||||
var dataOut = default(DATA_BLOB);
|
||||
|
||||
#if NET46
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
var success = UnsafeNativeMethods.CryptUnprotectData(
|
||||
|
|
@ -300,12 +289,9 @@ namespace Microsoft.AspNetCore.DataProtection.Cng
|
|||
using (unencryptedPayloadHandle)
|
||||
{
|
||||
var handleAcquired = false;
|
||||
#if NET46
|
||||
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
unencryptedPayloadHandle.DangerousAddRef(ref handleAcquired);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.AspNetCore.Cryptography;
|
||||
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
|
|
@ -16,10 +17,6 @@ using Microsoft.Extensions.Logging;
|
|||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Win32;
|
||||
|
||||
#if NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.AspNetCore.DataProtection
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -249,8 +246,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
return builder;
|
||||
}
|
||||
|
||||
#if NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
|
||||
/// <summary>
|
||||
/// Configures keys to be encrypted to a given certificate before being persisted to storage.
|
||||
/// </summary>
|
||||
|
|
@ -321,10 +316,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
|
||||
return builder;
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Configures keys to be encrypted with Windows DPAPI before being persisted to
|
||||
|
|
@ -604,4 +595,4 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,12 +98,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return dataProtectionProvider;
|
||||
});
|
||||
|
||||
#if NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
services.TryAddSingleton<ICertificateResolver, CertificateResolver>();
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
|
||||
namespace Microsoft.AspNetCore.DataProtection
|
||||
{
|
||||
#if NET46
|
||||
/// <summary>
|
||||
/// Provides access to configuration for the data protection system, which allows the
|
||||
/// developer to configure default cryptographic algorithms, key storage locations,
|
||||
|
|
@ -34,33 +33,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
/// contain existing keys that use older algorithms or protection mechanisms.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
#elif NETSTANDARD1_3
|
||||
/// <summary>
|
||||
/// Provides access to configuration for the data protection system, which allows the
|
||||
/// developer to configure default cryptographic algorithms, key storage locations,
|
||||
/// and the mechanism by which keys are protected at rest.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// If the developer changes the at-rest key protection mechanism, it is intended that
|
||||
/// he also change the key storage location, and vice versa.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Similarly, when a developer modifies the default protected payload cryptographic
|
||||
/// algorithms, it is intended that he also select an explitiy key storage location.
|
||||
/// A call to <see cref="DataProtectionBuilderExtensions.UseCryptographicAlgorithms(IDataProtectionBuilder,AuthenticatedEncryptorConfiguration)"/>
|
||||
/// should therefore generally be paired with a call to <see cref="DataProtectionBuilderExtensions.PersistKeysToFileSystem(IDataProtectionBuilder,DirectoryInfo)"/>,
|
||||
/// for example.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// When the default cryptographic algorithms or at-rest key protection mechanisms are
|
||||
/// changed, they only affect <strong>new</strong> keys in the repository. The repository may
|
||||
/// contain existing keys that use older algorithms or protection mechanisms.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
public interface IDataProtectionBuilder
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -343,14 +343,8 @@ namespace Microsoft.AspNetCore.DataProtection.Managed
|
|||
|
||||
using (var validationAlgorithm = CreateValidationAlgorithm(validationSubkey))
|
||||
{
|
||||
#if NET46
|
||||
// As an optimization, avoid duplicating the underlying buffer if we're on desktop CLR.
|
||||
// As an optimization, avoid duplicating the underlying buffer
|
||||
var underlyingBuffer = outputStream.GetBuffer();
|
||||
#elif NETSTANDARD1_3
|
||||
var underlyingBuffer = outputStream.ToArray();
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
var mac = validationAlgorithm.ComputeHash(underlyingBuffer, KEY_MODIFIER_SIZE_IN_BYTES, checked((int)outputStream.Length - KEY_MODIFIER_SIZE_IN_BYTES));
|
||||
outputStream.Write(mac, 0, mac.Length);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>ASP.NET Core logic to protect and unprotect data, similar to DPAPI.</Description>
|
||||
<TargetFrameworks>net46;netstandard1.3</TargetFrameworks>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
|
@ -19,22 +19,14 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.Cryptography.Internal\Microsoft.AspNetCore.Cryptography.Internal.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.AspNetCore.DataProtection.Abstractions\Microsoft.AspNetCore.DataProtection.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
||||
<PackageReference Include="Microsoft.Win32.Registry" Version="$(CoreFxVersion)" />
|
||||
<PackageReference Include="System.Reflection.TypeExtensions" Version="$(CoreFxVersion)" />
|
||||
<PackageReference Include="System.Security.Claims" Version="$(CoreFxVersion)" />
|
||||
<PackageReference Include="System.Security.Principal.Windows" Version="$(CoreFxVersion)" />
|
||||
<PackageReference Include="System.Security.Cryptography.Xml" Version="$(CoreFxVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
@ -37,8 +38,9 @@ namespace Microsoft.AspNetCore.DataProtection.Repositories
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// The default key storage directory, which currently corresponds to
|
||||
/// "%LOCALAPPDATA%\ASP.NET\DataProtection-Keys".
|
||||
/// The default key storage directory.
|
||||
/// On Windows, this currently corresponds to "Environment.SpecialFolder.LocalApplication/ASP.NET/DataProtection-Keys".
|
||||
/// On Linux and macOS, this currently corresponds to "$HOME/.aspnet/DataProtection-Keys".
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property can return null if no suitable default key storage directory can
|
||||
|
|
@ -82,28 +84,23 @@ namespace Microsoft.AspNetCore.DataProtection.Repositories
|
|||
|
||||
private static DirectoryInfo GetDefaultKeyStorageDirectory()
|
||||
{
|
||||
#if NET46
|
||||
// Environment.GetFolderPath returns null if the user profile isn't loaded.
|
||||
var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
if (!String.IsNullOrEmpty(folderPath))
|
||||
{
|
||||
return GetKeyStorageDirectoryFromBaseAppDataPath(folderPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
// On core CLR, we need to fall back to environment variables.
|
||||
DirectoryInfo retVal;
|
||||
|
||||
var localAppDataPath = Environment.GetEnvironmentVariable("LOCALAPPDATA");
|
||||
// Environment.GetFolderPath returns null if the user profile isn't loaded.
|
||||
var localAppDataFromSystemPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
var localAppDataFromEnvPath = Environment.GetEnvironmentVariable("LOCALAPPDATA");
|
||||
var userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
|
||||
var homePath = Environment.GetEnvironmentVariable("HOME");
|
||||
|
||||
if (localAppDataPath != null)
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !string.IsNullOrEmpty(localAppDataFromSystemPath))
|
||||
{
|
||||
retVal = GetKeyStorageDirectoryFromBaseAppDataPath(localAppDataPath);
|
||||
// To preserve backwards-compatibility with 1.x, Environment.SpecialFolder.LocalApplicationData
|
||||
// cannot take precedence over $LOCALAPPDATA and $HOME/.aspnet on non-Windows platforms
|
||||
retVal = GetKeyStorageDirectoryFromBaseAppDataPath(localAppDataFromSystemPath);
|
||||
}
|
||||
else if (localAppDataFromEnvPath != null)
|
||||
{
|
||||
retVal = GetKeyStorageDirectoryFromBaseAppDataPath(localAppDataFromEnvPath);
|
||||
}
|
||||
else if (userProfilePath != null)
|
||||
{
|
||||
|
|
@ -115,6 +112,12 @@ namespace Microsoft.AspNetCore.DataProtection.Repositories
|
|||
// it's a good guess that this is a *NIX machine. Use *NIX conventions for a folder name.
|
||||
retVal = new DirectoryInfo(Path.Combine(homePath, ".aspnet", DataProtectionKeysFolderName));
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(localAppDataFromSystemPath))
|
||||
{
|
||||
// Starting in 2.x, non-Windows platforms may use Environment.SpecialFolder.LocalApplicationData
|
||||
// but only after checking for $LOCALAPPDATA, $USERPROFILE, and $HOME.
|
||||
retVal = GetKeyStorageDirectoryFromBaseAppDataPath(localAppDataFromSystemPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
|
|
@ -131,9 +134,6 @@ namespace Microsoft.AspNetCore.DataProtection.Repositories
|
|||
{
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static DirectoryInfo GetKeyStorageDirectoryForAzureWebSites()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
private const string OldNamespace = "Microsoft.AspNet.DataProtection";
|
||||
private const string CurrentNamespace = "Microsoft.AspNetCore.DataProtection";
|
||||
private readonly ILogger _logger;
|
||||
private static readonly Regex _versionPattern = new Regex(@",\s?Version=(\d+\.?)(\d+\.?)?(\d+\.?)?(\d+\.?)?", RegexOptions.Compiled, TimeSpan.FromSeconds(2));
|
||||
private static readonly Regex _versionPattern = new Regex(@",\s?Version=[0-9]+(\.[0-9]+){0,3}", RegexOptions.Compiled, TimeSpan.FromSeconds(2));
|
||||
|
||||
public TypeForwardingActivator(IServiceProvider services)
|
||||
: this(services, DataProtectionProviderFactory.GetDefaultLoggerFactory())
|
||||
|
|
@ -39,16 +39,11 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
forwardedTypeName = originalTypeName.Replace(OldNamespace, CurrentNamespace);
|
||||
}
|
||||
|
||||
#if NET46
|
||||
if (candidate || forwardedTypeName.Contains(CurrentNamespace))
|
||||
if (candidate || forwardedTypeName.StartsWith(CurrentNamespace + ".", StringComparison.Ordinal))
|
||||
{
|
||||
candidate = true;
|
||||
forwardedTypeName = RemoveVersionFromAssemblyName(forwardedTypeName);
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error Target framework needs to be updated
|
||||
#endif
|
||||
|
||||
if (candidate)
|
||||
{
|
||||
|
|
@ -70,4 +65,4 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
protected string RemoveVersionFromAssemblyName(string forwardedTypeName)
|
||||
=> _versionPattern.Replace(forwardedTypeName, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
// 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 NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
||||
|
|
@ -40,9 +39,19 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
var store = new X509Store(location);
|
||||
try
|
||||
{
|
||||
store.Open(OpenFlags.ReadOnly);
|
||||
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
|
||||
var matchingCerts = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, validOnly: true);
|
||||
return (matchingCerts != null && matchingCerts.Count > 0) ? matchingCerts[0] : null;
|
||||
return (matchingCerts != null && matchingCerts.Count > 0)
|
||||
? matchingCerts[0]
|
||||
: null;
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
// Suppress first-chance exceptions when opening the store.
|
||||
// For example, LocalMachine\My is not supported on Linux yet and will throw on Open(),
|
||||
// but there isn't a good way to detect this without attempting to open the store.
|
||||
// See https://github.com/dotnet/corefx/issues/3690.
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -51,7 +60,4 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
}
|
||||
}
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -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 NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Security.Cryptography.Xml;
|
||||
|
|
@ -147,7 +145,3 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
}
|
||||
}
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,44 +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 NETSTANDARD1_3
|
||||
// [[ISSUE60]] Remove this entire file when Core CLR gets support for EncryptedXml.
|
||||
// This is just a dummy implementation of the class that always throws.
|
||||
// The only reason it's here (albeit internal) is to provide a nice error message if key
|
||||
// material that was generated by Desktop CLR needs to be read by Core CLR.
|
||||
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
||||
{
|
||||
internal sealed class EncryptedXmlDecryptor : IXmlDecryptor
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public EncryptedXmlDecryptor()
|
||||
: this(services: null)
|
||||
{
|
||||
}
|
||||
|
||||
public EncryptedXmlDecryptor(IServiceProvider services)
|
||||
{
|
||||
_logger = services.GetLogger<EncryptedXmlDecryptor>();
|
||||
}
|
||||
|
||||
public XElement Decrypt(XElement encryptedElement)
|
||||
{
|
||||
if (_logger.IsErrorLevelEnabled())
|
||||
{
|
||||
_logger.LogError(Resources.EncryptedXmlDecryptor_DoesNotWorkOnCoreClr);
|
||||
}
|
||||
|
||||
throw new PlatformNotSupportedException(Resources.EncryptedXmlDecryptor_DoesNotWorkOnCoreClr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif NET46
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
|
@ -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 NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography.Xml;
|
||||
using System.Xml;
|
||||
|
|
@ -73,7 +71,3 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
}
|
||||
}
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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 NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
||||
|
|
@ -20,7 +18,3 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
X509Certificate2 ResolveCertificate(string thumbprint);
|
||||
}
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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 NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Security.Cryptography.Xml;
|
||||
|
|
@ -17,7 +15,3 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
EncryptedData PerformEncryption(EncryptedXml encryptedXml, XmlElement elementToEncrypt);
|
||||
}
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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 NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography.Xml;
|
||||
|
||||
|
|
@ -16,7 +14,3 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
void PerformPreDecryptionSetup(EncryptedXml encryptedXml);
|
||||
}
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -133,7 +133,6 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
var memoryStream = new MemoryStream(DEFAULT_BUFFER_SIZE);
|
||||
element.Save(memoryStream);
|
||||
|
||||
#if NET46
|
||||
var underlyingBuffer = memoryStream.GetBuffer();
|
||||
fixed (byte* __unused__ = underlyingBuffer) // try to limit this moving around in memory while we allocate
|
||||
{
|
||||
|
|
@ -146,23 +145,6 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
Array.Clear(underlyingBuffer, 0, underlyingBuffer.Length);
|
||||
}
|
||||
}
|
||||
#elif NETSTANDARD1_3
|
||||
ArraySegment<byte> underlyingBuffer;
|
||||
CryptoUtil.Assert(memoryStream.TryGetBuffer(out underlyingBuffer), "Underlying buffer isn't exposable.");
|
||||
fixed (byte* __unused__ = underlyingBuffer.Array) // try to limit this moving around in memory while we allocate
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Secret(underlyingBuffer);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Array.Clear(underlyingBuffer.Array, underlyingBuffer.Offset, underlyingBuffer.Count);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error target frameworks need to be updated.
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -230,6 +230,44 @@
|
|||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ProtectKeysWithCertificate",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "builder",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder"
|
||||
},
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ProtectKeysWithCertificate",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "builder",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder"
|
||||
},
|
||||
{
|
||||
"Name": "thumbprint",
|
||||
"Type": "System.String"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder",
|
||||
"Static": true,
|
||||
"Extension": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ProtectKeysWithDpapi",
|
||||
|
|
@ -745,6 +783,132 @@
|
|||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.XmlEncryption.CertificateResolver",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"ImplementedInterfaces": [
|
||||
"Microsoft.AspNetCore.DataProtection.XmlEncryption.ICertificateResolver"
|
||||
],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ResolveCertificate",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "thumbprint",
|
||||
"Type": "System.String"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Security.Cryptography.X509Certificates.X509Certificate2",
|
||||
"Virtual": true,
|
||||
"ImplementedInterface": "Microsoft.AspNetCore.DataProtection.XmlEncryption.ICertificateResolver",
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.XmlEncryption.CertificateXmlEncryptor",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Sealed": true,
|
||||
"ImplementedInterfaces": [
|
||||
"Microsoft.AspNetCore.DataProtection.XmlEncryption.IInternalCertificateXmlEncryptor",
|
||||
"Microsoft.AspNetCore.DataProtection.XmlEncryption.IXmlEncryptor"
|
||||
],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Encrypt",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "plaintextElement",
|
||||
"Type": "System.Xml.Linq.XElement"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.XmlEncryption.EncryptedXmlInfo",
|
||||
"Sealed": true,
|
||||
"Virtual": true,
|
||||
"ImplementedInterface": "Microsoft.AspNetCore.DataProtection.XmlEncryption.IXmlEncryptor",
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "thumbprint",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "certificateResolver",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.XmlEncryption.ICertificateResolver"
|
||||
}
|
||||
],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "thumbprint",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "certificateResolver",
|
||||
"Type": "Microsoft.AspNetCore.DataProtection.XmlEncryption.ICertificateResolver"
|
||||
},
|
||||
{
|
||||
"Name": "services",
|
||||
"Type": "System.IServiceProvider"
|
||||
}
|
||||
],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
}
|
||||
],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "certificate",
|
||||
"Type": "System.Security.Cryptography.X509Certificates.X509Certificate2"
|
||||
},
|
||||
{
|
||||
"Name": "services",
|
||||
"Type": "System.IServiceProvider"
|
||||
}
|
||||
],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiNGProtectionDescriptorFlags",
|
||||
"Visibility": "Public",
|
||||
|
|
@ -990,6 +1154,54 @@
|
|||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.XmlEncryption.EncryptedXmlDecryptor",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Sealed": true,
|
||||
"ImplementedInterfaces": [
|
||||
"Microsoft.AspNetCore.DataProtection.XmlEncryption.IInternalEncryptedXmlDecryptor",
|
||||
"Microsoft.AspNetCore.DataProtection.XmlEncryption.IXmlDecryptor"
|
||||
],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "Decrypt",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "encryptedElement",
|
||||
"Type": "System.Xml.Linq.XElement"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Xml.Linq.XElement",
|
||||
"Sealed": true,
|
||||
"Virtual": true,
|
||||
"ImplementedInterface": "Microsoft.AspNetCore.DataProtection.XmlEncryption.IXmlDecryptor",
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "services",
|
||||
"Type": "System.IServiceProvider"
|
||||
}
|
||||
],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.XmlEncryption.EncryptedXmlInfo",
|
||||
"Visibility": "Public",
|
||||
|
|
@ -1032,6 +1244,28 @@
|
|||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.XmlEncryption.ICertificateResolver",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Interface",
|
||||
"Abstract": true,
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ResolveCertificate",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "thumbprint",
|
||||
"Type": "System.String"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Security.Cryptography.X509Certificates.X509Certificate2",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.XmlEncryption.IXmlDecryptor",
|
||||
"Visibility": "Public",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
|
@ -14,6 +14,9 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Cryptography.Internal\Microsoft.AspNetCore.Cryptography.Internal.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
|
@ -15,6 +15,9 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Cryptography.Internal\Microsoft.AspNetCore.Cryptography.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Cryptography.KeyDerivation\Microsoft.AspNetCore.Cryptography.KeyDerivation.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
@ -14,6 +14,9 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Cryptography.Internal\Microsoft.AspNetCore.Cryptography.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection.Abstractions\Microsoft.AspNetCore.DataProtection.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
<PackageReference Include="Moq" Version="$(MoqVersion)" />
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">$(PackageTargetFallback);dnxcore50;portable-net451+win8</PackageTargetFallback>
|
||||
|
|
@ -12,6 +12,9 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection\Microsoft.AspNetCore.DataProtection.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection.AzureStorage\Microsoft.AspNetCore.DataProtection.AzureStorage.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.AspNetCore.DataProtection.Repositories;
|
||||
using Microsoft.AspNetCore.DataProtection.Test.Shared;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
using Xunit;
|
||||
|
|
@ -13,8 +15,7 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
{
|
||||
public class DataProtectionProviderTests
|
||||
{
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyIfLocalAppDataAvailable]
|
||||
[Fact]
|
||||
public void System_UsesProvidedDirectory()
|
||||
{
|
||||
WithUniqueTempDirectory(directory =>
|
||||
|
|
@ -37,13 +38,13 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
});
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyIfLocalAppDataAvailable]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
[Fact]
|
||||
public void System_NoKeysDirectoryProvided_UsesDefaultKeysDirectory()
|
||||
{
|
||||
var keysPath = Path.Combine(Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%"), "ASP.NET", "DataProtection-Keys");
|
||||
var tempPath = Path.Combine(Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%"), "ASP.NET", "DataProtection-KeysTemp");
|
||||
Assert.NotNull(FileSystemXmlRepository.DefaultKeyStorageDirectory);
|
||||
|
||||
var keysPath = FileSystemXmlRepository.DefaultKeyStorageDirectory.FullName;
|
||||
var tempPath = FileSystemXmlRepository.DefaultKeyStorageDirectory.FullName + "Temp";
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -57,13 +58,21 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
var protector = DataProtectionProvider.Create("TestApplication").CreateProtector("purpose");
|
||||
Assert.Equal("payload", protector.Unprotect(protector.Protect("payload")));
|
||||
|
||||
// Step 3: Validate that there's now a single key in the directory and that it's protected using Windows DPAPI.
|
||||
// Step 3: Validate that there's now a single key in the directory
|
||||
var newFileName = Assert.Single(Directory.GetFiles(keysPath));
|
||||
var file = new FileInfo(newFileName);
|
||||
Assert.StartsWith("key-", file.Name, StringComparison.OrdinalIgnoreCase);
|
||||
var fileText = File.ReadAllText(file.FullName);
|
||||
Assert.DoesNotContain("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal);
|
||||
Assert.Contains("This key is encrypted with Windows DPAPI.", fileText, StringComparison.Ordinal);
|
||||
// On Windows, validate that it's protected using Windows DPAPI.
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
Assert.DoesNotContain("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal);
|
||||
Assert.Contains("This key is encrypted with Windows DPAPI.", fileText, StringComparison.Ordinal);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Contains("Warning: the key below is in an unencrypted form.", fileText, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -79,7 +88,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyIfLocalAppDataAvailable]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
public void System_UsesProvidedDirectory_WithConfigurationCallback()
|
||||
{
|
||||
|
|
@ -106,16 +114,13 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
});
|
||||
}
|
||||
|
||||
#if NET46 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyIfLocalAppDataAvailable]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
[Fact]
|
||||
public void System_UsesProvidedDirectoryAndCertificate()
|
||||
{
|
||||
var filePath = Path.Combine(GetTestFilesPath(), "TestCert.pfx");
|
||||
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
|
||||
store.Open(OpenFlags.ReadWrite);
|
||||
store.Add(new X509Certificate2(filePath, "password"));
|
||||
store.Add(new X509Certificate2(filePath, "password", X509KeyStorageFlags.Exportable));
|
||||
store.Close();
|
||||
|
||||
WithUniqueTempDirectory(directory =>
|
||||
|
|
@ -149,10 +154,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
}
|
||||
});
|
||||
}
|
||||
#elif NETCOREAPP2_0
|
||||
#else
|
||||
#error Target framework needs to be updated
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Runs a test and cleans up the temp directory afterward.
|
||||
|
|
@ -175,13 +176,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
}
|
||||
}
|
||||
|
||||
private class ConditionalRunTestOnlyIfLocalAppDataAvailable : Attribute, ITestCondition
|
||||
{
|
||||
public bool IsMet => Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%") != null;
|
||||
|
||||
public string SkipReason { get; } = "%LOCALAPPDATA% couldn't be located.";
|
||||
}
|
||||
|
||||
private static string GetTestFilesPath()
|
||||
{
|
||||
var projectName = typeof(DataProtectionProviderTests).GetTypeInfo().Assembly.GetName().Name;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
@ -14,6 +14,9 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection.Abstractions\Microsoft.AspNetCore.DataProtection.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection.Extensions\Microsoft.AspNetCore.DataProtection.Extensions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
<PackageReference Include="Moq" Version="$(MoqVersion)" />
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
@ -14,6 +14,9 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection.Abstractions\Microsoft.AspNetCore.DataProtection.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection.Redis\Microsoft.AspNetCore.DataProtection.Redis.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// 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 NET46
|
||||
#if NET461
|
||||
using System;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
|
|
@ -89,4 +89,4 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
#elif NETCOREAPP2_0
|
||||
#else
|
||||
#error Target framework needs to be updated
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ namespace Microsoft.AspNetCore.DataProtection.Cng.Internal
|
|||
{
|
||||
public unsafe class CngAuthenticatedEncryptorBaseTests
|
||||
{
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
[Fact]
|
||||
public void Decrypt_ForwardsArraySegment()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -37,8 +36,7 @@ namespace Microsoft.AspNetCore.DataProtection.Cng.Internal
|
|||
Assert.Equal(new byte[] { 0x20, 0x21, 0x22 }, retVal);
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
[Fact]
|
||||
public void Decrypt_HandlesEmptyAADPointerFixup()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -63,8 +61,7 @@ namespace Microsoft.AspNetCore.DataProtection.Cng.Internal
|
|||
Assert.Equal(new byte[] { 0x20, 0x21, 0x22 }, retVal);
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
[Fact]
|
||||
public void Decrypt_HandlesEmptyCiphertextPointerFixup()
|
||||
{
|
||||
// Arrange
|
||||
|
|
|
|||
|
|
@ -79,8 +79,7 @@ namespace Microsoft.AspNetCore.DataProtection.Managed
|
|||
});
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
[Fact]
|
||||
public void Encrypt_KnownKey()
|
||||
{
|
||||
// Arrange
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<Import Project="..\..\build\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
|
@ -14,6 +14,9 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.DataProtection\Microsoft.AspNetCore.DataProtection.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCoreVersion)" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||
|
|
@ -22,8 +25,4 @@
|
|||
<PackageReference Include="xunit" Version="$(XunitVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)'=='net46'">
|
||||
<Reference Include="System.Security" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -13,16 +13,19 @@ namespace Microsoft.AspNetCore.DataProtection.Repositories
|
|||
{
|
||||
public class FileSystemXmlRepositoryTests
|
||||
{
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyIfLocalAppDataAvailable]
|
||||
[Fact]
|
||||
public void DefaultKeyStorageDirectory_Property()
|
||||
{
|
||||
var baseDir = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ASP.NET")
|
||||
: Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".aspnet");
|
||||
var expectedDir = new DirectoryInfo(Path.Combine(baseDir, "DataProtection-Keys")).FullName;
|
||||
|
||||
// Act
|
||||
var defaultDirInfo = FileSystemXmlRepository.DefaultKeyStorageDirectory;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(defaultDirInfo.FullName,
|
||||
new DirectoryInfo(Path.Combine(GetLocalApplicationData(), "ASP.NET", "DataProtection-Keys")).FullName);
|
||||
Assert.Equal(expectedDir, defaultDirInfo.FullName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -156,23 +159,5 @@ namespace Microsoft.AspNetCore.DataProtection.Repositories
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetLocalApplicationData()
|
||||
{
|
||||
#if NETCOREAPP2_0
|
||||
return Environment.GetEnvironmentVariable("LOCALAPPDATA");
|
||||
#elif NET46
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
#else
|
||||
#error Target framework needs to be updated
|
||||
#endif
|
||||
}
|
||||
|
||||
private class ConditionalRunTestOnlyIfLocalAppDataAvailable : Attribute, ITestCondition
|
||||
{
|
||||
public bool IsMet => GetLocalApplicationData() != null;
|
||||
|
||||
public string SkipReason { get; } = "%LOCALAPPDATA% couldn't be located.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,11 +103,12 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
[MemberData(nameof(AssemblyVersions))]
|
||||
public void CreateInstance_ForwardsAcrossVersionChanges(Version version)
|
||||
{
|
||||
#if NET46
|
||||
#if NET461
|
||||
// run this test in an appdomain without testhost's custom assembly resolution hooks
|
||||
var setupInfo = new AppDomainSetup
|
||||
{
|
||||
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
|
||||
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);
|
||||
|
|
@ -132,13 +133,7 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
|
||||
Assert.NotEqual(typeInfo.AssemblyQualifiedName, newName);
|
||||
Assert.IsType<ClassWithParameterlessCtor>(activator.CreateInstance(typeof(object), newName, out var forwarded));
|
||||
#if NET46
|
||||
Assert.True(forwarded, "Should have forwarded this type to new version or namespace");
|
||||
#elif NETCOREAPP2_0
|
||||
Assert.False(forwarded, "Should not have forwarded this type to new version or namespace");
|
||||
#else
|
||||
#error Target framework should be updated
|
||||
#endif
|
||||
}
|
||||
|
||||
public static TheoryData<Version> AssemblyVersions
|
||||
|
|
@ -174,4 +169,4 @@ namespace Microsoft.AspNetCore.DataProtection
|
|||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +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 NET46
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.Xml;
|
||||
|
|
@ -61,8 +60,3 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
}
|
||||
}
|
||||
}
|
||||
#elif NETCOREAPP2_0
|
||||
#else
|
||||
#error Target framework needs to be updated
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.DataProtection.XmlEncryption
|
|||
XmlAssert.Equal(originalXml, roundTrippedElement);
|
||||
}
|
||||
|
||||
#if NET46
|
||||
#if NET461
|
||||
[ConditionalFact]
|
||||
[ConditionalRunTestOnlyOnWindows]
|
||||
public void Encrypt_CurrentUser_Decrypt_ImpersonatedAsAnonymous_Fails()
|
||||
|
|
|
|||
Loading…
Reference in New Issue