commit f5f2d79d3b94edc5efc297516288828ae3213203 Author: Michael Gibson Date: Thu May 21 13:52:09 2020 -0500 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ece105c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM golang:1.14-alpine as build +ENV LANG C.UTF-8 +RUN apk add --no-cache \ + gcc \ + git \ + libsecret-dev \ + make \ + musl-dev +WORKDIR /usr/src +RUN git clone https://github.com/ProtonMail/proton-bridge.git proton-bridge +WORKDIR /usr/src/proton-bridge +RUN make build-nogui + +FROM alpine:edge +ENV LANG C.UTF-8 +ENV SMTP_PORT 1025 +ENV IMAP_PORT 1143 +COPY --from=build /usr/src/proton-bridge/Desktop-Bridge /bin/protonmail-bridge +RUN apk add --no-cache \ + libsecret \ + pass \ + socat \ + su-exec +COPY entrypoint /bin/ +RUN chmod +x /bin/entrypoint +COPY initproton /bin/ +RUN chmod +x /bin/initproton +COPY gpgparams /tmp/ +WORKDIR /var/lib/proton +ENTRYPOINT ["/bin/entrypoint"] +CMD ["/bin/initproton"] diff --git a/entrypoint b/entrypoint new file mode 100755 index 0000000..09fbe3b --- /dev/null +++ b/entrypoint @@ -0,0 +1,15 @@ +#!/bin/bash +# Add local user +# Either use the PUID/PGID if passed in at runtime or +# fallback + +USER_ID=${PUID:-9001} +GROUP_ID=${PGID:-$USER_ID} +echo "Starting with UID : $USER_ID:$GROUP_ID" +addgroup -g $GROUP_ID proton +adduser -D -u $USER_ID -G proton -h /var/lib/proton -s /bin/bash proton +chown -R ${USER_ID}:${GROUP_ID} /var/lib/proton + +export HOME=/var/lib/proton + +exec /sbin/su-exec proton "$@" \ No newline at end of file diff --git a/gpgparams b/gpgparams new file mode 100755 index 0000000..720ad37 --- /dev/null +++ b/gpgparams @@ -0,0 +1,8 @@ +%no-protection +%echo Generating a basic OpenPGP key +Key-Type: RSA +Key-Length: 2048 +Name-Real: pass-key +Expire-Date: 0 +%commit +%echo done \ No newline at end of file diff --git a/initproton b/initproton new file mode 100755 index 0000000..0979cf2 --- /dev/null +++ b/initproton @@ -0,0 +1,43 @@ +#!/bin/bash +set -eufo pipefail + +BRIDGE=/bin/protonmail-bridge +PRINT_INFO=${PRINT_INFO:-""} +SMTP_PORT=${SMTP_PORT:-"1025"} +IMAP_PORT=${IMAP_PORT:-"1143"} + +#### INIT +PASS_FILE=${PASS_FILE:-} +if [ -n "$PASS_FILE" ]; then + echo "Using PASS file." + PASS=$(cat $PASS_FILE) +fi + +if ! [ -f ./initialized ]; then + gpg --generate-key --batch /tmp/gpgparams + pass init pass-key + COMMAND="login\n$EMAIL\n$PASSWORD" + RUN_2FA_LOGIN=${RUN_2FA_LOGIN:-} + if [ -n "$RUN_2FA_LOGIN" ]; then + echo "Using MFA code." + COMMAND="$COMMAND\n$MFA_CODE" + fi + echo "Executing COMMAND: $COMMAND" + echo -e "$COMMAND" | $BRIDGE --cli + touch ./initialized +fi + +if [ -n "$PRINT_INFO" ]; then + echo info | $BRIDGE --cli | egrep '(Username|Password)' | sort -ru +fi + +# socat will make the conn appear to come from 127.0.0.1 +# ProtonMail Bridge currently expects that. +# It also allows us to bind to the real ports :) +socat TCP-LISTEN:$SMTP_PORT,fork TCP:127.0.0.1:1025 & +socat TCP-LISTEN:$IMAP_PORT,fork TCP:127.0.0.1:1143 & + +# Fake a terminal, so it does not quit because of EOF... +rm -f faketty +mkfifo faketty +cat faketty | $BRIDGE --cli \ No newline at end of file