我使用makecert工具来创建:
然后,我在mmc中的“受信任证书颁发机构”部分安装了自签名证书.
服务器证书和客户端证书安装在mmc的个人部分。
然后,我使用服务器证书将web服务作为HTTP部署到IIS中。
然后,我有了另一个利用web服务的应用程序。它发送带有web服务请求的客户端证书,如下所示:
public static void Main(string[] args)
{
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, "client.com", true);
if (col.Count == 1)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
ClientServices web_service = new ClientServices();
web_service.ClientCertificates.Add(col[0]);
try
{
string check = web_service.CheckCertificate();
Console.WriteLine(check);
}
catch (WebException e)
{
Console.WriteLine(e.Message.ToString());
}
}
else
{
Console.WriteLine("The certificate was not found!");
}
Console.ReadKey();
}在服务器端,我检查客户端证书,如下所示:
[WebMethod]
public string CheckCertificate()
{
string message;
try
{
X509Certificate2 cert = new X509Certificate2(Context.Request.ClientCertificate.Certificate);
if (cert != null)
{
message = cert.SerialNumber.ToString();
}
else
{
message = "Error: No certificate was found!";
}
}
catch (Exception e)
{
message = e.Message.ToString();
}
return message;
}每当我运行客户端应用程序时,我都会收到以下错误消息:
请求被中止。无法创建SSL/TLS安全通道.
我该如何解决这个问题?
发布于 2013-04-28 07:40:40
我找到罪魁祸首。
我安装了WinHttpCertCfg工具,并授予了对证书私钥的访问权限。
我使用的命令如下:
WinHttpCertCfg.exe -g -c LOCAL_MACHINE\MY -s "<name of certificate>" -a EVERYONEhttps://stackoverflow.com/questions/16253412
复制相似问题