From: louisabraham Date: Fri, 7 Dec 2018 15:22:37 +0000 (+0100) Subject: solve #6 X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=3ad3f2037bb974017ee040c5bac6357278734bad;p=gamesguru%2Fffpass.git solve #6 --- diff --git a/README.md b/README.md index 03af4e9..f9afdbf 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,12 @@ ffpass export --to passwords.csv [instructions](https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data#w_how-do-i-find-my-profile) on the website of Firefox. + - `Firefox password database is empty. Please create it from Firefox.` + + It means that Firefox currently doens't store any password. `ffpass` + cannot create the password database for security reasons. Just add + one password manually to Firefox to create the database. + ## Credits Thanks a lot to @lclevy for the retro-engineering\! I was inspired by diff --git a/README.rst b/README.rst index 6e0d2ca..ee39bf9 100644 --- a/README.rst +++ b/README.rst @@ -148,6 +148,12 @@ Troubleshoot `instructions `__ on the website of Firefox. +- ``Firefox password database is empty. Please create it from Firefox.`` + + It means that Firefox currently doens’t store any password. + ``ffpass`` cannot create the password database for security reasons. + Just add one password manually to Firefox to create the database. + Credits ------- diff --git a/ffpass/__init__.py b/ffpass/__init__.py index b1b6ea7..a87a858 100755 --- a/ffpass/__init__.py +++ b/ffpass/__init__.py @@ -50,13 +50,20 @@ MAGIC1 = b"\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" MAGIC2 = (1, 2, 840, 113549, 3, 7) +class NoDatabase(Exception): + pass + + class WrongPassword(Exception): pass -def getKey(directory, masterPassword=""): +def getKey(directory: Path, masterPassword=""): + dbfile: Path = directory / "key4.db" + if not dbfile.exists(): + raise NoDatabase() # firefox 58.0.2 / NSS 3.35 with key4.db in SQLite - conn = sqlite3.connect((directory / "key4.db").as_posix()) + conn = sqlite3.connect(dbfile.as_posix()) c = conn.cursor() # first check password c.execute("SELECT item1,item2 FROM metadata WHERE id = 'password';") @@ -242,7 +249,11 @@ def askpass(directory): def main_export(args): - key = askpass(args.directory) + try: + key = askpass(args.directory) + except NoDatabase: + # if the database is empty, we are done! + return jsonLogins = getJsonLogins(args.directory) logins = exportLogins(key, jsonLogins) writer = csv.writer(args.to_file) @@ -255,6 +266,8 @@ def main_import(args): try: key = getKey(args.directory) except WrongPassword: + # it is not possible to read the password + # if stdin is used for input print( "Password is not empty. You have to specify FROM_FILE.", file=sys.stderr ) @@ -318,7 +331,13 @@ def main(): else: args.directory = guessed_dir args.directory = args.directory.expanduser() - args.func(args) + try: + args.func(args) + except NoDatabase: + print( + "Firefox password database is empty. Please create it from Firefox.", + file=sys.stderr, + ) if __name__ == "__main__":