简体   繁体   English

Mono C#Websocket库在linux下传入的wss连接请求上引发错误

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

I developed a websocket-server in C# with Mono under linux and the Websocket library called Fleck Websockets 我在Linux下使用Mono和C#开发了一个Websocket服务器,并使用名为Fleck Websockets的Websocket库

Javascript clients in Browsers are connecting and running smoothly with the websocket protocoll ws. 浏览器中的Javascript客户端正在通过websocket协议ws连接并平稳运行。

Now I want to use wss as the secure websocket connection. 现在,我想使用wss作为安全的websocket连接。

The library claims to be able to handle this by just pointing to the .pfx X509 certificate. 该库声称能够通过指向.pfx X509证书来处理此问题。

I also incorporated the solution from Mono Documentation which might be outdated though. 我还合并了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;
         }

However, once a wss-client (Browser) tries to connect, the programm throws the folling error/warning 但是,一旦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 

I am now not sure how to proceed to overcome the problem. 我现在不确定如何着手解决这个问题。 As a further background information, the Certificate is from letsencrypt and I converted it with openssl to .pfx. 作为进一步的背景信息,证书来自letsencrypt,我使用openssl将其转换为.pfx。

System.IO.IOException: The authentication or decryption has failed. System.IO.IOException:身份验证或解密失败。 ---> System.NotSupportedException: Unsupported security protocol type ---> System.NotSupportedException:不支持的安全协议类型

This error above hints me that you're using a version of Debian (8.10) which includes a version of Mono (4.6.2) which is a bit old. 上面的错误提示我使用的是Debian(8.10)版本,其中包括Mono(4.6.2)版本,该版本有些旧。 Mono 4.8.x and newer includes better TLS/cryptography support, upgrade to this version and test again. Mono 4.8.x和更高版本包括更好的TLS /密码支持,请升级到该版本并再次测试。

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

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