Last active
August 25, 2023 22:07
-
-
Save hyperreal64/fd4a3984c58fb36ce15fa9ad1a6c7f24 to your computer and use it in GitHub Desktop.
The Python script I used to import my ProtonPass data into Bitwarden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import subprocess | |
PROTON_DATA_FILE = "/path/to/Proton Pass/data.json" | |
bw_get_template_item = subprocess.run( | |
["bw", "get", "template", "item"], text=True, capture_output=True | |
).stdout | |
bw_get_template_item_login = subprocess.run( | |
["bw", "get", "template", "item.login"], text=True, capture_output=True | |
).stdout | |
bw_get_template_item_login_uri = subprocess.run( | |
["bw", "get", "template", "item.login.uri"], text=True, capture_output=True | |
).stdout | |
bw_get_template_item_securenote = subprocess.run( | |
["bw", "get", "template", "item.securenote"], text=True, capture_output=True | |
).stdout | |
json_bw_item = json.loads(bw_get_template_item) | |
json_bw_item_login = json.loads(bw_get_template_item_login) | |
json_bw_item_login_uri = json.loads(bw_get_template_item_login_uri) | |
json_bw_item_securenote = json.loads(bw_get_template_item_securenote) | |
with open(PROTON_DATA_FILE, "r") as outfile: | |
proton_data = json.load(outfile) | |
proton_vault = proton_data["vaults"]["<VAULT_ID>"]["items"] | |
for item in proton_vault: | |
if item["data"]["type"] == "login": | |
json_bw_item["name"] = item["data"]["metadata"]["name"] | |
if item["data"]["content"]["urls"]: | |
json_bw_item_login_uri["uri"] = item["data"]["content"]["urls"][0] | |
else: | |
json_bw_item_login_uri["uri"] = None | |
json_bw_item_login_uri_list = list() | |
json_bw_item_login_uri_list.append(json_bw_item_login_uri) | |
json_bw_item_login["username"] = item["data"]["content"]["username"] | |
json_bw_item_login["password"] = item["data"]["content"]["password"] | |
json_bw_item_login["totp"] = None | |
json_bw_item_login["uris"] = json_bw_item_login_uri_list | |
json_bw_item["login"] = json_bw_item_login | |
bw_json = subprocess.Popen( | |
["echo", json.dumps(json_bw_item)], text=True, stdout=subprocess.PIPE | |
) | |
bw_encode = subprocess.Popen( | |
["bw", "encode"], text=True, stdin=bw_json.stdout, stdout=subprocess.PIPE | |
) | |
bw_create = subprocess.Popen( | |
["bw", "create", "item"], stdin=bw_encode.stdout, stdout=subprocess.PIPE | |
) | |
bw_json.stdout.close() | |
bw_encode.stdout.close() | |
output = bw_create.communicate()[0] | |
print(output) | |
if item["data"]["type"] == "note": | |
json_bw_item["name"] = item["data"]["metadata"]["name"] | |
json_bw_item["notes"] = item["data"]["metadata"]["note"] | |
json_bw_item["type"] = 2 | |
json_bw_item["secureNote"] = json_bw_item_securenote | |
bw_json = subprocess.Popen( | |
["echo", json.dumps(json_bw_item)], text=True, stdout=subprocess.PIPE | |
) | |
bw_encode = subprocess.Popen( | |
["bw", "encode"], text=True, stdin=bw_json.stdout, stdout=subprocess.PIPE | |
) | |
bw_create = subprocess.Popen( | |
["bw", "create", "item"], | |
text=True, | |
stdin=bw_encode.stdout, | |
stdout=subprocess.PIPE, | |
) | |
bw_json.stdout.close() | |
bw_encode.stdout.close() | |
output = bw_create.communicate()[0] | |
print(output) | |
shredder_output = subprocess.run( | |
["shred", "-x", "-u", PROTON_DATA_FILE], | |
text=True, | |
capture_output=True, | |
).stdout | |
print(shredder_output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment