Adds TLS to the push notification client (keystore_tusky_api is omitted).
This commit is contained in:
parent
b396f2afc8
commit
6ee6157b7f
3 changed files with 11 additions and 12 deletions
|
@ -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<ResponseBody> response) {
|
||||
if (response.isSuccessful()) {
|
||||
pushNotificationClient.subscribeToTopic(getPushNotificationTopic());
|
||||
pushNotificationClient.connect();
|
||||
pushNotificationClient.connect(BaseActivity.this);
|
||||
} else {
|
||||
onEnablePushNotificationsFailure();
|
||||
onEnablePushNotificationsFailure(response.message());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ResponseBody> 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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<resources>
|
||||
<string name="app_name" translatable="false">Tusky</string>
|
||||
<string name="app_website" translatable="false">https://tusky.keylesspalace.com</string>
|
||||
<string name="tusky_api_domain" translatable="false">tuskyapi.keylesspalace.com</string>
|
||||
<string name="tusky_api_domain" translatable="false">apitusky.keylesspalace.com</string>
|
||||
<string name="tusky_api_keystore_password" translatable="false">your_password_here</string>
|
||||
|
||||
<string name="oauth_scheme" translatable="false">oauth2redirect</string>
|
||||
|
|
Loading…
Reference in a new issue