aboutsummaryrefslogtreecommitdiffstats
path: root/bitwarden-tools/bit2pass.py
blob: 47a64b089b2b842c3667cf874a45878877943204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 <your-file>
"""
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)