Merge "SyntheticPasswordManager: consolidate hex encoding logic" am: 2be0e5e3e9 am: 828e390db2 am: 65b42e199b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2132300 Change-Id: Iff07d91e976c71ab57b9586f51dd034b4588b39b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -278,9 +278,8 @@ public class SyntheticPasswordManager {
|
|||||||
* AuthenticationToken.mSyntheticPassword for details on what each block means.
|
* AuthenticationToken.mSyntheticPassword for details on what each block means.
|
||||||
*/
|
*/
|
||||||
private void recreate(byte[] escrowSplit0, byte[] escrowSplit1) {
|
private void recreate(byte[] escrowSplit0, byte[] escrowSplit1) {
|
||||||
mSyntheticPassword = String.valueOf(HexEncoding.encode(
|
mSyntheticPassword = bytesToHex(SyntheticPasswordCrypto.personalisedHash(
|
||||||
SyntheticPasswordCrypto.personalisedHash(
|
PERSONALIZATION_SP_SPLIT, escrowSplit0, escrowSplit1));
|
||||||
PERSONALIZATION_SP_SPLIT, escrowSplit0, escrowSplit1))).getBytes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1545,18 +1544,9 @@ public class SyntheticPasswordManager {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes();
|
@VisibleForTesting
|
||||||
private static byte[] bytesToHex(byte[] bytes) {
|
static byte[] bytesToHex(byte[] bytes) {
|
||||||
if (bytes == null) {
|
return HexEncoding.encodeToString(bytes).getBytes();
|
||||||
return "null".getBytes();
|
|
||||||
}
|
|
||||||
byte[] hexBytes = new byte[bytes.length * 2];
|
|
||||||
for ( int j = 0; j < bytes.length; j++ ) {
|
|
||||||
int v = bytes[j] & 0xFF;
|
|
||||||
hexBytes[j * 2] = HEX_ARRAY[v >>> 4];
|
|
||||||
hexBytes[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
|
||||||
}
|
|
||||||
return hexBytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -574,6 +574,13 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHexEncodingIsUppercase() {
|
||||||
|
final byte[] raw = new byte[] { (byte)0xAB, (byte)0xCD, (byte)0xEF };
|
||||||
|
final byte[] expected = new byte[] { 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||||
|
assertArrayEquals(expected, SyntheticPasswordManager.bytesToHex(raw));
|
||||||
|
}
|
||||||
|
|
||||||
// b/62213311
|
// b/62213311
|
||||||
//TODO: add non-migration work profile case, and unify/un-unify transition.
|
//TODO: add non-migration work profile case, and unify/un-unify transition.
|
||||||
//TODO: test token after user resets password
|
//TODO: test token after user resets password
|
||||||
|
|||||||
Reference in New Issue
Block a user