Revert "Update easysetup's security-provisioning logic."
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / src / 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 <atomic>
26 #include <condition_variable>
27
28 #include "ESRichCommon.h"
29 #include "OCProvisioningManager.h"
30
31 namespace OIC
32 {
33     namespace Service
34     {
35         #define ENROLEE_SECURITY_TAG "ENROLLEE_SECURITY"
36         #define UUID_SIZE (16)
37         #define UUID_STRING_SIZE (37)
38
39
40         class EnrolleeResource;
41         class OCSecureResource;
42
43         typedef std::vector<OCProvisionResult_t> PMResultList_t;
44
45         /**
46          * This class contains the methods needed for security  layer interaction.
47          *
48          * @see EnrolleeSecurity
49          */
50         class EnrolleeSecurity
51         {
52         public:
53             EnrolleeSecurity(std::shared_ptr< OC::OCResource > resource,
54             const std::string secDbPath);
55             void registerCallbackHandler(
56                 const SecurityProvStatusCb securityProvStatusCb,
57                 const SecurityPinCb securityPinCb,
58                 const SecProvisioningDbPathCb secProvisioningDbPathCb);
59             ESResult provisionOwnership();
60             std::string getUUID() const;
61
62         private:
63             std::shared_ptr< OC::OCResource > m_ocResource;
64             SecurityProvStatusCb m_securityProvStatusCb;
65             SecurityPinCb m_securityPinCb;
66             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
67             std::shared_ptr< OC::OCSecureResource > m_unownedDevice;
68
69             std::mutex m_mtx;
70             std::condition_variable m_cond;
71             std::atomic<bool> OTMResult;
72             std::atomic<bool> removeDeviceResult;
73             std::atomic<bool> aclResult;
74             std::atomic<bool> certResult;
75
76             std::shared_ptr< OC::OCSecureResource > m_securedResource;
77             std::shared_ptr< OC::OCSecureResource > findEnrolleeSecurityResource(
78                 OC::DeviceList_t &list);
79             ESResult performOwnershipTransfer();
80             bool isOwnedDeviceRegisteredInSVRDB();
81             void removeDeviceWithUuidCB(OC::PMResultList_t *result, int hasError);
82             void ownershipTransferCb(OC::PMResultList_t *result, int hasError);
83             void convertUUIDToString(const uint8_t uuid[UUID_SIZE],
84                                                 std::string& uuidString);
85
86 #if defined(__WITH_DTLS__) && defined(__WITH_TLS__)
87         public:
88             ESResult provisionSecurityForCloudServer(
89                 std::string cloudUuid, int credId);
90         private:
91             ESResult performCertProvisioningForCloudServer(
92                 std::shared_ptr< OC::OCSecureResource > ownedDevice,
93                 int credId);
94             ESResult performACLProvisioningForCloudServer(
95                 std::shared_ptr< OC::OCSecureResource > ownedDevice,
96                 std::string& cloudUuid);
97             OicSecAcl_t* createAcl(const OicUuid_t cloudUuid);
98             void ACLProvisioningCb(PMResultList_t *result, int hasError);
99             void CertProvisioningCb(PMResultList_t *result, int hasError);
100 #endif //defined(__WITH_DTLS__) && defined(__WITH_TLS__)
101         };
102     }
103 }
104
105 #endif /* ENROLLEE_SECURITY_H_*/
106