Add Tor stable 0.4.5.9

This commit is contained in:
nicolas.dorier 2021-10-03 11:01:38 +09:00
parent 763e2263ff
commit 00e534e82c
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
4 changed files with 382 additions and 0 deletions

View File

@ -0,0 +1,34 @@
#!/bin/sh
set -e
mkdir -p "$(dirname $TOR_CONFIG)"
mkdir -p "$TOR_DATA"
chown -R tor "$TOR_DATA"
chmod 700 "$TOR_DATA"
mkdir -p "/var/lib/tor/hidden_services"
chown -R tor /var/lib/tor/hidden_services
chmod 700 /var/lib/tor/hidden_services
cat <<-EOF > "$TOR_CONFIG"
ControlPort 0.0.0.0:9051
SOCKSPort 0.0.0.0:9050
${TOR_EXTRA_ARGS}
EOF
if ! [ -z "${TOR_ADDITIONAL_CONFIG}" ]; then
echo "%include $TOR_ADDITIONAL_CONFIG" >> "$TOR_CONFIG"
echo "" >> "$TOR_ADDITIONAL_CONFIG"
echo "Added '%include $TOR_ADDITIONAL_CONFIG' to tor config"
fi
chown -R tor "$(dirname $TOR_CONFIG)"
if ! [ -z "${TOR_PASSWORD}" ]; then
TOR_PASSWORD_HASH="$(gosu tor tor --hash-password "$TOR_PASSWORD")"
echo "HashedControlPassword $TOR_PASSWORD_HASH" >> "$TOR_CONFIG"
echo "'HashedControlPassword $TOR_PASSWORD_HASH' added to tor config"
fi
exec gosu tor "$@"

View File

@ -0,0 +1,88 @@
# Thanks to https://hub.docker.com/r/chriswayg/tor-alpine/dockerfile (Christian chriswayg@gmail.com)
# Dockerfile for Tor Relay Server with obfs4proxy (Multi-Stage build)
FROM alpine:3.13 AS tor-build
ARG TOR_GPG_KEY=0x6AFEE6D49E92B601
ENV TOR_VERSION=0.4.5.9
# Install prerequisites
RUN apk --no-cache add --update \
gnupg \
build-base \
libevent \
libevent-dev \
libressl \
libressl-dev \
xz-libs \
xz-dev \
zlib \
zlib-dev \
zstd \
zstd-dev \
# Install Tor from source, incl. GeoIP files (get latest release version number from Tor ReleaseNotes)
&& TOR_TARBALL_NAME="tor-${TOR_VERSION}.tar.gz" \
&& TOR_TARBALL_LINK="https://dist.torproject.org/${TOR_TARBALL_NAME}" \
&& wget -q $TOR_TARBALL_LINK \
&& wget $TOR_TARBALL_LINK.asc \
# Reliably fetch the TOR_GPG_KEY
&& found=''; \
for server in \
ha.pool.sks-keyservers.net \
hkp://keyserver.ubuntu.com:80 \
hkp://p80.pool.sks-keyservers.net:80 \
ipv4.pool.sks-keyservers.net \
keys.gnupg.net \
pgp.mit.edu \
; do \
echo "Fetching GPG key $TOR_GPG_KEY from $server"; \
gpg --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$TOR_GPG_KEY" && found=yes && break; \
done; \
test -z "$found" && echo >&2 "error: failed to fetch GPG key $TOR_GPG_KEY" && exit 1; \
gpg --verify $TOR_TARBALL_NAME.asc \
&& tar xf $TOR_TARBALL_NAME \
&& cd tor-$TOR_VERSION \
&& ./configure --disable-unittests --disable-systemd --disable-seccomp --disable-asciidoc \
&& make install \
&& ls -R /usr/local/ \
&& strip /usr/local/bin/tor-* && strip /usr/local/bin/tor
# Main files created (plus docs):
# /usr/local/bin/tor
# /usr/local/bin/tor-gencert
# /usr/local/bin/tor-resolve
# /usr/local/bin/torify
# /usr/local/share/tor/geoip
# /usr/local/share/tor/geoip6
# /usr/local/etc/tor/torrc.sample
WORKDIR /tmp/bin
RUN wget -qO gosu "https://github.com/tianon/gosu/releases/download/1.13/gosu-amd64" \
&& echo "6f333f520d31e212634c0777213a5d4f8f26bba1ab4b0edbbdf3c8bff8896ecf gosu" | sha256sum -c -
FROM alpine:3.13
ENV TOR_VERSION=0.4.6.5
# Installing dependencies of Tor
RUN apk --no-cache add --update \
libevent \
libressl \
xz-libs \
zlib \
zstd \
zstd-dev
# Copy Tor
COPY --from=tor-build "/tmp/bin" /usr/local/bin
COPY --from=tor-build /usr/local/ /usr/local/
ENV TOR_DATA /home/tor/.tor
RUN chmod +x /usr/local/bin/gosu && addgroup -g 19001 -S tor && adduser -u 19001 -G tor -S tor && mkdir -p ${TOR_DATA} && chown -R tor:tor "$TOR_DATA"
VOLUME /home/tor/.tor
COPY docker-entrypoint.sh /entrypoint.sh
# SOCKS5, TOR control
EXPOSE 9050 9051
ENV TOR_CONFIG=/usr/local/etc/tor/torrc
ENTRYPOINT ["./entrypoint.sh"]
CMD ["tor"]

View File

@ -0,0 +1,130 @@
FROM debian:buster-slim as download
RUN set -ex \
&& apt-get update \
&& apt-get install -qq --no-install-recommends ca-certificates dirmngr wget \
qemu qemu-user-static qemu-user binfmt-support
WORKDIR /tmp/bin
RUN wget -qO gosu "https://github.com/tianon/gosu/releases/download/1.13/gosu-armhf" \
&& echo "33e421b84b3f746e7353ac2e7c9f199c5beef5a3b2b7a013b591a9af25d84919 gosu" | sha256sum -c -
FROM debian:buster-slim as tor-build
ARG TOR_GPG_KEY=0x6AFEE6D49E92B601
ENV TOR_VERSION=0.4.5.9
ENV TOR_HASH=f304e456102ed26c39e5f16ece2115585398cdb4e67455139c86ea43cdf70856
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates perl autoconf automake build-essential git libtool python python3 wget gnupg dirmngr git \
libc6-armhf-cross gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
ENV target_host=arm-linux-gnueabihf
ENV AR=${target_host}-ar \
AS=${target_host}-as \
CC=${target_host}-gcc \
CXX=${target_host}-g++ \
LD=${target_host}-ld \
STRIP=${target_host}-strip \
QEMU_LD_PREFIX=/usr/${target_host} \
HOST=${target_host}
RUN wget -q https://zlib.net/zlib-1.2.11.tar.gz \
&& TAR_NAME=zlib-1.2.11.tar.gz \
&& FOLDER_NAME=zlib-1.2.11 \
&& echo "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1 $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& ./configure --prefix=$QEMU_LD_PREFIX \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
RUN wget -q https://github.com/openssl/openssl/archive/OpenSSL_1_1_1i.tar.gz \
&& TAR_NAME=OpenSSL_1_1_1i.tar.gz \
&& FOLDER_NAME=openssl-OpenSSL_1_1_1i \
&& echo "728d537d466a062e94705d44ee8c13c7b82d1b66f59f4e948e0cbf1cd7c461d8 $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& ./Configure --prefix=$QEMU_LD_PREFIX linux-armv4 -march=armv7 no-shared no-dso no-zlib no-asm \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
RUN wget -q https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz \
&& TAR_NAME=libevent-2.1.8-stable.tar.gz \
&& FOLDER_NAME=libevent-2.1.8-stable \
&& echo "965cc5a8bb46ce4199a47e9b2c9e1cae3b137e8356ffdad6d94d3b9069b71dc2 $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& ./autogen.sh \
&& ./configure --prefix=$QEMU_LD_PREFIX --host=${target_host} --disable-shared --enable-static --with-pic --disable-samples --disable-libevent-regress \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
# For lzma and zstd, we do not override prefix because those are discovered thanks to pkg-config during Tor build
# I did not managed to make pkg-config discover pkg on a different prefix...
RUN apt-get install -y autopoint && wget -q https://jaist.dl.sourceforge.net/project/lzmautils/xz-5.2.3.tar.gz \
&& TAR_NAME=xz-5.2.3.tar.gz \
&& FOLDER_NAME=xz-5.2.3 \
&& echo "71928b357d0a09a12a4b4c5fafca8c31c19b0e7d3b8ebb19622e96f26dbf28cb $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& ./autogen.sh \
&& ./configure --host=${target_host} --disable-shared --enable-static --disable-doc --disable-scripts --disable-xz --disable-xzdec --disable-lzmadec \
--disable-lzmainfo --disable-lzma-links \
&& make \
&& make install \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
RUN wget -q https://github.com/facebook/zstd/archive/v1.3.2.tar.gz \
&& TAR_NAME=v1.3.2.tar.gz \
&& FOLDER_NAME=zstd-1.3.2 \
&& echo "ac5054a3c64e6510bc1ae890d05e3d271cc33ceebc9d06ac9f08105766d2798a $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
# https://trac.torproject.org/projects/tor/ticket/27802
RUN apt-get install -y pkg-config && wget -q https://www.torproject.org/dist/tor-${TOR_VERSION}.tar.gz \
&& TAR_NAME=tor-${TOR_VERSION}.tar.gz \
&& FOLDER_NAME=tor-${TOR_VERSION} \
&& echo "${TOR_HASH} $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& LIBS="-lssl -lcrypto -lpthread -ldl" ./configure --prefix=$QEMU_LD_PREFIX --host=${target_host} --disable-gcc-hardening --disable-asciidoc \
--enable-static-tor \
--enable-static-libevent --with-libevent-dir=$QEMU_LD_PREFIX \
--enable-static-openssl --with-openssl-dir=$QEMU_LD_PREFIX \
--enable-static-zlib --with-zlib-dir=$QEMU_LD_PREFIX \
--enable-zstd --enable-lzma \
--disable-systemd --disable-seccomp --disable-unittests --disable-tool-name-check \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME \
&& ${STRIP} /usr/arm-linux-gnueabihf/bin/tor-* && ${STRIP} /usr/arm-linux-gnueabihf/bin/tor
FROM arm32v7/debian:buster-slim
ENV target_host=arm-linux-gnueabihf
ENV QEMU_LD_PREFIX=/usr/${target_host}
COPY --from=download /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static
COPY --from=download "/tmp/bin" /usr/local/bin
COPY --from=tor-build /usr/arm-linux-gnueabihf/bin/tor* /usr/bin/
COPY --from=tor-build ${QEMU_LD_PREFIX}/share/tor/ ${QEMU_LD_PREFIX}/share/tor/
ENV TOR_DATA /home/tor/.tor
RUN chmod +x /usr/local/bin/gosu && groupadd -r tor && useradd -r -m -g tor tor && mkdir -p ${TOR_DATA} && chown -R tor:tor "$TOR_DATA"
VOLUME /home/tor/.tor
COPY docker-entrypoint.sh /entrypoint.sh
# SOCKS5, TOR control
EXPOSE 9050 9051
ENV TOR_CONFIG=/usr/local/etc/tor/torrc
RUN rm -rf /usr/arm-linux-gnueabihf/etc/tor \
&& mkdir -p /usr/arm-linux-gnueabihf/etc \
&& mkdir -p /usr/local/etc/tor \
&& ln -sfn /usr/local/etc/tor /usr/arm-linux-gnueabihf/etc/tor
ENTRYPOINT ["./entrypoint.sh"]
CMD ["tor"]

View File

@ -0,0 +1,130 @@
FROM debian:buster-slim as download
RUN set -ex \
&& apt-get update \
&& apt-get install -qq --no-install-recommends ca-certificates dirmngr wget \
qemu qemu-user-static qemu-user binfmt-support
WORKDIR /tmp/bin
RUN wget -qO gosu "https://github.com/tianon/gosu/releases/download/1.13/gosu-arm64" \
&& echo "578b2c70936cae372f6826585f82e76de5858342dd179605a8cb58d58828a079 gosu" | sha256sum -c -
FROM debian:buster-slim as tor-build
ARG TOR_GPG_KEY=0x6AFEE6D49E92B601
ENV TOR_VERSION=0.4.5.9
ENV TOR_HASH=f304e456102ed26c39e5f16ece2115585398cdb4e67455139c86ea43cdf70856
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates perl autoconf automake build-essential git libtool python python3 wget gnupg dirmngr git \
libc6-arm64-cross gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
ENV target_host=aarch64-linux-gnu
ENV AR=${target_host}-ar \
AS=${target_host}-as \
CC=${target_host}-gcc \
CXX=${target_host}-g++ \
LD=${target_host}-ld \
STRIP=${target_host}-strip \
QEMU_LD_PREFIX=/usr/${target_host} \
HOST=${target_host}
RUN wget -q https://zlib.net/zlib-1.2.11.tar.gz \
&& TAR_NAME=zlib-1.2.11.tar.gz \
&& FOLDER_NAME=zlib-1.2.11 \
&& echo "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1 $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& ./configure --prefix=$QEMU_LD_PREFIX \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
RUN wget -q https://github.com/openssl/openssl/archive/OpenSSL_1_1_1i.tar.gz \
&& TAR_NAME=OpenSSL_1_1_1i.tar.gz \
&& FOLDER_NAME=openssl-OpenSSL_1_1_1i \
&& echo "728d537d466a062e94705d44ee8c13c7b82d1b66f59f4e948e0cbf1cd7c461d8 $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& ./Configure --prefix=$QEMU_LD_PREFIX linux-aarch64 no-shared no-dso no-zlib no-asm \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
RUN wget -q https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz \
&& TAR_NAME=libevent-2.1.8-stable.tar.gz \
&& FOLDER_NAME=libevent-2.1.8-stable \
&& echo "965cc5a8bb46ce4199a47e9b2c9e1cae3b137e8356ffdad6d94d3b9069b71dc2 $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& ./autogen.sh \
&& ./configure --prefix=$QEMU_LD_PREFIX --host=${target_host} --disable-shared --enable-static --with-pic --disable-samples --disable-libevent-regress \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
# For lzma and zstd, we do not override prefix because those are discovered thanks to pkg-config during Tor build
# I did not managed to make pkg-config discover pkg on a different prefix...
RUN apt-get install -y autopoint && wget -q https://jaist.dl.sourceforge.net/project/lzmautils/xz-5.2.3.tar.gz \
&& TAR_NAME=xz-5.2.3.tar.gz \
&& FOLDER_NAME=xz-5.2.3 \
&& echo "71928b357d0a09a12a4b4c5fafca8c31c19b0e7d3b8ebb19622e96f26dbf28cb $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& ./autogen.sh \
&& ./configure --host=${target_host} --disable-shared --enable-static --disable-doc --disable-scripts --disable-xz --disable-xzdec --disable-lzmadec \
--disable-lzmainfo --disable-lzma-links \
&& make \
&& make install \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
RUN wget -q https://github.com/facebook/zstd/archive/v1.3.2.tar.gz \
&& TAR_NAME=v1.3.2.tar.gz \
&& FOLDER_NAME=zstd-1.3.2 \
&& echo "ac5054a3c64e6510bc1ae890d05e3d271cc33ceebc9d06ac9f08105766d2798a $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME
# https://trac.torproject.org/projects/tor/ticket/27802
RUN apt-get install -y pkg-config && wget -q https://www.torproject.org/dist/tor-${TOR_VERSION}.tar.gz \
&& TAR_NAME=tor-${TOR_VERSION}.tar.gz \
&& FOLDER_NAME=tor-${TOR_VERSION} \
&& echo "${TOR_HASH} $TAR_NAME" | sha256sum -c - \
&& tar xvf $TAR_NAME \
&& cd $FOLDER_NAME \
&& LIBS="-lssl -lcrypto -lpthread -ldl" ./configure --prefix=$QEMU_LD_PREFIX --host=${target_host} --disable-gcc-hardening --disable-asciidoc \
--enable-static-tor \
--enable-static-libevent --with-libevent-dir=$QEMU_LD_PREFIX \
--enable-static-openssl --with-openssl-dir=$QEMU_LD_PREFIX \
--enable-static-zlib --with-zlib-dir=$QEMU_LD_PREFIX \
--enable-zstd --enable-lzma \
--disable-systemd --disable-seccomp --disable-unittests --disable-tool-name-check \
&& make \
&& make install && cd .. && rm $TAR_NAME && rm -rf $FOLDER_NAME \
&& ${STRIP} /usr/aarch64-linux-gnu/bin/tor-* && ${STRIP} /usr/aarch64-linux-gnu/bin/tor
FROM arm64v8/debian:buster-slim
ENV target_host=aarch64-linux-gnu
ENV QEMU_LD_PREFIX=/usr/${target_host}
COPY --from=download /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static
COPY --from=download "/tmp/bin" /usr/local/bin
COPY --from=tor-build /usr/aarch64-linux-gnu/bin/tor* /usr/bin/
COPY --from=tor-build ${QEMU_LD_PREFIX}/share/tor/ ${QEMU_LD_PREFIX}/share/tor/
ENV TOR_DATA /home/tor/.tor
RUN chmod +x /usr/local/bin/gosu && groupadd -r tor && useradd -r -m -g tor tor && mkdir -p ${TOR_DATA} && chown -R tor:tor "$TOR_DATA"
VOLUME /home/tor/.tor
COPY docker-entrypoint.sh /entrypoint.sh
# SOCKS5, TOR control
EXPOSE 9050 9051
ENV TOR_CONFIG=/usr/local/etc/tor/torrc
RUN rm -rf /usr/aarch64-linux-gnu/etc/tor \
&& mkdir -p /usr/aarch64-linux-gnu/etc \
&& mkdir -p /usr/local/etc/tor \
&& ln -sfn /usr/local/etc/tor /usr/aarch64-linux-gnu/etc/tor
ENTRYPOINT ["./entrypoint.sh"]
CMD ["tor"]