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

AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'. AWS sam build failure. #7959

Closed
RichaSharmaTR opened this issue Jan 2, 2023 · 8 comments

Comments

@RichaSharmaTR
Copy link

I'm getting below error after installing latest version of cryptography by using requirements.txt file in AWS deployment.

import OpenSSL.SSL
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/OpenSSL/crypto.py", line 3268, in <module>
_lib.OpenSSL_add_all_algorithms()
**_AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'_**

versions used during installation-
cryptography-39.0.0
Python- 3.9
cffi--1.15.1
pip-22.3.1
setuptools-58.1.0

Could you please help me in resolving this issue?

@reaperhulk
Copy link
Member

reaperhulk commented Jan 2, 2023

This occurs with an outdated pyOpenSSL version.

Edit: For anyone else who finds this. pyOpenSSL declares a min/max cryptography version to avoid incompatibilities like this, however it only started doing this in pyOpenSSL 22.1.0 and above. Upgrade to that version (or the latest, which would be a better choice: 23.0.0) and the issue will be (permanently) resolved.

@RichaSharmaTR RichaSharmaTR changed the title AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms' AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'. AWS sam build failure. Jan 2, 2023
@alex alex added the waiting-on-reporter Issue is waiting on a reply from the reporter. It will be automatically cloesd if there is no reply. label Jan 2, 2023
@shjasti
Copy link

shjasti commented Jan 2, 2023

Hi I'm having the same issue with cryptography==39.0.0 and pyOpenSSL==23.0.0. Downgrading to cryptography==38.0.4 and pyOpenSSL==22.1.0 didn't really help either.

@alex
Copy link
Member

alex commented Jan 2, 2023

Are you sure you're actually using cryptography 39.0.0 and pyopenssl 23.0.0?

The code to trigger this simply doesn't exist in pyopenssl, so I doubt that's what's happening. Perhaps try re-creating your virtualenv from scratch.

@shjasti
Copy link

shjasti commented Jan 3, 2023

@alex yep my mistake! turns out I was just looking in the wrong place. thanks!

@zjjott
Copy link

zjjott commented Jan 4, 2023

old version pyOpenssl using "cryptography>=35.0" ,but "cryptography==39.0.0" let openssl broken, and then pip broken too.
maybe cryptography should keep compatibility as a cornerstone of pip?

@reaperhulk
Copy link
Member

cryptography is not a cornerstone of pip, but old versions of pip vendored an older version of urllib3 which automatically used pyopenssl if present in an environment. Upgrading pip or pyopenssl (or removing pyopenssl!) will fix that situation.

@reaperhulk
Copy link
Member

For aws-sam-cli users they have fixed their bug in 1.68.0. I'm going to leave this issue open for a bit longer so others can easily find the solution on the issue tracker (upgrade pyOpenSSL in your pins!), but ultimately this issue is not cryptography's bug.

@reaperhulk reaperhulk removed the waiting-on-reporter Issue is waiting on a reply from the reporter. It will be automatically cloesd if there is no reply. label Jan 5, 2023
@RichaSharmaTR
Copy link
Author

Hi @reaperhulk
The issue is fixed in the latest version of aws-sam-cli. I am not seeing any build failures now. This bug is good to close now.
Thanks!

karen-avetisyan-mc added a commit to karen-avetisyan-mc/oauth1-signer-python that referenced this issue Jan 23, 2023
fix:  for the build issue "AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'

"cryptography 39.0.0 no longer supports openssl 1.1.0 or older and thus is causing this issue.
Reference:

pyca/cryptography#7959
https://cryptography.io/en/latest/changelog/#v39-0-0
As a workaround until the dependencies are fixed, you can force install cryptography 38.0.4 and sam should work (I just verified with my CI/CD builds which all got broken today due to the cryptography update).
taurus-forever added a commit to canonical/mysql-operator that referenced this issue Mar 21, 2023
To update cryptography from 38.0.4 to 39.0.2.

From pyca/cryptography#7959 (comment)
> pyOpenSSL declares a min/max cryptography version to
> avoid incompatibilities like this, however it only
> started doing this in pyOpenSSL 22.1.0 and above.
taurus-forever added a commit to canonical/mysql-operator that referenced this issue Mar 21, 2023
* Update dependency cryptography to v39

* Bump pyOpenSSL to version 23.0.0+

To update cryptography from 38.0.4 to 39.0.2.

From pyca/cryptography#7959 (comment)
> pyOpenSSL declares a min/max cryptography version to
> avoid incompatibilities like this, however it only
> started doing this in pyOpenSSL 22.1.0 and above.

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Alex Lutay <1928266+taurus-forever@users.noreply.github.com>
Co-authored-by: Paulo Machado <paulo.machado@canonical.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

5 participants