From dc07184015028ad3d4369f87467682004ce5b357 Mon Sep 17 00:00:00 2001 From: Finn Date: Tue, 4 Dec 2018 21:19:10 -0800 Subject: [PATCH 1/4] Add ability to patch (and maybe remove twilio?) --- signal-server-patches/remove-twilio.patch | 118 ++++++++++++++++++++++ signal-server.Dockerfile | 2 + 2 files changed, 120 insertions(+) create mode 100644 signal-server-patches/remove-twilio.patch diff --git a/signal-server-patches/remove-twilio.patch b/signal-server-patches/remove-twilio.patch new file mode 100644 index 0000000..0e83f58 --- /dev/null +++ b/signal-server-patches/remove-twilio.patch @@ -0,0 +1,118 @@ +diff --git a/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java b/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java +index 481965d..9e130f8 100644 +--- a/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java ++++ b/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java +@@ -19,105 +19,36 @@ package org.whispersystems.textsecuregcm.sms; + import com.codahale.metrics.Meter; + import com.codahale.metrics.MetricRegistry; + import com.codahale.metrics.SharedMetricRegistries; +-import com.twilio.sdk.TwilioRestClient; +-import com.twilio.sdk.TwilioRestException; +-import com.twilio.sdk.resource.factory.CallFactory; +-import com.twilio.sdk.resource.factory.MessageFactory; +-import org.apache.http.NameValuePair; +-import org.apache.http.message.BasicNameValuePair; + import org.whispersystems.textsecuregcm.configuration.TwilioConfiguration; + import org.whispersystems.textsecuregcm.util.Constants; +-import org.whispersystems.textsecuregcm.util.Util; + + import java.io.IOException; +-import java.util.ArrayList; +-import java.util.HashMap; +-import java.util.LinkedList; +-import java.util.List; +-import java.util.Map; + import java.util.Optional; +-import java.util.Random; ++ ++import org.slf4j.Logger; ++import org.slf4j.LoggerFactory; + + import static com.codahale.metrics.MetricRegistry.name; + +-@SuppressWarnings("OptionalUsedAsFieldOrParameterType") + public class TwilioSmsSender { + +- public static final String SAY_TWIML = "\n" + +- "\n" + +- " " + SmsSender.VOX_VERIFICATION_TEXT + "%s.\n" + +- ""; +- + private final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME); + private final Meter smsMeter = metricRegistry.meter(name(getClass(), "sms", "delivered")); + private final Meter voxMeter = metricRegistry.meter(name(getClass(), "vox", "delivered")); + +- private final String accountId; +- private final String accountToken; +- private final ArrayList numbers; +- private final String messagingServicesId; +- private final String localDomain; +- private final Random random; ++ private final Logger logger = LoggerFactory.getLogger(TwilioSmsSender.class); + + public TwilioSmsSender(TwilioConfiguration config) { +- this.accountId = config.getAccountId (); +- this.accountToken = config.getAccountToken(); +- this.numbers = new ArrayList<>(config.getNumbers()); +- this.localDomain = config.getLocalDomain(); +- this.messagingServicesId = config.getMessagingServicesId(); +- this.random = new Random(System.currentTimeMillis()); + } + +- public void deliverSmsVerification(String destination, Optional clientType, String verificationCode) +- throws IOException, TwilioRestException +- { +- TwilioRestClient client = new TwilioRestClient(accountId, accountToken); +- MessageFactory messageFactory = client.getAccount().getMessageFactory(); +- List messageParams = new LinkedList<>(); +- messageParams.add(new BasicNameValuePair("To", destination)); +- +- if (Util.isEmpty(messagingServicesId)) { +- messageParams.add(new BasicNameValuePair("From", getRandom(random, numbers))); +- } else { +- messageParams.add(new BasicNameValuePair("MessagingServiceSid", messagingServicesId)); +- } +- +- if ("ios".equals(clientType.orElse(null))) { +- messageParams.add(new BasicNameValuePair("Body", String.format(SmsSender.SMS_IOS_VERIFICATION_TEXT, verificationCode, verificationCode))); +- } else { +- messageParams.add(new BasicNameValuePair("Body", String.format(SmsSender.SMS_VERIFICATION_TEXT, verificationCode))); +- } +- +- try { +- messageFactory.create(messageParams); +- } catch (RuntimeException damnYouTwilio) { +- throw new IOException(damnYouTwilio); +- } +- ++ public void deliverSmsVerification(String destination, Optional clientType, String verificationCode) throws IOException { ++ logger.info("Pretending to send SMS verification to " + destination + ": " + verificationCode); + smsMeter.mark(); + } + +- public void deliverVoxVerification(String destination, String verificationCode) +- throws IOException, TwilioRestException +- { +- TwilioRestClient client = new TwilioRestClient(accountId, accountToken); +- CallFactory callFactory = client.getAccount().getCallFactory(); +- Map callParams = new HashMap<>(); +- callParams.put("To", destination); +- callParams.put("From", getRandom(random, numbers)); +- callParams.put("Url", "https://" + localDomain + "/v1/accounts/voice/twiml/" + verificationCode); +- +- try { +- callFactory.create(callParams); +- } catch (RuntimeException damnYouTwilio) { +- throw new IOException(damnYouTwilio); +- } +- ++ public void deliverVoxVerification(String destination, String verificationCode) throws IOException { ++ logger.info("Pretending to send voice verification to " + destination + ": " + verificationCode); + voxMeter.mark(); + } + +- private String getRandom(Random random, ArrayList elements) { +- return elements.get(random.nextInt(elements.size())); +- } +- + } diff --git a/signal-server.Dockerfile b/signal-server.Dockerfile index 42eed8a..e0e2893 100644 --- a/signal-server.Dockerfile +++ b/signal-server.Dockerfile @@ -2,6 +2,8 @@ FROM debian:9 as build RUN apt-get update && apt-get install -y openjdk-8-jdk-headless maven git RUN git -C /usr/local/src clone https://github.com/signalapp/Signal-Server WORKDIR /usr/local/src/Signal-Server +COPY signal-server-patches /tmp/signal-server-patches +RUN bash -exc "for patch in /tmp/signal-server-patches/*.patch; do patch -p1 $patch; done" RUN mvn install -DskipTests RUN ls -lha target From 37f43a05f8fad95a0df3ca310eb0596ff7352290 Mon Sep 17 00:00:00 2001 From: Finn Date: Tue, 4 Dec 2018 21:29:19 -0800 Subject: [PATCH 2/4] Change how signal server patches are applied --- signal-server-patches/apply-patches.sh | 6 ++++++ signal-server.Dockerfile | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100755 signal-server-patches/apply-patches.sh diff --git a/signal-server-patches/apply-patches.sh b/signal-server-patches/apply-patches.sh new file mode 100755 index 0000000..ab4e9e9 --- /dev/null +++ b/signal-server-patches/apply-patches.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -euo pipefail +for patch in /tmp/signal-server-patches/*.patch; do + echo "patch -p1 < \$patch" + patch -p1 < $patch +done diff --git a/signal-server.Dockerfile b/signal-server.Dockerfile index 3325a8b..3c9bf5a 100644 --- a/signal-server.Dockerfile +++ b/signal-server.Dockerfile @@ -3,7 +3,7 @@ RUN apt-get update && apt-get install -y openjdk-8-jdk-headless maven git RUN git -C /usr/local/src clone https://github.com/signalapp/Signal-Server WORKDIR /usr/local/src/Signal-Server COPY signal-server-patches /tmp/signal-server-patches -RUN bash -exc "for patch in /tmp/signal-server-patches/*.patch; do patch -p1 $patch; done" +RUN /tmp/signal-server-patches/apply-patches.sh RUN mvn install -DskipTests RUN ls -lha target From 6b8592d1d6cfc7717ad1b00bf828091202c9d036 Mon Sep 17 00:00:00 2001 From: Finn Date: Tue, 4 Dec 2018 21:40:56 -0800 Subject: [PATCH 3/4] Update remove-twilio patch to more completely remove it --- signal-server-patches/remove-twilio.patch | 140 ++++++---------------- 1 file changed, 39 insertions(+), 101 deletions(-) diff --git a/signal-server-patches/remove-twilio.patch b/signal-server-patches/remove-twilio.patch index 0e83f58..af0bbcc 100644 --- a/signal-server-patches/remove-twilio.patch +++ b/signal-server-patches/remove-twilio.patch @@ -1,118 +1,56 @@ -diff --git a/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java b/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java -index 481965d..9e130f8 100644 ---- a/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java -+++ b/src/main/java/org/whispersystems/textsecuregcm/sms/TwilioSmsSender.java -@@ -19,105 +19,36 @@ package org.whispersystems.textsecuregcm.sms; - import com.codahale.metrics.Meter; - import com.codahale.metrics.MetricRegistry; - import com.codahale.metrics.SharedMetricRegistries; --import com.twilio.sdk.TwilioRestClient; +diff --git a/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java b/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java +index 8b62e0f..3bde269 100644 +--- a/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java ++++ b/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java +@@ -17,27 +17,17 @@ + package org.whispersystems.textsecuregcm.sms; + + -import com.twilio.sdk.TwilioRestException; --import com.twilio.sdk.resource.factory.CallFactory; --import com.twilio.sdk.resource.factory.MessageFactory; --import org.apache.http.NameValuePair; --import org.apache.http.message.BasicNameValuePair; - import org.whispersystems.textsecuregcm.configuration.TwilioConfiguration; - import org.whispersystems.textsecuregcm.util.Constants; --import org.whispersystems.textsecuregcm.util.Util; + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; import java.io.IOException; --import java.util.ArrayList; --import java.util.HashMap; --import java.util.LinkedList; --import java.util.List; --import java.util.Map; import java.util.Optional; --import java.util.Random; -+ -+import org.slf4j.Logger; -+import org.slf4j.LoggerFactory; - - import static com.codahale.metrics.MetricRegistry.name; -@SuppressWarnings("OptionalUsedAsFieldOrParameterType") - public class TwilioSmsSender { - -- public static final String SAY_TWIML = "\n" + -- "\n" + -- " " + SmsSender.VOX_VERIFICATION_TEXT + "%s.\n" + -- ""; + public class SmsSender { - - private final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME); - private final Meter smsMeter = metricRegistry.meter(name(getClass(), "sms", "delivered")); - private final Meter voxMeter = metricRegistry.meter(name(getClass(), "vox", "delivered")); +- static final String SMS_IOS_VERIFICATION_TEXT = "Your Signal verification code: %s\n\nOr tap: sgnl://verify/%s"; +- static final String SMS_VERIFICATION_TEXT = "Your Signal verification code: %s"; +- static final String VOX_VERIFICATION_TEXT = "Your Signal verification code is: "; +- + private final Logger logger = LoggerFactory.getLogger(SmsSender.class); -- private final String accountId; -- private final String accountToken; -- private final ArrayList numbers; -- private final String messagingServicesId; -- private final String localDomain; -- private final Random random; -+ private final Logger logger = LoggerFactory.getLogger(TwilioSmsSender.class); +- private final TwilioSmsSender twilioSender; ++ public SmsSender(TwilioSmsSender twilioSender) { - public TwilioSmsSender(TwilioConfiguration config) { -- this.accountId = config.getAccountId (); -- this.accountToken = config.getAccountToken(); -- this.numbers = new ArrayList<>(config.getNumbers()); -- this.localDomain = config.getLocalDomain(); -- this.messagingServicesId = config.getMessagingServicesId(); -- this.random = new Random(System.currentTimeMillis()); - } - -- public void deliverSmsVerification(String destination, Optional clientType, String verificationCode) -- throws IOException, TwilioRestException +- public SmsSender(TwilioSmsSender twilioSender) - { -- TwilioRestClient client = new TwilioRestClient(accountId, accountToken); -- MessageFactory messageFactory = client.getAccount().getMessageFactory(); -- List messageParams = new LinkedList<>(); -- messageParams.add(new BasicNameValuePair("To", destination)); -- -- if (Util.isEmpty(messagingServicesId)) { -- messageParams.add(new BasicNameValuePair("From", getRandom(random, numbers))); -- } else { -- messageParams.add(new BasicNameValuePair("MessagingServiceSid", messagingServicesId)); -- } -- -- if ("ios".equals(clientType.orElse(null))) { -- messageParams.add(new BasicNameValuePair("Body", String.format(SmsSender.SMS_IOS_VERIFICATION_TEXT, verificationCode, verificationCode))); -- } else { -- messageParams.add(new BasicNameValuePair("Body", String.format(SmsSender.SMS_VERIFICATION_TEXT, verificationCode))); -- } -- -- try { -- messageFactory.create(messageParams); -- } catch (RuntimeException damnYouTwilio) { -- throw new IOException(damnYouTwilio); -- } -- -+ public void deliverSmsVerification(String destination, Optional clientType, String verificationCode) throws IOException { -+ logger.info("Pretending to send SMS verification to " + destination + ": " + verificationCode); - smsMeter.mark(); +- this.twilioSender = twilioSender; } -- public void deliverVoxVerification(String destination, String verificationCode) -- throws IOException, TwilioRestException -- { -- TwilioRestClient client = new TwilioRestClient(accountId, accountToken); -- CallFactory callFactory = client.getAccount().getCallFactory(); -- Map callParams = new HashMap<>(); -- callParams.put("To", destination); -- callParams.put("From", getRandom(random, numbers)); -- callParams.put("Url", "https://" + localDomain + "/v1/accounts/voice/twiml/" + verificationCode); -- + public void deliverSmsVerification(String destination, Optional clientType, String verificationCode) +@@ -48,20 +38,12 @@ public class SmsSender { + destination = "+521" + destination.substring(3); + } + - try { -- callFactory.create(callParams); -- } catch (RuntimeException damnYouTwilio) { -- throw new IOException(damnYouTwilio); +- twilioSender.deliverSmsVerification(destination, clientType, verificationCode); +- } catch (TwilioRestException e) { +- logger.info("Twilio SMS Failed: " + e.getErrorMessage()); - } -- -+ public void deliverVoxVerification(String destination, String verificationCode) throws IOException { -+ logger.info("Pretending to send voice verification to " + destination + ": " + verificationCode); - voxMeter.mark(); ++ logger.info("Sending SMS verification code to " + destination + ": " + destination); } -- private String getRandom(Random random, ArrayList elements) { -- return elements.get(random.nextInt(elements.size())); -- } -- + public void deliverVoxVerification(String destination, String verificationCode) + throws IOException + { +- try { +- twilioSender.deliverVoxVerification(destination, verificationCode); +- } catch (TwilioRestException e) { +- logger.info("Twilio Vox Failed: " + e.getErrorMessage()); +- } ++ logger.info("Sending voice verification code to " + destination + ": " + verificationCode); + } } From 079776702f97b0afce4797518accf708a3a7b5fb Mon Sep 17 00:00:00 2001 From: Finn Date: Tue, 4 Dec 2018 23:24:00 -0800 Subject: [PATCH 4/4] Update twilio patch again this time i tested it! --- signal-server-patches/remove-twilio.patch | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/signal-server-patches/remove-twilio.patch b/signal-server-patches/remove-twilio.patch index af0bbcc..ab494d0 100644 --- a/signal-server-patches/remove-twilio.patch +++ b/signal-server-patches/remove-twilio.patch @@ -1,11 +1,12 @@ diff --git a/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java b/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java -index 8b62e0f..3bde269 100644 +index 8b62e0f..0e68bb0 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java +++ b/src/main/java/org/whispersystems/textsecuregcm/sms/SmsSender.java -@@ -17,27 +17,17 @@ +@@ -16,15 +16,12 @@ + */ package org.whispersystems.textsecuregcm.sms; - +- -import com.twilio.sdk.TwilioRestException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,11 +16,10 @@ index 8b62e0f..3bde269 100644 -@SuppressWarnings("OptionalUsedAsFieldOrParameterType") public class SmsSender { -- -- static final String SMS_IOS_VERIFICATION_TEXT = "Your Signal verification code: %s\n\nOr tap: sgnl://verify/%s"; -- static final String SMS_VERIFICATION_TEXT = "Your Signal verification code: %s"; -- static final String VOX_VERIFICATION_TEXT = "Your Signal verification code is: "; -- + + static final String SMS_IOS_VERIFICATION_TEXT = "Your Signal verification code: %s\n\nOr tap: sgnl://verify/%s"; +@@ -33,11 +30,8 @@ public class SmsSender { + private final Logger logger = LoggerFactory.getLogger(SmsSender.class); - private final TwilioSmsSender twilioSender; @@ -31,7 +31,7 @@ index 8b62e0f..3bde269 100644 } public void deliverSmsVerification(String destination, Optional clientType, String verificationCode) -@@ -48,20 +38,12 @@ public class SmsSender { +@@ -48,20 +42,12 @@ public class SmsSender { destination = "+521" + destination.substring(3); }