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

Commit ca07cae6 authored by Martin Brabham's avatar Martin Brabham Committed by Myles Watson
Browse files

Security Facade: Implement CreateBondOutOfBand

Bug: 162984360
Tag: #gd-refactor
Test: cert/run --host SecurityTest
Change-Id: I78766ba130578b434298e739135951c9713a6748
parent e626e2d0
Loading
Loading
Loading
Loading
+34 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "l2cap/le/l2cap_le_module.h"
#include "os/handler.h"
#include "security/facade.grpc.pb.h"
#include "security/pairing/oob_data.h"
#include "security/security_manager_listener.h"
#include "security/security_module.h"
#include "security/ui.h"
@@ -93,11 +94,43 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
                            ::google::protobuf::Empty* response) override {
    hci::Address peer;
    ASSERT(hci::Address::FromString(request->address().address(), peer));
    hci::AddressType peer_type = hci::AddressType::PUBLIC_DEVICE_ADDRESS;
    hci::AddressType peer_type = static_cast<hci::AddressType>(request->type());
    security_module_->GetSecurityManager()->CreateBond(hci::AddressWithType(peer, peer_type));
    return ::grpc::Status::OK;
  }

  ::grpc::Status CreateBondOutOfBand(
      ::grpc::ServerContext* context,
      const ::bluetooth::security::OobDataBondMessage* request,
      ::google::protobuf::Empty* response) override {
    hci::Address peer;
    ASSERT(hci::Address::FromString(request->address().address().address(), peer));
    hci::AddressType peer_type = static_cast<hci::AddressType>(request->address().type());
    pairing::SimplePairingHash c;
    pairing::SimplePairingRandomizer r;
    std::copy(
        std::begin(request->p192_data().le_sc_confirmation_value()),
        std::end(request->p192_data().le_sc_confirmation_value()),
        c.data());
    std::copy(
        std::begin(request->p192_data().le_sc_random_value()),
        std::end(request->p192_data().le_sc_random_value()),
        r.data());
    pairing::OobData p192_data(c, r);
    std::copy(
        std::begin(request->p256_data().le_sc_confirmation_value()),
        std::end(request->p256_data().le_sc_confirmation_value()),
        c.data());
    std::copy(
        std::begin(request->p256_data().le_sc_random_value()),
        std::end(request->p256_data().le_sc_random_value()),
        r.data());
    pairing::OobData p256_data(c, r);
    security_module_->GetSecurityManager()->CreateBondOutOfBand(
        hci::AddressWithType(peer, peer_type), p192_data, p256_data);
    return ::grpc::Status::OK;
  }

  ::grpc::Status CreateBondLe(::grpc::ServerContext* context, const facade::BluetoothAddressWithType* request,
                              ::google::protobuf::Empty* response) override {
    hci::Address peer;