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

Commit 2ab4b53d authored by Myles Watson's avatar Myles Watson
Browse files

Classic AclManager: Validate encryption handle

Bug: 158683902
Test: cert/run --host
Tag: #gd-refactor
Change-Id: I4fa9d68c46ce5ebaf148e6d60e6469b61e6be94b
parent 60aa80c2
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -497,18 +497,22 @@ struct classic_impl : public DisconnectorForLe, public security::ISecurityManage

  void OnEncryptionStateChanged(EncryptionChangeView encryption_change_view) override {
    if (!encryption_change_view.IsValid()) {
      LOG_ERROR("Received on_encryption_change with invalid packet");
      LOG_ERROR("Invalid packet");
      return;
    } else if (encryption_change_view.GetStatus() != ErrorCode::SUCCESS) {
      auto status = encryption_change_view.GetStatus();
      std::string error_code = ErrorCodeText(status);
      LOG_ERROR("Received on_change_connection_link_key_complete with error code %s", error_code.c_str());
      LOG_ERROR("error_code %s", error_code.c_str());
      return;
    }
    uint16_t handle = encryption_change_view.GetConnectionHandle();
    auto& acl_connection = classic_impl_->acl_connections_.find(handle)->second;
    auto acl_connection = classic_impl_->acl_connections_.find(handle);
    if (acl_connection == classic_impl_->acl_connections_.end()) {
      LOG_INFO("Invalid handle (already closed?) %d", handle);
      return;
    }
    EncryptionEnabled enabled = encryption_change_view.GetEncryptionEnabled();
    acl_connection.connection_management_callbacks_->OnEncryptionChange(enabled);
    acl_connection->second.connection_management_callbacks_->OnEncryptionChange(enabled);
  }

  void set_security_module(security::SecurityModule* security_module) {