2013-04-27 57 views
1

我爲了使用makecert工具創建:發送數字證書

  1. 自簽名證書
  2. 使用使用自簽名證書
  3. 客戶證書的服務器證書籤名的自證書

然後,我在mmc的「可信證書頒發機構」部分中安裝了自簽名證書。

服務器證書和客戶端證書安裝在mmc的Personal部分。

然後,我使用服務器證書在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安全通道。

我該如何解決這個問題?

回答

0

我發現了罪魁禍首。

我安裝了WinHttpCertCfg工具並授予訪問證書的私鑰。

我使用的命令是這樣的:

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