m_localEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
}
+#ifdef __TIZEN__
+ /* NOTE: Execute cloud resource discovery and secure resource discovery in
+ different thread to avoid blocking of main event loop of Tizen */
+ std::thread secProvThread = std::thread([this, securityProvStatusCb](void)
+ {
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"provisionSecurity - thread IN");
+ ESResult res = m_localEnrolleeSecurity->provisionOwnership(NULL);
+
+ std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+ std::make_shared< SecProvisioningStatus >(m_localEnrolleeSecurity->getUUID(), res);
+ securityProvStatusCb(securityProvisioningStatus);
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"provisionSecurity - thread OUT");
+ });
+
+ // TODO: Join thread
+ secProvThread.detach();
+#else
res = m_localEnrolleeSecurity->provisionOwnership(NULL);
std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
std::make_shared< SecProvisioningStatus >(m_localEnrolleeSecurity->getUUID(), res);
securityProvStatusCb(securityProvisioningStatus);
+#endif
#else
OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured built.");
{
m_localEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
}
+#ifdef __TIZEN__
+ /* NOTE: Execute cloud resource discovery and secure resource discovery in
+ different thread to avoid blocking of main event loop of Tizen */
+ std::thread secProvThread = std::thread([this, securityProvStatusCbWithOption](void)
+ {
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"provisionSecurity - thread IN");
+ ESResult res = m_localEnrolleeSecurity->provisionOwnership(securityProvStatusCbWithOption);
+ std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+ std::make_shared< SecProvisioningStatus >(m_localEnrolleeSecurity->getUUID(), res);
+ securityProvStatusCbWithOption(securityProvisioningStatus);
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"provisionSecurity - thread OUT");
+ });
+
+ // TODO: Join thread
+ secProvThread.detach();
+#else
res = m_localEnrolleeSecurity->provisionOwnership(securityProvStatusCbWithOption);
std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
std::make_shared< SecProvisioningStatus >(m_localEnrolleeSecurity->getUUID(), res);
securityProvStatusCbWithOption(securityProvisioningStatus);
+#endif
#else
OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured built.");
OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource OUT");
}
+#ifndef __TIZEN__
void RemoteEnrollee::provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource,
const CloudProp& cloudProp,
const CloudPropProvStatusCb callback)
OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties OUT");
}
+#else
+ void RemoteEnrollee::provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource,
+ const CloudProp& cloudProp,
+ const CloudPropProvStatusCb callback)
+ {
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties IN");
+
+ if(!callback)
+ {
+ throw ESInvalidParameterException("Callback is empty");
+ }
+
+ m_cloudPropProvStatusCb = callback;
+
+ if((cloudProp.getAuthCode().empty() && cloudProp.getAccessToken().empty()) ||
+ cloudProp.getAuthProvider().empty() ||
+ cloudProp.getCiServer().empty())
+ {
+ throw ESBadRequestException ("Invalid Cloud Provisiong Info.");
+ }
+
+ if(resource)
+ {
+ if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_EASYSETUP ||
+ resource->connectivityType() & CT_ADAPTER_TCP)
+ {
+ OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG, "Given resource is not valid due to wrong rt or conntype");
+ throw ESInvalidParameterException("A given OCResource is wrong");
+ }
+
+ auto interfaces = resource->getResourceInterfaces();
+ bool isFound = false;
+ for(auto interface : interfaces)
+ {
+ if(interface.compare(BATCH_INTERFACE) == 0)
+ {
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "RemoteEnrollee object is succeessfully created");
+ OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "HOST: %s", resource->host().c_str());
+ OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "URI: %s", resource->uri().c_str());
+ OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "SID: %s", resource->sid().c_str());
+ OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "CONNECTIVITY: %d", resource->connectivityType());
+ isFound = true;
+ }
+ }
+ if(!isFound)
+ {
+ throw ESInvalidParameterException("A given OCResource has no batch interface");
+ }
+
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "Skip to find a provisioning resource");
+ m_ocResource = resource;
+ m_cloudResource = std::make_shared<CloudResource>(m_ocResource);
+ if (m_cloudResource == nullptr)
+ {
+ throw ESBadRequestException ("Cloud Resource not created");
+ }
+ }
+
+ /* NOTE: Execute cloud resource discovery and secure resource discovery in
+ different thread to avoid blocking of main event loop of Tizen */
+ std::thread cloudProvThread = std::thread([this, cloudProp]()
+ {
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties - thread IN");
+ try
+ {
+ // Discover easy-setup resource only if it is not provided by API caller
+ if(!m_cloudResource)
+ {
+ initCloudResource();
+ if (m_cloudResource == nullptr)
+ {
+ OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG, "Cloud resource is not created");
+ std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
+ CloudPropProvisioningStatus >(ESResult::ES_ENROLLEE_DISCOVERY_FAILURE);
+ m_cloudPropProvStatusCb(provStatus);
+ return;
+ }
+ }
+ }
+ catch (const std::exception& e)
+ {
+ OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
+ "Exception caught in provisionCloudProperties = %s", e.what());
+
+ std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
+ CloudPropProvisioningStatus >(ESResult::ES_ENROLLEE_DISCOVERY_FAILURE);
+ m_cloudPropProvStatusCb(provStatus);
+ return;
+ }
+
+#if defined(__WITH_DTLS__) && defined(__WITH_TLS__)
+ if(!(cloudProp.getCloudID().empty() && cloudProp.getCredID() <= 0))
+ {
+ ESResult res = ESResult::ES_ERROR;
+ if(!m_cloudEnrolleeSecurity.get())
+ {
+ m_cloudEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
+ }
+
+
+ res = m_cloudEnrolleeSecurity->provisionSecurityForCloudServer(cloudProp.getCloudID(),
+ cloudProp.getCredID());
+
+ if(res != ESResult::ES_OK)
+ {
+ m_cloudResource = nullptr;
+ std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
+ CloudPropProvisioningStatus >(res);
+ m_cloudPropProvStatusCb(provStatus);
+ return;
+ }
+ }
+ else
+ {
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "ACL and Cert. provisioning are skipped.");
+ }
+#endif //defined(__WITH_DTLS__) && defined(__WITH_TLS__)
+
+ CloudPropProvStatusCb cloudPropProvStatusCb = std::bind(
+ &RemoteEnrollee::onCloudPropProvisioningStatusHandlerCallback,
+ std::placeholders::_1,
+ shared_from_this());
+
+ m_cloudResource->registerCloudPropProvisioningStatusCallback(cloudPropProvStatusCb);
+ m_cloudResource->provisionProperties(cloudProp);
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties - thread OUT");
+ });
+
+ // TODO: Join thread
+ cloudProvThread.detach();
+ OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties OUT");
+ }
+#endif
void RemoteEnrollee::requestToConnect(const std::vector<ES_CONNECT_TYPE> &connectTypes, const ConnectRequestStatusCb callback)
{
OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connect IN");