Adding Signal SMS verification strings.

- Changes the voice verification string.
- Keeps the TextSecure SMS String for matching in Signal for Android.
- Changes TextSecure to Signal for iOS, adding tap to verify link.
- Added test for iOS query parameter.
This commit is contained in:
Frederic Jacobs
2015-11-29 16:50:11 +01:00
committed by Moxie Marlinspike
parent 85509c6d8b
commit b31a88043e
7 changed files with 53 additions and 23 deletions

View File

@@ -51,6 +51,7 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -103,7 +104,8 @@ public class AccountController {
@GET
@Path("/{transport}/code/{number}")
public Response createAccount(@PathParam("transport") String transport,
@PathParam("number") String number)
@PathParam("number") String number,
@QueryParam("client") String client)
throws IOException, RateLimitExceededException
{
if (!Util.isValidNumber(number)) {
@@ -128,7 +130,7 @@ public class AccountController {
if (testDevices.containsKey(number)) {
// noop
} else if (transport.equals("sms")) {
smsSender.deliverSmsVerification(number, verificationCode.getVerificationCodeDisplay());
smsSender.deliverSmsVerification(number, client, verificationCode.getVerificationCodeDisplay());
} else if (transport.equals("voice")) {
smsSender.deliverVoxVerification(number, verificationCode.getVerificationCodeSpeech());
}

View File

@@ -19,6 +19,7 @@ package org.whispersystems.textsecuregcm.sms;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.SharedMetricRegistries;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.configuration.NexmoConfiguration;
@@ -56,10 +57,18 @@ public class NexmoSmsSender {
this.number = config.getNumber();
}
public void deliverSmsVerification(String destination, String verificationCode) throws IOException {
URL url = new URL(String.format(NEXMO_SMS_URL, apiKey, apiSecret, number, destination,
URLEncoder.encode(SmsSender.SMS_VERIFICATION_TEXT + verificationCode, "UTF-8")));
public void deliverSmsVerification(String destination, String clientType, String verificationCode) throws IOException {
String verificationMsg;
if ("ios".equals(clientType)) {
verificationMsg = String.format(SmsSender.SMS_IOS_VERIFICATION_TEXT, verificationCode, verificationCode);
} else {
verificationMsg = String.format(SmsSender.SMS_VERIFICATION_TEXT, verificationCode);
}
URL url = new URL(String.format(NEXMO_SMS_URL, apiKey, apiSecret, number, destination,
URLEncoder.encode(verificationMsg, "UTF-8")));
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.connect();

View File

@@ -25,9 +25,9 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
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 TextSecure verification code: ";
static final String VOX_VERIFICATION_TEXT = "Your TextSecure verification code is: ";
static final String VOX_VERIFICATION_TEXT = "Your Signal verification code is: ";
private final Logger logger = LoggerFactory.getLogger(SmsSender.class);
@@ -44,7 +44,7 @@ public class SmsSender {
this.nexmoSender = nexmoSender;
}
public void deliverSmsVerification(String destination, String verificationCode)
public void deliverSmsVerification(String destination, String clientType, String verificationCode)
throws IOException
{
// Fix up mexico numbers to 'mobile' format just for SMS delivery.
@@ -53,14 +53,14 @@ public class SmsSender {
}
if (!isTwilioDestination(destination) && nexmoSender.isPresent()) {
nexmoSender.get().deliverSmsVerification(destination, verificationCode);
nexmoSender.get().deliverSmsVerification(destination, clientType, verificationCode);
} else {
try {
twilioSender.deliverSmsVerification(destination, verificationCode);
twilioSender.deliverSmsVerification(destination, clientType, verificationCode);
} catch (TwilioRestException e) {
logger.info("Twilio SMS Failed: " + e.getErrorMessage());
if (nexmoSender.isPresent()) {
nexmoSender.get().deliverSmsVerification(destination, verificationCode);
nexmoSender.get().deliverSmsVerification(destination, clientType, verificationCode);
}
}
}

View File

@@ -63,7 +63,7 @@ public class TwilioSmsSender {
this.random = new Random(System.currentTimeMillis());
}
public void deliverSmsVerification(String destination, String verificationCode)
public void deliverSmsVerification(String destination, String clientType, String verificationCode)
throws IOException, TwilioRestException
{
TwilioRestClient client = new TwilioRestClient(accountId, accountToken);
@@ -71,8 +71,13 @@ public class TwilioSmsSender {
List<NameValuePair> messageParams = new LinkedList<>();
messageParams.add(new BasicNameValuePair("To", destination));
messageParams.add(new BasicNameValuePair("From", getRandom(random, numbers)));
messageParams.add(new BasicNameValuePair("Body", SmsSender.SMS_VERIFICATION_TEXT + verificationCode));
if ("ios".equals(clientType)) {
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) {