From 5fe4dbb75a494b99c6c7b0f30fe9e42e11a5c168 Mon Sep 17 00:00:00 2001 From: Florian Bach Date: Thu, 28 Apr 2022 16:31:14 +0200 Subject: [PATCH] More Python2 fixes --- .gitignore | 1 + calibre-plugin/fulfill.py | 3 --- calibre-plugin/register_ADE_account.py | 18 +++++++++--------- tests/main.py | 11 +++-------- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 25125fb..443579e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /calibre-plugin/keyextract/*.exe /calibre-plugin/module_id.txt /calibre-plugin/__pycache__ +/calibre-plugin/*.pyc diff --git a/calibre-plugin/fulfill.py b/calibre-plugin/fulfill.py index ee4103e..da36c08 100644 --- a/calibre-plugin/fulfill.py +++ b/calibre-plugin/fulfill.py @@ -8,9 +8,6 @@ This is an experimental Python version of libgourou. # pyright: reportUndefinedVariable=false import sys, os, time, shutil -if sys.version_info[0] < 3: - print("This script requires Python 3.") - exit(1) import zipfile from lxml import etree diff --git a/calibre-plugin/register_ADE_account.py b/calibre-plugin/register_ADE_account.py index 47c73a4..6ba0e76 100644 --- a/calibre-plugin/register_ADE_account.py +++ b/calibre-plugin/register_ADE_account.py @@ -7,10 +7,6 @@ This is an experimental Python version of libgourou. import getpass, sys -if sys.version_info[0] < 3: - print("This script requires Python 3.") - exit(1) - from libadobe import createDeviceKeyFile, VAR_VER_SUPP_CONFIG_NAMES from libadobeAccount import createDeviceFile, createUser, signIn, activateDevice @@ -32,9 +28,9 @@ def main(): if (VAR_MAIL == ""): - VAR_MAIL = input("Please enter your AdobeID: ") + VAR_MAIL = input("Please enter your AdobeID (or press enter for anonymous auth): ") - if (VAR_PASS == ""): + if (VAR_PASS == "" and VAR_MAIL != ""): VAR_PASS = getpass.getpass("Please enter the password for your AdobeID: ") if (VAR_VER is None): @@ -44,8 +40,8 @@ def main(): print("Invalid version") exit(1) - if (VAR_MAIL == "" or VAR_PASS == ""): - print("Empty credential, aborting") + if (VAR_MAIL != "" and VAR_PASS == ""): + print("Empty password, aborting") exit(1) @@ -61,7 +57,11 @@ def main(): print("Error, couldn't create user: %s" % resp) exit(1) - success, resp = signIn("AdobeID", VAR_MAIL, VAR_PASS) + if VAR_MAIL == "": + success, resp = signIn("anonymous", "", "") + else: + success, resp = signIn("AdobeID", VAR_MAIL, VAR_PASS) + if (success is False): print("Login unsuccessful: " + resp) exit(1) diff --git a/tests/main.py b/tests/main.py index 8c86794..a9115f9 100755 --- a/tests/main.py +++ b/tests/main.py @@ -12,6 +12,7 @@ if sys.version_info[0] >= 3: else: from mock import patch from lxml import etree +import binascii try: @@ -187,10 +188,7 @@ class TestAdobe(unittest.TestCase): key = rsa.PrivateKey.load_pkcs1(RSA.importKey(base64.b64decode(mock_signing_key)).exportKey()) keylen = rsa.pkcs1.common.byte_size(key.n) - if sys.version_info[0] >= 3: - padded = rsa.pkcs1._pad_for_signing(bytes(payload_bytes), keylen) - else: - padded = rsa.pkcs1._pad_for_signing(bytes(payload_bytes), keylen) + padded = rsa.pkcs1._pad_for_signing(bytes(payload_bytes), keylen) payload = rsa.pkcs1.transform.bytes2int(padded) encrypted = key.blinded_encrypt(payload) block = rsa.pkcs1.transform.int2bytes(encrypted, keylen) @@ -310,10 +308,7 @@ class TestAdobe(unittest.TestCase): expected_msg.extend(bytearray(struct.pack("B", len(passwd)))) expected_msg.extend(bytearray(passwd.encode("latin-1"))) - if sys.version_info[0] >= 3: - self.assertEqual(msg.hex(), expected_msg.hex(), "devkey encryption returned invalid result") - else: - self.assertEqual(msg, expected_msg, "devkey encryption returned invalid result") + self.assertEqual(binascii.hexlify(msg), binascii.hexlify(expected_msg), "devkey encryption returned invalid result")