This commit is contained in:
Niels Andriesse 2019-06-07 15:21:25 +10:00
parent becce74cc8
commit c8cc22e8fe
7 changed files with 61 additions and 19 deletions

View File

@ -5,6 +5,8 @@ import java.security.MessageDigest
buildscript { buildscript {
ext.gradle_version = "3.4.1" ext.gradle_version = "3.4.1"
ext.kotlin_version = "1.3.31" ext.kotlin_version = "1.3.31"
ext.kovenant_version = "3.3.0"
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
@ -180,6 +182,7 @@ dependencies {
testImplementation 'org.robolectric:robolectric:4.2' testImplementation 'org.robolectric:robolectric:4.2'
testImplementation 'org.robolectric:shadows-multidex:4.2' testImplementation 'org.robolectric:shadows-multidex:4.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "nl.komponents.kovenant:kovenant:$kovenant_version"
} }
android { android {

View File

@ -29,6 +29,7 @@ import android.support.multidex.MultiDexApplication;
import com.google.android.gms.security.ProviderInstaller; import com.google.android.gms.security.ProviderInstaller;
import org.conscrypt.Conscrypt; import org.conscrypt.Conscrypt;
import org.jetbrains.annotations.NotNull;
import org.signal.aesgcmprovider.AesGcmProvider; import org.signal.aesgcmprovider.AesGcmProvider;
import org.thoughtcrime.securesms.components.TypingStatusRepository; import org.thoughtcrime.securesms.components.TypingStatusRepository;
import org.thoughtcrime.securesms.components.TypingStatusSender; import org.thoughtcrime.securesms.components.TypingStatusSender;
@ -69,6 +70,8 @@ import org.webrtc.PeerConnectionFactory.InitializationOptions;
import org.webrtc.voiceengine.WebRtcAudioManager; import org.webrtc.voiceengine.WebRtcAudioManager;
import org.webrtc.voiceengine.WebRtcAudioUtils; import org.webrtc.voiceengine.WebRtcAudioUtils;
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider; import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider;
import org.whispersystems.signalservice.loki.api.LokiP2PAPI;
import org.whispersystems.signalservice.loki.api.LokiP2PAPIDelegate;
import java.security.Security; import java.security.Security;
import java.util.HashSet; import java.util.HashSet;
@ -76,6 +79,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import dagger.ObjectGraph; import dagger.ObjectGraph;
import kotlin.jvm.functions.Function2;
/** /**
* Will be called once when the TextSecure process is created. * Will be called once when the TextSecure process is created.
@ -85,7 +89,7 @@ import dagger.ObjectGraph;
* *
* @author Moxie Marlinspike * @author Moxie Marlinspike
*/ */
public class ApplicationContext extends MultiDexApplication implements DependencyInjector, DefaultLifecycleObserver { public class ApplicationContext extends MultiDexApplication implements DependencyInjector, DefaultLifecycleObserver, LokiP2PAPIDelegate {
private static final String TAG = ApplicationContext.class.getSimpleName(); private static final String TAG = ApplicationContext.class.getSimpleName();
@ -126,6 +130,17 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
initializeBlobProvider(); initializeBlobProvider();
NotificationChannels.create(this); NotificationChannels.create(this);
ProcessLifecycleOwner.get().getLifecycle().addObserver(this); ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
if (hexEncodedPublicKey != null) {
LokiP2PAPI.Companion.configure(hexEncodedPublicKey, new Function2<Boolean, String, Void>() {
@Override
public Void invoke(Boolean aBoolean, String s) {
return null;
}
}, this);
}
} }
@Override @Override
@ -356,4 +371,9 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
private static class ProviderInitializationException extends RuntimeException { private static class ProviderInitializationException extends RuntimeException {
} }
@Override
public void ping(@NotNull String s) {
// TODO: Implement
}
} }

View File

@ -19,7 +19,6 @@ package org.thoughtcrime.securesms;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast;
import org.thoughtcrime.securesms.conversation.ConversationActivity; import org.thoughtcrime.securesms.conversation.ConversationActivity;
import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.Address;
@ -50,10 +49,10 @@ public class NewConversationActivity extends ContactSelectionActivity {
public void onContactSelected(String number) { public void onContactSelected(String number) {
boolean isValid = PublicKeyValidation.isValid(number); boolean isValid = PublicKeyValidation.isValid(number);
if (!isValid) { // if (!isValid) {
Toast.makeText(this, R.string.activity_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show(); // Toast.makeText(this, R.string.activity_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show();
return; // return;
} // }
Recipient recipient = Recipient.from(this, Address.fromSerialized(number), true); Recipient recipient = Recipient.from(this, Address.fromSerialized(number), true);

View File

@ -31,6 +31,7 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.helpers.ClassicOpenHelper; import org.thoughtcrime.securesms.database.helpers.ClassicOpenHelper;
import org.thoughtcrime.securesms.database.helpers.SQLCipherMigrationHelper; import org.thoughtcrime.securesms.database.helpers.SQLCipherMigrationHelper;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper; import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
import org.thoughtcrime.securesms.loki.LokiContactPreKeyDatabase; import org.thoughtcrime.securesms.loki.LokiContactPreKeyDatabase;
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase; import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
@ -62,6 +63,7 @@ public class DatabaseFactory {
private final JobDatabase jobDatabase; private final JobDatabase jobDatabase;
// Loki // Loki
private final LokiAPIDatabase lokiAPIDatabase;
private final LokiContactPreKeyDatabase lokiContactPreKeyDatabase; private final LokiContactPreKeyDatabase lokiContactPreKeyDatabase;
private final LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase; private final LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase;
@ -151,6 +153,10 @@ public class DatabaseFactory {
} }
// region Loki // region Loki
public static LokiAPIDatabase getLokiAPIDatabase(Context context) {
return getInstance(context).lokiAPIDatabase;
}
public static LokiContactPreKeyDatabase getLokiContactPreKeyDatabase(Context context) { public static LokiContactPreKeyDatabase getLokiContactPreKeyDatabase(Context context) {
return getInstance(context).lokiContactPreKeyDatabase; return getInstance(context).lokiContactPreKeyDatabase;
} }
@ -191,6 +197,7 @@ public class DatabaseFactory {
this.searchDatabase = new SearchDatabase(context, databaseHelper); this.searchDatabase = new SearchDatabase(context, databaseHelper);
this.jobDatabase = new JobDatabase(context, databaseHelper); this.jobDatabase = new JobDatabase(context, databaseHelper);
this.lokiAPIDatabase = new LokiAPIDatabase(TextSecurePreferences.getLocalNumber(context), context, databaseHelper);
this.lokiContactPreKeyDatabase = new LokiContactPreKeyDatabase(context, databaseHelper); this.lokiContactPreKeyDatabase = new LokiContactPreKeyDatabase(context, databaseHelper);
this.lokiPreKeyBundleDatabase = new LokiPreKeyBundleDatabase(context, databaseHelper); this.lokiPreKeyBundleDatabase = new LokiPreKeyBundleDatabase(context, databaseHelper);
} }

View File

@ -870,7 +870,7 @@ public class SmsDatabase extends MessagingDatabase {
long expireStarted = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.EXPIRE_STARTED)); long expireStarted = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.EXPIRE_STARTED));
String body = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY)); String body = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY));
boolean unidentified = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.UNIDENTIFIED)) == 1; boolean unidentified = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.UNIDENTIFIED)) == 1;
boolean isFriendRequest = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.IS_FRIEND_REQUEST)) == 1; boolean isFriendRequest = true;//= cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.IS_FRIEND_REQUEST)) == 1;
if (!TextSecurePreferences.isReadReceiptsEnabled(context)) { if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
readReceiptCount = 0; readReceiptCount = 0;

View File

@ -2,14 +2,13 @@ package org.thoughtcrime.securesms.jobs;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId;
import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode;
import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId;
import org.thoughtcrime.securesms.database.NoSuchMessageException; import org.thoughtcrime.securesms.database.NoSuchMessageException;
import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode;
import org.thoughtcrime.securesms.database.SmsDatabase; import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.dependencies.InjectableType;
@ -30,11 +29,16 @@ import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException; import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
import org.whispersystems.signalservice.loki.api.LokiAPI;
import org.whispersystems.signalservice.loki.messaging.SignalMessageInfo;
import java.io.IOException; import java.io.IOException;
import javax.inject.Inject; import javax.inject.Inject;
import kotlin.Unit;
public class PushTextSendJob extends PushSendJob implements InjectableType { public class PushTextSendJob extends PushSendJob implements InjectableType {
public static final String KEY = "PushTextSendJob"; public static final String KEY = "PushTextSendJob";
@ -90,6 +94,11 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
byte[] profileKey = recipient.getProfileKey(); byte[] profileKey = recipient.getProfileKey();
UnidentifiedAccessMode accessMode = recipient.getUnidentifiedAccessMode(); UnidentifiedAccessMode accessMode = recipient.getUnidentifiedAccessMode();
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context);
SignalMessageInfo message = new SignalMessageInfo(SignalServiceProtos.Envelope.Type.FRIEND_REQUEST, System.currentTimeMillis(), hexEncodedPublicKey, 0, "stub", recipient.getAddress().serialize(), 4 * 24 * 60 * 60 * 1000, false);
LokiAPI api = new LokiAPI(hexEncodedPublicKey, DatabaseFactory.getLokiAPIDatabase(context));
api.sendSignalMessage(message, () -> Unit.INSTANCE);
boolean unidentified = deliver(record); boolean unidentified = deliver(record);
database.markAsSent(messageId, true); database.markAsSent(messageId, true);

View File

@ -183,15 +183,19 @@ public class MessageSender {
} }
private static boolean isPushTextSend(Context context, Recipient recipient, boolean keyExchange) { private static boolean isPushTextSend(Context context, Recipient recipient, boolean keyExchange) {
if (!TextSecurePreferences.isPushRegistered(context)) { return true;
return false; // Loki - Original code
} // ========
// if (!TextSecurePreferences.isPushRegistered(context)) {
if (keyExchange) { // return false;
return false; // }
} //
// if (keyExchange) {
return isPushDestination(context, recipient); // return false;
// }
//
// return isPushDestination(context, recipient);
// ========
} }
private static boolean isPushMediaSend(Context context, Recipient recipient) { private static boolean isPushMediaSend(Context context, Recipient recipient) {