Addressed Vincent's comments

pull/6188/head
Donatien Garnier 2018-03-01 20:31:51 +00:00
parent ded1403399
commit a3383c139b
8 changed files with 83 additions and 150 deletions

View File

@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef _SECURITY_MANAGER_H_ #ifndef SECURITY_MANAGER_H_
#define _SECURITY_MANAGER_H_ #define SECURITY_MANAGER_H_
#include <stdint.h> #include <stdint.h>
@ -57,7 +57,7 @@
* it. If either side doesn't support it Legacy Pairing will be used. This is an older standard of pairing. * it. If either side doesn't support it Legacy Pairing will be used. This is an older standard of pairing.
* If higher security is required legacy pairing can be disabled by calling allowLegacyPairing(false); * If higher security is required legacy pairing can be disabled by calling allowLegacyPairing(false);
* *
* How to use * \par How to use
* *
* First thing you need to do is to initialise the manager by calling init() with your chosen settings. * First thing you need to do is to initialise the manager by calling init() with your chosen settings.
* *
@ -87,9 +87,11 @@
* accetPairing() or cancelPairing(). The result will be communicated on both peers through an event calling * accetPairing() or cancelPairing(). The result will be communicated on both peers through an event calling
* pairingResult() in the EventHandler. * pairingResult() in the EventHandler.
* *
* \par Sequence diagrams
* *
* Sequence diagram "Just Works" pairing * Sequence diagram "Just Works" pairing
* *
* \verbatim
* /----------- Device 1 --------------\ *------ BLE link ------* /-------------- Device 2 -------------\ * /----------- Device 1 --------------\ *------ BLE link ------* /-------------- Device 2 -------------\
* *
* App EventHandler SecurityManager SecurityManager EventHandler App * App EventHandler SecurityManager SecurityManager EventHandler App
@ -101,6 +103,7 @@
* | | |<---[pairing complete]----->| | | * | | |<---[pairing complete]----->| | |
* |<- pairingResult() <---------------| |----------------> pairingResult() -->| * |<- pairingResult() <---------------| |----------------> pairingResult() -->|
* | | | | | | * | | | | | |
* \endverbatim
* *
* @note the requestPairing() call isn't required to trigger pairing. Pairing will also be triggered * @note the requestPairing() call isn't required to trigger pairing. Pairing will also be triggered
* if you request encryption and authentication and no bonding information is available. The sequence will * if you request encryption and authentication and no bonding information is available. The sequence will
@ -109,6 +112,7 @@
* *
* Sequence diagram Encryption request when bonding information is available * Sequence diagram Encryption request when bonding information is available
* *
* \verbatim
* /----------- Device 1 --------------\ *------ BLE link ------* /-------------- Device 2 -------------\ * /----------- Device 1 --------------\ *------ BLE link ------* /-------------- Device 2 -------------\
* *
* App EventHandler SecurityManager SecurityManager EventHandler App * App EventHandler SecurityManager SecurityManager EventHandler App
@ -117,6 +121,7 @@
* | | |<-[encryption established]->| | | * | | |<-[encryption established]->| | |
* |<- linkEncryptionResult() <--------| |---------> linkEncryptionResult() -->| * |<- linkEncryptionResult() <--------| |---------> linkEncryptionResult() -->|
* | | | | | | * | | | | | |
* \endverbatim
* *
* @note if bonding information is not available, pairing will be triggered * @note if bonding information is not available, pairing will be triggered
* *
@ -124,6 +129,7 @@
* Sequence diagram for Secure Connections passkey entry pairing with one device having a display only * Sequence diagram for Secure Connections passkey entry pairing with one device having a display only
* and other a keyboard * and other a keyboard
* *
* \verbatim
* /----------- Device 1 (keyboard) ---\ *------ BLE link ------* /-------------- Device 2 (display) ---\ * /----------- Device 1 (keyboard) ---\ *------ BLE link ------* /-------------- Device 2 (display) ---\
* *
* App EventHandler SecurityManager SecurityManager EventHandler App * App EventHandler SecurityManager SecurityManager EventHandler App
@ -143,6 +149,7 @@
* | | |<---[pairing complete]----->| | | * | | |<---[pairing complete]----->| | |
* |<- pairingResult() <---------------| |----------------> pairingResult() -->| * |<- pairingResult() <---------------| |----------------> pairingResult() -->|
* | | | | | | * | | | | | |
* \endverbatim
* *
*/ */
@ -267,9 +274,7 @@ public:
* @param[in] whitelist pointer to the whitelist filled with entries based on bonding information * @param[in] whitelist pointer to the whitelist filled with entries based on bonding information
*/ */
virtual void whitelistFromBondTable(Gap::Whitelist_t* whitelist) { virtual void whitelistFromBondTable(Gap::Whitelist_t* whitelist) {
if (whitelist) { (void)whitelist;
delete whitelist;
}
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -1070,4 +1075,4 @@ protected:
LegacyEventHandler defaultEventHandler; LegacyEventHandler defaultEventHandler;
}; };
#endif /*_SECURITY_MANAGER_H_*/ #endif /*SECURITY_MANAGER_H_*/

View File

@ -276,7 +276,7 @@ private:
/** @note Implements ConnectionEventMonitor. /** @note Implements ConnectionEventMonitor.
* @copydoc ConnectionEventMonitor::set_connection_event_handler * @copydoc ConnectionEventMonitor::set_connection_event_handler
*/ */
void set_connection_event_handler(pal::ConnectionEventHandler *_connection_event_handler); void set_connection_event_handler(pal::ConnectionEventMonitor::EventHandler *_connection_event_handler);
void on_scan_timeout(); void on_scan_timeout();
@ -317,7 +317,7 @@ private:
mutable Whitelist_t _whitelist; mutable Whitelist_t _whitelist;
mbed::Timeout _advertising_timeout; mbed::Timeout _advertising_timeout;
mbed::Timeout _scan_timeout; mbed::Timeout _scan_timeout;
pal::ConnectionEventHandler *_connection_event_handler; pal::ConnectionEventMonitor::EventHandler *_connection_event_handler;
}; };
} }

View File

@ -28,16 +28,11 @@
namespace ble { namespace ble {
namespace generic { namespace generic {
using pal::advertising_peer_address_type_t;
using pal::AuthenticationMask;
using pal::KeyDistribution;
using pal::connection_peer_address_type_t;
typedef SecurityManager::SecurityIOCapabilities_t SecurityIOCapabilities_t; typedef SecurityManager::SecurityIOCapabilities_t SecurityIOCapabilities_t;
class GenericSecurityManager : public SecurityManager, class GenericSecurityManager : public SecurityManager,
public pal::SecurityManager::EventHandler, public pal::SecurityManager::EventHandler,
public pal::ConnectionEventHandler { public pal::ConnectionEventMonitor::EventHandler {
public: public:
typedef ble::pal::SecurityDistributionFlags_t SecurityDistributionFlags_t; typedef ble::pal::SecurityDistributionFlags_t SecurityDistributionFlags_t;
typedef ble::pal::SecurityEntryKeys_t SecurityEntryKeys_t; typedef ble::pal::SecurityEntryKeys_t SecurityEntryKeys_t;
@ -240,7 +235,7 @@ public:
_db(dbImpl), _db(dbImpl),
_connection_monitor(connMonitorImpl), _connection_monitor(connMonitorImpl),
_default_authentication(0), _default_authentication(0),
_default_key_distribution(KeyDistribution::KEY_DISTRIBUTION_ALL), _default_key_distribution(pal::KeyDistribution::KEY_DISTRIBUTION_ALL),
_pairing_authorisation_required(false), _pairing_authorisation_required(false),
_legacy_pairing_allowed(true), _legacy_pairing_allowed(true),
_master_sends_keys(false), _master_sends_keys(false),
@ -432,16 +427,16 @@ private:
struct ControlBlock_t : public pal::SecurityDistributionFlags_t { struct ControlBlock_t : public pal::SecurityDistributionFlags_t {
ControlBlock_t(); ControlBlock_t();
KeyDistribution get_initiator_key_distribution() { pal::KeyDistribution get_initiator_key_distribution() {
return KeyDistribution(initiator_key_distribution); return pal::KeyDistribution(initiator_key_distribution);
}; };
KeyDistribution get_responder_key_distribution() { pal::KeyDistribution get_responder_key_distribution() {
return KeyDistribution(responder_key_distribution); return pal::KeyDistribution(responder_key_distribution);
}; };
void set_initiator_key_distribution(KeyDistribution mask) { void set_initiator_key_distribution(pal::KeyDistribution mask) {
initiator_key_distribution = mask.value(); initiator_key_distribution = mask.value();
}; };
void set_responder_key_distribution(KeyDistribution mask) { void set_responder_key_distribution(pal::KeyDistribution mask) {
responder_key_distribution = mask.value(); responder_key_distribution = mask.value();
}; };
@ -476,8 +471,8 @@ private:
pal::SecurityDb &_db; pal::SecurityDb &_db;
pal::ConnectionEventMonitor &_connection_monitor; pal::ConnectionEventMonitor &_connection_monitor;
AuthenticationMask _default_authentication; pal::AuthenticationMask _default_authentication;
KeyDistribution _default_key_distribution; pal::KeyDistribution _default_key_distribution;
bool _pairing_authorisation_required; bool _pairing_authorisation_required;
bool _legacy_pairing_allowed; bool _legacy_pairing_allowed;
@ -504,9 +499,9 @@ public:
virtual void on_pairing_request( virtual void on_pairing_request(
connection_handle_t connection, connection_handle_t connection,
bool use_oob, bool use_oob,
AuthenticationMask authentication, pal::AuthenticationMask authentication,
KeyDistribution initiator_dist, pal::KeyDistribution initiator_dist,
KeyDistribution responder_dist pal::KeyDistribution responder_dist
); );
/** @copydoc ble::pal::SecurityManager::on_pairing_error /** @copydoc ble::pal::SecurityManager::on_pairing_error
@ -542,7 +537,7 @@ public:
*/ */
virtual void on_slave_security_request( virtual void on_slave_security_request(
connection_handle_t connection, connection_handle_t connection,
AuthenticationMask authentication pal::AuthenticationMask authentication
); );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -665,7 +660,7 @@ public:
*/ */
virtual void on_keys_distributed_bdaddr( virtual void on_keys_distributed_bdaddr(
connection_handle_t connection, connection_handle_t connection,
advertising_peer_address_type_t peer_address_type, pal::advertising_peer_address_type_t peer_address_type,
const address_t &peer_identity_address const address_t &peer_identity_address
); );

View File

@ -24,11 +24,17 @@
namespace ble { namespace ble {
namespace pal { namespace pal {
/**
* Implemented by classes that need to be notified of connection changes.
* Notification is done by calling functions in the passed in event handler
*/
class ConnectionEventMonitor {
public:
/** /**
* Implemented by classes that are reacting to connection changes. * Implemented by classes that are reacting to connection changes.
* @see ConnectionEventMonitor * @see ConnectionEventMonitor
*/ */
class ConnectionEventHandler { class EventHandler {
public: public:
/** /**
* Inform the Security manager of a new connection. This will create * Inform the Security manager of a new connection. This will create
@ -65,18 +71,12 @@ public:
) = 0; ) = 0;
}; };
/**
* Implemented by classes that need to be notified of connection changes.
* Notification is done by calling functions in the passed in event handler
*/
class ConnectionEventMonitor {
public:
/** /**
* Register a handler for connection events to be used internally and serviced first. * Register a handler for connection events to be used internally and serviced first.
* *
* @param[in] connection_event_handler Event handler being registered. * @param[in] connection_event_handler Event handler being registered.
*/ */
virtual void set_connection_event_handler(ConnectionEventHandler *connection_event_handler) = 0; virtual void set_connection_event_handler(EventHandler *connection_event_handler) = 0;
}; };
} // namespace pal } // namespace pal

View File

@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef _PAL_MEMORY_SECURITY_DB_H_ #ifndef PAL_MEMORY_SECURITY_DB_H_
#define _PAL_MEMORY_SECURITY_DB_H_ #define PAL_MEMORY_SECURITY_DB_H_
#include "SecurityDB.h" #include "SecurityDB.h"
@ -369,4 +369,4 @@ private:
} /* namespace pal */ } /* namespace pal */
} /* namespace ble */ } /* namespace ble */
#endif /*_PAL_MEMORY_SECURITY_DB_H_*/ #endif /*PAL_MEMORY_SECURITY_DB_H_*/

View File

@ -1169,7 +1169,7 @@ bool GenericGap::initialize_whitelist() const
return true; return true;
} }
void GenericGap::set_connection_event_handler(pal::ConnectionEventHandler *connection_event_handler) void GenericGap::set_connection_event_handler(pal::ConnectionEventMonitor::EventHandler *connection_event_handler)
{ {
_connection_event_handler = connection_event_handler; _connection_event_handler = connection_event_handler;
} }

View File

@ -21,6 +21,11 @@
#include "mbedtls/cmac.h" #include "mbedtls/cmac.h"
#endif #endif
using ble::pal::advertising_peer_address_type_t;
using ble::pal::AuthenticationMask;
using ble::pal::KeyDistribution;
using ble::pal::connection_peer_address_type_t;
namespace ble { namespace ble {
namespace generic { namespace generic {

View File

@ -1,72 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TESTS_GENERIC_SECURITYMANAGER_MOCK_MOCKSECURITYMANAGEREVENTHANDLER_H_
#define TESTS_GENERIC_SECURITYMANAGER_MOCK_MOCKSECURITYMANAGEREVENTHANDLER_H_
#include "gmock/gmock.h"
#include "ble/SecurityManager.h"
namespace ble {
namespace pal {
namespace vendor {
namespace mock {
/*
* Mock of ble::pal::SecurityManager
*/
class MockSecurityManagerEventHandler :
public ::SecurityManager::EventHandler {
public:
MockSecurityManagerEventHandler();
virtual ~MockSecurityManagerEventHandler();
MOCK_METHOD1(pairingRequest, void(connection_handle_t));
MOCK_METHOD2(pairingResult, void(connection_handle_t, ::SecurityManager::SecurityCompletionStatus_t));
MOCK_METHOD1(validMicTimeout, void(connection_handle_t));
MOCK_METHOD1(whitelistFromBondTable, void(::Gap::Whitelist_t*));
MOCK_METHOD2(whitelistFromBondTable, void(connection_handle_t, link_encryption_t));
MOCK_METHOD2(passkeyDisplay, void(connection_handle_t, const ::SecurityManager::Passkey_t));
MOCK_METHOD1(confirmationRequest, void(connection_handle_t));
MOCK_METHOD1(passkeyRequest, void(connection_handle_t));
MOCK_METHOD2(keypressNotification, void(connection_handle_t, ::SecurityManager::Keypress_t));
MOCK_METHOD1(legacyPairingOobRequest, void(connection_handle_t));
MOCK_METHOD1(oobRequest, void(connection_handle_t));
MOCK_METHOD2(legacyPairingOobGenerated, void(const address_t *, const oob_tk_t *));
MOCK_METHOD3(oobGenerated, void(const address_t *, const oob_lesc_value_t *, const oob_confirm_t *));
MOCK_METHOD3(signingKey, void(connection_handle_t, const csrk_t *, bool));
};
} // namespace ble
} // namespace pal
} // namespace vendor
} // namespace mock
#endif /* TESTS_GENERIC_SECURITYMANAGER_MOCK_MOCKSECURITYMANAGEREVENTHANDLER_H_ */