static OicSecAcl_t *gAcl = NULL;
static OicSecCrl_t *gCrl = NULL;
-static char PROV_TOOL_DB_FILE[] = "oic_svr_db_pt.json";
+static char PROV_TOOL_DB_FILE[] = "oic_svr_db_pt.dat";
static const char* PRVN_DB_FILE_NAME = "oic_prvn_mng.db";
static int gOwnershipState = 0;
}
OICFree((acl)->resources);
- /* Clean Owners */
- OICFree((acl)->owners);
-
/* Clean ACL node itself */
OICFree((acl));
{
if (DASH != temp_id[i])
{
- if(j>UUID_LENGTH)
+ if(j >= UUID_LENGTH)
{
printf("Invalid input\n");
return -1;
//Set Resource.
printf("Num. of Resource : \n");
ret = scanf("%zu", &acl->resourcesLen);
+ if(-1 == ret)
+ {
+ printf("Error while input\n");
+ return -1;
+ }
printf("-URI of resource\n");
printf("ex) /a/light (Max_URI_Length: 64 Byte )\n");
acl->resources = (char **)OICCalloc(acl->resourcesLen, sizeof(char *));
if (NULL == acl->resources)
{
- OC_LOG(ERROR, TAG, "Error while memory allocation");
+ OIC_LOG(ERROR, TAG, "Error while memory allocation");
return -1;
}
for (size_t i = 0; i < acl->resourcesLen; i++)
if (NULL == acl->resources[i])
{
- OC_LOG(ERROR, TAG, "Error while memory allocation");
+ OIC_LOG(ERROR, TAG, "Error while memory allocation");
return -1;
}
}
}
while (0 != CalculateAclPermission(temp_pms, &(acl->permission)) );
// Set Rowner
- printf("Num. of Rowner : ");
- ret = scanf("%zu", &acl->ownersLen);
printf("-URN identifying the rowner\n");
printf("ex) lightDeviceUUID0 (16 Numbers except to '-')\n");
- acl->owners = (OicUuid_t *)OICCalloc(acl->ownersLen, sizeof(OicUuid_t));
- if (NULL == acl->owners)
+
+ printf("Rowner : ");
+ char *ptr_temp_id = NULL;
+ ret = scanf("%19ms", &ptr_temp_id);
+ if (1 == ret)
+ {
+ OICStrcpy(temp_id, sizeof(temp_id), ptr_temp_id);
+ OICFree(ptr_temp_id);
+ }
+ else
{
- OC_LOG(ERROR, TAG, "Error while memory allocation");
+ printf("Error while input\n");
return -1;
}
- for (size_t i = 0; i < acl->ownersLen; i++)
+ j = 0;
+ for (int k = 0; temp_id[k] != '\0'; k++)
{
- printf("[%zu]Rowner : ", i + 1);
- char *ptr_temp_id = NULL;
- ret = scanf("%19ms", &ptr_temp_id);
- if (1 == ret)
- {
- OICStrcpy(temp_id, sizeof(temp_id), ptr_temp_id);
- OICFree(ptr_temp_id);
- }
- else
- {
- printf("Error while input\n");
- return -1;
- }
- j = 0;
- for (int k = 0; temp_id[k] != '\0'; k++)
+ if (DASH != temp_id[k])
{
- if (DASH != temp_id[k])
- {
- acl->owners[i].id[j++] = temp_id[k];
- }
+ acl->rownerID.id[j++] = temp_id[k];
}
}
return 0;
// const uint8_t revocationDatesContent[MAX_Revoked_NUMBER][DATE_LENGTH];
uint32_t nuberOfRevoked = 0;
printf("Enter number of Revoked certificates(1..%d)\n", MAX_Revoked_NUMBER);
- scanf("%u", &nuberOfRevoked);
+ int ret = 0;
+ ret = scanf("%u", &nuberOfRevoked);
+ if(-1 == ret)
+ {
+ printf("Error while input\n");
+ return PKI_UNKNOWN_ERROR;
+ }
+
+ if((uint32_t)MAX_Revoked_NUMBER < nuberOfRevoked)
+ {
+ OIC_LOG(ERROR, TAG, "Wrong revoked certificate number");
+ return PKI_UNKNOWN_ERROR;
+ }
for (size_t i = 0; i < nuberOfRevoked; ++i)
{
printf("Revoked certificate %d:", i);
printf("Serial number (E. g.: 100):");
- scanf("%u", &revokedNumbers[i]);
+ ret = scanf("%u", &revokedNumbers[i]);
+ if(-1 == ret)
+ {
+ printf("Error while input\n");
+ return PKI_UNKNOWN_ERROR;
+ }
+
revocationDates[i] = (const uint8_t*)"130101000005Z";
}
crl.len = CRL_MIN_SIZE + nuberOfRevoked * (sizeof(CertificateRevocationInfo_t) + 4)/* + 1000*/;
crl.data = (uint8_t *)OICCalloc(1, crl.len);
+ if (NULL == crl.data)
+ {
+ OIC_LOG(ERROR, TAG, "Error while memory allocation");
+ return PKI_MEMORY_ALLOC_FAILED;
+ }
+
CHECK_CALL(CKMIssueCRL, uint8ThisUpdateTime, nuberOfRevoked, revokedNumbers,
revocationDates, &crl);
PRINT_BYTE_ARRAY("CRL:\n",crl);
int main()
{
OCStackResult res = OC_STACK_OK;
+ OCProvisionDev_t* pDeviceList = NULL;
+ OCProvisionDev_t *pOwnedList = NULL;
// Initialize Persistent Storage for SVR database
OCPersistentStorage ps = { .open = client_fopen,
if (OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
{
- OC_LOG(ERROR, TAG, "OCStack init error");
+ OIC_LOG(ERROR, TAG, "OCStack init error");
goto error;
}
if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
{
- OC_LOG(ERROR, TAG, "OC_PM init error");
+ OIC_LOG(ERROR, TAG, "OC_PM init error");
goto error;
}
- OCProvisionDev_t* pDeviceList = NULL;
res = OCDiscoverUnownedDevices(PREDEFINED_TIMEOUT, &pDeviceList);
if(OC_STACK_OK != res)
{
- OC_LOG_V(ERROR, TAG, "Failed to PMDeviceDiscovery : %d", res);
+ OIC_LOG_V(ERROR, TAG, "Failed to PMDeviceDiscovery : %d", res);
goto error;
}
res = OCDoOwnershipTransfer((void*)myContext, pDeviceList, OwnershipTransferCB);
if(OC_STACK_OK == res)
{
- OC_LOG(INFO, TAG, "Request for ownership transfer is sent successfully.");
+ OIC_LOG(INFO, TAG, "Request for ownership transfer is sent successfully.");
}
else
{
- OC_LOG_V(ERROR, TAG, "Failed to OCDoOwnershipTransfer : %d", res);
+ OIC_LOG_V(ERROR, TAG, "Failed to OCDoOwnershipTransfer : %d", res);
}
gOwnershipState = 0;
{
if (OCProcess() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack process error");
+ OIC_LOG(ERROR, TAG, "OCStack process error");
goto error;
}
sleep(1);
// Credential & ACL provisioning between two devices.
- OCProvisionDev_t *pOwnedList = NULL;
OCProvisionDev_t *pOwnedDevices [MAX_OWNED_DEVICE] = {0,};
int nOwnedDevice = 0;
}
else
{
- OC_LOG(ERROR, TAG, "Error while Owned Device Discovery");
+ OIC_LOG(ERROR, TAG, "Error while Owned Device Discovery");
}
int Device1 = 0;
int Device2 = 0;
+ int ret = 0;
printf("Select 2 devices for Credential & ACL provisioning\n");
printf("Device 1: ");
- scanf("%d", &Device1);
+ ret = scanf("%d", &Device1);
+ if(-1 == ret)
+ {
+ printf("Error while input\n");
+ goto error;
+ }
+
printf("Device 2: ");
- scanf("%d", &Device2);
+ ret = scanf("%d", &Device2);
+ if(-1 == ret)
+ {
+ printf("Error while input\n");
+ goto error;
+ }
+ if( 0 > Device1 || 0 > Device2 || Device1 > nOwnedDevice || Device2 > nOwnedDevice)
+ {
+ OIC_LOG(ERROR, TAG, "Wrong devices number");
+ goto error;
+ }
gAcl = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
if (NULL == gAcl)
{
- OC_LOG(ERROR, TAG, "Error while memory allocation");
+ OIC_LOG(ERROR, TAG, "Error while memory allocation");
goto error;
}
if (PKI_SUCCESS != InitCA())
{
- OC_LOG(ERROR, TAG, "CA init error");
+ OIC_LOG(ERROR, TAG, "CA init error");
goto error;
}
res = OCProvisionCredentials(ctx, SIGNED_ASYMMETRIC_KEY, 0, pOwnedDevices[Device1],
NULL, ProvisionCertCB);
- if (OC_STACK_OK != res) OC_LOG_V(ERROR, TAG, "Failed to provision Device 1 : %d", res);
+ if (OC_STACK_OK != res) OIC_LOG_V(ERROR, TAG, "Failed to provision Device 1 : %d", res);
gOwnershipState = 0;
while ( gOwnershipState == 0 )
{
if (OCProcess() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack process error");
+ OIC_LOG(ERROR, TAG, "OCStack process error");
goto error;
}
sleep(1);
NULL, ProvisionCertCB);
if (OC_STACK_OK != res)
{
- OC_LOG_V(ERROR, TAG, "Failed to provision Device 2 : %d", res);
+ OIC_LOG_V(ERROR, TAG, "Failed to provision Device 2 : %d", res);
}
gOwnershipState = 0;
{
if (OCProcess() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack process error");
+ OIC_LOG(ERROR, TAG, "OCStack process error");
goto error;
}
sleep(1);
}
else
{
- OC_LOG(ERROR, TAG, "InputACL error");
+ OIC_LOG(ERROR, TAG, "InputACL error");
goto error;
}
res = OCProvisionACL(ctx, pOwnedDevices[Device2], gAcl, &ProvisionAclCB);
if (OC_STACK_OK != res)
{
- OC_LOG_V(ERROR, TAG, "Failed to ACL provision Device 2 : %d", res);
+ OIC_LOG_V(ERROR, TAG, "Failed to ACL provision Device 2 : %d", res);
}
gOwnershipState = 0;
{
if (OCProcess() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack process error");
+ OIC_LOG(ERROR, TAG, "OCStack process error");
goto error;
}
sleep(1);
}
gCrl = (OicSecCrl_t *)OICMalloc(sizeof(OicSecCrl_t));
+
+ if (NULL == gCrl)
+ {
+ OIC_LOG(ERROR, TAG, "Error while memory allocation");
+ goto error;
+ }
+
if (PKI_SUCCESS != InputCRL(gCrl))
{
- OC_LOG(ERROR, TAG, "CA init error");
+ OIC_LOG(ERROR, TAG, "CA init error");
goto error;
}
PRINT_BYTE_ARRAY("gCrl = \n", gCrl->CrlData);
res = OCProvisionCRL(ctx, pOwnedDevices[Device2], gCrl, &ProvisionCrlCB);
- if (OC_STACK_OK != res) OC_LOG_V(ERROR, TAG, "Failed to CRL provision Device 2 : %d", res);
+ if (OC_STACK_OK != res) OIC_LOG_V(ERROR, TAG, "Failed to CRL provision Device 2 : %d", res);
gOwnershipState = 0;
while (gOwnershipState == 0)
{
if (OCProcess() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack process error");
+ OIC_LOG(ERROR, TAG, "OCStack process error");
goto error;
}
sleep(1);
if (OCStop() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack process error");
+ OIC_LOG(ERROR, TAG, "OCStack process error");
goto error;
}