Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ServerCertificateValidationCallback Option #39

Closed
wants to merge 1 commit into from

Conversation

Harmonickey
Copy link

I would like to include the option to add the callback which is already checked in OpenConnectedSmtpClient(). The calling code would be able to have something like this to make sure that even default exchange setups work.

private bool ValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
	if (sslPolicyErrors == SslPolicyErrors.None)
		return true;

	// if there are errors in the certificate chain, look at each error to determine the cause.
	if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0 || (sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) != 0)
	{
		if (chain != null && chain.ChainStatus != null)
		{
			foreach (var status in chain.ChainStatus)
			{
				if ((certificate.Subject == certificate.Issuer) && (status.Status == X509ChainStatusFlags.UntrustedRoot))
				{
					// self-signed certificates with an untrusted root are valid. 
					continue;
				}
				else if (status.Status != X509ChainStatusFlags.NoError)
				{
					// if there are any other errors in the certificate chain, the certificate is invalid,
					// so the method returns false.
					return false;
				}
			}
		}

		// When processing reaches this line, the only errors in the certificate chain are 
		// untrusted root errors for self-signed certificates. These certificates are valid
		// for default Exchange server installations, so return true.
		return true;
	}

	return false;
}

Reference Callback Solution for Calling Code
jstedfast/MailKit#307 (comment)
Reference
#37

@Harmonickey
Copy link
Author

This functionality is already in dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant