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

Commit 8b419b07 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "SM: Keep track of Authenticated, MITM, OOB Present, Encryption Required"

parents 29fee4aa 8a08f42f
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -152,6 +152,37 @@ void ClassicPairingHandler::OnReceive(hci::IoCapabilityResponseView packet) {

  // Using local variable until device database pointer is ready
  remote_io_capability_ = packet.GetIoCapability();
  remote_authentication_requirements_ = packet.GetAuthenticationRequirements();
  remote_oob_present_ = packet.GetOobDataPresent();
  switch (remote_authentication_requirements_) {
    case hci::AuthenticationRequirements::NO_BONDING:
      GetRecord()->SetIsEncryptionRequired(false);
      GetRecord()->SetRequiresMitmProtection(false);
      break;
    case hci::AuthenticationRequirements::NO_BONDING_MITM_PROTECTION:
      GetRecord()->SetIsEncryptionRequired(false);
      GetRecord()->SetRequiresMitmProtection(true);
      break;
    case hci::AuthenticationRequirements::DEDICATED_BONDING:
      GetRecord()->SetIsEncryptionRequired(true);
      GetRecord()->SetRequiresMitmProtection(false);
      break;
    case hci::AuthenticationRequirements::DEDICATED_BONDING_MITM_PROTECTION:
      GetRecord()->SetIsEncryptionRequired(true);
      GetRecord()->SetRequiresMitmProtection(true);
      break;
    case hci::AuthenticationRequirements::GENERAL_BONDING:
      GetRecord()->SetIsEncryptionRequired(true);
      GetRecord()->SetRequiresMitmProtection(false);
      break;
    case hci::AuthenticationRequirements::GENERAL_BONDING_MITM_PROTECTION:
      GetRecord()->SetIsEncryptionRequired(true);
      GetRecord()->SetRequiresMitmProtection(true);
      break;
    default:
      GetRecord()->SetRequiresMitmProtection(false);
      break;
  }
}

void ClassicPairingHandler::OnReceive(hci::SimplePairingCompleteView packet) {
@@ -238,6 +269,7 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          GetChannel()->SendCommand(
              hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
        case hci::IoCapability::DISPLAY_YES_NO:
          // NumericComparison, Initiator auto confirm, Responder display
@@ -245,12 +277,14 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
              hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
          LOG_INFO("Numeric Comparison: A auto confirm");
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
        case hci::IoCapability::KEYBOARD_ONLY:
          // PassKey Entry, Initiator display, Responder input
          NotifyUiDisplayPasskey(packet.GetNumericValue());
          LOG_INFO("Passkey Entry: A display, B input");
          // Authenticated
          GetRecord()->SetAuthenticated(true);
          break;
        case hci::IoCapability::NO_INPUT_NO_OUTPUT:
          // NumericComparison, Both auto confirm
@@ -258,6 +292,7 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          GetChannel()->SendCommand(
              hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
      }
      break;
@@ -268,24 +303,28 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          LOG_INFO("Numeric Comparison: A DisplayYesNo, B auto confirm");
          NotifyUiDisplayYesNo(packet.GetNumericValue());
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
        case hci::IoCapability::DISPLAY_YES_NO:
          // NumericComparison Both Display, Both confirm
          LOG_INFO("Numeric Comparison: A and B DisplayYesNo");
          NotifyUiDisplayYesNo(packet.GetNumericValue());
          // Authenticated
          GetRecord()->SetAuthenticated(true);
          break;
        case hci::IoCapability::KEYBOARD_ONLY:
          // PassKey Entry, Initiator display, Responder input
          NotifyUiDisplayPasskey(packet.GetNumericValue());
          LOG_INFO("Passkey Entry: A display, B input");
          // Authenticated
          GetRecord()->SetAuthenticated(true);
          break;
        case hci::IoCapability::NO_INPUT_NO_OUTPUT:
          // NumericComparison, auto confirm Responder, Yes/No confirm Initiator. Don't show confirmation value
          NotifyUiDisplayYesNo();
          LOG_INFO("Numeric Comparison: A DisplayYesNo, B auto confirm, no show value");
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
      }
      break;
@@ -296,18 +335,21 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          NotifyUiDisplayPasskeyInput();
          LOG_INFO("Passkey Entry: A input, B display");
          // Authenticated
          GetRecord()->SetAuthenticated(true);
          break;
        case hci::IoCapability::DISPLAY_YES_NO:
          // PassKey Entry, Responder display, Initiator input
          NotifyUiDisplayPasskeyInput();
          LOG_INFO("Passkey Entry: A input, B display");
          // Authenticated
          GetRecord()->SetAuthenticated(true);
          break;
        case hci::IoCapability::KEYBOARD_ONLY:
          // PassKey Entry, both input
          NotifyUiDisplayPasskeyInput();
          LOG_INFO("Passkey Entry: A input, B input");
          // Authenticated
          GetRecord()->SetAuthenticated(true);
          break;
        case hci::IoCapability::NO_INPUT_NO_OUTPUT:
          // NumericComparison, both auto confirm
@@ -315,6 +357,7 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          GetChannel()->SendCommand(
              hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
      }
      break;
@@ -326,6 +369,7 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          GetChannel()->SendCommand(
              hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
        case hci::IoCapability::DISPLAY_YES_NO:
          // NumericComparison, Initiator auto confirm, Responder Yes/No confirm, no show conf val
@@ -333,6 +377,7 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          GetChannel()->SendCommand(
              hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
        case hci::IoCapability::KEYBOARD_ONLY:
          // NumericComparison, both auto confirm
@@ -340,6 +385,7 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          GetChannel()->SendCommand(
              hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
        case hci::IoCapability::NO_INPUT_NO_OUTPUT:
          // NumericComparison, both auto confirm
@@ -347,6 +393,7 @@ void ClassicPairingHandler::OnReceive(hci::UserConfirmationRequestView packet) {
          GetChannel()->SendCommand(
              hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
          // Unauthenticated
          GetRecord()->SetAuthenticated(false);
          break;
      }
      break;
+16 −0
Original line number Diff line number Diff line
@@ -270,6 +270,8 @@ TEST_F(ClassicPairingHandlerTest, locally_initiatied_display_only_display_only_t
  ReceiveLinkKeyNotification(device_, link_key, key_type);
  ASSERT_EQ(link_key, security_record_->GetLinkKey());
  ASSERT_EQ(key_type, security_record_->GetKeyType());
  ASSERT_FALSE(security_record_->IsAuthenticated());
  ASSERT_FALSE(security_record_->RequiresMitmProtection());
}

// display_only + display_yes_no is JustWorks no confirmation
@@ -306,6 +308,8 @@ TEST_F(ClassicPairingHandlerTest, locally_initiatied_display_only_display_yes_no
  ReceiveLinkKeyNotification(device_, link_key, key_type);
  ASSERT_EQ(link_key, security_record_->GetLinkKey());
  ASSERT_EQ(key_type, security_record_->GetKeyType());
  ASSERT_FALSE(security_record_->IsAuthenticated());
  ASSERT_FALSE(security_record_->RequiresMitmProtection());
}

// display_only + no_input_no_output is JustWorks no confirmation
@@ -342,6 +346,8 @@ TEST_F(ClassicPairingHandlerTest, locally_initiatied_display_only_no_input_no_ou
  ReceiveLinkKeyNotification(device_, link_key, key_type);
  ASSERT_EQ(link_key, security_record_->GetLinkKey());
  ASSERT_EQ(key_type, security_record_->GetKeyType());
  ASSERT_FALSE(security_record_->IsAuthenticated());
  ASSERT_FALSE(security_record_->RequiresMitmProtection());
}

// keyboard_only + no_input_no_output is JustWorks no confirmation
@@ -378,6 +384,8 @@ TEST_F(ClassicPairingHandlerTest, locally_initiatied_keyboard_only_no_input_no_o
  ReceiveLinkKeyNotification(device_, link_key, key_type);
  ASSERT_EQ(link_key, security_record_->GetLinkKey());
  ASSERT_EQ(key_type, security_record_->GetKeyType());
  ASSERT_FALSE(security_record_->IsAuthenticated());
  ASSERT_FALSE(security_record_->RequiresMitmProtection());
}

// no_input_no_output + display_only is JustWorks no confirmation
@@ -414,6 +422,8 @@ TEST_F(ClassicPairingHandlerTest, locally_initiatied_no_input_no_output_display_
  ReceiveLinkKeyNotification(device_, link_key, key_type);
  ASSERT_EQ(link_key, security_record_->GetLinkKey());
  ASSERT_EQ(key_type, security_record_->GetKeyType());
  ASSERT_FALSE(security_record_->IsAuthenticated());
  ASSERT_FALSE(security_record_->RequiresMitmProtection());
}

// no_input_no_output + display_yes_no is JustWorks no confirmation
@@ -450,6 +460,8 @@ TEST_F(ClassicPairingHandlerTest, locally_initiatied_no_input_no_output_display_
  ReceiveLinkKeyNotification(device_, link_key, key_type);
  ASSERT_EQ(link_key, security_record_->GetLinkKey());
  ASSERT_EQ(key_type, security_record_->GetKeyType());
  ASSERT_FALSE(security_record_->IsAuthenticated());
  ASSERT_FALSE(security_record_->RequiresMitmProtection());
}

// no_input_no_output + keyboard_only is JustWorks no confirmation
@@ -486,6 +498,8 @@ TEST_F(ClassicPairingHandlerTest, locally_initiatied_no_input_no_output_keyboard
  ReceiveLinkKeyNotification(device_, link_key, key_type);
  ASSERT_EQ(link_key, security_record_->GetLinkKey());
  ASSERT_EQ(key_type, security_record_->GetKeyType());
  ASSERT_FALSE(security_record_->IsAuthenticated());
  ASSERT_FALSE(security_record_->RequiresMitmProtection());
}

// no_input_no_output + no_input_no_output is JustWorks no confirmation
@@ -522,6 +536,8 @@ TEST_F(ClassicPairingHandlerTest, locally_initiatied_no_input_no_output_no_input
  ReceiveLinkKeyNotification(device_, link_key, key_type);
  ASSERT_EQ(link_key, security_record_->GetLinkKey());
  ASSERT_EQ(key_type, security_record_->GetKeyType());
  ASSERT_FALSE(security_record_->IsAuthenticated());
  ASSERT_FALSE(security_record_->RequiresMitmProtection());
}

/*** Numeric Comparison ***/
+27 −0
Original line number Diff line number Diff line
@@ -84,6 +84,30 @@ class SecurityRecord {
    return pseudo_address_;
  }

  void SetAuthenticated(bool is_authenticated) {
    this->is_authenticated_ = is_authenticated;
  }

  bool IsAuthenticated() {
    return this->is_authenticated_;
  }

  void SetRequiresMitmProtection(bool requires_mitm_protection) {
    this->requires_mitm_protection_ = requires_mitm_protection;
  }

  bool RequiresMitmProtection() {
    return this->requires_mitm_protection_;
  }

  void SetIsEncryptionRequired(bool is_encryption_required) {
    this->is_encryption_required_ = is_encryption_required;
  }

  bool IsEncryptionRequired() {
    return this->is_encryption_required_;
  }

 private:
  /* First address we have ever seen this device with, that we used to create bond */
  hci::AddressWithType pseudo_address_;
@@ -96,6 +120,9 @@ class SecurityRecord {
  }
  bool persisted_ = false;
  bool pairing_ = false;
  bool is_authenticated_ = false;
  bool requires_mitm_protection_ = false;
  bool is_encryption_required_ = false;

 public:
  /* Identity Address */