We have a legacy application and it needs Python version 3.2 to work. For this reason we compile and install Python version 3.2.
We were able to successfully compile and install version 3.2 Python on Ubuntu 20.04.1 LTS, but we started to have problems using the Python "hashlib" library as can be seen in the excerpt below...
root@sinj:/usr/local/src/lbginst# /usr/local/lb/py32/bin/python3.2 -c "import hashlib;m=hashlib.md5();print(m.hexdigest())"
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last): File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module> globals()[__func_name] = __get_hash(__func_name) File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last): File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module> globals()[__func_name] = __get_hash(__func_name) File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last): File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module> globals()[__func_name] = __get_hash(__func_name) File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last): File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module> globals()[__func_name] = __get_hash(__func_name) File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last): File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module> globals()[__func_name] = __get_hash(__func_name) File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last): File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module> globals()[__func_name] = __get_hash(__func_name) File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha512
Traceback (most recent call last): File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'md5'QUESTION: How can we solve the problem presented?
NOTE I: After consulting dozens of sources on the internet, we started to suspect something related to the libssl.so libcrypto.so binaries.
NOTE II: Information on how we can diagnose what is happening is also very welcome!
Thanks! =D
UPDATE: Another symptom is the occurrence of this message during building process (make, make install)...
Failed to build these modules:
_hashlib _ssl 6 2 Answers
Your problem is that you're using OpenSSL 1.1 and an old version of Python that doesn't support that version of OpenSSL. Python 3.2 was released in 2011 and OpenSSL 1.1.0 was released in 2016.
Since OpenSSL 1.0 is no longer security supported, you'll need to upgrade the version of Python you're using to a suitable version. If you can't wait and you plan to upgrade in the next three months, you could also use an Ubuntu 16.04 container, which contains OpenSSL 1.0 which is supported by Ubuntu until April. However, Python 3.2 likely has unpatched vulnerabilities as well.
3The problems pointed out occurs because python version 3.2 is not compatible with openssl version 1.1 which is the standard version (apt-get) used by Ubuntu 20.04.1 LTS.
The solution is compile and install (make, make install) version 1.0 of openssl and configure the compilation process using the variables "CFLAGS" and "LDFLAGS" so that it uses openssl version 1.0.
# NOTE: Download, compile and install openssl. By Questor
cd /usr/local/src
wget
tar -zxvf openssl-1.0.2k.tar.gz
cd ./openssl-1.0.2k
./config -fPIC shared
make && make install
cd ..
rm -rf ./openssl-1.0.2k
# NOTE: Download, compile and install Python 3.2. By Questor
cd /usr/local/src
wget
tar -zxvf Python-3.2.2.tgz
cd ./Python-3.2.2
eval "./configure --with-threads --enable-shared CFLAGS='-I/usr/local/ssl/include/openssl/ -I/usr/local/ssl/include/' LDFLAGS='-L/usr/local/lib/ -L/usr/local/ssl/lib/ -Wl,-rpath,/usr/local/lib/ -Wl,-rpath,/usr/local/ssl/lib/'"
make && make install
cd ..
rm -rf ./Python-3.2.2
# NOTE: Test python3.2 using "_hashlib" and "_ssl" resources. By Questor
/usr/local/bin/python3.2 -c "import hashlib;m=hashlib.md5();print(m.hexdigest())"Done! Thanks! =D
[Refs.: , , , , , , , , , , ]