diff --git a/briar-api/src/org/briarproject/api/LocalAuthor.java b/briar-api/src/org/briarproject/api/LocalAuthor.java index 16da123693614ca8fcd350d70c85c04ddf4d9d24..68520b6752df932a6d2cd73ea1d52560b2b95098 100644 --- a/briar-api/src/org/briarproject/api/LocalAuthor.java +++ b/briar-api/src/org/briarproject/api/LocalAuthor.java @@ -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; + } } diff --git a/briar-core/src/org/briarproject/db/JdbcDatabase.java b/briar-core/src/org/briarproject/db/JdbcDatabase.java index 9c660107971540f371306ec42f105a0c7ff3884a..7f4588d10d7d2418d067ee88b1c4df22a12f10b2 100644 --- a/briar-core/src/org/briarproject/db/JdbcDatabase.java +++ b/briar-core/src/org/briarproject/db/JdbcDatabase.java @@ -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(); diff --git a/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java b/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java index b40dc04ed3c2aa6722a6f55af0c3f04e49d99d95..6fca9a6c8ebea5ed1b881e8bcf88be9070c6623d 100644 --- a/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java +++ b/briar-core/src/org/briarproject/messaging/AuthorFactoryImpl.java @@ -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) { diff --git a/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java b/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java index 44bca26f2f4b276519eac41fd09eecad2946054f..98d2b8f97a52637f5a9a53dd469b38fd14a52e49 100644 --- a/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java +++ b/briar-tests/src/org/briarproject/db/DatabaseComponentTest.java @@ -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"; diff --git a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java index 103d12e252665d0bf9984ed96198280f555cc2ed..3b4e344cb2f38f9bfb9b33746c926e037e216806 100644 --- a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java +++ b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java @@ -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"; diff --git a/briar-tests/src/org/briarproject/messaging/simplex/SimplexMessagingIntegrationTest.java b/briar-tests/src/org/briarproject/messaging/simplex/SimplexMessagingIntegrationTest.java index 1e65c57a0b696e3ffde9b5adba2317274576b5b7..a32327b98d97765204bbe0ead560f3602274d408 100644 --- a/briar-tests/src/org/briarproject/messaging/simplex/SimplexMessagingIntegrationTest.java +++ b/briar-tests/src/org/briarproject/messaging/simplex/SimplexMessagingIntegrationTest.java @@ -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());