Commit 7e64d8f4 authored by Kishen Maloor's avatar Kishen Maloor

Deprecate fake uuids; enforce immutable uuids

Change-Id: I074870783429b99843847883ad9cb04d0c1dab3b
Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parent 9ea7f470
......@@ -155,12 +155,9 @@ oc_core_encode_interfaces_mask(CborEncoder *parent,
#ifdef OC_SECURITY
void
oc_core_regen_unique_ids(size_t device)
oc_core_gen_unique_ids(size_t device)
{
oc_sec_doxm_t *doxm = oc_sec_get_doxm(device);
oc_device_info_t *d = &oc_device_info[device];
oc_gen_uuid(&doxm->deviceuuid);
memcpy(d->di.id, doxm->deviceuuid.id, 16);
oc_device_info_t *d = oc_core_get_device_info(device);
oc_gen_uuid(&d->piid);
oc_gen_uuid(&oc_platform_info.pi);
}
......
......@@ -232,6 +232,7 @@ oc_main_init(const oc_handler_t *handler)
#ifdef OC_SECURITY
size_t device;
for (device = 0; device < oc_core_get_num_devices(); device++) {
oc_sec_load_unique_ids(device);
oc_sec_load_pstat(device);
oc_sec_load_doxm(device);
oc_sec_load_cred(device);
......@@ -240,7 +241,6 @@ oc_main_init(const oc_handler_t *handler)
oc_sec_load_sp(device);
oc_sec_load_ecdsa_keypair(device);
#endif /* OC_PKI */
oc_sec_load_unique_ids(device);
}
#endif
......
......@@ -88,7 +88,7 @@ void oc_core_populate_resource(int core_resource, size_t device_index,
oc_request_callback_t delete_cb,
int num_resource_types, ...);
void oc_core_regen_unique_ids(size_t device);
void oc_core_gen_unique_ids(size_t device);
bool oc_filter_resource_by_rt(oc_resource_t *resource, oc_request_t *request);
......
......@@ -71,7 +71,10 @@ oc_sec_doxm_default(size_t device)
doxm[device].owned = false;
memset(doxm[device].devowneruuid.id, 0, 16);
memset(doxm[device].rowneruuid.id, 0, 16);
oc_core_regen_unique_ids(device);
/* Generate a new temporary device UUID */
oc_device_info_t *d = oc_core_get_device_info(device);
oc_gen_uuid(&doxm[device].deviceuuid);
memcpy(d->di.id, doxm[device].deviceuuid.id, 16);
oc_sec_dump_doxm(device);
}
......@@ -256,17 +259,6 @@ oc_sec_decode_doxm(oc_rep_t *rep, bool from_storage, size_t device)
memcmp(oc_string(rep->name), "devowneruuid", 12) == 0) {
oc_str_to_uuid(oc_string(rep->value.string),
&doxm[device].devowneruuid);
if (!from_storage) {
int i;
for (i = 0; i < 16; i++) {
if (doxm[device].devowneruuid.id[i] != 0) {
break;
}
}
if (i != 16) {
oc_core_regen_unique_ids(device);
}
}
} else if (len == 10 &&
memcmp(oc_string(rep->name), "rowneruuid", 10) == 0) {
oc_str_to_uuid(oc_string(rep->value.string), &doxm[device].rowneruuid);
......
......@@ -1902,7 +1902,6 @@ oc_obt_init(void)
oc_sec_dump_doxm(0);
oc_sec_dump_cred(0);
oc_sec_dump_acl(0);
oc_sec_dump_unique_ids(0);
#ifdef OC_PKI
uint8_t public_key[OC_KEYPAIR_PUBKEY_SIZE];
......
......@@ -43,7 +43,6 @@ static oc_sec_pstat_t *pstat;
#else /* OC_DYNAMIC_ALLOCATION */
static oc_sec_pstat_t pstat[OC_MAX_NUM_DEVICES];
#endif /* !OC_DYNAMIC_ALLOCATION */
static bool store_unique_ids = true;
void
oc_sec_pstat_free(void)
......@@ -166,7 +165,6 @@ oc_pstat_handle_state(oc_sec_pstat_t *ps, size_t device, bool from_storage,
#endif /* OC_CLOUD */
#endif /* OC_CLIENT */
#endif /* OC_SERVER */
store_unique_ids = true;
#ifdef OC_SERVER
#if defined(OC_COLLECTIONS) && defined(OC_COLLECTIONS_IF_CREATE)
oc_rt_factory_free_created_resources(device);
......@@ -429,14 +427,6 @@ oc_sec_encode_pstat(size_t device)
oc_rep_end_root_object();
}
static oc_event_callback_retval_t
dump_unique_ids(void *data)
{
size_t device = (size_t)data;
oc_sec_dump_unique_ids(device);
return OC_EVENT_DONE;
}
#ifdef OC_SOFTWARE_UPDATE
static void
oc_pstat_handle_target_mode(size_t device, oc_dpmtype_t *tm)
......@@ -558,11 +548,6 @@ oc_sec_decode_pstat(oc_rep_t *rep, bool from_storage, size_t device)
if (!from_storage && transition_state) {
bool transition_success =
oc_pstat_handle_state(&ps, device, from_storage, false);
if (transition_success && ps.s == OC_DOS_RFNOP && store_unique_ids) {
size_t d = (size_t)device;
oc_ri_add_timed_event_callback_ticks((void *)d, &dump_unique_ids, 0);
store_unique_ids = false;
}
return transition_success;
}
memcpy(&pstat[device], &ps, sizeof(oc_sec_pstat_t));
......
......@@ -522,6 +522,9 @@ oc_sec_load_unique_ids(size_t device)
}
}
oc_free_rep(p);
} else {
oc_core_gen_unique_ids(device);
oc_sec_dump_unique_ids(device);
}
#ifdef OC_DYNAMIC_ALLOCATION
free(buf);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment