来自同一主机上Invoke-WebRequest的WCF客户端证书身份验证



我有一个运行Windows Server的WebServer WCF.NET4.6.2应用程序。我只想从同一台服务器中调用该Web服务器的API,因为防火墙会阻止我的Web服务器的端口。此外,我希望只允许具有管理员权限的用户调用WebServer API。就这一点而言,我认为证书身份验证会起作用。我的WCF服务设置是

var baseAddress = new Uri("https://localhost:2000/");
var binding = new WebHttpBinding(WebHttpSecurityMode.Transport);
binding.HostNameComparisonMode = HostNameComparisonMode.Exact;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var endpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(MyWebApi)),
binding,
new EndpointAddress(baseAddress));    
webServiceHost = new WebServiceHost(kernel.Get<MyWebApi>(), baseAddress);
webServiceHost.AddServiceEndpoint(endpoint);
webServiceHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
webServiceHost.Credentials.ClientCertificate.Authentication.TrustedStoreLocation = StoreLocation.CurrentUser;
webServiceHost.Description.Behaviors.Find<ServiceDebugBehavior>().HttpHelpPageEnabled = false;
webServiceHost.Open();

我已经创建了一个根证书,并将其放入LocalComputer\Trusted root CA。

我已经创建了一个中间证书,并将其放入LocalComputer\中间CA。

我已经创建了两个[证书+私钥];localhost";以及";客户";。

我把";localhost";到本地计算机\个人

我把";客户端";到LocalComputer\ Personal和到MyUser\ Trusted People。

我的WebServer以MyUser的身份运行。我注册了使用SSL的Web服务器。

netsh http add sslcert ipport=0.0.0.0:2000 certhash="hash of localhost" appid="{00112233-4455-6677-8899-AABBCCDDEEFF}"  clientcertnegotiation=enable

我正在尝试使用MyUser 在运行Web服务器的同一主机上运行以下命令

Invoke-WebRequest -method post -uri https://localhost:2000/ping -CertificateThumbprint "hash of client"

但我得到的是

Invoke-WebRequest : The remote server returned an error: (403) Forbidden.

Fiddler显示的响应

System.Security.Authentication.AuthenticationException The remote certificate is invalid according to the validation procedure

更改绑定。Security.Transport.ClientCredentialType到HttpClientCredentialType.None有效,并证明我的客户端可以验证我的Web服务器的证书,但我不明白为什么Web服务器不能验证客户端的证书。如有任何帮助,我们将不胜感激。

我找到了解决方案,我缺少了两件事:

  1. 我不得不为我的根CA部署证书吊销列表
  2. 我必须创建一个客户证书,其中包括预期目的";客户端认证">

最新更新