Merge remote-tracking branch 'origin/extended-easysetup'
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / EnrolleeSecurity.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef ENROLLEE_SECURITY_H_
22 #define ENROLLEE_SECURITY_H_
23
24 #include <functional>
25 #include <condition_variable>
26
27 #include "ESRichCommon.h"
28 #include "OCProvisioningManager.h"
29
30 namespace OIC
31 {
32     namespace Service
33     {
34 #define ENROLEE_SECURITY_TAG "ENROLEE_SECURITY"
35
36         class EnrolleeResource;
37         class OCSecureResource;
38
39         typedef std::vector<OCProvisionResult_t> PMResultList_t;
40
41         /**
42          * This class contains the methods needed for security  layer interaction.
43          *
44          * @see EnrolleeSecurity
45          */
46         class EnrolleeSecurity
47         {
48         public:
49             EnrolleeSecurity(std::shared_ptr< OC::OCResource > resource,
50             std::string secDbPath);
51             void registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
52                     SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb);
53             void performOwnershipTransfer();
54             ESResult performACLProvisioningForCloudServer(std::string cloudUuid);
55             std::string getUUID() const;
56
57         private:
58             std::shared_ptr< OC::OCResource > m_ocResource;
59             SecurityProvStatusCb m_securityProvStatusCb;
60             SecurityPinCb m_securityPinCb;
61             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
62             std::shared_ptr< OC::OCSecureResource > m_unownedDevice;
63
64             std::mutex m_mtx;
65             std::condition_variable m_cond;
66             bool aclResult;
67
68             std::shared_ptr< OC::OCSecureResource > m_securedResource;
69             std::shared_ptr< OC::OCSecureResource > getEnrollee(OC::DeviceList_t &list);
70             void ownershipTransferCb(OC::PMResultList_t *result, int hasError);
71             void convertUUIDToString(OicUuid_t uuid, std::string& uuidString);
72             void convertStringToUUID(OicUuid_t& uuid, std::string uuidString);
73             OicSecAcl_t* createAcl(OicUuid_t cloudUuid);
74
75             void ACLProvisioningCb(PMResultList_t *result, int hasError);
76         };
77     }
78 }
79
80 #endif /* ENROLLEE_SECURITY_H_*/
81