/** * Returns true if this is a preKeyMessage. * * @return preKeyMessage? */ public boolean isPreKeyMessage() { return getMessageType() == TYPE_OMEMO_PREKEY_MESSAGE; } }
public OmemoCachedDeviceList(OmemoCachedDeviceList original) { this(original.getActiveDevices(), original.getInactiveDevices()); }
@Override public boolean equals(Object other) { return other instanceof OmemoDevice && ((OmemoDevice) other).getJid().equals(this.getJid()) && ((OmemoDevice) other).getDeviceId() == this.getDeviceId(); }
/** * Check, if our freshly generated deviceId is available (unique) in our deviceList. * * @param userDevice our current device. * @param id deviceId to check for. * @return true if list did not contain our id, else false */ boolean isAvailableDeviceId(OmemoDevice userDevice, int id) { LOGGER.log(Level.INFO, "Check if id " + id + " is available..."); // Lookup local cached device list BareJid ownJid = userDevice.getJid(); OmemoCachedDeviceList cachedDeviceList; cachedDeviceList = loadCachedDeviceList(userDevice, ownJid); if (cachedDeviceList == null) { cachedDeviceList = new OmemoCachedDeviceList(); } // Does the list already contain that id? return !cachedDeviceList.contains(id); }
/** * Load a list of deviceIds from our own devices. * @param userDevice * @return */ public OmemoCachedDeviceList loadCachedDeviceList(OmemoDevice userDevice) { return loadCachedDeviceList(userDevice, userDevice.getJid()); }
/** * Return a set of all OMEMO capable devices of a contact. * Note, that this method does not explicitly refresh the device list of the contact, so it might be outdated. * @see #requestDeviceListUpdateFor(BareJid) * @param contact contact we want to get a set of device of. * @return set of known devices of that contact. */ public Set<OmemoDevice> getDevicesOf(BareJid contact) { OmemoCachedDeviceList list = getOmemoService().getOmemoStoreBackend().loadCachedDeviceList(getOwnDevice(), contact); HashSet<OmemoDevice> devices = new HashSet<>(); for (int deviceId : list.getActiveDevices()) { devices.add(new OmemoDevice(contact, deviceId)); } return devices; }
/** * Return the OmemoDevice of the user. * * @return omemoDevice */ public OmemoDevice getOwnDevice() { synchronized (LOCK) { BareJid jid = getOwnJid(); if (jid == null) { return null; } return new OmemoDevice(jid, getDeviceId()); } }
/** * Return the name of the PubSub {@link org.jivesoftware.smackx.pubsub.LeafNode} of this device. * @return node name. */ public String getBundleNodeName() { return OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(getDeviceId()); } }
public boolean isActive(int deviceId) { return getActiveDevices().contains(deviceId); }
public static SignalProtocolAddress asAddress(OmemoDevice device) { return new SignalProtocolAddress(device.getJid().toString(), device.getDeviceId()); } }
File getUserDirectory(OmemoDevice userDevice) { return getUserDirectory(userDevice.getJid()); }
@Override public void storeCachedDeviceList(OmemoDevice userDevice, BareJid contact, OmemoCachedDeviceList contactsDeviceList) { if (contact == null) { return; } File activeDevices = hierarchy.getContactsActiveDevicesPath(userDevice, contact); writeIntegers(activeDevices, contactsDeviceList.getActiveDevices()); File inactiveDevices = hierarchy.getContactsInactiveDevicesPath(userDevice, contact); writeIntegers(inactiveDevices, contactsDeviceList.getInactiveDevices()); }
OmemoStoreTest(OmemoStore<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_Sess, T_Addr, T_ECPub, T_Bundle, T_Ciph> store) throws XmppStringprepException { this.store = store; alice = new OmemoDevice(JidCreate.bareFrom("alice@wonderland.lit"), 123); bob = new OmemoDevice(JidCreate.bareFrom("bob@builder.tv"), 987); }
/** * Assemble an OmemoMessageElement from the current state of the builder. * * @return OmemoMessageElement */ public OmemoElement finish() { OmemoHeaderElement_VAxolotl header = new OmemoHeaderElement_VAxolotl( userDevice.getDeviceId(), keys, initializationVector ); return new OmemoElement_VAxolotl(header, ciphertextMessage); }
public OmemoDeviceListElement(OmemoCachedDeviceList cachedList) { this.deviceIds = Collections.unmodifiableSet(cachedList.getActiveDevices()); }
File getContactsDir(OmemoDevice userDevice, OmemoDevice contactsDevice) { return createDirectory(getContactsDir(userDevice, contactsDevice.getJid()), Integer.toString(contactsDevice.getDeviceId())); }
public CannotEstablishOmemoSessionException(OmemoDevice failed, Throwable reason) { super(); getFailsOfContact(failed.getJid()).put(failed, reason); }
@Override public PreKeyBundle bundleFromOmemoBundle(OmemoBundleElement bundle, OmemoDevice contact, int preKeyId) throws CorruptedOmemoKeyException { return new PreKeyBundle(0, contact.getDeviceId(), preKeyId, BUNDLE.preKeyPublic(bundle, preKeyId), BUNDLE.signedPreKeyId(bundle), BUNDLE.signedPreKeyPublic(bundle), BUNDLE.signedPreKeySignature(bundle), BUNDLE.identityKey(bundle)); }
File getUserDeviceDirectory(OmemoDevice userDevice) { return createDirectory(getUserDirectory(userDevice.getJid()), Integer.toString(userDevice.getDeviceId())); }
public void addSuccess(OmemoDevice success) { getSuccessesOfContact(success.getJid()).add(success); }