我必须在本地主机上配置HPKP,但我不知道如何配置或使用它。 请帮助我
答案 0 :(得分:1)
在ASP.NET Core中实现HPKP 实现HPKP的一种简单方法是使用我的库,您可以在NuGet上获得它:Joonasw.AspNetCore.SecurityHeaders.
只需将其安装到ASP.NET Core项目中,然后您就可以通过单个函数调用将HPKP标头添加到您的应用程序中。
Startup.cs中的Configure方法示例:
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug(LogLevel.Debug);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseHttpsEnforcement();
app.UseHsts(new HstsOptions
{
Seconds = 30 * 24 * 60 * 60,
IncludeSubDomains = false,
Preload = false
});
app.UseHpkp(hpkp =>
{
hpkp.UseMaxAgeSeconds(7 * 24 * 60 * 60)
.AddSha256Pin("nrmpk4ZI3wbRBmUZIT5aKAgP0LlKHRgfA2Snjzeg9iY=")
.SetReportOnly()
.ReportViolationsTo("/hpkp-report");
});
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "hpkp-report",
template: "hpkp-report",
defaults: new { controller = "Report", action = "Hpkp" });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}