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

Commit aa2fed07 authored by weichinweng's avatar weichinweng Committed by Automerger Merge Worker
Browse files

NIAP: Add a map to store the LTTKM am: e5508107

Change-Id: I9e6ddfbd362a8aed04ae324838d76f2cf071da9c
parents fb41c9b1 e5508107
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -384,6 +384,7 @@ static future_t* clean_up(void) {
  config_timer = NULL;
  config_timer = NULL;


  std::unique_lock<std::recursive_mutex> lock(config_lock);
  std::unique_lock<std::recursive_mutex> lock(config_lock);
  get_bluetooth_keystore_interface()->clear_map();
  MetricIdAllocator::GetInstance().Close();
  MetricIdAllocator::GetInstance().Close();
  config.reset();
  config.reset();
  return future_new_immediate(FUTURE_SUCCESS);
  return future_new_immediate(FUTURE_SUCCESS);
+28 −4
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#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>


using base::Bind;
using base::Bind;
using base::Unretained;
using base::Unretained;
@@ -40,19 +41,22 @@ class BluetoothKeystoreInterfaceImpl
  ~BluetoothKeystoreInterfaceImpl() override = default;
  ~BluetoothKeystoreInterfaceImpl() override = default;


  void init(BluetoothKeystoreCallbacks* callbacks) override {
  void init(BluetoothKeystoreCallbacks* callbacks) override {
    DVLOG(2) << __func__;
    VLOG(2) << __func__;
    this->callbacks = callbacks;
    this->callbacks = callbacks;
  }
  }


  void set_encrypt_key_or_remove_key(std::string prefix,
  void set_encrypt_key_or_remove_key(std::string prefix,
                                     std::string decryptedString) override {
                                     std::string decryptedString) override {
    DVLOG(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;
    }
    }


    // Save the value into a map.
    key_map[prefix] = decryptedString;

    do_in_jni_thread(
    do_in_jni_thread(
        base::Bind(&bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks::
        base::Bind(&bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks::
                       set_encrypt_key_or_remove_key,
                       set_encrypt_key_or_remove_key,
@@ -60,18 +64,38 @@ class BluetoothKeystoreInterfaceImpl
  }
  }


  std::string get_key(std::string prefix) override {
  std::string get_key(std::string prefix) override {
    DVLOG(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 "";
    }
    }


    return callbacks->get_key(prefix);
    std::string decryptedString;
    // try to find the key.
    std::map<std::string, std::string>::iterator iter = key_map.find(prefix);
    if (iter == key_map.end()) {
      decryptedString = callbacks->get_key(prefix);
      // Save the value into a map.
      key_map[prefix] = decryptedString;
      VLOG(2) << __func__ << ": get key from bluetoothkeystore.";
    } else {
      decryptedString = iter->second;
    }
    return decryptedString;
  }

  void clear_map() override {
    VLOG(2) << __func__;

    std::map<std::string, std::string> empty_map;
    key_map.swap(empty_map);
    key_map.clear();
  }
  }


 private:
 private:
  BluetoothKeystoreCallbacks* callbacks = nullptr;
  BluetoothKeystoreCallbacks* callbacks = nullptr;
  std::map<std::string, std::string> key_map;
};
};


BluetoothKeystoreInterface* getBluetoothKeystoreInterface() {
BluetoothKeystoreInterface* getBluetoothKeystoreInterface() {
+3 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,9 @@ class BluetoothKeystoreInterface {


  /** Interface for get key. */
  /** Interface for get key. */
  virtual std::string get_key(std::string prefix) = 0;
  virtual std::string get_key(std::string prefix) = 0;

  /** Interface for clear map. */
  virtual void clear_map() = 0;
};
};


}  // namespace bluetooth_keystore
}  // namespace bluetooth_keystore