+ OC::ResultCallBack selectMOTMethodCB = std::bind(
+ &EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+ std::placeholders::_1, std::placeholders::_2,
+ static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::selectMOTMethodCB,
+ this, std::placeholders::_1, std::placeholders::_2)),
+ shared_from_this());
+
+ OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "selectMOTMethod is called.");
+ if(OC_STACK_OK != m_securedResource->selectMOTMethod(
+ MOTData.getMOTMethod(),
+ selectMOTMethodCB))
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "selectMOTMethod API error");
+ res = ESResult:: ES_MOT_METHOD_SELECTION_FAILURE;
+ return res;
+ }
+
+ std::unique_lock<std::mutex> lck(m_mtx);
+ m_cond.wait(lck);
+
+ if(!motMethodProvResult)
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "selectMOTMethod is failed.");
+ res = ESResult:: ES_MOT_METHOD_SELECTION_FAILURE;
+ return res;
+ }
+
+ return ESResult::ES_OK;
+ }
+
+ ESResult EnrolleeSecurity::requestEnableMOTMode()
+ {
+ OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "requestEnableMOTMode IN");
+ ESResult res = ESResult:: ES_ERROR;
+
+ OC::ResultCallBack changeMOTMethodCB = std::bind(
+ &EnrolleeSecurity::onEnrolleeSecuritySafetyCB,
+ std::placeholders::_1, std::placeholders::_2,
+ static_cast<ESSecurityCb>(std::bind(&EnrolleeSecurity::changeMOTMethodCB,
+ this, std::placeholders::_1, std::placeholders::_2)),
+ shared_from_this());
+
+ if(OC_STACK_OK !=
+ m_securedResource->changeMOTMode(OIC_MULTIPLE_OWNER_ENABLE, changeMOTMethodCB))
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "changeMOTMode is failed.");
+ return ESResult:: ES_MOT_ENABLING_FAILURE;
+ }
+
+ std::unique_lock<std::mutex> lck(m_mtx);
+ m_cond.wait(lck);
+
+ if(!enableMOTModeResult)
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "requestEnableMOTMode is failed.");
+ res = ESResult:: ES_MOT_ENABLING_FAILURE;
+ return res;
+ }
+
+ return ESResult::ES_OK;
+ }
+
+ ESResult EnrolleeSecurity::provisionMOTConfig(const ESOwnershipTransferData& MOTData)
+ {
+ OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "provisionMOTConfig IN");
+ ESResult res = ESResult:: ES_ERROR;
+
+ if(!m_securedResource->isMOTEnabled())
+ {
+ res = requestEnableMOTMode();
+ if(res != ESResult::ES_OK)
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "requestEnableMOTMode is failed.");
+ return res;
+ }
+ }
+
+ if( OIC_PRECONFIG_PIN == MOTData.getMOTMethod() &&
+ !MOTData.getPreConfiguredPin().empty())
+ {
+ res = requestSetPreconfPinData(MOTData);
+
+ if(res != ESResult::ES_OK)
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "RequestSetPreconfPinData is failed.");
+ return res;
+ }
+ }
+ if(OIC_PRECONFIG_PIN == MOTData.getMOTMethod() ||
+ OIC_RANDOM_DEVICE_PIN == MOTData.getMOTMethod())
+ {
+ res = requestSetMOTMethod(MOTData);
+
+ if(res != ESResult::ES_OK)
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "RequestSetMOTMethod is failed.");
+ return res;
+ }
+ }
+ return res;
+ }
+#endif
+
+ void EnrolleeSecurity::ownershipTransferCb(OC::PMResultList_t *result, int hasError
+ , ESResult& res)
+ {
+ OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "ownershipTransferCb IN");
+
+ otmResult = false;
+
+ if (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 = OIC_OXM_COUNT;
+ 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;
+ }
+ }
+ else if(OC_STACK_COMM_ERROR == result->at(i).res)
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,
+ "OwnershipTransfer is failed with OC_STACK_COMM_ERROR");
+ res = ESResult::ES_COMMUNICATION_ERROR;
+ }
+ else if(OC_STACK_TIMEOUT == result->at(i).res)
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,
+ "OwnershipTransfer is failed with OC_STACK_TIMEOUT");
+ res = ESResult::ES_COMMUNICATION_ERROR;
+ }
+ else if(OC_STACK_GATEWAY_TIMEOUT== result->at(i).res)
+ {
+ OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,
+ "OwnershipTransfer is failed with OC_STACK_GATEWAY_TIMEOUT");
+ res = ESResult::ES_COMMUNICATION_ERROR;
+ }
+ }
+ }
+ OIC_LOG_V(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransfer is failed with ESResult(%d)", res);
+
+ otmResult = false;
+ }
+ else
+ {
+ 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_OK == result->at(i).res )
+ {
+ OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "OwnershipTransfer is succeeded");
+ OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Result is = %d", result->at(i).res);
+ OIC_LOG_V(INFO_PRIVATE, ENROLEE_SECURITY_TAG, "device uuid : %s", uuid.c_str());
+
+ otmResult = true;
+ }
+ else
+ {
+ OIC_LOG_V(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransfer is failed with code(%d)", hasError);
+ otmResult = false;
+ }
+ }
+ }
+ }
+
+ delete result;
+ m_cond.notify_all();
+ }
+
+ ESResult EnrolleeSecurity::discoverTargetSecureResource()
+ {
+ OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "discoverTargetSecureResource IN");
+