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 bc080be70bcb8..e851d8cf21b3e 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 ba40c67cb35d2..114da1aaebb52 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,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);