• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *  Copyright 2019 The Android Open Source Project
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  */
18 
19 #pragma once
20 
21 #include <memory>
22 #include <vector>
23 
24 #include "hci/address_with_type.h"
25 #include "security/internal/security_manager_impl.h"
26 #include "security/security_manager_listener.h"
27 
28 namespace bluetooth {
29 namespace security {
30 
31 /**
32  * Manages the security attributes, pairing, bonding of devices, and the
33  * encryption/decryption of communications.
34  */
35 class SecurityManager : public UICallbacks {
36  public:
37   friend class SecurityModule;
38 
39   /**
40    * Initialize the security record map from an internal device database.
41    */
42   void Init();
43 
44   /**
45    * Initiates bond over Classic transport with device, if not bonded yet.
46    *
47    * @param address device address we want to bond with
48    */
49   void CreateBond(hci::AddressWithType address);
50 
51   /**
52    * Initiates bond over Low Energy transport with device, if not bonded yet.
53    *
54    * @param address device address we want to bond with
55    */
56   void CreateBondLe(hci::AddressWithType address);
57 
58   /**
59    * Cancels the pairing process for this device.
60    *
61    * @param device pointer to device with which we want to cancel our bond
62    */
63   void CancelBond(hci::AddressWithType device);
64 
65   /**
66    * Disassociates the device and removes the persistent LTK
67    *
68    * @param device pointer to device we want to forget
69    */
70   void RemoveBond(hci::AddressWithType device);
71 
72   /**
73    * Register Security UI handler, for handling prompts around the Pairing process.
74    */
75   void SetUserInterfaceHandler(UI* user_interface, os::Handler* handler);
76 
77   /**
78    * Register to listen for callback events from SecurityManager
79    *
80    * @param listener ISecurityManagerListener instance to handle callbacks
81    */
82   void RegisterCallbackListener(ISecurityManagerListener* listener, os::Handler* handler);
83 
84   /**
85    * Unregister listener for callback events from SecurityManager
86    *
87    * @param listener ISecurityManagerListener instance to unregister
88    */
89   void UnregisterCallbackListener(ISecurityManagerListener* listener);
90 
91   void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) override;
92   void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) override;
93   void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) override;
94 
95  protected:
SecurityManager(os::Handler * security_handler,internal::SecurityManagerImpl * security_manager_impl)96   SecurityManager(os::Handler* security_handler, internal::SecurityManagerImpl* security_manager_impl)
97       : security_handler_(security_handler), security_manager_impl_(security_manager_impl) {}
98 
99  private:
100   os::Handler* security_handler_ = nullptr;
101   internal::SecurityManagerImpl* security_manager_impl_;
102   DISALLOW_COPY_AND_ASSIGN(SecurityManager);
103 };
104 
105 }  // namespace security
106 }  // namespace bluetooth
107