Add hint that messages must be regularly received

This commit is contained in:
AsamK 2021-05-24 12:14:44 +02:00
parent 2a0bba62be
commit cfc818872f
4 changed files with 31 additions and 1 deletions

View file

@ -57,6 +57,8 @@ Important: The USERNAME is your phone number in international format and must in
signal-cli -u USERNAME receive signal-cli -u USERNAME receive
**Hint**: The Signal protocol expects that incoming messages are regularly received (using `daemon` or `receive` command).
This is required for the encryption to work efficiently and for getting updates to groups, expiration timer and other features.
## Storage ## Storage

View file

@ -330,6 +330,17 @@ public class Manager implements Closeable {
} }
public void checkAccountState() throws IOException { public void checkAccountState() throws IOException {
if (account.getLastReceiveTimestamp() == 0) {
logger.warn("The Signal protocol expects that incoming messages are regularly received.");
} else {
var diffInMilliseconds = new Date().getTime() - account.getLastReceiveTimestamp();
long days = TimeUnit.DAYS.convert(diffInMilliseconds, TimeUnit.MILLISECONDS);
if (days > 7) {
logger.warn(
"Messages have been last received {} days ago. The Signal protocol expects that incoming messages are regularly received.",
days);
}
}
if (accountManager.getPreKeysCount() < ServiceConfig.PREKEY_MINIMUM_COUNT) { if (accountManager.getPreKeysCount() < ServiceConfig.PREKEY_MINIMUM_COUNT) {
refreshPreKeys(); refreshPreKeys();
} }
@ -1982,6 +1993,7 @@ public class Manager implements Closeable {
SignalServiceContent content = null; SignalServiceContent content = null;
Exception exception = null; Exception exception = null;
final CachedMessage[] cachedMessage = {null}; final CachedMessage[] cachedMessage = {null};
account.setLastReceiveTimestamp(new Date().getTime());
try { try {
var result = messagePipe.readOrEmpty(timeout, unit, envelope1 -> { var result = messagePipe.readOrEmpty(timeout, unit, envelope1 -> {
final var recipientId = envelope1.hasSource() final var recipientId = envelope1.hasSource()

View file

@ -84,6 +84,7 @@ public class SignalAccount implements Closeable {
private ProfileKey profileKey; private ProfileKey profileKey;
private int preKeyIdOffset; private int preKeyIdOffset;
private int nextSignedPreKeyId; private int nextSignedPreKeyId;
private long lastReceiveTimestamp = 0;
private boolean registered = false; private boolean registered = false;
@ -261,6 +262,7 @@ public class SignalAccount implements Closeable {
this.deviceId = deviceId; this.deviceId = deviceId;
this.registered = true; this.registered = true;
this.isMultiDevice = true; this.isMultiDevice = true;
this.lastReceiveTimestamp = 0;
} }
private void migrateLegacyConfigs() { private void migrateLegacyConfigs() {
@ -368,6 +370,9 @@ public class SignalAccount implements Closeable {
if (rootNode.hasNonNull("isMultiDevice")) { if (rootNode.hasNonNull("isMultiDevice")) {
isMultiDevice = rootNode.get("isMultiDevice").asBoolean(); isMultiDevice = rootNode.get("isMultiDevice").asBoolean();
} }
if (rootNode.hasNonNull("lastReceiveTimestamp")) {
lastReceiveTimestamp = rootNode.get("lastReceiveTimestamp").asLong();
}
int registrationId = 0; int registrationId = 0;
if (rootNode.hasNonNull("registrationId")) { if (rootNode.hasNonNull("registrationId")) {
registrationId = rootNode.get("registrationId").asInt(); registrationId = rootNode.get("registrationId").asInt();
@ -637,6 +642,7 @@ public class SignalAccount implements Closeable {
.put("deviceName", encryptedDeviceName) .put("deviceName", encryptedDeviceName)
.put("deviceId", deviceId) .put("deviceId", deviceId)
.put("isMultiDevice", isMultiDevice) .put("isMultiDevice", isMultiDevice)
.put("lastReceiveTimestamp", lastReceiveTimestamp)
.put("password", password) .put("password", password)
.put("registrationId", identityKeyStore.getLocalRegistrationId()) .put("registrationId", identityKeyStore.getLocalRegistrationId())
.put("identityPrivateKey", .put("identityPrivateKey",
@ -870,6 +876,15 @@ public class SignalAccount implements Closeable {
save(); save();
} }
public long getLastReceiveTimestamp() {
return lastReceiveTimestamp;
}
public void setLastReceiveTimestamp(final long lastReceiveTimestamp) {
this.lastReceiveTimestamp = lastReceiveTimestamp;
save();
}
public boolean isUnrestrictedUnidentifiedAccess() { public boolean isUnrestrictedUnidentifiedAccess() {
// TODO make configurable // TODO make configurable
return false; return false;
@ -893,6 +908,7 @@ public class SignalAccount implements Closeable {
this.registered = true; this.registered = true;
this.uuid = uuid; this.uuid = uuid;
this.registrationLockPin = pin; this.registrationLockPin = pin;
this.lastReceiveTimestamp = 0;
save(); save();
getSessionStore().archiveAllSessions(); getSessionStore().archiveAllSessions();

View file

@ -14,7 +14,7 @@ public class DateUtils {
public static String formatTimestamp(long timestamp) { public static String formatTimestamp(long timestamp) {
var date = new Date(timestamp); var date = new Date(timestamp);
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); // Quoted "Z" to indicate UTC, no timezone offset final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
df.setTimeZone(tzUTC); df.setTimeZone(tzUTC);
return timestamp + " (" + df.format(date) + ")"; return timestamp + " (" + df.format(date) + ")";
} }