Version 1.0.1-SNAPSHOT - fixed issue with requesting pubkey, and problem where your keys are overwritten if you try to import a contact again or worse, your identity as a contact

This commit is contained in:
Christian Basler 2016-01-31 18:11:20 +01:00
parent 3103ae6edd
commit 5f4dbfc985
6 changed files with 40 additions and 14 deletions

View File

@ -5,7 +5,7 @@ subprojects {
sourceCompatibility = 1.7
group = 'ch.dissem.jabit'
version = '1.0.0'
version = '1.0.1-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
@ -34,7 +34,7 @@ subprojects {
}
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
required { isReleaseVersion }
sign configurations.archives
}

View File

@ -200,6 +200,7 @@ public class BitmessageContext {
LOG.info("Public key is missing from recipient. Requesting.");
requestPubkey(msg.getFrom(), to);
msg.setStatus(PUBKEY_REQUESTED);
msg.addLabels(ctx.getMessageRepository().getLabels(Label.Type.OUTBOX));
ctx.getMessageRepository().save(msg);
} else {
LOG.info("Sending message.");
@ -224,7 +225,7 @@ public class BitmessageContext {
requestingIdentity,
address,
new GetPubkey(address),
+28 * DAY
+2 * DAY
);
}

View File

@ -4,6 +4,7 @@ import ch.dissem.bitmessage.entity.BitmessageAddress;
import ch.dissem.bitmessage.entity.ObjectMessage;
import ch.dissem.bitmessage.entity.Plaintext;
import ch.dissem.bitmessage.entity.PlaintextHolder;
import ch.dissem.bitmessage.entity.payload.Pubkey;
import ch.dissem.bitmessage.ports.MessageRepository;
import ch.dissem.bitmessage.ports.ProofOfWorkEngine;
import ch.dissem.bitmessage.ports.ProofOfWorkRepository;
@ -42,10 +43,10 @@ public class ProofOfWorkService implements ProofOfWorkEngine.Callback, InternalC
}
public void doProofOfWork(BitmessageAddress recipient, ObjectMessage object) {
long nonceTrialsPerByte = recipient == null ?
ctx.getNetworkNonceTrialsPerByte() : recipient.getPubkey().getNonceTrialsPerByte();
long extraBytes = recipient == null ?
ctx.getNetworkExtraBytes() : recipient.getPubkey().getExtraBytes();
Pubkey pubkey = recipient == null ? null : recipient.getPubkey();
long nonceTrialsPerByte = pubkey == null ? ctx.getNetworkNonceTrialsPerByte() : pubkey.getNonceTrialsPerByte();
long extraBytes = pubkey == null ? ctx.getNetworkExtraBytes() : pubkey.getExtraBytes();
powRepo.putObject(object, nonceTrialsPerByte, extraBytes);
if (object.getPayload() instanceof PlaintextHolder) {

View File

@ -79,6 +79,7 @@ public class Label implements Serializable {
INBOX,
BROADCAST,
DRAFT,
OUTBOX,
SENT,
UNREAD,
TRASH

View File

@ -152,13 +152,25 @@ public class JdbcAddressRepository extends JdbcHelper implements AddressReposito
private void update(BitmessageAddress address) throws IOException, SQLException {
try (Connection connection = config.getConnection()) {
PreparedStatement ps = connection.prepareStatement(
"UPDATE Address SET alias=?, public_key=?, private_key=?, subscribed=? WHERE address=?");
ps.setString(1, address.getAlias());
writePubkey(ps, 2, address.getPubkey());
writeBlob(ps, 3, address.getPrivateKey());
ps.setBoolean(4, address.isSubscribed());
ps.setString(5, address.getAddress());
StringBuilder statement = new StringBuilder("UPDATE Address SET alias=?");
if (address.getPubkey() != null) {
statement.append(", public_key=?");
}
if (address.getPrivateKey() != null) {
statement.append(", private_key=?");
}
statement.append(", subscribed=? WHERE address=?");
PreparedStatement ps = connection.prepareStatement(statement.toString());
int i = 0;
ps.setString(++i, address.getAlias());
if (address.getPubkey() != null) {
writePubkey(ps, ++i, address.getPubkey());
}
if (address.getPrivateKey() != null) {
writeBlob(ps, ++i, address.getPrivateKey());
}
ps.setBoolean(++i, address.isSubscribed());
ps.setString(++i, address.getAddress());
ps.executeUpdate();
}
}

View File

@ -128,6 +128,17 @@ public class JdbcAddressRepositoryTest extends TestBase {
assertEquals("Test-Alias", address.getAlias());
}
@Test
public void ensureExistingKeysAreNotDeleted() {
BitmessageAddress address = new BitmessageAddress(IDENTITY_A);
address.setAlias("Test");
repo.save(address);
BitmessageAddress identityA = repo.getAddress(IDENTITY_A);
assertNotNull(identityA.getPubkey());
assertNotNull(identityA.getPrivateKey());
assertEquals("Test", identityA.getAlias());
}
@Test
public void testRemove() throws Exception {
BitmessageAddress address = repo.getAddress(IDENTITY_A);