Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save VictorieeMan/ef228b4c9ab7e20865990ca785745c6e to your computer and use it in GitHub Desktop.
Save VictorieeMan/ef228b4c9ab7e20865990ca785745c6e to your computer and use it in GitHub Desktop.

Sicne the trezor password manager is closing down as of summer 2023, you might have tried migrating your data to another service. If it all went well, congrats!

If it all went bad? Then you realized that following the trezor export & migration instructions wasn't enough in your case. This could be because your Trezor Password Manager (TPM) entreis had newline chars in the extra/notes field. If this is the case I'll describe here below how I solved my problem.

WARNING: THE SOFTWARE ATTACHED AND THE SOLUTION IN THIS GitHub Gist IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Steps I encountered

  • Exported from TPM (success)
  • Imported to new Password manager as LastPass format (Fail)

The Trezor Password Manager exports to a file called trezor-export.csv, the formatting of this file is:

url,username,password,extra,name

It is supposed to be one entry per line in your csv file. If this isn't the case, the file is corrupted and no password manager knows how to correctly import the file. This is a problem.

Look at your file, if there are anyentries spread over several lines then you have to fix that. Preferably you do it manually in a text editor. But if you have more entreis than practical to manually handle, you can use the attached python script within a virtual environment to reformat the csv for you.

Preferably you do all this on a secure system considering that the sensitive password data is unencrypted during the process. Please be very careful, with your security. Be rather safe than sorry. Working on an encrypted partion (suggestions VeraCrypt / Virtual Machine /TailOS etc.) is a recommendation, since deleting files often leave recoverable data on your machine even after deletion.

Why does this problem occur? Because you had new line chars in your TPM entries and the export don't handle these well, so the csv file it exports get corrupted.

"""
No guarantees, use at your own risk. This script is provided as is, with no warranty or support. See License at bottom of file.
Requirements Python3
###-->>Read the readme: https://gist.github.com/VictorieeMan/ef228b4c9ab7e20865990ca785745c6e
### Note that this code breaks if your entries contain unwelcome "," signs. It expects there to only be 4x"," per entry line.
This is easy to fix by handling bad entries manually.
Run in as safe environment as possible. Treat your unencrypted trezor-export.csv file with outmost care.
"""
#This script is for fixing the csv export from the native Trezor password manager. It will take the csv file exported from
#Trezor, and format it so that it can be imported into a new password manager. It will also add a tag to the "extra" field, so
#that you can tell which entries were exported from Trezor, and processed by this script.
#This script is written in Python 3.7.3. It should work with any version of Python 3,
#but I haven't tested it. It will not work with Python 2.
#Open file read line by line
with open('trezor-export.csv') as f:
oldContent = f.read()
#For reference, this is added to the begining of each entry in the "extra" field. Change to whatever you want. If you want
#nothing, set to "". (But it's probably a good idea to have something there, so you can tell which entries were exported from
#Trezor, and processes in by this script.)
tag = "exported from trezor psw manager y2023: "
if len(tag) > 0:
tag = " "
#The native trezor pswd manager, allowed for new lines in the entry note, but it doesn't handle this well in the export,
#creating corrupted csv files. To fix this we need to replace the newline character. You may change this to your liking.
newLine_replacement = " \\newline "
newContent = []
col_counter = 0
url = "" #0
username = "" #1
password = "" #2
extra = "" #3
name = "" #4
for char in oldContent:
if char == ',':
col_counter += 1
elif col_counter == 4 and char == '\n':
col_counter = 0
newContent.append(url + "," + username + "," + password + "," + extra + "," + name + "\n")
url = ""
username = ""
password = ""
extra = tag
name = ""
else:
if col_counter == 0:
url += char
elif col_counter == 1:
username += char
elif col_counter == 2:
password += char
elif col_counter == 3:
temp_char = char
if (char == '\n'):
temp_char = newLine_replacement
extra += temp_char
elif col_counter == 4:
name += char
#Write new file
with open('trezor-export-formatted.csv', 'w') as f:
for line in newContent:
f.write(line)
print("Done")
"""
MIT License
Copyright (c) 2023 VictorieeMan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment