在Mono上使用HttpListener和SSL

时间:2017-02-20 15:10:34

标签: mono ubuntu-server httplistener

我有单声道4.6.2.16在Ubuntu 16.04.1 LTS上运行 我不能使用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

我尝试导出MONO_TLS_PROVIDER =“btls”,但它没有帮助。
该例外看起来与How to I catch SSL exceptions in a Mono HTTPListener server?完全相同 项目使用的.NET版本是4.6.1
如何在不安装新的单声道版本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 4.8.0.495但仍有错误:

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 ---

0 个答案:

没有答案