mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-05 20:51:07 +01:00
Rework support for XEP-0384: OMEMO Encryption
Changes:
Rework integration tests
New structure of base integration test classes
bump dependency on signal-protocol-java from 2.4.0 to 2.6.2
Introduced CachingOmemoStore implementations
Use CachingOmemoStore classes in integration tests
Removed OmemoSession classes (replaced with more logical OmemoRatchet classes)
Consequently also removed load/storeOmemoSession methods from OmemoStore
Removed some clutter from KeyUtil classes
Moved trust decision related code from OmemoStore to TrustCallback
Require authenticated connection for many functions
Add async initialization function in OmemoStore
Refactor omemo test package (/java/org/jivesoftware/smack/omemo -> /java/org/jivesoftware/smackx)
Remove OmemoStore method isFreshInstallation() as well as defaultDeviceId related stuff
FileBasedOmemoStore: Add cleaner methods to store/load base data types (Using tryWithResource, only for future releases, once Android API gets bumped)
Attempt to make OmemoManager thread safe
new logic for getInstanceFor() deviceId determination
OmemoManagers encrypt methods now don't throw exceptions when encryption for some devices fails. Instead message gets encrypted when possible and more information about failures gets returned alongside the message itself
Added OmemoMessage class for that purpose
Reworked entire OmemoService class
Use safer logic for creating trust-ignoring messages (like ratchet-update messages)
Restructure elements/provider in order to prepare for OMEMO namespace bumps
Remove OmemoManager.regenerate() methods in favor of getInstanceFor(connection, randomDeviceId)
Removed some unnecessary configuration options
Prepare for support of more AES message key types
Simplify session creation
Where possible, avoid side effects in methods
Add UntrustedOmemoIdentityException
Add TrustState enum
More improved tests
This commit is contained in:
parent
f290197f6a
commit
1f731f6318
96 changed files with 6915 additions and 5488 deletions
|
|
@ -1,91 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* This file is part of smack-omemo-signal.
|
||||
*
|
||||
* smack-omemo-signal is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.jivesoftware.smack.omemo;
|
||||
|
||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.CIPHERMODE;
|
||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYTYPE;
|
||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.PROVIDER;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.Security;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.util.OmemoMessageBuilder;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.junit.Test;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.SessionCipher;
|
||||
import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.state.PreKeyBundle;
|
||||
import org.whispersystems.libsignal.state.PreKeyRecord;
|
||||
import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||
|
||||
/**
|
||||
* Test the OmemoMessageBuilder.
|
||||
*/
|
||||
public class OmemoMessageBuilderTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void setTextTest() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidKeyException {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
String message = "Hello World!";
|
||||
byte[] key = OmemoMessageBuilder.generateKey();
|
||||
byte[] iv = OmemoMessageBuilder.generateIv();
|
||||
|
||||
SecretKey secretKey = new SecretKeySpec(key, KEYTYPE);
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||
Cipher cipher = Cipher.getInstance(CIPHERMODE, PROVIDER);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);
|
||||
|
||||
OmemoMessageBuilder<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher>
|
||||
mb = new OmemoMessageBuilder<>(null, null, key, iv);
|
||||
mb.setMessage(message);
|
||||
|
||||
byte[] expected = cipher.doFinal(message.getBytes(StringUtils.UTF8));
|
||||
byte[] messageKey = new byte[16];
|
||||
System.arraycopy(mb.getMessageKey(),0, messageKey, 0, 16);
|
||||
byte[] messagePlusTag = new byte[mb.getCiphertextMessage().length + 16];
|
||||
System.arraycopy(mb.getCiphertextMessage(),0,messagePlusTag,0,mb.getCiphertextMessage().length);
|
||||
System.arraycopy(mb.getMessageKey(), 16, messagePlusTag, mb.getCiphertextMessage().length, 16);
|
||||
|
||||
assertArrayEquals(key, messageKey);
|
||||
assertArrayEquals(expected, messagePlusTag);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,218 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* This file is part of smack-omemo-signal.
|
||||
*
|
||||
* smack-omemo-signal is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.jivesoftware.smack.omemo;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.FileBasedOmemoStore;
|
||||
import org.jivesoftware.smackx.omemo.OmemoConfiguration;
|
||||
import org.jivesoftware.smackx.omemo.OmemoManager;
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
||||
import org.jivesoftware.smackx.omemo.internal.CachedDeviceList;
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||
import org.jivesoftware.smackx.omemo.signal.SignalFileBasedOmemoStore;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||
|
||||
/**
|
||||
* Test the file-based signalOmemoStore.
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({OmemoManager.class})
|
||||
public class SignalFileBasedOmemoStoreTest {
|
||||
|
||||
private static File storePath;
|
||||
private static SignalFileBasedOmemoStore omemoStore;
|
||||
private static OmemoManager omemoManager;
|
||||
|
||||
|
||||
private void deleteStore() {
|
||||
FileBasedOmemoStore.deleteDirectory(storePath);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws XmppStringprepException {
|
||||
String userHome = System.getProperty("user.home");
|
||||
if (userHome != null) {
|
||||
File f = new File(userHome);
|
||||
storePath = new File(f, ".config/smack-integration-test/store");
|
||||
} else {
|
||||
storePath = new File("int_test_omemo_store");
|
||||
}
|
||||
|
||||
OmemoConfiguration.setFileBasedOmemoStoreDefaultPath(storePath);
|
||||
omemoStore = new SignalFileBasedOmemoStore();
|
||||
|
||||
OmemoDevice device = new OmemoDevice(JidCreate.bareFrom("storeTest@server.tld"), 55155);
|
||||
omemoManager = PowerMockito.mock(OmemoManager.class);
|
||||
when(omemoManager.getDeviceId()).thenReturn(device.getDeviceId());
|
||||
when(omemoManager.getOwnJid()).thenReturn(device.getJid());
|
||||
when(omemoManager.getOwnDevice()).thenReturn(device);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
deleteStore();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
deleteStore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFreshInstallationTest() {
|
||||
assertTrue(omemoStore.isFreshInstallation(omemoManager));
|
||||
omemoStore.storeOmemoIdentityKeyPair(omemoManager, omemoStore.generateOmemoIdentityKeyPair());
|
||||
assertFalse(omemoStore.isFreshInstallation(omemoManager));
|
||||
omemoStore.purgeOwnDeviceKeys(omemoManager);
|
||||
assertTrue(omemoStore.isFreshInstallation(omemoManager));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultDeviceIdTest() throws XmppStringprepException {
|
||||
assertEquals(-1, omemoStore.getDefaultDeviceId(omemoManager.getOwnJid()));
|
||||
omemoStore.setDefaultDeviceId(omemoManager.getOwnJid(), 55);
|
||||
assertEquals(55, omemoStore.getDefaultDeviceId(omemoManager.getOwnJid()));
|
||||
assertEquals(-1, omemoStore.getDefaultDeviceId(JidCreate.bareFrom("randomGuy@server.tld")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cachedDeviceListTest() throws XmppStringprepException {
|
||||
OmemoDevice bob = new OmemoDevice(JidCreate.bareFrom("bob@builder.tv"), 666);
|
||||
OmemoDevice craig = new OmemoDevice(JidCreate.bareFrom("craig@southpark.tv"), 3333333);
|
||||
|
||||
CachedDeviceList bobsList = new CachedDeviceList();
|
||||
assertEquals(0, bobsList.getAllDevices().size());
|
||||
bobsList.getActiveDevices().add(bob.getDeviceId());
|
||||
bobsList.getActiveDevices().add(777);
|
||||
bobsList.getInactiveDevices().add(888);
|
||||
|
||||
CachedDeviceList craigsList = new CachedDeviceList();
|
||||
craigsList.addDevice(craig.getDeviceId());
|
||||
|
||||
assertEquals(3, bobsList.getAllDevices().size());
|
||||
assertEquals(2, bobsList.getActiveDevices().size());
|
||||
assertTrue(bobsList.getInactiveDevices().contains(888));
|
||||
assertTrue(bobsList.getActiveDevices().contains(777));
|
||||
assertTrue(bobsList.getAllDevices().contains(888));
|
||||
|
||||
assertEquals(0, craigsList.getInactiveDevices().size());
|
||||
assertEquals(1, craigsList.getActiveDevices().size());
|
||||
assertEquals(1, craigsList.getAllDevices().size());
|
||||
assertEquals(craig.getDeviceId(), craigsList.getActiveDevices().iterator().next().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void omemoIdentityKeyPairTest() throws CorruptedOmemoKeyException {
|
||||
assertNull(omemoStore.loadOmemoIdentityKeyPair(omemoManager));
|
||||
omemoStore.storeOmemoIdentityKeyPair(omemoManager, omemoStore.generateOmemoIdentityKeyPair());
|
||||
IdentityKeyPair ikp = omemoStore.loadOmemoIdentityKeyPair(omemoManager);
|
||||
assertNotNull(ikp);
|
||||
|
||||
assertTrue(omemoStore.keyUtil().getFingerprint(ikp.getPublicKey()).equals(omemoStore.getFingerprint(omemoManager)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signedPreKeyTest() throws CorruptedOmemoKeyException {
|
||||
assertEquals(0, omemoStore.loadOmemoSignedPreKeys(omemoManager).size());
|
||||
IdentityKeyPair ikp = omemoStore.generateOmemoIdentityKeyPair();
|
||||
SignedPreKeyRecord spk = omemoStore.generateOmemoSignedPreKey(ikp, 14);
|
||||
omemoStore.storeOmemoSignedPreKey(omemoManager, 14, spk);
|
||||
assertEquals(1, omemoStore.loadOmemoSignedPreKeys(omemoManager).size());
|
||||
assertNotNull(omemoStore.loadOmemoSignedPreKey(omemoManager, 14));
|
||||
assertArrayEquals(spk.serialize(), omemoStore.loadOmemoSignedPreKey(omemoManager, 14).serialize());
|
||||
assertNull(omemoStore.loadOmemoSignedPreKey(omemoManager, 13));
|
||||
assertEquals(0, omemoStore.loadCurrentSignedPreKeyId(omemoManager));
|
||||
omemoStore.storeCurrentSignedPreKeyId(omemoManager, 15);
|
||||
assertEquals(15, omemoStore.loadCurrentSignedPreKeyId(omemoManager));
|
||||
omemoStore.removeOmemoSignedPreKey(omemoManager, 14);
|
||||
assertNull(omemoStore.loadOmemoSignedPreKey(omemoManager, 14));
|
||||
|
||||
assertNull(omemoStore.getDateOfLastSignedPreKeyRenewal(omemoManager));
|
||||
Date now = new Date();
|
||||
omemoStore.setDateOfLastSignedPreKeyRenewal(omemoManager, now);
|
||||
assertEquals(now, omemoStore.getDateOfLastSignedPreKeyRenewal(omemoManager));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preKeyTest() {
|
||||
assertEquals(0, omemoStore.loadOmemoPreKeys(omemoManager).size());
|
||||
assertNull(omemoStore.loadOmemoPreKey(omemoManager, 12));
|
||||
omemoStore.storeOmemoPreKeys(omemoManager,
|
||||
omemoStore.generateOmemoPreKeys(1, 20));
|
||||
assertNotNull(omemoStore.loadOmemoPreKey(omemoManager, 12));
|
||||
assertEquals(20, omemoStore.loadOmemoPreKeys(omemoManager).size());
|
||||
omemoStore.removeOmemoPreKey(omemoManager, 12);
|
||||
assertNull(omemoStore.loadOmemoPreKey(omemoManager, 12));
|
||||
assertEquals(19, omemoStore.loadOmemoPreKeys(omemoManager).size());
|
||||
|
||||
assertEquals(0, omemoStore.loadLastPreKeyId(omemoManager));
|
||||
omemoStore.storeLastPreKeyId(omemoManager, 35);
|
||||
assertEquals(35, omemoStore.loadLastPreKeyId(omemoManager));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trustingTest() throws XmppStringprepException, CorruptedOmemoKeyException {
|
||||
OmemoDevice bob = new OmemoDevice(JidCreate.bareFrom("bob@builder.tv"), 555);
|
||||
IdentityKey bobsKey = omemoStore.generateOmemoIdentityKeyPair().getPublicKey();
|
||||
assertFalse(omemoStore.isDecidedOmemoIdentity(omemoManager, bob, bobsKey));
|
||||
assertFalse(omemoStore.isTrustedOmemoIdentity(omemoManager, bob, bobsKey));
|
||||
omemoStore.trustOmemoIdentity(omemoManager, bob, bobsKey);
|
||||
assertTrue(omemoStore.isDecidedOmemoIdentity(omemoManager, bob, omemoStore.keyUtil().getFingerprint(bobsKey)));
|
||||
assertTrue(omemoStore.isTrustedOmemoIdentity(omemoManager, bob, omemoStore.keyUtil().getFingerprint(bobsKey)));
|
||||
assertNull(omemoStore.loadOmemoIdentityKey(omemoManager, bob));
|
||||
omemoStore.storeOmemoIdentityKey(omemoManager, bob, bobsKey);
|
||||
assertNotNull(omemoStore.loadOmemoIdentityKey(omemoManager, bob));
|
||||
IdentityKey bobsOtherKey = omemoStore.generateOmemoIdentityKeyPair().getPublicKey();
|
||||
assertFalse(omemoStore.isTrustedOmemoIdentity(omemoManager, bob, bobsOtherKey));
|
||||
assertFalse(omemoStore.isDecidedOmemoIdentity(omemoManager, bob, bobsOtherKey));
|
||||
omemoStore.distrustOmemoIdentity(omemoManager, bob, omemoStore.keyUtil().getFingerprint(bobsKey));
|
||||
assertTrue(omemoStore.isDecidedOmemoIdentity(omemoManager, bob, bobsKey));
|
||||
assertFalse(omemoStore.isTrustedOmemoIdentity(omemoManager, bob, bobsKey));
|
||||
|
||||
assertNull(omemoStore.getDateOfLastReceivedMessage(omemoManager, bob));
|
||||
Date now = new Date();
|
||||
omemoStore.setDateOfLastReceivedMessage(omemoManager, bob, now);
|
||||
assertEquals(now, omemoStore.getDateOfLastReceivedMessage(omemoManager, bob));
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* This file is part of smack-omemo-signal.
|
||||
*
|
||||
* smack-omemo-signal is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.jivesoftware.smackx.omemo;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertNotSame;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static junit.framework.TestCase.fail;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
||||
import org.jivesoftware.smackx.omemo.signal.SignalOmemoKeyUtil;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||
|
||||
/**
|
||||
* Test SignalOmemoKeyUtil methods.
|
||||
*
|
||||
* @author Paul Schaub
|
||||
*/
|
||||
public class LegacySignalOmemoKeyUtilTest extends SmackTestSuite {
|
||||
|
||||
private final SignalOmemoKeyUtil keyUtil = new SignalOmemoKeyUtil();
|
||||
|
||||
@Test
|
||||
public void omemoIdentityKeyPairSerializationTest() throws CorruptedOmemoKeyException {
|
||||
IdentityKeyPair ikp = keyUtil.generateOmemoIdentityKeyPair();
|
||||
byte[] bytes = keyUtil.identityKeyPairToBytes(ikp);
|
||||
assertNotNull("serialized identityKeyPair must not be null.",
|
||||
bytes);
|
||||
assertNotSame("serialized identityKeyPair must not be of length 0.",
|
||||
0, bytes.length);
|
||||
|
||||
IdentityKeyPair ikp2 = keyUtil.identityKeyPairFromBytes(bytes);
|
||||
assertTrue("Deserialized IdentityKeyPairs PublicKey must equal the originals one.",
|
||||
ikp.getPublicKey().equals(ikp2.getPublicKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void omemoIdentityKeySerializationTest() {
|
||||
IdentityKey k = keyUtil.generateOmemoIdentityKeyPair().getPublicKey();
|
||||
|
||||
try {
|
||||
assertEquals("Deserialized IdentityKey must equal the original one.",
|
||||
k, keyUtil.identityKeyFromBytes(keyUtil.identityKeyToBytes(k)));
|
||||
} catch (CorruptedOmemoKeyException e) {
|
||||
fail("Caught exception while serializing and deserializing identityKey (" + e + "): " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateOmemoSignedPreKeyTest() {
|
||||
IdentityKeyPair ikp = keyUtil.generateOmemoIdentityKeyPair();
|
||||
try {
|
||||
SignedPreKeyRecord spk = keyUtil.generateOmemoSignedPreKey(ikp, 1);
|
||||
assertNotNull("SignedPreKey must not be null.", spk);
|
||||
assertEquals("SignedPreKeyId must match.", 1, spk.getId());
|
||||
assertEquals("singedPreKeyId must match here also.", 1, keyUtil.signedPreKeyIdFromKey(spk));
|
||||
} catch (CorruptedOmemoKeyException e) {
|
||||
fail("Caught an exception while generating signedPreKey (" + e + "): " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFingerprintTest() {
|
||||
IdentityKeyPair ikp = keyUtil.generateOmemoIdentityKeyPair();
|
||||
IdentityKey ik = ikp.getPublicKey();
|
||||
assertTrue("Length of fingerprint must be 64.",
|
||||
keyUtil.getFingerprintOfIdentityKey(ik).length() == 64);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* This file is part of smack-omemo-signal.
|
||||
*
|
||||
* smack-omemo-signal is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.jivesoftware.smackx.omemo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.signal.SignalOmemoKeyUtil;
|
||||
import org.jivesoftware.smackx.omemo.util.OmemoKeyUtil;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.state.PreKeyBundle;
|
||||
import org.whispersystems.libsignal.state.PreKeyRecord;
|
||||
import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||
|
||||
/**
|
||||
* smack-omemo-signal implementation of {@link OmemoKeyUtilTest}.
|
||||
* This class executes tests of its super class with available implementations of {@link OmemoKeyUtil}.
|
||||
* So far this includes {@link SignalOmemoKeyUtil}.
|
||||
*/
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class SignalOmemoKeyUtilTest
|
||||
extends OmemoKeyUtilTest<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, ECPublicKey, PreKeyBundle> {
|
||||
|
||||
public SignalOmemoKeyUtilTest(OmemoKeyUtil<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, ECPublicKey, PreKeyBundle> keyUtil) {
|
||||
super(keyUtil);
|
||||
}
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> getParameters() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ new SignalOmemoKeyUtil()}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.jivesoftware.smack.omemo;
|
||||
package org.jivesoftware.smackx.omemo;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
|
|
@ -26,26 +26,11 @@ import static junit.framework.TestCase.assertNotNull;
|
|||
import static junit.framework.TestCase.assertNotSame;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
|
||||
import org.jivesoftware.smack.DummyConnection;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.OmemoManager;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoElement;
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
||||
import org.jivesoftware.smackx.omemo.provider.OmemoVAxolotlProvider;
|
||||
import org.jivesoftware.smackx.omemo.signal.SignalOmemoService;
|
||||
|
||||
|
|
@ -54,10 +39,10 @@ import org.junit.Test;
|
|||
/**
|
||||
* Test OmemoManager functionality.
|
||||
*/
|
||||
public class OmemoManagerTest extends SmackTestSuite {
|
||||
public class SignalOmemoManagerTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void instantiationTest() throws CorruptedOmemoKeyException, NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException, InterruptedException, XMPPException.XMPPErrorException, NoSuchPaddingException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchProviderException, IllegalBlockSizeException, SmackException {
|
||||
public void instantiationTest() {
|
||||
SignalOmemoService.acknowledgeLicense();
|
||||
SignalOmemoService.setup();
|
||||
|
||||
|
|
@ -73,8 +58,8 @@ public class OmemoManagerTest extends SmackTestSuite {
|
|||
assertNotNull(c);
|
||||
assertNotNull(d);
|
||||
|
||||
assertEquals(123, a.getDeviceId());
|
||||
assertEquals(234, b.getDeviceId());
|
||||
assertEquals(Integer.valueOf(123), a.getDeviceId());
|
||||
assertEquals(Integer.valueOf(234), b.getDeviceId());
|
||||
|
||||
assertFalse(a == b);
|
||||
assertFalse(a == c);
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.jivesoftware.smack.omemo;
|
||||
package org.jivesoftware.smackx.omemo;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
|
@ -41,6 +41,6 @@ public class SignalOmemoStoreConnectorTest {
|
|||
@Test
|
||||
public void isTrustedIdentityTest() {
|
||||
SignalOmemoStoreConnector connector = new SignalOmemoStoreConnector(null, null);
|
||||
assertTrue("All identities must be trusted by default.", connector.isTrustedIdentity(null, null));
|
||||
assertTrue("All identities must be trusted by default.", connector.isTrustedIdentity(null, null, null));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
*
|
||||
* This file is part of smack-omemo-signal.
|
||||
*
|
||||
* smack-omemo-signal is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.jivesoftware.smackx.omemo;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.signal.SignalCachingOmemoStore;
|
||||
import org.jivesoftware.smackx.omemo.signal.SignalFileBasedOmemoStore;
|
||||
import org.jivesoftware.smackx.omemo.signal.SignalOmemoKeyUtil;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
import org.whispersystems.libsignal.SessionCipher;
|
||||
import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||
import org.whispersystems.libsignal.ecc.ECPublicKey;
|
||||
import org.whispersystems.libsignal.state.PreKeyBundle;
|
||||
import org.whispersystems.libsignal.state.PreKeyRecord;
|
||||
import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||
|
||||
/**
|
||||
* smack-omemo-signal implementation of {@link OmemoStoreTest}.
|
||||
* This class executes tests of its super class with available implementations of {@link OmemoStore}.
|
||||
* So far this includes {@link SignalFileBasedOmemoStore}, {@link SignalCachingOmemoStore}.
|
||||
*/
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class SignalOmemoStoreTest extends OmemoStoreTest<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher> {
|
||||
|
||||
public SignalOmemoStoreTest(OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord, SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher> store)
|
||||
throws XmppStringprepException {
|
||||
super(store);
|
||||
}
|
||||
|
||||
/**
|
||||
* We are running this Test with multiple available OmemoStore implementations.
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> getParameters() throws IOException {
|
||||
TemporaryFolder temp = initStaticTemp();
|
||||
return Arrays.asList(new Object[][] {
|
||||
// Simple file based store
|
||||
{ new SignalFileBasedOmemoStore(temp.newFolder("sigFileBased"))},
|
||||
// Ephemeral caching store
|
||||
{ new SignalCachingOmemoStore()},
|
||||
// Caching file based store
|
||||
{ new SignalCachingOmemoStore(new SignalFileBasedOmemoStore(temp.newFolder("cachingSigFileBased")))}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keyUtilTest() {
|
||||
assertTrue(store.keyUtil() instanceof SignalOmemoKeyUtil);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue