mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Dont accept shards from mismatched sets - all muss match the first shard received
This commit is contained in:
@@ -13,6 +13,7 @@ import org.briarproject.briar.android.activity.ActivityComponent;
|
|||||||
import org.briarproject.briar.android.activity.BaseActivity;
|
import org.briarproject.briar.android.activity.BaseActivity;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
||||||
|
import org.briarproject.briar.api.socialbackup.recovery.RestoreAccount;
|
||||||
import org.briarproject.briar.api.socialbackup.recovery.SecretOwnerTask;
|
import org.briarproject.briar.api.socialbackup.recovery.SecretOwnerTask;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
@@ -146,9 +147,16 @@ public class OwnerReturnShardActivity extends BaseActivity
|
|||||||
if (state instanceof SecretOwnerTask.State.Success) {
|
if (state instanceof SecretOwnerTask.State.Success) {
|
||||||
ReturnShardPayload shardPayload =
|
ReturnShardPayload shardPayload =
|
||||||
((SecretOwnerTask.State.Success) state).getRemotePayload();
|
((SecretOwnerTask.State.Success) state).getRemotePayload();
|
||||||
boolean added = viewModel.addToShardSet(shardPayload);
|
RestoreAccount.AddReturnShardPayloadResult result = viewModel.addToShardSet(shardPayload);
|
||||||
|
if (result == RestoreAccount.AddReturnShardPayloadResult.MISMATCH) {
|
||||||
|
// TODO improve this
|
||||||
|
Toast.makeText(this,
|
||||||
|
"WARNING: Mismatched backup piece!",
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
boolean added = (result != RestoreAccount.AddReturnShardPayloadResult.DUPLICATE) ? true : false;
|
||||||
Toast.makeText(this,
|
Toast.makeText(this,
|
||||||
"Success - got shard" + (added ? "" : " duplicate"),
|
"Success - got backup piece" + (added ? "" : " duplicate"),
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
if (added && viewModel.canRecover()) {
|
if (added && viewModel.canRecover()) {
|
||||||
LOG.info("Secret key recovered");
|
LOG.info("Secret key recovered");
|
||||||
@@ -173,19 +181,10 @@ public class OwnerReturnShardActivity extends BaseActivity
|
|||||||
}
|
}
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
} else if (state instanceof SecretOwnerTask.State.Failure) {
|
} else if (state instanceof SecretOwnerTask.State.Failure) {
|
||||||
// Toast.makeText(this,
|
|
||||||
// "Shard return failed!",
|
|
||||||
// Toast.LENGTH_SHORT).show();
|
|
||||||
// onBackPressed();
|
|
||||||
showNextFragment(new OwnerRecoveryModeErrorFragment());
|
showNextFragment(new OwnerRecoveryModeErrorFragment());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void showErrorFragment() {
|
|
||||||
// // TODO change this for an appropriate error message fragment
|
|
||||||
// showNextFragment(new AddNearbyContactErrorFragment());
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void runOnDbThread(Runnable runnable) {
|
public void runOnDbThread(Runnable runnable) {
|
||||||
|
|||||||
@@ -226,8 +226,7 @@ class OwnerReturnShardViewModel extends AndroidViewModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO figure out how to actually use a hash set for these objects
|
public RestoreAccount.AddReturnShardPayloadResult addToShardSet(ReturnShardPayload toAdd) {
|
||||||
public boolean addToShardSet(ReturnShardPayload toAdd) {
|
|
||||||
return restoreAccount.addReturnShardPayload(toAdd);
|
return restoreAccount.addReturnShardPayload(toAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,15 @@ import java.security.GeneralSecurityException;
|
|||||||
|
|
||||||
public interface RestoreAccount {
|
public interface RestoreAccount {
|
||||||
|
|
||||||
|
enum AddReturnShardPayloadResult {
|
||||||
|
DUPLICATE,
|
||||||
|
MISMATCH,
|
||||||
|
OK
|
||||||
|
}
|
||||||
|
|
||||||
int getNumberOfShards();
|
int getNumberOfShards();
|
||||||
|
|
||||||
boolean addReturnShardPayload(ReturnShardPayload toAdd);
|
AddReturnShardPayloadResult addReturnShardPayload(ReturnShardPayload toAdd);
|
||||||
|
|
||||||
boolean canRecover();
|
boolean canRecover();
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.briarproject.briar.socialbackup.BackupPayloadDecoder;
|
|||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ public class RestoreAccountImpl implements RestoreAccount {
|
|||||||
private SecretKey secretKey;
|
private SecretKey secretKey;
|
||||||
private final BackupPayloadDecoder backupPayloadDecoder;
|
private final BackupPayloadDecoder backupPayloadDecoder;
|
||||||
private SocialBackup socialBackup;
|
private SocialBackup socialBackup;
|
||||||
|
private byte[] secretId;
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(RestoreAccountImpl.class.getName());
|
getLogger(RestoreAccountImpl.class.getName());
|
||||||
@@ -59,24 +61,30 @@ public class RestoreAccountImpl implements RestoreAccount {
|
|||||||
return recoveredShards.size();
|
return recoveredShards.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO figure out how to actually use a hash set for these objects
|
public AddReturnShardPayloadResult addReturnShardPayload(ReturnShardPayload toAdd) {
|
||||||
public boolean addReturnShardPayload(ReturnShardPayload toAdd) {
|
AddReturnShardPayloadResult result = AddReturnShardPayloadResult.OK;
|
||||||
boolean found = false;
|
// TODO figure out how to actually use a hash set for these objects
|
||||||
for (ReturnShardPayload returnShardPayload : recoveredShards) {
|
for (ReturnShardPayload returnShardPayload : recoveredShards) {
|
||||||
if (toAdd.equals(returnShardPayload)) {
|
if (toAdd.equals(returnShardPayload)) {
|
||||||
found = true;
|
return AddReturnShardPayloadResult.DUPLICATE;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) recoveredShards.add(toAdd);
|
|
||||||
return !found;
|
if (secretId == null) secretId = toAdd.getShard().getSecretId();
|
||||||
|
if (!Arrays.equals(secretId, toAdd.getShard().getSecretId())) {
|
||||||
|
return AddReturnShardPayloadResult.MISMATCH;
|
||||||
|
}
|
||||||
|
recoveredShards.add(toAdd);
|
||||||
|
return AddReturnShardPayloadResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canRecover() {
|
public boolean canRecover() {
|
||||||
ArrayList<Shard> shards = new ArrayList<>();
|
ArrayList<Shard> shards = new ArrayList<>();
|
||||||
for (ReturnShardPayload returnShardPayload : recoveredShards) {
|
for (ReturnShardPayload returnShardPayload : recoveredShards) {
|
||||||
// TODO check shards all have same secret id
|
// TODO check shards all have same secret id
|
||||||
shards.add(returnShardPayload.getShard());
|
Shard shard = returnShardPayload.getShard();
|
||||||
|
// shard.getSecretId();
|
||||||
|
shards.add(shard);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
secretKey = darkCrystal.combineShards(shards);
|
secretKey = darkCrystal.combineShards(shards);
|
||||||
|
|||||||
Reference in New Issue
Block a user