Skip to content

Commit

Permalink
ENH Add tabular output with -t/--tabular
Browse files Browse the repository at this point in the history
  • Loading branch information
unode committed Feb 10, 2017
1 parent 5d3ade8 commit 3649dcb
Show file tree
Hide file tree
Showing 6 changed files with 38 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.6.2
- Add `--tabular` output

##### 0.6.1
- Fix a bug on `--version` affecting primarily Python 3 (@criztovyl)

Expand Down
26 changes: 19 additions & 7 deletions firefox_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -407,17 +414,20 @@ 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),
u"Username: '{0}'\n".format(user),
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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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__":
Expand Down
13 changes: 13 additions & 0 deletions tests/tabular_46.t
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/test_data/users/complex_tabular.user
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'https://github.com' 'cömplex' 'сЮЛОажс$4vz*VçàhxpfCbmwo'
1 change: 1 addition & 0 deletions tests/test_data/users/doesntexist_tabular.user
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'https://github.com' 'doesntexist' 'xrbSDzYf94gfk'
1 change: 1 addition & 0 deletions tests/test_data/users/onemore_tabular.user
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'https://github.com' 'onemore' '}]¢öðæ[{'

0 comments on commit 3649dcb

Please sign in to comment.