borisbabic / browser_cookie3

This is a fork of browser_cookie
GNU Lesser General Public License v3.0
854 stars 144 forks source link

chromium: handle latest sqlite schema #215

Open Arth-ur opened 4 weeks ago

Arth-ur commented 4 weeks ago

Starting from version 24, the sha256 of the domain is prepended to the encrypted value of the cookie.

See:

Fix #214

Eitol commented 4 weeks ago

@borisbabic Support for the latest version of Chrome is broken. This fixes the problem

wimglenn commented 3 weeks ago

Until a fix is merged, to install directly from this PR:

pip install --force-reinstall git+https://github.com/borisbabic/browser_cookie3.git@refs/pull/215/head
amitkumarwali commented 3 weeks ago

Until a fix is merged, to install directly from this PR:

pip install git+https://github.com/borisbabic/browser_cookie3.git@refs/pull/215/head

I still get error after this, am i missing something?

On Chrome:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 578, in _decrypt
    data = aes.decrypt_and_verify(encrypted_value[12:-16], tag)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\Cryptodome\Cipher\_mode_gcm.py", line 567, in decrypt_and_verify
    self.verify(received_mac_tag)
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\Cryptodome\Cipher\_mode_gcm.py", line 508, in verify
    raise ValueError("MAC check failed")
ValueError: MAC check failed

During handling of the above exception, another exception occurred:

File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 1186, in chrome
    return Chrome(cookie_file, domain_name, key_file).load()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 516, in load
    value = self._decrypt(value, enc_value, has_integrity_check_for_cookie_domain)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 580, in _decrypt
    raise BrowserCookieError(
browser_cookie3.BrowserCookieError: Unable to get key for cookie decryption

On Vivaldi


Traceback (most recent call last):
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 562, in _decrypt
    return self._decrypt_windows_chromium(value, encrypted_value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 553, in _decrypt_windows_chromium
    _, data = _crypt_unprotect_data(encrypted_value)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 89, in _crypt_unprotect_data
    raise RuntimeError('Failed to decrypt the cipher text with DPAPI')
RuntimeError: Failed to decrypt the cipher text with DPAPI

During handling of the above exception, another exception occurred:

File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 1228, in vivaldi
    return Vivaldi(cookie_file, domain_name, key_file).load()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 516, in load
    value = self._decrypt(value, enc_value, has_integrity_check_for_cookie_domain)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\amitw\AppData\Local\Programs\Python\Python311\Lib\site-packages\browser_cookie3\__init__.py", line 582, in _decrypt
    return data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd8 in position 3: invalid continuation byte
bluesmilery commented 3 weeks ago

@amitkumarwali Try the following command: pip install --force-reinstall --no-deps git+https://github.com/borisbabic/browser_cookie3.git@refs/pull/215/head

--force-reinstall: This flag is used to overwrite the installation of browser_cookie3. --no-deps: This flag is used to prevent upgrading other dependent packages.

amitkumarwali commented 3 weeks ago

@amitkumarwali Try the following command: pip install --force-reinstall --no-deps git+https://github.com/borisbabic/browser_cookie3.git@refs/pull/215/head

--force-reinstall: This flag is used to overwrite the installation of browser_cookie3. --no-deps: This flag is used to prevent upgrading other dependent packages.

Thank you for taking out time and suggesting fix, appreciate it.

Tried the above way but this doesnt seem to work for me. Also tried in a complete new venv but still end up in same error as stated above. In case i can check/debug something, please let me know. thank you again.


     83 if not ctypes.windll.crypt32.CryptUnprotectData(
     84         ctypes.byref(blob_in), ctypes.byref(
     85             desc), ctypes.byref(blob_entropy),
     86         reserved, prompt_struct, CRYPTPROTECT_UI_FORBIDDEN, ctypes.byref(
     87             blob_out)
     88 ):
---> 89     raise RuntimeError('Failed to decrypt the cipher text with DPAPI')
     91 description = desc.value

RuntimeError: Failed to decrypt the cipher text with DPAPI

During handling of the above exception, another exception occurred

    [507] if mac1.digest() != mac2.digest():
--> [508]     raise ValueError("MAC check failed")
ValueError: MAC check failed

    578             data = aes.decrypt_and_verify(encrypted_value[12:-16], tag)
    579         except ValueError:
--> 580             raise BrowserCookieError(
    581                 'Unable to get key for cookie decryption')
    582         return data.decode()
    584 if value or (encrypted_value[:3] not in [b'v11', b'v10']):

BrowserCookieError: Unable to get key for cookie decryption
Arth-ur commented 3 weeks ago

@amitkumarwali I've updated my branch, could you try again if it fixes your problem on Vivaldi?

I don't think it will fix Chrome on Windows because of this https://security.googleblog.com/2024/07/improving-security-of-chrome-cookies-on.html

amitkumarwali commented 2 weeks ago

@Arth-ur - thank you, this fixed my issue on Vivaldi. Appreciate your kind and quick help.

justinnewitter commented 2 weeks ago

This PR fixes the issue for me as well. Hope this gets into a release soon 😄

pjaudiomv commented 1 week ago

@rafiibrahim8 any chance we can get some eyes on this