OpenSSL Error
We are seeing the following error:
Traceback (most recent call last):, referer: <url>
from elasticsearch import Elasticsearch, referer: <url>
File "<path>/lib/python2.7/site-packages/elasticsearch/__init__.py", line 7, in <module>, referer: <url>
from elasticsearch.client import Elasticsearch, referer: <url>
File "<path>/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 4, in <module>, referer: <url>
from ..transport import Transport, referer: <url>
File "<path>/lib/python2.7/site-packages/elasticsearch/transport.py", line 4, in <module>, referer: <url>
from .connection import Urllib3HttpConnection, referer: <url>
File "<path>/lib/python2.7/site-packages/elasticsearch/connection/__init__.py", line 2, in <module>, referer: <url>
from .http_requests import RequestsHttpConnection, referer: <url>
File "<path>/lib/python2.7/site-packages/elasticsearch/connection/http_requests.py", line 3, in <module>, referer: <url>
import requests, referer: <url>
File "<path>/lib/python2.7/site-packages/requests/__init__.py", line 53, in <module>, referer: <url>
from .packages.urllib3.contrib import pyopenssl, referer: <url>
File "<path>/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 54, in <module>, referer: <url>
import OpenSSL.SSL, referer: <url>
File "<path>/lib/python2.7/site-packages/OpenSSL/__init__.py", line 8, in <module>, referer: <url>
from OpenSSL import rand, crypto, SSL, referer: <url>
File "<path>/lib/python2.7/site-packages/OpenSSL/rand.py", line 11, in <module>, referer: <url>
from OpenSSL._util import (, referer: <url>
File "<path>/lib/python2.7/site-packages/OpenSSL/_util.py", line 6, in <module>, referer: <url>
from cryptography.hazmat.bindings.openssl.binding import Binding, referer: <url>
File "<path>/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 205, in <module>, referer: <url>
Binding.init_static_locks(), referer: <url>
File "<path>/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 161, in init_static_locks, referer: <url>
cls._ensure_ffi_initialized(), referer: <url>
File "<path>/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 156, in _ensure_ffi_initialized, referer: <url>
cls._register_osrandom_engine(), referer: <url>
File "<path>/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 121, in _register_osrandom_engine, referer: <url>
_openssl_assert(cls.lib, cls.lib.ERR_peek_error() == 0), referer: <url>
File "<path>/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 43, in _openssl_assert, referer: <url>
errors, referer: <url>
InternalError: Unknown OpenSSL error. Please file an issue at https://github.com/pyca/cryptography/issues with information on how to reproduce this. ([_OpenSSLError(code=151441516L, lib=9, func=109, reason=108), _OpenSSLError(code=151441516L, lib=9, func=109, reason=108)])
We are using Python 2.7.5 cryptography 1.2.2 CentOS 7
This error corresponds to error:0906D06C:PEM routines:PEM_read_bio:no start line which implies something else is adding to (and not cleaning up) the OpenSSL error stack before startup. Do you have another lib that uses OpenSSL (like m2crypto) in your dependencies?
Yes we do have m2crypto installed as a dependancy of the SaltStack minion running on the server. We have had these running together for quite a while. The issue only started today. Do you have any suggestions on a way to work around the issue while keeping the m2crypto package?
I don't recommend this as a long term fix (as it's dangerous to have code that isn't clearing the error stack interacting with OpenSSL when using cryptography), but this check can be changed to just clear the error stack during init. If you edit the _openssl_assert(cls.lib, cls.lib.ERR_peek_error() == 0) line and replace it with cls.lib.ERR_clear_error() then you should be able to proceed.
Thank you very much. This cleared up the error that I was seeing. What should our long term goal be to prevent this from happening? Is there a way to determine what exactly is not clearing the error stack?
There's no way to tell exactly what put the error on the stack unfortunately. Ultimately the best solution is to not depend on m2crypto. It looks like saltstack depends on it for x509 (https://github.com/saltstack/salt/blob/8ec28e85635cdaa32ffc036b2663ccbf2831e725/salt/modules/x509.py), which cryptography could potentially replace. It might be worth opening an issue with them to see if they'd be interested in migrating their dependency.
I'm going to go ahead and close this issue but feel free to keep commenting on it if needed.