4a4e4c1ae227754f39d4751fede6fcff6345f150
[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
68             std::mutex m_mtx;
69             std::condition_variable m_cond;
70             std::atomic<bool> OTMResult;
71             std::atomic<bool> removeDeviceResult;
72             std::atomic<bool> aclResult;
73             std::atomic<bool> certResult;
74
75             std::shared_ptr< OC::OCSecureResource > m_securedResource;
76
77             ESResult performOwnershipTransfer();
78             bool isOwnedDeviceRegisteredInSVRDB();
79             void removeDeviceWithUuidCB(OC::PMResultList_t *result, int hasError);
80             void ownershipTransferCb(OC::PMResultList_t *result, int hasError);
81             void convertUUIDToString(const uint8_t uuid[UUID_SIZE],
82                                                 std::string& uuidString);
83
84 #if defined(__WITH_DTLS__) && defined(__WITH_TLS__)
85         public:
86             ESResult provisionSecurityForCloudServer(
87                 std::string cloudUuid, int credId);
88         private:
89             ESResult performCertProvisioningForCloudServer(
90                 std::shared_ptr< OC::OCSecureResource > ownedDevice,
91                 int credId);
92             ESResult performACLProvisioningForCloudServer(
93                 std::shared_ptr< OC::OCSecureResource > ownedDevice,
94                 std::string& cloudUuid);
95             OicSecAcl_t* createAcl(const OicUuid_t cloudUuid);
96             void ACLProvisioningCb(PMResultList_t *result, int hasError);
97             void CertProvisioningCb(PMResultList_t *result, int hasError);
98 #endif //defined(__WITH_DTLS__) && defined(__WITH_TLS__)
99         };
100     }
101 }
102
103 #endif /* ENROLLEE_SECURITY_H_*/
104