Compiling cURL with HTTP/2 support on Kali Linux 2

Introduction

The cURL tool supports HTTP/2 in it’s current version 7.47, of 27th of January 2016. This version is however not yet (January 2016) distributed in Debian or Kali packages so in order to take advantage of this feature, one must take this matter into its own hands… Let’s get and compile the latest version…

Previous Post: “HTTP/2 – A very brave new World

Download of the compiled version: curl-7.47.1-dev.tar

Common dependencies

root@KALI2:~/dev> apt-get install build-essential libtool autoconf
root@KALI2:~/dev> apt-get install g++ make binutils autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev 
root@KALI2:~/dev> # apt-get install git

HTTP/2 Library

The documentation states that libcurl uses a 3rd party library for the low level protocol handling. The reason is that HTTP/2 is much more complex at that layer than HTTP/1.1, which cURL implements directly, and that nghttp2 is an already existing and functional library.

In the past, it was required to compile the nghttp2 library from the sources, but in the meantime it has been included in the official Debian packages.

:
root@KALI2:~/dev> apt-get install nghttp2
:

The correct installation can be verified like this:

:
root@KALI2:~/dev> ldconfig -v | grep http2

/sbin/ldconfig.real: Path `/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: Path `/usr/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real:     libnghttp2.so.14 -> libnghttp2.so.14.4.1
/lib/x86_64-linux-gnu/ld-2.19.so is the dynamic linker, ignoring
    libnghttp2.so.5 -> libnghttp2.so.5.1.1

Downloading and configuring cURL source repository

root@KALI2:~> # Enter your development directory
root@KALI2:~> cd dev

root@KALI2:~/dev> # Get the sources
root@KALI2:~/dev> git clone https://github.com/bagder/curl.git
root@KALI2:~/dev> cd curl

root@KALI2:~/dev/curl> # Build the build configuration
root@KALI2:~/dev/curl> ./buildconf

buildconf: autoconf version 2.69 (ok)
buildconf: autom4te version 2.69 (ok)
buildconf: autoheader version 2.69 (ok)
buildconf: automake version 1.14.1 (ok)
buildconf: aclocal version 1.14.1 (ok)
buildconf: libtoolize version 2.4.2 (ok)
buildconf: GNU m4 version 1.4.17 (ok)
buildconf: running libtoolize
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
libtoolize: Remember to add `LT_INIT' to configure.ac.
buildconf: converting all mv to mv -f in local m4/libtool.m4
buildconf: running aclocal
buildconf: converting all mv to mv -f in local aclocal.m4
buildconf: running autoheader
buildconf: running autoconf
buildconf: running automake
configure.ac:130: installing './compile'
configure.ac:184: installing './config.guess'
configure.ac:184: installing './config.sub'
configure.ac:130: installing './install-sh'
configure.ac:131: installing './missing'
docs/examples/Makefile.am: installing './depcomp'
parallel-tests: installing './test-driver'
buildconf: OK

root@KALI2:~/dev/curl>  # Display compilation and feature options (result, see below)
root@KALI2:~/dev/curl> ./configure --help

root@KALI2:~/dev/curl> # Define what the build should execute. We activate the HTTP/2 feature
root@KALI2:~/dev/curl> # and we make sure that this version does not overwrite the local cURL
root@KALI2:~/dev/curl> # version. For this, we specify our own target directory.
root@KALI2:~/dev/curl> #
root@KALI2:~/dev/curl> # Please adapt the target directory prefix to your needs. 
root@KALI2:~/dev/curl> #
root@KALI2:~/dev/curl> # In case of problems, consult the config.log file.
root@KALI2:~/dev/curl> #
root@KALI2:~/dev/curl> ./configure --with-nghttp2 --prefix=$HOME/bin --enable-verbose --enable-ipv6 

checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make supports nested variables... yes
:
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
:

Building

root@KALI2:~/dev/curl> make

Making all in lib
make[1]: Entering directory '/root/dev/curl/lib'
make  all-am
make[2]: Entering directory '/root/dev/curl/lib'
  CC       libcurl_la-file.lo
  CC       libcurl_la-timeval.lo
  CC       libcurl_la-base64.lo
  :
  :

root@KALI2:~/dev/curl># This builds the tool in the 'src' directory, where it can also be executed.
root@KALI2:~/dev/curl># Make sure to not to forget the './', otherwise the 'normal' cURL present in the 
root@KALI2:~/dev/curl># path is called.
root@KALI2:~/dev/curl/src> ./curl -V

root@KALI2:~/dev/curl> # Install the tool and all dependencies in the 'prefix' (see above) directory
root@KALI2:~/dev/curl> make install

Making install in lib
make[1]: Entering directory '/root/dev/curl/lib'
make[2]: Entering directory '/root/dev/curl/lib'
 /bin/mkdir -p '/root/bin/lib'
 /bin/bash ../libtool   --mode=install /usr/bin/install -c   libcurl.la '/root/bin/lib'
libtool: install: /usr/bin/install -c .libs/libcurl.so.4.4.0 /root/bin/lib/libcurl.so.4.4.0
:
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /root/bin/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /root/bin/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/root/dev/curl/lib'
make[1]: Leaving directory '/root/dev/curl/lib'
:

Testing

root@KALI2:~/dev/curl> # Enter the target directory specified during the build
root@KALI2:~/dev/curl> cd ~/bin
root@KALI2:~/bin# ls -R
.:
bin  include  lib  share
./bin:
:

root@KALI2:~/bin> cd bin

root@KALI2:~/bin/bin> # We need to see HTTP2 in the features list and the version is 7.47.1-DEV
root@KALI2:~/bin/bin> curl -V

curl 7.47.1-DEV (x86_64-unknown-linux-gnu) libcurl/7.47.1-DEV OpenSSL/1.0.1k zlib/1.2.8 nghttp2/1.7.1-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 TLS-SRP HTTP2 UnixSockets 
.

The nghttp2 library web site is also served via HTTP/2, so that’s a good place to test our tool. Note the first result line indicating HTTP/2.

root@KALI2:~/bin/bin>./curl -I https://nghttp2.org/ 

HTTP/2.0 200
date:Sat, 30 Jan 2016 15:25:52 GMT
content-type:text/html
content-length:6680
last-modified:Mon, 25 Jan 2016 11:01:34 GMT
etag:"56a6008e-1a18"
link:/stylesheets/screen.css>; rel=preload; as=stylesheet
accept-ranges:bytes
x-backend-header-rtt:0.000544
server:nghttpx nghttp2/1.7.1-DEV
via:1.1 nghttpx
strict-transport-security:max-age=31536000

Google is served using HTTP/2 as well, only on https.

root@KALI2:~/bin/bin# ./curl --http2 -I https://google.com

HTTP/2.0 302
cache-control:private
content-type:text/html; charset=UTF-8
location:https://www.google.be/?gfe_rd=cr
content-length:259
date:Sat, 30 Jan 2016 15:29:26 GMT
server:GFE/2.0

Download of the compiled version: curl-7.47.1-dev.tar

Leave a Reply

Your email address will not be published. Required fields are marked *