From 6ee6157b7f35f1ac50c7a2cd2955860bdcb1ba9c Mon Sep 17 00:00:00 2001 From: Vavassor Date: Mon, 22 May 2017 02:05:37 -0400 Subject: [PATCH] Adds TLS to the push notification client (keystore_tusky_api is omitted). --- .../com/keylesspalace/tusky/BaseActivity.java | 15 +++++++-------- .../tusky/util/PushNotificationClient.java | 6 +++--- app/src/main/res/values/donottranslate.xml | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java index 97bbebec..c6d27244 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java @@ -163,7 +163,7 @@ public class BaseActivity extends AppCompatActivity { protected void createTuskyApi() { Retrofit retrofit = new Retrofit.Builder() - .baseUrl("http://" + getString(R.string.tusky_api_domain) + ":8080") + .baseUrl("https://" + getString(R.string.tusky_api_domain) + ":8080") .client(OkHttpUtils.getCompatibleClient()) .addConverterFactory(GsonConverterFactory.create()) .build(); @@ -172,9 +172,8 @@ public class BaseActivity extends AppCompatActivity { } protected void createPushNotificationClient() { - // TODO: Switch to ssl:// when TLS support is added. pushNotificationClient = new PushNotificationClient(getApplicationContext(), - "tcp://" + getString(R.string.tusky_api_domain) + ":1883"); + "ssl://" + getString(R.string.tusky_api_domain) + ":8883"); } protected void redirectIfNotLoggedIn() { @@ -214,15 +213,15 @@ public class BaseActivity extends AppCompatActivity { retrofit2.Response response) { if (response.isSuccessful()) { pushNotificationClient.subscribeToTopic(getPushNotificationTopic()); - pushNotificationClient.connect(); + pushNotificationClient.connect(BaseActivity.this); } else { - onEnablePushNotificationsFailure(); + onEnablePushNotificationsFailure(response.message()); } } @Override public void onFailure(Call call, Throwable t) { - onEnablePushNotificationsFailure(); + onEnablePushNotificationsFailure(t.getMessage()); } }; String deviceToken = pushNotificationClient.getDeviceToken(); @@ -231,8 +230,8 @@ public class BaseActivity extends AppCompatActivity { .enqueue(callback); } - private void onEnablePushNotificationsFailure() { - Log.e(TAG, "Enabling push notifications failed."); + private void onEnablePushNotificationsFailure(String message) { + Log.e(TAG, "Enabling push notifications failed. " + message); } protected void disablePushNotifications() { diff --git a/app/src/main/java/com/keylesspalace/tusky/util/PushNotificationClient.java b/app/src/main/java/com/keylesspalace/tusky/util/PushNotificationClient.java index 1d7741a3..f3df738f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/PushNotificationClient.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/PushNotificationClient.java @@ -7,6 +7,7 @@ import android.text.Spanned; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Notification; import com.keylesspalace.tusky.json.SpannedTypeAdapter; import com.keylesspalace.tusky.json.StringWithEmoji; @@ -23,6 +24,7 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttMessage; +import java.io.InputStream; import java.util.ArrayDeque; import java.util.ArrayList; @@ -104,12 +106,11 @@ public class PushNotificationClient { } /** Connect to the MQTT broker. */ - public void connect() { + public void connect(Context context) { MqttConnectOptions options = new MqttConnectOptions(); options.setAutomaticReconnect(true); options.setCleanSession(false); try { - /* String password = context.getString(R.string.tusky_api_keystore_password); InputStream keystore = context.getResources().openRawResource(R.raw.keystore_tusky_api); try { @@ -117,7 +118,6 @@ public class PushNotificationClient { } finally { IOUtils.closeQuietly(keystore); } - */ mqttAndroidClient.connect(options).setActionCallback(new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) { diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index e6982534..6d61f3f3 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -2,7 +2,7 @@ Tusky https://tusky.keylesspalace.com - tuskyapi.keylesspalace.com + apitusky.keylesspalace.com your_password_here oauth2redirect