Skip to content

Commit

Permalink
Merge pull request ARMmbed#25 from paul-szczepanek-arm/oob-gen
Browse files Browse the repository at this point in the history
generate oob at will and without passing in connection handle
  • Loading branch information
paul-szczepanek-arm authored Apr 3, 2018
2 parents 5d3b80e + 576796b commit 381b99b
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 73 deletions.
21 changes: 21 additions & 0 deletions features/FEATURE_BLE/ble/BLETypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@ class PasskeyAscii {
uint8_t ascii[PASSKEY_LEN];
};

/**
* Returns true if every byte is equal to zero
*/
template <class byte_array_class>
bool is_all_zeros(byte_array_class &byte_array) {
for (size_t i = 0; i < byte_array.size(); i++) {
if (byte_array[i] != 0) {
return false;
}
}
return true;
}

/**
* Zero out all bytes
*/
template <class byte_array_class>
void set_all_zeros(byte_array_class &byte_array) {
memset(&byte_array[0], 0x00, byte_array.size());
}

template <size_t array_size>
struct byte_array_t {
/**
Expand Down
39 changes: 36 additions & 3 deletions features/FEATURE_BLE/ble/SecurityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -735,15 +735,48 @@ class SecurityManager {
// MITM
//

/**
* Generate OOB data with the given address. If Secure Connections is supported this will
* also generate Secure Connections OOB data on top of legacy pairing OOB data. This can be used
* to generate such data before the connection takes place.
*
* In this model the OOB exchange takes place before the devices connect. Devices should establish
* communication over another channel and exchange the OOB data. The address provided will be used
* by the peer to associate the received data with the address of the device it will then connect
* to over BLE.
*
* @param[in] address The local address you will use in the connection using this OOB data. This
* address will be returned along with the rest of the OOB data when generation
* is complete. Using an invalid address is illegal.
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
*/
virtual ble_error_t generateOOB(const ble::address_t *address) {
/* Avoid compiler warnings about unused variables */
(void) address;
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if security is supported. */
}

/**
* Enable OOB data usage during paring. If Secure Connections is supported enabling useOOB will
* generate Secure Connections OOB data through oobGenerated().
* generate Secure Connections OOB data through oobGenerated() on top of legacy pairing OOB data.
*
* You do not have to call this function to return received OOB data. Use legacyPairingOobReceived
* or oobReceived to hand it in. This will allow the stack to use it if possible. You only need to
* call this function to attempt legacy OOB data exchange after pairing start and to inform
* the stack OOB data does not provide MITM protection (by default it is set to provide this).
*
* In this model the OOB exchange takes places after the devices have connected but possibly
* prior to pairing. For secure connections pairing must not be started until after the OOB
* data has been sent and/or received. The address in the OOB data generated will match
* the original address used to establish the connection and will be used by the peer to
* identify which connection the OOB data belongs to.
*
* @param[in] connectionHandle Handle to identify the connection.
* @param[in] useOOB If set to true, authenticate using OOB data.
* @param[in] OOBProvidesMITM If set to true keys exchanged during pairing using OOB data
* will provide MITM protection. This indicates that the form
* of exchange used by the OOB data itself provides MITM protection.
* will provide Man-in-the-Middle protection. This indicates that
* the form of exchange used by the OOB data itself provides MITM
* protection.
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
*/
virtual ble_error_t setOOBDataUsage(ble::connection_handle_t connectionHandle, bool useOOB, bool OOBProvidesMITM = true) {
Expand Down
11 changes: 10 additions & 1 deletion features/FEATURE_BLE/ble/generic/GenericSecurityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ class GenericSecurityManager : public SecurityManager,
// MITM
//

virtual ble_error_t generateOOB(
const address_t *address
);

virtual ble_error_t setOOBDataUsage(
connection_handle_t connection,
bool useOOB,
Expand Down Expand Up @@ -240,6 +244,11 @@ class GenericSecurityManager : public SecurityManager,
_legacy_pairing_allowed(true),
_master_sends_keys(false) {
_pal.set_event_handler(this);

/* We create a fake value for oob to allow creation of the next oob which needs
* the last process to finish first before restarting (this is to simplify checking).
* This fake value will not be used as the oob address is currently invalid */
_oob_local_random[0] = 1;
}

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -441,6 +450,7 @@ class GenericSecurityManager : public SecurityManager,
pal::ConnectionEventMonitor &_connection_monitor;

/* OOB data */
address_t _oob_local_address;
address_t _oob_peer_address;
oob_lesc_value_t _oob_peer_random;
oob_confirm_t _oob_peer_confirm;
Expand Down Expand Up @@ -572,7 +582,6 @@ class GenericSecurityManager : public SecurityManager,
/** @copydoc ble::pal::SecurityManager::on_secure_connections_oob_generated
*/
virtual void on_secure_connections_oob_generated(
connection_handle_t connection,
const oob_lesc_value_t &random,
const oob_confirm_t &confirm
);
Expand Down
Loading

0 comments on commit 381b99b

Please sign in to comment.