build and test libre on travis (#4256)

* build and test libre on travis

* remove libressl jenkinsfile data
diff --git a/.travis.yml b/.travis.yml
index cbbff3b..9b60e64 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -38,6 +38,10 @@
         - python: 3.5
           env: TOXENV=py35 OPENSSL=1.1.0h
         - python: 3.6
+          env: TOXENV=py36 LIBRESSL=2.4.5
+        - python: 3.6
+          env: TOXENV=py36 LIBRESSL=2.6.4
+        - python: 3.6
           env: TOXENV=docs OPENSSL=1.1.0h
           addons:
               apt:
diff --git a/.travis/install.sh b/.travis/install.sh
index 6698b5c..2858d25 100755
--- a/.travis/install.sh
+++ b/.travis/install.sh
@@ -3,6 +3,14 @@
 set -e
 set -x
 
+shlib_sed() {
+    # modify the shlib version to a unique one to make sure the dynamic
+    # linker doesn't load the system one.
+    sed -i "s/^SHLIB_MAJOR=.*/SHLIB_MAJOR=100/" Makefile
+    sed -i "s/^SHLIB_MINOR=.*/SHLIB_MINOR=0.0/" Makefile
+    sed -i "s/^SHLIB_VERSION_NUMBER=.*/SHLIB_VERSION_NUMBER=100.0.0/" Makefile
+}
+
 # download, compile, and install if it's not already present via travis
 # cache
 if [ -n "${OPENSSL}" ]; then
@@ -12,15 +20,20 @@
         tar zxf "openssl-${OPENSSL}.tar.gz"
         cd "openssl-${OPENSSL}"
         ./config shared no-asm no-ssl2 no-ssl3 -fPIC --prefix="$HOME/$OPENSSL_DIR"
-        # modify the shlib version to a unique one to make sure the dynamic
-        # linker doesn't load the system one. This isn't required for 1.1.0 at the
-        # moment since our Travis builders have a diff shlib version, but it doesn't hurt
-        sed -i "s/^SHLIB_MAJOR=.*/SHLIB_MAJOR=100/" Makefile
-        sed -i "s/^SHLIB_MINOR=.*/SHLIB_MINOR=0.0/" Makefile
-        sed -i "s/^SHLIB_VERSION_NUMBER=.*/SHLIB_VERSION_NUMBER=100.0.0/" Makefile
+        shlib_sed
         make depend
         make install
     fi
+elif [ -n "${LIBRESSL}" ]; then
+    LIBRESSL_DIR="ossl-1/${LIBRESSL}"
+    if [[ ! -f "$HOME/$LIBRESSL_DIR/bin/openssl" ]]; then
+        curl -O "https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${LIBRESSL}.tar.gz"
+        tar zxf "libressl-${LIBRESSL}.tar.gz"
+        cd "libressl-${LIBRESSL}"
+        ./config -Wl -Wl,-Bsymbolic-functions -fPIC shared --prefix="$HOME/$LIBRESSL_DIR"
+        shlib_sed
+        make -j"$(nproc)" install
+    fi
 fi
 pip install virtualenv
 
diff --git a/.travis/run.sh b/.travis/run.sh
index ed23725..19f8c48 100755
--- a/.travis/run.sh
+++ b/.travis/run.sh
@@ -8,6 +8,9 @@
     PATH="$PYENV_ROOT/bin:$PATH"
     eval "$(pyenv init -)"
 fi
+if [ -n "${LIBRESSL}" ]; then
+    OPENSSL=$LIBRESSL
+fi
 if [ -n "${OPENSSL}" ]; then
     OPENSSL_DIR="ossl-1/${OPENSSL}"
 
diff --git a/Jenkinsfile b/Jenkinsfile
index 44e9ab9..33bce2d 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -55,16 +55,6 @@
     ],
     [
         label: 'docker',
-        imageName: 'pyca/cryptography-runner-jessie-libressl:2.4.5',
-        toxenvs: ['py27'],
-    ],
-    [
-        label: 'docker',
-        imageName: 'pyca/cryptography-runner-jessie-libressl:2.6.4',
-        toxenvs: ['py27'],
-    ],
-    [
-        label: 'docker',
         imageName: 'pyca/cryptography-runner-ubuntu-xenial',
         toxenvs: ['py27', 'py35'],
     ],
@@ -227,14 +217,7 @@
                             sh """#!/usr/bin/env bash
                                 set -xe
                                 cd cryptography
-                                if [[ "\${IMAGE_NAME}" == *"libressl"* ]]; then
-                                    LD_LIBRARY_PATH="/usr/local/libressl/lib:\$LD_LIBRARY_PATH" \
-                                        LDFLAGS="-L/usr/local/libressl/lib" \
-                                        CFLAGS="-I/usr/local/libressl/include" \
-                                        tox -r -- --color=yes
-                                else
-                                    tox -r -- --color=yes
-                                fi
+                                tox -r -- --color=yes
                                 virtualenv .venv
                                 source .venv/bin/activate
                                 # This pin must be kept in sync with tox.ini