nabla-c0d3 / nassl

Experimental OpenSSL wrapper for Python 3.8+ and SSLyze.
GNU Affero General Public License v3.0
39 stars 35 forks source link

Compatibility with Python 3.6.8 #75

Closed sskras closed 3 years ago

sskras commented 3 years ago

I use CentOS 7.9 and got interested in updating the version of this lib I get using pip. Which is 2.2.0:

$ pip3 install --user nassl
Collecting nassl
  Using cached https://files.pythonhosted.org/packages/1c/59/2aa9ab432a09e0814231b52cd2dd030d7b308d7288ffcc8493a2bdb957db/nassl-2.2.0-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: nassl
Successfully installed nassl-2.2.0

If I uninistall that default version + clone this repo and check out a commit by tag 2.2.0:

$ git branch
* (detached from 2.2.0)
  release

... then it starts building it and fails:

$ pip3 install --user .
Processing /home/admin2/nassl
Installing collected packages: nassl
  Running setup.py install for nassl ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-8zmtyiqd-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-zagcipu2-record/install-record.txt --single-version-externally-managed --compile --user --prefix=:
    /home/admin2/.local/lib/python3.6/site-packages/setuptools/dist.py:645: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions.
Please use the underscore name 'description_file' instead
      % (opt, underscore_opt))
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/nassl
    copying nassl/__init__.py -> build/lib.linux-x86_64-3.6/nassl
    copying nassl/ssl_client.py -> build/lib.linux-x86_64-3.6/nassl
    copying nassl/legacy_ssl_client.py -> build/lib.linux-x86_64-3.6/nassl
    copying nassl/ocsp_response.py -> build/lib.linux-x86_64-3.6/nassl
    running build_ext
    building 'nassl._nassl_legacy' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/nassl
    creating build/temp.linux-x86_64-3.6/nassl/_nassl
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DLEGACY_OPENSSL=1 -I/tmp/pip-8zmtyiqd-build/deps/openssl-OpenSSL_1_0_2e/include -Inassl/_nassl -I/usr/include/python3.6m -c nassl/_nassl/nassl.c -o build/temp.linux-x86_64-3.6/nassl/_nassl/nassl.o -Wall
  ...
    gcc -pthread -shared -Wl,-z,relro -g build/temp.linux-x86_64-3.6/nassl/_nassl/nassl.o build/temp.linux-x86_64-3.6/nassl/_nassl/nassl_SSL_CTX.o build/temp.linux-x86_64-3.6 /nassl/_nassl/nassl_SSL.o build/temp.linux-x86_64-3.6/nassl/_nassl/nassl_X509.o build/temp.linux-x86_64-3.6/nassl/_nassl/nassl_errors.o build/temp.linux-x86_64-3.6/nassl/_nassl/nassl_BIO.o build/temp.linux-x86_64-3.6/nassl/_nassl/nassl_SSL_SESSION.o build/temp.linux-x86_64-3.6/nassl/_nassl/openssl_utils.o build/temp.linux-x86_64-3.6/nassl/_nassl/nassl_OCSP_RESPONSE.o build/temp.linux-x86_64-3.6/nassl/_nassl/python_utils.o /tmp/pip-p2iu12r6-build/deps/openssl-OpenSSL_1_0_2e/libssl.a /tmp/pip-p2iu12r6-build/deps/openssl-OpenSSL_1_0_2e/libcrypto.a /tmp/pip-p2iu12r6-build/deps/zlib-1.2.11/libz.a -L/usr/lib64 -lpython3.6m -o build/lib.linux-x86_64-3.6/nassl/_nassl_legacy.cpython-36m-x86_64-linux-gnu.so -Wl,-z,noexecstack
    gcc: error: /tmp/pip-p2iu12r6-build/deps/openssl-OpenSSL_1_0_2e/libssl.a: No such file or directory
    gcc: error: /tmp/pip-p2iu12r6-build/deps/openssl-OpenSSL_1_0_2e/libcrypto.a: No such file or directory
    gcc: error: /tmp/pip-p2iu12r6-build/deps/zlib-1.2.11/libz.a: No such file or directory
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-p2iu12r6-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-net6kca1-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-p2iu12r6-build/

The mentioned static libs are presented by OS packages:

$ rpm -qal | egrep 'lib(ssl|crypto|z).a'
/opt/puppetlabs/puppet/lib/libcrypto.a
/opt/puppetlabs/puppet/lib/libssl.a
/usr/lib64/libz.a
/usr/lib64/libcrypto.a
/usr/lib64/libssl.a

And their versions:

$ rpm -qf $(rpm -qal | egrep 'lib64/lib(ssl|crypto|z).a')
zlib-static-1.2.7-19.el7_9.x86_64
openssl-static-1.0.2k-21.el7_9.x86_64
openssl-static-1.0.2k-21.el7_9.x86_64

Any ideas on how to proceed and get the updated version?

sskras commented 3 years ago

Unfortunately I am not familiar with Python development to get the idea in straight way.

sskras commented 3 years ago

OK, I noticed the README.md only after everything else was tried.

It seems that I needed to run these commands:

$ pip3 install --user pipenv
$ patch -p1 <<EOF
--- a/Pipfile
+++ b/Pipfile
@@ -14,4 +14,4 @@ invoke = "*"
 requests = "*"

 [requires]
-python_version = "3.7"
+python_version = "3.6"
EOF
patching file Pipfile

$ pipenv install --dev
$ pipenv run invoke build.all

... then increase the disk space on your home dir (yay!) and wait for several minutes. Then I needed to increase space on my /tmp too. And after this there was surely the last step to go:

$ python3 -m pip install --user .
Processing /home/admin2/nassl
Building wheels for collected packages: nassl
  Building wheel for nassl (setup.py) ... done
  Created wheel for nassl: filename=nassl-2.2.0-cp36-cp36m-linux_x86_64.whl size=3070575 sha256=e9dfaf4b0981c8e847f23d3039597c88e81f75bbd3d532236f4860f7d44afb77
  Stored in directory: /tmp/pip-ephem-wheel-cache-2dqwws9f/wheels/90/26/de/24cb84915a1141d2011a91dd6dac7bb939db3c89447d2e9bde
Successfully built nassl
Installing collected packages: nassl
Successfully installed nassl-2.2.0

Wow, that's a hell of a crash course!