Update for Multi Ownership Transfer condition
authorJihun Ha <jihun.ha@samsung.com>
Sat, 7 Jan 2017 04:09:08 +0000 (13:09 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 9 Jan 2017 02:01:09 +0000 (02:01 +0000)
The found enrollee's owner ID indicates a same ID of mediator.
However, a list of owned devices managed in mediator's PMD db has
no element for the found enrollee. In that case, MOT will be failed.

For this, ES_OWNERSHIP_IS_NOT_SYNCHRONIZED value is returned, which
guides a user to reset a Enrollee's SVR DB file.

Change-Id: Ia5feaccccfc4cca4a0673d08cbba4d473324e37f
Signed-off-by: Parkhi <h_w.park@samsung.com>
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16191
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/inc/escommon.h
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp

index ecd31bb..39636ef 100755 (executable)
@@ -174,7 +174,10 @@ typedef enum
     ES_SECURE_RESOURCE_DISCOVERY_FAILURE,
 
     /**
-     * Ownership transfer fails because DTLS handshake failure happens
+     * Ownership transfer fails due to one of unexpected reasons.
+     * E.g. A packet loss even with retransmission happens during ownership transfer.
+     * E.g. Mediator's owned status is 'unowned'
+     * E.g. A user confirmation for random pin-based or certificate-based OT fails
      */
     ES_OWNERSHIP_TRANSFER_FAILURE,
 
@@ -203,6 +206,14 @@ typedef enum
     ES_PRE_CONFIG_PIN_PROVISIONING_FAILURE,
 
     /**
+     * The found enrollee's owner ID indicates a same ID of mediator.
+     * However, a list of owned devices managed in mediator's PMD db has no element for the found enrollee.
+     * That can happen where only mediator is reset without any inform to the enrollee.
+     * To proceed an ownership transfer to the enrollee, it needs to reset the enrollee's SVR DB for its owner, i.e. the mediator
+     */
+    ES_OWNERSHIP_IS_NOT_SYNCHRONIZED,
+
+    /**
      * Provisioning fails for some reason.
      */
     ES_ERROR = 255
index d9d1b47..99bc477 100755 (executable)
@@ -493,6 +493,53 @@ namespace OIC
 #ifdef MULTIPLE_OWNER
                     else
                     {
+                        OCUUIdentity* mediatorDevId = (OCUUIdentity* )OICMalloc(sizeof(OCUUIdentity));
+
+                        if(!mediatorDevId)
+                        {
+                            OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "provisionOwnership: OICMalloc error return");
+                            res = ESResult::ES_OWNERSHIP_TRANSFER_FAILURE;
+                            return res;
+                        }
+
+                        if(OC::OCPlatform::getDeviceId(mediatorDevId) != OC_STACK_OK)
+                        {
+                            OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "getDeviceId is failed.");
+                            res = ESResult::ES_OWNERSHIP_TRANSFER_FAILURE;
+                            OICFree(mediatorDevId);
+                            return res;
+                        }
+
+                        if(!memcmp(m_securedResource->getDevPtr()->doxm->owner.id,
+                                   mediatorDevId->id, UUID_IDENTITY_SIZE * sizeof(uint8_t)))
+                        {
+                            OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,
+                                "The found device's owner ID is same as Mediator's ID but Meditor does not know it");
+                            OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Only Mediator would be reset");
+                            res = ESResult::ES_OWNERSHIP_IS_NOT_SYNCHRONIZED;
+                            OICFree(mediatorDevId);
+                            return res;
+                        }
+
+                        OicSecSubOwner_t* subOwnerList = m_securedResource->getDevPtr()->doxm->subOwners;
+
+                        while(subOwnerList)
+                        {
+                            if(!memcmp(subOwnerList->uuid.id, mediatorDevId->id,
+                                UUID_IDENTITY_SIZE * sizeof(uint8_t)))
+                            {
+                                OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,
+                                    "The found device's subOwner ID is same as Mediator's ID but Meditor does not know it");
+                                OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Only Mediator would be reset");
+                                res = ESResult::ES_OWNERSHIP_IS_NOT_SYNCHRONIZED;
+                                OICFree(mediatorDevId);
+                                return res;
+                            }
+                            subOwnerList = subOwnerList->next;
+                        }
+
+                        OICFree(mediatorDevId);
+
                         res = performMultipleOwnershipTransfer();
 
                         if(res != ESResult::ES_OK)