Re: crypto.py bug on server add form (button save) with python 3.5 - Can't convert 'bytes' object to str implicitly

From: Dave Page <dpage(at)pgadmin(dot)org>
To: Khushboo Vashi <khushboo(dot)vashi(at)enterprisedb(dot)com>
Cc: Ladislav Jech <archenroot(at)gmail(dot)com>, pgadmin-hackers <pgadmin-hackers(at)postgresql(dot)org>
Subject: Re: crypto.py bug on server add form (button save) with python 3.5 - Can't convert 'bytes' object to str implicitly
Date: 2017-06-28 13:44:46
Message-ID: CA+OCxoywkmu7txeXOCVx4Hmctspor2=o36+EF+39ebHQB68xbA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-hackers

Thanks, patch applied.

On Wed, Jun 28, 2017 at 12:19 AM, Khushboo Vashi <
khushboo(dot)vashi(at)enterprisedb(dot)com> wrote:

> Hi,
>
> Please find the attached patch which will fix the password
> encryption/decryption for python3.
> I have modified the fix suggested by Ladislav to work with both python2
> and python3.
>
> Thanks,
> Khushboo
>
>
> On Tue, Jun 27, 2017 at 4:41 PM, Ladislav Jech <archenroot(at)gmail(dot)com>
> wrote:
>
>> Hi,
>> It will be good if you support fully github or any GIT repository for
>> managing pull requests. Is there any or you wan't me to generate *.patch
>> file? I am new to pgadmin 4, so not sure how this works. Let me know.
>> Ladislav
>>
>> 2017-06-27 11:52 GMT+02:00 Khushboo Vashi <khushboo(dot)vashi(at)enterprisedb(dot)c
>> om>:
>>
>>> Hi,
>>>
>>> Can you send the patch for the same. I think this is the valid fix.
>>>
>>> Thanks,
>>> Khushboo
>>>
>>> On Tue, Jun 27, 2017 at 3:02 PM, Ladislav Jech <archenroot(at)gmail(dot)com>
>>> wrote:
>>>
>>>> I am running on following Gentoo system with Python 3.5 as default
>>>> (although i have 2.7 and 3.4 available to switch as well).
>>>>
>>>> I compiled from source code via github:
>>>> commit 15cb9fc35b41736a331a452b9303a79e8f13ee36 (HEAD -> master,
>>>> origin/master, origin/HEAD)
>>>>
>>>> The error appears when I want to click on Save while adding new server
>>>> to the list, I put few lines into the code to detect the times:
>>>> 2017-06-27 13:21:48,329: DEBUG pgadmin: Not running under the desktop
>>>> runtime, port: 5050
>>>> Starting pgAdmin 4. Please navigate to http://127.0.0.1:5050 in your
>>>> browser.
>>>> str var python type is <class 'str'>
>>>> str var object's type is str
>>>> padding_string var python type is <class 'bytes'>
>>>> padding_string var object's type is bytes
>>>> 2017-06-27 13:21:53,028: ERROR pgadmin: Can't convert 'bytes' object
>>>> to str implicitly
>>>> Traceback (most recent call last):
>>>> File "/home/zangetsu/devel/tmp/pgadmin4/web/pgadmin/browser/server_groups/servers/__init__.py",
>>>> line 619, in create
>>>> password = encrypt(password, current_user.password)
>>>> File "/home/zangetsu/devel/tmp/pgadmin4/web/pgadmin/utils/crypto.py",
>>>> line 31, in encrypt
>>>> cipher = AES.new(pad(key), AES.MODE_CFB, iv)
>>>> File "/home/zangetsu/devel/tmp/pgadmin4/web/pgadmin/utils/crypto.py",
>>>> line 80, in pad
>>>> return str + ((32 - len(str) % 32) * padding_string)
>>>> TypeError: Can't convert 'bytes' object to str implicitly
>>>> 2017-06-27 13:21:53,031: INFO werkzeug: 127.0.0.1 - - [27/Jun/2017
>>>> 13:21:53] "POST /browser/server/obj/2/ HTTP/1.1" 410 -
>>>> 2017-06-27 13:22:49,936: INFO werkzeug: * Detected change in
>>>> '/home/zangetsu/devel/tmp/pgadmin4/web/pgadmin/utils/crypto.py',
>>>> reloading
>>>> 2017-06-27 13:22:50,138: INFO werkzeug: * Restarting with reloader
>>>>
>>>> So this is the error:
>>>> Can't convert 'bytes' object to str implicitly
>>>>
>>>> To fix this on Python 3.5 I simply changed in
>>>> pgadmin4/web/pgadmin/utils/crypto.py file this line:
>>>> return str + ((32 - len(str) % 32) * padding_string)
>>>> to
>>>> return str + ((32 - len(str) % 32) * padding_string.decode())
>>>>
>>>> Another solution could be to change whole str into bytes. Not sure what
>>>> is better, but now it works.
>>>>
>>>
>>>
>>
>

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgadmin-hackers by date

  From Date Subject
Next Message Harshal Dhumal 2017-06-28 13:48:01 Re: [pgAdmin4][Patch]: Fixed RM #2489: Copy from the results grid is extremely slow and fails with large datasets
Previous Message Dave Page 2017-06-28 13:44:37 pgAdmin 4 commit: Fix encoding issue when saving servers. Fixes #2518