Merge pull request #16 from pan-/palsm-test

Security DB mock
pull/6188/head
Paul Szczepanek 2018-02-19 17:56:47 +00:00 committed by GitHub
commit c1d15b5731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 252 additions and 20 deletions

View File

@ -28,7 +28,7 @@
#ifdef YOTTA_CFG_MBED_OS
#include "mbed-drivers/mbed_error.h"
#else
#include "mbed_error.h"
#include "platform/mbed_error.h"
#endif
#include "platform/mbed_toolchain.h"

View File

@ -28,7 +28,7 @@
#include "ble/BLETypes.h"
#include "ble/pal/GenericAccessService.h"
#include "ble/pal/EventQueue.h"
#include "ble/ConnectionEventMonitor.h"
#include "ble/pal/ConnectionEventMonitor.h"
#include "drivers/Timeout.h"
@ -42,7 +42,7 @@ namespace generic {
* @attention: Not part of the public interface of BLE API.
*/
class GenericGap : public ::Gap,
public ConnectionEventMonitor {
public pal::ConnectionEventMonitor {
public:
/**
@ -275,7 +275,7 @@ public:
/** @note Implements ConnectionEventMonitor.
* @copydoc ConnectionEventMonitor::set_connection_event_handler
*/
virtual void set_connection_event_handler(ConnectionEventHandler *_connection_event_handler);
void set_connection_event_handler(pal::ConnectionEventHandler *_connection_event_handler);
private:
void on_scan_timeout();
@ -317,7 +317,7 @@ private:
mutable Whitelist_t _whitelist;
mbed::Timeout _advertising_timeout;
mbed::Timeout _scan_timeout;
ConnectionEventHandler *_connection_event_handler;
pal::ConnectionEventHandler *_connection_event_handler;
};
}

View File

@ -21,7 +21,7 @@
#include "ble/BLETypes.h"
#include "ble/pal/SecurityDb.h"
#include "platform/Callback.h"
#include "ble/Gap.h"
#include "ble/pal/ConnectionEventMonitor.h"
#include "ble/generic/GenericGap.h"
#include "ble/pal/PalSecurityManager.h"
@ -39,7 +39,7 @@ class GenericSecurityManagerEventHandler;
class GenericSecurityManager : public SecurityManager,
public pal::SecurityManagerEventHandler,
public ConnectionEventHandler {
public pal::ConnectionEventHandler {
public:
typedef ble::pal::SecurityEntry_t SecurityEntry_t;
typedef ble::pal::SecurityEntryKeys_t SecurityEntryKeys_t;
@ -237,10 +237,10 @@ public:
GenericSecurityManager(
pal::SecurityManager &palImpl,
pal::SecurityDb &dbImpl,
GenericGap &gapImpl
pal::ConnectionEventMonitor &connMonitorImpl
) : _pal(palImpl),
_db(dbImpl),
_gap(gapImpl),
_connection_monitor(connMonitorImpl),
_default_authentication(0),
_default_key_distribution(KeyDistribution::KEY_DISTRIBUTION_ALL),
_pairing_authorisation_required(false),
@ -433,7 +433,7 @@ private:
private:
pal::SecurityManager &_pal;
pal::SecurityDb &_db;
GenericGap &_gap;
pal::ConnectionEventMonitor &_connection_monitor;
AuthenticationMask _default_authentication;
KeyDistribution _default_key_distribution;

View File

@ -30,22 +30,23 @@
#include "ble/pal/EventQueue.h"
namespace ble {
namespace pal {
class ConnectionEventHandler {
public:
virtual void on_connected(
connection_handle_t connection,
Gap::Role_t role,
::Gap::Role_t role,
BLEProtocol::AddressType_t peer_address_type,
const BLEProtocol::AddressBytes_t peer_address,
BLEProtocol::AddressType_t local_address_type,
const BLEProtocol::AddressBytes_t local_address,
const Gap::ConnectionParams_t *connection_params
const ::Gap::ConnectionParams_t *connection_params
) = 0;
virtual void on_disconnected(
connection_handle_t connection,
Gap::DisconnectionReason_t reason
::Gap::DisconnectionReason_t reason
) = 0;
};
@ -59,6 +60,7 @@ public:
virtual void set_connection_event_handler(ConnectionEventHandler *connection_event_handler) = 0;
};
}
} // namespace pal
} // namespace ble
#endif /* MBED_BLE_CONNECTION_EVENT_MONITOR */

View File

@ -20,6 +20,7 @@
#include "platform/Callback.h"
#include "ble/pal/GapTypes.h"
#include "ble/BLETypes.h"
#include "ble/Gap.h"
#include <stdlib.h>
namespace ble {

View File

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

View File

@ -55,7 +55,7 @@ ble_error_t GenericSecurityManager::init(
init_signing();
}
_gap.set_connection_event_handler(this);
_connection_monitor.set_connection_event_handler(this);
_pal.generate_public_key();

View File

@ -93,12 +93,14 @@ add_test(NAME GattClientTests COMMAND gatt-client-tests)
add_executable(security-manager-tests
mbed_os_stub/mbed_assert.c
generic/SecurityManager/mock/MockPalSecurityManager.cpp
generic/SecurityManager/mock/MockPalSecurityDb.cpp
${PROJECT_SOURCE_DIR}/../source/generic/GenericSecurityManager.cpp
)
target_include_directories(security-manager-tests PRIVATE
"${PROJECT_SOURCE_DIR}/.."
"${PROJECT_SOURCE_DIR}/../../.."
"${PROJECT_SOURCE_DIR}/mbed_os_stub"
"${PROJECT_SOURCE_DIR}/generic/SecurityManager"
)

View File

@ -0,0 +1,35 @@
/* 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.
*/
#include "MockPalSecurityDb.h"
namespace ble {
namespace pal {
namespace vendor {
namespace mock {
////////////////////////////////////////////////////////////////////////////////
// Constructor implementation of the mocked pal security manager
//
// WARNING: Do not remove; it speedup compile time.
MockPalSecurityDb::MockPalSecurityDb() { }
MockPalSecurityDb::~MockPalSecurityDb() { }
} // namespace ble
} // namespace pal
} // namespace vendor
} // namespace mock

View File

@ -0,0 +1,192 @@
/* 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_MOCKPALSECURITYDB_H_
#define TESTS_GENERIC_SECURITYMANAGER_MOCK_MOCKPALSECURITYDB_H_
#include "gmock/gmock.h"
#include "ble/pal/SecurityDB.h"
namespace ble {
namespace pal {
namespace vendor {
namespace mock {
/*
* Mock of ble::pal::SecurityDB
*/
class MockPalSecurityDb : public ble::pal::SecurityDb {
public:
MockPalSecurityDb();
virtual ~MockPalSecurityDb();
MOCK_METHOD1(get_entry, SecurityEntry_t*(connection_handle_t));
MOCK_METHOD1(get_entry, SecurityEntry_t*(const address_t &));
MOCK_METHOD4(
get_entry_local_keys,
void(
SecurityEntryKeysDbCb_t,
connection_handle_t,
const ediv_t &,
const rand_t &
)
);
MOCK_METHOD2(
get_entry_local_keys,
void(SecurityEntryKeysDbCb_t, connection_handle_t)
);
MOCK_METHOD2(
set_entry_local_ltk,
void(connection_handle_t, const ltk_t &)
);
MOCK_METHOD3(
set_entry_local_ediv_rand,
void(connection_handle_t, const ediv_t &, const rand_t &)
);
MOCK_METHOD2(
get_entry_peer_csrk,
void(SecurityEntryCsrkDbCb_t, connection_handle_t)
);
MOCK_METHOD2(
get_entry_peer_keys,
void(SecurityEntryKeysDbCb_t, connection_handle_t)
);
MOCK_METHOD2(
set_entry_peer_ltk,
void(connection_handle_t, const ltk_t &)
);
MOCK_METHOD3(
set_entry_peer_ediv_rand,
void(connection_handle_t, const ediv_t &, const rand_t &)
);
MOCK_METHOD2(
set_entry_peer_irk,
void(connection_handle_t, const irk_t &)
);
MOCK_METHOD3(
set_entry_peer_bdaddr,
void(connection_handle_t, bool, const address_t &)
);
MOCK_METHOD2(
set_entry_peer_csrk,
void(connection_handle_t, const csrk_t &)
);
MOCK_METHOD0(get_local_csrk, const csrk_t*());
MOCK_METHOD1(set_local_csrk, void(const csrk_t &));
MOCK_METHOD0(get_public_key_x, const public_key_t&());
MOCK_METHOD0(get_public_key_y, const public_key_t&());
MOCK_METHOD2(set_public_key, void(const public_key_t &, const public_key_t &));
MOCK_METHOD0(get_peer_sc_oob_address, const address_t&());
MOCK_METHOD0(get_peer_sc_oob_random, const oob_rand_t&());
MOCK_METHOD0(get_peer_sc_oob_confirm, const oob_confirm_t&());
MOCK_METHOD4(
get_sc_oob_data,
void(
address_t &,
oob_rand_t &,
oob_confirm_t &,
oob_rand_t &
)
);
MOCK_METHOD0(get_local_sc_oob_random, const oob_rand_t&());
MOCK_METHOD3(
set_peer_sc_oob_data,
void(
const address_t &,
const oob_rand_t &,
const oob_confirm_t &
)
);
MOCK_METHOD1(set_local_sc_oob_random, void(const oob_rand_t&));
MOCK_METHOD4(
connect_entry,
SecurityEntry_t*(
connection_handle_t,
BLEProtocol::AddressType_t,
const address_t &,
const address_t &
)
);
MOCK_METHOD1(disconnect_entry, void(connection_handle_t));
MOCK_METHOD1(remove_entry, void(const address_t));
MOCK_METHOD0(clear_entries, void());
MOCK_METHOD2(get_whitelist, void(WhitelistDbCb_t, Gap::Whitelist_t *));
MOCK_METHOD2(
generate_whitelist_from_bond_table,
void(WhitelistDbCb_t, Gap::Whitelist_t *)
);
MOCK_METHOD2(
set_whitelist,
void(WhitelistDbCb_t, const Gap::Whitelist_t &)
);
MOCK_METHOD1(
add_whitelist_entry,
void(const address_t &)
);
MOCK_METHOD1(
remove_whitelist_entry,
void(const address_t &)
);
MOCK_METHOD0(clear_whitelist, void());
MOCK_METHOD0(restore, void());
MOCK_METHOD0(sync, void());
MOCK_METHOD1(set_restore, void(bool));
};
} // namespace ble
} // namespace pal
} // namespace vendor
} // namespace mock
#endif /* TESTS_GENERIC_SECURITYMANAGER_MOCK_MOCKPALSECURITYDB_H_ */

View File

@ -5,7 +5,7 @@
* \defgroup platform_sleep Sleep functions
* @{
*/
/* mbed Microcontroller Library
* Copyright (c) 2006-2017 ARM Limited
*
@ -24,7 +24,7 @@
#ifndef MBED_SLEEP_H
#define MBED_SLEEP_H
#include "sleep_api.h"
#include "hal/sleep_api.h"
#include "mbed_toolchain.h"
#include <stdbool.h>
@ -128,7 +128,7 @@ void sleep_manager_sleep_auto(void);
* Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be
* able to access the LocalFileSystem
*/
__INLINE static void sleep(void)
static inline void sleep(void)
{
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
#if DEVICE_SLEEP
@ -158,7 +158,7 @@ __INLINE static void sleep(void)
*/
MBED_DEPRECATED_SINCE("mbed-os-5.6", "One entry point for an application, use sleep()")
__INLINE static void deepsleep(void)
static inline void deepsleep(void)
{
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
#if DEVICE_SLEEP