use of org.jivesoftware.smackx.omemo.internal.OmemoDevice in project Smack by igniterealtime.
the class SignalOmemoStoreConnector method loadSession.
@Override
public SessionRecord loadSession(SignalProtocolAddress signalProtocolAddress) {
OmemoDevice device;
try {
device = asOmemoDevice(signalProtocolAddress);
} catch (XmppStringprepException e) {
throw new AssertionError(e);
}
SessionRecord record;
try {
record = omemoStore.loadRawSession(getOurDevice(), device);
} catch (IOException e) {
throw new IllegalStateException(e);
}
if (record != null) {
return record;
} else {
return new SessionRecord();
}
}
use of org.jivesoftware.smackx.omemo.internal.OmemoDevice in project Smack by igniterealtime.
the class OmemoExceptionsTest method cannotEstablishOmemoSessionExceptionTest.
@Test
public void cannotEstablishOmemoSessionExceptionTest() throws XmppStringprepException {
OmemoDevice alice1 = new OmemoDevice(JidCreate.bareFrom("alice@server.tld"), 1234);
OmemoDevice alice2 = new OmemoDevice(JidCreate.bareFrom("alice@server.tld"), 2345);
OmemoDevice bob = new OmemoDevice(JidCreate.bareFrom("bob@server.tld"), 5678);
CannotEstablishOmemoSessionException c = new CannotEstablishOmemoSessionException(alice1, null);
assertEquals(1, c.getFailures().size());
assertTrue(c.getFailures().containsKey(alice1.getJid()));
c.addSuccess(alice2);
assertFalse(c.requiresThrowing());
c.addFailures(new CannotEstablishOmemoSessionException(bob, null));
assertTrue(c.requiresThrowing());
assertEquals(1, c.getSuccesses().size());
assertEquals(2, c.getFailures().size());
c.getSuccesses().remove(alice2.getJid());
c.addFailures(new CannotEstablishOmemoSessionException(alice2, null));
assertEquals(2, c.getFailures().size());
}
use of org.jivesoftware.smackx.omemo.internal.OmemoDevice in project Smack by igniterealtime.
the class OmemoExceptionsTest method undecidedOmemoIdentityExceptionTest.
@Test
public void undecidedOmemoIdentityExceptionTest() throws XmppStringprepException {
OmemoDevice alice = new OmemoDevice(JidCreate.bareFrom("alice@server.tld"), 1234);
OmemoDevice bob = new OmemoDevice(JidCreate.bareFrom("bob@server.tld"), 5678);
OmemoDevice mallory = new OmemoDevice(JidCreate.bareFrom("mallory@server.tld"), 9876);
UndecidedOmemoIdentityException u = new UndecidedOmemoIdentityException(alice);
assertTrue(u.getUndecidedDevices().contains(alice));
assertTrue(u.getUndecidedDevices().size() == 1);
UndecidedOmemoIdentityException v = new UndecidedOmemoIdentityException(bob);
v.getUndecidedDevices().add(mallory);
assertTrue(v.getUndecidedDevices().size() == 2);
assertTrue(v.getUndecidedDevices().contains(bob));
assertTrue(v.getUndecidedDevices().contains(mallory));
u.getUndecidedDevices().add(bob);
u.join(v);
assertTrue(u.getUndecidedDevices().size() == 3);
}
use of org.jivesoftware.smackx.omemo.internal.OmemoDevice in project Zom-Android by zom.
the class IOCipherOmemoStore method loadAllRawSessionsOf.
@Override
public HashMap<Integer, T_Sess> loadAllRawSessionsOf(OmemoManager omemoManager, BareJid contact) {
File contactsDirectory = hierarchy.getContactsDir(omemoManager, contact);
HashMap<Integer, T_Sess> sessions = new HashMap<>();
String[] devices = contactsDirectory.list();
for (String deviceId : devices != null ? devices : new String[0]) {
int id;
try {
id = Integer.parseInt(deviceId);
} catch (NumberFormatException e) {
continue;
}
OmemoDevice device = new OmemoDevice(contact, id);
File session = hierarchy.getContactsSessionPath(omemoManager, device);
try {
byte[] bytes = readBytes(session);
if (bytes == null) {
continue;
}
T_Sess s = keyUtil().rawSessionFromBytes(bytes);
sessions.put(id, s);
} catch (IOException e) {
// Do nothing
}
}
return sessions;
}
use of org.jivesoftware.smackx.omemo.internal.OmemoDevice in project Zom-Android by zom.
the class Omemo method getFingerprints.
public ArrayList<String> getFingerprints(BareJid jid, boolean autoload) throws CorruptedOmemoKeyException, SmackException, XMPPException.XMPPErrorException, InterruptedException {
try {
mOmemoManager.buildSessionsWith(jid);
} catch (CannotEstablishOmemoSessionException e) {
debug(TAG, "couldn't establish omemo session: " + e);
}
CachedDeviceList list = mOmemoStore.loadCachedDeviceList(mOmemoManager, jid);
if (list == null) {
list = new CachedDeviceList();
}
ArrayList<String> fps = new ArrayList<>();
for (int id : list.getActiveDevices()) {
OmemoDevice d = new OmemoDevice(jid, id);
IdentityKey idk = (IdentityKey) mOmemoStore.loadOmemoIdentityKey(mOmemoManager, d);
if (idk == null) {
System.out.println("No identityKey for " + d);
} else {
fps.add(mOmemoStore.keyUtil().getFingerprint(idk).toString());
}
}
return fps;
}
Aggregations