{
OIC_JUST_WORKS = 0x0,
OIC_RANDOM_DEVICE_PIN = 0x1,
- OIC_MANUFACTURER_CERTIFICATE = 0x2,
+ OIC_MANUFACTURER_CERTIFICATE = 0x2,
+ OIC_DECENTRALIZED_PUBLIC_KEY = 0x3,
+ OIC_OXM_COUNT,
#ifdef _ENABLE_MULTIPLE_OWNER_
- OIC_PRECONFIG_PIN = 0x3,
+ OIC_PRECONFIG_PIN = 0xFF00,
#endif //_ENABLE_MULTIPLE_OWNER_
- OIC_OXM_COUNT
}OicSecOxm_t;
typedef enum
#define OXM_STRING_MAX_LENGTH 32\r
#define WRONG_PIN_MAX_ATTEMP 5\r
\r
-/**\r
- * Context for ownership transfer(OT)\r
- */\r
-typedef struct OTMContext{\r
- void* userCtx; /**< Context for user.*/\r
- OCProvisionDev_t* selectedDeviceInfo; /**< Selected device info for OT. */\r
- OicUuid_t subIdForPinOxm; /**< Subject Id which uses PIN based OTM. */\r
- OCProvisionResultCB ctxResultCallback; /**< Function pointer to store result callback. */\r
- OCProvisionResult_t* ctxResultArray; /**< Result array having result of all device. */\r
- size_t ctxResultArraySize; /**< No of elements in result array. */\r
- bool ctxHasError; /**< Does OT process have any error. */\r
- int attemptCnt;\r
-}OTMContext_t;\r
+typedef struct OTMCallbackData OTMCallbackData_t;\r
+typedef struct OTMContext OTMContext_t;\r
\r
/**\r
* Do ownership transfer for the unowned devices.\r
/**\r
* Required callback for performing ownership transfer\r
*/\r
-typedef struct OTMCallbackData\r
+struct OTMCallbackData\r
{\r
OTMLoadSecret loadSecretCB;\r
OTMCreateSecureSession createSecureSessionCB;\r
OTMCreatePayloadCallback createSelectOxmPayloadCB;\r
OTMCreatePayloadCallback createOwnerTransferPayloadCB;\r
-} OTMCallbackData_t;\r
+};\r
+\r
+/**\r
+ * Context for ownership transfer(OT)\r
+ */\r
+struct OTMContext{\r
+ void* userCtx; /**< Context for user.*/\r
+ OCProvisionDev_t* selectedDeviceInfo; /**< Selected device info for OT. */\r
+ OicUuid_t subIdForPinOxm; /**< Subject Id which uses PIN based OTM. */\r
+ OCProvisionResultCB ctxResultCallback; /**< Function pointer to store result callback. */\r
+ OCProvisionResult_t* ctxResultArray; /**< Result array having result of all device. */\r
+ size_t ctxResultArraySize; /**< No of elements in result array. */\r
+ bool ctxHasError; /**< Does OT process have any error. */\r
+ OTMCallbackData_t otmCallback; /**< OTM callbacks to perform the OT/MOT. **/\r
+ int attemptCnt;\r
+};\r
\r
+// TODO: Remove this OTMSetOwnershipTransferCallbackData, Please see the jira ticket IOT-1484\r
/**\r
* Set the callbacks for ownership transfer\r
*\r
*/\r
OCStackResult OTMSetOwnershipTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t* callbackData);\r
\r
+/**\r
+ * API to assign the OTMCallback for each OxM.\r
+ *\r
+ * @param[out] callbacks Instance of OTMCallback_t\r
+ * @param[in] oxm Ownership transfer method\r
+ * @return OC_STACK_OK on success\r
+ */\r
+OCStackResult OTMSetOTCallback(OicSecOxm_t oxm, OTMCallbackData_t* callbacks);\r
+\r
#ifdef __cplusplus\r
}\r
#endif\r
printf(" Entered Wrong Number. Please Enter Again\n");
}
+ const int preconfOxm = 4;
int oxm = 0;
for( ; ; )
{
- printf(" 0. (Not Supported)\n");
- printf(" 1. Random PIN OxM\n");
- printf(" 2. (Not Supported)\n");
- printf(" 3. Pre-Configured PIN OxM\n");
+ printf(" %d. (Not Supported)\n", OIC_JUST_WORKS);
+ printf(" %d. Random PIN OxM\n", OIC_RANDOM_DEVICE_PIN);
+ printf(" %d. (Not Supported)\n", OIC_MANUFACTURER_CERTIFICATE);
+ printf(" %d. (Not Supported)\n", OIC_DECENTRALIZED_PUBLIC_KEY);
+ printf(" %d. Pre-Configured PIN OxM\n", OIC_PRECONFIG_PIN);
printf(" > Enter Number of OxM for Multiple Ownership Transfer : ");
for(int ret=0; 1!=ret; )
{
OIC_LOG(DEBUG, TAG, "IN MOTAddMOTMethod");
- VERIFY_SUCCESS(TAG, (OIC_OXM_COUNT > newOxm), ERROR);
+ VERIFY_SUCCESS(TAG, (OIC_OXM_COUNT > newOxm || OIC_PRECONFIG_PIN == newOxm), ERROR);
VERIFY_NON_NULL(TAG, targetDeviceInfo, ERROR);
postOxmRes = OC_STACK_INVALID_CALLBACK;
VERIFY_NON_NULL(TAG, resultCallback, ERROR);
static OCStackResult StartMultipleOwnershipTransfer(OTMContext_t* motCtx,
OCProvisionDev_t* selectedDevice);
-/**
- * Array to store the callbacks for each owner transfer method.
- */
-static OTMCallbackData_t g_MOTCbDatas[OIC_OXM_COUNT] = {
- //Just works
- {.loadSecretCB = LoadSecretJustWorksCallback,
- .createSecureSessionCB = CreateSecureSessionJustWorksCallback,
- .createSelectOxmPayloadCB = NULL,
- .createOwnerTransferPayloadCB = NULL},
-
- //Random PIN
- {.loadSecretCB = InputPinCodeCallback,
- .createSecureSessionCB = CreateSecureSessionRandomPinCallback,
- .createSelectOxmPayloadCB = NULL,
- .createOwnerTransferPayloadCB = NULL},
-
- //Manufacturer Cert
- {.loadSecretCB = NULL,
- .createSecureSessionCB = NULL,
- .createSelectOxmPayloadCB = NULL,
- .createOwnerTransferPayloadCB = NULL},
-
- //Preconfig PIN
- {.loadSecretCB = LoadPreconfPinCodeCallback,
- .createSecureSessionCB = CreateSecureSessionPreconfPinCallback,
- .createSelectOxmPayloadCB = NULL,
- .createOwnerTransferPayloadCB = NULL},
-};
-
static OTMContext_t* g_MotCtx = NULL;
static bool IsComplete(OTMContext_t* otmCtx)
OIC_LOG(WARNING, TAG, "StartOwnershipTransfer : Failed to register DTLS handshake callback.");
}
- size_t oxmSel = (size_t)(selectedDevice->doxm->oxmSel);
- OIC_LOG_V(DEBUG, TAG, "Multiple Ownership Transfer method = %d", selectedDevice->doxm->oxmSel);
+ OicSecOxm_t oxmSel = selectedDevice->doxm->oxmSel;
+ OIC_LOG_V(DEBUG, TAG, "Multiple Ownership Transfer method = %d", (int)oxmSel);
+
+ res = OTMSetOTCallback(selectedDevice->doxm->oxmSel, &motCtx->otmCallback);
+ if(OC_STACK_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "Error in OTMSetOTCallback : %d", res);
+ return res;
+ }
+ //Only two functions required for MOT
+ VERIFY_NON_NULL(TAG, motCtx->otmCallback.loadSecretCB, ERROR);
+ VERIFY_NON_NULL(TAG, motCtx->otmCallback.createSecureSessionCB, ERROR);
if(OIC_PRECONFIG_PIN != oxmSel && OIC_RANDOM_DEVICE_PIN != oxmSel)
{
return OC_STACK_ERROR;
}
- if(OIC_RANDOM_DEVICE_PIN == selectedDevice->doxm->oxmSel)
+ if(OIC_RANDOM_DEVICE_PIN == oxmSel)
{
if(CA_STATUS_OK != CAregisterPskCredentialsHandler(GetDtlsPskForRandomPinOxm))
{
}
}
- res = g_MOTCbDatas[oxmSel].loadSecretCB(motCtx);
+ res = motCtx->otmCallback.loadSecretCB(motCtx);
VERIFY_SUCCESS(TAG, OC_STACK_OK == res, ERROR);
//Save the current context instance to use on the dtls handshake callback
g_MotCtx = motCtx;
- res = g_MOTCbDatas[oxmSel].createSecureSessionCB(motCtx);
+ res = motCtx->otmCallback.createSecureSessionCB(motCtx);
VERIFY_SUCCESS(TAG, OC_STACK_OK == res, ERROR);
OIC_LOG(INFO, TAG, "OUT StartMultipleOwnershipTransfer");
#define TAG "OTM"
/**
- * Array to store the callbacks for each owner transfer method.
+ * Variables for pointing the OTMContext to be used in the DTLS handshake result callback.
*/
-static OTMCallbackData_t g_OTMCbDatas[OIC_OXM_COUNT] = {
- //Just works
- {.loadSecretCB = LoadSecretJustWorksCallback,
- .createSecureSessionCB = CreateSecureSessionJustWorksCallback,
- .createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload,
- .createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload},
-
- //Random PIN
- {.loadSecretCB = InputPinCodeCallback,
- .createSecureSessionCB = CreateSecureSessionRandomPinCallback,
- .createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload,
- .createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload},
-
- //Manufacturer Cert
- {.loadSecretCB = NULL,
- .createSecureSessionCB = NULL,
- .createSelectOxmPayloadCB = NULL,
- .createOwnerTransferPayloadCB = NULL},
+static OTMContext_t* g_otmCtx = NULL;
+
+OCStackResult OTMSetOTCallback(OicSecOxm_t oxm, OTMCallbackData_t* callbacks)
+{
+ OCStackResult res = OC_STACK_INVALID_PARAM;
+
+ OIC_LOG(INFO, TAG, "IN OTMSetOTCallback");
+ VERIFY_NON_NULL(TAG, callbacks, ERROR);
#ifdef _ENABLE_MULTIPLE_OWNER_
- //Preconfig PIN
- {.loadSecretCB = LoadPreconfPinCodeCallback,
- .createSecureSessionCB = CreateSecureSessionPreconfPinCallback,
- .createSelectOxmPayloadCB = CreatePreconfPinBasedSelectOxmPayload,
- .createOwnerTransferPayloadCB = CreatePreconfPinBasedOwnerTransferPayload},
+ VERIFY_SUCCESS(TAG, (OIC_OXM_COUNT > oxm || OIC_PRECONFIG_PIN == oxm), ERROR);
+#else
+ VERIFY_SUCCESS(TAG, (OIC_OXM_COUNT > oxm), ERROR);
#endif //_ENABLE_MULTIPLE_OWNER_
-};
-/**
- * Variables for pointing the OTMContext to be used in the DTLS handshake result callback.
- */
-static OTMContext_t* g_otmCtx = NULL;
+ switch(oxm)
+ {
+ case OIC_JUST_WORKS:
+ callbacks->loadSecretCB = LoadSecretJustWorksCallback;
+ callbacks->createSecureSessionCB = CreateSecureSessionJustWorksCallback;
+ callbacks->createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload;
+ callbacks->createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload;
+ break;
+ case OIC_RANDOM_DEVICE_PIN:
+ callbacks->loadSecretCB = InputPinCodeCallback;
+ callbacks->createSecureSessionCB = CreateSecureSessionRandomPinCallback;
+ callbacks->createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload;
+ callbacks->createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload;
+ break;
+ case OIC_MANUFACTURER_CERTIFICATE:
+ OIC_LOG(ERROR, TAG, "OIC_MANUFACTURER_CERTIFICATE not supported yet.");
+ return OC_STACK_INVALID_METHOD;
+ case OIC_DECENTRALIZED_PUBLIC_KEY:
+ OIC_LOG(ERROR, TAG, "OIC_DECENTRALIZED_PUBLIC_KEY not supported yet.");
+ return OC_STACK_INVALID_METHOD;
+#ifdef _ENABLE_MULTIPLE_OWNER_
+ case OIC_PRECONFIG_PIN:
+ callbacks->loadSecretCB = LoadPreconfPinCodeCallback;
+ callbacks->createSecureSessionCB = CreateSecureSessionPreconfPinCallback;
+ callbacks->createSelectOxmPayloadCB = CreatePreconfPinBasedSelectOxmPayload;
+ callbacks->createOwnerTransferPayloadCB = CreatePreconfPinBasedOwnerTransferPayload;
+ break;
+#endif //_ENABLE_MULTIPLE_OWNER_
+ default:
+ OIC_LOG_V(ERROR, TAG, "Unknown OxM : %d", (int)oxm);
+ return OC_STACK_INVALID_PARAM;
+ break;
+ }
+
+ res = OC_STACK_OK;
+exit:
+ OIC_LOG(INFO, TAG, "OUT OTMSetOTCallback");
+ return res;
+}
+
/**
* Function to select appropriate provisioning method.
}
}
- if(NULL == g_OTMCbDatas[(*selectedMethod)].loadSecretCB ||
- NULL == g_OTMCbDatas[(*selectedMethod)].createSecureSessionCB ||
- NULL == g_OTMCbDatas[(*selectedMethod)].createSelectOxmPayloadCB ||
- NULL == g_OTMCbDatas[(*selectedMethod)].createOwnerTransferPayloadCB)
- {
- OIC_LOG_V(ERROR, TAG, "Please make sure the OxM(%d)'s callback registration", (int)(*selectedMethod));
- return OC_STACK_INVALID_CALLBACK;
- }
-
OIC_LOG(DEBUG, TAG, "OUT SelectProvisioningMethod");
return OC_STACK_OK;
//DTLS Handshake
//Load secret for temporal secure session.
- if(g_OTMCbDatas[selOxm].loadSecretCB)
+ if(otmCtx->otmCallback.loadSecretCB)
{
- res = g_OTMCbDatas[selOxm].loadSecretCB(otmCtx);
+ res = otmCtx->otmCallback.loadSecretCB(otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "OperationModeUpdate : Failed to load secret");
g_otmCtx = otmCtx;
//Try DTLS handshake to generate secure session
- if(g_OTMCbDatas[selOxm].createSecureSessionCB)
+ if(otmCtx->otmCallback.createSecureSessionCB)
{
- res = g_OTMCbDatas[selOxm].createSecureSessionCB(otmCtx);
+ res = otmCtx->otmCallback.createSecureSessionCB(otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "OperationModeUpdate : Failed to create DTLS session");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
+
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
+
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- OCStackResult res = g_OTMCbDatas[selectedOxm].createSelectOxmPayloadCB(otmCtx,
+ OCStackResult res = otmCtx->otmCallback.createSelectOxmPayloadCB(otmCtx,
&secPayload->securityData, &secPayload->payloadSize);
if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- OCStackResult res = g_OTMCbDatas[deviceInfo->doxm->oxmSel].createOwnerTransferPayloadCB(
+ OCStackResult res = otmCtx->otmCallback.createOwnerTransferPayloadCB(
otmCtx, &secPayload->securityData, &secPayload->payloadSize);
if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
}
OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
+ res = OTMSetOTCallback(selectedDevice->doxm->oxmSel, &otmCtx->otmCallback);
+ if(OC_STACK_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "Error in OTMSetOTCallback : %d", res);
+ return res;
+ }
+
//Send Req: POST /oic/sec/doxm [{..."OxmSel" :g_OTMCbDatas[Index of Selected OxM].OXMString,...}]
res = PostOwnerTransferModeToResource(otmCtx);
if(OC_STACK_OK != res)
return OC_STACK_INVALID_PARAM;
}
- g_OTMCbDatas[oxmType].loadSecretCB= data->loadSecretCB;
- g_OTMCbDatas[oxmType].createSecureSessionCB = data->createSecureSessionCB;
- g_OTMCbDatas[oxmType].createSelectOxmPayloadCB = data->createSelectOxmPayloadCB;
- g_OTMCbDatas[oxmType].createOwnerTransferPayloadCB = data->createOwnerTransferPayloadCB;
+ // TODO: Remove this API, Please see the jira ticket IOT-1484
OIC_LOG(DEBUG, TAG, "OUT OTMSetOwnerTransferCallbackData");
const char * OXM_RANDOM_DEVICE_PIN = "oic.sec.doxm.rdp";
const char * OXM_MANUFACTURER_CERTIFICATE = "oic.sec.doxm.mfgcert";
#ifdef _ENABLE_MULTIPLE_OWNER_
-const char * OXM_PRECONF_PIN = "oic.sec.doxm.pcp";
+const char * OXM_PRECONF_PIN = "x.org.iotivity.doxm.pcp";
#endif //_ENABLE_MULTIPLE_OWNER_
//Credential data encoding methods