Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Add support for "old" style imap over tls#1

Open
Arvedui wants to merge 2 commits intoUnrud:masterfrom
Arvedui:master
Open

Add support for "old" style imap over tls#1
Arvedui wants to merge 2 commits intoUnrud:masterfrom
Arvedui:master

Conversation

@Arvedui
Copy link

@Arvedui Arvedui commented Aug 27, 2017

No description provided.

type = radicale_imap
imap_host = imap.server.tld
imap_secure = True
imaps = True # for "old"-style imap over tls
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change True to False. I think IMAP over SSL is better.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably named this badly.
What I mean with "old-style" is that it uses a dedicated port for imap over SSL/TLS, which I consider to be more secure than upgrading with STARTTLS.
The proper imap over SSL/TLS is not even supported without this patch.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted you to change the line to something like:

imaps = False # for "old"-style IMAP over SSL

def get_secure_connection(self, host, port, imaps):
try:
if imaps:
connection = imaplib.IMAP4_SSL(host=host, port=port)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hostname is not checked. This is very insecure.
Enable the check if secure is true.

if imaps:
connection = imaplib.IMAP4_SSL(host=host, port=port)
else:
connection = self.get_connection(host, port)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the above must not be inside of the try-except-block. If secure is false exceptions are ignored.

imaps = False
if self.configuration.has_option("auth", "imaps"):
imaps = self.configuration.getboolean("auth", "imaps")

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the empty lines.

if sys.version_info < (3, 4) and secure:
raise RuntimeError("Secure IMAP is not availabe in Python < 3.4")
try:
connection = imaplib.IMAP4(host=address, port=port)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do something like this, instead of creating two methods:

if imaps and secure:
    connection = imaplib.IMAP4_SSL(...
elif imaps:
    connection = imaplib.IMAP4_SSL(...
else:
    connection = imaplib.IMAP4(host=address, port=port)
    try:
    ...

if secure or imaps:
connection = self.get_secure_connection(address, port, imaps)
else:
connection = self.get_connection(address, port)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If secure is false we can still try to use STARTTLS opportunistically, to protect against passive monitoring.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly disagree, this is a tool for people who know what they are doing. If I explicitly disable transport encryption I expect that it honors that, the current implementation is broken btw, it fails if STARTTLS is not available.
If at all opportunistic encryption should have it's own switch.

type = radicale_imap
imap_host = imap.server.tld
imap_secure = True
imaps = True # for "old"-style imap over tls
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted you to change the line to something like:

imaps = False # for "old"-style IMAP over SSL


def get_connection(self, host, port, secure, imaps):
ssl_context = ssl.create_default_context()
try:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try-except-block is unnecessary,

"""

def get_connection(self, host, port, secure, imaps):
ssl_context = ssl.create_default_context()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with Python < 3.4. Only create the context when secure.

try:
if secure and imaps:
connection = imaplib.IMAP4_SSL(
host=host, port=port, ssl_context=ssl_context)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case of insecure imaps (without hostname checks) is missing:

elif imaps:
    connection = imaplib.IMAP4_SSL(host=host, port=port)

Otherwise, it's impossible to use it with Python < 3.4 or with self-signed certificates.

host=host, port=port, ssl_context=ssl_context)
elif secure:
connection = imaplib.IMAP4(host=host, port=port)
if sys.version_info < (3, 4):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case can't happen. You can't use secure with Python < 3.4.

else:
connection.starttls(ssl_context)
else:
connection = imaplib.IMAP4(host=host, port=port)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove opportunistic encryption?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants