mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Include creation time in LocalAuthor.
This allows the oldest LocalAuthor to be used as the default.
This commit is contained in:
@@ -4,15 +4,21 @@ package org.briarproject.api;
|
||||
public class LocalAuthor extends Author {
|
||||
|
||||
private final byte[] privateKey;
|
||||
private final long created;
|
||||
|
||||
public LocalAuthor(AuthorId id, String name, byte[] publicKey,
|
||||
byte[] privateKey) {
|
||||
byte[] privateKey, long created) {
|
||||
super(id, name, publicKey);
|
||||
this.privateKey = privateKey;
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
/** Returns the private key used to generate the pseudonym's signatures. */
|
||||
public byte[] getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
public long getTimeCreated() {
|
||||
return created;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ import org.briarproject.api.transport.TemporarySecret;
|
||||
*/
|
||||
abstract class JdbcDatabase implements Database<Connection> {
|
||||
|
||||
private static final int SCHEMA_VERSION = 4;
|
||||
private static final int MIN_SCHEMA_VERSION = 4;
|
||||
private static final int SCHEMA_VERSION = 5;
|
||||
private static final int MIN_SCHEMA_VERSION = 5;
|
||||
|
||||
private static final String CREATE_SETTINGS =
|
||||
"CREATE TABLE settings"
|
||||
@@ -77,6 +77,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " name VARCHAR NOT NULL,"
|
||||
+ " publicKey BINARY NOT NULL,"
|
||||
+ " privateKey BINARY NOT NULL,"
|
||||
+ " created BIGINT NOT NULL,"
|
||||
+ " PRIMARY KEY (authorId))";
|
||||
|
||||
// Locking: contact
|
||||
@@ -789,13 +790,14 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
String sql = "INSERT INTO localAuthors"
|
||||
+ " (authorId, name, publicKey, privateKey)"
|
||||
+ " VALUES (?, ?, ?, ?)";
|
||||
+ " (authorId, name, publicKey, privateKey, created)"
|
||||
+ " VALUES (?, ?, ?, ?, ?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, a.getId().getBytes());
|
||||
ps.setString(2, a.getName());
|
||||
ps.setBytes(3, a.getPublicKey());
|
||||
ps.setBytes(4, a.getPrivateKey());
|
||||
ps.setLong(5, a.getTimeCreated());
|
||||
int affected = ps.executeUpdate();
|
||||
if(affected != 1) throw new DbStateException();
|
||||
ps.close();
|
||||
@@ -1584,14 +1586,19 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT name, publicKey, privateKey FROM localAuthors"
|
||||
String sql = "SELECT name, publicKey, privateKey, created"
|
||||
+ " FROM localAuthors"
|
||||
+ " WHERE authorId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, a.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
if(!rs.next()) throw new DbStateException();
|
||||
LocalAuthor localAuthor = new LocalAuthor(a, rs.getString(1),
|
||||
rs.getBytes(2), rs.getBytes(3));
|
||||
String name = rs.getString(1);
|
||||
byte[] publicKey = rs.getBytes(2);
|
||||
byte[] privateKey = rs.getBytes(3);
|
||||
long created = rs.getLong(4);
|
||||
LocalAuthor localAuthor = new LocalAuthor(a, name, publicKey,
|
||||
privateKey, created);
|
||||
if(rs.next()) throw new DbStateException();
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1608,7 +1615,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT authorId, name, publicKey, privateKey"
|
||||
String sql = "SELECT authorId, name, publicKey, privateKey, created"
|
||||
+ " FROM localAuthors";
|
||||
ps = txn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
@@ -1618,8 +1625,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
String name = rs.getString(2);
|
||||
byte[] publicKey = rs.getBytes(3);
|
||||
byte[] privateKey = rs.getBytes(4);
|
||||
long created = rs.getLong(5);
|
||||
authors.add(new LocalAuthor(authorId, name, publicKey,
|
||||
privateKey));
|
||||
privateKey, created));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
@@ -15,16 +15,20 @@ import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.MessageDigest;
|
||||
import org.briarproject.api.serial.Writer;
|
||||
import org.briarproject.api.serial.WriterFactory;
|
||||
import org.briarproject.api.system.Clock;
|
||||
|
||||
class AuthorFactoryImpl implements AuthorFactory {
|
||||
|
||||
private final CryptoComponent crypto;
|
||||
private final WriterFactory writerFactory;
|
||||
private final Clock clock;
|
||||
|
||||
@Inject
|
||||
AuthorFactoryImpl(CryptoComponent crypto, WriterFactory writerFactory) {
|
||||
AuthorFactoryImpl(CryptoComponent crypto, WriterFactory writerFactory,
|
||||
Clock clock) {
|
||||
this.crypto = crypto;
|
||||
this.writerFactory = writerFactory;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
public Author createAuthor(String name, byte[] publicKey) {
|
||||
@@ -34,7 +38,7 @@ class AuthorFactoryImpl implements AuthorFactory {
|
||||
public LocalAuthor createLocalAuthor(String name, byte[] publicKey,
|
||||
byte[] privateKey) {
|
||||
return new LocalAuthor(getId(name, publicKey), name, publicKey,
|
||||
privateKey);
|
||||
privateKey, clock.currentTimeMillis());
|
||||
}
|
||||
|
||||
private AuthorId getId(String name, byte[] publicKey) {
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
author = new Author(authorId, "Alice", new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||
localAuthorId = new AuthorId(TestUtils.getRandomId());
|
||||
localAuthor = new LocalAuthor(localAuthorId, "Bob",
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100]);
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], 1234);
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
contentType = "text/plain";
|
||||
|
||||
@@ -74,7 +74,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
author = new Author(authorId, "Alice", new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||
localAuthorId = new AuthorId(TestUtils.getRandomId());
|
||||
localAuthor = new LocalAuthor(localAuthorId, "Bob",
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100]);
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], 1234);
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
contentType = "text/plain";
|
||||
subject = "Foo";
|
||||
|
||||
@@ -114,7 +114,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
// Add a local pseudonym for Alice
|
||||
AuthorId aliceId = new AuthorId(TestUtils.getRandomId());
|
||||
LocalAuthor aliceAuthor = new LocalAuthor(aliceId, "Alice",
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100]);
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], 1234);
|
||||
db.addLocalAuthor(aliceAuthor);
|
||||
// Add Bob as a contact
|
||||
AuthorId bobId = new AuthorId(TestUtils.getRandomId());
|
||||
@@ -173,7 +173,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
// Add a local pseudonym for Bob
|
||||
AuthorId bobId = new AuthorId(TestUtils.getRandomId());
|
||||
LocalAuthor bobAuthor = new LocalAuthor(bobId, "Bob",
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100]);
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], 1234);
|
||||
db.addLocalAuthor(bobAuthor);
|
||||
// Add Alice as a contact
|
||||
AuthorId aliceId = new AuthorId(TestUtils.getRandomId());
|
||||
|
||||
Reference in New Issue
Block a user