mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Add DB method for setting local handshake key pair.
This commit is contained in:
@@ -685,6 +685,12 @@ interface Database<T> {
|
||||
void setGroupVisibility(T txn, ContactId c, GroupId g, boolean shared)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Sets the handshake key pair for the local pseudonym with the given ID.
|
||||
*/
|
||||
void setHandshakeKeyPair(T txn, AuthorId local, byte[] publicKey,
|
||||
byte[] privateKey) throws DbException;
|
||||
|
||||
/**
|
||||
* Marks the given message as shared.
|
||||
*/
|
||||
|
||||
@@ -1035,6 +1035,16 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHandshakeKeyPair(Transaction transaction, AuthorId local,
|
||||
byte[] publicKey, byte[] privateKey) throws DbException {
|
||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsLocalAuthor(txn, local))
|
||||
throw new NoSuchLocalAuthorException();
|
||||
db.setHandshakeKeyPair(txn, local, publicKey, privateKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReorderingWindow(Transaction transaction,
|
||||
TransportKeySetId k, TransportId t, long timePeriod, long base,
|
||||
|
||||
@@ -1681,10 +1681,18 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
byte[] handshakePublicKey = rs.getBytes(5);
|
||||
byte[] handshakePrivateKey = rs.getBytes(6);
|
||||
long created = rs.getLong(7);
|
||||
LocalAuthor localAuthor = new LocalAuthor(a, formatVersion, name,
|
||||
publicKey, privateKey, handshakePublicKey,
|
||||
handshakePrivateKey, created);
|
||||
if (rs.next()) throw new DbStateException();
|
||||
LocalAuthor localAuthor;
|
||||
if (handshakePublicKey == null) {
|
||||
if (handshakePrivateKey != null) throw new DbStateException();
|
||||
localAuthor = new LocalAuthor(a, formatVersion, name,
|
||||
publicKey, privateKey, created);
|
||||
} else {
|
||||
if (handshakePrivateKey == null) throw new DbStateException();
|
||||
localAuthor = new LocalAuthor(a, formatVersion, name,
|
||||
publicKey, privateKey, handshakePublicKey,
|
||||
handshakePrivateKey, created);
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
return localAuthor;
|
||||
@@ -3180,6 +3188,27 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHandshakeKeyPair(Connection txn, AuthorId local,
|
||||
byte[] publicKey, byte[] privateKey) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
String sql = "UPDATE localAuthors"
|
||||
+ " SET handshakePublicKey = ?, handshakePrivateKey = ?"
|
||||
+ " WHERE authorId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, publicKey);
|
||||
ps.setBytes(2, privateKey);
|
||||
ps.setBytes(3, local.getBytes());
|
||||
int affected = ps.executeUpdate();
|
||||
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessageShared(Connection txn, MessageId m)
|
||||
throws DbException {
|
||||
|
||||
Reference in New Issue
Block a user