Remove arbitrary SMS and add a NANPA message service (#123)

* Remove arbitrary SMS code

This code has run its course and is no longer needed for now.

* Add elements to sample config that were left out

* Add a messaging service for NANPA

* Fixup sample config capitalization
This commit is contained in:
Ehren Kret
2020-08-05 13:35:11 -05:00
committed by GitHub
parent 178a6bd66e
commit 4fa3a136ad
6 changed files with 101 additions and 82 deletions

View File

@@ -1,18 +1,18 @@
/**
* Copyright (C) 2013 Open WhisperSystems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
Copyright (C) 2013 Open WhisperSystems
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.whispersystems.textsecuregcm.configuration;
@@ -37,7 +37,8 @@ public class TwilioConfiguration {
@NotEmpty
private String localDomain;
private String messagingServicesId;
private String messagingServiceSid;
private String nanpaMessagingServiceSid;
@NotNull
@Valid
@@ -99,13 +100,22 @@ public class TwilioConfiguration {
this.localDomain = localDomain;
}
public String getMessagingServicesId() {
return messagingServicesId;
public String getMessagingServiceSid() {
return messagingServiceSid;
}
@VisibleForTesting
public void setMessagingServicesId(String messagingServicesId) {
this.messagingServicesId = messagingServicesId;
public void setMessagingServiceSid(String messagingServiceSid) {
this.messagingServiceSid = messagingServiceSid;
}
public String getNanpaMessagingServiceSid() {
return nanpaMessagingServiceSid;
}
@VisibleForTesting
public void setNanpaMessagingServiceSid(String nanpaMessagingServiceSid) {
this.nanpaMessagingServiceSid = nanpaMessagingServiceSid;
}
public CircuitBreakerConfiguration getCircuitBreaker() {

View File

@@ -21,6 +21,7 @@ import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.SharedMetricRegistries;
import com.codahale.metrics.annotation.Timed;
import com.google.common.annotations.VisibleForTesting;
import io.dropwizard.auth.Auth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.auth.AuthenticationCredentials;
@@ -84,7 +85,6 @@ import java.util.Optional;
import java.util.UUID;
import static com.codahale.metrics.MetricRegistry.name;
import io.dropwizard.auth.Auth;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@Path("/v1/accounts")
@@ -227,11 +227,6 @@ public class AccountController {
throw new WebApplicationException(Response.status(422).build());
}
if (userAgent != null && userAgent.stream().anyMatch(header -> header.toLowerCase().contains("okhttp"))) {
smsSender.deliverUpdatetoSignalSms(number);
return Response.ok().build();
}
VerificationCode verificationCode = generateVerificationCode(number);
StoredVerificationCode storedVerificationCode = new StoredVerificationCode(verificationCode.getVerificationCode(),
System.currentTimeMillis(),

View File

@@ -27,10 +27,6 @@ public class SmsSender {
this.twilioSender = twilioSender;
}
public void deliverUpdatetoSignalSms(String destination) {
twilioSender.deliverArbitrarySms(destination, "To continue installing, update to Signal: https://play.google.com/store/apps/details?id=org.thoughtcrime.securesms");
}
public void deliverSmsVerification(String destination, Optional<String> clientType, String verificationCode) {
// Fix up mexico numbers to 'mobile' format just for SMS delivery.
if (destination.startsWith("+52") && !destination.startsWith("+521")) {

View File

@@ -22,6 +22,7 @@ import com.codahale.metrics.SharedMetricRegistries;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.configuration.TwilioConfiguration;
@@ -57,7 +58,6 @@ public class TwilioSmsSender {
private static final Logger logger = LoggerFactory.getLogger(TwilioSmsSender.class);
private final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
private final Meter arbitraryMeter = metricRegistry.meter(name(getClass(), "arbitrary", "delivered"));
private final Meter smsMeter = metricRegistry.meter(name(getClass(), "sms", "delivered"));
private final Meter voxMeter = metricRegistry.meter(name(getClass(), "vox", "delivered"));
private final Meter priceMeter = metricRegistry.meter(name(getClass(), "price"));
@@ -65,7 +65,8 @@ public class TwilioSmsSender {
private final String accountId;
private final String accountToken;
private final ArrayList<String> numbers;
private final String messagingServicesId;
private final String messagingServiceSid;
private final String nanpaMessagingServiceSid;
private final String localDomain;
private final SenderIdSupplier senderIdSupplier;
private final Random random;
@@ -86,7 +87,8 @@ public class TwilioSmsSender {
this.accountToken = twilioConfiguration.getAccountToken();
this.numbers = new ArrayList<>(twilioConfiguration.getNumbers());
this.localDomain = twilioConfiguration.getLocalDomain();
this.messagingServicesId = twilioConfiguration.getMessagingServicesId();
this.messagingServiceSid = twilioConfiguration.getMessagingServiceSid();
this.nanpaMessagingServiceSid = twilioConfiguration.getNanpaMessagingServiceSid();
this.senderIdSupplier = new SenderIdSupplier(twilioConfiguration.getSenderId());
this.random = new Random(System.currentTimeMillis());
this.androidNgVerificationText = twilioConfiguration.getAndroidNgVerificationText();
@@ -110,26 +112,6 @@ public class TwilioSmsSender {
this("https://api.twilio.com", twilioConfiguration);
}
public CompletableFuture<Boolean> deliverArbitrarySms(String destination, String message) {
Map<String, String> requestParameters = new HashMap<>();
requestParameters.put("To", destination);
setOriginationRequestParameter(destination, requestParameters);
requestParameters.put("Body", message);
HttpRequest request = HttpRequest.newBuilder()
.uri(smsUri)
.POST(FormDataBodyPublisher.of(requestParameters))
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Authorization", "Basic " + Base64.encodeBytes((accountId + ":" + accountToken).getBytes()))
.build();
arbitraryMeter.mark();
return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(this::parseResponse)
.handle(this::processResponse);
}
public CompletableFuture<Boolean> deliverSmsVerification(String destination, Optional<String> clientType, String verificationCode) {
Map<String, String> requestParameters = new HashMap<>();
requestParameters.put("To", destination);
@@ -193,10 +175,12 @@ public class TwilioSmsSender {
final Optional<String> senderId = senderIdSupplier.get(destination);
if (senderId.isPresent()) {
requestParameters.put("From", senderId.get());
} else if (Util.isEmpty(messagingServicesId)) {
requestParameters.put("From", getRandom(random, numbers));
} else if (StringUtils.isNotEmpty(nanpaMessagingServiceSid) && "1".equals(Util.getCountryCode(destination))) {
requestParameters.put("MessagingServiceSid", nanpaMessagingServiceSid);
} else if (StringUtils.isNotEmpty(messagingServiceSid)) {
requestParameters.put("MessagingServiceSid", messagingServiceSid);
} else {
requestParameters.put("MessagingServiceSid", messagingServicesId);
requestParameters.put("From", getRandom(random, numbers));
}
}