Update ESResult according to OTM is subdivided.
authorParkhi <h_w.park@samsung.com>
Mon, 16 Jan 2017 06:15:10 +0000 (15:15 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 17 Jan 2017 04:56:15 +0000 (04:56 +0000)
- ES_USER_DENIED_CONFIRMATION_REQ
- ES_AUTHENTICATION_FAILURE_WITH_WRONG_CERT
- ES_AUTHENTICATION_FAILURE_WITH_WRONG_PIN

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

index 39636ef..30289da 100755 (executable)
@@ -214,6 +214,21 @@ typedef enum
     ES_OWNERSHIP_IS_NOT_SYNCHRONIZED,
 
     /**
+     * Ownership transfer which is cert-based method fails due to user confirmation is denied.
+     */
+    ES_USER_DENIED_CONFIRMATION_REQ,
+
+    /**
+     * Ownership transfer which is cert-based method fails due to wrong certificate.
+     */
+    ES_AUTHENTICATION_FAILURE_WITH_WRONG_CERT,
+
+    /**
+     * Ownership transfer which is random-pin method fails due to wrong pin.
+     */
+    ES_AUTHENTICATION_FAILURE_WITH_WRONG_PIN,
+
+    /**
      * Provisioning fails for some reason.
      */
     ES_ERROR = 255
index 99bc477..a609fa9 100755 (executable)
@@ -245,7 +245,8 @@ namespace OIC
         }
 #endif
 
-        void EnrolleeSecurity::ownershipTransferCb(OC::PMResultList_t *result, int hasError)
+        void EnrolleeSecurity::ownershipTransferCb(OC::PMResultList_t *result, int hasError
+                                                   , ESResult& res)
         {
             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "ownershipTransferCb IN");
 
@@ -253,7 +254,43 @@ namespace OIC
 
             if (hasError)
             {
-                OIC_LOG_V(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransfer is failed with code(%d)", hasError);
+                for (unsigned int i = 0; i < result->size(); i++)
+                {
+                    std::string uuid;
+                    convertUUIDToString(result->at(i).deviceId.id, uuid);
+
+                    if(m_ocResource != NULL && m_ocResource->sid() == uuid)
+                    {
+                        if(OC_STACK_USER_DENIED_REQ == result->at(i).res)
+                        {
+                            res = ESResult::ES_USER_DENIED_CONFIRMATION_REQ;
+                        }
+                        else if(OC_STACK_AUTHENTICATION_FAILURE  == result->at(i).res)
+                        {
+                            OicSecOxm_t oxm;
+                            if(OC_STACK_OK != m_securedResource->getOTMethod(&oxm))
+                            {
+                                OTMResult = false;
+                                return;
+                            }
+
+                            if(OIC_MANUFACTURER_CERTIFICATE == oxm)
+                            {
+                                res = ESResult::ES_AUTHENTICATION_FAILURE_WITH_WRONG_CERT;
+                            }
+                            else if(OIC_CON_MFG_CERT == oxm)
+                            {
+                                res = ESResult::ES_AUTHENTICATION_FAILURE_WITH_WRONG_CERT;
+                            }
+                            else if(OIC_RANDOM_DEVICE_PIN == oxm)
+                            {
+                                res = ESResult::ES_AUTHENTICATION_FAILURE_WITH_WRONG_PIN;
+                            }
+                        }
+                    }
+                }
+                OIC_LOG_V(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransfer is failed with ESResult(%d)", res);
+
                 OTMResult = false;
             }
             else
@@ -400,12 +437,13 @@ namespace OIC
                             res = ESResult::ES_OWNERSHIP_TRANSFER_FAILURE;
                             return res;
                         }
-                        OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Removing device is succeeded.");
+                        OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Removing device is succeeded.");
                     }
 
                     if(!m_securedResource->getOwnedStatus())
                     {
-                        res = performOwnershipTransfer();
+                        ESResult result = ESResult::ES_OWNERSHIP_TRANSFER_FAILURE;
+                        res = performOwnershipTransfer(result);
 
                         if(res != ESResult::ES_OK)
                         {
@@ -420,8 +458,7 @@ namespace OIC
                         if(!OTMResult)
                         {
                             OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Ownership-Transfer failed.");
-                            res = ESResult::ES_OWNERSHIP_TRANSFER_FAILURE;
-                            return res;
+                            return result;
                         }
 #ifdef MULTIPLE_OWNER
                         if( m_securedResource->isMOTSupported() &&
@@ -576,7 +613,7 @@ namespace OIC
             return res;
         }
 
-        ESResult EnrolleeSecurity::performOwnershipTransfer()
+        ESResult EnrolleeSecurity::performOwnershipTransfer(ESResult& res)
         {
             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "performOwnershipTransfer IN.");
 
@@ -589,7 +626,7 @@ namespace OIC
                 std::bind(&EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
                           std::placeholders::_1, std::placeholders::_2,
                           static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::ownershipTransferCb,
-                          this, std::placeholders::_1, std::placeholders::_2)),
+                          this, std::placeholders::_1, std::placeholders::_2, std::ref(res))),
                           shared_from_this());
 
 
@@ -1071,3 +1108,4 @@ namespace OIC
 #endif //defined(__WITH_DTLS__) && defined(__WITH_TLS__)
     }
 }
+
index 6179634..435ef7c 100755 (executable)
@@ -81,7 +81,7 @@ namespace OIC
                                     ESSecurityCb cb,
                                     std::weak_ptr<EnrolleeSecurity> this_ptr);
 
-            ESResult performOwnershipTransfer();
+            ESResult performOwnershipTransfer(ESResult& res);
             bool isOwnedDeviceRegisteredInSVRDB();
             void removeDeviceWithUuidCB(OC::PMResultList_t *result, int hasError);
 #ifdef MULTIPLE_OWNER
@@ -90,7 +90,7 @@ namespace OIC
             void PreconfigPinProvCB(PMResultList_t *result, int hasError);
             void MultipleOwnershipTransferCb(OC::PMResultList_t *result, int hasError);
 #endif
-            void ownershipTransferCb(OC::PMResultList_t *result, int hasError);
+            void ownershipTransferCb(OC::PMResultList_t *result, int hasError, ESResult& res);
             void convertUUIDToString(const uint8_t uuid[UUID_SIZE],
                                                 std::string& uuidString);
             std::string getResourceDeviceAddress(const std::string& host);