Loading system/btif/src/bluetooth.cc +19 −2 Original line number Original line Diff line number Diff line Loading @@ -73,6 +73,7 @@ #include "common/os_utils.h" #include "common/os_utils.h" #include "device/include/interop.h" #include "device/include/interop.h" #include "gd/common/init_flags.h" #include "gd/common/init_flags.h" #include "gd/os/parameter_provider.h" #include "main/shim/dumpsys.h" #include "main/shim/dumpsys.h" #include "main/shim/shim.h" #include "main/shim/shim.h" #include "osi/include/alarm.h" #include "osi/include/alarm.h" Loading Loading @@ -178,8 +179,24 @@ static int init(bt_callbacks_t* callbacks, bool start_restricted, set_hal_cbacks(callbacks); set_hal_cbacks(callbacks); restricted_mode = start_restricted; 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_mode = is_common_criteria_mode; common_criteria_config_compare_result = config_compare_result; common_criteria_config_compare_result = config_compare_result; } is_local_device_atv = is_atv; is_local_device_atv = is_atv; stack_manager_get_interface()->init_stack(); stack_manager_get_interface()->init_stack(); Loading system/btif/src/btif_keystore.cc +32 −8 Original line number Original line Diff line number Diff line Loading @@ -16,16 +16,21 @@ /* BluetoothKeystore Interface */ /* BluetoothKeystore Interface */ #include <btif_common.h> #include "btif_keystore.h" #include <btif_keystore.h> #include "btif_storage.h" #include <base/bind.h> #include <base/bind.h> #include <base/location.h> #include <base/location.h> #include <base/logging.h> #include <base/logging.h> #include <hardware/bluetooth.h> #include <hardware/bluetooth.h> #include <map> #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::Bind; using base::Unretained; using base::Unretained; using bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks; using bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks; Loading @@ -35,27 +40,45 @@ namespace bluetooth { namespace bluetooth_keystore { namespace bluetooth_keystore { class BluetoothKeystoreInterfaceImpl; class BluetoothKeystoreInterfaceImpl; std::unique_ptr<BluetoothKeystoreInterface> bluetoothKeystoreInstance; std::unique_ptr<BluetoothKeystoreInterface> bluetoothKeystoreInstance; const int CONFIG_COMPARE_ALL_PASS = 0b11; class BluetoothKeystoreInterfaceImpl class BluetoothKeystoreInterfaceImpl : public bluetooth::bluetooth_keystore::BluetoothKeystoreInterface, : public bluetooth::bluetooth_keystore::BluetoothKeystoreInterface { public bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks { ~BluetoothKeystoreInterfaceImpl() override = default; ~BluetoothKeystoreInterfaceImpl() override = default; void init(BluetoothKeystoreCallbacks* callbacks) override { void init(BluetoothKeystoreCallbacks* callbacks) override { VLOG(2) << __func__; VLOG(2) << __func__; this->callbacks = callbacks; 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( do_in_jni_thread( FROM_HERE, base::Bind([]() { btif_storage_get_num_bonded_devices(); })); 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 { std::string decryptedString) override { VLOG(2) << __func__ << " prefix: " << prefix; VLOG(2) << __func__ << " prefix: " << prefix; if (!callbacks) { if (!callbacks) { LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix; LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix; return; return false; } } // Save the value into a map. // Save the value into a map. Loading @@ -65,6 +88,7 @@ class BluetoothKeystoreInterfaceImpl base::Bind(&bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks:: base::Bind(&bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks:: set_encrypt_key_or_remove_key, set_encrypt_key_or_remove_key, base::Unretained(callbacks), prefix, decryptedString)); base::Unretained(callbacks), prefix, decryptedString)); return true; } } std::string get_key(std::string prefix) override { std::string get_key(std::string prefix) override { Loading system/gd/os/android/parameter_provider.cc +36 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,9 @@ #include "os/parameter_provider.h" #include "os/parameter_provider.h" #include <private/android_filesystem_config.h> #include <unistd.h> #include <mutex> #include <mutex> #include <string> #include <string> Loading @@ -27,6 +30,9 @@ std::mutex parameter_mutex; std::string config_file_path; std::string config_file_path; std::string snoop_log_file_path; std::string snoop_log_file_path; std::string snooz_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 } // namespace // On Android we always write a single default location // On Android we always write a single default location Loading Loading @@ -76,5 +82,35 @@ void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) { snooz_log_file_path = 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 os } // namespace bluetooth } // namespace bluetooth No newline at end of file system/gd/os/bt_keystore.h 0 → 100644 +25 −0 Original line number Original line 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 system/gd/os/host/parameter_provider.cc +18 −0 Original line number Original line Diff line number Diff line Loading @@ -96,5 +96,23 @@ void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) { snooz_log_file_path = 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 os } // namespace bluetooth } // namespace bluetooth No newline at end of file Loading
system/btif/src/bluetooth.cc +19 −2 Original line number Original line Diff line number Diff line Loading @@ -73,6 +73,7 @@ #include "common/os_utils.h" #include "common/os_utils.h" #include "device/include/interop.h" #include "device/include/interop.h" #include "gd/common/init_flags.h" #include "gd/common/init_flags.h" #include "gd/os/parameter_provider.h" #include "main/shim/dumpsys.h" #include "main/shim/dumpsys.h" #include "main/shim/shim.h" #include "main/shim/shim.h" #include "osi/include/alarm.h" #include "osi/include/alarm.h" Loading Loading @@ -178,8 +179,24 @@ static int init(bt_callbacks_t* callbacks, bool start_restricted, set_hal_cbacks(callbacks); set_hal_cbacks(callbacks); restricted_mode = start_restricted; 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_mode = is_common_criteria_mode; common_criteria_config_compare_result = config_compare_result; common_criteria_config_compare_result = config_compare_result; } is_local_device_atv = is_atv; is_local_device_atv = is_atv; stack_manager_get_interface()->init_stack(); stack_manager_get_interface()->init_stack(); Loading
system/btif/src/btif_keystore.cc +32 −8 Original line number Original line Diff line number Diff line Loading @@ -16,16 +16,21 @@ /* BluetoothKeystore Interface */ /* BluetoothKeystore Interface */ #include <btif_common.h> #include "btif_keystore.h" #include <btif_keystore.h> #include "btif_storage.h" #include <base/bind.h> #include <base/bind.h> #include <base/location.h> #include <base/location.h> #include <base/logging.h> #include <base/logging.h> #include <hardware/bluetooth.h> #include <hardware/bluetooth.h> #include <map> #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::Bind; using base::Unretained; using base::Unretained; using bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks; using bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks; Loading @@ -35,27 +40,45 @@ namespace bluetooth { namespace bluetooth_keystore { namespace bluetooth_keystore { class BluetoothKeystoreInterfaceImpl; class BluetoothKeystoreInterfaceImpl; std::unique_ptr<BluetoothKeystoreInterface> bluetoothKeystoreInstance; std::unique_ptr<BluetoothKeystoreInterface> bluetoothKeystoreInstance; const int CONFIG_COMPARE_ALL_PASS = 0b11; class BluetoothKeystoreInterfaceImpl class BluetoothKeystoreInterfaceImpl : public bluetooth::bluetooth_keystore::BluetoothKeystoreInterface, : public bluetooth::bluetooth_keystore::BluetoothKeystoreInterface { public bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks { ~BluetoothKeystoreInterfaceImpl() override = default; ~BluetoothKeystoreInterfaceImpl() override = default; void init(BluetoothKeystoreCallbacks* callbacks) override { void init(BluetoothKeystoreCallbacks* callbacks) override { VLOG(2) << __func__; VLOG(2) << __func__; this->callbacks = callbacks; 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( do_in_jni_thread( FROM_HERE, base::Bind([]() { btif_storage_get_num_bonded_devices(); })); 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 { std::string decryptedString) override { VLOG(2) << __func__ << " prefix: " << prefix; VLOG(2) << __func__ << " prefix: " << prefix; if (!callbacks) { if (!callbacks) { LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix; LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix; return; return false; } } // Save the value into a map. // Save the value into a map. Loading @@ -65,6 +88,7 @@ class BluetoothKeystoreInterfaceImpl base::Bind(&bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks:: base::Bind(&bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks:: set_encrypt_key_or_remove_key, set_encrypt_key_or_remove_key, base::Unretained(callbacks), prefix, decryptedString)); base::Unretained(callbacks), prefix, decryptedString)); return true; } } std::string get_key(std::string prefix) override { std::string get_key(std::string prefix) override { Loading
system/gd/os/android/parameter_provider.cc +36 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,9 @@ #include "os/parameter_provider.h" #include "os/parameter_provider.h" #include <private/android_filesystem_config.h> #include <unistd.h> #include <mutex> #include <mutex> #include <string> #include <string> Loading @@ -27,6 +30,9 @@ std::mutex parameter_mutex; std::string config_file_path; std::string config_file_path; std::string snoop_log_file_path; std::string snoop_log_file_path; std::string snooz_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 } // namespace // On Android we always write a single default location // On Android we always write a single default location Loading Loading @@ -76,5 +82,35 @@ void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) { snooz_log_file_path = 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 os } // namespace bluetooth } // namespace bluetooth No newline at end of file
system/gd/os/bt_keystore.h 0 → 100644 +25 −0 Original line number Original line 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
system/gd/os/host/parameter_provider.cc +18 −0 Original line number Original line Diff line number Diff line Loading @@ -96,5 +96,23 @@ void ParameterProvider::OverrideSnoozLogFilePath(const std::string& path) { snooz_log_file_path = 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 os } // namespace bluetooth } // namespace bluetooth No newline at end of file