From 72be77b47ed11cd33b6bd5642f977e8e0fc1edb1 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sun, 1 Dec 2013 16:24:30 -0800 Subject: [PATCH] Catch bad prekeys --- .../textsecure/push/PushServiceSocket.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java index 97442cc84..26afbc8de 100644 --- a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java +++ b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java @@ -5,6 +5,7 @@ import android.util.Log; import android.util.Pair; import com.google.thoughtcrimegson.Gson; +import com.google.thoughtcrimegson.JsonParseException; import org.apache.http.conn.ssl.StrictHostnameVerifier; import org.whispersystems.textsecure.crypto.IdentityKey; @@ -149,15 +150,20 @@ public class PushServiceSocket { } public PreKeyEntity getPreKey(PushDestination destination) throws IOException { - String path = String.format(PREKEY_PATH, destination.getNumber()); + try { + String path = String.format(PREKEY_PATH, destination.getNumber()); - if (!Util.isEmpty(destination.getRelay())) { - path = path + "?relay=" + destination.getRelay(); + if (!Util.isEmpty(destination.getRelay())) { + path = path + "?relay=" + destination.getRelay(); + } + + String responseText = makeRequest(path, "GET", null); + Log.w("PushServiceSocket", "Got prekey: " + responseText); + return PreKeyEntity.fromJson(responseText); + } catch (JsonParseException e) { + Log.w("PushServiceSocket", e); + throw new IOException("Bad prekey"); } - - String responseText = makeRequest(path, "GET", null); - Log.w("PushServiceSocket", "Got prekey: " + responseText); - return PreKeyEntity.fromJson(responseText); } public long sendAttachment(PushAttachmentData attachment) throws IOException {