mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Session request removed. Private chats no longer use any encryption.
This commit is contained in:
parent
45ff8fba36
commit
63d1e7087a
@ -33,6 +33,7 @@ import com.google.firebase.iid.FirebaseInstanceId;
|
||||
|
||||
import org.conscrypt.Conscrypt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.session.libsignal.libsignal.state.SessionRecord;
|
||||
import org.signal.aesgcmprovider.AesGcmProvider;
|
||||
import org.thoughtcrime.securesms.components.TypingStatusRepository;
|
||||
import org.thoughtcrime.securesms.components.TypingStatusSender;
|
||||
@ -68,7 +69,6 @@ import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase;
|
||||
import org.thoughtcrime.securesms.loki.database.LokiUserDatabase;
|
||||
import org.thoughtcrime.securesms.loki.database.SharedSenderKeysDatabase;
|
||||
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol;
|
||||
import org.thoughtcrime.securesms.loki.protocol.SessionRequestMessageSendJob;
|
||||
import org.thoughtcrime.securesms.loki.protocol.SessionResetImplementation;
|
||||
import org.thoughtcrime.securesms.loki.utilities.Broadcaster;
|
||||
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities;
|
||||
@ -595,39 +595,51 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
Runtime.getRuntime().exit(0);
|
||||
}
|
||||
|
||||
public boolean hasSentSessionRequestExpired(@NotNull String publicKey) {
|
||||
LokiAPIDatabase apiDB = DatabaseFactory.getLokiAPIDatabase(this);
|
||||
Long timestamp = apiDB.getSessionRequestSentTimestamp(publicKey);
|
||||
if (timestamp != null) {
|
||||
long expiration = timestamp + TTLUtilities.getTTL(TTLUtilities.MessageType.SessionRequest);
|
||||
return new Date().getTime() > expiration;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// public boolean hasSentSessionRequestExpired(@NotNull String publicKey) {
|
||||
// LokiAPIDatabase apiDB = DatabaseFactory.getLokiAPIDatabase(this);
|
||||
// Long timestamp = apiDB.getSessionRequestSentTimestamp(publicKey);
|
||||
// if (timestamp != null) {
|
||||
// long expiration = timestamp + TTLUtilities.getTTL(TTLUtilities.MessageType.SessionRequest);
|
||||
// return new Date().getTime() > expiration;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void sendSessionRequestIfNeeded(@NotNull String publicKey) {
|
||||
// // It's never necessary to establish a session with self
|
||||
// String userPublicKey = TextSecurePreferences.getLocalNumber(this);
|
||||
// if (publicKey.equals(userPublicKey)) { return; }
|
||||
// // Check that we don't already have a session
|
||||
// SignalProtocolAddress address = new SignalProtocolAddress(publicKey, SignalServiceAddress.DEFAULT_DEVICE_ID);
|
||||
// boolean hasSession = new TextSecureSessionStore(this).containsSession(address);
|
||||
// if (hasSession) { return; }
|
||||
// // Check that we didn't already send a session request
|
||||
// LokiAPIDatabase apiDB = DatabaseFactory.getLokiAPIDatabase(this);
|
||||
// boolean hasSentSessionRequest = (apiDB.getSessionRequestSentTimestamp(publicKey) != null);
|
||||
// boolean hasSentSessionRequestExpired = hasSentSessionRequestExpired(publicKey);
|
||||
// if (hasSentSessionRequestExpired) {
|
||||
// apiDB.setSessionRequestSentTimestamp(publicKey, 0);
|
||||
// }
|
||||
// if (hasSentSessionRequest && !hasSentSessionRequestExpired) { return; }
|
||||
// // Send the session request
|
||||
// long timestamp = new Date().getTime();
|
||||
// apiDB.setSessionRequestSentTimestamp(publicKey, timestamp);
|
||||
// SessionRequestMessageSendJob job = new SessionRequestMessageSendJob(publicKey, timestamp);
|
||||
// jobManager.add(job);
|
||||
|
||||
|
||||
// It's never necessary to establish a session with self
|
||||
String userPublicKey = TextSecurePreferences.getLocalNumber(this);
|
||||
if (publicKey.equals(userPublicKey)) { return; }
|
||||
// Check that we don't already have a session
|
||||
SignalProtocolAddress address = new SignalProtocolAddress(publicKey, SignalServiceAddress.DEFAULT_DEVICE_ID);
|
||||
boolean hasSession = new TextSecureSessionStore(this).containsSession(address);
|
||||
if (hasSession) { return; }
|
||||
// Check that we didn't already send a session request
|
||||
LokiAPIDatabase apiDB = DatabaseFactory.getLokiAPIDatabase(this);
|
||||
boolean hasSentSessionRequest = (apiDB.getSessionRequestSentTimestamp(publicKey) != null);
|
||||
boolean hasSentSessionRequestExpired = hasSentSessionRequestExpired(publicKey);
|
||||
if (hasSentSessionRequestExpired) {
|
||||
apiDB.setSessionRequestSentTimestamp(publicKey, 0);
|
||||
TextSecureSessionStore sessionStore = new TextSecureSessionStore(this);
|
||||
boolean hasSession = sessionStore.containsSession(address);
|
||||
if (!hasSession) {
|
||||
sessionStore.storeSession(address, new SessionRecord());
|
||||
}
|
||||
if (hasSentSessionRequest && !hasSentSessionRequestExpired) { return; }
|
||||
// Send the session request
|
||||
long timestamp = new Date().getTime();
|
||||
apiDB.setSessionRequestSentTimestamp(publicKey, timestamp);
|
||||
SessionRequestMessageSendJob job = new SessionRequestMessageSendJob(publicKey, timestamp);
|
||||
jobManager.add(job);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,11 +36,11 @@ import org.thoughtcrime.securesms.loki.api.PrepareAttachmentAudioExtrasJob;
|
||||
import org.thoughtcrime.securesms.loki.api.ResetThreadSessionJob;
|
||||
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupUpdateMessageSendJob;
|
||||
import org.thoughtcrime.securesms.loki.protocol.NullMessageSendJob;
|
||||
import org.thoughtcrime.securesms.loki.protocol.SessionRequestMessageSendJob;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
//TODO AC: Looks like we don't use it anymore. Make sure it's abandoned and delete.
|
||||
public class WorkManagerFactoryMappings {
|
||||
|
||||
private static final Map<String, String> FACTORY_MAP = new HashMap<String, String>() {{
|
||||
@ -69,7 +69,6 @@ public class WorkManagerFactoryMappings {
|
||||
put(RotateProfileKeyJob.class.getName(), RotateProfileKeyJob.KEY);
|
||||
put(SendDeliveryReceiptJob.class.getName(), SendDeliveryReceiptJob.KEY);
|
||||
put(SendReadReceiptJob.class.getName(), SendReadReceiptJob.KEY);
|
||||
put(SessionRequestMessageSendJob.class.getName(), SessionRequestMessageSendJob.KEY);
|
||||
put(SmsReceiveJob.class.getName(), SmsReceiveJob.KEY);
|
||||
put(SmsSendJob.class.getName(), SmsSendJob.KEY);
|
||||
put(SmsSentJob.class.getName(), SmsSentJob.KEY);
|
||||
|
@ -18,7 +18,6 @@ import org.thoughtcrime.securesms.loki.api.PrepareAttachmentAudioExtrasJob;
|
||||
import org.thoughtcrime.securesms.loki.api.ResetThreadSessionJob;
|
||||
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupUpdateMessageSendJob;
|
||||
import org.thoughtcrime.securesms.loki.protocol.NullMessageSendJob;
|
||||
import org.thoughtcrime.securesms.loki.protocol.SessionRequestMessageSendJob;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -54,7 +53,6 @@ public final class JobManagerFactories {
|
||||
put(RotateProfileKeyJob.KEY, new RotateProfileKeyJob.Factory());
|
||||
put(SendDeliveryReceiptJob.KEY, new SendDeliveryReceiptJob.Factory());
|
||||
put(SendReadReceiptJob.KEY, new SendReadReceiptJob.Factory());
|
||||
put(SessionRequestMessageSendJob.KEY, new SessionRequestMessageSendJob.Factory());
|
||||
put(SmsReceiveJob.KEY, new SmsReceiveJob.Factory());
|
||||
put(SmsSendJob.KEY, new SmsSendJob.Factory());
|
||||
put(SmsSentJob.KEY, new SmsSentJob.Factory());
|
||||
|
@ -1,107 +0,0 @@
|
||||
package org.thoughtcrime.securesms.loki.protocol
|
||||
|
||||
import com.google.protobuf.ByteString
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.jobmanager.Data
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
|
||||
import org.thoughtcrime.securesms.jobs.BaseJob
|
||||
import org.thoughtcrime.securesms.logging.Log
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.session.libsignal.service.api.push.SignalServiceAddress
|
||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||
import org.session.libsignal.service.loki.protocol.meta.TTLUtilities
|
||||
import java.io.IOException
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class SessionRequestMessageSendJob private constructor(parameters: Parameters, private val publicKey: String, private val timestamp: Long) : BaseJob(parameters) {
|
||||
|
||||
companion object {
|
||||
const val KEY = "SessionRequestMessageSendJob"
|
||||
}
|
||||
|
||||
constructor(publicKey: String, timestamp: Long) : this(Parameters.Builder()
|
||||
.addConstraint(NetworkConstraint.KEY)
|
||||
.setQueue(KEY)
|
||||
.setLifespan(TimeUnit.DAYS.toMillis(1))
|
||||
.setMaxAttempts(1)
|
||||
.build(),
|
||||
publicKey,
|
||||
timestamp)
|
||||
|
||||
override fun serialize(): Data {
|
||||
return Data.Builder().putString("publicKey", publicKey).putLong("timestamp", timestamp).build()
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String { return KEY }
|
||||
|
||||
public override fun onRun() {
|
||||
// Prepare
|
||||
val contentMessage = SignalServiceProtos.Content.newBuilder()
|
||||
// Attach the pre key bundle message
|
||||
// val preKeyBundleMessage = SignalServiceProtos.PreKeyBundleMessage.newBuilder()
|
||||
// val preKeyBundle = DatabaseFactory.getLokiPreKeyBundleDatabase(context).generatePreKeyBundle(publicKey) ?: return
|
||||
// preKeyBundleMessage.identityKey = ByteString.copyFrom(preKeyBundle.identityKey.serialize())
|
||||
// preKeyBundleMessage.deviceId = preKeyBundle.deviceId
|
||||
// preKeyBundleMessage.preKeyId = preKeyBundle.preKeyId
|
||||
// preKeyBundleMessage.signedKeyId = preKeyBundle.signedPreKeyId
|
||||
// preKeyBundleMessage.preKey = ByteString.copyFrom(preKeyBundle.preKey.serialize())
|
||||
// preKeyBundleMessage.signedKey = ByteString.copyFrom(preKeyBundle.signedPreKey.serialize())
|
||||
// preKeyBundleMessage.signature = ByteString.copyFrom(preKeyBundle.signedPreKeySignature)
|
||||
// contentMessage.preKeyBundleMessage = preKeyBundleMessage.build()
|
||||
// Attach the null message
|
||||
val nullMessage = SignalServiceProtos.NullMessage.newBuilder()
|
||||
val sr = SecureRandom()
|
||||
val paddingSize = sr.nextInt(512)
|
||||
val padding = ByteArray(paddingSize)
|
||||
sr.nextBytes(padding)
|
||||
nullMessage.padding = ByteString.copyFrom(padding)
|
||||
contentMessage.nullMessage = nullMessage.build()
|
||||
// Send the result
|
||||
val serializedContentMessage = contentMessage.build().toByteArray()
|
||||
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
|
||||
val address = SignalServiceAddress(publicKey)
|
||||
val recipient = Recipient.from(context, Address.fromSerialized(publicKey), false)
|
||||
val udAccess = UnidentifiedAccessUtil.getAccessFor(context, recipient)
|
||||
val ttl = TTLUtilities.getTTL(TTLUtilities.MessageType.SessionRequest)
|
||||
try {
|
||||
messageSender.sendMessage(0, address, udAccess.get().targetUnidentifiedAccess,
|
||||
Date().time, serializedContentMessage, false, ttl, false,
|
||||
true, false, false, false)
|
||||
} catch (e: Exception) {
|
||||
Log.d("Loki", "Failed to send session request to: $publicKey due to error: $e.")
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
public override fun onShouldRetry(e: Exception): Boolean {
|
||||
// Disable since we have our own retrying
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onCanceled() {
|
||||
// Update the DB on fail if this is still the most recently sent session request (should always be true)
|
||||
val apiDB = DatabaseFactory.getLokiAPIDatabase(context)
|
||||
if (apiDB.getSessionRequestSentTimestamp(publicKey) == timestamp) {
|
||||
apiDB.setSessionRequestSentTimestamp(publicKey, 0)
|
||||
}
|
||||
}
|
||||
|
||||
class Factory : Job.Factory<SessionRequestMessageSendJob> {
|
||||
|
||||
override fun create(parameters: Parameters, data: Data): SessionRequestMessageSendJob {
|
||||
try {
|
||||
val publicKey = data.getString("publicKey")
|
||||
val timestamp = data.getLong("timestamp")
|
||||
return SessionRequestMessageSendJob(parameters, publicKey, timestamp)
|
||||
} catch (e: IOException) {
|
||||
throw AssertionError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1186,8 +1186,8 @@ public class SignalServiceMessageSender {
|
||||
final String senderID;
|
||||
if (type == SignalServiceProtos.Envelope.Type.CLOSED_GROUP_CIPHERTEXT) {
|
||||
senderID = recipient.getNumber();
|
||||
} else if (type == SignalServiceProtos.Envelope.Type.UNIDENTIFIED_SENDER) {
|
||||
senderID = "";
|
||||
// } else if (type == SignalServiceProtos.Envelope.Type.UNIDENTIFIED_SENDER) {
|
||||
// senderID = "";
|
||||
} else {
|
||||
senderID = userPublicKey;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user