Coredump when compiling python with a custom openssl version

前端 未结 7 1200

When compiling python-3.4.0rc3 with a local openssl-1.0.1f shared install, make prints no error but then I get the following core dump on make install or make t

7条回答
  •  难免孤独
    2020-12-18 01:30

    How should I go about changing it ? Will adding a _ssl.c: gcc ... line anywhere override the default behaviour ? My Makefile skills are rusted and this beast is 1600+ lines long !!

    Here are the files you want to look at:

    $ cd Python-3.4.0rc3
    
    $ grep -R -- '-lcrypto' *
    Modules/Setup.dist:#    -L$(SSL)/lib -lssl -lcrypto
    
    $ grep -R -- '-lssl' *
    Modules/Setup.dist:#    -L$(SSL)/lib -lssl -lcrypto
    

    Here are the lines of interest in Setup.dist:

    # Socket module helper for SSL support; you must comment out the other
    # socket line above, and possibly edit the SSL variable:
    #SSL=/usr/local/ssl
    #_ssl _ssl.c \
    #   -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    #   -L$(SSL)/lib -lssl -lcrypto
    

    Uncomment the lines and change Setup.dist to the following. I keep my OpenSSL in /usr/local/ssl, so that's how mine is setup below (you should use /data2/soft/openssl/lib/...):

    SSL=/usr/local/ssl
    _ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        /usr/local/ssl/lib/libssl.a /usr/local/ssl/lib/libcrypto.a -ldl
    

    Use the full path to the archive, and don't use -l. Be sure to add -ldl because OpenSSL needs it in this configuration.

    Once you change Setup.dist, re-run ./configure to effect the changes.


    After changing the above line to, here's what I look like after a configure:

    $ grep -R "libssl.a" *
    Makefile:LOCALMODLIBS=  /usr/local/ssl/lib/libssl.a /usr/local/ssl/lib/libcrypto.a -ldl 
    Makefile:Modules/_ssl$(SO):  Modules/_ssl.o; $(BLDSHARED)  Modules/_ssl.o  /usr/local/ssl/lib/libssl.a /usr/local/ssl/lib/libcrypto.a -ldl  -o Modules/_ssl$(SO)
    Modules/Setup: /usr/local/ssl/lib/libssl.a /usr/local/ssl/lib/libcrypto.a -ldl 
    Modules/Setup.dist: /usr/local/ssl/lib/libssl.a /usr/local/ssl/lib/libcrypto.a -ldl 
    

    You can test the static linking by using ldd or otool -L. You will not see an OpenSSL dependency. After make'ing, here's what I got:

    $ find . -iname python
    ./python
    $ ldd ./python
        linux-vdso.so.1 =>  (0x00007fff67709000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3aed8e1000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3aed6dd000)
        libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f3aed4d9000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3aed257000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3aececc000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f3aedb14000)
    

    No libssl or libcrypto dependencies to go wrong :) And make test ran fine (actually, one failed test due to a Python bug: Issue 20896):

    ======================================================================
    ERROR: test_get_server_certificate (test.test_ssl.NetworkedTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/jwalton/Python-3.4.0rc3/Lib/test/test_ssl.py", line 1373, in test_get_server_certificate
        _test_get_server_certificate('svn.python.org', 443, SVN_PYTHON_ORG_ROOT_CERT)
      File "/home/jwalton/Python-3.4.0rc3/Lib/test/test_ssl.py", line 1354, in _test_get_server_certificate
        pem = ssl.get_server_certificate((host, port))
      File "/home/jwalton/Python-3.4.0rc3/Lib/ssl.py", line 902, in get_server_certificate
        with context.wrap_socket(sock) as sslsock:
      File "/home/jwalton/Python-3.4.0rc3/Lib/ssl.py", line 344, in wrap_socket
        _context=self)
      File "/home/jwalton/Python-3.4.0rc3/Lib/ssl.py", line 540, in __init__
        self.do_handshake()
      File "/home/jwalton/Python-3.4.0rc3/Lib/ssl.py", line 767, in do_handshake
        self._sslobj.do_handshake()
    ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:598)
    
    ----------------------------------------------------------------------
    Ran 96 tests in 8.610s
    
    FAILED (errors=1, skipped=3)
    test test_ssl failed
    make: *** [test] Error 1
    

提交回复
热议问题