mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch 'social-backup-poc' into remote-wipe-poc
* social-backup-poc: Dont accept shards from mismatched sets - all muss match the first shard received Change wording on shard notification messages Change message on success fragments
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.fragment.BaseFragment;
|
||||
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.RestoreAccount;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.SecretOwnerTask;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
@@ -146,9 +147,16 @@ public class OwnerReturnShardActivity extends BaseActivity
|
||||
if (state instanceof SecretOwnerTask.State.Success) {
|
||||
ReturnShardPayload shardPayload =
|
||||
((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,
|
||||
"Success - got shard" + (added ? "" : " duplicate"),
|
||||
"Success - got backup piece" + (added ? "" : " duplicate"),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
if (added && viewModel.canRecover()) {
|
||||
LOG.info("Secret key recovered");
|
||||
@@ -173,19 +181,10 @@ public class OwnerReturnShardActivity extends BaseActivity
|
||||
}
|
||||
onBackPressed();
|
||||
} else if (state instanceof SecretOwnerTask.State.Failure) {
|
||||
// Toast.makeText(this,
|
||||
// "Shard return failed!",
|
||||
// Toast.LENGTH_SHORT).show();
|
||||
// onBackPressed();
|
||||
showNextFragment(new OwnerRecoveryModeErrorFragment());
|
||||
}
|
||||
}
|
||||
|
||||
// private void showErrorFragment() {
|
||||
// // TODO change this for an appropriate error message fragment
|
||||
// showNextFragment(new AddNearbyContactErrorFragment());
|
||||
// }
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
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 boolean addToShardSet(ReturnShardPayload toAdd) {
|
||||
public RestoreAccount.AddReturnShardPayloadResult addToShardSet(ReturnShardPayload toAdd) {
|
||||
return restoreAccount.addReturnShardPayload(toAdd);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="@string/backup_done_dismiss"
|
||||
android:text="@string/ok"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="@string/backup_done_dismiss"
|
||||
android:text="@string/ok"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="@string/backup_done_dismiss"
|
||||
android:text="@string/ok"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="@string/backup_done_dismiss"
|
||||
android:text="@string/ok"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
@@ -669,7 +669,6 @@
|
||||
<string name="threshold_m_of_n">%d of %d contacts needed to recover your account</string>
|
||||
|
||||
<string name="backup_done_info">Backup pieces sent to trusted contacts</string>
|
||||
<string name="backup_done_dismiss">Got it</string>
|
||||
|
||||
<string name="backup_created">Backup created 1/6/2020</string>
|
||||
|
||||
@@ -723,8 +722,8 @@
|
||||
<string name="activity_name_restore_account">Restore Account</string>
|
||||
|
||||
<!-- conversation -->
|
||||
<string name="social_backup_shard_received">%1$s has sent you a social backup shard.</string>
|
||||
<string name="social_backup_shard_sent">You have sent a social backup shard to %1$s.</string>
|
||||
<string name="social_backup_shard_received">%1$s has sent you a social backup piece.</string>
|
||||
<string name="social_backup_shard_sent">You have sent a social backup piece to %1$s.</string>
|
||||
|
||||
<string name="activity_name_new_or_recover_account">Create new account or recover existing account</string>
|
||||
<string name="activity_name_recovery">Recover Account</string>
|
||||
|
||||
@@ -9,10 +9,15 @@ import java.security.GeneralSecurityException;
|
||||
|
||||
public interface RestoreAccount {
|
||||
|
||||
enum AddReturnShardPayloadResult {
|
||||
DUPLICATE,
|
||||
MISMATCH,
|
||||
OK
|
||||
}
|
||||
|
||||
int getNumberOfShards();
|
||||
|
||||
boolean addReturnShardPayload(ReturnShardPayload toAdd);
|
||||
AddReturnShardPayloadResult addReturnShardPayload(ReturnShardPayload toAdd);
|
||||
|
||||
boolean canRecover();
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.briarproject.briar.socialbackup.BackupPayloadDecoder;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -37,6 +38,7 @@ public class RestoreAccountImpl implements RestoreAccount {
|
||||
private SecretKey secretKey;
|
||||
private final BackupPayloadDecoder backupPayloadDecoder;
|
||||
private SocialBackup socialBackup;
|
||||
private byte[] secretId;
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(RestoreAccountImpl.class.getName());
|
||||
@@ -59,24 +61,30 @@ public class RestoreAccountImpl implements RestoreAccount {
|
||||
return recoveredShards.size();
|
||||
}
|
||||
|
||||
// TODO figure out how to actually use a hash set for these objects
|
||||
public boolean addReturnShardPayload(ReturnShardPayload toAdd) {
|
||||
boolean found = false;
|
||||
public AddReturnShardPayloadResult addReturnShardPayload(ReturnShardPayload toAdd) {
|
||||
AddReturnShardPayloadResult result = AddReturnShardPayloadResult.OK;
|
||||
// TODO figure out how to actually use a hash set for these objects
|
||||
for (ReturnShardPayload returnShardPayload : recoveredShards) {
|
||||
if (toAdd.equals(returnShardPayload)) {
|
||||
found = true;
|
||||
break;
|
||||
return AddReturnShardPayloadResult.DUPLICATE;
|
||||
}
|
||||
}
|
||||
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() {
|
||||
ArrayList<Shard> shards = new ArrayList<>();
|
||||
for (ReturnShardPayload returnShardPayload : recoveredShards) {
|
||||
// TODO check shards all have same secret id
|
||||
shards.add(returnShardPayload.getShard());
|
||||
Shard shard = returnShardPayload.getShard();
|
||||
// shard.getSecretId();
|
||||
shards.add(shard);
|
||||
}
|
||||
try {
|
||||
secretKey = darkCrystal.combineShards(shards);
|
||||
|
||||
Reference in New Issue
Block a user