Initial implementation of social backup client.

This commit is contained in:
akwizgran
2021-02-23 15:48:19 +00:00
parent f160efb0e7
commit 513e696238
42 changed files with 1207 additions and 4 deletions

View File

@@ -0,0 +1,11 @@
package org.briarproject.briar.api.socialbackup;
import org.briarproject.bramble.api.db.DbException;
/**
* Thrown when an attempt is made to create a social account backup but a
* backup already exists. This exception may occur due to concurrent updates
* and does not indicate a database error.
*/
public class BackupExistsException extends DbException {
}

View File

@@ -0,0 +1,42 @@
package org.briarproject.briar.api.socialbackup;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.List;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class BackupMetadata {
private final SecretKey secret;
private final List<Author> custodians;
private final int threshold, version;
public BackupMetadata(SecretKey secret, List<Author> custodians,
int threshold, int version) {
this.secret = secret;
this.custodians = custodians;
this.threshold = threshold;
this.version = version;
}
public SecretKey getSecret() {
return secret;
}
public List<Author> getCustodians() {
return custodians;
}
public int getThreshold() {
return threshold;
}
public int getVersion() {
return version;
}
}

View File

@@ -0,0 +1,37 @@
package org.briarproject.briar.api.socialbackup;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class Shard {
private final byte[] secretId, shard;
private final int numShards, threshold;
public Shard(byte[] secretId, int numShards, int threshold,
byte[] shard) {
this.secretId = secretId;
this.numShards = numShards;
this.threshold = threshold;
this.shard = shard;
}
public byte[] getSecretId() {
return secretId;
}
public int getNumShards() {
return numShards;
}
public int getThreshold() {
return threshold;
}
public byte[] getShard() {
return shard;
}
}

View File

@@ -0,0 +1,47 @@
package org.briarproject.briar.api.socialbackup;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.ClientId;
import java.util.List;
import javax.annotation.Nullable;
@NotNullByDefault
public interface SocialBackupManager {
/**
* The unique ID of the social backup client.
*/
ClientId CLIENT_ID = new ClientId("pw.darkcrystal.backup");
/**
* The current major version of the social backup client.
*/
int MAJOR_VERSION = 0;
/**
* The current minor version of the social backup client.
*/
int MINOR_VERSION = 0;
/**
* Returns the metadata for this device's backup, or null if no backup has
* been created.
*/
@Nullable
BackupMetadata getBackupMetadata(Transaction txn) throws DbException;
/**
* Creates a backup for this device using the given custodians and
* threshold. The encrypted backup and a shard of the backup key will be
* sent to each custodian.
*
* @throws BackupExistsException If a backup already exists
*/
void createBackup(Transaction txn, List<ContactId> custodianIds,
int threshold) throws DbException;
}