solve #6
authorlouisabraham <louis.abraham@yahoo.fr>
Fri, 7 Dec 2018 15:22:37 +0000 (16:22 +0100)
committerlouisabraham <louis.abraham@yahoo.fr>
Fri, 7 Dec 2018 15:22:37 +0000 (16:22 +0100)
README.md
README.rst
ffpass/__init__.py

index 03af4e9dcaf8ea45e17b879e25289fd0ad05965d..f9afdbf2118498ccc36edd0ad4a1ca4a526dce94 100644 (file)
--- 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
index 6e0d2ca205ce80ec05eb3f499aeba11b4470b453..ee39bf9ff05c9681c3afa0989527d9eb1409cec2 100644 (file)
@@ -148,6 +148,12 @@ Troubleshoot
    `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
 -------
 
index b1b6ea702508ccc4456aff9f1633ed3e13a06310..a87a858bca69c088c8302582b46f8308a095f09d 100755 (executable)
@@ -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__":