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

Commit 8bcbc697 authored by Martin Brabham's avatar Martin Brabham
Browse files

Security: Add pin code methods to Ui interface

Provide functions to allow communication of Ui events
related to PIN Code entry.

Bug: 162984360
Tag: #gd-refactor
Test: cert/run --host SecurityTest
Change-Id: I10eceaf0f7e398c132868e9abf716ccae54e1233
parent 42220e26
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -176,6 +176,12 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
        security_module_->GetSecurityManager()->OnPairingPromptAccepted(
            hci::AddressWithType(peer, remote_type), request->boolean());
        break;
      case UiCallbackType::PIN:
        LOG_INFO("PIN Callback");
        security_module_->GetSecurityManager()->OnPinEntry(
            hci::AddressWithType(peer, remote_type),
            std::vector<uint8_t>(request->pin().cbegin(), request->pin().cend()));
        break;
      default:
        LOG_ERROR("Unknown UiCallbackType %d", static_cast<int>(request->message_type()));
        return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Unknown UiCallbackType");
@@ -414,6 +420,17 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
    ui_events_.OnIncomingEvent(display_passkey_input);
  }

  void DisplayEnterPinDialog(ConfirmationData data) override {
    const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType();
    std::string name = data.GetName();
    LOG_INFO("%s", peer.ToString().c_str());
    UiMsg display_pin_input;
    *display_pin_input.mutable_peer() = ToFacadeAddressWithType(peer);
    display_pin_input.set_message_type(UiMsgType::DISPLAY_PIN_ENTRY);
    display_pin_input.set_unique_id(unique_id++);
    ui_events_.OnIncomingEvent(display_pin_input);
  }

  void Cancel(const bluetooth::hci::AddressWithType& peer) override {
    LOG_INFO("%s", peer.ToString().c_str());
    UiMsg display_cancel;
+7 −4
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ enum UiMsgType {
  DISPLAY_PASSKEY_ENTRY = 3;
  DISPLAY_CANCEL = 4;
  DISPLAY_PAIRING_PROMPT = 5;
  DISPLAY_PIN_ENTRY = 6;
}

message UiMsg {
@@ -63,14 +64,16 @@ enum UiCallbackType {
  YES_NO = 0;
  PASSKEY = 1;
  PAIRING_PROMPT = 2;
  PIN = 3;
}

message UiCallbackMsg {
  UiCallbackType message_type = 1;
  bool boolean = 2;
  uint32 numeric_value = 3;
  uint32 unique_id = 4;
  facade.BluetoothAddressWithType address = 5;
  facade.BluetoothAddressWithType address = 2;
  bool boolean = 3;
  uint32 numeric_value = 4;
  uint32 unique_id = 5;
  bytes pin = 6;
}

enum BondMsgType {
+11 −0
Original line number Diff line number Diff line
@@ -414,6 +414,17 @@ void SecurityManagerImpl::OnPasskeyEntry(const bluetooth::hci::AddressWithType&
  }
}

void SecurityManagerImpl::OnPinEntry(const bluetooth::hci::AddressWithType& address, std::vector<uint8_t> pin) {
  auto entry = pairing_handler_map_.find(address.GetAddress());
  if (entry != pairing_handler_map_.end()) {
    LOG_INFO("PIN for %s", address.ToString().c_str());
    entry->second->OnPinEntry(address, pin);
  } else {
    LOG_WARN("No handler found for PIN for %s", address.ToString().c_str());
    // TODO(jpawlowski): Implement LE version
  }
}

void SecurityManagerImpl::OnPairingHandlerComplete(hci::Address address, PairingResultOrFailure status) {
  auto entry = pairing_handler_map_.find(address);
  if (entry != pairing_handler_map_.end()) {
+1 −0
Original line number Diff line number Diff line
@@ -181,6 +181,7 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener, pub
  void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) override;
  void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) override;
  void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) override;
  void OnPinEntry(const bluetooth::hci::AddressWithType& address, std::vector<uint8_t> pin) override;

  // Facade Configuration API functions
  using FacadeDisconnectCallback = common::Callback<void(bluetooth::hci::AddressWithType)>;
+9 −0
Original line number Diff line number Diff line
@@ -84,6 +84,15 @@ void ClassicPairingHandler::OnPasskeyEntry(const bluetooth::hci::AddressWithType
  LOG_WARN("TODO Not Implemented!");
}

void ClassicPairingHandler::OnPinEntry(const bluetooth::hci::AddressWithType& address, std::vector<uint8_t> pin) {
  std::array<uint8_t, 16> padded_pin;
  for (size_t i = 0; i < 16 && i < pin.size(); i++) {
    padded_pin[i] = pin[i];
  }
  LOG_INFO("%s", address.GetAddress().ToString().c_str());
  GetChannel()->SendCommand(hci::PinCodeRequestReplyBuilder::Create(address.GetAddress(), pin.size(), padded_pin));
}

void ClassicPairingHandler::Initiate(
    bool locally_initiated,
    hci::IoCapability io_capability,
Loading