在Mono上使用带SSL的HttpListener

在Mono上使用带SSL的HttpListener,mono,ubuntu-server,httplistener,Mono,Ubuntu Server,Httplistener,我在Ubuntu 16.04.1 LTS上运行mono 4.6.2.16 我无法使用HttpListener侦听SSL连接。证书没有问题,因为NGINX可以毫无问题地使用它们。 这是我收到的错误: Unhandled Exception: System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The clien

我在Ubuntu 16.04.1 LTS上运行mono 4.6.2.16
我无法使用HttpListener侦听SSL连接。证书没有问题,因为NGINX可以毫无问题地使用它们。
这是我收到的错误:

    Unhandled Exception:
System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The client stopped the handshake.
  at Mono.Security.Protocol.Tls.SslServerStream.EndNegotiateHandshake (System.IAsyncResult asyncResult) [0x000b9] in <...>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback(System.IAsyncResult asyncResult) [0x0000c] in <...>:0
   --- End of inner exception stack trace ---
  at Mono.Security.Protocol.Tls.SslStreamBase.EndRead(System.IAsyncResult asyncResult) [0x00057] in <...>:0
  at Mono.Net.Security.Private.LegacySslStream.EndAuthenticateAsServer(System.IAsyncResult asyncResult) [0x00011] in <...>:0
  at Mono.Net.Security.Private.LegacySslStream.AuthenticateAsServer(System.Security.Cryptography.X509Certificates.X509Certificate serverCertificate, System.Boolean clientCertificateRequired, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x0000e] in <...>:0
  at System.Net.HttpConnection.Init() [0x0001d] in <...>:0
  at System.Net.HttpConnection..ctor(System.Net.Sockets.Socket sock, System.Net.EndPointListener epl, System.Boolean secure, System.Security.Cryptography.X509Certificates.X509Certificate cert) [0x00096] in <...>:0
  at System.Net.EndPointListener.ProcessAccept(System.Net.Sockets.SocketAsyncEventArgs args) [0x00052] in <...>:0
  at System.Net.EndPointListener.OnAccept(System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in <...>:0
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) [0x00014] in <...>:0
  at System.Net.Sockets.SocketAsyncEventArgs.Complete() [0x00000] in <...>:0
  at System.Net.Sockets.Socket.<AcceptAsyncCallback>m__0 (System.IAsyncResult ares) [0x000a0] in <...>:0
  at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) [0x00000] in <...>:0
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() [0x00019] in <...>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch() [0x00096] in <...>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [0x00000] in <...>:0
未处理的异常:
System.IO.IOException:身份验证或解密失败。-->Mono.Security.Protocol.Tls.TlsException:客户端停止了握手。
在:0中的Mono.Security.Protocol.Tls.SslServerStream.EndNegotiateHandshake(System.IAsyncResult asyncResult)[0x000b9]处
位于:0中的Mono.Security.Protocol.Tls.SslStreamBase.AsynchHandshakeCallback(System.IAsyncResult asyncResult)[0x0000c]
---内部异常堆栈跟踪的结束---
位于:0中的Mono.Security.Protocol.Tls.SslStreamBase.EndRead(System.IAsyncResult asyncResult asyncResult)[0x00057]
位于:0中的Mono.Net.Security.Private.legacyssltream.EndAuthenticateAsServer(System.IAsyncResult asyncResult)[0x00011]
位于Mono.Net.Security.Private.legacyssltream.authenticatesServer(System.Security.Cryptography.X509Certificates.X509CertificateServerCertificate,需要System.Boolean客户端证书,System.Security.Authentication.SslProtocols启用DSLProtocols,System.Boolean checkCertificateRetrieve)[0x0000e]in:0
在中的System.Net.HttpConnection.Init()[0x0001d]处:0
在System.Net.HttpConnection..ctor(System.Net.Sockets.Socket sock、System.Net.EndPointListener epl、System.Boolean secure、System.Security.Cryptography.X509Certificates.X509Certificate cert)[0x00096]中:0
在:0中的System.Net.EndPointListener.ProcessAccept(System.Net.Sockets.SocketAsyncEventArgs args)[0x00052]处
在System.Net.EndPointListener.OnAccept(System.Object sender,System.Net.Sockets.SocketAsyncEventArgs e)[0x00000]中:0
在System.Net.Sockets.SocketAsyncEventArgs.OnCompleted处(System.Net.Sockets.SocketAsyncEventArgs e)[0x00014]中:0
位于:0中的System.Net.Sockets.SocketAsyncEventArgs.Complete()[0x00000]处
位于System.Net.Sockets.Socket.
项目使用的.NET版本为4.6.1
如果不安装新的mono版本4.8,我如何解决这个问题

p.S.升级到mono 4.8.0.489后,我收到另一个错误:

    System.IO.IOException: Remote prematurely closed connection.
  at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncProtocolRequest asyncRequest, Mono.Net.Security.AsyncOperationStatus status) [0x0001b] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(Mono.Net.Security.AsyncOperationStatus status) [0x0009e] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation() [0x0000d] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.StartOperation() [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in <f712f98eb8e445c8918edaf595bbe465>:0
  at Mono.Net.Security.MobileAuthenticatedStream.ProcessAuthentication(System.Net.LazyAsyncResult lazyResult) [0x00083] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.MobileAuthenticatedStream.AuthenticateAsServer(System.Security.Cryptography.X509Certificates.X509Certificate serverCertificate, System.Boolean clientCertificateRequired, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x00010] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.Private.MonoSslStreamWrapper.AuthenticateAsServer(System.Security.Cryptography.X509Certificates.X509Certificate serverCertificate, System.Boolean clientCertificateRequired, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x00006] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.HttpConnection.Init() [0x0001d] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.HttpConnection..ctor(System.Net.Sockets.Socket sock, System.Net.EndPointListener epl, System.Boolean secure, System.Security.Cryptography.X509Certificates.X509Certificate cert) [0x00096] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.EndPointListener.ProcessAccept(System.Net.Sockets.SocketAsyncEventArgs args) [0x00052] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.EndPointListener.OnAccept(System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) [0x00014] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.Sockets.SocketAsyncEventArgs.Complete() [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.Sockets.Socket.<AcceptAsyncCallback>m__0 (System.IAsyncResult ares) [0x000a0] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() [0x00019] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch() [0x00096] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [0x00000] in <f712f98eb8e445c8918edaf595bbe465>:0
[ERROR]
FATAL UNHANDLED EXCEPTION: System.IO.IOException: Remote prematurely closed connection.
at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncProtocolRequest asyncRequest, Mono.Net.Security.AsyncOperationStatus status) [0x0001b] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(Mono.Net.Security.AsyncOperationStatus status) [0x0009e] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation() [0x0000d] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.StartOperation() [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
--- End of stack trace from previous location where exception was thrown ---
Mono JIT compiler version 4.8.0 (Stable 4.8.0.495/e4a3cf3 Wed Feb 22 18:30:58 UTC 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

    sudo mono --debug=mdb-optimizations --trace=N:system.Net ./testssl.exe
Starting HTTP server at https://172.16.xx.xx:40510/
[0x7f8a97bb6740:] EXCEPTION handling: Mono.Btls.MonoBtlsException: MonoBtlsPkcs12.Import failed.
[0x7f8a97bb6740:] EXCEPTION handling: Mono.Btls.MonoBtlsException: MonoBtlsPkcs12.Import failed.
listening for request...
[0x7f8a8f675700:] EXCEPTION handling: System.IO.IOException: Remote prematurely closed connection.
[0x7f8a8f474700:] EXCEPTION handling: System.IO.IOException: Remote prematurely closed connection.

Unhandled Exception:
System.IO.IOException: Remote prematurely closed connection.
  at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncProtocolRequest asyncRequest, Mono.Net.Security.AsyncOperationStatus status) [0x0001b] in <5641e4edad4f4464ba58c620a7b8ea48>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (Mono.Net.Security.AsyncOperationStatus status) [0x0009e] in <5641e4edad4f4464ba58c620a7b8ea48>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation () [0x0000d] in <5641e4edad4f4464ba58c620a7b8ea48>:0
  at Mono.Net.Security.AsyncProtocolRequest.StartOperation () [0x00000] in <5641e4edad4f4464ba58c620a7b8ea48>:0
--- End of stack trace from previous location where exception was thrown ---
System.IO.IOException:远程过早关闭的连接。
在Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.Net.Security.AsyncProtocolRequest asyncRequest,Mono.Net.Security.AsyncOperationStatus状态)[0x0001b]中:0
位于:0中的Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(Mono.Net.Security.AsyncOperationStatus状态)[0x0009e]
在:0中的Mono.Net.Security.AsyncProtocolRequest.ProcessOperation()[0x0000d]处
在:0中的Mono.Net.Security.AsyncProtocolRequest.StartOperation()[0x00000]处
---来自引发异常的上一个位置的堆栈结束跟踪---
0中的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000c]时
在:0中的Mono.Net.Security.MobileAuthenticatedStream.ProcessAuthentication(System.Net.LazyAsyncResult lazyResult)[0x00083]处
在Mono.Net.Security.MobileAuthenticatedStream.AuthenticateAsServer(System.Security.Cryptography.X509Certificates.X509CertificateServerCertificate,需要System.Boolean客户端证书,System.Security.Authentication.SslProtocols启用DSLProtocols,System.Boolean checkCertificateReshicate)[0x00010]中:0
在Mono.Net.Security.Private.MonoSslStreamWrapper.AuthenticateAsServer(System.Security.Cryptography.X509Certificates.X509CertificateServerCertificate,System.Boolean客户端证书Required,System.Security.Authentication.SslProtocols enabledSslProtocols,System.Boolean CheckCertificateResortation)[0x00006]中:0
在中的System.Net.HttpConnection.Init()[0x0001d]处:0
在System.Net.HttpConnection..ctor(System.Net.Sockets.Socket sock、System.Net.EndPointListener epl、System.Boolean secure、System.Security.Cryptography.X509Certificates.X509Certificate cert)[0x00096]中:0
在:0中的System.Net.EndPointListener.ProcessAccept(System.Net.Sockets.SocketAsyncEventArgs args)[0x00052]处
在System.Net.EndPointListener.OnAccept(System.Object sender,System.Net.Sockets.SocketAsyncEventArgs e)[0x00000]中:0
在System.Net.Sockets.SocketAsyncEventArgs.OnCompleted处(System.Net.Sockets.SocketAsyncEventArgs e)[0x00014]中:0
位于:0中的System.Net.Sockets.SocketAsyncEventArgs.Complete()[0x00000]处
在System.Net.Sockets.Socket.m__0(System.IAsyncResult ares)[0x000a0]中:0
在System.Net.Sockets.SocketAsyncResult+c__AnonStorey0.m__0(System.Object)[0x00000]中:0
位于:0中的System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()[0x00019]处
位于:0中的System.Threading.ThreadPoolWorkQueue.Dispatch()[0x00096]处
位于System.Threading.\u ThreadPoolWaitCallback.PerformWaitCallback()[0x00000]中:0
[错误]
致命的未处理异常:System.IO.IOException:远程过早关闭的连接。
在Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.Net.Security.AsyncProtocolRequest asyncRequest,Mono.Net.Security.AsyncOperationStatus状态)[0x0001b]中:0
位于:0中的Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(Mono.Net.Security.AsyncOperationStatus状态)[0x0009e]
在:0中的Mono.Net.Security.AsyncProtocolRequest.ProcessOperation()[0x0000d]处
在:0中的Mono.Net.Security.AsyncProtocolRequest.StartOperation()[0x00000]处
---来自引发异常的上一个位置的堆栈结束跟踪---
更新:我安装了Mono 4.8.0.495,但仍然有一个错误:

    System.IO.IOException: Remote prematurely closed connection.
  at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncProtocolRequest asyncRequest, Mono.Net.Security.AsyncOperationStatus status) [0x0001b] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(Mono.Net.Security.AsyncOperationStatus status) [0x0009e] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation() [0x0000d] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.StartOperation() [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in <f712f98eb8e445c8918edaf595bbe465>:0
  at Mono.Net.Security.MobileAuthenticatedStream.ProcessAuthentication(System.Net.LazyAsyncResult lazyResult) [0x00083] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.MobileAuthenticatedStream.AuthenticateAsServer(System.Security.Cryptography.X509Certificates.X509Certificate serverCertificate, System.Boolean clientCertificateRequired, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x00010] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.Private.MonoSslStreamWrapper.AuthenticateAsServer(System.Security.Cryptography.X509Certificates.X509Certificate serverCertificate, System.Boolean clientCertificateRequired, System.Security.Authentication.SslProtocols enabledSslProtocols, System.Boolean checkCertificateRevocation) [0x00006] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.HttpConnection.Init() [0x0001d] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.HttpConnection..ctor(System.Net.Sockets.Socket sock, System.Net.EndPointListener epl, System.Boolean secure, System.Security.Cryptography.X509Certificates.X509Certificate cert) [0x00096] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.EndPointListener.ProcessAccept(System.Net.Sockets.SocketAsyncEventArgs args) [0x00052] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.EndPointListener.OnAccept(System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) [0x00014] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.Sockets.SocketAsyncEventArgs.Complete() [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.Sockets.Socket.<AcceptAsyncCallback>m__0 (System.IAsyncResult ares) [0x000a0] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() [0x00019] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch() [0x00096] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [0x00000] in <f712f98eb8e445c8918edaf595bbe465>:0
[ERROR]
FATAL UNHANDLED EXCEPTION: System.IO.IOException: Remote prematurely closed connection.
at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncProtocolRequest asyncRequest, Mono.Net.Security.AsyncOperationStatus status) [0x0001b] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(Mono.Net.Security.AsyncOperationStatus status) [0x0009e] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation() [0x0000d] in <1ad50d57fda24e15afa9ae11713723af>:0
  at Mono.Net.Security.AsyncProtocolRequest.StartOperation() [0x00000] in <1ad50d57fda24e15afa9ae11713723af>:0
--- End of stack trace from previous location where exception was thrown ---
Mono JIT compiler version 4.8.0 (Stable 4.8.0.495/e4a3cf3 Wed Feb 22 18:30:58 UTC 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

    sudo mono --debug=mdb-optimizations --trace=N:system.Net ./testssl.exe
Starting HTTP server at https://172.16.xx.xx:40510/
[0x7f8a97bb6740:] EXCEPTION handling: Mono.Btls.MonoBtlsException: MonoBtlsPkcs12.Import failed.
[0x7f8a97bb6740:] EXCEPTION handling: Mono.Btls.MonoBtlsException: MonoBtlsPkcs12.Import failed.
listening for request...
[0x7f8a8f675700:] EXCEPTION handling: System.IO.IOException: Remote prematurely closed connection.
[0x7f8a8f474700:] EXCEPTION handling: System.IO.IOException: Remote prematurely closed connection.

Unhandled Exception:
System.IO.IOException: Remote prematurely closed connection.
  at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncProtocolRequest asyncRequest, Mono.Net.Security.AsyncOperationStatus status) [0x0001b] in <5641e4edad4f4464ba58c620a7b8ea48>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (Mono.Net.Security.AsyncOperationStatus status) [0x0009e] in <5641e4edad4f4464ba58c620a7b8ea48>:0
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation () [0x0000d] in <5641e4edad4f4464ba58c620a7b8ea48>:0
  at Mono.Net.Security.AsyncProtocolRequest.StartOperation () [0x00000] in <5641e4edad4f4464ba58c620a7b8ea48>:0
--- End of stack trace from previous location where exception was thrown ---
Mono JIT编译器版本4.8.0(稳定的4.8.0.495/e4a3cf3周三2017年2月22日18:30:58 UTC)
版权所有(C)2002-2014 Novell公司、Xamarin公司和贡献者。www.mono-project.com
TLS:u_螺纹
SIGSEGV:altstack
通知:epoll
架构:amd64
残疾人士:无
杂项:软调试
LLVM:受支持,未启用。
GC:sgen
sudo mono--debug=mdb优化--trace=N:system.Net./te