From: Parkhi Date: Fri, 30 Sep 2016 02:41:03 +0000 (+0900) Subject: Merge all changes of easy setup in master branch to 1.2-rel branch X-Git-Tag: 1.2.0+RC3~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6b5e9ff337264c38951bef39fd4980ab697f14ac;p=platform%2Fupstream%2Fiotivity.git Merge all changes of easy setup in master branch to 1.2-rel branch https://gerrit.iotivity.org/gerrit/#/c/11947/ https://gerrit.iotivity.org/gerrit/#/c/12003/ https://gerrit.iotivity.org/gerrit/#/c/12155/ https://gerrit.iotivity.org/gerrit/#/c/11991/ Change-Id: Id3ac0160c5edd6c7abecb9714425601747d1a384 Signed-off-by: Parkhi Reviewed-on: https://gerrit.iotivity.org/gerrit/12607 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp b/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp index ef6611f..6ebe826 100755 --- a/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp +++ b/service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp @@ -422,8 +422,7 @@ TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess) mocks.OnCallFunc(cloudProvisioningStatusCallback).Do( [& cntForReceivedCallbackWithSuccess](std::shared_ptr< CloudPropProvisioningStatus > status) { - // Will called twice - if(status->getESResult() == ES_OK || status->getESResult() == ES_FOUND_ENROLLEE) + if(status->getESResult() == ES_OK) { cntForReceivedCallbackWithSuccess++; } @@ -447,7 +446,7 @@ TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess) std::unique_lock< std::mutex > lock{ mutexForCondition }; responseCon.wait_for(lock, g_waitForResponse); - EXPECT_EQ(cntForReceivedCallbackWithSuccess, 3); + EXPECT_EQ(cntForReceivedCallbackWithSuccess, 2); ESTerminateEnrollee(); } diff --git a/service/easy-setup/inc/escommon.h b/service/easy-setup/inc/escommon.h index f31e3d5..8ce57b0 100755 --- a/service/easy-setup/inc/escommon.h +++ b/service/easy-setup/inc/escommon.h @@ -130,37 +130,49 @@ typedef enum ES_OK = 0, /** - * Successfully found Enrollee in a given network. This will be given in Cloud provisioning step. + * Enrollee discovery fails in cloud provisioning */ - ES_FOUND_ENROLLEE = 1, + ES_ENROLLEE_DISCOVERY_FAILURE = 11, /** - * Not found Enrollee in a give network. This will be given in Cloud provisioning step. + * Valid GET or POST request fails for some reason. + * This failure may happen when it failed to receive any response from Enrollee by a timeout threshold */ - ES_NOT_FOUND_ENROLLEE = 11, + ES_COMMUNICATION_ERROR, /** - * Security opertion is not supported because it is built as unsecured mode. + * Security opertion is not supported because Mediator is built as unsecured mode. */ ES_SEC_OPERATION_IS_NOT_SUPPORTED = 20, /** - * A previous request is denied due to its unauthority. It means, Mediator is not unauthroized - * to Enrollee for some reaons. + * Security resource discovery fails due to loss of discovery packet or absence of the resource in a network */ - ES_UNAUTHORIZED_REQ = 21, + ES_SECURE_RESOURCE_DISCOVERY_FAILURE, /** - * Security provisioning fails. The reasons would be: a packet loss for unowned/owned device - * discovery request or ownership transfer request, or a denial to ownership transfer by Enrollee - * for some reason. + * Ownership transfer fails because DTLS handshake failure happens */ - ES_SEC_PROVISION_FAILS = 22, + ES_OWNERSHIP_TRANSFER_FAILURE, + + /** + * ACL provisioning fails in cloud provisioning. + * It could be that UUID format of cloud server is wrong. + * Or any response for the provisioning request is not arrived at Mediator + */ + ES_ACL_PROVISIONING_FAILURE, + + /** + * Cert. provisioning fails in cloud provisioning. + * It could be that you put a wrong cred ID of which the corresponding certificate does not exist in SVR DB. + * Or any response for the provisioning request is not arrived at Mediator + */ + ES_CERT_PROVISIONING_FAILURE, /** * Provisioning fails for some reason. */ - ES_ERROR = 255, + ES_ERROR = 255 } ESResult; /** diff --git a/service/easy-setup/mediator/richsdk/SConscript b/service/easy-setup/mediator/richsdk/SConscript old mode 100644 new mode 100755 index af54740..0805bfe --- a/service/easy-setup/mediator/richsdk/SConscript +++ b/service/easy-setup/mediator/richsdk/SConscript @@ -105,7 +105,6 @@ if target_os in ['android','linux']: # For bring up purposes only, the forked version will live here. easy_setup_env.AppendUnique(CPPPATH = [env.get('SRC_DIR') + '/resource/csdk/connectivity/lib/libcoap-4.1.1/include']) easy_setup_env.AppendUnique(CPPPATH = [ - env.get('SRC_DIR') + '/resource/csdk/connectivity/lib/libcoap-4.1.1', env.get('SRC_DIR') + '/resource/csdk/security/provisioning/include', env.get('SRC_DIR') + '/resource/csdk/security/include/internal', env.get('SRC_DIR') + '/resource/csdk/connectivity/api/', diff --git a/service/easy-setup/mediator/richsdk/src/CloudResource.cpp b/service/easy-setup/mediator/richsdk/src/CloudResource.cpp index c206c4d..adc5271 100755 --- a/service/easy-setup/mediator/richsdk/src/CloudResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/CloudResource.cpp @@ -68,10 +68,11 @@ namespace OIC OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is failed "); - if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ) + if(eCode == OCStackResult::OC_STACK_COMM_ERROR) { - OIC_LOG(DEBUG, ES_CLOUD_RES_TAG, "Mediator is unauthorized from Enrollee."); - result = ESResult::ES_UNAUTHORIZED_REQ; + OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, + "can't receive any response from Enrollee by a timeout threshold."); + result = ESResult::ES_COMMUNICATION_ERROR; } std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared< diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp index 2623462..0b3e4ab 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp @@ -46,10 +46,20 @@ namespace OIC if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED) { + ESResult result = ESResult::ES_ERROR; + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, - "onProvisioningResponse : Provisioning is failed "); + "onProvisioningResponse : Provisioning is failed "); + + if(eCode == OCStackResult::OC_STACK_COMM_ERROR) + { + OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, + "can't receive any response from Enrollee by a timeout threshold."); + result = ESResult::ES_COMMUNICATION_ERROR; + } + std::shared_ptr< DevicePropProvisioningStatus > provStatus = std::make_shared< - DevicePropProvisioningStatus >(ESResult::ES_ERROR); + DevicePropProvisioningStatus >(result); m_devicePropProvStatusCb(provStatus); return; } @@ -75,11 +85,11 @@ namespace OIC OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetStatusResponse : onGetStatusResponse is failed "); - if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ) + if(eCode == OCStackResult::OC_STACK_COMM_ERROR) { OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, - "Mediator is unauthorized from Enrollee."); - result = ESResult::ES_UNAUTHORIZED_REQ; + "can't receive any response from Enrollee by a timeout threshold."); + result = ESResult::ES_COMMUNICATION_ERROR; } EnrolleeStatus enrolleeStatus(rep); @@ -106,16 +116,16 @@ namespace OIC if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED) { - ESResult result = ESResult::ES_ERROR; + ESResult result = ESResult::ES_ERROR; OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetConfigurationResponse : onGetConfigurationResponse is failed "); - if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ) + if(eCode == OCStackResult::OC_STACK_COMM_ERROR) { OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, - "Mediator is unauthorized from Enrollee."); - result = ESResult::ES_UNAUTHORIZED_REQ; + "can't receive any response from Enrollee by a timeout threshold."); + result = ESResult::ES_COMMUNICATION_ERROR; } EnrolleeConf enrolleeConf(rep); diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp index 0bc2d9e..f209efb 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp @@ -111,13 +111,7 @@ namespace OIC if (hasError) { OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,"Error!!! in OwnershipTransfer"); - - std::string uuid; - convertUUIDToString(result->at(0).deviceId.id, uuid); - std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = - std::make_shared< SecProvisioningStatus >(uuid, ES_ERROR); - m_securityProvStatusCb(securityProvisioningStatus); - return; + OTMResult = false; } else { @@ -125,22 +119,17 @@ namespace OIC for (unsigned int i = 0; i < result->size(); i++) { OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Result is = %d for device",result->at(i).res); - std::string uuid; - convertUUIDToString(result->at(0).deviceId.id, uuid); - - OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "UUID : %s",uuid.c_str()); - std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = - std::make_shared< SecProvisioningStatus >(uuid, ES_OK); - m_securityProvStatusCb(securityProvisioningStatus); - return; } - delete result; + OTMResult = true; } + m_cond.notify_all(); } - void EnrolleeSecurity::provisionOwnership() + ESResult EnrolleeSecurity::provisionOwnership() { + ESResult res = ESResult::ES_ERROR; + OC::DeviceList_t pUnownedDevList, pOwnedDevList; pOwnedDevList.clear(); @@ -153,8 +142,8 @@ namespace OIC if (result != OC_STACK_OK) { OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Owned Discovery failed."); - //Throw exception - throw ESPlatformException(result); + res = ESResult:: ES_SECURE_RESOURCE_DISCOVERY_FAILURE; + return res; } else if (pOwnedDevList.size()) { @@ -165,10 +154,17 @@ namespace OIC if (ownedDevice) { - std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = - std::make_shared< SecProvisioningStatus >(ownedDevice->getDeviceID(), ES_OK); - m_securityProvStatusCb(securityProvisioningStatus); - return; + if (isOwnedDeviceRegisteredInSVRDB()) + { + res = ESResult::ES_OK; + } + else + { + OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, + "The found owned device is not in Mediator's PDM."); + res = ESResult::ES_ERROR; + } + return res; } } @@ -176,8 +172,8 @@ namespace OIC if (result != OC_STACK_OK) { OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "UnOwned Discovery failed."); - //Throw exception - throw ESPlatformException(result); + res = ESResult:: ES_SECURE_RESOURCE_DISCOVERY_FAILURE; + return res; } else if (pUnownedDevList.size()) { @@ -196,29 +192,58 @@ namespace OIC &EnrolleeSecurity::removeDeviceWithUuidCB, this, std::placeholders::_1, std::placeholders::_2); - OCSecure::removeDeviceWithUuid(DISCOVERY_TIMEOUT, - m_ocResource->sid(), - removeDeviceWithUuidCB); + result = OCSecure::removeDeviceWithUuid(DISCOVERY_TIMEOUT, + m_ocResource->sid(), + removeDeviceWithUuidCB); + if(result != OC_STACK_OK) + { + OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "removeDeviceWithUuid failed."); + res = ESResult:: ES_OWNERSHIP_TRANSFER_FAILURE; + return res; + } + + std::unique_lock lck(m_mtx); + m_cond.wait(lck); + + if(!removeDeviceResult) + { + res = ESResult:: ES_OWNERSHIP_TRANSFER_FAILURE; + return res; + } } - else + + res = performOwnershipTransfer(); + + if(res != ESResult::ES_OK) + { + OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Ownership-Transfer failed."); + res = ESResult:: ES_OWNERSHIP_TRANSFER_FAILURE; + return res; + } + + std::unique_lock lck(m_mtx); + m_cond.wait(lck); + + if(!OTMResult) { - performOwnershipTransfer(); + res = ESResult::ES_OWNERSHIP_TRANSFER_FAILURE; } } else { OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "No matched unowned devices found."); - throw ESException("No matched unowned devices found."); + res = ESResult:: ES_SECURE_RESOURCE_DISCOVERY_FAILURE; } } else { OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "No unowned devices found."); - throw ESException("No unowned devices found."); + res = ESResult:: ES_SECURE_RESOURCE_DISCOVERY_FAILURE; } + return res; } - void EnrolleeSecurity::performOwnershipTransfer() + ESResult EnrolleeSecurity::performOwnershipTransfer() { OCStackResult result = OC_STACK_ERROR; @@ -241,8 +266,9 @@ namespace OIC if (result != OC_STACK_OK) { OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "doOwnershipTransfer is failed"); - throw ESPlatformException(result); + return ESResult::ES_ERROR; } + return ESResult::ES_OK; } void EnrolleeSecurity::removeDeviceWithUuidCB(OC::PMResultList_t *result, int hasError) @@ -250,7 +276,7 @@ namespace OIC if (hasError) { OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Error in removeDeviceWithUuid operation!"); - throw ESException("removeDeviceWithUuid Error"); + removeDeviceResult = false; } else @@ -265,8 +291,9 @@ namespace OIC OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Result is = %d for device %s", result->at(i).res, uuid.c_str()); } - performOwnershipTransfer(); + removeDeviceResult = true; } + m_cond.notify_all(); } bool EnrolleeSecurity::isOwnedDeviceRegisteredInSVRDB() @@ -308,9 +335,11 @@ namespace OIC }; #if defined(__WITH_DTLS__) && defined(__WITH_TLS__) - void EnrolleeSecurity::provisionSecurityForCloudServer( + ESResult EnrolleeSecurity::provisionSecurityForCloudServer( std::string cloudUuid, int credId) { + ESResult res = ESResult::ES_ERROR; + // Need to discover Owned device in a given network, again OC::DeviceList_t pOwnedDevList; std::shared_ptr< OC::OCSecureResource > ownedDevice = NULL; @@ -324,8 +353,8 @@ namespace OIC if (result != OC_STACK_OK) { OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Owned Discovery failed."); - //Throw exception - throw ESPlatformException(result); + res = ESResult::ES_SECURE_RESOURCE_DISCOVERY_FAILURE; + return res; } else if (pOwnedDevList.size()) { @@ -336,13 +365,15 @@ namespace OIC if (!ownedDevice) { OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Not found matched owned device."); - throw ESException("Not found matched owned device."); + res = ESResult::ES_SECURE_RESOURCE_DISCOVERY_FAILURE; + return res; } } else { OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Not found owned devices."); - throw ESException("Not found owned devices."); + res = ESResult::ES_SECURE_RESOURCE_DISCOVERY_FAILURE; + return res; } if(cloudUuid.empty()) @@ -350,10 +381,14 @@ namespace OIC OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "ACL provisioning is skipped due to empty UUID of cloud server"); } - else if(performACLProvisioningForCloudServer(ownedDevice, cloudUuid) != ESResult::ES_OK) + else { - OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "error performACLProvisioningForCloudServer"); - throw ESException("error performACLProvisioningForCloudServer"); + res = performACLProvisioningForCloudServer(ownedDevice, cloudUuid); + if(res != ESResult::ES_OK) + { + OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "error performACLProvisioningForCloudServer"); + return res; + } } if(credId < 1) @@ -361,17 +396,23 @@ namespace OIC OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Cert. provisioning is skipped due to wrong cred ID (<1)"); } - else if(performCertProvisioningForCloudServer(ownedDevice, credId) != ESResult::ES_OK) + else { - OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "error performCertProvisioningForCloudServer"); - throw ESException("error performCertProvisioningForCloudServer"); + res = performCertProvisioningForCloudServer(ownedDevice, credId); + if(res != ESResult::ES_OK) + { + OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "error performCertProvisioningForCloudServer"); + return res; + } } + + return res; } ESResult EnrolleeSecurity::performCertProvisioningForCloudServer( std::shared_ptr< OC::OCSecureResource > ownedDevice, int credId) { - ESResult res = ESResult::ES_ERROR; + ESResult res = ESResult::ES_CERT_PROVISIONING_FAILURE; if(!ownedDevice) { @@ -391,7 +432,7 @@ namespace OIC } std::unique_lock lck(m_mtx); - m_cond.wait_for(lck, std::chrono::seconds(ES_SEC_DISCOVERY_TIMEOUT)); + m_cond.wait(lck); if(certResult) { @@ -404,18 +445,13 @@ namespace OIC ESResult EnrolleeSecurity::performACLProvisioningForCloudServer( std::shared_ptr< OC::OCSecureResource > ownedDevice, std::string& cloudUuid) { - ESResult res = ESResult::ES_ERROR; + ESResult res = ESResult::ES_ACL_PROVISIONING_FAILURE; if(!ownedDevice) { OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Invalid param"); return res; } - if(cloudUuid.empty()) - { - OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "Invalid param"); - return res; - } OicUuid_t uuid; ConvertStrToUuid(cloudUuid.c_str(), &uuid); @@ -440,7 +476,7 @@ namespace OIC } std::unique_lock lck(m_mtx); - m_cond.wait_for(lck, std::chrono::seconds(ES_SEC_DISCOVERY_TIMEOUT)); + m_cond.wait(lck); if(aclResult) { diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h index 644eddd..a713ff3 100755 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h @@ -56,7 +56,7 @@ namespace OIC const SecurityProvStatusCb securityProvStatusCb, const SecurityPinCb securityPinCb, const SecProvisioningDbPathCb secProvisioningDbPathCb); - void provisionOwnership(); + ESResult provisionOwnership(); std::string getUUID() const; private: @@ -68,13 +68,15 @@ namespace OIC std::mutex m_mtx; std::condition_variable m_cond; - std::atomic aclResult; - std::atomic certResult; + std::atomic OTMResult; + std::atomic removeDeviceResult; + std::atomic aclResult; + std::atomic certResult; std::shared_ptr< OC::OCSecureResource > m_securedResource; std::shared_ptr< OC::OCSecureResource > findEnrolleeSecurityResource( OC::DeviceList_t &list); - void performOwnershipTransfer(); + ESResult performOwnershipTransfer(); bool isOwnedDeviceRegisteredInSVRDB(); void removeDeviceWithUuidCB(OC::PMResultList_t *result, int hasError); void ownershipTransferCb(OC::PMResultList_t *result, int hasError); @@ -83,7 +85,7 @@ namespace OIC #if defined(__WITH_DTLS__) && defined(__WITH_TLS__) public: - void provisionSecurityForCloudServer( + ESResult provisionSecurityForCloudServer( std::string cloudUuid, int credId); private: ESResult performCertProvisioningForCloudServer( diff --git a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp index 44d26d6..e23f2c2 100755 --- a/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp +++ b/service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp @@ -224,7 +224,7 @@ namespace OIC void RemoteEnrollee::provisionSecurity(const SecurityProvStatusCb callback) { #ifdef __WITH_DTLS__ - std::cout << __func__ << std::endl; + ESResult res = ESResult::ES_ERROR; if(!callback) { throw ESInvalidParameterException("Callback is empty"); @@ -241,22 +241,11 @@ namespace OIC m_enrolleeSecurity->registerCallbackHandler(securityProvStatusCb, m_securityPinCb, m_secProvisioningDbPathCb); - try - { - m_enrolleeSecurity->provisionOwnership(); - } - catch (const std::exception& e) - { - OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG, - "Exception for performOwnershipTransfer : %s", e.what()); - - OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Fail performOwnershipTransfer"); - std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = - std::make_shared< SecProvisioningStatus > - (m_enrolleeSecurity->getUUID(), ES_ERROR); - m_securityProvStatusCb(securityProvisioningStatus); - return ; - } + res = m_enrolleeSecurity->provisionOwnership(); + + std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = + std::make_shared< SecProvisioningStatus >(m_enrolleeSecurity->getUUID(), res); + m_securityProvStatusCb(securityProvisioningStatus); #else OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured."); if(!callback) @@ -359,11 +348,6 @@ namespace OIC if(m_ocResource != nullptr) { m_cloudResource = std::make_shared(m_ocResource); - - std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared< - CloudPropProvisioningStatus >(ESResult::ES_FOUND_ENROLLEE); - - m_cloudPropProvStatusCb(provStatus); } else { @@ -402,37 +386,31 @@ namespace OIC "Exception caught in provisionCloudProperties = %s", e.what()); std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared< - CloudPropProvisioningStatus >(ESResult::ES_NOT_FOUND_ENROLLEE); + CloudPropProvisioningStatus >(ESResult::ES_ENROLLEE_DISCOVERY_FAILURE); m_cloudPropProvStatusCb(provStatus); return; } #if defined(__WITH_DTLS__) && defined(__WITH_TLS__) - try + if(!(cloudProp.getCloudID().empty() && cloudProp.getCredID() <= 0)) { - if(!(cloudProp.getCloudID().empty() && cloudProp.getCredID() <= 0)) - { - m_enrolleeSecurity = std::make_shared (m_ocResource, ""); + ESResult res = ESResult::ES_ERROR; + m_enrolleeSecurity = std::make_shared (m_ocResource, ""); - m_enrolleeSecurity->provisionSecurityForCloudServer(cloudProp.getCloudID(), - cloudProp.getCredID()); - } - else + res = m_enrolleeSecurity->provisionSecurityForCloudServer(cloudProp.getCloudID(), + cloudProp.getCredID()); + + if(res != ESResult::ES_OK) { - OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "ACL and Cert. provisioning are skipped."); + m_cloudResource = nullptr; + std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared< + CloudPropProvisioningStatus >(res); + m_cloudPropProvStatusCb(provStatus); + return; } } - - catch (const std::exception& e) + else { - OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG, - "Exception caught in provisionCloudProperties = %s", e.what()); - - m_cloudResource = nullptr; - - std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared< - CloudPropProvisioningStatus >(ESResult::ES_ERROR); - m_cloudPropProvStatusCb(provStatus); - return; + OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "ACL and Cert. provisioning are skipped."); } #endif //defined(__WITH_DTLS__) && defined(__WITH_TLS__) diff --git a/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp b/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp index 4cc18ab..cb1d8ee 100755 --- a/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp +++ b/service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp @@ -462,8 +462,7 @@ TEST_F(ProvisionCloudPropertiesTest, ProvisionCloudPropertiesSucceed) mocks.OnCallFunc(cloudPropProvStatusCb).Do( [& cntForReceivedCallbackWithSuccess](std::shared_ptr< CloudPropProvisioningStatus > status) { - // Will called twice - if(status->getESResult() == ES_OK || status->getESResult() == ES_FOUND_ENROLLEE) + if(status->getESResult() == ES_OK) { cntForReceivedCallbackWithSuccess++; } @@ -474,7 +473,7 @@ TEST_F(ProvisionCloudPropertiesTest, ProvisionCloudPropertiesSucceed) std::unique_lock< std::mutex > lock{ mutexForCondition }; responseCon.wait_for(lock, g_waitForResponse); - EXPECT_EQ(cntForReceivedCallbackWithSuccess, 2); + EXPECT_EQ(cntForReceivedCallbackWithSuccess, 1); ESTerminateEnrollee(); } diff --git a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp index 2f55cc2..144685d 100755 --- a/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp +++ b/service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp @@ -231,12 +231,15 @@ void cloudProvisioningStatusCallback(std::shared_ptr< CloudPropProvisioningStatu case ES_OK: cout << "Cloud Provisioning is success." << endl; break; - case ES_FOUND_ENROLLEE: - cout << "Enrollee is found in a given network." << endl; - break; - case ES_NOT_FOUND_ENROLLEE: + case ES_SECURE_RESOURCE_DISCOVERY_FAILURE: cout << "Enrollee is not found in a given network." << endl; break; + case ES_ACL_PROVISIONING_FAILURE: + cout << "ACL provisioning is failed." << endl; + break; + case ES_CERT_PROVISIONING_FAILURE: + cout << "CERT provisioning is failed." << endl; + break; default: cout << "Cloud Provisioning is failed." << endl; break; @@ -399,7 +402,7 @@ int main() PlatformConfig config { - OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos, &ps + OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::HighQos, &ps }; OCPlatform::Configure(config);