From 2dcf26be18cc2e461443225089d700cef2ba9bb3 Mon Sep 17 00:00:00 2001 From: Florian Bach Date: Tue, 17 Sep 2024 19:15:25 +0200 Subject: [PATCH] Force plugin to use TLS v1.2 instead of v1.3. This is needed due to a change on Adobe's end, breaking Python > 3.7.16. Fixes #105. --- calibre-plugin/libadobe.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/calibre-plugin/libadobe.py b/calibre-plugin/libadobe.py index 8e264ad..af54bf4 100644 --- a/calibre-plugin/libadobe.py +++ b/calibre-plugin/libadobe.py @@ -294,7 +294,13 @@ def sendHTTPRequest_getSimple(URL): # It appears as if lots of book distributors have either invalid or expired certs ... # No idea how Adobe handles that (pinning?), but we can just ignore SSL errors and continue anyways. # Not the best solution, but it works. - ctx = ssl.create_default_context() + try: + ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) + # This is needed due to an Adobe change. + # Without this, only Python <= 3.7.16 can connect, 3.7.17 and above fail. + except: + ctx = ssl.create_default_context() + ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE @@ -328,7 +334,13 @@ def sendPOSTHTTPRequest(URL, document, type, returnRC = False): # It appears as if lots of book distributors have either invalid or expired certs ... # No idea how Adobe handles that (pinning?), but we can just ignore SSL errors and continue anyways. # Not the best solution, but it works. - ctx = ssl.create_default_context() + try: + ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) + # This is needed due to an Adobe change. + # Without this, only Python <= 3.7.16 can connect, 3.7.17 and above fail. + except: + ctx = ssl.create_default_context() + ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE