mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Fix some bugs with PKWM padding and attachment detection.
This commit is contained in:
parent
9a6f65988f
commit
d9d4ec9d9d
@ -274,6 +274,17 @@ public class SessionCipher {
|
||||
}
|
||||
}
|
||||
|
||||
public int getSessionVersion() {
|
||||
synchronized (SESSION_LOCK) {
|
||||
if (!sessionStore.containsSession(recipientId, deviceId)) {
|
||||
throw new IllegalStateException(String.format("No session for (%d, %d)!", recipientId, deviceId));
|
||||
}
|
||||
|
||||
SessionRecord record = sessionStore.loadSession(recipientId, deviceId);
|
||||
return record.getSessionState().getSessionVersion();
|
||||
}
|
||||
}
|
||||
|
||||
private ChainKey getOrCreateChainKey(SessionState sessionState, ECPublicKey theirEphemeral)
|
||||
throws InvalidMessageException
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.whispersystems.textsecure.api.crypto;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.whispersystems.libaxolotl.DuplicateMessageException;
|
||||
@ -30,18 +32,14 @@ import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageCo
|
||||
|
||||
public class TextSecureCipher {
|
||||
|
||||
private final SessionCipher sessionCipher;
|
||||
private final PushTransportDetails transportDetails;
|
||||
private final SessionCipher sessionCipher;
|
||||
|
||||
public TextSecureCipher(AxolotlStore axolotlStore, long recipientId, int deviceId) {
|
||||
int sessionVersion = axolotlStore.loadSession(recipientId, deviceId)
|
||||
.getSessionState().getSessionVersion();
|
||||
|
||||
this.transportDetails = new PushTransportDetails(sessionVersion);
|
||||
this.sessionCipher = new SessionCipher(axolotlStore, recipientId, deviceId);
|
||||
this.sessionCipher = new SessionCipher(axolotlStore, recipientId, deviceId);
|
||||
}
|
||||
|
||||
public CiphertextMessage encrypt(byte[] unpaddedMessage) {
|
||||
PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
|
||||
return sessionCipher.encrypt(transportDetails.getPaddedMessageBody(unpaddedMessage));
|
||||
}
|
||||
|
||||
@ -63,7 +61,9 @@ public class TextSecureCipher {
|
||||
throw new InvalidMessageException("Unknown type: " + envelope.getType());
|
||||
}
|
||||
|
||||
PushMessageContent content = PushMessageContent.parseFrom(transportDetails.getStrippedPaddingMessageBody(paddedMessage));
|
||||
PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
|
||||
PushMessageContent content = PushMessageContent.parseFrom(transportDetails.getStrippedPaddingMessageBody(paddedMessage));
|
||||
|
||||
return createTextSecureMessage(envelope, content);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
|
@ -27,11 +27,16 @@ public class TextSecureMessage {
|
||||
|
||||
public TextSecureMessage(long timestamp, TextSecureGroup group, List<TextSecureAttachment> attachments, String body, boolean secure, boolean endSession) {
|
||||
this.timestamp = timestamp;
|
||||
this.attachments = Optional.fromNullable(attachments);
|
||||
this.body = Optional.fromNullable(body);
|
||||
this.group = Optional.fromNullable(group);
|
||||
this.secure = secure;
|
||||
this.endSession = endSession;
|
||||
|
||||
if (attachments != null && !attachments.isEmpty()) {
|
||||
this.attachments = Optional.of(attachments);
|
||||
} else {
|
||||
this.attachments = Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
|
@ -101,6 +101,10 @@ public class PushDecryptJob extends MasterSecretJob {
|
||||
else if (message.isGroupUpdate()) handleGroupMessage(masterSecret, envelope, message);
|
||||
else if (message.getAttachments().isPresent()) handleMediaMessage(masterSecret, envelope, message);
|
||||
else handleTextMessage(masterSecret, envelope, message);
|
||||
|
||||
if (envelope.isPreKeyWhisperMessage()) {
|
||||
ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
|
||||
}
|
||||
} catch (InvalidVersionException e) {
|
||||
Log.w(TAG, e);
|
||||
handleInvalidVersionMessage(masterSecret, envelope);
|
||||
|
@ -2,15 +2,16 @@ package org.thoughtcrime.securesms.push;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
||||
|
||||
public class SecurityEventListener implements TextSecureMessageSender.EventListener {
|
||||
|
||||
private static final String TAG = SecurityEventListener.class.getSimpleName();
|
||||
|
||||
private final Context context;
|
||||
|
||||
public SecurityEventListener(Context context) {
|
||||
@ -23,10 +24,6 @@ public class SecurityEventListener implements TextSecureMessageSender.EventListe
|
||||
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
|
||||
|
||||
SecurityEvent.broadcastSecurityUpdateEvent(context, threadId);
|
||||
|
||||
ApplicationContext.getInstance(context)
|
||||
.getJobManager()
|
||||
.add(new RefreshPreKeysJob(context));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user