From e3b03bdd25c4cba2af371577e6adad63590fa22a Mon Sep 17 00:00:00 2001 From: Parkhi Date: Mon, 16 Jan 2017 15:15:10 +0900 Subject: [PATCH] Update ESResult according to OTM is subdivided. - ES_USER_DENIED_CONFIRMATION_REQ - ES_AUTHENTICATION_FAILURE_WITH_WRONG_CERT - ES_AUTHENTICATION_FAILURE_WITH_WRONG_PIN Change-Id: Iaca2ae2551161685fed738b9a588945938b3cd43 Signed-off-by: Parkhi Reviewed-on: https://gerrit.iotivity.org/gerrit/16373 Reviewed-by: Jihun Ha Tested-by: jenkins-iotivity Reviewed-by: Uze Choi Tested-by: Uze Choi --- service/easy-setup/inc/escommon.h | 15 ++++++ .../mediator/richsdk/src/EnrolleeSecurity.cpp | 54 ++++++++++++++++++---- .../mediator/richsdk/src/EnrolleeSecurity.h | 4 +- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/service/easy-setup/inc/escommon.h b/service/easy-setup/inc/escommon.h index 39636ef..30289da 100755 --- a/service/easy-setup/inc/escommon.h +++ b/service/easy-setup/inc/escommon.h @@ -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 diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp index 99bc477..a609fa9 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp @@ -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(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__) } } + diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h index 6179634..435ef7c 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h @@ -81,7 +81,7 @@ namespace OIC ESSecurityCb cb, std::weak_ptr 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); -- 2.7.4