Loading src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java +27 −14 Original line number Original line Diff line number Diff line Loading @@ -213,6 +213,7 @@ public class BluetoothKeystoreService { @VisibleForTesting @VisibleForTesting public void cleanupForCommonCriteriaModeEnable() { public void cleanupForCommonCriteriaModeEnable() { try { try { Thread.sleep(100); setEncryptKeyOrRemoveKey(CONFIG_FILE_PREFIX, CONFIG_FILE_HASH); setEncryptKeyOrRemoveKey(CONFIG_FILE_PREFIX, CONFIG_FILE_HASH); } catch (InterruptedException e) { } catch (InterruptedException e) { reportBluetoothKeystoreException(e, "Interrupted while operating."); reportBluetoothKeystoreException(e, "Interrupted while operating."); Loading Loading @@ -523,7 +524,7 @@ public class BluetoothKeystoreService { */ */ @VisibleForTesting @VisibleForTesting public boolean compareFileHash(String hashFilePathString) public boolean compareFileHash(String hashFilePathString) throws IOException, NoSuchAlgorithmException { throws InterruptedException, IOException, NoSuchAlgorithmException { if (!Files.exists(Paths.get(hashFilePathString))) { if (!Files.exists(Paths.get(hashFilePathString))) { infoLog("compareFileHash: File does not exist, path: " + hashFilePathString); infoLog("compareFileHash: File does not exist, path: " + hashFilePathString); return false; return false; Loading Loading @@ -558,13 +559,15 @@ public class BluetoothKeystoreService { } } private void readHashFile(String filePathString, String prefixString) private void readHashFile(String filePathString, String prefixString) throws IOException, NoSuchAlgorithmException { throws InterruptedException, NoSuchAlgorithmException { byte[] dataBuffer = new byte[BUFFER_SIZE]; byte[] dataBuffer = new byte[BUFFER_SIZE]; int bytesRead = 0; int bytesRead = 0; boolean successful = false; int counter = 0; while (!successful && counter < TRY_MAX) { try { MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); InputStream fileStream = Files.newInputStream(Paths.get(filePathString)); InputStream fileStream = Files.newInputStream(Paths.get(filePathString)); while ((bytesRead = fileStream.read(dataBuffer)) != -1) { while ((bytesRead = fileStream.read(dataBuffer)) != -1) { messageDigest.update(dataBuffer, 0, bytesRead); messageDigest.update(dataBuffer, 0, bytesRead); } } Loading @@ -577,6 +580,16 @@ public class BluetoothKeystoreService { } } mNameDecryptKey.put(prefixString, hashString.toString()); mNameDecryptKey.put(prefixString, hashString.toString()); successful = true; } catch (IOException e) { infoLog("Fail to open file, try again. counter: " + counter); Thread.sleep(50); counter++; } } if (counter > 3) { errorLog("Fail to open file"); } } } private void readChecksumFile(String filePathString, String prefixString) throws IOException { private void readChecksumFile(String filePathString, String prefixString) throws IOException { Loading tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -214,7 +214,7 @@ public final class BluetoothKeystoreServiceTest { private boolean compareFileHash(String hashFilePathString) { private boolean compareFileHash(String hashFilePathString) { try { try { return mBluetoothKeystoreService.compareFileHash(hashFilePathString); return mBluetoothKeystoreService.compareFileHash(hashFilePathString); } catch (IOException | NoSuchAlgorithmException e) { } catch (InterruptedException | IOException | NoSuchAlgorithmException e) { return false; return false; } } } } Loading Loading
src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java +27 −14 Original line number Original line Diff line number Diff line Loading @@ -213,6 +213,7 @@ public class BluetoothKeystoreService { @VisibleForTesting @VisibleForTesting public void cleanupForCommonCriteriaModeEnable() { public void cleanupForCommonCriteriaModeEnable() { try { try { Thread.sleep(100); setEncryptKeyOrRemoveKey(CONFIG_FILE_PREFIX, CONFIG_FILE_HASH); setEncryptKeyOrRemoveKey(CONFIG_FILE_PREFIX, CONFIG_FILE_HASH); } catch (InterruptedException e) { } catch (InterruptedException e) { reportBluetoothKeystoreException(e, "Interrupted while operating."); reportBluetoothKeystoreException(e, "Interrupted while operating."); Loading Loading @@ -523,7 +524,7 @@ public class BluetoothKeystoreService { */ */ @VisibleForTesting @VisibleForTesting public boolean compareFileHash(String hashFilePathString) public boolean compareFileHash(String hashFilePathString) throws IOException, NoSuchAlgorithmException { throws InterruptedException, IOException, NoSuchAlgorithmException { if (!Files.exists(Paths.get(hashFilePathString))) { if (!Files.exists(Paths.get(hashFilePathString))) { infoLog("compareFileHash: File does not exist, path: " + hashFilePathString); infoLog("compareFileHash: File does not exist, path: " + hashFilePathString); return false; return false; Loading Loading @@ -558,13 +559,15 @@ public class BluetoothKeystoreService { } } private void readHashFile(String filePathString, String prefixString) private void readHashFile(String filePathString, String prefixString) throws IOException, NoSuchAlgorithmException { throws InterruptedException, NoSuchAlgorithmException { byte[] dataBuffer = new byte[BUFFER_SIZE]; byte[] dataBuffer = new byte[BUFFER_SIZE]; int bytesRead = 0; int bytesRead = 0; boolean successful = false; int counter = 0; while (!successful && counter < TRY_MAX) { try { MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); InputStream fileStream = Files.newInputStream(Paths.get(filePathString)); InputStream fileStream = Files.newInputStream(Paths.get(filePathString)); while ((bytesRead = fileStream.read(dataBuffer)) != -1) { while ((bytesRead = fileStream.read(dataBuffer)) != -1) { messageDigest.update(dataBuffer, 0, bytesRead); messageDigest.update(dataBuffer, 0, bytesRead); } } Loading @@ -577,6 +580,16 @@ public class BluetoothKeystoreService { } } mNameDecryptKey.put(prefixString, hashString.toString()); mNameDecryptKey.put(prefixString, hashString.toString()); successful = true; } catch (IOException e) { infoLog("Fail to open file, try again. counter: " + counter); Thread.sleep(50); counter++; } } if (counter > 3) { errorLog("Fail to open file"); } } } private void readChecksumFile(String filePathString, String prefixString) throws IOException { private void readChecksumFile(String filePathString, String prefixString) throws IOException { Loading
tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -214,7 +214,7 @@ public final class BluetoothKeystoreServiceTest { private boolean compareFileHash(String hashFilePathString) { private boolean compareFileHash(String hashFilePathString) { try { try { return mBluetoothKeystoreService.compareFileHash(hashFilePathString); return mBluetoothKeystoreService.compareFileHash(hashFilePathString); } catch (IOException | NoSuchAlgorithmException e) { } catch (InterruptedException | IOException | NoSuchAlgorithmException e) { return false; return false; } } } } Loading