Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to build stunnel for Raspberry Pi

How to build stunnel for Raspberry Pi

This document explains how to stunnel for the Raspberry Pi (or more precisely, for the ARM architecture). All the information here has been gathered, and adapted where needed, from these blog posts: "Cross compiling for ARM with Ubuntu 16.04 LTS" and "Cross-compile OpenSSL for your Raspberry Pi". I needed to do that in order to be able to use my Raspberry Pi to provide Internet via WiFi for my Ethernet-only MSX. The OS I used as the building host is Linux Mint 18.3.

This is just a concise recipe and I'm not going to explain the details, feel free to take a look at the linked blog posts for more information.

First we are going to create a temporary directory for all the dirty work.

cd ~/
mkdir build_stunnel
cd build_stunnel

Then we'll install the ARM cross development tools:

sudo apt-get install git gcc make autoconf gcc-arm-linux-gnueabi g++-arm-linux-gnueabi binutils-arm-linux-gnueabi 
git clone https://github.com/raspberrypi/tools.git --depth=1 pitools

The following commands will clone and build OpenSSL for ARM, it's a prerequisite for building stunnel:

git clone --single-branch --branch OpenSSL_1_1_1-stable https://github.com/openssl/openssl.git
cd openssl

export CROSSCOMP_DIR=~/build_stunnel/pitools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
export INSTALL_DIR=~/build_stunnel/openssl_arm

./Configure linux-generic32 shared \
--prefix=$INSTALL_DIR --openssldir=$INSTALL_DIR/openssl \
--cross-compile-prefix=$CROSSCOMP_DIR/arm-linux-gnueabihf-

make
make install
cd ..

Now let's download the stunnel sources. If you want to get them from the official repositories run the following:

git clone https://github.com/mtrojnar/stunnel.git

However, if you want to get my modified version with SOCKS SSL support run this instead:

git clone --single-branch --branch socks-server-with-ssl-on-remote https://github.com/Konamiman/stunnel.git

Now let's go ahead and build it:

cd stunnel

./configure --with-ssl=$INSTALL_DIR --build x86_64-pc-linux-gnu --host arm-linux-gnueabi
autoreconf -f -i

make

That's it, the compiled stunnel is located at ~/build_stunnel/stunnel/src. You need to make it executable with chmod +x ~/build_stunnel/stunnel/src/stunnel and you're done.

In order to copy the compiled stunnel to your Pi you can use scp:

scp ~/build_stunnel/stunnel/src/stunnel pi@raspberrypi.local:~/

(if you have changed the username to something different than pi, or your Pi isn't accessible via host name, change the pi@raspberrypi.local as appropriate)

Finally, that's how you cleanup all the stunnel and OpenSSL intermediate files from your Linux system:

cd ~/
rm -rf build_stunnel
@egbertn
Copy link

egbertn commented Dec 27, 2020

Hi Bro,
Thanks but these tools are not available anymore :(
g++-arm-linux-gnueabi binutils-arm-linux-gnueabi

I fixed using stunnel4 on my Bash for Windows (WSL 2). Working good. No need to build it.

@uriee
Copy link

uriee commented Dec 29, 2020

Hi Friend,
I followed the instructions.
while running "autoreconf -f -i"
I got:
configure.ac:4: error: possibly undefined macro: AC_MSG_NOTICE
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:22: error: possibly undefined macro: AC_DEFINE
autoreconf: /usr/bin/autoconf failed with exit status:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment