From 0c4ad98839dd2a39e7d0697cc965a006be1c341b Mon Sep 17 00:00:00 2001 From: ameba23 Date: Mon, 30 Aug 2021 12:19:37 +0200 Subject: [PATCH] Validate revoke messages --- .../briar/remotewipe/RemoteWipeManagerImpl.java | 2 +- .../briar/remotewipe/RemoteWipeValidator.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 d6b9727c0..18f34f004 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 @@ -297,7 +297,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl public void wipe(Transaction txn, Contact contact) throws DbException, FormatException { - // Check that we have a SETUP message from contact + // Check that we have wiper status if (!amWiper(txn, contact.getId())) throw new DbException(); Group group = getContactGroup(contact); diff --git a/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeValidator.java b/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeValidator.java index 761991a21..91d9e487e 100644 --- a/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeValidator.java +++ b/briar-core/src/main/java/org/briarproject/briar/remotewipe/RemoteWipeValidator.java @@ -17,6 +17,7 @@ import javax.annotation.concurrent.Immutable; import javax.inject.Inject; import static org.briarproject.bramble.util.ValidationUtils.checkSize; +import static org.briarproject.briar.api.remotewipe.MessageType.REVOKE; import static org.briarproject.briar.api.remotewipe.MessageType.SETUP; import static org.briarproject.briar.api.remotewipe.MessageType.WIPE; import static org.briarproject.briar.socialbackup.SocialBackupConstants.MSG_KEY_LOCAL; @@ -40,6 +41,7 @@ class RemoteWipeValidator extends BdfMessageValidator { .fromValue(body.getLong(0).intValue()); if (type == SETUP) return validateSetupMessage(body); else if (type == WIPE) return validateWipeMessage(body); + else if (type == REVOKE) return validateRevokeMessage(body); else throw new AssertionError(); } @@ -60,4 +62,13 @@ class RemoteWipeValidator extends BdfMessageValidator { new BdfEntry(MSG_KEY_LOCAL, false)); return new BdfMessageContext(meta); } + + private BdfMessageContext validateRevokeMessage(BdfList body) + throws FormatException { + checkSize(body, 1); + BdfDictionary meta = BdfDictionary.of( + new BdfEntry(MSG_KEY_MESSAGE_TYPE, REVOKE.getValue()), + new BdfEntry(MSG_KEY_LOCAL, false)); + return new BdfMessageContext(meta); + } }