mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user