POP3.Connect Error: An existing connection was forcibly closed by the remote host

0 votes
asked Jul 5 by easyone (160 points)

Hello,

I get this error on connect both to pop3 or imap:
"TLS socket was closed: System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host"

This is the code used:

  Pop3 _pop = new Pop3();
  SslMode security;
  _pop.LogWriter = new Rebex.FileLogWriter(@"C:\Temp\log.txt", Rebex.LogLevel.Verbose);
  _pop.Settings.SslAllowedVersions = TlsVersion.SSL30 | TlsVersion.TLS10;
  _pop.Settings.SslAllowedSuites = TlsCipherSuite.Secure;
  _pop.Settings.SslServerName = "mbox.cert.legalmail.it" /*ma.InboundSrvAddress*/;
  security = SslMode.Implicit;

  pop.ValidatingCertificate += pop_ValidatingCertificate;

  _pop.Connect("mbox.cert.legalmail.it", 995, security);

This is the log:

2019-07-05 14:52:24.623 Opening log file.
2019-07-05 14:52:24.628 INFO FileLogWriter(1)[1] Info: Assembly: Rebex.Common 2019 R3 for .NET 4.0-4.8
2019-07-05 14:52:24.631 INFO FileLogWriter(1)[1] Info: Platform: Windows 6.2.9200 64-bit; CLR: 4.0.30319.42000
2019-07-05 14:52:24.633 DEBUG FileLogWriter(1)[1] Info: Culture: it; Windows-1252
2019-07-05 14:52:24.648 DEBUG Pop3(1)[1] Info: State changed from 'Disconnected' to 'Connecting'.
2019-07-05 14:52:24.648 INFO Pop3(1)[1] Info: Connecting to mbox.cert.legalmail.it:995 using Pop3.
2019-07-05 14:52:24.649 INFO Pop3(1)[1] Info: Assembly: Rebex.Pop3 2019 R3 for .NET 4.0-4.8
2019-07-05 14:52:24.649 INFO Pop3(1)[1] Info: Platform: Windows 6.2.9200 64-bit; CLR: 4.0.30319.42000
2019-07-05 14:52:24.649 DEBUG Pop3(1)[1] Info: Culture: it; Windows-1252
2019-07-05 14:52:24.650 INFO Pop3(1)[1] Info: Connecting to mbox.cert.legalmail.it.
2019-07-05 14:52:24.671 DEBUG Pop3(1)[1] Proxy: Resolving 'mbox.cert.legalmail.it'.
2019-07-05 14:52:24.682 DEBUG Pop3(1)[1] Proxy: Connecting to 185.102.40.53:995 (no proxy).
2019-07-05 14:52:24.719 DEBUG Pop3(1)[1] Info: Connection succeeded.
2019-07-05 14:52:24.723 DEBUG Pop3(1)[1] Info: Upgrading connection to TLS/SSL.
2019-07-05 14:52:24.730 INFO Pop3(1)[1] TLS: Warning: SSL 3.0 has been deprecated. According to RFC 7568, it must no longer be used.
2019-07-05 14:52:24.760 DEBUG Pop3(1)[1] TLS: Enabled cipher suites: 0x000FFCC33F000000.
2019-07-05 14:52:24.761 DEBUG Pop3(1)[1] TLS: Applicable cipher suites: 0x000000003F000000.
2019-07-05 14:52:24.790 VERBOSE Pop3(1)[1] TLS: Sent TLS packet: 
 0000 |16-03-01-00-5A-01-00-00 56-03-01-5D-1F-48-08-AD| ....Z...V..].H..
 0010 |90-D8-BC-88-93-B5-4A-89 53-8E-51-D2-49-F3-C3-DE| ......J.S.Q.I...
 0020 |4A-FD-F2-A3-08-40-CF-52 F1-F7-53-00-00-0E-00-6B| J....@.R..S....k
 0030 |00-67-00-3D-00-3C-00-6A 00-40-00-FF-01-00-00-1F| .g.=.<.j.@......
 0040 |00-00-00-1B-00-19-00-00 16-6D-62-6F-78-2E-63-65| .........mbox.ce
 0050 |72-74-2E-6C-65-67-61-6C 6D-61-69-6C-2E-69-74   | rt.legalmail.it
2019-07-05 14:52:24.792 INFO Pop3(1)[1] TLS: State StateChange:Negotiating
2019-07-05 14:52:24.793 DEBUG Pop3(1)[1] TLS: HandshakeMessage:ClientHello was sent.
2019-07-05 14:52:24.834 DEBUG Pop3(1)[1] TLS: TLS socket error, 0 bytes of data were received.
2019-07-05 14:52:24.839 DEBUG Pop3(1)[1] TLS: TLS socket was closed: System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.ProxySocket.Receive(Byte[] buffer, Int32 offset, Int32 count, SocketFlags socketFlags)
   at pzaa.rtqr(Int32 bcl)
   at pzaa.rtqs()
   at pzaa.rtqt()
2019-07-05 14:52:24.843 INFO Pop3(1)[1] TLS: Alert Alert:Alert was sent.
2019-07-05 14:52:24.843 INFO Pop3(1)[1] TLS: State StateChange:Closed
2019-07-05 14:52:24.843 VERBOSE Pop3(1)[1] TLS: Sent TLS packet: 
 0000 |15-03-01-00-02-02-50                           | ......P
2019-07-05 14:52:24.847 DEBUG Pop3(1)[1] TLS: Closing TLS socket.
2019-07-05 14:52:24.849 DEBUG Pop3(1)[1] Info: State changed from 'Connecting' to 'Disconnected'.
2019-07-05 14:52:24.850 ERROR Pop3(1)[1] Info: Rebex.Net.TlsException: Connection was closed by the remote connection end. ---> Rebex.Net.TlsException: Connection was closed by the remote connection end. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.ProxySocket.Receive(Byte[] buffer, Int32 offset, Int32 count, SocketFlags socketFlags)
   at pzaa.rtqr(Int32 bcl)
   at pzaa.rtqs()
   at pzaa.rtqt()
   --- End of inner exception stack trace ---
   at pzaa.rtqt()
   at pzaa.rtra()
   at ffph.thxf(TlsParameters jz)
   at Rebex.Net.Pop3.bdyv(TlsParameters bm, Boolean bn)
   --- End of inner exception stack trace ---
   at Rebex.Net.Pop3.bdyv(TlsParameters bm, Boolean bn)
   at Rebex.Net.Pop3.bdyt(String bf, Int32 bg, TlsParameters bh, SslMode bi)

The same code works few days ago.

Could you give me some help?

Thanks

Applies to: Rebex Secure Mail

1 Answer

+1 vote
answered Jul 5 by Lukas Pokorny (103,050 points)
selected Jul 5 by easyone
 
Best answer

Apparently, the server at mbox.cert.legalmail.it requires TLS 1.2. However, you only enabled deprecated legacy versions of the protocol (SSL 3.0 and TLS 1.0) on the client.

Instead of this:
_pop.Settings.SslAllowedVersions = TlsVersion.SSL30 | TlsVersion.TLS10;

Try this:
_pop.Settings.SslAllowedVersions = TlsVersion.Any;

...