From bd8c5865c9991dd318c7ac47263b527ad7a4cd9b Mon Sep 17 00:00:00 2001 From: Martin Brabham Date: Fri, 31 May 2019 12:53:07 -0700 Subject: [PATCH] Confirm the presence of BT key when BT ON After clearing Bluetooth data, the Bluetooth key will be cleared in the same time. When turn on Bluetooth, NE happened at the step of checking Bluetooth key. Bug: 133214365 Test: ahost --host test net_test_bluetooth Change-Id: I88f5dfae07352a794b304da60e09253c004fb3d4 --- btif/include/btif_keystore.h | 8 ++++++++ btif/src/btif_config.cc | 4 +++- btif/src/btif_keystore.cc | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/btif/include/btif_keystore.h b/btif/include/btif_keystore.h index 4762350f8..cc06a9826 100644 --- a/btif/include/btif_keystore.h +++ b/btif/include/btif_keystore.h @@ -59,6 +59,14 @@ class BtifKeystore { */ std::string Decrypt(const std::string& input_filename); + /** + * Check for existence of keystore key. + * + * This key can be cleared if a user manually wipes bluetooth storage data + * b/133214365 + */ + bool DoesKeyExist(); + private: std::unique_ptr keystore_client_; std::mutex api_mutex_; diff --git a/btif/src/btif_config.cc b/btif/src/btif_config.cc index be006abd4..ed24d7dde 100644 --- a/btif/src/btif_config.cc +++ b/btif/src/btif_config.cc @@ -183,7 +183,9 @@ static BtifKeystore btif_keystore(new keystore::KeystoreClientImpl); static future_t* init(void) { std::unique_lock lock(config_lock); - if (is_factory_reset()) delete_config_files(); + if (is_factory_reset() || + (use_key_attestation() && !btif_keystore.DoesKeyExist())) + delete_config_files(); std::string file_source; diff --git a/btif/src/btif_keystore.cc b/btif/src/btif_keystore.cc index fe9d3ddb7..0af03e11b 100644 --- a/btif/src/btif_keystore.cc +++ b/btif/src/btif_keystore.cc @@ -98,4 +98,8 @@ KeyStoreNativeReturnCode BtifKeystore::GenerateKey(const std::string& name, &software_enforced_characteristics); } +bool BtifKeystore::DoesKeyExist() { + return keystore_client_->doesKeyExist(kKeyStore); +} + } // namespace bluetooth -- 2.11.0