marcwebbie / passpie

:closed_lock_with_key: Multiplatform command-line password manager
http://passpie.readthedocs.org/
MIT License
921 stars 68 forks source link

Error on spesific password #41

Closed enmy211 closed 9 years ago

enmy211 commented 9 years ago

If I use a password like Tjo13'Ex* I get error: AttributeError: 'NoneType' object has no attribute 'encode' and passpie stops and nothing is inserted.

I use Ubuntu 14.04 LTS and the system is updated.

marcwebbie commented 9 years ago

Hello @enmy211

enmy211 commented 9 years ago

passpie update egg

Name [egg]: 
Login [spam]: 
Password [*****]: 
Repeat for confirmation: 
Comment [her er en kommentar]: 
Traceback (most recent call last):
  File "/usr/local/bin/passpie", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 644, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 991, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/passpie/cli.py", line 216, in update
    values["password"] = cryptor.encrypt(password)
  File "/usr/local/lib/python2.7/dist-packages/passpie/crypt.py", line 65, in encrypt
    encrypted = self._gpg.encrypt(data, self.current_key)
  File "/usr/local/lib/python2.7/dist-packages/gnupg/gnupg.py", line 972, in encrypt
    stream = _make_binary_stream(data, self._encoding)
  File "/usr/local/lib/python2.7/dist-packages/gnupg/_util.py", line 547, in _make_binary_stream
    thing = thing.encode(encoding)
AttributeError: 'NoneType' object has no attribute 'encode'

passpie version: 0.1 python version: 2.7.6 Yes, I installed via pip install passpie

marcwebbie commented 9 years ago

Thanks for the reply.

If you update to last version is the problem solved? pip install -U passpie. If not, do you have any other credentials that were added to the database ok?

What is the output of passpie status?

enmy211 commented 9 years ago

Hey, thanks for your quick response!

~$ passpie update test1@testen
Name [testen]: 
Login [test1]: 
Password [*****]: 
Repeat for confirmation: 
Comment []: 
Traceback (most recent call last):
  File "/usr/local/bin/passpie", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 644, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 991, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/passpie/cli.py", line 219, in update
    values["password"] = cryptor.encrypt(password)
  File "/usr/local/lib/python2.7/dist-packages/passpie/crypt.py", line 66, in encrypt
    encrypted = self._gpg.encrypt(data, self.current_key)
  File "/usr/local/lib/python2.7/dist-packages/gnupg/gnupg.py", line 972, in encrypt
    stream = _make_binary_stream(data, self._encoding)
  File "/usr/local/lib/python2.7/dist-packages/gnupg/_util.py", line 547, in _make_binary_stream
    thing = thing.encode(encoding)
AttributeError: 'NoneType' object has no attribute 'encode'
enmy211 commented 9 years ago

Sorry, I forgot passpie status

 passpie status
Passphrase: 
╒═══════════════════╤═════════╤════════════╤════════════╕
│ Name              │ Login   │ Password   │ Modified   │
╞═══════════════════╪═════════╪════════════╪════════════╡
│ balle             │ test    │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ egg               │ spam    │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ github.com        │ enmy211 │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ klorin            │ balle   │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ nesbanken         │ _       │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ pythonchallenge   │ einy    │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ ringnettadslmodem │ admin   │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ test2             │ _       │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ testen            │ test    │ OK         │ OK         │
├───────────────────┼─────────┼────────────┼────────────┤
│ testen            │ test1   │ OK         │ OK         │
╘═══════════════════╧═════════╧════════════╧════════════╛
marcwebbie commented 9 years ago

it might be a problem with GnuPG.

Do you manage do re-insert the credential using: passpie add test1@testen --force?

enmy211 commented 9 years ago

Yes, I can passpie add test1@testen --force successfully. I get the same error as earlier when I use update.

marcwebbie commented 9 years ago

With that Tjo13'Ex* password that you are having the error right?

enmy211 commented 9 years ago

I can add a new credential with any kind of password now. When I try to update a credential I get the same error as earlier, no matter what the password is.

I am a cmd-geek and this program would fit perfect in my workflow. Thank you for your patience.

marcwebbie commented 9 years ago

Hello @enmy211

Could you try this:

export PYTHONIOENCODING=utf-8
passpie update test1@testen
enmy211 commented 9 years ago

Sorry, the same failure. My locale is norwegian but I changed to English, but no difference.

Don't give up!!! I don't.

marcwebbie commented 9 years ago

Do you have python3 and virtualenv installed?

if so, try something:

virtualenv -p `which python3` /tmp/env
source /tmp/env/bin/activate
pip install passpie
which passpie
which python
passpie update test1@testen
enmy211 commented 9 years ago

When I install passpie, there is one error when the installation program is trying to import #include <yaml.h>

(env)eivind@gampen:~$ pip install passpie Downloading/unpacking passpie Downloading passpie-0.1.3-py2.py3-none-any.whl Downloading/unpacking gnupg==2.0.2 (from passpie) Downloading gnupg-2.0.2.tar.gz (97kB): 97kB downloaded Running setup.py (path:/tmp/env/build/gnupg/setup.py) egg_info for package gnupg

Downloading/unpacking PyYAML==3.11 (from passpie) Downloading PyYAML-3.11.tar.gz (248kB): 248kB downloaded Running setup.py (path:/tmp/env/build/PyYAML/setup.py) egg_info for package PyYAML

Downloading/unpacking tinydb==2.3.1.post2 (from passpie) Downloading tinydb-2.3.1.post2.zip Running setup.py (path:/tmp/env/build/tinydb/setup.py) egg_info for package tinydb

Downloading/unpacking tabulate==0.7.5 (from passpie) Downloading tabulate-0.7.5.tar.gz Running setup.py (path:/tmp/env/build/tabulate/setup.py) egg_info for package tabulate

Downloading/unpacking pyperclip==1.5.9 (from passpie) Downloading pyperclip-1.5.9.zip Running setup.py (path:/tmp/env/build/pyperclip/setup.py) egg_info for package pyperclip

Downloading/unpacking click==4.0 (from passpie) Downloading click-4.0-py2.py3-none-any.whl (62kB): 62kB downloaded Downloading/unpacking psutil>=1.2.1 (from gnupg==2.0.2->passpie) Downloading psutil-2.2.1.tar.gz (223kB): 223kB downloaded Running setup.py (path:/tmp/env/build/psutil/setup.py) egg_info for package psutil

warning: no previously-included files matching '*' found under directory 'docs/_build'

Installing collected packages: passpie, gnupg, PyYAML, tinydb, tabulate, pyperclip, click, psutil Running setup.py install for gnupg got version from file gnupg/_version.py {'full': '4f1b1f6a8d16df9d4e1f29ba9223f05889131189', 'version': '2.0.2'} changing mode of build/scripts-3.4/versioneer.py from 664 to 775 UPDATING build/lib/gnupg/_version.py

changing mode of /tmp/env/bin/versioneer.py to 775

Running setup.py install for PyYAML checking if libyaml is compilable x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -I/tmp/env/include/python3.4m -c build/temp.linux-x86_64-3.4/check_libyaml.c -o build/temp.linux-x86_64-3.4/check_libyaml.o build/temp.linux-x86_64-3.4/check_libyaml.c:2:18: fatal error: yaml.h: Ingen slik fil eller filkatalog #include <yaml.h>
^ compilation terminated.

libyaml is not found or a compiler error: forcing --without-libyaml
(if libyaml is installed correctly, you may need to
 specify the option --include-dirs or uncomment and
 modify the parameter include_dirs in setup.cfg)

Running setup.py install for tinydb

Running setup.py install for tabulate

Installing tabulate script to /tmp/env/bin

Running setup.py install for pyperclip

Running setup.py install for psutil building '_psutil_linux' extension x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -DPSUTIL_VERSION=221 -I/usr/include/python3.4m -I/tmp/env/include/python3.4m -c psutil/_psutil_linux.c -o build/temp.linux-x86_64-3.4/psutil/_psutil_linux.o x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/psutil/_psutil_linux.o -o build/lib.linux-x86_64-3.4/_psutil_linux.cpython-34m.so building '_psutil_posix' extension x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -I/tmp/env/include/python3.4m -c psutil/_psutil_posix.c -o build/temp.linux-x86_64-3.4/psutil/_psutil_posix.o x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/psutil/_psutil_posix.o -o build/lib.linux-x86_64-3.4/_psutil_posix.cpython-34m.so

warning: no previously-included files matching '*' found under directory 'docs/_build'

Successfully installed passpie gnupg PyYAML tinydb tabulate pyperclip click psutil Cleaning up...

The error is still the same:

(env)eivind@gampen:~$ passpie update test1@testen Name [testen]: Login [test1]: Password [**_]: Repeat for confirmation: Comment []: Traceback (most recent call last): File "/usr/local/bin/passpie", line 11, in sys.exit(cli()) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 664, in call* return self.main(_args, _kwargs) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 644, in main rv = self.invoke(ctx) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 991, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 837, in invoke return ctx.invoke(self.callback, _ctx.params) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 464, in invoke return callback(_args, _kwargs) File "/usr/local/lib/python2.7/dist-packages/passpie/cli.py", line 224, in update values["password"] = cryptor.encrypt(password) File "/usr/local/lib/python2.7/dist-packages/passpie/crypt.py", line 66, in encrypt encrypted = self._gpg.encrypt(data, self.current_key) File "/usr/local/lib/python2.7/dist-packages/gnupg/gnupg.py", line 972, in encrypt stream = _make_binary_stream(data, self._encoding) File "/usr/local/lib/python2.7/dist-packages/gnupg/_util.py", line 547, in _make_binary_stream thing = thing.encode(encoding) AttributeError: 'NoneType' object has no attribute 'encode'

enmy211 commented 9 years ago

Version of python in env: (env)eivind@gampen:~$ python -V Python 3.4.0

marcwebbie commented 9 years ago

Strange,

Even though the output of python -V is 3.4.0 when you run passpie it stills uses your global passpie

Traceback (most recent call last):
File "/usr/local/bin/passpie", line 11, in 

Can you tell me the output of with this env activated:

which python
echo $PATH
enmy211 commented 9 years ago

eivind@gampen:~$ source /tmp/env/bin/activate (env)eivind@gampen:~$ which python /tmp/env/bin/python (env)eivind@gampen:~$ echo $PATH /tmp/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games (env)eivind@gampen:~$

marcwebbie commented 9 years ago

Thanks,

What about which passpie?

enmy211 commented 9 years ago

(env)eivind@gampen:~$ which passpie /tmp/env/bin/passpie (env)eivind@gampen:~$

marcwebbie commented 9 years ago

Hello,

Could you open python from the virtualenv. Make sure it is python3 then run this:

from passpie.crypt import Cryptor
with Cryptor("/tmp/.passpie") as cryptor:
    test_passphrase = "s3cr3t"
    cryptor.create_keys(test_passphrase)
    encrypted = cryptor.encrypt('super secret passpword')
    decrypted = cryptor.decrypt(encrypted, test_passphrase)

print(encrypted)
print('=====================')
print(decrypted)

What does that print?

enmy211 commented 9 years ago

To be 100% shure that it is python3, type python at command prompt:

(env)eivind@gampen:/tmp/env$ python
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

I have made a file of your (passpie_test.py) code and run it with python passpie_test.py

There is no response so i type crtl+c to stop it and the error is:

(env)eivind@gampen:/tmp/env$ python passpie_test.py 
^CTraceback (most recent call last):
  File "passpie_test.py", line 4, in <module>
    cryptor.create_keys(test_passphrase)
  File "/tmp/env/lib/python3.4/site-packages/passpie/crypt.py", line 58, in create_keys
    keys = self._gpg.gen_key(KEY_INPUT.format(passphrase))
  File "/tmp/env/lib/python3.4/site-packages/gnupg/gnupg.py", line 563, in gen_key
    self._handle_io(args, f, key, binary=True)
  File "/tmp/env/lib/python3.4/site-packages/gnupg/_meta.py", line 744, in _handle_io
    self._collect_output(p, result, writer, stdin)
  File "/tmp/env/lib/python3.4/site-packages/gnupg/_meta.py", line 721, in _collect_output
    dr.join()
  File "/usr/lib/python3.4/threading.py", line 1060, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.4/threading.py", line 1076, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt

(env)eivind@gampen:/tmp/env$

marcwebbie commented 9 years ago

Unfortunately, GnuPG keys creation can be very slow some times, it might even take 1 minute due to the default GPG key size that passpie uses: 4096 bits.

Please try again... when you have time

enmy211 commented 9 years ago

I gave it more time and good news:

(env)eivind@gampen:/tmp/env$ python passpie_test.py 
-----BEGIN PGP MESSAGE-----

hQEMA//5SvDqAknOAQgAqCtMSMGA/IAB7sK5yWJLxDN5dofU0GRQ55HCr5H04oqt
tnYPf69v99uZ1WNlz3s9swDZANjETZD8ae1O1k/1foUXAUufIVHzF1/n7nrhdI3q
OKNqtgiJ17GHRTCMfm0SBsNR76XX8zjU2gMna8Tlr7N9+oznNJEL3Yei8j+9CN+m
Adh6/r//mYIf86uuqp25R6cE8a9w5HyMP9zsHuQO1kNGiMhSfqojCvHkMAYrAQWY
NSCxjO8omkwVDF0uIrgBBFVYMHksIn/hhW90YOqd3LmCFLVR2gO6BnZw9L5b9bgG
8cGlGheHPHQ3i5JhArhAkKUJdqufj+lkOSgsBNq/utJRARG59HsCRJUEuTWwSopt
AHzx4X4hT1uFWyDTjn8DHT9uTTBEFa9M4QNAMicYH4b7Y8fpvnca3Hw2KhrZQdzd
5iwegJndp77kIeN1WxCf9Dl7
=mEHQ
-----END PGP MESSAGE-----

=====================
super secret passpword
(env)eivind@gampen:/tmp/env$ 

There is more good news: I removed the /tmp/env and installed it once more this morning. And now I can update passpie update test1@testen with no errors! Everyting is working with python 3.4.

Unfortunatly not with python 2.7.

marcwebbie commented 9 years ago

For the python2 issue, it looks like a python-gnupg issue, I will investigate more about it. Unfortunately I couldn't reproduce on my linux boxes.

Anyway.. Nice to see that it is working for you now. :smiley:

enmy211 commented 9 years ago

Thank you for your patience and help. Good luck!

marcwebbie commented 9 years ago

Hello @enmy211 I've managed to reproduce that bug on a 2.7.1 python installation. It looked like it was encoding error for unicode strings.

It looks like it is fixed now. Thanks for your feedback

enmy211 commented 9 years ago

Now it's working on my installation of python (version 2.7.6)!!! Perfect!

Thank you!