mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 12:48:33 +00:00
Support for an 'end session' protocol message.
1) On the push side, this message is a flag in PushMessageContent. Any secure message with that flag will terminate the current sessin. 2) On the SMS side, there is an "end session" wire type and the convention that a message with this wire type must be secure and contain the string "TERMINATE."
This commit is contained in:
@@ -22,6 +22,7 @@ import android.util.Log;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor;
|
||||
import org.thoughtcrime.securesms.crypto.KeyExchangeProcessorV2;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||
@@ -85,12 +86,15 @@ public class PushTransport extends BaseTransport {
|
||||
Recipient recipient = message.getIndividualRecipient();
|
||||
long threadId = message.getThreadId();
|
||||
PushServiceSocket socket = PushServiceSocketFactory.create(context);
|
||||
byte[] plaintext = PushMessageContent.newBuilder()
|
||||
.setBody(message.getBody().getBody())
|
||||
.build().toByteArray();
|
||||
byte[] plaintext = getPlaintextMessage(message);
|
||||
|
||||
deliver(socket, recipient, threadId, plaintext);
|
||||
|
||||
if (message.isEndSession()) {
|
||||
SessionRecordV2.deleteAll(context, recipient);
|
||||
KeyExchangeProcessor.broadcastSecurityUpdateEvent(context, threadId);
|
||||
}
|
||||
|
||||
context.sendBroadcast(constructSentIntent(context, message.getId(), message.getType(), true));
|
||||
|
||||
} catch (InvalidNumberException e) {
|
||||
@@ -295,6 +299,17 @@ public class PushTransport extends BaseTransport {
|
||||
return builder.build().toByteArray();
|
||||
}
|
||||
|
||||
private byte[] getPlaintextMessage(SmsMessageRecord record) {
|
||||
PushMessageContent.Builder builder = PushMessageContent.newBuilder()
|
||||
.setBody(record.getBody().getBody());
|
||||
|
||||
if (record.isEndSession()) {
|
||||
builder.setFlags(PushMessageContent.Flags.END_SESSION_VALUE);
|
||||
}
|
||||
|
||||
return builder.build().toByteArray();
|
||||
}
|
||||
|
||||
private OutgoingPushMessageList getEncryptedMessages(PushServiceSocket socket, long threadId,
|
||||
Recipient recipient, byte[] plaintext)
|
||||
throws IOException, InvalidNumberException, UntrustedIdentityException
|
||||
@@ -352,8 +367,4 @@ public class PushTransport extends BaseTransport {
|
||||
throw new AssertionError("Unknown ciphertext type: " + message.getType());
|
||||
}
|
||||
}
|
||||
|
||||
private void destroySessions(Recipient recipient) {
|
||||
SessionRecordV2.deleteAll(context, recipient);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
import org.whispersystems.textsecure.crypto.SessionCipher;
|
||||
import org.whispersystems.textsecure.crypto.protocol.CiphertextMessage;
|
||||
import org.whispersystems.textsecure.storage.RecipientDevice;
|
||||
import org.whispersystems.textsecure.util.Hex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class SmsTransport extends BaseTransport {
|
||||
}
|
||||
|
||||
public void deliver(SmsMessageRecord message) throws UndeliverableMessageException {
|
||||
if (message.isSecure() || message.isKeyExchange()) {
|
||||
if (message.isSecure() || message.isKeyExchange() || message.isEndSession()) {
|
||||
deliverSecureMessage(message);
|
||||
} else {
|
||||
deliverPlaintextMessage(message);
|
||||
@@ -58,7 +59,7 @@ public class SmsTransport extends BaseTransport {
|
||||
MultipartSmsMessageHandler multipartMessageHandler = new MultipartSmsMessageHandler();
|
||||
OutgoingTextMessage transportMessage = OutgoingTextMessage.from(message);
|
||||
|
||||
if (message.isSecure()) {
|
||||
if (message.isSecure() || message.isEndSession()) {
|
||||
transportMessage = getAsymmetricEncrypt(masterSecret, transportMessage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user