KeePass2 Converter for 1Password 4

Options
MrC
MrC
Volunteer Moderator
edited October 2014 in Mac

I've created a script to convert your KeePass2 data into a format that can be imported by 1Password 4.

Edit: this version of the converter has been obsoleted. The new and improved version is located here:

https://discussions.agilebits.com/discussion/30286/mrcs-convert-to-1password-utility/p1

Comments

  • jonathanmorgan
    jonathanmorgan
    Community Member
    Options

    Hello,

    Just used this converter, and it worked great except for one thing: I have some entries that are just a password, no username (for things like a password-protected Quicken file, for example, or hardware where there is an admin password, but no username), and some where there is just a username, no password (logins that use shibboleth, so I just record the site and username, reference the master login record in notes, so leave no password). Either of these conditions throws off your script, causing all the information for the entry to be placed into one or more of the website fields in 1Password instead of in the other fields. Not sure what the issue is, but looks like it always expects username and password, and doesn't deal gracefully with their not being present - and, in the website fields, it looks to be preserving carriage returns, so probably it is a comma/column problem shifting content because comma isn't being inserted when value is missing. I deleted the import files as soon as I was done so I'd have to re-generate if you want the precise inputs and outputs, but I'd be happy to if you are inclined to investigate. If not, let me know. My perl is very rusty, but I might be able to poke around and see if it is an easy fix.

    Otherwise, a great tool, and much-appreciated - the way you handle groups as delimited strings is about the best option short of them having the capacity to create and populate folders on import.

    Thanks,

    Jon

  • MrC
    MrC
    Volunteer Moderator
    Options

    Hi jonathanmorgan,

    Thanks for the nice feedback and kind words. Lets see if we can get these issues resolved. I'll PM you my private email so that I can get more details and can send you an updated version to test out.

    MrC

  • MrC
    MrC
    Volunteer Moderator
    Options

    A closure reply to the above thread. @jonathanmorgan‌ and I via email resolved the reported issue above. It turned out that there was a misunderstanding that each specific CSV export required being imported as that specific type (1P4 expects data to be in certain columns of a type's specific CSV, so the correct one must be selected upon import).

    Our discussion lead me to implement support for the 1PIF import format and add a new option; these changes are noted in the next post.

  • MrC
    MrC
    Volunteer Moderator
    edited September 2014
    Options

    I've posted an update to the script. The changes are as follows:

    1. The CSV export format has been deprecated; 1PIF is now used as it has far superior import capabilities and only requires a single import file.

    2. Two new options are available: --nowatchtower and --sparselogin. See the Miscellaneous Notes in the ReadMe file.

    Edit: 2014-09-22 - I've removed the --sparselogin option in the 2.01 update, and instead always create a Login card if ANY of URL, Username, or Password exists.

  • arfer
    arfer
    Community Member
    Options

    Hi MrC

    I just acquired 1password and want to export my considerable Keepass 2x database to it.
    I dutifully followed all the instructions on my Win7 64 bit machine.
    The script ran, but produced the following error message:

    Can't find file "..\keepass2_export.xml" at keepass2_to_1p4.pl line 86

    Any suggestions how to move forward from this would be most welcome.
    Thanks for your work in developing the script...most appreciated!

  • MrC
    MrC
    Volunteer Moderator
    Options

    Hi arfer,

    Some questions:

    Did you download the script from the link in post #1?

    Do you see the file keepass2_export.xml on your Desktop in Windows? You might have Windows configured to not show the extension for files (and so you might not be noticing that it has a different suffix).

    The Windows command shell can help you auto-complete the file name. When you have the command shell open, and you've partially entered the command, for example:

    perl keepass2_to_1p4 -v ..\kee

    at the end of the "kee", but without adding any spaces, hit the Tab key and the command shell will autocomplete the filename. Hitting Tab repeatedly will cycle through the matching names (you may need to do this one or more times if you have several file names that partially match "kee"). The command above, and in the instructions, assume you've placed your file on the Desktop, and that you've already done the change of directory as per the instructions. You can verify your Windows command shell directory by its prompt.

  • arfer
    arfer
    Community Member
    Options

    Thanks for the prompt response MrC

    Your first question identified the problem.
    Not sure where I did get the original download but it wasn't the link above.
    So...I cleared the decks and started again, this time using Perl 5.16 (x64)
    I got further than before...but not far enough.

    The error message now reads:
    Imported 387 cards
    Cannot create 1pif output file: \Users\Ian/Desktop/1P4_import.1pif
    No such file or directory
    Stopped at keepass2_to_1p4.pl line 162

    I believe I know why but don't know how to fix it.
    My desktop is not on my C drive.
    Instead it sits on D:Libraries/Desktop
    I was able to run the perl script from there, but obviously there's a line in it for the output file that is seeking the Desktop on the C drive
    I created a folder at C:\Users\Ian called Desktop but this didn't help.

    Hope you can suggest something...I'm not looking forward to recreating the 387 records by hand...:))

  • MrC
    MrC
    Volunteer Moderator
    Options

    Ok, great. You're almost there. You can use the -o or --outfile option to specify your own destination for the generated 1pif output file. Use a full file path. Example:

    perl keepass2_to_1p4 -v -o D:\Libraries\Desktop\1P4_import.1pif ....

    you may need to double quote the path portion supplied to -o if it contains any spaces or other special characters.

  • arfer
    arfer
    Community Member
    Options

    MrC....you're da Man!!

    This time it worked perfectly.
    All 387 records, all with every field, including notes, in the right place.

    Thanks for your patient and knowledgeable help....:))

  • MrC
    MrC
    Volunteer Moderator
    Options

    Outstanding. And thanks for the feedback. It helps me to improve the converters.

  • jon102034050
    jon102034050
    Community Member
    Options

    I seem to be having an issue with this... Not sure if I have an incorrect version of perl or something, but this is what I get when I run it:

    perl ~/Downloads/keepass2_to_1p4/keepass2_to_1p4.pl -v keepass2_export.xml -o keepass.1pif

    Can't locate UUID/Tiny.pm in @INC (@INC contains: /Library/Perl/5.16/darwin-thread-multi-2level /Library/Perl/5.16 /Network/Library/Perl/5.16/darwin-thread-multi-2level /Network/Library/Perl/5.16 /Library/Perl/Updates/5.16.2 /System/Library/Perl/5.16/darwin-thread-multi-2level /System/Library/Perl/5.16 /System/Library/Perl/Extras/5.16/darwin-thread-multi-2level /System/Library/Perl/Extras/5.16 .) at /Users/USERNAME/Downloads/keepass2_to_1p4/keepass2_to_1p4.pl line 20.

  • MrC
    MrC
    Volunteer Moderator
    Options

    Hi jon102034050,

    I can see from the command you are executing that you are not in the correct directory. Do this:

    cd ~/Downloads/keepass2_to_1p4

    and then do this:

    perl keepass2_to_1p4.pl -v keepass2_export.xml -o keepass.1pif

  • jon102034050
    jon102034050
    Community Member
    Options

    Don't think that's it.... everything tab completes when I'm in the terminal. But, as a sanity check, I just moved the pl file to the location that my xml file was, and ran it as you suggested and got the same error. From what I can see, it looks like I may need to install the Tiny perl module... but I've no clue how to do this.

  • MrC
    MrC
    Volunteer Moderator
    edited September 2014
    Options

    That module is included in the zip archive, which I just checked on my AgileBits Utilities folder:

    $ zip -sf ~/Dropbox/Agilebits/keepass2_to_1p4.zip
    Archive contains:
      keepass2_to_1p4.pl
      UUID/
      UUID/Tiny.pm
      JSON/
      JSON/PP/
      JSON/PP/Boolean.pm
      JSON/PP.pm
      ReadMe-KeePass2_to_1p4.txt
    
  • jon102034050
    jon102034050
    Community Member
    Options

    alright, got past that error - I just simply didn't copy my xml file into the downloaded converter directory. But, when I run it now, I get "no entries detected". when I ran it with debug, it chunked through my whole xml file, and I can see the entries... thoughts?

  • MrC
    MrC
    Volunteer Moderator
    Options

    Do you have keepassX perchance, instead of keepass2 ?

    $ perl keepass2_to_1p4.pl -v  ~/Desktop/keepass2_export.xml
    Imported 345 cards
    Exporting 283 login items
    Exporting 62 note items
    
    $ perl keepass2_to_1p4.pl -v  ~/Desktop/keepassx_export.xml
    No entries detected
    
  • jon102034050
    jon102034050
    Community Member
    Options

    Derp, I'm an idiot... Guess I didn't realize there was any difference. Got it working! Thanks for the awesome support!

  • Hi jon,

    MrC is definitely awesome. I'm glad you got it working!

This discussion has been closed.