1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

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) SessionCipher> store)
{ {
super(omemoManager, store); super(omemoManager, store);
this.storeConnector = new SignalOmemoStoreConnector(omemoManager.getOwnDevice(), store); this.storeConnector = new SignalOmemoStoreConnector(omemoManager, store);
} }
@Override @Override

View file

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

View file

@ -26,6 +26,7 @@ import java.util.TreeMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smackx.omemo.OmemoManager;
import org.jivesoftware.smackx.omemo.OmemoStore; import org.jivesoftware.smackx.omemo.OmemoStore;
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException; import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
import org.jivesoftware.smackx.omemo.internal.OmemoDevice; import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
@ -61,17 +62,17 @@ public class SignalOmemoStoreConnector
private final OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, private final OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord,
SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher> SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher>
omemoStore; 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, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, SignalProtocolAddress, ECPublicKey,
PreKeyBundle, SessionCipher> store) { PreKeyBundle, SessionCipher> store) {
this.userDevice = userDevice; this.omemoManager = omemoManager;
this.omemoStore = store; this.omemoStore = store;
} }
OmemoDevice getOurDevice() { OmemoDevice getOurDevice() {
return userDevice; return omemoManager.getOwnDevice();
} }
@Override @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. // Do not encrypt for our own device.
removeOurDevice(userDevice, contactsDevices); removeOurDevice(userDevice, contactsDevices);
buildMissingSessionsWithDevices(manager.getConnection(), userDevice, contactsDevices);
ArrayList<OmemoDevice> undecidedDevices = getUndecidedDevices(userDevice, manager.getTrustCallback(), contactsDevices); ArrayList<OmemoDevice> undecidedDevices = getUndecidedDevices(userDevice, manager.getTrustCallback(), contactsDevices);
if (!undecidedDevices.isEmpty()) { if (!undecidedDevices.isEmpty()) {
throw new UndecidedOmemoIdentityException(undecidedDevices); 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); T_Bundle randomPreKeyBundle = new ArrayList<>(bundlesList.values()).get(randomIndex);
// build the session // 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); fingerprint = getOmemoStoreBackend().getFingerprint(userDevice, device);
} catch (CorruptedOmemoKeyException | NoIdentityKeyException e) { } catch (CorruptedOmemoKeyException | NoIdentityKeyException e) {
// TODO: Best solution? // TODO: Best solution?
LOGGER.log(Level.WARNING, "Could not load fingerprint of " + device, e);
undecidedDevices.add(device); undecidedDevices.add(device);
continue; 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. * 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 contactsBundle bundle of the contact
* @param contactsDevice OmemoDevice of the contact * @param contactsDevice OmemoDevice of the contact
* @throws CorruptedOmemoKeyException * @throws CorruptedOmemoKeyException
*/ */
protected abstract void processBundle(OmemoDevice userDevice, protected abstract void processBundle(OmemoManager omemoManager,
T_Bundle contactsBundle, T_Bundle contactsBundle,
OmemoDevice contactsDevice) OmemoDevice contactsDevice)
throws CorruptedOmemoKeyException; throws CorruptedOmemoKeyException;
@ -1161,20 +1165,13 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
{ {
OmemoManager omemoManager = managerGuard.get(); OmemoManager omemoManager = managerGuard.get();
OmemoDevice userDevice = omemoManager.getOwnDevice(); OmemoDevice userDevice = omemoManager.getOwnDevice();
OmemoCachedDeviceList list = getOmemoStoreBackend().loadCachedDeviceList(userDevice);
//Mark all devices inactive OmemoDeviceListElement_VAxolotl newList =
for (int i : list.getActiveDevices()) { new OmemoDeviceListElement_VAxolotl(Collections.singleton(userDevice.getDeviceId()));
list.addInactiveDevice(i);
}
// Add back our device
list.addDevice(userDevice.getDeviceId());
OmemoDeviceListElement_VAxolotl listElement = new OmemoDeviceListElement_VAxolotl(list);
// Merge 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);
} }
} }