diff --git a/CHANGELOG.md b/CHANGELOG.md index 6625a40..8d968d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ #### Changelog +##### 0.6.2 +- Add `--tabular` output + ##### 0.6.1 - Fix a bug on `--version` affecting primarily Python 3 (@criztovyl) diff --git a/firefox_decrypt.py b/firefox_decrypt.py index ff7d4c0..00f60e9 100755 --- a/firefox_decrypt.py +++ b/firefox_decrypt.py @@ -75,7 +75,7 @@ def internal_version(): return stdout.strip().decode("utf-8") -__version_info__ = (0, 6, 1) +__version_info__ = (0, 6, 2) __version__ = get_version() @@ -366,16 +366,23 @@ def decode_entry(self, user, passw): return user, passw - def decrypt_passwords(self, profile, password, export): + def decrypt_passwords(self, profile, password, export, tabular): """ Decrypt requested profile using the provided password and print out all stored passwords. """ + def output_line(line): + if PY3: + sys.stdout.write(line) + else: + sys.stdout.write(line.encode("utf8")) + self.initialize_libnss(profile, password) # Any password in this profile store at all? got_password = False + header = False credentials = obtain_credentials(profile) @@ -407,6 +414,12 @@ def decrypt_passwords(self, profile, password, export): else: to_export[address.netloc][user] = passw + elif tabular: + if header: + output_line(u"Website\tUsername\tPassword}\n".format(host, user, passw)) + + output_line(u"'{0}'\t'{1}'\t'{2}'\n".format(host, user, passw)) + else: output = ( u"\nWebsite: {0}\n".format(host), @@ -414,10 +427,7 @@ def decrypt_passwords(self, profile, password, export): u"Password: '{0}'\n".format(passw), ) for line in output: - if PY3: - sys.stdout.write(line) - else: - sys.stdout.write(line.encode("utf8")) + output_line(line) credentials.done() self.NSS.NSS_Shutdown() @@ -701,6 +711,8 @@ def parse_sys_args(): help="Path to profile folder (default: {0})".format(profile_path)) parser.add_argument("-e", "--export-pass", action="store_true", help="Export URL, username and password to pass from passwordstore.org") + parser.add_argument("-t", "--tabular", action="store_true", + help="Output in tabular format") parser.add_argument("-n", "--no-interactive", action="store_true", help="Disable interactivity.") parser.add_argument("-c", "--choice", nargs=1, @@ -760,7 +772,7 @@ def main(): password = ask_password(profile, args.no_interactive) # And finally decode all passwords - nss.decrypt_passwords(profile, password, args.export_pass) + nss.decrypt_passwords(profile, password, args.export_pass, args.tabular) if __name__ == "__main__": diff --git a/tests/tabular_46.t b/tests/tabular_46.t new file mode 100755 index 0000000..1b308a9 --- /dev/null +++ b/tests/tabular_46.t @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +. bash_tap_fd.sh + +PASSWD=$(get_password) +CMD="$(get_script) --tabular" +TEST="$(get_test_data)/test_profile_firefox_46/" + + +diff -u <(echo ${PASSWD} | ${CMD} ${TEST} | grep doesntexist || kill $$) <(get_user_data "doesntexist_tabular") +diff -u <(echo ${PASSWD} | ${CMD} ${TEST} | grep onemore || kill $$) <(get_user_data "onemore_tabular") +diff -u <(echo ${PASSWD} | ${CMD} ${TEST} | grep cömplex || kill $$) <(get_user_data "complex_tabular") + +# vim: ai sts=4 et sw=4 diff --git a/tests/test_data/users/complex_tabular.user b/tests/test_data/users/complex_tabular.user new file mode 100644 index 0000000..d806eea --- /dev/null +++ b/tests/test_data/users/complex_tabular.user @@ -0,0 +1 @@ +'https://github.com' 'cömplex' 'сЮЛОажс$4vz*VçàhxpfCbmwo' diff --git a/tests/test_data/users/doesntexist_tabular.user b/tests/test_data/users/doesntexist_tabular.user new file mode 100644 index 0000000..918a68f --- /dev/null +++ b/tests/test_data/users/doesntexist_tabular.user @@ -0,0 +1 @@ +'https://github.com' 'doesntexist' 'xrbSDzYf94gfk' diff --git a/tests/test_data/users/onemore_tabular.user b/tests/test_data/users/onemore_tabular.user new file mode 100644 index 0000000..a5893a4 --- /dev/null +++ b/tests/test_data/users/onemore_tabular.user @@ -0,0 +1 @@ +'https://github.com' 'onemore' '}]¢öðæ[{'