modoboa / modoboa-imap-migration

An extension to ease the migration between 2 IMAP servers using offlineimap
ISC License
16 stars 12 forks source link

Error retrieving password from modoboa #17

Closed InToSSH closed 7 years ago

InToSSH commented 7 years ago

Hi, there was an error while offlineimap was running, so I tried to manually run the function get_user_password. Problem is that this function returns an error, which I am not able to fix.

File ".offlineimap.py", line 21, in <module>
    get_user_password("test@example.com");
  File ".offlineimap.py", line 17, in get_user_password
    mailbox__user__username=username
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa_imap_migration/models.py", line 24, in password
    return decrypt(self._password)
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/cryptutils.py", line 52, in decrypt
    clear = decryptor.update(ct) + decryptor.finalize()
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 159, in finalize
    data = self._ctx.finalize()
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 172, in finalize
    "The length of the provided data is not a multiple of "
ValueError: The length of the provided data is not a multiple of the block length.

Is there anything to do to fix it? I tried running it with and without modoboa environment. Modoboa is the latest version installed using modoboa-installer. Thanks

InToSSH commented 7 years ago

So after some elaborating, I found the problem in DB. In table modoboa_imap_migration_migration the size for varchar field _password is 100 characters, which was not enough for the encrypted password to be saved. I raised this value to 255, readded the account to be migrated and now the password works fine.

tonioo commented 7 years ago

@InToSSH thank you for reporting this, I'll fix it asap.

dugite-code commented 7 years ago

Just ran into this issue myself when re-building my server. To save anyone else some time searching how to do it.

sudo psql -U modoboa -W -h localhost
ALTER TABLE modoboa_imap_migration_migration ALTER COLUMN _password TYPE varchar(255);
/q