Commit 92268a18 authored by Sangjoon Je's avatar Sangjoon Je Committed by Randeep

[IOT-2494] SVR DB Editor : Add doxm edit features

Add doxm add, remove, modify
Apply InputUuid allow empty input or zero input from user

New Feature: https://jira.iotivity.org/browse/IOT-2494
Change-Id: I9c5dc06bdbc29c5ba7e0a8e0a6e898e162e7959d
Signed-off-by: default avatarSangjoon Je <sangjoon.je@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21831Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarJongmin Choi <jminl.choi@samsung.com>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
(cherry picked from commit 04875c73)
parent d8fe0189
......@@ -177,9 +177,31 @@ static int MainOperation(const char *svrpath)
}
break;
case SVR_EDIT_DOXM:
PRINT_INFO("NOT SUPPORTED YET");
//PrintEditMenu("Doxm Resource", false, false, true);
//T.B.D
for (;;)
{
PrintEditMenu("Doxm Resource", true, true, true, true);
editMenu = (SubOperationType_t)InputNumber("Select the menu : ");
if (0 < editMenu && editMenu < SVR_EDIT_IDX_SIZE)
{
if (!g_allowedEditMenu[editMenu])
{
PRINT_ERR("Disabled menu");
continue;
}
}
else if (BACK == editMenu)
{
PRINT_INFO("Back to the previous menu.");
break;
}
else
{
PRINT_ERR("Invalid menu");
continue;
}
HandleDoxmOperation(editMenu);
RefreshDoxm();
}
break;
case SVR_EDIT_PSTAT:
for (;;)
......@@ -298,7 +320,7 @@ static void PrintMainMenu(void)
PRINT_DATA("\t%2d. Print All Security Resource.\n", SVR_PRINT_ALL);
PRINT_DATA("\t%2d. Edit Credential Resource.\n", SVR_EDIT_CRED);
PRINT_DATA("\t%2d. Edit ACL Resource.\n", SVR_EDIT_ACL);
PRINT_PROG("\t%2d. Edit Doxm Resource. (T.B.D)\n", SVR_EDIT_DOXM);
PRINT_DATA("\t%2d. Edit Doxm Resource.\n", SVR_EDIT_DOXM);
PRINT_DATA("\t%2d. Edit Pstat Resource.\n", SVR_EDIT_PSTAT);
PRINT_DATA("\t%2d. Exit.\n", EXIT);
}
......@@ -17,6 +17,8 @@
* limitations under the License.
*
* *****************************************************************/
#include <stdio.h>
#include <string.h>
#include "utlist.h"
......@@ -29,6 +31,9 @@
#include "svrdbeditorcommon.h"
#define STR_UUID_LENGTH (UUID_LENGTH * 2 + 4 + 1) // length + dash length + '\0'
#define STR_UUID_ZERO "0"
void PrintUuid(const OicUuid_t *uuid)
{
char *strUuid = NULL;
......@@ -120,30 +125,39 @@ char *InputString(const char *infoText)
int InputUuid(OicUuid_t *uuid)
{
char strSubject[UUID_LENGTH * 2 + 4 + 1] = {0};
OCStackResult ocResult = OC_STACK_ERROR;
char strUuid[STR_UUID_LENGTH] = {0};
size_t strLen = 0;
if (NULL == uuid)
{
PRINT_ERR("Failed InputUuid");
PRINT_ERR("Invalid parameter");
return -1;
}
for (int ret = 0; 1 != ret; )
if (NULL == fgets(strUuid, STR_UUID_LENGTH, stdin))
{
ret = scanf("%37s", strSubject);
for ( ; 0x20 <= getchar(); ); // for removing overflow garbages
// '0x20<=code' is character region
PRINT_ERR("Failed fgets");
return -1;
}
strLen = strlen(strUuid);
if ('\n' == strUuid[strLen - 1])
{
strUuid[strLen - 1] = '\0';
}
if (0 == strncmp(strSubject, (char *)WILDCARD_SUBJECT_ID.id, sizeof(OicUuid_t)))
if (0 == strncmp(strUuid, STR_UUID_ZERO, sizeof(STR_UUID_ZERO)))
{
memset(uuid->id, 0x00, sizeof(uuid->id));
}
else if (0 == strncmp(strUuid, (char *)WILDCARD_SUBJECT_ID.id, sizeof(WILDCARD_SUBJECT_ID.id)))
{
memset(uuid->id, 0x00, sizeof(uuid->id));
memcpy(uuid->id, WILDCARD_SUBJECT_ID.id, WILDCARD_SUBJECT_ID_LEN);
}
else
{
ocResult = ConvertStrToUuid(strSubject, uuid);
ocResult = ConvertStrToUuid(strUuid, uuid);
if (OC_STACK_OK != ocResult)
{
PRINT_ERR("Failed ConvertStrToUuid");
......
......@@ -20,17 +20,65 @@
#include "octypes.h"
#include "srmresourcestrings.h"
#include "octypes.h"
#include "oic_malloc.h"
#include "psinterface.h"
#include "doxmresource.h"
#include "doxmresource.h"
#include "svrdbeditordoxm.h"
#ifdef MULTIPLE_OWNER
#define DOXM_TYPE_CNT (6)
#else
#define DOXM_TYPE_CNT (5)
#endif //MULTIPLE_OWNER
static const char *DOXM_TYPE_STRING[DOXM_TYPE_CNT] =
{
"OCFJustWorks", "OCFSharedPin", "OCFMfgCert",
#ifdef MULTIPLE_OWNER
"PRECONFIG_PIN",
#endif //MULTIPLE_OWNER
"MV_JUST_WORKS", "CON_MFG_CERT"
};
static const unsigned int DOXM_TYPE_NUMBER[DOXM_TYPE_CNT] =
{
OIC_JUST_WORKS, OIC_RANDOM_DEVICE_PIN, OIC_MANUFACTURER_CERTIFICATE,
#ifdef MULTIPLE_OWNER
OIC_PRECONFIG_PIN,
#endif //MULTIPLE_OWNER
OIC_MV_JUST_WORKS, OIC_CON_MFG_CERT
};
#define DOXM_SCT_CNT (6)
static const char *DOXM_SCT_STRING[DOXM_SCT_CNT] =
{
"SYMMETRIC_PAIR_WISE_KEY", "SYMMETRIC_GROUP_KEY", "ASYMMETRIC_KEY",
"SIGNED_ASYMMETRIC_KEY", "PIN_PASSWORD", "ASYMMETRIC_ENCRYPTION_KEY"
};
static const unsigned int DOXM_SCT_NUMBER[DOXM_SCT_CNT] =
{
SYMMETRIC_PAIR_WISE_KEY, SYMMETRIC_GROUP_KEY, ASYMMETRIC_KEY, SIGNED_ASYMMETRIC_KEY,
PIN_PASSWORD, ASYMMETRIC_ENCRYPTION_KEY
};
typedef enum DoxmModifyType
{
DOXM_EDIT_OXM = 1,
DOXM_EDIT_OXMSEL,
DOXM_EDIT_SCT,
DOXM_EDIT_OWNED,
DOXM_EDIT_DEVICEID,
DOXM_EDIT_OWNER,
DOXM_EDIT_ROWNERID = 7,
DOXM_SAVE = 98,
DOXM_CANCEL = 99
} DoxmModifyType;
static OicSecDoxm_t *g_doxm = NULL;
void DeInitDoxm()
void DeInitDoxm(void)
{
DeleteDoxmBinData(g_doxm);
g_doxm = NULL;
......@@ -46,12 +94,43 @@ int GetDoxmDevID(OicUuid_t *deviceuuid)
return -1;
}
void RefreshDoxm()
#ifdef MULTIPLE_OWNER
static void PrintMom(const OicSecMom_t *mom)
{
if (mom)
{
PRINT_DATA("%d (", mom->mode);
switch (mom->mode)
{
case OIC_MULTIPLE_OWNER_DISABLE:
PRINT_DATA(" OIC_MULTIPLE_OWNER_DISABLE ");
break;
case OIC_MULTIPLE_OWNER_ENABLE:
PRINT_DATA(" OIC_MULTIPLE_OWNER_ENABLE ");
break;
case OIC_MULTIPLE_OWNER_TIMELY_ENABLE:
PRINT_DATA(" OIC_MULTIPLE_OWNER_TIMELY_ENABLE ");
break;
default:
break;
}
PRINT_DATA(") \n");
}
else
{
PRINT_DATA("NULL\n");
}
}
#endif
void RefreshDoxm(void)
{
OCStackResult ocResult = OC_STACK_ERROR;
OicSecDoxm_t *tmpDoxm = NULL;
uint8_t *secPayload = NULL;
size_t payloadSize = 0;
OCStackResult ocResult = OC_STACK_ERROR;
ocResult = GetSecureVirtualDatabaseFromPS(OIC_JSON_DOXM_NAME, &secPayload, &payloadSize);
if (OC_STACK_OK != ocResult)
......@@ -75,80 +154,483 @@ void RefreshDoxm()
g_doxm = tmpDoxm;
}
static void UpdateDoxm(void)
{
OCStackResult doxmResult = OC_STACK_ERROR;
uint8_t *doxmPayload = NULL;
size_t doxmPayloadSize = 0;
doxmResult = DoxmToCBORPayload(g_doxm, &doxmPayload, &doxmPayloadSize);
if (OC_STACK_OK != doxmResult)
{
PRINT_ERR("doxmToCBORPayload error : %d", doxmResult);
return;
}
doxmResult = UpdateSecureResourceInPS(OIC_JSON_DOXM_NAME, doxmPayload, doxmPayloadSize);
if (OC_STACK_OK != doxmResult)
{
PRINT_ERR("UpdateSecureResourceInPS error : %d", doxmResult);
OICFree(doxmPayload);
return;
}
OICFree(doxmPayload);
}
void PrintDoxm(void)
{
PRINT_INFO("\n\n********************* [%-20s] *********************",
"DOXM Resource");
if (g_doxm)
{
PRINT_PROG("%15s : ", OIC_JSON_OWNED_NAME);
(g_doxm->owned ? PrintString("True (Owned)") : PrintString("False (Unowned)"));
PRINT_PROG("%15s : ", OIC_JSON_OXMS_NAME);
PrintIntArray((int *)g_doxm->oxm, g_doxm->oxmLen);
PRINT_PROG("%15s : ", OIC_JSON_OXM_SEL_NAME);
PrintInt((int)g_doxm->oxmSel);
PRINT_PROG("%15s : ", OIC_JSON_SUPPORTED_CRED_TYPE_NAME);
PrintInt((int)g_doxm->sct);
#ifdef MULTIPLE_OWNER
void PrintMom(const OicSecMom_t *mom)
PRINT_PROG("%15s : ", OIC_JSON_MOM_NAME);
PrintMom(g_doxm->mom);
// TODO: Print Subowner List
#endif //MULTIPLE_OWNER
PRINT_PROG("%15s : ", OIC_JSON_DEVICE_ID_NAME);
PrintUuid(&g_doxm->deviceID);
PRINT_PROG("%15s : ", OIC_JSON_DEVOWNERID_NAME);
PrintUuid(&g_doxm->owner);
PRINT_PROG("%15s : ", OIC_JSON_ROWNERID_NAME);
PrintUuid(&g_doxm->rownerID);
}
else
{
PRINT_PROG("doxm is empty.\n");
return;
}
PRINT_INFO("********************* [%-20s] *********************",
"DOXM Resource");
}
static int InputOxm(OicSecOxm_t **oxm, size_t *oxmLen)
{
if (mom)
bool oxmSelected[DOXM_TYPE_CNT] = {false};
unsigned int sel = 0;
unsigned int *tmpOxm = NULL;
size_t tmpLen = 0;
size_t oxmIdx = 0;
PRINT_PROG("\nInput value identifying the owner transfer method\n");
for (;;)
{
PRINT_DATA("%d (", mom->mode);
for (size_t i = 0; i < DOXM_TYPE_CNT; i++)
{
if (oxmSelected[i])
{
PRINT_DATA("\t%zu. %s\n", i, DOXM_TYPE_STRING[i]);
}
else
{
PRINT_NORMAL("\t%zu. %s\n", i, DOXM_TYPE_STRING[i]);
}
}
PRINT_NORMAL("\t%d. Save\n", DOXM_SAVE);
PRINT_NORMAL("\t%d. Cancel\n", DOXM_CANCEL);
sel = InputNumber("Select number : ");
if (sel < DOXM_TYPE_CNT)
{
if (oxmSelected[sel])
{
tmpLen--;
oxmSelected[sel] = false;
}
else
{
tmpLen++;
oxmSelected[sel] = true;
}
}
else if (DOXM_SAVE == sel)
{
break;
}
else if (DOXM_CANCEL == sel)
{
return -1;
}
else
{
PRINT_WARN("Wrong number.");
}
}
tmpOxm = (unsigned int *)OICCalloc(tmpLen, sizeof(unsigned int));
if (NULL == tmpOxm)
{
PRINT_ERR("Failed to allocate memory");
return -1;
}
for (size_t i = 0; i < DOXM_TYPE_CNT; i++)
{
if (oxmSelected[i])
{
tmpOxm[oxmIdx++] = DOXM_TYPE_NUMBER[i];
}
}
if (*oxm)
{
OICFree(*oxm);
}
*oxm = tmpOxm;
*oxmLen = tmpLen;
return 0;
}
switch (mom->mode)
static int InputOxmSel(OicSecOxm_t *oxms, size_t oxmLen, OicSecOxm_t *oxmSel)
{
bool oxmSelected[DOXM_TYPE_CNT] = {false};
unsigned int sel = 0;
for (size_t i = 0; i < oxmLen; i++)
{
for (size_t j = 0; j < DOXM_TYPE_CNT; j++)
{
case OIC_MULTIPLE_OWNER_DISABLE:
PRINT_DATA(" OIC_MULTIPLE_OWNER_DISABLE ");
break;
case OIC_MULTIPLE_OWNER_ENABLE:
PRINT_DATA(" OIC_MULTIPLE_OWNER_ENABLE ");
break;
case OIC_MULTIPLE_OWNER_TIMELY_ENABLE:
PRINT_DATA(" OIC_MULTIPLE_OWNER_TIMELY_ENABLE ");
break;
default:
if (DOXM_TYPE_NUMBER[j] == oxms[i])
{
oxmSelected[j] = true;
break;
}
}
}
PRINT_DATA(") \n");
PRINT_PROG("\nInput selected owner transfer method\n");
PRINT_INFO("You can select CYAN COLOR methods in oxms\n");
for (;;)
{
for (size_t i = 0; i < DOXM_TYPE_CNT; i++)
{
if (oxmSelected[i])
{
PRINT_DATA("\t%zu. %s\n", i, DOXM_TYPE_STRING[i]);
}
else
{
PRINT_NORMAL("\t%zu. %s\n", i, DOXM_TYPE_STRING[i]);
}
}
PRINT_NORMAL("\t%d. Cancel\n", DOXM_CANCEL);
sel = InputNumber("Select number : ");
if (sel < DOXM_TYPE_CNT)
{
if (oxmSelected[sel])
{
*oxmSel = DOXM_TYPE_NUMBER[sel];
break;
}
else
{
PRINT_INFO("You can select CYAN COLOR methods in oxms\n");
}
}
else if (DOXM_CANCEL == sel)
{
return -1;
}
else
{
PRINT_WARN("Wrong number.");
}
}
else
return 0;
}
static int InputSct(OicSecCredType_t *sct)
{
unsigned int sel = 0;
OicSecCredType_t tmpSct = 0;
for (;;)
{
PRINT_DATA("NULL\n");
for (size_t i = 0; i < DOXM_SCT_CNT; i++)
{
(tmpSct & DOXM_SCT_NUMBER[i]) ? PRINT_DATA("\t%zu. %s\n", i, DOXM_SCT_STRING[i]) :
PRINT_NORMAL("\t%zu. %s\n", i, DOXM_SCT_STRING[i]);
}
PRINT_NORMAL("\t%d. Save\n", DOXM_SAVE);
PRINT_NORMAL("\t%d. Cancel\n", DOXM_CANCEL);
sel = InputNumber("Select number: ");
if (sel < DOXM_SCT_CNT)
{
tmpSct ^= DOXM_SCT_NUMBER[sel];
}
else if (DOXM_SAVE == sel)
{
break;
}
else if (DOXM_CANCEL == sel)
{
return -1;
}
else
{
PRINT_WARN("Wrong number.");
}
}
*sct = tmpSct;
return 0;
}
#endif
static bool InputOwned(void)
{
char ans = 0;
for (;;)
{
PRINT_NORMAL("\tEnter Owned (y/n): ");
for (int ret = 0; 1 != ret; )
{
ret = scanf("%c", &ans);
for ( ; 0x20 <= getchar(); ); // for removing overflow garbages
// '0x20<=code' is character region
}
if ('y' == ans || 'Y' == ans || 'n' == ans || 'N' == ans)
{
ans &= ~0x20; // for masking lower case, 'y/n'
break;
}
PRINT_NORMAL("\tEntered Wrong Answer. Please Enter 'y/n' Again\n");
}
return 'Y' == ans;
}
void PrintDoxm()
static OicSecDoxm_t *InputDoxmData(void)
{
OicSecDoxm_t *doxm = NULL;
int ret = 0;
PRINT_INFO("\n\n********************* [%-20s] *********************",
"DOXM Resource");
doxm = (OicSecDoxm_t *)OICCalloc(1, sizeof(OicSecDoxm_t));
if (NULL == doxm)
{
PRINT_ERR("Failed to allocate memory");
return NULL;
}
PRINT_PROG("%15s : ", OIC_JSON_OWNED_NAME);
(g_doxm->owned ? PrintString("True (Owned)") : PrintString("False (Unowned)"));
PRINT_PROG("\n\nPlease input the each entity of new doxm.\n");
PRINT_PROG("%15s : ", OIC_JSON_OXMS_NAME);
PrintIntArray((int *)g_doxm->oxm, g_doxm->oxmLen);
ret = InputOxm(&(doxm->oxm), &(doxm->oxmLen));
if (0 != ret)
{
PRINT_ERR("Failed InputOxm\n");
DeleteDoxmBinData(doxm);
return NULL;
}
ret = InputOxmSel(doxm->oxm, doxm->oxmLen, &(doxm->oxmSel));
if (0 != ret)
{
PRINT_ERR("Failed InputOxmSel\n");
DeleteDoxmBinData(doxm);
return NULL;
}
PRINT_PROG("%15s : ", OIC_JSON_OXM_SEL_NAME);
PrintInt((int)g_doxm->oxmSel);
ret = InputSct(&(doxm->sct));
if (0 != ret)
{
PRINT_ERR("Failed InputSct\n");
DeleteDoxmBinData(doxm);
return NULL;
}
PRINT_PROG("%15s : ", OIC_JSON_SUPPORTED_CRED_TYPE_NAME);
PrintInt((int)g_doxm->sct);
doxm->owned = InputOwned();
#ifdef MULTIPLE_OWNER
PRINT_PROG("%15s : ", OIC_JSON_MOM_NAME);
PrintMom(g_doxm->mom);
PRINT_PROG(
"\tInput the device UUID (e.g. 61646D69-6E44-6576-6963-655575696430) : ");
ret = InputUuid(&(doxm->deviceID));
if (0 != ret)
{
PRINT_ERR("InputUuid error");
DeleteDoxmBinData(doxm);
return NULL;
}
// TODO: Print Subowner List
#endif //MULTIPLE_OWNER
PRINT_PROG(
"\tInput the owner UUID (e.g. 61646D69-6E44-6576-6963-655575696430) : ");
ret = InputUuid(&(doxm->owner));
if (0 != ret)
{
PRINT_ERR("InputUuid error");
DeleteDoxmBinData(doxm);
return NULL;
}
PRINT_PROG("%15s : ", OIC_JSON_DEVICE_ID_NAME);
PrintUuid(&g_doxm->deviceID);
PRINT_PROG(
"\tInput the ROWNER UUID (e.g. 61646D69-6E44-6576-6963-655575696430) : ");
ret = InputUuid(&(doxm->rownerID));
if (0 != ret)
{
PRINT_ERR("InputUuid error");
DeleteDoxmBinData(doxm);
return NULL;
}
PRINT_PROG("%15s : ", OIC_JSON_DEVOWNERID_NAME);
PrintUuid(&g_doxm->owner);
return doxm;
}
PRINT_PROG("%15s : ", OIC_JSON_ROWNERID_NAME);
PrintUuid(&g_doxm->rownerID);
PRINT_INFO("********************* [%-20s] *********************",
"DOXM Resource");
static int ModifyDoxm(void)
{
int ret = 0;
int modifyMenu = 0;
if (NULL == g_doxm)
{
PRINT_ERR("Doxm is NULL");
return -1;
}
PRINT_PROG("\n\nPlease input the attribute you want to modify\n");
PRINT_DATA("\t%2d. Edit oxms\n", DOXM_EDIT_OXM);
PRINT_DATA("\t%2d. Edit oxmSel\n", DOXM_EDIT_OXMSEL);
PRINT_DATA("\t%2d. Edit sct\n", DOXM_EDIT_SCT);
PRINT_DATA("\t%2d. Edit owned\n", DOXM_EDIT_OWNED);
PRINT_DATA("\t%2d. Edit deviceID\n", DOXM_EDIT_DEVICEID);
PRINT_DATA("\t%2d. Edit owner\n", DOXM_EDIT_OWNER);