This project is read-only.

Establishing An SSL Connection

Jul 13, 2009 at 5:54 PM

I run the IMapFullSSLPlainTest but receive an error

Koolwired.Imap.ImapMailboxTest.CheckBodyStructure:
Koolwired.Imap.ImapConnectionException : Connection Failed
  ----> System.Security.Authentication.AuthenticationException : The remote certificate is invalid according to the validation procedure.

 

I guess it is because I do not have a certificate.  How do I get the server certificate?

 

at Koolwired.Imap.ImapConnect.Open() in C:\DevProjects\DoeTicketDesk\DoeTicketDesk\KoolWired\src\Koolwired.Imap\ImapConnect.cs:line 266
at Koolwired.Imap.ImapMailboxTest.CheckBodyStructure() in C:\DevProjects\DoeTicketDesk\DoeTicketDesk\KoolWired\src\Koolwired.IMAP.Test\ImapMailboxTest.cs:line 58
--AuthenticationException
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost)
at Koolwired.Imap.ImapConnect.Open() in C:\DevProjects\DoeTicketDesk\DoeTicketDesk\KoolWired\src\Koolwired.Imap\ImapConnect.cs:line 248

Jul 30, 2009 at 6:36 AM

Are you asking how to get a certificate for the IMAP server or where to install install a self signed certificate?

Jan 19, 2010 at 10:34 PM

How do you get around this when using your component?  Please let me know?

Jan 22, 2010 at 4:02 AM
Edited Jan 22, 2010 at 5:02 AM

I wanted to be able to use the code with a test server that does not have a signed certificate.

 

This is how I enabled this. Use with discretion. I suspect that there may be some support for bypassing this in other ways as well, but as this works for me, 

In ImapConnect.cs.Open() :

 

.... 
public bool Open()
{
string
read; _connectionState = ConnectionState.Connecting; _connection = new TcpClient(); _connection.ReceiveTimeout = ReceiveTimeout; _connection.SendTimeout = SendTimeout; try { _connection.Connect(_hostname, _port); if (!_ssl) { _stream = _connection.GetStream(); _streamReader = new StreamReader(_stream, System.Text.Encoding.ASCII); } else { //20100101 - code to optionally bypass certificate validation // original code //_sslstream = new SslStream(_connection.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidationCallback)); if (_disableSSLServerAuthentication) // custom property added to enable this behaviour { _sslstream = new SslStream( _connection.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate)); } else { _sslstream = new SslStream( _connection.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidationCallback)); } // end of changes 20100101 .... // 2010.01.01 - // support code to allow use of mail servers with invalid certificates. public static bool ValidateServerCertificate( object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; // ignore authentication errors! }

Great library.

 

Kudos!

Jan 22, 2010 at 4:04 AM
sorry about that. First post here. I'll make it pretty once I figure out how to do that.