Merge branch 'social-backup-poc' of https://code.briarproject.org/briar/briar into social-backup-poc

* 'social-backup-poc' of https://code.briarproject.org/briar/briar:
  add combine shards stub
This commit is contained in:
ameba23
2021-02-24 15:44:39 +01:00
2 changed files with 19 additions and 0 deletions

View File

@@ -4,10 +4,12 @@ import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.socialbackup.Shard;
import java.security.GeneralSecurityException;
import java.util.List;
@NotNullByDefault
interface DarkCrystal {
List<Shard> createShards(SecretKey secret, int shards, int threshold);
SecretKey combineShards(List<Shard> shards) throws GeneralSecurityException;
}

View File

@@ -4,7 +4,9 @@ import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.socialbackup.Shard;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
@@ -33,4 +35,19 @@ class DarkCrystalStub implements DarkCrystal {
}
return shards;
}
@Override
public SecretKey combineShards(List<Shard> shards) throws
GeneralSecurityException {
// Check each shard has the same secret Id
byte[] secretId = shards.get(0).getSecretId();
for (Shard shard : shards) {
if (!Arrays.equals(shard.getSecretId(), secretId)) throw new GeneralSecurityException();
}
Random random = new Random();
byte[] secretBytes = new byte[SecretKey.LENGTH];
random.nextBytes(secretId);
return new SecretKey(secretBytes);
}
}