mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-21 22:02:06 +01:00
[omemo] Add OmemoManager.purgeEveryting()
This is basically the already existing method from OmemoManagerSetupHelper.cleanUpPubSub() moved over into OmemoManager as purgeEverything().
This commit is contained in:
parent
3fde4830e4
commit
4120b42761
3 changed files with 54 additions and 46 deletions
|
@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||
|
@ -63,7 +64,7 @@ public abstract class AbstractTwoUsersOmemoIntegrationTest extends AbstractOmemo
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
public void cleanUp() throws IOException {
|
||||
public void cleanUp() throws IOException, NotConnectedException, InterruptedException {
|
||||
alice.stopStanzaAndPEPListeners();
|
||||
bob.stopStanzaAndPEPListeners();
|
||||
OmemoManagerSetupHelper.cleanUpPubSub(alice);
|
||||
|
|
|
@ -22,8 +22,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.roster.Roster;
|
||||
|
@ -31,12 +33,9 @@ import org.jivesoftware.smack.roster.RosterEntry;
|
|||
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException;
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList;
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||
import org.jivesoftware.smackx.omemo.util.OmemoConstants;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubException;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
@ -124,48 +123,10 @@ public class OmemoManagerSetupHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void cleanUpPubSub(OmemoManager omemoManager) throws IOException {
|
||||
PubSubManager pm = PubSubManager.getInstanceFor(omemoManager.getConnection(), omemoManager.getOwnJid());
|
||||
try {
|
||||
omemoManager.requestDeviceListUpdateFor(omemoManager.getOwnJid());
|
||||
} catch (SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException | PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
OmemoCachedDeviceList deviceList = OmemoService.getInstance().getOmemoStoreBackend()
|
||||
.loadCachedDeviceList(omemoManager.getOwnDevice(), omemoManager.getOwnJid());
|
||||
|
||||
for (int id : deviceList.getAllDevices()) {
|
||||
try {
|
||||
pm.getLeafNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)).deleteAllItems();
|
||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException |
|
||||
PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException |
|
||||
PubSubException.NotAPubSubNodeException e) {
|
||||
// Silent
|
||||
}
|
||||
|
||||
try {
|
||||
pm.deleteNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id));
|
||||
} catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException
|
||||
| XMPPException.XMPPErrorException e) {
|
||||
// Silent
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
pm.getLeafNode(OmemoConstants.PEP_NODE_DEVICE_LIST).deleteAllItems();
|
||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException |
|
||||
PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException |
|
||||
PubSubException.NotAPubSubNodeException e) {
|
||||
// Silent
|
||||
}
|
||||
|
||||
try {
|
||||
pm.deleteNode(OmemoConstants.PEP_NODE_DEVICE_LIST);
|
||||
} catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException |
|
||||
XMPPException.XMPPErrorException e) {
|
||||
// Silent
|
||||
}
|
||||
public static void cleanUpPubSub(OmemoManager omemoManager)
|
||||
throws IOException, NotConnectedException, InterruptedException {
|
||||
List<Exception> exceptions = omemoManager.purgeEverything();
|
||||
assertTrue(exceptions.isEmpty(), "There where exceptions while purging OMEMO: " + exceptions);
|
||||
}
|
||||
|
||||
public static void cleanUpRoster(OmemoManager omemoManager) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.logging.Logger;
|
|||
import org.jivesoftware.smack.ConnectionListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
@ -73,6 +74,7 @@ import org.jivesoftware.smackx.omemo.util.OmemoConstants;
|
|||
import org.jivesoftware.smackx.pep.PepEventListener;
|
||||
import org.jivesoftware.smackx.pep.PepManager;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubException;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
@ -727,6 +729,50 @@ public final class OmemoManager extends Manager {
|
|||
getOmemoService().purgeDeviceList(new LoggedInOmemoManager(this));
|
||||
}
|
||||
|
||||
public List<Exception> purgeEverything() throws NotConnectedException, InterruptedException, IOException {
|
||||
List<Exception> exceptions = new ArrayList<>(5);
|
||||
PubSubManager pm = PubSubManager.getInstanceFor(getConnection(), getOwnJid());
|
||||
try {
|
||||
requestDeviceListUpdateFor(getOwnJid());
|
||||
} catch (SmackException.NoResponseException | PubSubException.NotALeafNodeException
|
||||
| XMPPException.XMPPErrorException e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
|
||||
OmemoCachedDeviceList deviceList = OmemoService.getInstance().getOmemoStoreBackend()
|
||||
.loadCachedDeviceList(getOwnDevice(), getOwnJid());
|
||||
|
||||
for (int id : deviceList.getAllDevices()) {
|
||||
try {
|
||||
pm.getLeafNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)).deleteAllItems();
|
||||
} catch (SmackException.NoResponseException | PubSubException.NotALeafNodeException
|
||||
| XMPPException.XMPPErrorException | PubSubException.NotAPubSubNodeException e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
|
||||
try {
|
||||
pm.deleteNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id));
|
||||
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
pm.getLeafNode(OmemoConstants.PEP_NODE_DEVICE_LIST).deleteAllItems();
|
||||
} catch (SmackException.NoResponseException | PubSubException.NotALeafNodeException
|
||||
| XMPPException.XMPPErrorException | PubSubException.NotAPubSubNodeException e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
|
||||
try {
|
||||
pm.deleteNode(OmemoConstants.PEP_NODE_DEVICE_LIST);
|
||||
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the signedPreKey published in our OmemoBundle and republish it. This should be done every now and
|
||||
* then (7-14 days). The old signedPreKey should be kept for some more time (a month or so) to enable decryption
|
||||
|
|
Loading…
Reference in a new issue