diff --git a/calibre-plugin/libadobe.py b/calibre-plugin/libadobe.py index 2caaf84..849d9c6 100644 --- a/calibre-plugin/libadobe.py +++ b/calibre-plugin/libadobe.py @@ -5,19 +5,26 @@ Helper library with code needed for Adobe stuff. ''' -from Crypto import Random from uuid import getnode import os, hashlib, base64 import urllib.request, ssl -from Crypto.Cipher import AES from datetime import datetime, timedelta from lxml import etree import rsa - -from Crypto.PublicKey import RSA -from Crypto.Hash import SHA +try: + from Crypto import Random + from Crypto.Cipher import AES + from Crypto.PublicKey import RSA + from Crypto.Hash import SHA +except ImportError: + # Debian (and Ubuntu) ship pycryptodome, but not in its compatible mode with pycrypto + # If `Crypto` can't be found, try under pycryptodome's own namespace + from Cryptodome import Random + from Cryptodome.Cipher import AES + from Cryptodome.PublicKey import RSA + from Cryptodome.Hash import SHA from oscrypto import keys from oscrypto.asymmetric import dump_certificate, dump_private_key, dump_public_key diff --git a/calibre-plugin/libadobeAccount.py b/calibre-plugin/libadobeAccount.py index 17fcd80..8ef7eda 100644 --- a/calibre-plugin/libadobeAccount.py +++ b/calibre-plugin/libadobeAccount.py @@ -2,9 +2,16 @@ from lxml import etree import base64 import os, locale, platform -from Crypto.PublicKey import RSA -from Crypto.Util.asn1 import DerSequence -from Crypto.Cipher import PKCS1_v1_5 +try: + from Crypto.PublicKey import RSA + from Crypto.Util.asn1 import DerSequence + from Crypto.Cipher import PKCS1_v1_5 +except ImportError: + # Debian (and Ubuntu) ship pycryptodome, but not in its compatible mode with pycrypto + # If `Crypto` can't be found, try under pycryptodome's own namespace + from Cryptodome.PublicKey import RSA + from Cryptodome.Util.asn1 import DerSequence + from Cryptodome.Cipher import PKCS1_v1_5 try: from libadobe import addNonce, sign_node, sendRequestDocu, sendHTTPRequest