WebRequest MutualAuthRequired

时间:2019-04-10 12:45:49

标签: authentication ssl webrequest httpwebresponse

在Windows环境中,我想向服务器发出相互安全的WebRequest。

我已经获得了我的服务器将接受的受信任的PFX证书(P12)。我也有一些CA证书,可以用来证明在通信过程中将从服务器获得的证书。

我已将CA证书导入Windows证书存储区。

我的代码:

const string url = "https://...//Deliver";
HttpWebRequest webRequest = WebRequest.CreateHttp(url);

// Security:
webRequest.AuthenticationLevel=AuthenticationLevel.MutualAuthRequired;
webRequest.Credentials = CredentialCache.DefaultCredentials;
var p12Certificate = new X509Certificate("MyCertificate.P12", "my password");
webRequest.ClientCertificates.Add(p12Certificate);
... // add webRequest content

// Perform the WebRequest and get the Response
using (WebResponse response = webRequest.GetResponse())
{

此刻,我似乎得到了正确的答复(204无内容),但是response.IsMutuallyAuthenticated等于假。

我该怎么做才能确保通信相互认证?

0 个答案:

没有答案