Skip to content

Commit

Permalink
ENH Improve compatibility with Windows and OSX (Darwin)
Browse files Browse the repository at this point in the history
Credits to @AlisterAmo and @Anthropohedron
  • Loading branch information
unode committed Sep 28, 2016
1 parent d30c3f1 commit 3b6f6e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ further improvements:

George L. Yermulnik (@yermulnik)
Christoph Schulz (@criztovyl)
Anthropohedron (@Anthropohedron)
Alister Amo (@AlisterAmo)


As third party developers often go uncredited, we'd also like to extend our
Expand Down
33 changes: 27 additions & 6 deletions firefox_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class SqliteCredentials(Credentials):
"""SQLite credentials backend manager
"""
def __init__(self, profile):
db = profile + "/signons.sqlite"
db = os.path.join(profile, "signons.sqlite")

super(SqliteCredentials, self).__init__(db)

Expand Down Expand Up @@ -149,7 +149,7 @@ class JsonCredentials(Credentials):
"""JSON credentials backend manager
"""
def __init__(self, profile):
db = profile + "/logins.json"
db = os.path.join(profile, "logins.json")

super(JsonCredentials, self).__init__(db)

Expand Down Expand Up @@ -183,10 +183,24 @@ def load_libnss(self):

if os.name == "nt":
nssname = "nss3.dll"
firefox = r"c:\Program Files (x86)\Mozilla Firefox"
firefox = r"C:\Program Files (x86)\Mozilla Firefox"
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 = (
"/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
else:
nssname = "libnss3.so"

Expand Down Expand Up @@ -460,6 +474,7 @@ def get_sections(profiles):
continue
return sections


def print_sections(sections, textIOWrapper=sys.stderr):
"""
Prints all available sections to an textIOWrapper (defaults to sys.stderr)
Expand All @@ -468,6 +483,7 @@ def print_sections(sections, textIOWrapper=sys.stderr):
textIOWrapper.write("{0} -> {1}\n".format(i, sections[i]))
textIOWrapper.flush()


def ask_section(profiles, choice_arg):
"""
Prompt the user which profile should be used for decryption
Expand All @@ -489,11 +505,10 @@ def ask_section(profiles, choice_arg):
print_sections(sections)
try:
choice = raw_input("Choice: ")
except EOFError as e:
except EOFError:
LOG.error("Could not read Choice, got EOF")
raise Exit(Exit.READ_GOT_EOF)


try:
final_choice = sections[choice]
except KeyError:
Expand Down Expand Up @@ -612,7 +627,13 @@ def get_profile(basepath, no_interactive, choice, list_profiles):
def parse_sys_args():
"""Parse command line arguments
"""
profile_path = "~/.mozilla/firefox/"

if os.name == "nt":
profile_path = os.path.join(os.environ['APPDATA'], "Mozilla", "Firefox")
elif os.uname()[0] == "Darwin":
profile_path = "~/Library/Application Support/Firefox"
else:
profile_path = "~/.mozilla/firefox"

parser = argparse.ArgumentParser(
description="Access Firefox/Thunderbird profiles and decrypt existing passwords"
Expand Down

0 comments on commit 3b6f6e1

Please sign in to comment.