I'm getting the following exception:
File ".../hazmat/primitives/serialization.py", line 20, in load_pem_private_key
return backend.load_pem_private_key(data, password)
File ".../hazmat/backends/multibackend.py", line 276, in load_pem_private_key
return b.load_pem_private_key(data, password)
File ".../hazmat/backends/openssl/backend.py", line 691, in load_pem_private_key
password,
File ".../hazmat/backends/openssl/backend.py", line 831, in _load_key
self._ffi.NULL
TypeError: initializer for ctype 'int(*)(char *, int, int, void *)' must be a pointer to same type, not cdata 'int(*)(char *, int, int, void *)'
The exception isn't deterministic, but it is guaranteed to happen after a short while. I'm running from a wsgi module within apache (mod_apache). I'm running cryptography 0.8.2
The code that I'm running is:
import cryptography.hazmat.backends
import cryptography.hazmat.primitives.serialization
with open(my_pem_file, 'rb') as f:
pem = f.read()
pkey = cryptography.hazmat.primitives.serialization.load_pem_private_key(
pem, password=None,
backend=cryptography.hazmat.backends.default_backend())
From logs on the calling module, I'm learning that it when it happens it is always the first time I'm calling load_pem_private_key
from a new thread.
A "real" solution is obviously preferred, but I'm also looking for quick workaround such as limiting number of threads to 1 (maybe with multiple process).
EDIT:
This may be a known issue. I opened a report in github: https://github.com/pyca/cryptography/issues/1868
So right now I'm mainly looking for workarounds.