Use the same VaultParams encoding as the server side

Change-Id: I99887f2e52c24726b40fa4cfedc0a1854490160f
Test: adb shell am instrument -w -e package
com.android.server.locksettings.recoverablekeystore
com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
This commit is contained in:
Bo Zhu
2018-01-04 00:11:35 -08:00
parent 5ec9db0e8d
commit 328f0b849e
2 changed files with 20 additions and 19 deletions

View File

@@ -298,8 +298,8 @@ public class KeySyncUtils {
.order(ByteOrder.LITTLE_ENDIAN)
.put(SecureBox.encodePublicKey(thmPublicKey))
.putLong(counterId)
.putInt(maxAttempts)
.putLong(deviceId)
.putInt(maxAttempts)
.array();
}

View File

@@ -386,23 +386,7 @@ public class KeySyncUtilsTest {
}
@Test
public void packVaultParams_encodesMaxAttemptsAsThirdParam() throws Exception {
int maxAttempts = 10;
byte[] packedForm = KeySyncUtils.packVaultParams(
SecureBox.genKeyPair().getPublic(),
/*counterId=*/ 1001L,
maxAttempts,
/*deviceId=*/ 1L);
ByteBuffer byteBuffer = ByteBuffer.wrap(packedForm)
.order(ByteOrder.LITTLE_ENDIAN);
byteBuffer.position(PUBLIC_KEY_LENGTH_BYTES + Long.BYTES);
assertEquals(maxAttempts, byteBuffer.getInt());
}
@Test
public void packVaultParams_encodesDeviceIdAsLastParam() throws Exception {
public void packVaultParams_encodesDeviceIdAsThirdParam() throws Exception {
long deviceId = 102942158152L;
byte[] packedForm = KeySyncUtils.packVaultParams(
@@ -413,10 +397,27 @@ public class KeySyncUtilsTest {
ByteBuffer byteBuffer = ByteBuffer.wrap(packedForm)
.order(ByteOrder.LITTLE_ENDIAN);
byteBuffer.position(PUBLIC_KEY_LENGTH_BYTES + Long.BYTES + Integer.BYTES);
byteBuffer.position(PUBLIC_KEY_LENGTH_BYTES + Long.BYTES);
assertEquals(deviceId, byteBuffer.getLong());
}
@Test
public void packVaultParams_encodesMaxAttemptsAsLastParam() throws Exception {
int maxAttempts = 10;
byte[] packedForm = KeySyncUtils.packVaultParams(
SecureBox.genKeyPair().getPublic(),
/*counterId=*/ 1001L,
maxAttempts,
/*deviceId=*/ 1L);
ByteBuffer byteBuffer = ByteBuffer.wrap(packedForm)
.order(ByteOrder.LITTLE_ENDIAN);
byteBuffer.position(PUBLIC_KEY_LENGTH_BYTES + 2 * Long.BYTES);
assertEquals(maxAttempts, byteBuffer.getInt());
}
private static byte[] randomBytes(int n) {
byte[] bytes = new byte[n];
new Random().nextBytes(bytes);