2011-01-07 87 views
2

我試圖使用asp.net,C#將通知推送到iphone。在這行代碼中出現以下錯誤「驗證失敗,因爲遠程方已關閉傳輸流」。APNS SSlStream驗證失敗,因爲遠程方關閉了傳輸流

sslStream.AuthenticateAsClient(「gateway.sandbox.push.apple.com」,clientCertificateCollection,SslProtocols.Ssl3,false);

任何人都可以在這幫助我。

在此先感謝。

回答

0

我個人使用的:

sslStream.AuthenticateAsClient( 「gateway.sandbox.push.apple.com」,clientCertificateCollection,SslProtocols.Default,FALSE);

  using (TcpClient client = new TcpClient()) 
      { 


       client.Connect("gateway.sandbox.push.apple.com", 2195); 


       using (NetworkStream networkStream = client.GetStream()) 
       { 
        try 
        { 

         SslStream sslStream = new SslStream(client.GetStream(), false); 


         try 
         { 
          sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", "gateway.sandbox.push.apple.com", SslProtocols.Default, false); 
          //building messages 
          sslStream.Write(msg); 
          sslStream.close(); 
+1

謝謝malinois。我檢查了你的代碼行,但它返回相同的錯誤。你可以發佈代碼和步驟來做這個使用C#的APNS。提前致謝。非常感激你的幫助。 – Kodee 2011-01-11 10:23:26

2

你可以通過改變x509證書到X509Certificate2和X509CertificateCollection到X509Certificate2Collection嘗試。

2

最近我還收到錯誤: 「對SSPI的調用失敗,收到的消息是意外或格式錯誤。」 與內部異常: 「驗證失敗,因爲遠程方已關閉傳輸流」

什麼幫助我是改變一點點OpenSslStream方法 - TSL SSL協議中

舊代碼:

apnsStream.AuthenticateAsClient(
    this.Host, this.certificates, 
    System.Security.Authentication.SslProtocols.Ssl3, 
    false 
); 

新代碼:

apnsStream.AuthenticateAsClient(
    this.Host, this.certificates, 
    System.Security.Authentication.SslProtocols.Ssl3 | System.Security.Authentication.SslProtocols.Tls, 
    false 
); 

希望這將幫助別人......

+0

有同樣的問題。在我的情況下,只有將X509Certificate - > X509Certificate2,X509CertificateCollection應用於X509Certificate2Collection並添加SslProtocols.Tls標誌解決了問題。所以,兩個答案都是正確的,都需要解決這個問題 – Madman 2014-11-24 14:07:55

0

我覺得這裏的問題是,你有蘋果轉換證書,證書上服務器的研究與開發,你可以在OpenSSL的使用下面的命令來做到這一點:

  • 命令1 : OpenSSL的X​​509 -in 「apn_developer_identity.cer」 -inform DER退房手續 「apn_developer_identity.pem」 -outform PEM
  • 命令2: OpenSSL的PKCS12 -nocerts -in 「pushkey1.p12」 退房手續 「pushkey1.pem」 -passin傳球:你的傳球 - 傳球傳球:你的傳球
  • 指令代碼3: OpenSSL的PKCS12 -export -inkey 「pushkey1.pem」 -in 「apn_developer_identity.pem」 -out 「apn_developer_identity.p12」 -passin傳遞:yourpass -passout傳遞:yourpass
0

嘗試下面的代碼 sslStream.AuthenticateAsClient(「gateway.sandbox.push.apple.com」,clientCertificateCollection,SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls,false);

0

嘗試僅使用私鑰創建證書。

相關問題