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

Commit 4fef0345 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Implement Common Criteria Mode for GD" am: 56973e56

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1856140

Change-Id: I7a4bfb92c121e263ba89fe3cc03c62d73a99d09b
parents 0c943823 56973e56
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@
#include "common/os_utils.h"
#include "device/include/interop.h"
#include "gd/common/init_flags.h"
#include "gd/os/parameter_provider.h"
#include "main/shim/dumpsys.h"
#include "main/shim/shim.h"
#include "osi/include/alarm.h"
@@ -178,8 +179,24 @@ static int init(bt_callbacks_t* callbacks, bool start_restricted,
  set_hal_cbacks(callbacks);

  restricted_mode = start_restricted;

  if (bluetooth::shim::is_any_gd_enabled()) {
    bluetooth::os::ParameterProvider::SetBtKeystoreInterface(
        bluetooth::bluetooth_keystore::getBluetoothKeystoreInterface());
    bluetooth::os::ParameterProvider::SetCommonCriteriaMode(
        is_common_criteria_mode);
    if (is_bluetooth_uid() && is_common_criteria_mode) {
      bluetooth::os::ParameterProvider::SetCommonCriteriaConfigCompareResult(
          config_compare_result);
    } else {
      bluetooth::os::ParameterProvider::SetCommonCriteriaConfigCompareResult(
          CONFIG_COMPARE_ALL_PASS);
    }
  } else {
    common_criteria_mode = is_common_criteria_mode;
    common_criteria_config_compare_result = config_compare_result;
  }

  is_local_device_atv = is_atv;

  stack_manager_get_interface()->init_stack();
+32 −8
Original line number Diff line number Diff line
@@ -16,16 +16,21 @@

/* BluetoothKeystore Interface */

#include <btif_common.h>
#include <btif_keystore.h>
#include "btif_storage.h"
#include "btif_keystore.h"

#include <base/bind.h>
#include <base/location.h>
#include <base/logging.h>
#include <hardware/bluetooth.h>

#include <map>

#include "btif_common.h"
#include "btif_storage.h"
#include "gd/os/parameter_provider.h"
#include "main/shim/config.h"
#include "main/shim/shim.h"

using base::Bind;
using base::Unretained;
using bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks;
@@ -35,27 +40,45 @@ namespace bluetooth {
namespace bluetooth_keystore {
class BluetoothKeystoreInterfaceImpl;
std::unique_ptr<BluetoothKeystoreInterface> bluetoothKeystoreInstance;
const int CONFIG_COMPARE_ALL_PASS = 0b11;

class BluetoothKeystoreInterfaceImpl
    : public bluetooth::bluetooth_keystore::BluetoothKeystoreInterface,
      public bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks {
    : public bluetooth::bluetooth_keystore::BluetoothKeystoreInterface {
  ~BluetoothKeystoreInterfaceImpl() override = default;

  void init(BluetoothKeystoreCallbacks* callbacks) override {
    VLOG(2) << __func__;
    this->callbacks = callbacks;
    // Get bonded devices number to get all bonded devices key.

    bluetooth::os::ParameterProvider::SetCommonCriteriaConfigCompareResult(
        CONFIG_COMPARE_ALL_PASS);
    ConvertEncryptOrDecryptKeyIfNeeded();
  }

  void ConvertEncryptOrDecryptKeyIfNeeded() {
    VLOG(2) << __func__;
    if (!callbacks) {
      LOG(INFO) << __func__ << " callback isn't ready.";
      return;
    }
    if (bluetooth::shim::is_any_gd_enabled()) {
      do_in_jni_thread(
          FROM_HERE, base::Bind([]() {
            shim::BtifConfigInterface::ConvertEncryptOrDecryptKeyIfNeeded();
          }));
      return;
    }
    do_in_jni_thread(
        FROM_HERE, base::Bind([]() { btif_storage_get_num_bonded_devices(); }));
  }

  void set_encrypt_key_or_remove_key(std::string prefix,
  bool set_encrypt_key_or_remove_key(std::string prefix,
                                     std::string decryptedString) override {
    VLOG(2) << __func__ << " prefix: " << prefix;

    if (!callbacks) {
      LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix;
      return;
      return false;
    }

    // Save the value into a map.
@@ -65,6 +88,7 @@ class BluetoothKeystoreInterfaceImpl
        base::Bind(&bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks::
                       set_encrypt_key_or_remove_key,
                   base::Unretained(callbacks), prefix, decryptedString));
    return true;
  }

  std::string get_key(std::string prefix) override {
+36 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

#include "os/parameter_provider.h"

#include <private/android_filesystem_config.h>
#include <unistd.h>

#include <mutex>
#include <string>

@@ -27,6 +30,9 @@ std::mutex parameter_mutex;
std::string config_file_path;
std::string snoop_log_file_path;
std::string snooz_log_file_path;
bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore_interface = nullptr;
bool is_common_criteria_mode = false;
int common_criteria_config_compare_result = 0b11;
}  // namespace

// On Android we always write a single default location
@@ -76,5 +82,35 @@ void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) {
  snooz_log_file_path = path;
}

bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  return bt_keystore_interface;
}

void ParameterProvider::SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore) {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  bt_keystore_interface = bt_keystore;
}

bool ParameterProvider::IsCommonCriteriaMode() {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  return (getuid() == AID_BLUETOOTH) && is_common_criteria_mode;
}

void ParameterProvider::SetCommonCriteriaMode(bool enable) {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  is_common_criteria_mode = enable;
}

int ParameterProvider::GetCommonCriteriaConfigCompareResult() {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  return common_criteria_config_compare_result;
}

void ParameterProvider::SetCommonCriteriaConfigCompareResult(int result) {
  std::lock_guard<std::mutex> lock(parameter_mutex);
  common_criteria_config_compare_result = result;
}

}  // namespace os
}  // namespace bluetooth
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <../include/hardware/bt_keystore.h>

namespace bluetooth {
namespace bluetooth_keystore {

BluetoothKeystoreInterface* getBluetoothKeystoreInterface();

}  // namespace bluetooth_keystore
}  // namespace bluetooth
 No newline at end of file
+18 −0
Original line number Diff line number Diff line
@@ -96,5 +96,23 @@ void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) {
  snooz_log_file_path = path;
}

bluetooth_keystore::BluetoothKeystoreInterface* ParameterProvider::GetBtKeystoreInterface() {
  return nullptr;
}

void ParameterProvider::SetBtKeystoreInterface(bluetooth_keystore::BluetoothKeystoreInterface* bt_keystore) {}

bool ParameterProvider::IsCommonCriteriaMode() {
  return false;
}

void ParameterProvider::SetCommonCriteriaMode(bool enable) {}

int ParameterProvider::GetCommonCriteriaConfigCompareResult() {
  return 0b11;
}

void ParameterProvider::SetCommonCriteriaConfigCompareResult(int result) {}

}  // namespace os
}  // namespace bluetooth
 No newline at end of file
Loading