Skip to content

Commit

Permalink
MNT Refactor NSS finding code and include a few more locations on Win…
Browse files Browse the repository at this point in the history
…dows
  • Loading branch information
unode committed Feb 2, 2017
1 parent dd1926d commit dca2b69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
28 changes: 21 additions & 7 deletions firefox_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,33 +175,47 @@ 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",
"/sw/lib/firefox",
"/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)
Expand Down

0 comments on commit dca2b69

Please sign in to comment.