diff options
| author | 2018-01-04 00:11:35 -0800 | |
|---|---|---|
| committer | 2018-01-04 00:12:22 -0800 | |
| commit | 328f0b849e06f3eb0d007ce441a734c36e6f668f (patch) | |
| tree | 36371c6f98f680feb7cd4b74507c3b35c69a60be | |
| parent | 5ec9db0e8da47f3a91b9d15048891afdbf5dfd75 (diff) | |
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
2 files changed, 15 insertions, 14 deletions
diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/KeySyncUtils.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/KeySyncUtils.java index bc080be70bcb..e851d8cf21b3 100644 --- a/services/core/java/com/android/server/locksettings/recoverablekeystore/KeySyncUtils.java +++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/KeySyncUtils.java @@ -298,8 +298,8 @@ public class KeySyncUtils { .order(ByteOrder.LITTLE_ENDIAN) .put(SecureBox.encodePublicKey(thmPublicKey)) .putLong(counterId) - .putInt(maxAttempts) .putLong(deviceId) + .putInt(maxAttempts) .array(); } diff --git a/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/KeySyncUtilsTest.java b/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/KeySyncUtilsTest.java index ba40c67cb35d..114da1aaebb5 100644 --- a/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/KeySyncUtilsTest.java +++ b/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/KeySyncUtilsTest.java @@ -386,37 +386,38 @@ public class KeySyncUtilsTest { } @Test - public void packVaultParams_encodesMaxAttemptsAsThirdParam() throws Exception { - int maxAttempts = 10; + public void packVaultParams_encodesDeviceIdAsThirdParam() throws Exception { + long deviceId = 102942158152L; byte[] packedForm = KeySyncUtils.packVaultParams( SecureBox.genKeyPair().getPublic(), - /*counterId=*/ 1001L, - maxAttempts, - /*deviceId=*/ 1L); + /*counterId=*/ 10021L, + /*maxAttempts=*/ 10, + deviceId); ByteBuffer byteBuffer = ByteBuffer.wrap(packedForm) .order(ByteOrder.LITTLE_ENDIAN); byteBuffer.position(PUBLIC_KEY_LENGTH_BYTES + Long.BYTES); - assertEquals(maxAttempts, byteBuffer.getInt()); + assertEquals(deviceId, byteBuffer.getLong()); } @Test - public void packVaultParams_encodesDeviceIdAsLastParam() throws Exception { - long deviceId = 102942158152L; + public void packVaultParams_encodesMaxAttemptsAsLastParam() throws Exception { + int maxAttempts = 10; byte[] packedForm = KeySyncUtils.packVaultParams( SecureBox.genKeyPair().getPublic(), - /*counterId=*/ 10021L, - /*maxAttempts=*/ 10, - deviceId); + /*counterId=*/ 1001L, + maxAttempts, + /*deviceId=*/ 1L); ByteBuffer byteBuffer = ByteBuffer.wrap(packedForm) .order(ByteOrder.LITTLE_ENDIAN); - byteBuffer.position(PUBLIC_KEY_LENGTH_BYTES + Long.BYTES + Integer.BYTES); - assertEquals(deviceId, byteBuffer.getLong()); + 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); |