roddhjav / pass-import

A pass extension for importing data from most existing password managers
https://www.passwordstore.org/
GNU General Public License v3.0
807 stars 89 forks source link

Import of keepassxc fails (2) #161

Closed pietrotavares closed 2 years ago

pietrotavares commented 3 years ago

UPDATE: The keepass2csv2pass.py script did it for me.

I'm having the same issue described in #90 My database has compression enabled, therefore it should work (I presume..).

However, when I try to pass import keepassxc passwords.kbdx I get the following error:

sequence item 1: expected str instance, NoneType found
Error: passwords.kbdx is not a valid exported keepassxc file.

I've also tried to import from a csv file with pass import keepassxc passwords.csv. First, it prompts with "Password for passwords.csv:" (?) Then, no matter what I type in, it fails with the following error:

'NoneType' object has no attribute 'payload'
Error: passwords.csv is not a valid exported keepassxc file.

I'm on Debian 10 (4.19.0-17-amd64) running Python 3.7.3.

Thank you.

roddhjav commented 3 years ago

That can be different things, can you provide the output with the -vvv option used: pass import keepassxc passwords.kbdx -vvv You can also try directly: pass import passwords.kbdx -vvv

pietrotavares commented 3 years ago

UPDATE: keepass2csv2pass.py worked for me.

Oops, totally missed the -vvv option at first. I apologize. Both pass import passwords.kbdx -vvv and pass import keepassxc passwords.kbdx -vvv yield this same error:

.  Trying to guess file format and manager name.
.  Importer: keepassxc, Format: kdbx, Version:
.  Importing passwords from KeepassxcKDBX to PasswordStore
Password for passwords.kbdx:
.  Traceback (most recent call last):
File "/home/pietro/.local/lib/python3.7/site-packages/pass_import/__main__.py", line 342, in pass_import
  importer.parse()
File "/home/pietro/.local/lib/python3.7/site-packages/pass_import/formats/kdbx.py", line 138, in parse
  history = self._getentry(hentry)
File "/home/pietro/.local/lib/python3.7/site-packages/pass_import/formats/kdbx.py", line 56, in _getentry
  entry['group'] = os.sep.join(kpentry.path)
TypeError: sequence item 1: expected str instance, NoneType found

sequence item 1: expected str instance, NoneType found
Error: passwords.kbdx is not a valid exported keepassxc file.

Looks like a parsing error regarding groups? Anyways, I got rid of all groups containing whitespaces and/or slashes (e.g., "Backup / Safety Net") but the error persisted.

Here's the "directory structure" for my database, in case it helps:

image

roddhjav commented 3 years ago

Ok, that was a bug. It should be fixed with 2231afe.

pietrotavares commented 3 years ago

I'm trying to test the patch, but it's giving me the same error. Please see if I'm doing something wrong: (Note that I had installed pass-import previously with pip (i.e., pip install pass-import)

These are the steps I took:

  1. pip uninstall pass-import
  2. pip uninstall pass_import
  3. git clone https://github.com/roddhjav/pass-import
  4. cd pass-import
  5. python3 setup.py install --user

Then, I ran:

pass import passwords.kbdx -vvv
pass import keepassxc passwords.kbdx -vvv
./import.bash ~/Backups/passwords.kbdx -vvv

All yielding the same error as before, that is:

.  Trying to guess file format and manager name.
.  Importer: keepassxc, Format: kdbx, Version:
.  Importing passwords from KeepassxcKDBX to PasswordStore
Password for passwords.kbdx:
.  Traceback (most recent call last):
File "/home/pietro/.local/lib/python3.7/site-packages/pass_import/__main__.py", line 342, in pass_import
  importer.parse()
File "/home/pietro/.local/lib/python3.7/site-packages/pass_import/formats/kdbx.py", line 139, in parse
  history = self._getentry(hentry)
File "/home/pietro/.local/lib/python3.7/site-packages/pass_import/formats/kdbx.py", line 57, in _getentry
  entry['group'] = os.sep.join(kpentry.path)
TypeError: sequence item 1: expected str instance, NoneType found

sequence item 1: expected str instance, NoneType found
Error: passwords.kbdx is not a valid exported keepassxc file.

I'm positive that I'm running the updated version, since the line numbers in the error message have changed by one (the line added in your patch)

Would you like me to send a redacted version of my database to run tests against? I think we might be hitting an edge-case here.

amorphous commented 2 years ago

I'm having the same problem - using a build from the master branch. I get this when trying to import a keepassx file:

$ pass import keepassx  '~/Documents/KeyPass Dec 2021.kdbx' -vvv

  .  Trying to guess file format.
  .  Importer: keepassx, Format: xml, Version: 
  .  Importing passwords from KeepassxXML to PasswordStore
  .  Traceback (most recent call last):
  File "~/.local/lib/python3.9/site-packages/pass_import-3.2-py3.9.egg/pass_import/__main__.py", line 341, in pass_import
    with cls_import(conf['in'], settings=settings) as importer:
  File "~/.local/lib/python3.9/site-packages/pass_import-3.2-py3.9.egg/pass_import/core.py", line 113, in __enter__
    raise PMError("%s is not a password repository." % self.prefix)
pass_import.errors.PMError: ~/Documents/KeyPass Dec 2021.kdbx is not a password repository.
$ pass import keepassx  '~/Documents/key.csv' -vvv
  .  Trying to guess file format.
  .  Importer: keepassx, Format: xml, Version: 
  .  Importing passwords from KeepassxXML to PasswordStore
  .  Traceback (most recent call last):
  File "~/.local/lib/python3.9/site-packages/pass_import-3.2-py3.9.egg/pass_import/__main__.py", line 341, in pass_import
    with cls_import(conf['in'], settings=settings) as importer:
  File "~/.local/lib/python3.9/site-packages/pass_import-3.2-py3.9.egg/pass_import/core.py", line 113, in __enter__
    raise PMError("%s is not a password repository." % self.prefix)
pass_import.errors.PMError: ~/Documents/key.csv is not a password repository.

I've also tried importing using keepassxc and keepassx2 against the keepassx file.

Should I be expecting a request for a passowrd?

roddhjav commented 2 years ago

That is different. According to the code your path ~/Documents/KeyPass Dec 2021.kdbx does not exist.

zeorin commented 2 years ago

Also not working for me:

❯ pass import ~/Documents/Passwords/passwords.kdbx -vvv
  .  Trying to guess file format and manager name.
  .  Importer: keepassxc, Format: kdbx, Version:
  .  Importing passwords from KeepassxcKDBX to PasswordStore
Password for /home/zeorin/Documents/Passwords/passwords.kdbx:
  .  Traceback (most recent call last):
  File "/nix/store/22snjka6ccrp5n1yl05sch46xdv34p1x-pass-import-3.2/lib/python3.9/site-packages/pass_import/__main__.py", line 342, in pass_import
    importer.parse()
  File "/nix/store/22snjka6ccrp5n1yl05sch46xdv34p1x-pass-import-3.2/lib/python3.9/site-packages/pass_import/formats/kdbx.py", line 138, in parse
    history = self._getentry(hentry)
  File "/nix/store/22snjka6ccrp5n1yl05sch46xdv34p1x-pass-import-3.2/lib/python3.9/site-packages/pass_import/formats/kdbx.py", line 56, in _getentry
    entry['group'] = os.sep.join(kpentry.path)
TypeError: sequence item 3: expected str instance, NoneType found

  w  sequence item 3: expected str instance, NoneType found
 [x] Error: /home/zeorin/Documents/Passwords/passwords.kdbx is not a valid exported keepassxc file.
roddhjav commented 2 years ago

This has already been fixed with 2231afe. Please use the master branch. I will release a new version soon anyway.

rigrig commented 2 years ago

I'm still getting this error in the master branch.
I added some logging like this to kdbx.py:

        if kpentry.path is not None:
            try:
                entry['group'] = os.sep.join(kpentry.path)
            except TypeError as e:
                print('-')
                print(e)
                print('--')
                print(kpentry)
                print('---')
                print(kpentry.path)
                print('----')

And it outputs errors like this:

-
sequence item 3: expected str instance, NoneType found
--
HistoryEntry: Entry: "Websites/Gaming/DCSS/ (rigrig)"
---
['Websites', 'Gaming', 'DCSS', None]
----

So it trips up over the path containing None. No idea if that is expected to happen and can just be filtered out.

roddhjav commented 2 years ago

That obviously an issue for pykeepass, pass import will manage it anyway. Should be fixed in a68d947.