mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-05 19:55:59 +01:00
Remove unused code, rafactor
This commit is contained in:
parent
28cabf00ee
commit
1cbc112c88
10 changed files with 55 additions and 75 deletions
|
@ -46,10 +46,6 @@ public class SignalFileBasedOmemoStore
|
|||
SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher>
|
||||
{
|
||||
|
||||
public SignalFileBasedOmemoStore() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SignalFileBasedOmemoStore(File base) {
|
||||
super(base);
|
||||
}
|
||||
|
|
|
@ -52,10 +52,6 @@ public abstract class FileBasedOmemoStore<T_IdKeyPair, T_IdKey, T_PreKey, T_SigP
|
|||
private final FileHierarchy hierarchy;
|
||||
private static final Logger LOGGER = Logger.getLogger(FileBasedOmemoStore.class.getName());
|
||||
|
||||
public FileBasedOmemoStore() {
|
||||
this(OmemoConfiguration.getFileBasedOmemoStoreDefaultPath());
|
||||
}
|
||||
|
||||
public FileBasedOmemoStore(File basePath) {
|
||||
super();
|
||||
if (basePath == null) {
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.omemo;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Contains OMEMO related configuration options.
|
||||
*
|
||||
|
@ -33,31 +31,6 @@ public final class OmemoConfiguration {
|
|||
private static boolean IGNORE_STALE_DEVICES = true;
|
||||
private static int IGNORE_STALE_DEVICE_AFTER_HOURS = 24 * 7; //One week
|
||||
|
||||
/**
|
||||
* Delete stale devices from the device list after a period of time.
|
||||
*/
|
||||
private static boolean DELETE_STALE_DEVICES = true;
|
||||
private static int DELETE_STALE_DEVICE_AFTER_HOURS = 24 * 7 * 4; //4 weeks
|
||||
|
||||
/**
|
||||
* Upload a new signed prekey in intervals. This improves forward secrecy. Old keys are kept for some more time and
|
||||
* then deleted.
|
||||
*/
|
||||
private static boolean RENEW_OLD_SIGNED_PREKEYS = false;
|
||||
private static int RENEW_OLD_SIGNED_PREKEYS_AFTER_HOURS = 24 * 7; //One week
|
||||
private static int MAX_NUMBER_OF_STORED_SIGNED_PREKEYS = 4;
|
||||
|
||||
/**
|
||||
* Add a plaintext body hint about omemo encryption to the message.
|
||||
*/
|
||||
private static boolean ADD_OMEMO_HINT_BODY = true;
|
||||
|
||||
private static boolean REPAIR_BROKEN_SESSIONS_WITH_PREKEY_MESSAGES = true;
|
||||
|
||||
private static boolean COMPLETE_SESSION_WITH_EMPTY_MESSAGE = true;
|
||||
|
||||
private static File FILE_BASED_OMEMO_STORE_DEFAULT_PATH = null;
|
||||
|
||||
public static void setIgnoreStaleDevices(boolean ignore) {
|
||||
IGNORE_STALE_DEVICES = ignore;
|
||||
}
|
||||
|
@ -77,6 +50,12 @@ public final class OmemoConfiguration {
|
|||
return IGNORE_STALE_DEVICE_AFTER_HOURS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete stale devices from the device list after a period of time.
|
||||
*/
|
||||
private static boolean DELETE_STALE_DEVICES = true;
|
||||
private static int DELETE_STALE_DEVICE_AFTER_HOURS = 24 * 7 * 4; //4 weeks
|
||||
|
||||
public static void setDeleteStaleDevices(boolean delete) {
|
||||
DELETE_STALE_DEVICES = delete;
|
||||
}
|
||||
|
@ -96,6 +75,14 @@ public final class OmemoConfiguration {
|
|||
return DELETE_STALE_DEVICE_AFTER_HOURS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a new signed prekey in intervals. This improves forward secrecy. Old keys are kept for some more time and
|
||||
* then deleted.
|
||||
*/
|
||||
private static boolean RENEW_OLD_SIGNED_PREKEYS = false;
|
||||
private static int RENEW_OLD_SIGNED_PREKEYS_AFTER_HOURS = 24 * 7; //One week
|
||||
private static int MAX_NUMBER_OF_STORED_SIGNED_PREKEYS = 4;
|
||||
|
||||
/**
|
||||
* Decide, whether signed preKeys are automatically rotated or not.
|
||||
* It is highly recommended to rotate signed preKeys to preserve forward secrecy.
|
||||
|
@ -160,6 +147,11 @@ public final class OmemoConfiguration {
|
|||
return MAX_NUMBER_OF_STORED_SIGNED_PREKEYS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plaintext body hint about omemo encryption to the message.
|
||||
*/
|
||||
private static boolean ADD_OMEMO_HINT_BODY = true;
|
||||
|
||||
/**
|
||||
* Decide, whether an OMEMO message should carry a plaintext hint about OMEMO encryption.
|
||||
* Eg. "I sent you an OMEMO encrypted message..."
|
||||
|
@ -179,13 +171,7 @@ public final class OmemoConfiguration {
|
|||
return ADD_OMEMO_HINT_BODY;
|
||||
}
|
||||
|
||||
public static void setFileBasedOmemoStoreDefaultPath(File path) {
|
||||
FILE_BASED_OMEMO_STORE_DEFAULT_PATH = path;
|
||||
}
|
||||
|
||||
public static File getFileBasedOmemoStoreDefaultPath() {
|
||||
return FILE_BASED_OMEMO_STORE_DEFAULT_PATH;
|
||||
}
|
||||
private static boolean REPAIR_BROKEN_SESSIONS_WITH_PREKEY_MESSAGES = true;
|
||||
|
||||
/**
|
||||
* Determine, whether incoming messages, which have broken sessions should automatically be answered by an empty
|
||||
|
@ -207,6 +193,8 @@ public final class OmemoConfiguration {
|
|||
REPAIR_BROKEN_SESSIONS_WITH_PREKEY_MESSAGES = repair;
|
||||
}
|
||||
|
||||
private static boolean COMPLETE_SESSION_WITH_EMPTY_MESSAGE = true;
|
||||
|
||||
/**
|
||||
* Determine, whether incoming preKeyMessages should automatically be answered by an empty message in order to
|
||||
* complete the session.
|
||||
|
|
|
@ -67,7 +67,7 @@ import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
|||
import org.jivesoftware.smackx.omemo.listener.OmemoMessageListener;
|
||||
import org.jivesoftware.smackx.omemo.listener.OmemoMucMessageListener;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||
import org.jivesoftware.smackx.omemo.trust.TrustCallback;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoTrustCallback;
|
||||
import org.jivesoftware.smackx.omemo.trust.TrustState;
|
||||
import org.jivesoftware.smackx.pep.PEPListener;
|
||||
import org.jivesoftware.smackx.pep.PEPManager;
|
||||
|
@ -101,7 +101,7 @@ public final class OmemoManager extends Manager {
|
|||
private final HashSet<OmemoMessageListener> omemoMessageListeners = new HashSet<>();
|
||||
private final HashSet<OmemoMucMessageListener> omemoMucMessageListeners = new HashSet<>();
|
||||
|
||||
private TrustCallback trustCallback;
|
||||
private OmemoTrustCallback trustCallback;
|
||||
|
||||
private BareJid ownJid;
|
||||
private Integer deviceId;
|
||||
|
@ -206,7 +206,7 @@ public final class OmemoManager extends Manager {
|
|||
*
|
||||
* @param callback trustCallback.
|
||||
*/
|
||||
public void setTrustCallback(TrustCallback callback) {
|
||||
public void setTrustCallback(OmemoTrustCallback callback) {
|
||||
if (trustCallback != null) {
|
||||
throw new IllegalStateException("TrustCallback can only be set once.");
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ public final class OmemoManager extends Manager {
|
|||
* Return the TrustCallback of this manager.
|
||||
* @return
|
||||
*/
|
||||
TrustCallback getTrustCallback() {
|
||||
OmemoTrustCallback getTrustCallback() {
|
||||
return trustCallback;
|
||||
}
|
||||
|
||||
|
@ -266,12 +266,19 @@ public final class OmemoManager extends Manager {
|
|||
});
|
||||
}
|
||||
|
||||
public List<OmemoDevice> getDevicesOf(BareJid recipient) {
|
||||
OmemoCachedDeviceList list = getOmemoService().getOmemoStoreBackend().loadCachedDeviceList(getOwnDevice(), recipient);
|
||||
/**
|
||||
* Return a list 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 list of device of.
|
||||
* @return list of known devices of that contact.
|
||||
*/
|
||||
public List<OmemoDevice> getDevicesOf(BareJid contact) {
|
||||
OmemoCachedDeviceList list = getOmemoService().getOmemoStoreBackend().loadCachedDeviceList(getOwnDevice(), contact);
|
||||
ArrayList<OmemoDevice> devices = new ArrayList<>();
|
||||
|
||||
for (int deviceId : list.getActiveDevices()) {
|
||||
devices.add(new OmemoDevice(recipient, deviceId));
|
||||
devices.add(new OmemoDevice(contact, deviceId));
|
||||
}
|
||||
|
||||
return devices;
|
||||
|
@ -353,7 +360,7 @@ public final class OmemoManager extends Manager {
|
|||
SmackException.NotLoggedInException
|
||||
{
|
||||
synchronized (LOCK) {
|
||||
if (!multiUserChatSupportsOmemo(muc.getRoom())) {
|
||||
if (!multiUserChatSupportsOmemo(muc)) {
|
||||
throw new NoOmemoSupportException();
|
||||
}
|
||||
|
||||
|
@ -492,18 +499,19 @@ public final class OmemoManager extends Manager {
|
|||
* Returns true, if the MUC with the EntityBareJid multiUserChat is non-anonymous and members only (prerequisite
|
||||
* for OMEMO encryption in MUC).
|
||||
*
|
||||
* @param multiUserChat EntityBareJid of the MUC
|
||||
* @param multiUserChat MUC
|
||||
* @return true if chat supports OMEMO
|
||||
* @throws XMPPException.XMPPErrorException if
|
||||
* @throws SmackException.NotConnectedException something
|
||||
* @throws InterruptedException goes
|
||||
* @throws SmackException.NoResponseException wrong
|
||||
*/
|
||||
public boolean multiUserChatSupportsOmemo(EntityBareJid multiUserChat)
|
||||
public boolean multiUserChatSupportsOmemo(MultiUserChat multiUserChat)
|
||||
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
|
||||
SmackException.NoResponseException
|
||||
{
|
||||
RoomInfo roomInfo = MultiUserChatManager.getInstanceFor(connection()).getRoomInfo(multiUserChat);
|
||||
EntityBareJid jid = multiUserChat.getRoom();
|
||||
RoomInfo roomInfo = MultiUserChatManager.getInstanceFor(connection()).getRoomInfo(jid);
|
||||
return roomInfo.isNonanonymous() && roomInfo.isMembersOnly();
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
|||
import org.jivesoftware.smackx.omemo.internal.listener.OmemoCarbonCopyStanzaReceivedListener;
|
||||
import org.jivesoftware.smackx.omemo.internal.listener.OmemoMessageStanzaReceivedListener;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||
import org.jivesoftware.smackx.omemo.trust.TrustCallback;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoTrustCallback;
|
||||
import org.jivesoftware.smackx.omemo.trust.TrustState;
|
||||
import org.jivesoftware.smackx.omemo.util.OmemoConstants;
|
||||
import org.jivesoftware.smackx.omemo.util.OmemoMessageBuilder;
|
||||
|
@ -857,7 +857,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
return devicesWithSessions;
|
||||
}
|
||||
|
||||
private ArrayList<OmemoDevice> getUndecidedDevices(OmemoDevice userDevice, TrustCallback callback, List<OmemoDevice> devices) {
|
||||
private ArrayList<OmemoDevice> getUndecidedDevices(OmemoDevice userDevice, OmemoTrustCallback callback, List<OmemoDevice> devices) {
|
||||
ArrayList<OmemoDevice> undecidedDevices = new ArrayList<>();
|
||||
|
||||
for (OmemoDevice device : devices) {
|
||||
|
@ -880,7 +880,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
return undecidedDevices;
|
||||
}
|
||||
|
||||
private ArrayList<OmemoDevice> getUntrustedDeviced(OmemoDevice userDevice, TrustCallback trustCallback, List<OmemoDevice> devices) {
|
||||
private ArrayList<OmemoDevice> getUntrustedDeviced(OmemoDevice userDevice, OmemoTrustCallback trustCallback, List<OmemoDevice> devices) {
|
||||
ArrayList<OmemoDevice> untrustedDevices = new ArrayList<>();
|
||||
|
||||
for (OmemoDevice device : devices) {
|
||||
|
@ -1060,7 +1060,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
* This is only used for insensitive OMEMO messages like RatchetUpdateMessages.
|
||||
* DO NOT USE THIS FOR ANYTHING ELSE!
|
||||
*/
|
||||
private static final TrustCallback gullibleTrustCallback = new TrustCallback() {
|
||||
private static final OmemoTrustCallback gullibleTrustCallback = new OmemoTrustCallback() {
|
||||
@Override
|
||||
public TrustState getTrust(OmemoDevice device, OmemoFingerprint fingerprint) {
|
||||
return TrustState.trusted;
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.jivesoftware.smackx.omemo.trust;
|
|||
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||
|
||||
public interface TrustCallback {
|
||||
public interface OmemoTrustCallback {
|
||||
|
||||
TrustState getTrust(OmemoDevice device, OmemoFingerprint fingerprint);
|
||||
|
|
@ -17,5 +17,7 @@
|
|||
package org.jivesoftware.smackx.omemo.trust;
|
||||
|
||||
public enum TrustState {
|
||||
undecided, untrusted, trusted
|
||||
undecided, // User has yet to decide, whether the identity is trusted or not.
|
||||
untrusted, // User decided NOT to trust this device.
|
||||
trusted // User decided to trust this device.
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.jivesoftware.smackx.omemo.exceptions.UntrustedOmemoIdentityException;
|
|||
import org.jivesoftware.smackx.omemo.internal.CiphertextTuple;
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||
import org.jivesoftware.smackx.omemo.trust.TrustCallback;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoTrustCallback;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
|
||||
private final OmemoDevice userDevice;
|
||||
private final OmemoRatchet<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_Sess, T_Addr, T_ECPub, T_Bundle, T_Ciph> ratchet;
|
||||
private final TrustCallback trustCallback;
|
||||
private final OmemoTrustCallback trustCallback;
|
||||
|
||||
private byte[] messageKey;
|
||||
private final byte[] initializationVector;
|
||||
|
@ -100,7 +100,7 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
* @throws InvalidAlgorithmParameterException
|
||||
*/
|
||||
public OmemoMessageBuilder(OmemoDevice userDevice,
|
||||
TrustCallback callback,
|
||||
OmemoTrustCallback callback,
|
||||
OmemoRatchet<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_Sess, T_Addr, T_ECPub, T_Bundle, T_Ciph> ratchet,
|
||||
byte[] aesKey,
|
||||
byte[] iv,
|
||||
|
@ -134,7 +134,7 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
* @throws InvalidAlgorithmParameterException
|
||||
*/
|
||||
public OmemoMessageBuilder(OmemoDevice userDevice,
|
||||
TrustCallback callback,
|
||||
OmemoTrustCallback callback,
|
||||
OmemoRatchet<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_Sess, T_Addr, T_ECPub, T_Bundle, T_Ciph> ratchet,
|
||||
String message)
|
||||
throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException,
|
||||
|
|
|
@ -18,11 +18,8 @@ package org.jivesoftware.smackx.omemo;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -34,13 +31,6 @@ public class OmemoConfigurationTest {
|
|||
@Test
|
||||
public void omemoConfigurationTest() {
|
||||
@SuppressWarnings("unused") OmemoConfiguration configuration = new OmemoConfiguration();
|
||||
// Default Store Path
|
||||
File storePath = new File("test");
|
||||
assertNull("getFileBasedOmemoStoreDefaultPath MUST return null at this point.",
|
||||
OmemoConfiguration.getFileBasedOmemoStoreDefaultPath());
|
||||
OmemoConfiguration.setFileBasedOmemoStoreDefaultPath(storePath);
|
||||
assertEquals("FileBasedOmemoStoreDefaultPath must equal the one we set.", storePath.getAbsolutePath(),
|
||||
OmemoConfiguration.getFileBasedOmemoStoreDefaultPath().getAbsolutePath());
|
||||
|
||||
// Body hint
|
||||
OmemoConfiguration.setAddOmemoHintBody(false);
|
||||
|
|
|
@ -20,13 +20,13 @@ import java.util.HashMap;
|
|||
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||
import org.jivesoftware.smackx.omemo.trust.TrustCallback;
|
||||
import org.jivesoftware.smackx.omemo.trust.OmemoTrustCallback;
|
||||
import org.jivesoftware.smackx.omemo.trust.TrustState;
|
||||
|
||||
/**
|
||||
* Ephemera Trust Callback used to make trust decisions in tests.
|
||||
*/
|
||||
public class EphemeralTrustCallback implements TrustCallback {
|
||||
public class EphemeralTrustCallback implements OmemoTrustCallback {
|
||||
|
||||
private final HashMap<OmemoDevice, HashMap<OmemoFingerprint, TrustState>> trustStates = new HashMap<>();
|
||||
|
||||
|
|
Loading…
Reference in a new issue