From 439cfe11083939273c39607236ed894cecb9560e Mon Sep 17 00:00:00 2001 From: Milan Stute Date: Wed, 2 Dec 2020 10:22:20 +0100 Subject: [PATCH] Remove unused OpenSSL/ctypescrypto dependency --- README.md | 8 ++--- opendrop/__init__.py | 5 +--- opendrop/util.py | 71 -------------------------------------------- setup.py | 1 - 4 files changed, 5 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 3c9fbb7..1040b00 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,12 @@ In addition, it requires Python >=3.6 as well as several libraries. As AirDrop exclusively runs over Apple Wireless Direct Link (AWDL), OpenDrop is only supported on macOS or on Linux systems running an open re-implementation of AWDL such as [OWL](https://github.com/seemoo-lab/owl). **Libraries.** -OpenDrop relies on current versions of [OpenSSL](https://www.openssl.org) and [libarchive](https://www.libarchive.org). -macOS ships with rather old versions of the two, so you will need to install newer version, for example, via [Homebrew](https://brew.sh): +OpenDrop relies on a current version of [libarchive](https://www.libarchive.org). +macOS ships with a rather old version, so you will need to install a newer version, for example, via [Homebrew](https://brew.sh): ```bash -brew install libarchive openssl +brew install libarchive ``` -OpenDrop automatically sets `DYLD_LIBRARY_PATH` to look for the Homebrew versions. You may need to update the variable yourself if you install the libraries differently. +OpenDrop automatically sets `DYLD_LIBRARY_PATH` to look for the Homebrew version. You may need to update the variable yourself if you install the libraries differently. Linux distributions should ship with more up-to-date versions, so this won't be necessary. diff --git a/opendrop/__init__.py b/opendrop/__init__.py index 3bd9c58..c3463c4 100644 --- a/opendrop/__init__.py +++ b/opendrop/__init__.py @@ -25,10 +25,7 @@ __version__ = "0.11.0" if platform.system() == "Darwin": dyld_path = os.environ.get("DYLD_LIBRARY_PATH", "") # save old path - openssl_path = "/usr/local/opt/openssl/lib" archive_path = "/usr/local/opt/libarchive/lib" - os.environ["DYLD_LIBRARY_PATH"] = "{}:{}:{}".format( - dyld_path, openssl_path, archive_path - ) + os.environ["DYLD_LIBRARY_PATH"] = "{}:{}".format(dyld_path, archive_path) logger = logging.getLogger(__name__) diff --git a/opendrop/util.py b/opendrop/util.py index a34f439..6b9b75e 100644 --- a/opendrop/util.py +++ b/opendrop/util.py @@ -27,7 +27,6 @@ import plistlib import ifaddr from PIL import Image, ExifTags -from ctypescrypto import cms, x509, pkey, oid from libarchive import ffi from libarchive.entry import new_archive_entry, ArchiveEntry from libarchive.ffi import ( @@ -91,76 +90,6 @@ class AirDropUtil: return uti_type - @staticmethod - def record_data(config, tls_cert, sign_cert, key): - """ - This method generates the sender record data and will sign it using the CMS format. - - This code serves documentation purposes only and is UNTESTED. To be accepted by Apple clients, we would need the - Apple-owned private key of the signing certificate. - - :param tls_cert: path to certificate used for AirDrop TLS connections - :param sign_cert: path to signing certificate - :param key: path to private key to the signing certificate - """ - - valid_date = datetime.datetime.now() - datetime.timedelta(days=3) - valid_date_string = valid_date.strftime("%Y-%m-%dT%H:%M:%SZ") - - emails_hashed = [ - hashlib.sha256(email.encode("utf-8")).hexdigest() for email in config.email - ] - phone_numbers_hashed = [ - hashlib.sha256(phone_number.encode("utf-8")).hexdigest() - for phone_number in config.phone - ] - - # Get the common name of the TLS certificate - with open(tls_cert, "rb") as cert_file: - cert = x509.X509(cert_file.read()) - cn = cert.subject[oid.Oid("2.5.4.3")] - encDsID = cn.replace("com.apple.idms.appleid.prd.", "") - - # Construct record data - record_data = { - "Version": 2, - "encDsID": encDsID, # Common name suffix of the certificate - "altDsID": encDsID, # Same as encDsID - "SuggestValidDuration": 30 * 24 * 60 * 60, # in seconds - "ValidAsOf": valid_date_string, # 3 days before now - "ValidatedEmailHashes": emails_hashed, - "ValidatedPhoneHashes": phone_numbers_hashed, - } - record_data_plist = plistlib.dumps(record_data, fmt=plistlib.FMT_XML) - - with open(sign_cert, "rb") as sign_cert_file: - with open(key, "rb") as key_file: - cert = x509.X509(sign_cert_file.read()) - key = pkey.PKey(privkey=key_file.read()) - # possibly need to add intermediate certs - cms_signed = cms.SignedData.create( - record_data_plist, - cert=cert, - pkey=key, - certs=None, - flags=cms.Flags.PARTIAL, - ) - signed_data = AirDropUtil.pem2der(cms_signed.pem()) - - return signed_data - - @staticmethod - def pem2der(s): - """ - Create DER Formatted bytes from a PEM Base64 String - - :param s: PEM formatted string - """ - start = s.find("-----\n") - finish = s.rfind("\n-----END") - data = s[start + 6 : finish] - return base64.b64decode(data) - @staticmethod def generate_file_icon(file_path): """ diff --git a/setup.py b/setup.py index b0d8001..d0770c8 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,6 @@ setup( package_data={"opendrop": ["certs/*.pem"]}, install_requires=[ "Pillow", - "ctypescrypto", "fleep", "ifaddr", "libarchive-c",