繁体   English   中英

发送数字证书

[英]Sending Digital Certificates

我使用了makecert工具来创建:

  1. 自签名证书
  2. 使用自签名证书的服务器证书
  3. 使用自签名证书的客户证书

然后,我在mmc的“受信任的证书颁发机构”部分中安装了自签名证书。

服务器证书和客户端证书已安装在mmc的“个人”部分中。

然后,我使用服务器证书在IIS中将Web服务部署为HTTP。

然后,我有了另一个利用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安全通道。

我怎么解决这个问题?

我找到了罪魁祸首。

我安装了WinHttpCertCfg工具,并授予了对证书私钥的访问权限。

我使用的命令是这样的:

WinHttpCertCfg.exe -g -c LOCAL_MACHINE\MY -s "<name of certificate>" -a EVERYONE

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM