簡體   English   中英

Mono C#Websocket庫在linux下傳入的wss連接請求上引發錯誤

[英]Mono c# Websocket library throws errors on incoming wss-connection requests under linux

我在Linux下使用Mono和C#開發了一個Websocket服務器,並使用名為Fleck Websockets的Websocket庫

瀏覽器中的Javascript客戶端正在通過websocket協議ws連接並平穩運行。

現在,我想使用wss作為安全的websocket連接。

該庫聲稱能夠通過指向.pfx X509證書來處理此問題。

我還合並了Mono文檔中可能已經過時的解決方案。

WebSocketServer server = new WebSocketServer("wss://" + Tools.LocalIPAddress()  + ":" + MainClass.websocketport);
server.Certificate = new 

// Mono Hack for Handling potential Certificate problems
ServicePointManager.ServerCertificateValidationCallback = Validator;

System.Security.Cryptography.X509Certificates.X509Certificate2(new System.Security.Cryptography.X509Certificates.X509Certificate(zertifikatsfile,"<password>"));
server.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls;

public static bool Validator(System.Object sender,
            X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            return true;
         }

但是,一旦wss客戶端(瀏覽器)嘗試連接,程序將引發以下錯誤/警告

[Warn] Failed to Authenticate System.AggregateException: One or more errors occured ---> System.IO.IOException: The authentication or decryption has failed. ---> System.NotSupportedException: Unsupported security protocol type
  at Mono.Security.Protocol.Tls.Context.DecodeProtocolCode (Int16 code) [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.Handshake.Server.TlsClientHello.processProtocol (Int16 protocol) [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.Handshake.Server.TlsClientHello.ProcessAsTls1 () [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
  at Mono.Security.Protocol.Tls.ServerRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
 --> (Inner exception 0) System.IO.IOException: The authentication or decryption has failed. ---> System.NotSupportedException: Unsupported security protocol type
  at Mono.Security.Protocol.Tls.Context.DecodeProtocolCode (Int16 code) [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.Handshake.Server.TlsClientHello.processProtocol (Int16 protocol) [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.Handshake.Server.TlsClientHello.ProcessAsTls1 () [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
  at Mono.Security.Protocol.Tls.ServerRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0 
  at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 

我現在不確定如何着手解決這個問題。 作為進一步的背景信息,證書來自letsencrypt,我使用openssl將其轉換為.pfx。

System.IO.IOException:身份驗證或解密失敗。 ---> System.NotSupportedException:不支持的安全協議類型

上面的錯誤提示我使用的是Debian(8.10)版本,其中包括Mono(4.6.2)版本,該版本有些舊。 Mono 4.8.x和更高版本包括更好的TLS /密碼支持,請升級到該版本並再次測試。

暫無
暫無

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

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