session-android/src/org/thoughtcrime/securesms/sms/MultipartSmsIdentifier.java
Moxie Marlinspike 7d07d56fc3 Fix for 'bad encrypted message' errors.
1) There was a regression in the outgoing multipart transport
   logic, such that the same 'identifier' byte would be used
   for all messages (0).  This now works correctly.

2) Added some additional heuristics on the receiving side.
   Now mutlipart containers are only valid for 1hr, and are
   considered invalid if the container size is different from
   the multipart message size.
2013-07-22 15:04:31 -07:00

32 lines
711 B
Java

package org.thoughtcrime.securesms.sms;
import java.util.HashMap;
public class MultipartSmsIdentifier {
private static final MultipartSmsIdentifier instance = new MultipartSmsIdentifier();
public static MultipartSmsIdentifier getInstance() {
return instance;
}
private final HashMap<String, Integer> idMap = new HashMap<String, Integer>();
public synchronized byte getIdForRecipient(String recipient) {
Integer currentId;
if (idMap.containsKey(recipient)) {
currentId = idMap.get(recipient);
idMap.remove(recipient);
} else {
currentId = 0;
}
byte id = currentId.byteValue();
idMap.put(recipient, (currentId + 1) % 255);
return id;
}
}