browser_cookie3 icon indicating copy to clipboard operation
browser_cookie3 copied to clipboard

Error decrypting cookies in Chrome with Python 3.11

Open Nekmo opened this issue 3 years ago • 0 comments

Hi,

I'm testing your library, thank you very much for your work! I've had a problem testing your project with Python 3.11 and Chrome. I try to follow the usage example but I get this error:

$ python
Python 3.11.0 (main, Oct 25 2022, 23:59:53) [GCC 12.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import browser_cookie3
>>> cj = browser_cookie3.chrome()
Traceback (most recent call last):
  File "/home/nekmo/.virtualenvs/xxxxxxxxxxxxx/lib/python3.11/site-packages/browser_cookie3/__init__.py", line 395, in _decrypt
    decrypted += cipher.feed()
                 ^^^^^^^^^^^^^
  File "/home/nekmo/.virtualenvs/xxxxxxxxxxxxx/lib/python3.11/site-packages/pyaes/blockfeeder.py", line 169, in feed
    result = self._final(self._buffer, self._padding)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nekmo/.virtualenvs/xxxxxxxxxxxxx/lib/python3.11/site-packages/pyaes/blockfeeder.py", line 77, in _block_final_decrypt
    return strip_PKCS7_padding(self.decrypt(data))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nekmo/.virtualenvs/xxxxxxxxxxxxx/lib/python3.11/site-packages/pyaes/util.py", line 58, in strip_PKCS7_padding
    raise ValueError("invalid padding byte")
ValueError: invalid padding byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nekmo/.virtualenvs/xxxxxxxxxxxxx/lib/python3.11/site-packages/browser_cookie3/__init__.py", line 840, in chrome
    return Chrome(cookie_file, domain_name, key_file).load()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nekmo/.virtualenvs/xxxxxxxxxxxxx/lib/python3.11/site-packages/browser_cookie3/__init__.py", line 329, in load
    value = self._decrypt(value, enc_value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nekmo/.virtualenvs/xxxxxxxxxxxxx/lib/python3.11/site-packages/browser_cookie3/__init__.py", line 397, in _decrypt
    raise BrowserCookieError('Unable to get key for cookie decryption')
browser_cookie3.BrowserCookieError: Unable to get key for cookie decryption

However with Python 3.10 I do not receive an error:

$ ipython
/usr/lib/python3.10/site-packages/IPython/core/interactiveshell.py:852: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn(
Python 3.10.5 (main, Jun  6 2022, 18:49:26) [GCC 12.1.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import browser_cookie3

In [2]: cj = browser_cookie3.chrome()

Python 3.11 pip freeze:

aiohttp==3.8.3
aiosignal==1.3.1
aiosmtplib==2.0.0
async-timeout==4.0.2
attrs==22.1.0
browser-cookie3==0.16.2
build==0.9.0
certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
click==8.1.3
crontab==0.22.8
cryptography==38.0.3
frozenlist==1.3.3
idna==3.4
importlib-metadata==5.0.0
jaraco.classes==3.2.3
jeepney==0.8.0
Jinja2==3.1.2
keyring==23.11.0
lz4==4.0.2
MarkupSafe==2.1.1
more-itertools==9.0.0
multidict==6.0.2
packaging==21.3
pbkdf2==1.3
pep517==0.13.0
pip-tools==6.9.0
pyaes==1.6.1
pycparser==2.21
pycryptodome==3.15.0
pyparsing==3.0.9
python-dateutil==2.8.2
pytz==2022.6
requests==2.28.1
ruamel.yaml==0.17.4
SecretStorage==3.3.3
sentry-sdk==1.10.1
six==1.16.0
strictyaml==1.6.2
urllib3==1.26.12
yacron==0.17.0
yarl==1.8.1
zipp==3.10.0

Python 3.10 pip freeze:

cffi==1.15.1
cryptography==38.0.3
importlib-metadata==5.0.0
jaraco.classes==3.2.3
jeepney==0.8.0
keyring==23.11.0
lz4==4.0.2
more-itertools==9.0.0
pbkdf2==1.3
pyaes==1.6.1
pycparser==2.21
pycryptodome==3.15.0
SecretStorage==3.3.3
zipp==3.10.0

Let me know if you need more information. Also if you need help with the error.

Thanks!

Nekmo avatar Nov 11 '22 01:11 Nekmo