mirror of https://github.com/ARMmbed/mbed-os.git
new API call to change db at runtime
parent
608ad338e8
commit
439d002f7d
|
@ -441,7 +441,7 @@ public:
|
|||
* support out-of-band exchanges of security data.
|
||||
* @param[in] passkey To specify a static passkey.
|
||||
* @param[in] signing Generate and distribute signing key during pairing
|
||||
* @param[in] dbPath Path to the folder used to store keys in the filesystem,
|
||||
* @param[in] dbPath Path to the file used to store keys in the filesystem,
|
||||
* if NULL keys will be only stored in memory
|
||||
*
|
||||
*
|
||||
|
@ -452,17 +452,31 @@ public:
|
|||
SecurityIOCapabilities_t iocaps = IO_CAPS_NONE,
|
||||
const Passkey_t passkey = NULL,
|
||||
bool signing = true,
|
||||
const char *dbPath = NULL) {
|
||||
const char *dbFilepath = NULL) {
|
||||
/* Avoid compiler warnings about unused variables. */
|
||||
(void)enableBonding;
|
||||
(void)requireMITM;
|
||||
(void)iocaps;
|
||||
(void)passkey;
|
||||
(void)dbPath;
|
||||
(void)dbFilepath;
|
||||
|
||||
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if security is supported. */
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the file used for the security datagse. If path is invalid or a NULL is passed
|
||||
* keys will only be stored in memory.
|
||||
*
|
||||
* @param[in] dbPath Path to the file used to store keys in the filesystem,
|
||||
* if NULL keys will be only stored in memory
|
||||
*
|
||||
* @return BLE_ERROR_NONE on success.
|
||||
*/
|
||||
virtual ble_error_t setDatabaseFile(const char *dbFilepath = NULL) {
|
||||
(void)dbFilepath;
|
||||
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if security is supported. */
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify all registered onShutdown callbacks that the SecurityManager is
|
||||
* about to be shutdown and clear all SecurityManager state of the
|
||||
|
|
|
@ -53,6 +53,8 @@ public:
|
|||
const char* db_path = NULL
|
||||
);
|
||||
|
||||
virtual ble_error_t setDatabaseFile(const char *db_path = NULL);
|
||||
|
||||
virtual ble_error_t reset();
|
||||
|
||||
virtual ble_error_t preserveBondingStateOnReset(
|
||||
|
|
|
@ -43,29 +43,16 @@ ble_error_t GenericSecurityManager::init(
|
|||
const char* db_path
|
||||
) {
|
||||
|
||||
ble_error_t err = _pal.initialize();
|
||||
if (err) {
|
||||
return err;
|
||||
ble_error_t result = _pal.initialize();
|
||||
if (result != BLE_ERROR_NONE) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (_db) {
|
||||
delete _db;
|
||||
result = setDatabaseFile(db_path);
|
||||
if (result != BLE_ERROR_NONE) {
|
||||
return result;
|
||||
}
|
||||
|
||||
FILE* db_file = FileSecurityDb::open_db_file(db_path);
|
||||
|
||||
if (db_file) {
|
||||
_db = new (std::nothrow) FileSecurityDb(db_file);
|
||||
} else {
|
||||
_db = new (std::nothrow) MemorySecurityDb();
|
||||
}
|
||||
|
||||
if (!_db) {
|
||||
return BLE_ERROR_NO_MEM;
|
||||
}
|
||||
|
||||
_db->restore();
|
||||
|
||||
_pal.set_io_capability((io_capability_t::type) iocaps);
|
||||
|
||||
if (passkey) {
|
||||
|
@ -115,6 +102,30 @@ ble_error_t GenericSecurityManager::init(
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t GenericSecurityManager::setDatabaseFile(
|
||||
const char *db_path
|
||||
) {
|
||||
if (_db) {
|
||||
delete _db;
|
||||
}
|
||||
|
||||
FILE* db_file = FileSecurityDb::open_db_file(db_path);
|
||||
|
||||
if (db_file) {
|
||||
_db = new (std::nothrow) FileSecurityDb(db_file);
|
||||
} else {
|
||||
_db = new (std::nothrow) MemorySecurityDb();
|
||||
}
|
||||
|
||||
if (!_db) {
|
||||
return BLE_ERROR_NO_MEM;
|
||||
}
|
||||
|
||||
_db->restore();
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t GenericSecurityManager::reset(void) {
|
||||
_pal.reset();
|
||||
SecurityManager::reset();
|
||||
|
|
Loading…
Reference in New Issue