mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-27 05:03:28 +00:00
Replace pinstretcher with Argon2 and new PIN encryption.
This commit is contained in:
committed by
Greyson Parrelli
parent
f7a3bb2ae8
commit
e37c4b1f87
@@ -1,10 +1,12 @@
|
||||
package org.thoughtcrime.securesms.registration.v2;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.registration.v2.testdata.KbsTestVector;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException;
|
||||
import org.whispersystems.signalservice.api.kbs.HashedPin;
|
||||
import org.whispersystems.signalservice.api.kbs.KbsData;
|
||||
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
||||
import org.whispersystems.signalservice.internal.util.JsonUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -12,17 +14,17 @@ import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.thoughtcrime.securesms.testutil.SecureRandomTestUtil.mockRandom;
|
||||
|
||||
public final class HashedPinKbsDataTest {
|
||||
|
||||
@Test
|
||||
public void vectors_createNewKbsData() throws IOException {
|
||||
for (KbsTestVector vector : getKbsTestVectorList().getVectors()) {
|
||||
for (KbsTestVector vector : getKbsTestVectorList()) {
|
||||
HashedPin hashedPin = HashedPin.fromArgon2Hash(vector.getArgon2Hash());
|
||||
|
||||
KbsData kbsData = hashedPin.createNewKbsData(mockRandom(vector.getMasterKey()));
|
||||
KbsData kbsData = hashedPin.createNewKbsData(MasterKey.createNew(mockRandom(vector.getMasterKey())));
|
||||
|
||||
assertArrayEquals(vector.getMasterKey(), kbsData.getMasterKey().serialize());
|
||||
assertArrayEquals(vector.getIvAndCipher(), kbsData.getCipherText());
|
||||
@@ -33,7 +35,7 @@ public final class HashedPinKbsDataTest {
|
||||
|
||||
@Test
|
||||
public void vectors_decryptKbsDataIVCipherText() throws IOException, InvalidCiphertextException {
|
||||
for (KbsTestVector vector : getKbsTestVectorList().getVectors()) {
|
||||
for (KbsTestVector vector : getKbsTestVectorList()) {
|
||||
HashedPin hashedPin = HashedPin.fromArgon2Hash(vector.getArgon2Hash());
|
||||
|
||||
KbsData kbsData = hashedPin.decryptKbsDataIVCipherText(vector.getIvAndCipher());
|
||||
@@ -45,12 +47,12 @@ public final class HashedPinKbsDataTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static KbsTestVectorList getKbsTestVectorList() throws IOException {
|
||||
private static KbsTestVector[] getKbsTestVectorList() throws IOException {
|
||||
try (InputStream resourceAsStream = ClassLoader.getSystemClassLoader().getResourceAsStream("data/kbs_vectors.json")) {
|
||||
|
||||
KbsTestVectorList data = JsonUtil.fromJson(Util.readFullyAsString(resourceAsStream), KbsTestVectorList.class);
|
||||
KbsTestVector[] data = JsonUtil.fromJson(Util.readFullyAsString(resourceAsStream), KbsTestVector[].class);
|
||||
|
||||
assertFalse(data.getVectors().isEmpty());
|
||||
assertTrue(data.length > 0);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package org.thoughtcrime.securesms.registration.v2;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class KbsTestVectorList {
|
||||
|
||||
@JsonProperty("vectors")
|
||||
private List<KbsTestVector> vectors;
|
||||
|
||||
public List<KbsTestVector> getVectors() {
|
||||
return vectors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.thoughtcrime.securesms.registration.v2;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.registration.v2.testdata.PinSanitationVector;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.internal.registrationpin.PinHasher;
|
||||
import org.whispersystems.signalservice.internal.util.Hex;
|
||||
import org.whispersystems.signalservice.internal.util.JsonUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public final class PinHasher_normalize_Test {
|
||||
|
||||
@Test
|
||||
public void vectors_normalize() throws IOException {
|
||||
for (PinSanitationVector vector : getKbsPinSanitationTestVectorList()) {
|
||||
byte[] normalized = PinHasher.normalize(vector.getPin());
|
||||
|
||||
if (!Arrays.equals(vector.getBytes(), normalized)) {
|
||||
assertEquals(String.format("%s [%s]", vector.getName(), vector.getPin()),
|
||||
Hex.toStringCondensed(vector.getBytes()),
|
||||
Hex.toStringCondensed(normalized));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PinSanitationVector[] getKbsPinSanitationTestVectorList() throws IOException {
|
||||
try (InputStream resourceAsStream = ClassLoader.getSystemClassLoader().getResourceAsStream("data/kbs_pin_normalization_vectors.json")) {
|
||||
|
||||
PinSanitationVector[] data = JsonUtil.fromJson(Util.readFullyAsString(resourceAsStream), PinSanitationVector[].class);
|
||||
|
||||
assertTrue(data.length > 0);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.thoughtcrime.securesms.registration.v2;
|
||||
package org.thoughtcrime.securesms.registration.v2.testdata;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
31
app/src/test/java/org/thoughtcrime/securesms/registration/v2/testdata/PinSanitationVector.java
vendored
Normal file
31
app/src/test/java/org/thoughtcrime/securesms/registration/v2/testdata/PinSanitationVector.java
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package org.thoughtcrime.securesms.registration.v2.testdata;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
|
||||
import org.thoughtcrime.securesms.testutil.HexDeserializer;
|
||||
|
||||
public class PinSanitationVector {
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("pin")
|
||||
private String pin;
|
||||
|
||||
@JsonProperty("bytes")
|
||||
@JsonDeserialize(using = HexDeserializer.class)
|
||||
private byte[] bytes;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPin() {
|
||||
return pin;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user