Skip to content

Commit

Permalink
onboarding_tool:handle group OSCORE contexts
Browse files Browse the repository at this point in the history
Signed-off-by: Kishen Maloor <kishen.maloor@intel.com>
  • Loading branch information
kmaloor committed Oct 15, 2020
1 parent e407ccc commit f410c62
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 16 deletions.
6 changes: 3 additions & 3 deletions include/oc_obt.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ int oc_obt_device_hard_reset(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb,
void *data);

/**
* Provision pair-wise 128-bit pre-shared key (PSK) credentials to a Client
* Provision pairwise 128-bit pre-shared key (PSK) credentials to a Client
* and Server so they may establish a secure (D)TLS session.
*
* Example:
Expand All @@ -588,9 +588,9 @@ int oc_obt_device_hard_reset(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb,
* provision_credentials_cb(int status, void *data)
* {
* if (status >= 0) {
* printf("Successfully provisioned pair-wise credentials\n");
* printf("Successfully provisioned pairwise credentials\n");
* } else {
* printf("ERROR provisioning pair-wise credentials\n");
* printf("ERROR provisioning pairwise credentials\n");
* }
* }
*
Expand Down
134 changes: 124 additions & 10 deletions onboarding_tool/obtmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ display_menu(void)
PRINT("[11] Manufacturer Certificate based Ownership Transfer Method\n");
#endif /* OC_PKI */
PRINT("-----------------------------------------------\n");
PRINT("[12] Provision pair-wise credentials\n");
PRINT("[12] Provision pairwise credentials\n");
PRINT("[13] Provision ACE2\n");
PRINT("[14] Provision auth-crypt RW access to NCRs\n");
PRINT("[15] RETRIEVE /oic/sec/cred\n");
Expand All @@ -107,9 +107,11 @@ display_menu(void)
PRINT("[23] Provision role certificate\n");
#endif /* OC_PKI */
#ifdef OC_OSCORE
PRINT("[24] Provision pair-wise OSCORE contexts\n");
PRINT("[24] Provision pairwise OSCORE contexts\n");
PRINT("[25] Provision Client Group OSCORE context\n");
PRINT("[26] Provision Server Group OSCORE context\n");
#endif /* OC_OSCORE */
PRINT("[25] Set security domain info\n");
PRINT("[27] Set security domain info\n");
PRINT("-----------------------------------------------\n");
#ifdef OC_PKI
PRINT("[96] Install new manufacturer trust anchor\n");
Expand Down Expand Up @@ -1190,14 +1192,120 @@ provision_role_wildcard_ace(void)
#endif /* OC_PKI */

#ifdef OC_OSCORE
static void
provision_group_context_cb(oc_uuid_t *uuid, int status, void *data)
{
(void)data;
char di[37];
oc_uuid_to_str(uuid, di, 37);

if (status >= 0) {
PRINT("\nSuccessfully provisioned group OSCORE context to device %s\n", di);
} else {
PRINT("\nERROR provisioning group OSCORE context to device %s\n", di);
}
}

static void
provision_server_group_oscore_context(void)
{
if (oc_list_length(owned_devices) == 0) {
PRINT("\n\nPlease Re-Discover Owned devices\n");
return;
}

device_handle_t *devices[MAX_NUM_DEVICES];
device_handle_t *device = (device_handle_t *)oc_list_head(owned_devices);
int i = 0, dev;

PRINT("\nProvision server group OSCORE context\nMy Devices:\n");
while (device != NULL) {
devices[i] = device;
char di[OC_UUID_LEN];
oc_uuid_to_str(&device->uuid, di, OC_UUID_LEN);
PRINT("[%d]: %s - %s\n", i, di, device->device_name);
i++;
device = device->next;
}

if (i == 0) {
PRINT("\nNo devices to provision.. Please Re-Discover Owned devices.\n");
return;
}

PRINT("\n\nSelect device for provisioning: ");
SCANF("%d", &dev);
if (dev < 0 || dev >= i) {
PRINT("ERROR: Invalid selection\n");
return;
}

otb_mutex_lock(app_sync_lock);
int ret = oc_obt_provision_server_group_oscore_context(
&devices[dev]->uuid, provision_group_context_cb, NULL);
otb_mutex_unlock(app_sync_lock);
if (ret >= 0) {
PRINT("\nSuccessfully issued request to provision server group OSCORE "
"context\n");
} else {
PRINT("\nERROR issuing request to provision server group OSCORE context\n");
}
}

static void
provision_client_group_oscore_context(void)
{
if (oc_list_length(owned_devices) == 0) {
PRINT("\n\nPlease Re-Discover Owned devices\n");
return;
}

device_handle_t *devices[MAX_NUM_DEVICES];
device_handle_t *device = (device_handle_t *)oc_list_head(owned_devices);
int i = 0, dev;

PRINT("\nProvision client group OSCORE context\nMy Devices:\n");
while (device != NULL) {
devices[i] = device;
char di[OC_UUID_LEN];
oc_uuid_to_str(&device->uuid, di, OC_UUID_LEN);
PRINT("[%d]: %s - %s\n", i, di, device->device_name);
i++;
device = device->next;
}

if (i == 0) {
PRINT("\nNo devices to provision.. Please Re-Discover Owned devices.\n");
return;
}

PRINT("\n\nSelect device for provisioning: ");
SCANF("%d", &dev);
if (dev < 0 || dev >= i) {
PRINT("ERROR: Invalid selection\n");
return;
}

otb_mutex_lock(app_sync_lock);
int ret = oc_obt_provision_client_group_oscore_context(
&devices[dev]->uuid, provision_group_context_cb, NULL);
otb_mutex_unlock(app_sync_lock);
if (ret >= 0) {
PRINT("\nSuccessfully issued request to provision client group OSCORE "
"context\n");
} else {
PRINT("\nERROR issuing request to provision client group OSCORE context\n");
}
}

static void
provision_oscore_contexts_cb(int status, void *data)
{
(void)data;
if (status >= 0) {
PRINT("\nSuccessfully provisioned pair-wise OSCORE contexts\n");
PRINT("\nSuccessfully provisioned pairwise OSCORE contexts\n");
} else {
PRINT("\nERROR provisioning pair-wise OSCORE contexts\n");
PRINT("\nERROR provisioning pairwise OSCORE contexts\n");
}
}

Expand All @@ -1213,7 +1321,7 @@ provision_oscore_contexts(void)
device_handle_t *device = (device_handle_t *)oc_list_head(owned_devices);
int i = 0, c1, c2;

PRINT("\nMy Devices:\n");
PRINT("\nProvision pairwise OSCORE contexts\nMy Devices:\n");
while (device != NULL) {
devices[i] = device;
char di[OC_UUID_LEN];
Expand Down Expand Up @@ -1252,9 +1360,9 @@ provision_credentials_cb(int status, void *data)
{
(void)data;
if (status >= 0) {
PRINT("\nSuccessfully provisioned pair-wise credentials\n");
PRINT("\nSuccessfully provisioned pairwise credentials\n");
} else {
PRINT("\nERROR provisioning pair-wise credentials\n");
PRINT("\nERROR provisioning pairwise credentials\n");
}
}

Expand All @@ -1270,7 +1378,7 @@ provision_credentials(void)
device_handle_t *device = (device_handle_t *)oc_list_head(owned_devices);
int i = 0, c1, c2;

PRINT("\nMy Devices:\n");
PRINT("\nProvision pairwise (PSK) credentials\nMy Devices:\n");
while (device != NULL) {
devices[i] = device;
char di[OC_UUID_LEN];
Expand Down Expand Up @@ -1907,8 +2015,14 @@ main(void)
case 24:
provision_oscore_contexts();
break;
#endif /* OC_OSCORE */
case 25:
provision_client_group_oscore_context();
break;
case 26:
provision_server_group_oscore_context();
break;
#endif /* OC_OSCORE */
case 27:
set_sd_info();
break;
#ifdef OC_PKI
Expand Down
6 changes: 3 additions & 3 deletions security/oc_obt.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ oc_obt_device_hard_reset(oc_uuid_t *uuid, oc_obt_device_status_cb_t cb,
/* End of hard RESET sequence */

#ifdef OC_OSCORE
/* Provision pairwise credentials sequence */
/* Provision pairwise OSCORE contexts sequence */
static void
free_oscoreprov_state(oc_oscoreprov_ctx_t *p, int status)
{
Expand Down Expand Up @@ -1189,7 +1189,7 @@ oc_obt_provision_pairwise_oscore_contexts(oc_uuid_t *uuid1, oc_uuid_t *uuid2,

return 0;
}
/* End of provision pair-wise OSCORE contexts sequence */
/* End of provision pairwise OSCORE contexts sequence */
/* Provision Group OSCORE contexts */
static void
free_oscoregroupprov_state(oc_oscoregroupprov_ctx_t *request, int status)
Expand Down Expand Up @@ -1607,7 +1607,7 @@ oc_obt_provision_pairwise_credentials(oc_uuid_t *uuid1, oc_uuid_t *uuid2,

return 0;
}
/* End of provision pair-wise credentials sequence */
/* End of provision pairwise credentials sequence */

#ifdef OC_PKI
/* Construct list of role ids to encode into a role certificate */
Expand Down

0 comments on commit f410c62

Please sign in to comment.