Sending messages works again

This commit is contained in:
Paul Schaub 2018-01-05 18:07:37 +01:00
parent 9c7a027b62
commit 20cca54ec2
4 changed files with 19 additions and 21 deletions

View File

@ -68,7 +68,7 @@ public class SignalOmemoRatchet
SessionCipher> store)
{
super(omemoManager, store);
this.storeConnector = new SignalOmemoStoreConnector(omemoManager.getOwnDevice(), store);
this.storeConnector = new SignalOmemoStoreConnector(omemoManager, store);
}
@Override

View File

@ -92,12 +92,12 @@ public final class SignalOmemoService
}
@Override
protected void processBundle(OmemoDevice userDevice,
protected void processBundle(OmemoManager omemoManager,
PreKeyBundle contactsBundle,
OmemoDevice contactsDevice)
throws CorruptedOmemoKeyException
{
SignalOmemoStoreConnector connector = new SignalOmemoStoreConnector(userDevice, getOmemoStoreBackend());
SignalOmemoStoreConnector connector = new SignalOmemoStoreConnector(omemoManager, getOmemoStoreBackend());
SessionBuilder builder = new SessionBuilder(connector, connector, connector, connector,
SignalOmemoStoreConnector.asAddress(contactsDevice));
try {

View File

@ -26,6 +26,7 @@ import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smackx.omemo.OmemoManager;
import org.jivesoftware.smackx.omemo.OmemoStore;
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
@ -61,17 +62,17 @@ public class SignalOmemoStoreConnector
private final OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord,
SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher>
omemoStore;
private final OmemoDevice userDevice;
private final OmemoManager omemoManager;
public SignalOmemoStoreConnector(OmemoDevice userDevice, OmemoStore<IdentityKeyPair,
public SignalOmemoStoreConnector(OmemoManager omemoManager, OmemoStore<IdentityKeyPair,
IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, SignalProtocolAddress, ECPublicKey,
PreKeyBundle, SessionCipher> store) {
this.userDevice = userDevice;
this.omemoManager = omemoManager;
this.omemoStore = store;
}
OmemoDevice getOurDevice() {
return userDevice;
return omemoManager.getOwnDevice();
}
@Override

View File

@ -351,6 +351,8 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
// Do not encrypt for our own device.
removeOurDevice(userDevice, contactsDevices);
buildMissingSessionsWithDevices(manager.getConnection(), userDevice, contactsDevices);
ArrayList<OmemoDevice> undecidedDevices = getUndecidedDevices(userDevice, manager.getTrustCallback(), contactsDevices);
if (!undecidedDevices.isEmpty()) {
throw new UndecidedOmemoIdentityException(undecidedDevices);
@ -757,7 +759,8 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
T_Bundle randomPreKeyBundle = new ArrayList<>(bundlesList.values()).get(randomIndex);
// build the session
processBundle(userDevice, randomPreKeyBundle, contactsDevice);
OmemoManager omemoManager = OmemoManager.getInstanceFor(connection, userDevice.getDeviceId());
processBundle(omemoManager, randomPreKeyBundle, contactsDevice);
}
/**
@ -865,6 +868,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
fingerprint = getOmemoStoreBackend().getFingerprint(userDevice, device);
} catch (CorruptedOmemoKeyException | NoIdentityKeyException e) {
// TODO: Best solution?
LOGGER.log(Level.WARNING, "Could not load fingerprint of " + device, e);
undecidedDevices.add(device);
continue;
}
@ -913,12 +917,12 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
/**
* Process a received bundle. Typically that includes saving keys and building a session.
*
* @param userDevice our OmemoDevice
* @param omemoManager our OmemoManager
* @param contactsBundle bundle of the contact
* @param contactsDevice OmemoDevice of the contact
* @throws CorruptedOmemoKeyException
*/
protected abstract void processBundle(OmemoDevice userDevice,
protected abstract void processBundle(OmemoManager omemoManager,
T_Bundle contactsBundle,
OmemoDevice contactsDevice)
throws CorruptedOmemoKeyException;
@ -1161,20 +1165,13 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
{
OmemoManager omemoManager = managerGuard.get();
OmemoDevice userDevice = omemoManager.getOwnDevice();
OmemoCachedDeviceList list = getOmemoStoreBackend().loadCachedDeviceList(userDevice);
//Mark all devices inactive
for (int i : list.getActiveDevices()) {
list.addInactiveDevice(i);
}
OmemoDeviceListElement_VAxolotl newList =
new OmemoDeviceListElement_VAxolotl(Collections.singleton(userDevice.getDeviceId()));
// Add back our device
list.addDevice(userDevice.getDeviceId());
OmemoDeviceListElement_VAxolotl listElement = new OmemoDeviceListElement_VAxolotl(list);
// Merge list
getOmemoStoreBackend().mergeCachedDeviceList(userDevice, userDevice.getJid(), listElement);
getOmemoStoreBackend().mergeCachedDeviceList(userDevice, userDevice.getJid(), newList);
OmemoService.publishDeviceList(omemoManager.getConnection(), listElement);
OmemoService.publishDeviceList(omemoManager.getConnection(), newList);
}
}