From dca2b693f3d534cd39c88c0bfa59ad459ff5b261 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Thu, 2 Feb 2017 21:26:07 +0100 Subject: [PATCH] MNT Refactor NSS finding code and include a few more locations on Windows --- CHANGELOG.md | 3 +++ firefox_decrypt.py | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc1a5cf..be85c6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ #### Changelog +##### 0.5.4 +- Search for NSS on additional folders when on Windows + ##### 0.5.3 - Compatibility improvements with Windows and OSX diff --git a/firefox_decrypt.py b/firefox_decrypt.py index fe44b2d..14b9433 100755 --- a/firefox_decrypt.py +++ b/firefox_decrypt.py @@ -175,20 +175,36 @@ def __init__(self): self.NSS = None self.load_libnss() + def find_nss(self, locations, nssname): + """Locate nss is one of the many possible locations + """ + for loc in locations: + if os.path.exists(os.path.join(loc, nssname)): + return loc + + LOG.warn("%s not found on any of the default locations for this platform. " + "Attempting to continue nonetheless.", nssname) + return "" + def load_libnss(self): """Load libnss into python using the CDLL interface """ - firefox = "" - if os.name == "nt": nssname = "nss3.dll" - firefox = r"C:\Program Files (x86)\Mozilla Firefox" + locations = ( + "", # Current directory or system lib finder + r"C:\Program Files (x86)\Mozilla Firefox", + r"C:\Program Files\Mozilla Firefox" + ) + firefox = self.find_nss(locations, nssname) + os.environ["PATH"] = ';'.join([os.environ["PATH"], firefox]) LOG.debug("PATH is now %s", os.environ["PATH"]) elif os.uname()[0] == "Darwin": nssname = "libnss3.dylib" locations = ( + "", # Current directory or system lib finder "/usr/local/lib/nss", "/usr/local/lib", "/opt/local/lib/nss", @@ -196,12 +212,10 @@ def load_libnss(self): "/sw/lib/mozilla", ) - for loc in locations: - if os.path.exists(os.path.join(loc, nssname)): - firefox = loc - break + firefox = self.find_nss(locations, nssname) else: nssname = "libnss3.so" + firefox = "" # Current directory or system lib finder try: nsslib = os.path.join(firefox, nssname)