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

Incompatibility with 'crypography' 40.1 #12

Open
PeterWalchhofer opened this issue Jun 11, 2023 · 0 comments
Open

Incompatibility with 'crypography' 40.1 #12

PeterWalchhofer opened this issue Jun 11, 2023 · 0 comments

Comments

@PeterWalchhofer
Copy link

Installed package via pip install git+https://... but get an error when running

from amcat4py import AmcatClient
amcat = AmcatClient("http://localhost/amcat")
amcat.login()

---
TypeError                                 Traceback (most recent call last)
Cell In[2], line 2
      1 from amcat4py import AmcatClient
----> 2 amcat = AmcatClient("http://localhost/amcat")
      3 amcat.login()

File [~/anaconda3/envs/opted/lib/python3.11/site-packages/amcat4py/amcatclient.py:44](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/peter/uni/ParLawSpeechDashboard/~/anaconda3/envs/opted/lib/python3.11/site-packages/amcat4py/amcatclient.py:44), in AmcatClient.__init__(self, host, ignore_tz)
     42 self.server_config = self.get_server_config()
     43 # If we have a token cached, load it. Otherwise, only log in if explicitly requested
---> 44 self.token = _get_token(self.host, login_if_needed=False)

File [~/anaconda3/envs/opted/lib/python3.11/site-packages/amcat4py/auth.py:132](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/peter/uni/ParLawSpeechDashboard/~/anaconda3/envs/opted/lib/python3.11/site-packages/amcat4py/auth.py:132), in _get_token(host, force_refresh, login_if_needed)
    130 file_path = user_cache_dir(CLIENT_ID) + "/" + sha256(host.encode()).hexdigest()
    131 if os.path.exists(file_path) and not force_refresh:
--> 132     token = secret_read(file_path, host)
    133 elif login_if_needed:
    134     token = get_middlecat_token(host)

File [~/anaconda3/envs/opted/lib/python3.11/site-packages/amcat4py/auth.py:176](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/peter/uni/ParLawSpeechDashboard/~/anaconda3/envs/opted/lib/python3.11/site-packages/amcat4py/auth.py:176), in secret_read(path, host)
    174 with open(path, "rb") as f:
    175     token_enc = f.read()
--> 176 fernet = Fernet(make_key(host))
    177 return loads(fernet.decrypt(token_enc).decode())

File [~/anaconda3/envs/opted/lib/python3.11/site-packages/amcat4py/auth.py:191](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/peter/uni/ParLawSpeechDashboard/~/anaconda3/envs/opted/lib/python3.11/site-packages/amcat4py/auth.py:191), in make_key(key)
    181 """
    182 Helper function to make key for encryption of tokens
    183 :param key: string that is turned into key.
    184 """
    185 kdf = PBKDF2HMAC(
    186     algorithm=sha256(),
    187     length=32,
    188     salt="supergeheim".encode(),
    189     iterations=5,
    190 )
--> 191 return urlsafe_b64encode(kdf.derive(key.encode()))

File [~/anaconda3/envs/opted/lib/python3.11/site-packages/cryptography/hazmat/primitives/kdf/pbkdf2.py:53](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/peter/uni/ParLawSpeechDashboard/~/anaconda3/envs/opted/lib/python3.11/site-packages/cryptography/hazmat/primitives/kdf/pbkdf2.py:53), in PBKDF2HMAC.derive(self, key_material)
     50     raise AlreadyFinalized("PBKDF2 instances can only be used once.")
     51 self._used = True
---> 53 return rust_openssl.kdf.derive_pbkdf2_hmac(
     54     key_material,
     55     self._algorithm,
     56     self._salt,
     57     self._iterations,
     58     self._length,
     59 )

It works when downgrading cryptgraphy to 40.0.2

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

1 participant