Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added the possibility to skip ssl certificate validation process if needed. #43

Merged
merged 1 commit into from

2 participants

piher Andy Edinborough
piher

Added a mandatory bool parameter skipSslValidation in TextClient Connect method, specifying if, when using ssl, the certificate validation step should be skipped.
Added a corresponding bool parameter in ImapClient and Pop3Client as an optional parameter so that previous codes won't change.
The default behavior is not to skip the certificate validation step. If the validation should be skipped, it has to be explicitly specified when creating the ImapClient or Pop3Client.

See issue #40 for details.

Andy Edinborough andyedinborough merged commit 4a8c7f2 into from
Andy Edinborough

Cool. Should we add an overload for Connect(...) that allows a delegate to be passed in for validation?

piher

Why not, I guess it wouldn't change anything for most people but could be very useful to a few.
After all, if the .net framework offers to do so there must be a reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 6 deletions.
  1. +3 −2 ImapClient.cs
  2. +3 −2 Pop3Client.cs
  3. +7 −2 TextClient.cs
5 ImapClient.cs
View
@@ -20,8 +20,9 @@ public class ImapClient : TextClient, IMailClient {
private string _FetchHeaders = null;
- public ImapClient(string host, string username, string password, AuthMethods method = AuthMethods.Login, int port = 143, bool secure = false) {
- Connect(host, port, secure);
+ public ImapClient(string host, string username, string password, AuthMethods method = AuthMethods.Login, int port = 143, bool secure = false, bool skipSslValidation = false)
+ {
+ Connect(host, port, secure, skipSslValidation);
AuthMethod = method;
Login(username, password);
}
5 Pop3Client.cs
View
@@ -4,8 +4,9 @@
namespace AE.Net.Mail {
public class Pop3Client : TextClient, IMailClient {
public Pop3Client() { }
- public Pop3Client(string host, string username, string password, int port = 110, bool secure = false) {
- Connect(host, port, secure);
+ public Pop3Client(string host, string username, string password, int port = 110, bool secure = false, bool skipSslValidation = false)
+ {
+ Connect(host, port, secure, skipSslValidation);
Login(username, password);
}
9 TextClient.cs
View
@@ -41,7 +41,8 @@ public abstract class TextClient : IDisposable {
}
- public void Connect(string hostname, int port, bool ssl) {
+ public void Connect(string hostname, int port, bool ssl, bool skipSslValidation)
+ {
try {
Host = hostname;
Port = port;
@@ -50,7 +51,11 @@ public abstract class TextClient : IDisposable {
_Connection = new TcpClient(hostname, port);
_Stream = _Connection.GetStream();
if (ssl) {
- var sslStream = new System.Net.Security.SslStream(_Stream, false);
+ System.Net.Security.SslStream sslStream;
+ if (skipSslValidation)
+ sslStream = new System.Net.Security.SslStream(_Stream, false, (sender, cert, chain, err) => true);
+ else
+ sslStream = new System.Net.Security.SslStream(_Stream, false);
_Stream = sslStream;
sslStream.AuthenticateAsClient(hostname);
}
Something went wrong with that request. Please try again.