1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "RemoteEnrollee.h"
22 #include "EnrolleeResource.h"
23 #include "CloudResource.h"
24 #include "OCPlatform.h"
25 #include "ESException.h"
27 #include "OCResource.h"
28 #include "oic_string.h"
30 #include "EnrolleeSecurity.h"
32 #include "oic_malloc.h"
40 static const char ES_BASE_RES_URI[] = "/oic/res";
41 #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"
42 #define DISCOVERY_TIMEOUT 1
44 RemoteEnrollee::RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource)
46 m_ocResource = resource;
47 m_enrolleeResource = std::make_shared<EnrolleeResource>(m_ocResource);
48 m_securityProvStatusCb = nullptr;
49 m_getConfigurationStatusCb = nullptr;
50 m_securityPinCb = nullptr;
51 m_secProvisioningDbPathCb = nullptr;
52 m_devicePropProvStatusCb = nullptr;
53 m_cloudPropProvStatusCb = nullptr;
54 m_connectRequestStatusCb = nullptr;
56 m_deviceId = resource->sid();
59 void RemoteEnrollee::onSecurityStatusHandlerCallback(
60 const std::shared_ptr< SecProvisioningStatus > status,
61 std::weak_ptr<RemoteEnrollee> this_ptr)
63 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onSecurityStatusHandlerCallback");
64 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
67 Ptr->securityStatusHandler(status);
71 void RemoteEnrollee::securityStatusHandler(
72 const std::shared_ptr< SecProvisioningStatus > status) const
74 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "securityStatusHandlr IN");
75 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "UUID = %s", status->getDeviceUUID().c_str());
76 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "ESResult = %d", status->getESResult());
78 if(status->getESResult() == ES_OK)
80 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "Ownership transfer is successfully done.");
81 m_securityProvStatusCb(status);
85 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG, "Ownership transfer is failed.");
86 m_securityProvStatusCb(status);
88 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "securityStatusHandlr OUT");
91 ESOwnershipTransferData RemoteEnrollee::onSecurityStatusWithOptionHandlerCallback(
92 const std::shared_ptr< SecProvisioningStatus > status,
93 std::weak_ptr<RemoteEnrollee> this_ptr)
95 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onSecurityStatusWithOptionHandlerCallback");
96 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
99 return Ptr->securityStatusWithOptionHandler(status);
101 return ESOwnershipTransferData();
104 ESOwnershipTransferData RemoteEnrollee::securityStatusWithOptionHandler(
105 const std::shared_ptr< SecProvisioningStatus > status) const
107 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "securityStatusWithOptionHandler IN");
108 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "UUID = %s", status->getDeviceUUID().c_str());
109 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "ESResult = %d", status->getESResult());
111 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "securityStatusWithOptionHandler OUT");
112 return m_securityProvStatusCbWithOption(status);
115 void RemoteEnrollee::onGetStatusHandlerCallback(
116 const std::shared_ptr< GetEnrolleeStatus > status,
117 std::weak_ptr<RemoteEnrollee> this_ptr)
119 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onGetStatusHandlerCallback");
120 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
123 Ptr->getStatusHandler(status);
127 void RemoteEnrollee::getStatusHandler(
128 const std::shared_ptr< GetEnrolleeStatus > status) const
130 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatusHandler IN");
132 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatusHandler = %d",
133 status->getESResult());
134 m_getStatusCb(status);
136 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatusHandler OUT");
139 void RemoteEnrollee::onGetConfigurationStatusHandlerCallback(
140 const std::shared_ptr< GetConfigurationStatus > status,
141 std::weak_ptr<RemoteEnrollee> this_ptr)
143 OIC_LOG(INFO,ES_REMOTE_ENROLLEE_TAG,"onGetConfigurationStatusHandlerCallback");
144 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
147 Ptr->getConfigurationStatusHandler(status);
151 void RemoteEnrollee::getConfigurationStatusHandler (
152 const std::shared_ptr< GetConfigurationStatus > status) const
154 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getConfigurationStatusHandler IN");
156 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG,"GetConfigurationStatus = %d",
157 status->getESResult());
158 m_getConfigurationStatusCb(status);
160 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getConfigurationStatusHandler OUT");
163 void RemoteEnrollee::onDevicePropProvisioningStatusHandlerCallback(
164 const std::shared_ptr< DevicePropProvisioningStatus > status,
165 std::weak_ptr<RemoteEnrollee> this_ptr)
167 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onDevicePropProvisioningStatusHandlerCallback");
168 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
171 Ptr->devicePropProvisioningStatusHandler(status);
175 void RemoteEnrollee::devicePropProvisioningStatusHandler(
176 const std::shared_ptr< DevicePropProvisioningStatus > status) const
178 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "devicePropProvisioningStatusHandler IN");
180 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "DeviceProvStatus = %d", status->getESResult());
181 m_devicePropProvStatusCb(status);
183 if( m_ocResource.get() != nullptr &&
184 !(m_ocResource->connectivityType() & CT_ADAPTER_GATT_BTLE) &&
185 ES_OK == status->getESResult() )
187 // NOTE: Temporary patch
188 CAEndpoint_t endpoint = {
189 .adapter = CA_ADAPTER_IP,
190 .flags = CA_DEFAULT_FLAGS,
195 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
199 OCDevAddr address = m_ocResource->getDevAddr();
200 OICStrcpy(endpoint.addr, MAX_ADDR_STR_SIZE, address.addr);
201 endpoint.port = address.port;
203 OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "HOST = %s", endpoint.addr);
204 OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "PORT = %u", endpoint.port);
205 CAcloseSslSession(&endpoint);
208 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "devicePropProvisioningStatusHandler OUT");
211 void RemoteEnrollee::onCloudPropProvisioningStatusHandlerCallback(
212 const std::shared_ptr< CloudPropProvisioningStatus > status,
213 std::weak_ptr<RemoteEnrollee> this_ptr)
215 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onCloudPropProvisioningStatusHandlerCallback");
216 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
219 Ptr->cloudPropProvisioningStatusHandler(status);
223 void RemoteEnrollee::cloudPropProvisioningStatusHandler (
224 const std::shared_ptr< CloudPropProvisioningStatus > status) const
226 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "cloudPropProvisioningStatusHandler IN");
228 OIC_LOG_V(INFO,ES_REMOTE_ENROLLEE_TAG,"CloudProvStatus = %d",
229 status->getESResult());
230 m_cloudPropProvStatusCb(status);
232 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "cloudPropProvisioningStatusHandler OUT");
235 void RemoteEnrollee::onConnectRequestStatusHandlerCallback(
236 const std::shared_ptr< ConnectRequestStatus > status,
237 std::weak_ptr<RemoteEnrollee> this_ptr)
239 OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onConnectRequestStatusHandlerCallback");
240 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
243 Ptr->connectRequestStatusHandler(status);
247 void RemoteEnrollee::connectRequestStatusHandler(
248 const std::shared_ptr< ConnectRequestStatus > status) const
250 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connectRequestStatusHandler IN");
252 OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "RequestConnectStatus = %d", status->getESResult());
253 m_connectRequestStatusCb(status);
255 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connectRequestStatusHandler OUT");
258 void RemoteEnrollee::onDiscoveredCallback(const std::shared_ptr<OC::OCResource> resource,
259 std::weak_ptr<RemoteEnrollee> this_ptr)
261 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"onDiscoveredCallback()");
262 std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
265 Ptr->onDeviceDiscovered(resource);
269 void RemoteEnrollee::onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource)
271 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "onDeviceDiscovered IN");
277 if(!(resource->connectivityType() & CT_ADAPTER_TCP))
279 std::string resourceURI;
280 std::string hostAddress;
281 std::string hostDeviceID;
283 // Get the resource URI
284 resourceURI = resource->uri();
285 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG,
286 "URI of the resource: %s", resourceURI.c_str());
288 // Get the resource host address
289 hostAddress = resource->host();
290 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG,
291 "Host address of the resource: %s", hostAddress.c_str());
293 hostDeviceID = resource->sid();
294 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG,
295 "Host DeviceID of the resource: %s", hostDeviceID.c_str());
297 if(!m_deviceId.empty() && m_deviceId == hostDeviceID)
299 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "Find matched resource for cloud provisioning");
300 m_ocResource = resource;
301 m_discoveryResponse = true;
307 catch(std::exception& e)
309 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG,
310 "Exception in foundResource: %s", e.what());
313 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "onDeviceDiscovered OUT");
316 ESResult RemoteEnrollee::discoverResource()
318 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "discoverResource IN");
320 std::string query("");
321 query.append(ES_BASE_RES_URI);
322 query.append("?rt=");
323 query.append(OC_RSRVD_ES_RES_TYPE_EASYSETUP);
325 OIC_LOG_V(INFO, ES_REMOTE_ENROLLEE_TAG, "query = %s", query.c_str());
327 m_discoveryResponse = false;
329 onDeviceDiscoveredCb cb = std::bind(&RemoteEnrollee::onDiscoveredCallback,
330 std::placeholders::_1,
333 OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT, cb);
335 if (result != OCStackResult::OC_STACK_OK)
337 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG,
338 "Failed discoverResource");
342 std::unique_lock<std::mutex> lck(m_discoverymtx);
343 m_cond.wait_for(lck, std::chrono::seconds(DISCOVERY_TIMEOUT));
345 if (!m_discoveryResponse)
347 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG,
348 "Failed discoverResource because timeout");
355 void RemoteEnrollee::provisionSecurity(const SecurityProvStatusCb callback)
357 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionSecurity IN");
359 ESResult res = ESResult::ES_ERROR;
362 throw ESInvalidParameterException("Callback is empty");
364 m_securityProvStatusCb = callback;
366 SecurityProvStatusCb securityProvStatusCb = std::bind(
367 &RemoteEnrollee::onSecurityStatusHandlerCallback,
368 std::placeholders::_1,
370 //TODO : DBPath is passed empty as of now. Need to take dbpath from application.
371 if(!m_localEnrolleeSecurity.get())
373 m_localEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
376 res = m_localEnrolleeSecurity->provisionOwnership(NULL);
378 std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
379 std::make_shared< SecProvisioningStatus >(m_localEnrolleeSecurity->getUUID(), res);
380 securityProvStatusCb(securityProvisioningStatus);
382 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured built.");
386 throw ESInvalidParameterException("Callback is empty");
388 std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
389 std::make_shared< SecProvisioningStatus >
390 ("", ESResult::ES_SEC_OPERATION_IS_NOT_SUPPORTED);
391 callback(securityProvisioningStatus);
393 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionSecurity OUT");
396 void RemoteEnrollee::provisionSecurity(const SecurityProvStatusCbWithOption callback)
398 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionSecurity IN");
400 ESResult res = ESResult::ES_ERROR;
403 throw ESInvalidParameterException("Callback is empty");
405 m_securityProvStatusCbWithOption = callback;
407 SecurityProvStatusCbWithOption securityProvStatusCbWithOption = std::bind(
408 &RemoteEnrollee::onSecurityStatusWithOptionHandlerCallback,
409 std::placeholders::_1,
412 if(!m_localEnrolleeSecurity.get())
414 m_localEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
417 res = m_localEnrolleeSecurity->provisionOwnership(securityProvStatusCbWithOption);
419 std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
420 std::make_shared< SecProvisioningStatus >(m_localEnrolleeSecurity->getUUID(), res);
421 securityProvStatusCbWithOption(securityProvisioningStatus);
423 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured built.");
427 throw ESInvalidParameterException("Callback is empty");
429 std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
430 std::make_shared< SecProvisioningStatus >
431 ("", ESResult::ES_SEC_OPERATION_IS_NOT_SUPPORTED);
432 callback(securityProvisioningStatus);
434 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionSecurity OUT");
437 void RemoteEnrollee::getStatus(const GetStatusCb callback)
439 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatus IN");
443 throw ESInvalidParameterException("Callback is empty");
446 if (m_enrolleeResource == nullptr)
448 throw ESBadRequestException ("Device not created");
451 m_getStatusCb = callback;
453 GetStatusCb getStatusCb = std::bind(
454 &RemoteEnrollee::onGetStatusHandlerCallback,
455 std::placeholders::_1,
458 m_enrolleeResource->registerGetStatusCallback(getStatusCb);
459 m_enrolleeResource->getStatus();
461 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getStatus OUT");
464 void RemoteEnrollee::getConfiguration(const GetConfigurationStatusCb callback)
466 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getConfiguration IN");
470 throw ESInvalidParameterException("Callback is empty");
473 if (m_enrolleeResource == nullptr)
475 throw ESBadRequestException ("Device not created");
478 m_getConfigurationStatusCb = callback;
480 GetConfigurationStatusCb getConfigurationStatusCb = std::bind(
481 &RemoteEnrollee::onGetConfigurationStatusHandlerCallback,
482 std::placeholders::_1,
485 m_enrolleeResource->registerGetConfigurationStatusCallback(getConfigurationStatusCb);
486 m_enrolleeResource->getConfiguration();
488 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "getConfiguration OUT");
491 void RemoteEnrollee::provisionDeviceProperties(const DeviceProp& deviceProp,
492 const DevicePropProvStatusCb callback)
494 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionDeviceProperties IN");
498 throw ESInvalidParameterException("Callback is empty");
501 m_devicePropProvStatusCb = callback;
503 if (m_enrolleeResource == nullptr)
505 throw ESBadRequestException ("Device not created");
508 DevicePropProvStatusCb devicePropProvStatusCb = std::bind(
509 &RemoteEnrollee::onDevicePropProvisioningStatusHandlerCallback,
510 std::placeholders::_1,
513 m_enrolleeResource->registerDevicePropProvStatusCallback(devicePropProvStatusCb);
514 m_enrolleeResource->provisionProperties(deviceProp);
516 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionDeviceProperties OUT");
519 void RemoteEnrollee::initCloudResource()
521 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "initCloudResource IN");
523 ESResult result = ES_ERROR;
525 result = discoverResource();
527 if (result == ES_ERROR)
529 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG,
530 "Failed to create resource object using discoverResource");
531 throw ESBadRequestException ("Resource object not created");
536 if(m_ocResource != nullptr)
538 m_cloudResource = std::make_shared<CloudResource>(m_ocResource);
542 throw ESBadGetException ("Resource handle is invalid");
546 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "initCloudResource OUT");
549 void RemoteEnrollee::provisionCloudProperties(const CloudProp& cloudProp,
550 const CloudPropProvStatusCb callback)
552 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource IN");
554 provisionCloudProperties(NULL, cloudProp, callback);
556 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource OUT");
559 void RemoteEnrollee::provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource,
560 const CloudProp& cloudProp,
561 const CloudPropProvStatusCb callback)
563 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties IN");
567 throw ESInvalidParameterException("Callback is empty");
570 m_cloudPropProvStatusCb = callback;
572 if((cloudProp.getAuthCode().empty() && cloudProp.getAccessToken().empty()) ||
573 cloudProp.getAuthProvider().empty() ||
574 cloudProp.getCiServer().empty())
576 throw ESBadRequestException ("Invalid Cloud Provisiong Info.");
581 if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_EASYSETUP ||
582 resource->connectivityType() & CT_ADAPTER_TCP)
584 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG, "Given resource is not valid due to wrong rt or conntype");
585 throw ESInvalidParameterException("A given OCResource is wrong");
588 auto interfaces = resource->getResourceInterfaces();
589 bool isFound = false;
590 for(auto interface : interfaces)
592 if(interface.compare(BATCH_INTERFACE) == 0)
594 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "RemoteEnrollee object is succeessfully created");
595 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "HOST: %s", resource->host().c_str());
596 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "URI: %s", resource->uri().c_str());
597 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "SID: %s", resource->sid().c_str());
598 OIC_LOG_V(INFO_PRIVATE, ES_REMOTE_ENROLLEE_TAG, "CONNECTIVITY: %d", resource->connectivityType());
605 throw ESInvalidParameterException("A given OCResource has no batch interface");
617 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "Skip to find a provisioning resource");
618 m_ocResource = resource;
619 m_cloudResource = std::make_shared<CloudResource>(m_ocResource);
622 catch (const std::exception& e)
624 OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
625 "Exception caught in provisionCloudProperties = %s", e.what());
627 std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
628 CloudPropProvisioningStatus >(ESResult::ES_ENROLLEE_DISCOVERY_FAILURE);
629 m_cloudPropProvStatusCb(provStatus);
632 #if defined(__WITH_DTLS__) && defined(__WITH_TLS__)
633 if(!(cloudProp.getCloudID().empty() && cloudProp.getCredID() <= 0))
635 ESResult res = ESResult::ES_ERROR;
636 if(!m_cloudEnrolleeSecurity.get())
638 m_cloudEnrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_ocResource);
642 res = m_cloudEnrolleeSecurity->provisionSecurityForCloudServer(cloudProp.getCloudID(),
643 cloudProp.getCredID());
645 if(res != ESResult::ES_OK)
647 m_cloudResource = nullptr;
648 std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
649 CloudPropProvisioningStatus >(res);
650 m_cloudPropProvStatusCb(provStatus);
656 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "ACL and Cert. provisioning are skipped.");
658 #endif //defined(__WITH_DTLS__) && defined(__WITH_TLS__)
660 if (m_cloudResource == nullptr)
662 throw ESBadRequestException ("Cloud Resource not created");
665 CloudPropProvStatusCb cloudPropProvStatusCb = std::bind(
666 &RemoteEnrollee::onCloudPropProvisioningStatusHandlerCallback,
667 std::placeholders::_1,
670 m_cloudResource->registerCloudPropProvisioningStatusCallback(cloudPropProvStatusCb);
671 m_cloudResource->provisionProperties(cloudProp);
673 OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties OUT");
676 void RemoteEnrollee::requestToConnect(const std::vector<ES_CONNECT_TYPE> &connectTypes, const ConnectRequestStatusCb callback)
678 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connect IN");
682 throw ESInvalidParameterException("Callback is empty");
685 m_connectRequestStatusCb = callback;
687 ConnectRequestStatusCb connectRequestStatusCb = std::bind(
688 &RemoteEnrollee::onConnectRequestStatusHandlerCallback,
689 std::placeholders::_1,
692 m_enrolleeResource->registerConnectRequestStatusCallback(connectRequestStatusCb);
693 m_enrolleeResource->requestToConnect(connectTypes);
695 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "connect OUT");