Skip to content

Commit

Permalink
Merge branch 'signal_cli_v_0_10_0_upgrade'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard B committed Dec 30, 2021
2 parents 0d0b061 + 9037bce commit 2e6e45b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 80 deletions.
98 changes: 34 additions & 64 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
ARG SIGNAL_CLI_VERSION=0.9.2
ARG ZKGROUP_VERSION=0.8.2
ARG LIBSIGNAL_CLIENT_VERSION=0.9.7
ARG SIGNAL_CLI_VERSION=0.10.0
ARG LIBSIGNAL_CLIENT_VERSION=0.11.0

ARG SWAG_VERSION=1.6.7
ARG GRAALVM_JAVA_VERSION=11
ARG GRAALVM_JAVA_VERSION=17
ARG GRAALVM_VERSION=21.3.0

FROM golang:1.17-bullseye AS buildcontainer

ARG SIGNAL_CLI_VERSION
ARG ZKGROUP_VERSION
ARG LIBSIGNAL_CLIENT_VERSION
ARG SWAG_VERSION
ARG GRAALVM_JAVA_VERSION
ARG GRAALVM_VERSION

COPY ext/libraries/zkgroup/v${ZKGROUP_VERSION} /tmp/zkgroup-libraries
COPY ext/libraries/libsignal-client/v${LIBSIGNAL_CLIENT_VERSION} /tmp/libsignal-client-libraries

# use architecture specific libzkgroup.so
RUN arch="$(uname -m)"; \
case "$arch" in \
aarch64) echo "[DEBUG] Using arm64 zkgroup" && cp /tmp/zkgroup-libraries/arm64/libzkgroup.so /tmp/libzkgroup.so ;; \
armv7l) echo "[DEBUG] Using armv7 zkgroup" && cp /tmp/zkgroup-libraries/armv7/libzkgroup.so /tmp/libzkgroup.so ;; \
x86_64) echo "[DEBUG] Using x86-64 zkgroup" && cp /tmp/zkgroup-libraries/x86-64/libzkgroup.so /tmp/libzkgroup.so ;; \
*) echo "Unknown architecture" && exit 1 ;; \
esac;

# use architecture specific libsignal_jni.so
RUN arch="$(uname -m)"; \
case "$arch" in \
Expand All @@ -37,14 +25,14 @@ RUN arch="$(uname -m)"; \
esac;

RUN apt-get update \
&& apt-get install -y --no-install-recommends wget default-jre software-properties-common git locales zip file build-essential libz-dev zlib1g-dev \
&& apt-get install -y --no-install-recommends wget openjdk-17-jre software-properties-common git locales zip file build-essential libz-dev zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8

ENV PATH="/root/.cargo/bin:${PATH}"
ENV JAVA_OPTS="-Djdk.lang.Process.launchMechanism=vfork"

ENV LANG en_US.UTF-8

Expand All @@ -57,14 +45,8 @@ RUN cd /tmp/ \
&& rm -r /tmp/swag-${SWAG_VERSION}

RUN cd /tmp/ \
&& git clone https://github.com/AsamK/signal-cli.git signal-cli-${SIGNAL_CLI_VERSION} \
&& cd signal-cli-${SIGNAL_CLI_VERSION} \
&& git checkout v${SIGNAL_CLI_VERSION} \
&& cp /tmp/libzkgroup.so ./lib/src/main/resources/libzkgroup.so \
&& cp /tmp/libsignal_jni.so ./lib/src/main/resources/libsignal_jni.so \
&& ./gradlew build \
&& ./gradlew installDist \
&& ./gradlew distTar
&& wget https://github.com/AsamK/signal-cli/releases/download/v${SIGNAL_CLI_VERSION}/signal-cli-${SIGNAL_CLI_VERSION}.tar.gz -O /tmp/signal-cli.tar.gz \
&& tar xvf signal-cli.tar.gz

# build native image with graalvm

Expand All @@ -73,57 +55,44 @@ RUN arch="$(uname -m)"; \
aarch64) wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${GRAALVM_VERSION}/graalvm-ce-java${GRAALVM_JAVA_VERSION}-linux-aarch64-${GRAALVM_VERSION}.tar.gz -O /tmp/gvm.tar.gz ;; \
armv7l) echo "GRAALVM doesn't support 32bit" ;; \
x86_64) wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${GRAALVM_VERSION}/graalvm-ce-java${GRAALVM_JAVA_VERSION}-linux-amd64-${GRAALVM_VERSION}.tar.gz -O /tmp/gvm.tar.gz ;; \
*) echo "Invalid architecture" ;; \
esac;

RUN if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "x86_64" ]; then \
cd /tmp && tar xvf gvm.tar.gz \
RUN if [ "$(uname -m)" = "x86_64" ]; then \
cd /tmp \
&& git clone https://github.com/AsamK/signal-cli.git signal-cli-${SIGNAL_CLI_VERSION}-source \
&& cd signal-cli-${SIGNAL_CLI_VERSION}-source \
&& git checkout v${SIGNAL_CLI_VERSION} \
&& cd /tmp && tar xvf gvm.tar.gz \
&& export GRAALVM_HOME=/tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION} \
&& export PATH=/tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION}/bin:$PATH \
&& cd /tmp/signal-cli-${SIGNAL_CLI_VERSION} \
&& cd /tmp/signal-cli-${SIGNAL_CLI_VERSION}-source \
&& chmod +x /tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION}/bin/gu \
&& /tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION}/bin/gu install native-image \
&& ./gradlew nativeCompile; \
elif [ "$(uname -m)" = "armv7l" ]; then \
elif [ "$(uname -m)" = "aarch64" ] ; then \
echo "GRAALVM for aarch64 temporarily disabled" \
&& echo "Creating temporary file, otherwise the below copy doesn't work for aarch64" \
&& mkdir -p /tmp/signal-cli-${SIGNAL_CLI_VERSION}-source/build/native/nativeCompile \
&& touch /tmp/signal-cli-${SIGNAL_CLI_VERSION}-source/build/native/nativeCompile/signal-cli; \
elif [ "$(uname -m)" = "armv7l" ] ; then \
echo "GRAALVM doesn't support 32bit" \
&& echo "Creating temporary file, otherwise the below copy doesn't work for armv7" \
&& mkdir -p /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/native/nativeCompile \
&& touch /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/native/nativeCompile/signal-cli; \
&& mkdir -p /tmp/signal-cli-${SIGNAL_CLI_VERSION}-source/build/native/nativeCompile \
&& touch /tmp/signal-cli-${SIGNAL_CLI_VERSION}-source/build/native/nativeCompile/signal-cli; \
else \
echo "Unknown architecture"; \
fi;

# replace zkgroup

RUN ls /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/zkgroup-java-${ZKGROUP_VERSION}.jar || (echo "\n\nzkgroup jar file with version ${ZKGROUP_VERSION} not found. Maybe the version needs to be bumped in the signal-cli-rest-api Dockerfile?\n\n" && echo "Available version: \n" && ls /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/zkgroup-java-* && echo "\n\n" && exit 1)

RUN cd /tmp/ \
&& zip -u /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/zkgroup-java-${ZKGROUP_VERSION}.jar libzkgroup.so

RUN cd /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/ \
&& mkdir -p signal-cli-${SIGNAL_CLI_VERSION}/lib/ \
&& cp /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/zkgroup-java-${ZKGROUP_VERSION}.jar signal-cli-${SIGNAL_CLI_VERSION}/lib/ \
# update zip
&& zip -u /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.zip signal-cli-${SIGNAL_CLI_VERSION}/lib/zkgroup-java-${ZKGROUP_VERSION}.jar \
# update tar
&& tar --delete -vPf /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.tar signal-cli-${SIGNAL_CLI_VERSION}/lib/zkgroup-java-${ZKGROUP_VERSION}.jar \
&& tar --owner='' --group='' -rvPf /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.tar signal-cli-${SIGNAL_CLI_VERSION}/lib/zkgroup-java-${ZKGROUP_VERSION}.jar

# replace libsignal-client

RUN ls /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar || (echo "\n\nsignal-client jar file with version ${LIBSIGNAL_CLIENT_VERSION} not found. Maybe the version needs to be bumped in the signal-cli-rest-api Dockerfile?\n\n" && echo "Available version: \n" && ls /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/signal-client-java-* && echo "\n\n" && exit 1)
RUN ls /tmp/signal-cli-${SIGNAL_CLI_VERSION}/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar || (echo "\n\nsignal-client jar file with version ${LIBSIGNAL_CLIENT_VERSION} not found. Maybe the version needs to be bumped in the signal-cli-rest-api Dockerfile?\n\n" && echo "Available version: \n" && ls /tmp/signal-cli-${SIGNAL_CLI_VERSION}/lib/signal-client-java-* && echo "\n\n" && exit 1)

RUN cd /tmp/ \
&& zip -u /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar libsignal_jni.so

RUN cd /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/ \
&& mkdir -p signal-cli-${SIGNAL_CLI_VERSION}/lib/ \
&& cp /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar signal-cli-${SIGNAL_CLI_VERSION}/lib/ \
# update zip
&& zip -u /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.zip signal-cli-${SIGNAL_CLI_VERSION}/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar \
# update tar
&& tar --delete -vPf /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.tar signal-cli-${SIGNAL_CLI_VERSION}/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar \
&& tar --owner='' --group='' -rvPf /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.tar signal-cli-${SIGNAL_CLI_VERSION}/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar
&& zip -u /tmp/signal-cli-${SIGNAL_CLI_VERSION}/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar libsignal_jni.so

RUN cd /tmp \
&& zip -r signal-cli-${SIGNAL_CLI_VERSION}.zip signal-cli-${SIGNAL_CLI_VERSION}/*

COPY src/api /tmp/signal-cli-rest-api-src/api
COPY src/client /tmp/signal-cli-rest-api-src/client
Expand All @@ -141,7 +110,7 @@ RUN cd /tmp/signal-cli-rest-api-src/scripts && go build -o jsonrpc2-helper


# Start a fresh container for release container
FROM eclipse-temurin:11-jre-focal
FROM eclipse-temurin:17-focal

ENV GIN_MODE=release

Expand All @@ -150,17 +119,17 @@ ENV PORT=8080
ARG SIGNAL_CLI_VERSION

RUN apt-get update \
&& apt-get install -y --no-install-recommends util-linux supervisor netcat \
&& apt-get install -y --no-install-recommends util-linux supervisor netcat unzip \
&& rm -rf /var/lib/apt/lists/*

COPY --from=buildcontainer /tmp/signal-cli-rest-api-src/signal-cli-rest-api /usr/bin/signal-cli-rest-api
COPY --from=buildcontainer /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.tar /tmp/signal-cli-${SIGNAL_CLI_VERSION}.tar
COPY --from=buildcontainer /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/native/nativeCompile/signal-cli /tmp/signal-cli-native
COPY --from=buildcontainer /tmp/signal-cli-${SIGNAL_CLI_VERSION}.zip /tmp/signal-cli-${SIGNAL_CLI_VERSION}.zip
COPY --from=buildcontainer /tmp/signal-cli-${SIGNAL_CLI_VERSION}-source/build/native/nativeCompile/signal-cli /tmp/signal-cli-native
COPY --from=buildcontainer /tmp/signal-cli-rest-api-src/scripts/jsonrpc2-helper /usr/bin/jsonrpc2-helper
COPY entrypoint.sh /entrypoint.sh

RUN tar xf /tmp/signal-cli-${SIGNAL_CLI_VERSION}.tar -C /opt
RUN rm -rf /tmp/signal-cli-${SIGNAL_CLI_VERSION}.tar
RUN unzip /tmp/signal-cli-${SIGNAL_CLI_VERSION}.zip -d /opt
RUN rm -rf /tmp/signal-cli-${SIGNAL_CLI_VERSION}.zip

RUN groupadd -g 1000 signal-api \
&& useradd --no-log-init -M -d /home -s /bin/bash -u 1000 -g 1000 signal-api \
Expand All @@ -175,6 +144,7 @@ RUN groupadd -g 1000 signal-api \
RUN arch="$(uname -m)"; \
case "$arch" in \
armv7l) echo "GRAALVM doesn't support 32bit" && rm /opt/signal-cli-${SIGNAL_CLI_VERSION}/bin/signal-cli-native /usr/bin/signal-cli-native ;; \
aarch64) echo "GRAALVM temporarily disabled for aarch64" && rm /opt/signal-cli-${SIGNAL_CLI_VERSION}/bin/signal-cli-native /usr/bin/signal-cli-native ;; \
esac;

EXPOSE ${PORT}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
32 changes: 16 additions & 16 deletions src/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (s *SignalClient) send(number string, message string,
return nil, err
}
} else {
cmd := []string{"--config", s.signalCliConfig, "-u", number, "send"}
cmd := []string{"--config", s.signalCliConfig, "-a", number, "send"}
if !isGroup {
cmd = append(cmd, recipients...)
} else {
Expand Down Expand Up @@ -471,7 +471,7 @@ func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha stri
if s.signalCliMode == JsonRpc {
return errors.New(endpointNotSupportedInJsonRpcMode)
}
command := []string{"--config", s.signalCliConfig, "-u", number, "register"}
command := []string{"--config", s.signalCliConfig, "-a", number, "register"}

if useVoice {
command = append(command, "--voice")
Expand All @@ -490,7 +490,7 @@ func (s *SignalClient) VerifyRegisteredNumber(number string, token string, pin s
return errors.New(endpointNotSupportedInJsonRpcMode)
}

cmd := []string{"--config", s.signalCliConfig, "-u", number, "verify", token}
cmd := []string{"--config", s.signalCliConfig, "-a", number, "verify", token}
if pin != "" {
cmd = append(cmd, "--pin")
cmd = append(cmd, pin)
Expand Down Expand Up @@ -572,7 +572,7 @@ func (s *SignalClient) Receive(number string, timeout int64) (string, error) {
}
return string(msg.Params), nil
} else {
command := []string{"--config", s.signalCliConfig, "--output", "json", "-u", number, "receive", "-t", strconv.FormatInt(timeout, 10)}
command := []string{"--config", s.signalCliConfig, "--output", "json", "-a", number, "receive", "-t", strconv.FormatInt(timeout, 10)}

out, err := runSignalCli(true, command, "", s.signalCliMode)
if err != nil {
Expand Down Expand Up @@ -624,7 +624,7 @@ func (s *SignalClient) CreateGroup(number string, name string, members []string,
}
internalGroupId = resp.GroupId
} else {
cmd := []string{"--config", s.signalCliConfig, "-u", number, "updateGroup", "-n", name, "-m"}
cmd := []string{"--config", s.signalCliConfig, "-a", number, "updateGroup", "-n", name, "-m"}
cmd = append(cmd, members...)

if addMembersPermission != DefaultGroupPermission {
Expand Down Expand Up @@ -674,7 +674,7 @@ func (s *SignalClient) GetGroups(number string) ([]GroupEntry, error) {
return groupEntries, err
}
} else {
rawData, err = runSignalCli(true, []string{"--config", s.signalCliConfig, "--output", "json", "-u", number, "listGroups", "-d"}, "", s.signalCliMode)
rawData, err = runSignalCli(true, []string{"--config", s.signalCliConfig, "--output", "json", "-a", number, "listGroups", "-d"}, "", s.signalCliMode)
if err != nil {
return groupEntries, err
}
Expand Down Expand Up @@ -736,7 +736,7 @@ func (s *SignalClient) GetGroup(number string, groupId string) (*GroupEntry, err
}

func (s *SignalClient) DeleteGroup(number string, groupId string) error {
_, err := runSignalCli(true, []string{"--config", s.signalCliConfig, "-u", number, "quitGroup", "-g", string(groupId)}, "", s.signalCliMode)
_, err := runSignalCli(true, []string{"--config", s.signalCliConfig, "-a", number, "quitGroup", "-g", string(groupId)}, "", s.signalCliMode)
return err
}

Expand Down Expand Up @@ -871,7 +871,7 @@ func (s *SignalClient) UpdateProfile(number string, profileName string, base64Av
}
_, err = jsonRpc2Client.getRaw("updateProfile", request)
} else {
cmd := []string{"--config", s.signalCliConfig, "-u", number, "updateProfile", "--name", profileName}
cmd := []string{"--config", s.signalCliConfig, "-a", number, "updateProfile", "--name", profileName}
if base64Avatar == "" {
cmd = append(cmd, "--remove-avatar")
} else {
Expand Down Expand Up @@ -909,7 +909,7 @@ func (s *SignalClient) ListIdentities(number string) (*[]IdentityEntry, error) {
identityEntries = append(identityEntries, identityEntry)
}
} else {
rawData, err := runSignalCli(true, []string{"--config", s.signalCliConfig, "-u", number, "listIdentities"}, "", s.signalCliMode)
rawData, err := runSignalCli(true, []string{"--config", s.signalCliConfig, "-a", number, "listIdentities"}, "", s.signalCliMode)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -946,7 +946,7 @@ func (s *SignalClient) TrustIdentity(number string, numberToTrust string, verifi
}
_, err = jsonRpc2Client.getRaw("trust", request)
} else {
cmd := []string{"--config", s.signalCliConfig, "-u", number, "trust", numberToTrust, "--verified-safety-number", verifiedSafetyNumber}
cmd := []string{"--config", s.signalCliConfig, "-a", number, "trust", numberToTrust, "--verified-safety-number", verifiedSafetyNumber}
_, err = runSignalCli(true, cmd, "", s.signalCliMode)
}
return err
Expand All @@ -965,7 +965,7 @@ func (s *SignalClient) BlockGroup(number string, groupId string) error {
}
_, err = jsonRpc2Client.getRaw("block", request)
} else {
_, err = runSignalCli(true, []string{"--config", s.signalCliConfig, "-u", number, "block", "-g", groupId}, "", s.signalCliMode)
_, err = runSignalCli(true, []string{"--config", s.signalCliConfig, "-a", number, "block", "-g", groupId}, "", s.signalCliMode)
}
return err
}
Expand All @@ -983,7 +983,7 @@ func (s *SignalClient) JoinGroup(number string, groupId string) error {
}
_, err = jsonRpc2Client.getRaw("updateGroup", request)
} else {
_, err = runSignalCli(true, []string{"--config", s.signalCliConfig, "-u", number, "updateGroup", "-g", groupId}, "", s.signalCliMode)
_, err = runSignalCli(true, []string{"--config", s.signalCliConfig, "-a", number, "updateGroup", "-g", groupId}, "", s.signalCliMode)
}
return err
}
Expand All @@ -1001,7 +1001,7 @@ func (s *SignalClient) QuitGroup(number string, groupId string) error {
}
_, err = jsonRpc2Client.getRaw("quitGroup", request)
} else {
_, err = runSignalCli(true, []string{"--config", s.signalCliConfig, "-u", number, "quitGroup", "-g", groupId}, "", s.signalCliMode)
_, err = runSignalCli(true, []string{"--config", s.signalCliConfig, "-a", number, "quitGroup", "-g", groupId}, "", s.signalCliMode)
}
return err
}
Expand Down Expand Up @@ -1053,7 +1053,7 @@ func (s *SignalClient) SendReaction(number string, recipient string, emoji strin

cmd := []string{
"--config", s.signalCliConfig,
"-u", number,
"-a", number,
"sendReaction",
}
if !isGroup {
Expand Down Expand Up @@ -1099,7 +1099,7 @@ func (s *SignalClient) SendStartTyping(number string, recipient string) error {
}
_, err = jsonRpc2Client.getRaw("sendTyping", request)
} else {
cmd := []string{"--config", s.signalCliConfig, "-u", number, "sendTyping"}
cmd := []string{"--config", s.signalCliConfig, "-a", number, "sendTyping"}
if !isGroup {
cmd = append(cmd, recp)
} else {
Expand Down Expand Up @@ -1142,7 +1142,7 @@ func (s *SignalClient) SendStopTyping(number string, recipient string) error {
}
_, err = jsonRpc2Client.getRaw("sendTyping", request)
} else {
cmd := []string{"--config", s.signalCliConfig, "-u", number, "sendTyping", "--stop"}
cmd := []string{"--config", s.signalCliConfig, "-a", number, "sendTyping", "--stop"}
if !isGroup {
cmd = append(cmd, recp)
} else {
Expand Down

0 comments on commit 2e6e45b

Please sign in to comment.