parent
6d442c1e3d
commit
12966c63a6
|
|
@ -115,7 +115,6 @@
|
|||
<PackageArtifact Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Category="noship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.DataProtection.Abstractions" Category="noship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.DataProtection.Extensions" Category="noship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.DataProtection.SystemWeb" Category="noship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.DataProtection" Category="noship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Category="noship" />
|
||||
<PackageArtifact Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Category="noship" />
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" ProjectPath="$(RepositoryRoot)src\DataProtection\EntityFrameworkCore\src\Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DataProtection.Extensions" ProjectPath="$(RepositoryRoot)src\DataProtection\Extensions\src\Microsoft.AspNetCore.DataProtection.Extensions.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" ProjectPath="$(RepositoryRoot)src\DataProtection\StackExchangeRedis\src\Microsoft.AspNetCore.DataProtection.StackExchangeRedis.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DataProtection.SystemWeb" ProjectPath="$(RepositoryRoot)src\DataProtection\SystemWeb\src\Microsoft.AspNetCore.DataProtection.SystemWeb.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Hosting.Abstractions" ProjectPath="$(RepositoryRoot)src\Hosting\Abstractions\src\Microsoft.AspNetCore.Hosting.Abstractions.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Hosting" ProjectPath="$(RepositoryRoot)src\Hosting\Hosting\src\Microsoft.AspNetCore.Hosting.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" ProjectPath="$(RepositoryRoot)src\Hosting\Server.Abstractions\src\Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj" />
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
Commonly used types:
|
||||
Microsoft.AspNetCore.DataProtection.IDataProtectionProvider
|
||||
Microsoft.AspNetCore.DataProtection.IDataProtector</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Microsoft Azure KeyVault key encryption support.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection;azure;keyvault</PackageTags>
|
||||
<EnableApiCheck>false</EnableApiCheck>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Microsoft Azure Blob storrage support as key store.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection;azure;blob</PackageTags>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Infrastructure for ASP.NET Core cryptographic packages. Applications and libraries should not reference this package directly.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>ASP.NET Core utilities for key derivation.</Description>
|
||||
<TargetFrameworks>netstandard2.0;netcoreapp3.0</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection</PackageTags>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NonDISample", "samples\NonD
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Redis", "samples\Redis\Redis.csproj", "{E578D5C2-76AD-4A9B-A4F0-3A74D7ACD98E}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SystemWeb", "SystemWeb", "{AA4BAE43-BD74-4292-8468-46F4DF60F9C7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.DataProtection.SystemWeb", "SystemWeb\src\Microsoft.AspNetCore.DataProtection.SystemWeb.csproj", "{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EntityFrameworkCore", "EntityFrameworkCore", "{64FD02D7-B6F4-4C77-A3F8-E6BD6404168E}"
|
||||
|
|
@ -352,18 +350,6 @@ Global
|
|||
{E578D5C2-76AD-4A9B-A4F0-3A74D7ACD98E}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E578D5C2-76AD-4A9B-A4F0-3A74D7ACD98E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E578D5C2-76AD-4A9B-A4F0-3A74D7ACD98E}.Release|x86.Build.0 = Release|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7}.Release|x86.Build.0 = Release|Any CPU
|
||||
{8A7D0D2D-A5F1-4DF7-BBAA-9A0EFDBB5224}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8A7D0D2D-A5F1-4DF7-BBAA-9A0EFDBB5224}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8A7D0D2D-A5F1-4DF7-BBAA-9A0EFDBB5224}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -412,7 +398,6 @@ Global
|
|||
{03406538-75CB-4655-B210-643FE11A2B00} = {9DF098B3-C8ED-471C-AE03-52E3196C1811}
|
||||
{C5C425C8-5626-409B-9A81-4DC496CE41F4} = {9DF098B3-C8ED-471C-AE03-52E3196C1811}
|
||||
{E578D5C2-76AD-4A9B-A4F0-3A74D7ACD98E} = {9DF098B3-C8ED-471C-AE03-52E3196C1811}
|
||||
{A65DAFB6-E03F-4140-892F-D7CA3B8D81D7} = {AA4BAE43-BD74-4292-8468-46F4DF60F9C7}
|
||||
{8A7D0D2D-A5F1-4DF7-BBAA-9A0EFDBB5224} = {64FD02D7-B6F4-4C77-A3F8-E6BD6404168E}
|
||||
{74CE0E8B-DE23-4B53-8D02-69D6FB849ADC} = {64FD02D7-B6F4-4C77-A3F8-E6BD6404168E}
|
||||
EndGlobalSection
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>ASP.NET Core logic to protect and unprotect data, similar to DPAPI.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Support for storing keys using Entity Framework Core.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection;entityframeworkcore</PackageTags>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Additional APIs for ASP.NET Core data protection.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<Description>Support for storing data protection keys in Redis.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;dataprotection;redis</PackageTags>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,133 +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.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Microsoft.AspNetCore.DataProtection.SystemWeb
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="DataProtector"/> that can be used by ASP.NET 4.x to interact with ASP.NET Core's
|
||||
/// DataProtection stack. This type is for internal use only and shouldn't be directly used by
|
||||
/// developers.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public sealed class CompatibilityDataProtector : DataProtector
|
||||
{
|
||||
private static readonly Lazy<IDataProtectionProvider> _lazyProtectionProvider = new Lazy<IDataProtectionProvider>(CreateProtectionProvider);
|
||||
|
||||
[ThreadStatic]
|
||||
private static bool _suppressPrimaryPurpose;
|
||||
|
||||
private readonly Lazy<IDataProtector> _lazyProtector;
|
||||
private readonly Lazy<IDataProtector> _lazyProtectorSuppressedPrimaryPurpose;
|
||||
|
||||
public CompatibilityDataProtector(string applicationName, string primaryPurpose, string[] specificPurposes)
|
||||
: base("application-name", "primary-purpose", null) // we feed dummy values to the base ctor
|
||||
{
|
||||
// We don't want to evaluate the IDataProtectionProvider factory quite yet,
|
||||
// as we'd rather defer failures to the call to Protect so that we can bubble
|
||||
// up a good error message to the developer.
|
||||
|
||||
_lazyProtector = new Lazy<IDataProtector>(() => _lazyProtectionProvider.Value.CreateProtector(primaryPurpose, specificPurposes));
|
||||
|
||||
// System.Web always provides "User.MachineKey.Protect" as the primary purpose for calls
|
||||
// to MachineKey.Protect. Only in this case should we allow suppressing the primary
|
||||
// purpose, as then we can easily map calls to MachineKey.Protect(userData, purposes)
|
||||
// into calls to provider.GetProtector(purposes).Protect(userData).
|
||||
if (primaryPurpose == "User.MachineKey.Protect")
|
||||
{
|
||||
_lazyProtectorSuppressedPrimaryPurpose = new Lazy<IDataProtector>(() => _lazyProtectionProvider.Value.CreateProtector(specificPurposes));
|
||||
}
|
||||
else
|
||||
{
|
||||
_lazyProtectorSuppressedPrimaryPurpose = _lazyProtector;
|
||||
}
|
||||
}
|
||||
|
||||
// We take care of flowing purposes ourselves.
|
||||
protected override bool PrependHashedPurposeToPlaintext { get; } = false;
|
||||
|
||||
// Retrieves the appropriate protector (potentially with a suppressed primary purpose) for this operation.
|
||||
private IDataProtector Protector => ((_suppressPrimaryPurpose) ? _lazyProtectorSuppressedPrimaryPurpose : _lazyProtector).Value;
|
||||
|
||||
private static IDataProtectionProvider CreateProtectionProvider()
|
||||
{
|
||||
// Read from <appSettings> the startup type we need to use, then create it
|
||||
const string APPSETTINGS_KEY = "aspnet:dataProtectionStartupType";
|
||||
string startupTypeName = ConfigurationManager.AppSettings[APPSETTINGS_KEY];
|
||||
if (String.IsNullOrEmpty(startupTypeName))
|
||||
{
|
||||
// fall back to default startup type if one hasn't been specified in config
|
||||
startupTypeName = typeof(DataProtectionStartup).AssemblyQualifiedName;
|
||||
}
|
||||
Type startupType = Type.GetType(startupTypeName, throwOnError: true);
|
||||
var startupInstance = (DataProtectionStartup)Activator.CreateInstance(startupType);
|
||||
|
||||
// Use it to initialize the system.
|
||||
return startupInstance.InternalConfigureServicesAndCreateProtectionProvider();
|
||||
}
|
||||
|
||||
public override bool IsReprotectRequired(byte[] encryptedData)
|
||||
{
|
||||
// Nobody ever calls this.
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override byte[] ProviderProtect(byte[] userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Protector.Protect(userData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// System.Web special-cases ConfigurationException errors and allows them to bubble
|
||||
// up to the developer without being homogenized. Since a call to Protect should
|
||||
// never fail, any exceptions here really do imply a misconfiguration.
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
throw new ConfigurationException(Resources.DataProtector_ProtectFailed, ex);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
}
|
||||
|
||||
protected override byte[] ProviderUnprotect(byte[] encryptedData)
|
||||
{
|
||||
return Protector.Unprotect(encryptedData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a delegate where calls to <see cref="ProviderProtect(byte[])"/>
|
||||
/// and <see cref="ProviderUnprotect(byte[])"/> will ignore the primary
|
||||
/// purpose and instead use only the sub-purposes.
|
||||
/// </summary>
|
||||
public static byte[] RunWithSuppressedPrimaryPurpose(Func<object, byte[], byte[]> callback, object state, byte[] input)
|
||||
{
|
||||
if (_suppressPrimaryPurpose)
|
||||
{
|
||||
return callback(state, input); // already suppressed - just forward call
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
_suppressPrimaryPurpose = true;
|
||||
return callback(state, input);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_suppressPrimaryPurpose = false;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// defeat exception filters
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,102 +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.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNetCore.DataProtection.SystemWeb
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows controlling the configuration of the ASP.NET Core Data Protection system.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Developers should not call these APIs directly. Instead, developers should subclass
|
||||
/// this type and override the <see cref="ConfigureServices(IServiceCollection)"/>
|
||||
/// method or <see cref="CreateDataProtectionProvider(IServiceProvider)"/> methods
|
||||
/// as appropriate.
|
||||
/// </remarks>
|
||||
public class DataProtectionStartup
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures services used by the Data Protection system.
|
||||
/// </summary>
|
||||
/// <param name="services">A mutable collection of services.</param>
|
||||
/// <remarks>
|
||||
/// Developers may override this method to change the default behaviors of
|
||||
/// the Data Protection system.
|
||||
/// </remarks>
|
||||
public virtual void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// InternalConfigureServices already takes care of default configuration.
|
||||
// The reason we don't configure default logic in this method is that we don't
|
||||
// want to punish the developer for forgetting to call base.ConfigureServices
|
||||
// from within his own override.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of an <see cref="IDataProtectionProvider"/>.
|
||||
/// </summary>
|
||||
/// <param name="services">A collection of services from which to create the <see cref="IDataProtectionProvider"/>.</param>
|
||||
/// <returns>An <see cref="IDataProtectionProvider"/>.</returns>
|
||||
/// <remarks>
|
||||
/// Developers should generally override the <see cref="ConfigureServices(IServiceCollection)"/>
|
||||
/// method instead of this method.
|
||||
/// </remarks>
|
||||
public virtual IDataProtectionProvider CreateDataProtectionProvider(IServiceProvider services)
|
||||
{
|
||||
return services.GetDataProtectionProvider();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a default implementation of required services, calls the developer's
|
||||
/// configuration overrides, then creates an <see cref="IDataProtectionProvider"/>.
|
||||
/// </summary>
|
||||
internal IDataProtectionProvider InternalConfigureServicesAndCreateProtectionProvider()
|
||||
{
|
||||
// Configure the default implementation, passing in our custom discriminator
|
||||
var services = new ServiceCollection();
|
||||
services.AddDataProtection();
|
||||
services.AddSingleton<IApplicationDiscriminator>(new SystemWebApplicationDiscriminator());
|
||||
|
||||
// Run user-specified configuration and get an instance of the provider
|
||||
ConfigureServices(services);
|
||||
var provider = CreateDataProtectionProvider(services.BuildServiceProvider());
|
||||
if (provider == null)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.Startup_CreateProviderReturnedNull);
|
||||
}
|
||||
|
||||
// And we're done!
|
||||
return provider;
|
||||
}
|
||||
|
||||
private sealed class SystemWebApplicationDiscriminator : IApplicationDiscriminator
|
||||
{
|
||||
private readonly Lazy<string> _lazyDiscriminator = new Lazy<string>(GetAppDiscriminatorCore);
|
||||
|
||||
public string Discriminator => _lazyDiscriminator.Value;
|
||||
|
||||
private static string GetAppDiscriminatorCore()
|
||||
{
|
||||
// Try reading the discriminator from <machineKey applicationName="..." /> defined
|
||||
// at the web app root. If the value was set explicitly (even if the value is empty),
|
||||
// honor it as the discriminator.
|
||||
var machineKeySection = (MachineKeySection)WebConfigurationManager.GetWebApplicationSection("system.web/machineKey");
|
||||
if (machineKeySection.ElementInformation.Properties["applicationName"].ValueOrigin != PropertyValueOrigin.Default)
|
||||
{
|
||||
return machineKeySection.ApplicationName;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, fall back to the IIS metabase config path.
|
||||
// This is unique per machine.
|
||||
return HttpRuntime.AppDomainAppId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<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>net461</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnet;aspnetcore;dataprotection</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="web.config.transform" PackagePath="content/net46/" Pack="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.DataProtection" />
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Web" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// <auto-generated />
|
||||
namespace Microsoft.AspNetCore.DataProtection.SystemWeb
|
||||
{
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
|
||||
internal static class Resources
|
||||
{
|
||||
private static readonly ResourceManager _resourceManager
|
||||
= new ResourceManager("Microsoft.AspNetCore.DataProtection.SystemWeb.Resources", typeof(Resources).GetTypeInfo().Assembly);
|
||||
|
||||
/// <summary>
|
||||
/// A call to Protect failed. This most likely means that the data protection system is misconfigured. See the inner exception for more information.
|
||||
/// </summary>
|
||||
internal static string DataProtector_ProtectFailed
|
||||
{
|
||||
get => GetString("DataProtector_ProtectFailed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A call to Protect failed. This most likely means that the data protection system is misconfigured. See the inner exception for more information.
|
||||
/// </summary>
|
||||
internal static string FormatDataProtector_ProtectFailed()
|
||||
=> GetString("DataProtector_ProtectFailed");
|
||||
|
||||
/// <summary>
|
||||
/// The CreateDataProtectionProvider method returned null.
|
||||
/// </summary>
|
||||
internal static string Startup_CreateProviderReturnedNull
|
||||
{
|
||||
get => GetString("Startup_CreateProviderReturnedNull");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The CreateDataProtectionProvider method returned null.
|
||||
/// </summary>
|
||||
internal static string FormatStartup_CreateProviderReturnedNull()
|
||||
=> GetString("Startup_CreateProviderReturnedNull");
|
||||
|
||||
private static string GetString(string name, params string[] formatterNames)
|
||||
{
|
||||
var value = _resourceManager.GetString(name);
|
||||
|
||||
System.Diagnostics.Debug.Assert(value != null);
|
||||
|
||||
if (formatterNames != null)
|
||||
{
|
||||
for (var i = 0; i < formatterNames.Length; i++)
|
||||
{
|
||||
value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}");
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="DataProtector_ProtectFailed" xml:space="preserve">
|
||||
<value>A call to Protect failed. This most likely means that the data protection system is misconfigured. See the inner exception for more information.</value>
|
||||
</data>
|
||||
<data name="Startup_CreateProviderReturnedNull" xml:space="preserve">
|
||||
<value>The CreateDataProtectionProvider method returned null.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
{
|
||||
"AssemblyIdentity": "Microsoft.AspNetCore.DataProtection.SystemWeb, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
|
||||
"Types": [
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.SystemWeb.CompatibilityDataProtector",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"Sealed": true,
|
||||
"BaseType": "System.Security.Cryptography.DataProtector",
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "get_PrependHashedPurposeToPlaintext",
|
||||
"Parameters": [],
|
||||
"ReturnType": "System.Boolean",
|
||||
"Virtual": true,
|
||||
"Override": true,
|
||||
"Visibility": "Protected",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "IsReprotectRequired",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "encryptedData",
|
||||
"Type": "System.Byte[]"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Boolean",
|
||||
"Virtual": true,
|
||||
"Override": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ProviderProtect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "userData",
|
||||
"Type": "System.Byte[]"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"Virtual": true,
|
||||
"Override": true,
|
||||
"Visibility": "Protected",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ProviderUnprotect",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "encryptedData",
|
||||
"Type": "System.Byte[]"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"Virtual": true,
|
||||
"Override": true,
|
||||
"Visibility": "Protected",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "RunWithSuppressedPrimaryPurpose",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "callback",
|
||||
"Type": "System.Func<System.Object, System.Byte[], System.Byte[]>"
|
||||
},
|
||||
{
|
||||
"Name": "state",
|
||||
"Type": "System.Object"
|
||||
},
|
||||
{
|
||||
"Name": "input",
|
||||
"Type": "System.Byte[]"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Byte[]",
|
||||
"Static": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "applicationName",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "primaryPurpose",
|
||||
"Type": "System.String"
|
||||
},
|
||||
{
|
||||
"Name": "specificPurposes",
|
||||
"Type": "System.String[]"
|
||||
}
|
||||
],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft.AspNetCore.DataProtection.SystemWeb.DataProtectionStartup",
|
||||
"Visibility": "Public",
|
||||
"Kind": "Class",
|
||||
"ImplementedInterfaces": [],
|
||||
"Members": [
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "ConfigureServices",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "services",
|
||||
"Type": "Microsoft.Extensions.DependencyInjection.IServiceCollection"
|
||||
}
|
||||
],
|
||||
"ReturnType": "System.Void",
|
||||
"Virtual": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Method",
|
||||
"Name": "CreateDataProtectionProvider",
|
||||
"Parameters": [
|
||||
{
|
||||
"Name": "services",
|
||||
"Type": "System.IServiceProvider"
|
||||
}
|
||||
],
|
||||
"ReturnType": "Microsoft.AspNetCore.DataProtection.IDataProtectionProvider",
|
||||
"Virtual": true,
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
},
|
||||
{
|
||||
"Kind": "Constructor",
|
||||
"Name": ".ctor",
|
||||
"Parameters": [],
|
||||
"Visibility": "Public",
|
||||
"GenericParameter": []
|
||||
}
|
||||
],
|
||||
"GenericParameters": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<!--
|
||||
If you want to customize the behavior of the ASP.NET Core Data Protection stack, set the
|
||||
"aspnet:dataProtectionStartupType" switch below to be the fully-qualified name of a
|
||||
type which subclasses Microsoft.AspNetCore.DataProtection.SystemWeb.DataProtectionStartup.
|
||||
-->
|
||||
<add key="aspnet:dataProtectionStartupType" value="" />
|
||||
</appSettings>
|
||||
<system.web>
|
||||
<machineKey compatibilityMode="Framework45" dataProtectorType="Microsoft.AspNetCore.DataProtection.SystemWeb.CompatibilityDataProtector, Microsoft.AspNetCore.DataProtection.SystemWeb" />
|
||||
</system.web>
|
||||
</configuration>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net461;netcoreapp3.0</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<OutputType>exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>exe</OutputType>
|
||||
<TargetFrameworks>net461;netcoreapp3.0</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net461;netcoreapp3.0</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<OutputType>exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net461;netcoreapp3.0</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<OutputType>exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net461;netcoreapp3.0</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<OutputType>exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue