ASP.NETweb.api。我可以在没有 https 的情况下使用客户端身份验证证书吗?
ASP.NET web.api. Can I use client authentication certificates without https?
我想在没有 https 的 IIS 上 web.api 应用程序 运行ning 中使用客户端身份验证证书。这可以通过 WCF 实现,但似乎无法通过 web.api 实现。下面的文章明确说明了这一点,但我想了解为什么不能这样做。
http://southworks.com/blog/2014/06/16/enabling-ssl-client-certificates-in-asp-net-web-api/
注意:我理解为什么在生产中永远不应该这样做。要求是 运行 在 SSL 不可用的测试环境中提供服务。
谢谢
是的,如果您让应用程序而不是 IIS 验证证书,这是可能的。
确保在 IIS 中的 SSL 设置下将客户端证书设置为 'Accept'。这将确保证书传递给应用程序。 'Require SSL'不需要打勾
然后您可以在代码中实现您自己的证书验证。例如:
http://leastprivilege.com/2013/11/11/client-certificate-authentication-middleware-for-katana
public class ClientCertificateAuthenticationHandler :
AuthenticationHandler<ClientCertificateAuthenticationOptions>
{
protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
{
var cert = Context.Get<X509Certificate2>(“ssl.ClientCertificate”);
if (cert == null)
{
return Task.FromResult<AuthenticationTicket>(null);
}
try
{
Options.Validator.Validate(cert);
}
catch
{
return Task.FromResult<AuthenticationTicket>(null);
}
var claims = GetClaimsFromCertificate(
cert, cert.Issuer, Options.CreateExtendedClaimSet);
var identity = new ClaimsIdentity(Options.AuthenticationType);
identity.AddClaims(claims);
var ticket = new AuthenticationTicket(
identity, new AuthenticationProperties());
return Task.FromResult<AuthenticationTicket>(ticket);
}
}
我想在没有 https 的 IIS 上 web.api 应用程序 运行ning 中使用客户端身份验证证书。这可以通过 WCF 实现,但似乎无法通过 web.api 实现。下面的文章明确说明了这一点,但我想了解为什么不能这样做。
http://southworks.com/blog/2014/06/16/enabling-ssl-client-certificates-in-asp-net-web-api/
注意:我理解为什么在生产中永远不应该这样做。要求是 运行 在 SSL 不可用的测试环境中提供服务。
谢谢
是的,如果您让应用程序而不是 IIS 验证证书,这是可能的。
确保在 IIS 中的 SSL 设置下将客户端证书设置为 'Accept'。这将确保证书传递给应用程序。 'Require SSL'不需要打勾
然后您可以在代码中实现您自己的证书验证。例如: http://leastprivilege.com/2013/11/11/client-certificate-authentication-middleware-for-katana
public class ClientCertificateAuthenticationHandler :
AuthenticationHandler<ClientCertificateAuthenticationOptions>
{
protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
{
var cert = Context.Get<X509Certificate2>(“ssl.ClientCertificate”);
if (cert == null)
{
return Task.FromResult<AuthenticationTicket>(null);
}
try
{
Options.Validator.Validate(cert);
}
catch
{
return Task.FromResult<AuthenticationTicket>(null);
}
var claims = GetClaimsFromCertificate(
cert, cert.Issuer, Options.CreateExtendedClaimSet);
var identity = new ClaimsIdentity(Options.AuthenticationType);
identity.AddClaims(claims);
var ticket = new AuthenticationTicket(
identity, new AuthenticationProperties());
return Task.FromResult<AuthenticationTicket>(ticket);
}
}