mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
Ignore stale devices when encrypting
This commit is contained in:
parent
7bff6e7d99
commit
e5cdd89edc
2 changed files with 57 additions and 1 deletions
|
@ -53,6 +53,7 @@ import org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionExcep
|
||||||
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
||||||
import org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException;
|
import org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException;
|
||||||
import org.jivesoftware.smackx.omemo.exceptions.NoIdentityKeyException;
|
import org.jivesoftware.smackx.omemo.exceptions.NoIdentityKeyException;
|
||||||
|
import org.jivesoftware.smackx.omemo.exceptions.StaleDeviceException;
|
||||||
import org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException;
|
import org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException;
|
||||||
import org.jivesoftware.smackx.omemo.exceptions.UntrustedOmemoIdentityException;
|
import org.jivesoftware.smackx.omemo.exceptions.UntrustedOmemoIdentityException;
|
||||||
import org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList;
|
import org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList;
|
||||||
|
@ -384,6 +385,19 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore stale devices
|
||||||
|
if (OmemoConfiguration.getIgnoreStaleDevices()) {
|
||||||
|
|
||||||
|
Date lastActivity = getOmemoStoreBackend().getDateOfLastReceivedMessage(userDevice, contactsDevice);
|
||||||
|
|
||||||
|
if (isStale(userDevice, contactsDevice, lastActivity, OmemoConfiguration.getIgnoreStaleDevicesAfterHours())) {
|
||||||
|
LOGGER.log(Level.FINE, "Device " + contactsDevice + " seems to be stale (last message received "
|
||||||
|
+ lastActivity + "). Ignore it.");
|
||||||
|
skippedRecipients.put(contactsDevice, new StaleDeviceException(contactsDevice, lastActivity));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add recipients
|
// Add recipients
|
||||||
try {
|
try {
|
||||||
builder.addRecipient(contactsDevice);
|
builder.addRecipient(contactsDevice);
|
||||||
|
@ -393,7 +407,8 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
||||||
skippedRecipients.put(contactsDevice, e);
|
skippedRecipients.put(contactsDevice, e);
|
||||||
}
|
}
|
||||||
catch (UndecidedOmemoIdentityException e) {
|
catch (UndecidedOmemoIdentityException e) {
|
||||||
throw new AssertionError("At this point, devices cannot be undecided. " + e);
|
throw new AssertionError("Recipients device seems to be undecided, even though we should have thrown" +
|
||||||
|
" an exception earlier in that case. " + e);
|
||||||
}
|
}
|
||||||
catch (UntrustedOmemoIdentityException e) {
|
catch (UntrustedOmemoIdentityException e) {
|
||||||
LOGGER.log(Level.WARNING, "Device " + contactsDevice + " is untrusted. Message is not encrypted for it.");
|
LOGGER.log(Level.WARNING, "Device " + contactsDevice + " is untrusted. Message is not encrypted for it.");
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2018 Paul Schaub
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.omemo.exceptions;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||||
|
|
||||||
|
public class StaleDeviceException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private final OmemoDevice device;
|
||||||
|
private final Date lastActivity;
|
||||||
|
|
||||||
|
public StaleDeviceException(OmemoDevice device, Date lastActivity) {
|
||||||
|
this.device = device;
|
||||||
|
this.lastActivity = lastActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastActivity() {
|
||||||
|
return lastActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OmemoDevice getDevice() {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue