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

Commit 5b10581d authored by Brian Delwiche's avatar Brian Delwiche Committed by Android Build Coastguard Worker
Browse files

Improve audio sharing password handling

This is a backport of ag/31824318.  ag/31424453 against the same bug is
superseded by these changes and need not be backported.

Test: atest
Bug: 389127608
Ignore-AOSP-First: security
Tag: #security
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:a794c32c13d2835ce5065f97fd2d76721c42fba1)
Merged-In: If2ad220dc2f4890ee67be62962a9b25d2f803e24
Change-Id: If2ad220dc2f4890ee67be62962a9b25d2f803e24
parent 7f5cc94e
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.google.common.collect.ImmutableList;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -93,6 +94,10 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
    private static final String SETTINGS_PKG = "com.android.settings";
    private static final String TAG = "LocalBluetoothLeBroadcast";
    private static final boolean DEBUG = BluetoothUtils.D;
    private static final String VALID_PASSWORD_CHARACTERS =
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[]{}|;:,"
                    + ".<>?/";
    private static final int PASSWORD_LENGTH = 16;

    static final String NAME = "LE_AUDIO_BROADCAST";
    private static final String UNDERLINE = "_";
@@ -1076,9 +1081,15 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
    }

    private String generateRandomPassword() {
        String randomUUID = UUID.randomUUID().toString();
        // first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
        return randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
        SecureRandom random = new SecureRandom();
        StringBuilder stringBuilder = new StringBuilder(PASSWORD_LENGTH);

        for (int i = 0; i < PASSWORD_LENGTH; i++) {
            int randomIndex = random.nextInt(VALID_PASSWORD_CHARACTERS.length());
            stringBuilder.append(VALID_PASSWORD_CHARACTERS.charAt(randomIndex));
        }

        return stringBuilder.toString();
    }

    private void registerContentObserver() {