newDevDoxm->owned = false;
otmCtx->attemptCnt++;
- if(WRONG_PIN_MAX_ATTEMP > otmCtx->attemptCnt)
+ // In order to re-start ownership transfer, device information should be deleted from PDM.
+ res = PDMDeleteDevice(&(otmCtx->selectedDeviceInfo->doxm->deviceID));
+ if (OC_STACK_OK != res)
{
- res = StartOwnershipTransfer(otmCtx, otmCtx->selectedDeviceInfo);
- if(OC_STACK_OK != res)
- {
- SetResult(otmCtx, res);
- OIC_LOG(ERROR, TAG, "Failed to Re-StartOwnershipTransfer");
- }
+ SetResult(otmCtx, res);
+ OIC_LOG(ERROR, TAG, "Failed to PDMDeleteDevice");
}
else
{
- OIC_LOG(ERROR, TAG, "User has exceeded the number of authentication attempts.");
- SetResult(otmCtx, OC_STACK_AUTHENTICATION_FAILURE);
+ if(WRONG_PIN_MAX_ATTEMP > otmCtx->attemptCnt)
+ {
+ res = StartOwnershipTransfer(otmCtx, otmCtx->selectedDeviceInfo);
+ if(OC_STACK_OK != res)
+ {
+ SetResult(otmCtx, res);
+ OIC_LOG(ERROR, TAG, "Failed to Re-StartOwnershipTransfer");
+ }
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "User has exceeded the number of authentication attempts.");
+ SetResult(otmCtx, OC_STACK_AUTHENTICATION_FAILURE);
+ }
}
}
else
OCEntityHandlerResult ehRet = OC_EH_ERROR;
OicUuid_t emptyOwner = {.id = {0} };
static uint16_t previousMsgId = 0;
+ bool isDuplicatedMsg = false;
/*
* Convert CBOR Doxm data into binary. This will also validate
OCStackResult res = CBORPayloadToDoxmBin(payload, size, &newDoxm, &roParsed);
if (newDoxm && OC_STACK_OK == res)
{
+ /*
+ * message ID is supported for CoAP over UDP only according to RFC 7252
+ * So we should check message ID to prevent duplicate request handling in case of OC_ADAPTER_IP.
+ * In case of other transport adapter, duplicate message check is not required.
+ */
+ if (OC_ADAPTER_IP == ehRequest->devAddr.adapter &&
+ previousMsgId == ehRequest->messageID)
+ {
+ isDuplicatedMsg = true;
+ }
+
// Check request on RO property
if (true == roParsed)
{
//In case of Mutual Verified Just-Works, verify mutualVerifNum
if (OIC_MV_JUST_WORKS == newDoxm->oxmSel && false == newDoxm->owned &&
- previousMsgId != ehRequest->messageID)
+ false == isDuplicatedMsg)
{
uint8_t preMutualVerifNum[OWNER_PSK_LENGTH_128] = {0};
uint8_t mutualVerifNum[MUTUAL_VERIF_NUM_LEN] = {0};
ehRequest->devAddr.adapter);
VERIFY_SUCCESS(TAG, caRes == CA_STATUS_OK, ERROR);
- char ranPin[OXM_RANDOM_PIN_MAX_SIZE + 1] = {0};
- //TODO ehRequest->messageID for copa over TCP always is null. Find reason why.
- if(ehRequest->devAddr.adapter == OC_ADAPTER_IP && previousMsgId != ehRequest->messageID)
- {
- if(OC_STACK_OK == GeneratePin(ranPin, sizeof(ranPin)))
- {
- //Set the device id to derive temporal PSK
- SetUuidForPinBasedOxm(&gDoxm->deviceID);
-
- /**
- * Since PSK will be used directly by DTLS layer while PIN based ownership transfer,
- * Credential should not be saved into SVR.
- * For this reason, use a temporary get_psk_info callback to random PIN OxM.
- */
- caRes = CAregisterPskCredentialsHandler(GetDtlsPskForRandomPinOxm);
- VERIFY_SUCCESS(TAG, caRes == CA_STATUS_OK, ERROR);
- ehRet = OC_EH_OK;
- }
- else
- {
- OIC_LOG(ERROR, TAG, "Failed to generate random PIN");
- ehRet = OC_EH_ERROR;
- }
- }
- else if(OC_ADAPTER_TCP == ehRequest->devAddr.adapter)
+ if (!isDuplicatedMsg)
{
- if(OC_STACK_OK == GeneratePin(ranPin, sizeof(ranPin)))
+ char ranPin[OXM_RANDOM_PIN_MAX_SIZE + 1] = {0};
+ if (OC_STACK_OK == GeneratePin(ranPin, sizeof(ranPin)))
{
//Set the device id to derive temporal PSK
SetUuidForPinBasedOxm(&gDoxm->deviceID);
OIC_LOG(ERROR, TAG, "Failed to generate random PIN");
ehRet = OC_EH_ERROR;
}
-
}
#endif // __WITH_DTLS__ or __WITH_TLS__
}
//In case of Confirm Manufacturer Cert, get user confirmation
if (OIC_CON_MFG_CERT == newDoxm->oxmSel && false == newDoxm->owned &&
- previousMsgId != ehRequest->messageID &&
- memcmp(&(newDoxm->owner), &emptyOwner, sizeof(OicUuid_t)) != 0)
+ false == isDuplicatedMsg &&
+ memcmp(&(newDoxm->owner), &emptyOwner, sizeof(OicUuid_t)) != 0)
{
if (OC_STACK_OK != VerifyOwnershipTransfer(NULL, USER_CONFIRM))
{
{
OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request");
- if((OC_ADAPTER_IP == ehRequest->devAddr.adapter && previousMsgId != ehRequest->messageID)
- || OC_ADAPTER_TCP == ehRequest->devAddr.adapter)
+ if (!isDuplicatedMsg)
{
RestoreDoxmToInitState();
RestorePstatToInitState();
}
else
{
- previousMsgId = ehRequest->messageID++;
+ previousMsgId = ehRequest->messageID;
}
//Send payload to request originator
OIC_LOG(INFO, TAG, "HandlePstatPostRequest processing POST request");
OicSecPstat_t *pstat = NULL;
static uint16_t previousMsgId = 0;
+ bool isDuplicatedMsg = false;
if (ehRequest->payload && NULL != gPstat)
{
{
bool validReq = false;
+ /*
+ * message ID is supported for CoAP over UDP only according to RFC 7252
+ * So we should check message ID to prevent duplicate request handling in case of OC_ADAPTER_IP.
+ * In case of other transport adapter, duplicate message check is not required.
+ */
+ if (OC_ADAPTER_IP == ehRequest->devAddr.adapter &&
+ previousMsgId == ehRequest->messageID)
+ {
+ isDuplicatedMsg = true;
+ }
+
if (true == roParsed)
{
OIC_LOG(ERROR, TAG, "Not acceptable request because of read-only properties");
{
OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request");
- if((OC_ADAPTER_IP == ehRequest->devAddr.adapter && previousMsgId != ehRequest->messageID)
- || OC_ADAPTER_TCP == ehRequest->devAddr.adapter)
+ if (!isDuplicatedMsg)
{
RestoreDoxmToInitState();
RestorePstatToInitState();
{
if(ehRequest->devAddr.adapter == OC_ADAPTER_IP)
{
- previousMsgId = ehRequest->messageID++;
+ previousMsgId = ehRequest->messageID;
}
}