Versioned Profiles support (disabled).

This commit is contained in:
Alan Evans
2020-02-10 18:40:22 -05:00
committed by Greyson Parrelli
parent f10d1eac61
commit 7ecb50a3fe
67 changed files with 1200 additions and 321 deletions

View File

@@ -4,6 +4,8 @@ package org.whispersystems.signalservice.api.crypto;
import junit.framework.TestCase;
import org.conscrypt.Conscrypt;
import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.profiles.ProfileKey;
import org.whispersystems.signalservice.internal.util.Util;
import java.io.ByteArrayInputStream;
@@ -16,8 +18,8 @@ public class ProfileCipherTest extends TestCase {
Security.insertProviderAt(Conscrypt.newProvider(), 1);
}
public void testEncryptDecrypt() throws InvalidCiphertextException {
byte[] key = Util.getSecretBytes(32);
public void testEncryptDecrypt() throws InvalidCiphertextException, InvalidInputException {
ProfileKey key = new ProfileKey(Util.getSecretBytes(32));
ProfileCipher cipher = new ProfileCipher(key);
byte[] name = cipher.encryptName("Clement\0Duval".getBytes(), ProfileCipher.NAME_PADDED_LENGTH);
byte[] plaintext = cipher.decryptName(name);
@@ -25,7 +27,7 @@ public class ProfileCipherTest extends TestCase {
}
public void testEmpty() throws Exception {
byte[] key = Util.getSecretBytes(32);
ProfileKey key = new ProfileKey(Util.getSecretBytes(32));
ProfileCipher cipher = new ProfileCipher(key);
byte[] name = cipher.encryptName("".getBytes(), 26);
byte[] plaintext = cipher.decryptName(name);
@@ -34,7 +36,7 @@ public class ProfileCipherTest extends TestCase {
}
public void testStreams() throws Exception {
byte[] key = Util.getSecretBytes(32);
ProfileKey key = new ProfileKey(Util.getSecretBytes(32));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ProfileCipherOutputStream out = new ProfileCipherOutputStream(baos, key);

View File

@@ -3,6 +3,8 @@ package org.whispersystems.signalservice.api.crypto;
import junit.framework.TestCase;
import org.conscrypt.OpenSSLProvider;
import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.profiles.ProfileKey;
import java.security.Security;
import java.util.Arrays;
@@ -15,11 +17,11 @@ public class UnidentifiedAccessTest extends TestCase {
private final byte[] EXPECTED_RESULT = {(byte)0x5a, (byte)0x72, (byte)0x3a, (byte)0xce, (byte)0xe5, (byte)0x2c, (byte)0x5e, (byte)0xa0, (byte)0x2b, (byte)0x92, (byte)0xa3, (byte)0xa3, (byte)0x60, (byte)0xc0, (byte)0x95, (byte)0x95};
public void testKeyDerivation() {
public void testKeyDerivation() throws InvalidInputException {
byte[] key = new byte[32];
Arrays.fill(key, (byte)0x02);
byte[] result = UnidentifiedAccess.deriveAccessKeyFrom(key);
byte[] result = UnidentifiedAccess.deriveAccessKeyFrom(new ProfileKey(key));
assertTrue(Arrays.equals(result, EXPECTED_RESULT));
}

View File

@@ -0,0 +1,53 @@
package org.whispersystems.signalservice.api.util;
import org.junit.Test;
import org.whispersystems.libsignal.util.guava.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public final class OptionalUtilTest {
@Test
public void absent_are_equal() {
assertTrue(OptionalUtil.byteArrayEquals(Optional.<byte[]>absent(), Optional.<byte[]>absent()));
}
@Test
public void first_non_absent_not_equal() {
assertFalse(OptionalUtil.byteArrayEquals(Optional.of(new byte[1]), Optional.<byte[]>absent()));
}
@Test
public void second_non_absent_not_equal() {
assertFalse(OptionalUtil.byteArrayEquals(Optional.<byte[]>absent(), Optional.of(new byte[1])));
}
@Test
public void equal_contents() {
byte[] contentsA = new byte[]{1, 2, 3};
byte[] contentsB = contentsA.clone();
Optional<byte[]> a = Optional.of(contentsA);
Optional<byte[]> b = Optional.of(contentsB);
assertTrue(OptionalUtil.byteArrayEquals(a, b));
assertEquals(OptionalUtil.byteArrayHashCode(a), OptionalUtil.byteArrayHashCode(b));
}
@Test
public void in_equal_contents() {
byte[] contentsA = new byte[]{1, 2, 3};
byte[] contentsB = new byte[]{4, 5, 6};
Optional<byte[]> a = Optional.of(contentsA);
Optional<byte[]> b = Optional.of(contentsB);
assertFalse(OptionalUtil.byteArrayEquals(a, b));
assertNotEquals(OptionalUtil.byteArrayHashCode(a), OptionalUtil.byteArrayHashCode(b));
}
@Test
public void hash_code_absent() {
assertEquals(0, OptionalUtil.byteArrayHashCode(Optional.<byte[]>absent()));
}
}