簡體   English   中英

TCP客戶端C#:根據驗證過程,遠程證書無效

[英]TCP Client C#: The remote certificate is invalid according to the validation procedure

我正在嘗試通過TCP / SSL在C#客戶端和C#服務器之間建立通信。

我已經使用IIS生成了自簽名證書,並將其導入到信任存儲中。

當客戶端和服務器托管在同一台計算機上時,通信正常進行。 (我能夠交換數據包)。

但是,當客戶端在另一台計算機上時,出現此錯誤:根據驗證過程,遠程證書無效。

  • 我已經重新創建了證書。 (相同的錯誤)

      public static bool ValidateCertifiate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true; Console.WriteLine("Error: {0}", sslPolicyErrors); return false; } 

//主要代碼

   public static int Main(string[] args){

   TcpClient tcpClient = new TcpClient("IP", 8080);

  SslStream stream = new SslStream(tcpClient.GetStream(), false, new   RemoteCertificateValidationCallback(ValidateCertifiate), null);

  try {
   stream.AuthenticateAsClient("CertificateIssuer");
  } catch (Exception e) {
    Console.WriteLine("Exception: {0}", e.Message);
 }

 }

我想知道為什么當客戶端在服務器的同一主機上時該程序可以工作,而當客戶端在另一台計算機上時為什么該程序不能工作。

我將證書導入了正確的客戶信任庫。 現在建立了通信。

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM