diff --git a/custom_components/mail_and_packages/helpers.py b/custom_components/mail_and_packages/helpers.py index 647f7c22..619c521d 100644 --- a/custom_components/mail_and_packages/helpers.py +++ b/custom_components/mail_and_packages/helpers.py @@ -11,7 +11,6 @@ import os import quopri import re -import ssl import subprocess # nosec import uuid from datetime import timezone @@ -33,6 +32,7 @@ CONF_USERNAME, ) from homeassistant.core import HomeAssistant +from homeassistant.util import ssl from PIL import Image, ImageOps from .const import ( @@ -119,21 +119,16 @@ async def _test_login( Returns success boolean """ - context = ssl.create_default_context() # Catch invalid mail server / host names try: if security == "SSL": if not verify: - context = ssl.create_default_context() - context.check_hostname = False - context.verify_mode = ssl.CERT_NONE + context = ssl.client_context_no_verify() else: - context = ssl.create_default_context(purpose=Purpose.SERVER_AUTH) + context = ssl.client_context() account = imaplib.IMAP4_SSL(host=host, port=port, ssl_context=context) elif security == "startTLS": - context = ssl.create_default_context(purpose=Purpose.SERVER_AUTH) - context.check_hostname = False - context.verify_mode = ssl.CERT_NONE + context = ssl.client_context() account = imaplib.IMAP4(host=host, port=port) account.starttls(context) else: @@ -465,16 +460,12 @@ def login( try: if security == "SSL": if not verify: - context = ssl.create_default_context() - context.check_hostname = False - context.verify_mode = ssl.CERT_NONE + context = ssl.client_context_no_verify() else: - context = ssl.create_default_context(purpose=Purpose.SERVER_AUTH) + context = ssl.client_context() account = imaplib.IMAP4_SSL(host=host, port=port, ssl_context=context) elif security == "startTLS": - context = ssl.create_default_context(purpose=Purpose.SERVER_AUTH) - context.check_hostname = False - context.verify_mode = ssl.CERT_NONE + context = ssl.client_context() account = imaplib.IMAP4(host=host, port=port) account.starttls(context) else: