Kompilieren von Curl mit OpenSSL ergibt falsche OpenSSL-Version

Kompilieren von Curl mit OpenSSL ergibt falsche OpenSSL-Version

Ich habe verschiedene Antworten dazu gefunden, aber ich kann nichts finden, was für mich funktioniert. Ich versuche, curl mit nghttp2 auf meinem CentOS-Server zu kompilieren.

Ich habe alles ordnungsgemäß kompiliert, aber mein Problem ist, dass curl -Vdie falsche OpenSSL-Version angezeigt wird:

curl 7.51.0-DEV (x86_64-unknown-linux-gnu) libcurl/7.51.0-DEV
OpenSSL/1.0.1e zlib/1.2.3 nghttp2/1.16.0-DEV
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s
rtsp smb smbs smtp smtps telnet tftp 
Features: IPv6 Largefile NTLM NTLM_WB SSL libz HTTP2 UnixSockets 

Wenn ich das mache openssl version, wird Folgendes gemeldet:

OpenSSL 1.0.2h  3 May 2016

Kann mir bitte jemand helfen, das zu beheben (ich befinde mich hier außerhalb meiner Komfortzone!)? So wie ich das verstehe, funktioniert http2 nicht richtig, da OpenSSL 1.0.2 sein muss.

Danke

BEARBEITEN

Ich habe versucht, meine Konfiguration wie folgt zu ändern:

./configure  --with-nghttp2=/usr/local --with-ssl=/var/tmp/openssl-1.0.2h
 CPPFLAGS="-I/var/tmp/openssl-1.0.2h/include/openssl" 
 LDFLAGS="-L/var/tmp/openssl-1.0.2h" 

Aber jetzt wird die Konfiguration nicht abgeschlossen:

error: one or more libs available at link-time are not available run-time. 
Libs used at link-time: -lnghttp2   -lssl -lcrypto -lz -lrt

Das Problem liegt definitiv an der OpenSSL-Verknüpfung, da ich die Konfiguration mithilfe von problemlos durchführen kann --without-ssl. Ich nehme an, meine Pfade müssen falsch sein – aber ich bin nicht sicher, worauf sie verweisen sollen?

Antwort1

Ich denke, der Trick dabei ist, dass Sie alle drei Komponenten (OpenSSL, ngHTTP und cURL) dazu bringen müssen, das neu erstellte OpenSSL zu verwenden. Der einfachste Weg ist die Verwendung eines RPATH, und das ist der -Wl,-rpath,/usr/local/libgezeigte Schlag.

OpenSSL erstellen

OpenSSL berücksichtigt nicht CFLAGS, daher müssen Sie -Wl,-rpath,/usr/local/libIhrer Konfigurationszeile hinzufügen. Es erklärt Flags wie ec_nistp_64_gcc_128.

Siehe auchKompilierung und Installationim OpenSSL-Wiki.

$ wget https://www.openssl.org/source/openssl-1.1.0b.tar.gz
$ tar xzf openssl-1.1.0b.tar.gz

$ cd openssl-1.1.0b
$ ./Configure linux-x86_64 shared no-ssl2 no-ssl3 no-comp enable-ec_nistp_64_gcc_128 -Wl,-rpath,/usr/local/lib
Configuring OpenSSL version 1.1.0b (0x0x1010002fL)
***** Deprecated options: no-ssl2
...
SIXTY_FOUR_BIT_LONG mode
Configured for linux-x86_64.

$ make -j 4
...
$ sudo make install
...

$ /usr/local/bin/openssl version
OpenSSL 1.1.0b  26 Sep 2016

$ ldd /usr/local/bin/openssl 
    linux-vdso.so.1 =>  (0x00007ffcd27e0000)
    libssl.so.1.1 => /usr/local/lib/libssl.so.1.1 (0x00007fe8f8740000)
    libcrypto.so.1.1 => /usr/local/lib/libcrypto.so.1.1 (0x00007fe8f8294000)
    ...

CFLAGS und CXXFLAGS

Da nun ein neues OpenSSL verfügbar ist, benötigen Sie die restlichen Komponenten, um es verwenden zu können. Die kleine Schwachstelle ist, dass ngHTTP sowohl als auch verwendet gcc, sodass Sie sowohl als auch g++anpassen müssen .CFLAGSCXXFLAGS

Persönlich lasse ich mich nicht von CPPFLAGSden Flags für den C-Präprozessor ab. Es ist die Aufgabe des Compilertreibers, sie bei Bedarf an den Präprozessor weiterzugeben.

$ export CFLAGS="-I/usr/local/include/ -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lssl -lcrypto"
$ export CXXFLAGS="-I/usr/local/include/ -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lssl -lcrypto"

Erstellen Sie nghttp2

Das Besondere hierbei ist, dass sowohl CFLAGSals auch festgelegt werden CXXFLAGS.

$ wget https://github.com/nghttp2/nghttp2/releases/download/v1.16.0/nghttp2-1.16.0.tar.gz
$ tar xzf nghttp2-1.16.0.tar.gz
$ cd nghttp2-1.16.0

$ CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" ./configure
...
    Compiler:
      C compiler:     gcc
      CFLAGS:         -I/usr/local/include/ -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lssl -lcrypto
      LDFLAGS:        
      C++ compiler:   g++
      CXXFLAGS:       -I/usr/local/include/ -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lssl -lcrypto
...
    Libs:
      OpenSSL:        yes (CFLAGS='-I/usr/local/include' LIBS='-L/usr/local/lib -lssl -lcrypto')
    ...

$ make -j 4
...
$ sudo make install
...

Libraries have been installed in:
   /usr/local/lib
...

Erstellen Sie cURL

Hier ist nichts wirklich Besonderes. cURL verwendet das CFLAGSauch.

$ wget https://curl.haxx.se/download/curl-7.51.0.tar.gz
$ tar xzf curl-7.51.0.tar.gz

$ cd curl-7.51.0
$ ./configure --help | egrep '(ssl|tls|nghttp2)'
  --enable-tls-srp        Enable TLS-SRP authentication
  --disable-tls-srp       Disable TLS-SRP authentication
  --with-winssl           enable Windows native SSL/TLS
  --without-winssl        disable Windows native SSL/TLS
  --with-darwinssl        enable Apple OS native SSL/TLS
  --without-darwinssl     disable Apple OS native SSL/TLS
  --with-ssl=PATH         Where to look for OpenSSL, PATH points to the SSL
                          installation (default: /usr/local/ssl); when
  --without-ssl           disable OpenSSL
  --with-gnutls=PATH      where to look for GnuTLS, PATH points to the
  --without-gnutls        disable GnuTLS detection
  --with-polarssl=PATH    where to look for PolarSSL, PATH points to the
  --without-polarssl      disable PolarSSL detection
  --with-mbedtls=PATH     where to look for mbedTLS, PATH points to the
  --without-mbedtls       disable mbedTLS detection
  --with-cyassl=PATH      where to look for CyaSSL, PATH points to the
  --without-cyassl        disable CyaSSL detection
  --with-axtls=PATH       Where to look for axTLS, PATH points to the axTLS
  --without-axtls         disable axTLS
  --with-nghttp2=PATH     Enable nghttp2 usage
  --without-nghttp2       Disable nghttp2 usage

$ ./configure --with-ssl=/usr/local --with-nghttp2=/usr/local
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make supports nested variables... yes
...
checking for egrep... /bin/grep -E
checking for ar... /usr/bin/ar
configure: using CFLAGS: -I/usr/local/include/ -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lssl -lcrypto
...
configure: Configured to build curl/libcurl:

  curl version:     7.51.0
  Host setup:       x86_64-pc-linux-gnu
  Install prefix:   /usr/local
  Compiler:         gcc
  SSL support:      enabled (OpenSSL)
  SSH support:      no      (--with-libssh2)
  zlib support:     no      (--with-zlib)
  GSS-API support:  no      (--with-gssapi)
  TLS-SRP support:  enabled
  resolver:         default (--enable-ares / --enable-threaded-resolver)
  IPv6 support:     enabled
  Unix sockets support: enabled
  IDN support:      no      (--with-{libidn2,winidn})
  Build libcurl:    Shared=yes, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  SSPI support:     no      (--enable-sspi)
  ca cert bundle:   /etc/ssl/certs/ca-certificates.crt
  ca cert path:     no
  ca fallback:      no
  LDAP support:     no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS support:    no      (--enable-ldaps)
  RTSP support:     enabled
  RTMP support:     no      (--with-librtmp)
  metalink support: no      (--with-libmetalink)
  PSL support:      no      (libpsl not found)
  HTTP2 support:    enabled (nghttp2)
  Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP

$ make -j 4
...
$ sudo make install
...

Überprüfen von Bibliotheken

Überprüfen Sie die Dinge, nachdem Sie alle Hürden überwunden haben. Besonders wichtig ist der RPATH, damit Sie keine Zeit damit verschwenden müssen LD_LIBRARY_PATH. -Wl,-rpath,/usr/local/libstellt sicher, dass der Pfad mit den richtigen gemeinsam genutzten Objekten in die ausführbare Datei gewählt wird.

$ which curl
/usr/local/bin/curl

$ ldd /usr/local/bin/curl
    linux-vdso.so.1 =>  (0x00007ffcd0ffd000)
    libcurl.so.4 => /usr/local/lib/libcurl.so.4 (0x00007f86ad8a4000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f86ad4c4000)
    libnghttp2.so.14 => /usr/local/lib/libnghttp2.so.14 (0x00007f86ad293000)
    libssl.so.1.1 => /usr/local/lib/libssl.so.1.1 (0x00007f86ad025000)
    libcrypto.so.1.1 => /usr/local/lib/libcrypto.so.1.1 (0x00007f86acb79000)
    /lib64/ld-linux-x86-64.so.2 (0x0000560d3d474000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f86ac95b000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f86ac757000)

Endlich:

$ /usr/local/bin/curl -V
curl 7.51.0 (x86_64-pc-linux-gnu) libcurl/7.51.0 OpenSSL/1.1.0b nghttp2/1.16.0
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: IPv6 Largefile NTLM NTLM_WB SSL TLS-SRP HTTP2 UnixSockets 

Sie können mit Folgendem bereinigen:

$ cd ..
$ rm -rf curl-7.51.0* nghttp2-1.16.0* openssl-1.1.0b*
...

verwandte Informationen