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

Allow disabling TLS hostname verification #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kiall
Copy link

@kiall kiall commented Mar 10, 2018

This adds a new configuration option to disable TLS hostname verification. This allows for configuring TLS to be on, but pointed at localhost - even though the IMAP servers TLS cert doesn't contain a localhost as a SAN or CN.

@kousu
Copy link

kousu commented Apr 24, 2022

I thought about writing this too, but concluded that I would never need this.

If connecting to localhost I don't really need encryption anyway, and in any case most servers have their name in /etc/hosts like mail.yourdomain.com 127.0.0.1, so I can just talk to its public address and TLS will work correctly; if my server doesn't have the right line there, it's just as easy to add that line as this extra config line.

And if connecting to a remote server with a self-signed cert, it's about equal effort to install it to /etc/ssl/certs the conventional way, rather than opening yourself up to MITM; either:

openssl s_client -connect mail.example.org:143 -starttls imap -showcerts | openssl x509 | sudo tee /etc/ssl/certs/mail.example.org.pem && sudo c_rehash`

openssl s_client -connect mail.example.org:993 -showcerts | openssl x509 | sudo tee /etc/ssl/certs/mail.example.org.pem && sudo c_rehash

@kousu
Copy link

kousu commented Apr 24, 2022

Funny, looks like the author wanted this feature at some point? #1 (comment)

But in the 2022 version there's no way to disable the hostname check, now, because every path uses ssl.create_default_context() which implies cert verification:

if security == "tls":
port = 993 if port is None else port
connection = imaplib.IMAP4_SSL(
host=host, port=port,
ssl_context=ssl.create_default_context())
else:
port = 143 if port is None else port
connection = imaplib.IMAP4(host=host, port=port)
if security == "starttls":
connection.starttls(ssl.create_default_context())

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.

2 participants