From 2f463d02d70445f45a20f04787578ac937a6a4de Mon Sep 17 00:00:00 2001 From: mjfernez Date: Sat, 19 Feb 2022 15:35:26 -0500 Subject: Add AD scripts and bitwarden to pass script --- bitwarden-tools/bit2pass.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 bitwarden-tools/bit2pass.py (limited to 'bitwarden-tools/bit2pass.py') diff --git a/bitwarden-tools/bit2pass.py b/bitwarden-tools/bit2pass.py new file mode 100644 index 0000000..47a64b0 --- /dev/null +++ b/bitwarden-tools/bit2pass.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 +""" +bit2pass.py - grabs the bare minimum info from a bitwarden JSON export +(unencrypted) to populate a UNIX pass datastore. This assumes you named +your entry and gave it a password, otherwise, this script will yell at +you. + +This does NOT grab notes or usernames. I find that in pass to be kind of +useless since I rarely need to copy them. I use it purely for easy (and +secure) copying of passwords. If a really need the notes, it's probably +not something I'm going to be copying much. I also exclude anything +that's not a login because, well that's what bitwarden's good for... +Don't limit yourself to one tool + + +Usage: +0) (before running) Initialize a pass database: + pass init +1) python bit2pass.py +""" +import sys +import subprocess +import json +with open(sys.argv[1]) as f: + data = json.load(f) + +folders = { x['id'] : x['name'] for x in data['folders'] } +passwords = { + folders[x['folderId']] + '/' + x['name'] : + x['login']['password'] + for x in data['items'] + if x['type'] == 1 + } +print(passwords) + +for p in passwords: + echo = subprocess.run(["echo", passwords[p]], + check=True, + capture_output=True + ) + pass2pass = subprocess.run(["pass", "insert", "-e", p], + input=echo.stdout, + capture_output=True + ) + print(pass2pass.stdout) -- cgit v1.2.3