Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Chrome/94.0.4606.71 - "Failed to decrypt the cipher text with DPAPI" with 0.12.1 #97

Closed
howardjones opened this issue Oct 5, 2021 · 1 comment

Comments

@howardjones
Copy link

howardjones commented Oct 5, 2021

This seems to be #44 but that was before PR #48 which supposedly fixed it. I guess something has changed again since?

Python 3.9.5 on Windows 10.

I am loading cookies from a non-standard location, written to by my Selenium session:

  options = webdriver.ChromeOptions()
  options.add_argument('--user-data-dir=c:\\temp\\profile2')
  client = webdriver.Chrome(options)
  # ---
  cookies = browser_cookie3.chrome(cookie_file="C:\\temp\\profile2\\Default\\Cookies")  

and I can see a sqlite file where I am pointing with valid contents (I can browse the tables in pycharm)

Traceback (most recent call last):
  File "E:\mpr\venv39\lib\site-packages\browser_cookie3\__init__.py", line 317, in _decrypt
    return self._decrypt_windows_chromium(value, encrypted_value)
  File "E:\mpr\venv39\lib\site-packages\browser_cookie3\__init__.py", line 308, in _decrypt_windows_chromium
    _, data = crypt_unprotect_data(encrypted_value)
  File "E:\mpr\venv39\lib\site-packages\browser_cookie3\__init__.py", line 98, 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:

Traceback (most recent call last):
  File "E:\mpr\venv39\lib\site-packages\browser_cookie3\__init__.py", line 333, in _decrypt
    data = aes.decrypt_and_verify(encrypted_value[12:-16], tag)
  File "E:\mpr\venv39\lib\site-packages\Crypto\Cipher\_mode_gcm.py", line 567, in decrypt_and_verify
  File "E:\mpr\venv39\lib\site-packages\Crypto\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:

Traceback (most recent call last):
  File "E:\mpr\code\selenium-test.py", line 160, in <module>
    main()
  File "E:\mpr\code\selenium-test.py", line 154, in main
    cookies = browser_cookie3.chrome(cookie_file="C:\\temp\\profile2\\Default\\Cookies")
  File "E:\mpr\venv39\lib\site-packages\browser_cookie3\__init__.py", line 596, in chrome
    return Chrome(cookie_file, domain_name, key_file).load()
  File "E:\mpr\venv39\lib\site-packages\browser_cookie3\__init__.py", line 293, in load
    value = self._decrypt(item[5], item[6])
  File "E:\mpr\venv39\lib\site-packages\browser_cookie3\__init__.py", line 335, in _decrypt
    raise BrowserCookieError('Unable to get key for cookie decryption')
browser_cookie3.BrowserCookieError: Unable to get key for cookie decryption
Exception ignored in: <function ChromiumBased.__del__ at 0x00000202566FDEE0>
Traceback (most recent call last):
  File "E:\mpr\venv39\lib\site-packages\browser_cookie3\__init__.py", line 256, in __del__
    os.remove(self.tmp_cookie_file)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\HOWARD~1\\AppData\\Local\\Temp\\tmprktw7dzz.sqlite'

@rafiibrahim8
Copy link
Collaborator

rafiibrahim8 commented Oct 5, 2021

You have to pass the key_file argument too to the chrome method. The key file is named Local State. And it should be on user data dir ('c:\temp\profile2\Local State' in your case.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants