mirror of
https://github.com/seemoo-lab/opendrop.git
synced 2026-09-14 15:16:11 -04:00
Remove unused OpenSSL/ctypescrypto dependency
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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__)
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user