diff --git a/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeManagerImpl.java b/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeManagerImpl.java index 01d7803d9..c006a2432 100644 --- a/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeManagerImpl.java +++ b/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeManagerImpl.java @@ -14,6 +14,7 @@ import org.briarproject.bramble.api.data.MetadataParser; import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.Transaction; +import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.lifecycle.LifecycleManager; import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.GroupId; @@ -124,6 +125,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl // message.getGroupId turn into contactid // txn.attach event } else if (type == WIPE) { + if (!remoteWipeIsSetup(txn)) return false; ContactId contactId = getContactId(txn, m.getGroupId()); // Check if contact is in list of wipers if (findMessage(txn, m.getGroupId(), SETUP, true) != null) { @@ -170,7 +172,10 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl public void setup(Transaction txn, List wipers) throws DbException, FormatException { - // TODO if (we already have a set of wipers?) do something + // If we already have a set of wipers do nothing + // TODO revoke existing wipers + if (remoteWipeIsSetup(txn)) throw new FormatException(); + if (wipers.size() < 2) throw new FormatException(); BdfList wipersMetadata = new BdfList(); @@ -388,4 +393,30 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl results.entrySet().iterator().next(); return new Pair<>(e.getKey(), e.getValue()); } + + @Override + public boolean remoteWipeIsSetup(Transaction txn) { + try { + return !db.getGroupMetadata(txn, localGroup.getId()).isEmpty(); + } catch (DbException e) { + return false; + } + } + + public List getWipers(Transaction txn) throws DbException { + try { + BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn, + localGroup.getId()); + BdfList bdfWipers = meta.getList(GROUP_KEY_WIPERS); + + List wipers = new ArrayList<>(bdfWipers.size()); + for (int i = 0; i < bdfWipers.size(); i++) { + BdfList author = bdfWipers.getList(i); + wipers.add(clientHelper.parseAndValidateAuthor(author)); + } + return wipers; + } catch (FormatException e) { + throw new DbException(e); + } + } } diff --git a/briar-core/src/main/java/org/briarproject/briar/socialbackup/SocialBackupManagerImpl.java b/briar-core/src/main/java/org/briarproject/briar/socialbackup/SocialBackupManagerImpl.java index 0709cd75f..e249edbc2 100644 --- a/briar-core/src/main/java/org/briarproject/briar/socialbackup/SocialBackupManagerImpl.java +++ b/briar-core/src/main/java/org/briarproject/briar/socialbackup/SocialBackupManagerImpl.java @@ -261,6 +261,7 @@ class SocialBackupManagerImpl extends ConversationClientImpl try { BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn, localGroup.getId()); + return backupMetadataParser.parseBackupMetadata(meta); } catch (FormatException e) { throw new DbException(e); diff --git a/briar-core/src/test/java/org/briarproject/briar/remotewipe/RemoteWipeIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/remotewipe/RemoteWipeIntegrationTest.java index 9a763ebe8..7b6898814 100644 --- a/briar-core/src/test/java/org/briarproject/briar/remotewipe/RemoteWipeIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/remotewipe/RemoteWipeIntegrationTest.java @@ -74,16 +74,16 @@ public class RemoteWipeIntegrationTest extends BriarIntegrationTest { - // TODO assert that we do not already have a wipe setup -// assertNull(socialBackupManager0.getBackupMetadata(txn)); + // Assert that we do not already have a wipe setup + assertFalse(remoteWipeManager0.remoteWipeIsSetup(txn)); remoteWipeManager0.setup(txn, asList(contactId1From0, contactId2From0)); - // TODO now check that we do have a wipe setup + // Now check that we do have a wipe setup + assertTrue(remoteWipeManager0.remoteWipeIsSetup(txn)); }); // Sync the setup messages to the contacts sync0To1(1, true);