我使用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;
}每当我运行客户端应用程序时,我都会收到以下错误消息:
我怎样才能解决这个问题?我被困在这上面已经两天了,所以任何帮助都会受到极大的感谢。
发布于 2013-04-28 07:42:39
我解决了问题。我安装了WinHttpCertCfg工具并授予了对私钥的访问权限。对我起作用的命令是:
WinHttpCertCfg.exe -g -c LOCAL_MACHINE\MY -s“-a EVERYONE”
https://security.stackexchange.com/questions/34931
复制相似问题