louisabraham / ffpass

Import and Export passwords for Firefox Quantum 🔑
MIT License
380 stars 39 forks source link

UnicodeDecodeError in decodeLoginData #50

Closed mcepl closed 4 years ago

mcepl commented 4 years ago

ffpass 0.4.8, python 3.7.3 on Linux/openSUSE/Tumbleweed. Locale cs_CZ.UTF-8

~@stitny$ ffpass export --to passwords.csv
Traceback (most recent call last):
  File "/home/matej/.local/bin/ffpass", line 8, in <module>
    sys.exit(main())
  File "/home/matej/.local/lib/python3.7/site-packages/ffpass/__init__.py", line 354, in main
    args.func(args)
  File "/home/matej/.local/lib/python3.7/site-packages/ffpass/__init__.py", line 269, in main_export
    logins = exportLogins(key, jsonLogins)
  File "/home/matej/.local/lib/python3.7/site-packages/ffpass/__init__.py", line 171, in exportLogins
    decodeLoginData(key, encUsername),
  File "/home/matej/.local/lib/python3.7/site-packages/ffpass/__init__.py", line 133, in decodeLoginData
    return PKCS7unpad(des.decrypt(ciphertext)).decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 0: invalid start byte
~@stitny$
louisabraham commented 4 years ago

Hi, it's very hard for me to reproduce the error.

I tried to create a login kůň and ffpass exported it without any issue.

If you can reproduce the bug, please download the test version (https://github.com/louisabraham/ffpass/archive/encoding.zip), install it with cd ffpass && pip install ..

It should output a more explicit error message (it might contain a password so be careful before publishing the output).

mcepl commented 4 years ago

The problem is not using non-ASCII characters (that .decode() deals with perfectly), but using bytes which are not valid UTF-8. E.g., for some inexplicable reasons:

~ $ grep bugzilla.redhat passwords.csv.gpg 
https://bugzilla.redhat.com,b'\x8b\x16^f',b''
https://bugzilla.redhat.com,b'',b''
https://bugzilla.redhat.com,b'mcepl@cepl.eu',b'VERYSECRET'
https://bugzilla.redhat.com,b'mcepl@redhat.com',b'EVENMORESECRET'
https://bugzilla.redhat.com,b'mcepl@redhat.com',b'EVENMORESECRET'
~ $

Yes, of course, the first two lines present probably invalid data, but with this script I don't care about it, and I would rather have preserved a bit of nonsense, than not having preserved anything (I have just removed that .decode() so all my strings are bytes, ignore that for a moment).

louisabraham commented 4 years ago

I don't understand how these non utf-8 passwords arrived in FF.

I think that your use case is very specific and you seem to be much more advanced than the average user so maybe it's better not to add this as a feature. What do you think?

mcepl commented 4 years ago

I think that your use case is very specific and you seem to be much more advanced than the average user so maybe it's better not to add this as a feature. What do you think?

Certainly, but still you should follow “Be conservative in what you do, be liberal in what you accept from others.” anyway. You never know what comes your way.