mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-08 12:01:09 +01:00
Fix some issues and delete old code.
This commit is contained in:
parent
2db7717abc
commit
7bff6e7d99
10 changed files with 76 additions and 1389 deletions
|
|
@ -538,8 +538,8 @@ public final class OmemoManager extends Manager {
|
|||
|
||||
public OmemoFingerprint getFingerprint(OmemoDevice device)
|
||||
throws CannotEstablishOmemoSessionException, SmackException.NotLoggedInException,
|
||||
CorruptedOmemoKeyException
|
||||
{
|
||||
CorruptedOmemoKeyException, SmackException.NotConnectedException, InterruptedException,
|
||||
SmackException.NoResponseException {
|
||||
synchronized (LOCK) {
|
||||
if (getOwnJid() == null) {
|
||||
throw new SmackException.NotLoggedInException();
|
||||
|
|
@ -554,13 +554,22 @@ public final class OmemoManager extends Manager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return all fingerprints of active devices of a contact.
|
||||
* Return all OmemoFingerprints of active devices of a contact.
|
||||
* TODO: Make more fail-safe
|
||||
* @param contact contact
|
||||
* @return HashMap of deviceIds and corresponding fingerprints.
|
||||
* @return Map of all active devices of the contact and their fingerprints.
|
||||
*
|
||||
* @throws SmackException.NotLoggedInException
|
||||
* @throws CorruptedOmemoKeyException
|
||||
* @throws CannotEstablishOmemoSessionException
|
||||
* @throws SmackException.NotConnectedException
|
||||
* @throws InterruptedException
|
||||
* @throws SmackException.NoResponseException
|
||||
*/
|
||||
public HashMap<OmemoDevice, OmemoFingerprint> getActiveFingerprints(BareJid contact)
|
||||
throws SmackException.NotLoggedInException, CorruptedOmemoKeyException,
|
||||
CannotEstablishOmemoSessionException
|
||||
CannotEstablishOmemoSessionException, SmackException.NotConnectedException, InterruptedException,
|
||||
SmackException.NoResponseException
|
||||
{
|
||||
synchronized (LOCK) {
|
||||
if (getOwnJid() == null) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ import org.jivesoftware.smack.SmackException;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoBundleElement;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement_VAxolotl;
|
||||
|
|
@ -317,7 +320,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
throw new AssertionError("Gullible Trust Callback reported undecided or untrusted device, " +
|
||||
"even though it MUST NOT do that.");
|
||||
} catch (NoIdentityKeyException e) {
|
||||
throw new AssertionError("We MUST have an identityKey for " + contactsDevice + " since we built a session.", e);
|
||||
throw new AssertionError("We MUST have an identityKey for " + contactsDevice + " since we built a session." + e);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
|
|
@ -390,7 +393,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
skippedRecipients.put(contactsDevice, e);
|
||||
}
|
||||
catch (UndecidedOmemoIdentityException e) {
|
||||
throw new AssertionError("At this point, devices cannot be undecided.", e);
|
||||
throw new AssertionError("At this point, devices cannot be undecided. " + e);
|
||||
}
|
||||
catch (UntrustedOmemoIdentityException e) {
|
||||
LOGGER.log(Level.WARNING, "Device " + contactsDevice + " is untrusted. Message is not encrypted for it.");
|
||||
|
|
@ -641,7 +644,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
* @throws SmackException.NoResponseException
|
||||
* @throws CorruptedOmemoKeyException if our IdentityKeyPair is corrupted.
|
||||
*/
|
||||
private void buildFreshSessionWithDevice(XMPPConnection connection, OmemoDevice userDevice, OmemoDevice contactsDevice)
|
||||
void buildFreshSessionWithDevice(XMPPConnection connection, OmemoDevice userDevice, OmemoDevice contactsDevice)
|
||||
throws CannotEstablishOmemoSessionException, SmackException.NotConnectedException, InterruptedException,
|
||||
SmackException.NoResponseException, CorruptedOmemoKeyException {
|
||||
|
||||
|
|
@ -664,7 +667,7 @@ 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(connection, userDevice, randomPreKeyBundle, contactsDevice);
|
||||
processBundle(userDevice, randomPreKeyBundle, contactsDevice);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -813,21 +816,19 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
* @param contactsDevice OmemoDevice of the contact.
|
||||
* @return true if userDevice has session with contactsDevice.
|
||||
*/
|
||||
private boolean hasSession(OmemoDevice userDevice, OmemoDevice contactsDevice) {
|
||||
boolean hasSession(OmemoDevice userDevice, OmemoDevice contactsDevice) {
|
||||
return getOmemoStoreBackend().loadRawSession(userDevice, contactsDevice) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a received bundle. Typically that includes saving keys and building a session.
|
||||
*
|
||||
* @param connection authenticated XMPP connection
|
||||
* @param userDevice our OmemoDevice
|
||||
* @param contactsBundle bundle of the contact
|
||||
* @param contactsDevice OmemoDevice of the contact
|
||||
* @throws CorruptedOmemoKeyException
|
||||
*/
|
||||
protected abstract void processBundle(XMPPConnection connection,
|
||||
OmemoDevice userDevice,
|
||||
protected abstract void processBundle(OmemoDevice userDevice,
|
||||
T_Bundle contactsBundle,
|
||||
OmemoDevice contactsDevice)
|
||||
throws CorruptedOmemoKeyException;
|
||||
|
|
@ -974,4 +975,13 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onOmemoCarbonCopyReceived(CarbonExtension.Direction direction, Message carbonCopy, Message wrappingMessage, OmemoManager.LoggedInOmemoManager omemoManager) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOmemoMessageStanzaReceived(Stanza stanza, OmemoManager.LoggedInOmemoManager omemoManager) {
|
||||
// TODO: Implement
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -26,6 +26,7 @@ import java.util.TreeMap;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoBundleElement_VAxolotl;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement;
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException;
|
||||
|
|
@ -559,22 +560,33 @@ public abstract class OmemoStore<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
|
||||
/**
|
||||
* Return the fingerprint of the given devices announced identityKey.
|
||||
* If we have no local copy of the identityKey of the contact, build a fresh session in order to get the key.
|
||||
*
|
||||
* @param managerGuard omemoManager of our device.
|
||||
* @param contactsDevice device
|
||||
* @throws CannotEstablishOmemoSessionException if we cannot establish a session
|
||||
* @return fingerprint of the identityKey
|
||||
* @param managerGuard authenticated OmemoManager
|
||||
* @param contactsDevice OmemoDevice we want to get the fingerprint from
|
||||
* @return fingerprint
|
||||
*
|
||||
* @throws CannotEstablishOmemoSessionException If we have no local copy of the identityKey of the contact
|
||||
* and are unable to build a fresh session
|
||||
* @throws CorruptedOmemoKeyException If the identityKey we have of the contact is corrupted
|
||||
* @throws SmackException.NotConnectedException
|
||||
* @throws InterruptedException
|
||||
* @throws SmackException.NoResponseException
|
||||
*/
|
||||
public OmemoFingerprint getFingerprintAndMaybeBuildSession(OmemoManager.LoggedInOmemoManager managerGuard, OmemoDevice contactsDevice)
|
||||
throws CannotEstablishOmemoSessionException, CorruptedOmemoKeyException
|
||||
{
|
||||
throws CannotEstablishOmemoSessionException, CorruptedOmemoKeyException,
|
||||
SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
OmemoManager omemoManager = managerGuard.get();
|
||||
|
||||
// Load identityKey
|
||||
T_IdKey identityKey = loadOmemoIdentityKey(omemoManager.getOwnDevice(), contactsDevice);
|
||||
if (identityKey == null) {
|
||||
// Key cannot be loaded. Maybe it doesn't exist. Fetch a bundle to get it...
|
||||
OmemoService.getInstance().buildSessionWithDevice(managerGuard, contactsDevice, true);
|
||||
OmemoService.getInstance().buildFreshSessionWithDevice(omemoManager.getConnection(),
|
||||
omemoManager.getOwnDevice(), contactsDevice);
|
||||
}
|
||||
|
||||
// Load identityKey again
|
||||
identityKey = loadOmemoIdentityKey(omemoManager.getOwnDevice(), contactsDevice);
|
||||
if (identityKey == null) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -238,6 +238,7 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
case trusted:
|
||||
CiphertextTuple encryptedKey = ratchet.doubleRatchetEncrypt(contactsDevice, messageKey);
|
||||
keys.add(new OmemoKeyElement(encryptedKey.getCiphertext(), contactsDevice.getDeviceId(), encryptedKey.isPreKeyMessage()));
|
||||
break;
|
||||
|
||||
case untrusted:
|
||||
throw new UntrustedOmemoIdentityException(contactsDevice, fingerprint);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ package org.jivesoftware.smackx.omemo;
|
|||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYLENGTH;
|
||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYTYPE;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
|
@ -25,20 +27,14 @@ import static org.junit.Assert.assertNotNull;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Security;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoElement;
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException;
|
||||
import org.jivesoftware.smackx.omemo.internal.CipherAndAuthTag;
|
||||
import org.jivesoftware.smackx.omemo.internal.CiphertextTuple;
|
||||
import org.jivesoftware.smackx.omemo.internal.ClearTextMessage;
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoMessageInformation;
|
||||
import org.jivesoftware.smackx.omemo.util.OmemoMessageBuilder;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
/**
|
||||
* Test the identityKeyWrapper.
|
||||
|
|
@ -58,30 +54,10 @@ public class WrapperObjectsTest {
|
|||
assertEquals(OmemoElement.TYPE_OMEMO_MESSAGE, c2.getMessageType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearTextMessageTest() throws Exception {
|
||||
BareJid senderJid = JidCreate.bareFrom("bob@server.tld");
|
||||
OmemoDevice sender = new OmemoDevice(senderJid, 1234);
|
||||
OmemoMessageInformation information = new OmemoMessageInformation(null, sender, OmemoMessageInformation.CARBON.NONE);
|
||||
|
||||
assertTrue("OmemoInformation must state that the message is an OMEMO message.",
|
||||
information.isOmemoMessage());
|
||||
assertEquals(OmemoMessageInformation.CARBON.NONE, information.getCarbon());
|
||||
assertEquals(sender, information.getSenderDevice());
|
||||
|
||||
String body = "Decrypted Body";
|
||||
Message message = new Message(senderJid, body);
|
||||
ClearTextMessage c = new ClearTextMessage(body, message, information);
|
||||
|
||||
assertEquals(message, c.getOriginalMessage());
|
||||
assertEquals(information, c.getMessageInformation());
|
||||
assertEquals(body, c.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cipherAndAuthTagTest() throws NoSuchAlgorithmException, CryptoFailedException {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
byte[] key = OmemoMessageBuilder.generateKey();
|
||||
byte[] key = OmemoMessageBuilder.generateKey(KEYTYPE, KEYLENGTH);
|
||||
byte[] iv = OmemoMessageBuilder.generateIv();
|
||||
byte[] authTag = OmemoMessageBuilder.generateIv();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue