Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e2934e1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "ErrorProne: BluetoothKeystoreService"

parents 2e259314 f1c5e408
Loading
Loading
Loading
Loading
+5 −19
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
@@ -42,9 +41,9 @@ import java.security.NoSuchProviderException;
import java.security.ProviderException;
import java.security.UnrecoverableEntryException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -92,10 +91,6 @@ public class BluetoothKeystoreService {

    private static final String CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf";
    private static final String CONFIG_BACKUP_PATH = "/data/misc/bluedroid/bt_config.bak";
    private static final String CONFIG_FILE_CHECKSUM_PATH =
            "/data/misc/bluedroid/bt_config.conf.encrypted-checksum";
    private static final String CONFIG_BACKUP_CHECKSUM_PATH =
            "/data/misc/bluedroid/bt_config.bak.encrypted-checksum";

    private static final int BUFFER_SIZE = 400 * 10;

@@ -449,8 +444,8 @@ public class BluetoothKeystoreService {
    @VisibleForTesting
    public void saveEncryptedKey() {
        stopThread();
        List<String> configEncryptedLines = new LinkedList<>();
        List<String> keyEncryptedLines = new LinkedList<>();
        List<String> configEncryptedLines = new ArrayList<>();
        List<String> keyEncryptedLines = new ArrayList<>();
        for (String key : mNameEncryptKey.keySet()) {
            if (key.equals(CONFIG_FILE_PREFIX) || key.equals(CONFIG_BACKUP_PREFIX)) {
                configEncryptedLines.add(getEncryptedKeyData(key));
@@ -554,7 +549,7 @@ public class BluetoothKeystoreService {
                }

                byte[] messageDigestBytes = messageDigest.digest();
                StringBuffer hashString = new StringBuffer();
                StringBuilder hashString = new StringBuilder();
                for (int index = 0; index < messageDigestBytes.length; index++) {
                    hashString.append(Integer.toString((
                            messageDigestBytes[index] & 0xff) + 0x100, 16).substring(1));
@@ -573,15 +568,6 @@ public class BluetoothKeystoreService {
        }
    }

    private void readChecksumFile(String filePathString, String prefixString) throws IOException {
        if (!Files.exists(Paths.get(filePathString))) {
            return;
        }
        byte[] allBytes = Files.readAllBytes(Paths.get(filePathString));
        String checksumDataBase64 = mEncoder.encodeToString(allBytes);
        mNameEncryptKey.put(prefixString, checksumDataBase64);
    }

    /**
     * Parses a file to search for the key and put it into the pending compute queue
     */
@@ -729,7 +715,7 @@ public class BluetoothKeystoreService {
    /**
     * Decrypt the original data blob from the provided {@link EncryptedData}.
     *
     * @param data String as base64 to be decrypted.
     * @param encryptedDataBase64 String as base64 to be decrypted.
     * @return String.
     */
    private @Nullable String decrypt(String encryptedDataBase64) {