jstedfast/MailKit

Error SSL with proxy (urgent please)

iqresults opened this issue · 1 comments

Describe the bug
When I try to connect to imap yahoo without proxy, it works!
When I try to connect to a proxy it gives me an SSL error
Before this last update it worked perfectly.

Platform (please complete the following information):

  • OS: Windows
  • .NET Runtime: .NET 4.8 windows forms
  • .NET Framework: .NET 4.8 windows forms
  • MailKit Version: 4.7.1.1

Exception
The handshake failed due to an unexpected packet format.

An error occurred while attempting to establish an SSL or TLS connection.

This usually means that the SSL certificate presented by the server is not trusted by the system for one or more of
the following reasons:

  1. The server is using a self-signed certificate which cannot be verified.
  2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.
  3. A Certificate Authority CRL server for one or more of the certificates in the chain is temporarily unavailable.
  4. The certificate presented by the server is expired or invalid.
  5. The set of SSL/TLS protocols supported by the client and server do not match.
  6. You are trying to connect to a port which does not support SSL/TLS.

See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#ssl-handshake-exception for possible solutions.

To Reproduce
Connect to Yahoo imap with proxy.

Expected behavior
Connect to Yahoo imap with proxy.

Code Snippets
System.Net.NetworkCredential objNetworkCredential = new System.Net.NetworkCredential("", "");
MailKit.Net.Proxy.HttpProxyClient objHttpProxyClient = new HttpProxyClient("cc60815c86754b61.dmv.eu.pyproxy.io", 16666, objNetworkCredential);

        try
        {

            using (var client = new ImapClient(new ProtocolLogger("imap.log")))
            {
                client.ProxyClient = objHttpProxyClient;
                await client.ConnectAsync("imap.mail.yahoo.com", 993, SecureSocketOptions.SslOnConnect);

Protocol Logs
Dont generate log

"The handshake failed due to an unexpected packet format."

This usually means you are trying to connect via SSL/TLS but that the server is plain-text only - this results in the above error message because the SslStream is expecting an SSL packet, but instead it gets unencrypted text which it can't "decode" as an SSL packet, hence the "unexpected packet format".

Port 993 is obviously supposed to be an SSL port, so it looks like your code is correct, but for whatever reason, apparently the client is receiving plain text (possibly a proxy bug?).

You could try using SecureSocketOptions.None and see what shows up in the log.

What version of MailKit were you using before? Can you switch back to that version? Does it work if you do?