Add access API to the control service.
[platform/core/security/key-manager.git] / src / manager / service / ckm-logic.h
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  *
16  *
17  * @file        ckm-logic.h
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       Sample service implementation.
21  */
22 #pragma once
23
24 #include <string>
25 #include <vector>
26
27 #include <message-buffer.h>
28 #include <protocols.h>
29 #include <ckm/ckm-type.h>
30 #include <connection-info.h>
31 #include <db-crypto.h>
32 #include <key-provider.h>
33 #include <crypto-logic.h>
34 #include <certificate-store.h>
35
36 namespace CKM {
37
38 struct UserData {
39     KeyProvider    keyProvider;
40     DBCrypto       database;
41     CryptoLogic    crypto;
42 };
43
44 class CKMLogic {
45 public:
46     CKMLogic();
47     CKMLogic(const CKMLogic &) = delete;
48     CKMLogic(CKMLogic &&) = delete;
49     CKMLogic& operator=(const CKMLogic &) = delete;
50     CKMLogic& operator=(CKMLogic &&) = delete;
51     virtual ~CKMLogic();
52
53     RawBuffer unlockUserKey(uid_t user, const Password &password);
54
55     RawBuffer lockUserKey(uid_t user);
56
57     RawBuffer removeUserData(uid_t user);
58
59     RawBuffer changeUserPassword(
60         uid_t user,
61         const Password &oldPassword,
62         const Password &newPassword);
63
64     RawBuffer resetUserPassword(
65         uid_t user,
66         const Password &newPassword);
67
68     RawBuffer removeApplicationData(const std::string &smackLabel);
69
70     RawBuffer saveData(
71         Credentials &cred,
72         int commandId,
73         DBDataType dataType,
74         const Alias &alias,
75         const RawBuffer &key,
76         const PolicySerializable &policy);
77
78     RawBuffer removeData(
79         Credentials &cred,
80         int commandId,
81         DBDataType dataType,
82         const Alias &alias);
83
84     RawBuffer getData(
85         Credentials &cred,
86         int commandId,
87         DBDataType dataType,
88         const Alias &alias,
89         const Password &password);
90
91     RawBuffer getDataList(
92         Credentials &cred,
93         int commandId,
94         DBDataType dataType);
95
96     RawBuffer createKeyPair(
97         Credentials &cred,
98         LogicCommand protocol_cmd,
99         int commandId,
100         const int additional_param,
101         const Alias &aliasPrivate,
102         const Alias &alaisPublic,
103         const PolicySerializable &policyPrivate,
104         const PolicySerializable &policyPublic);
105
106     RawBuffer getCertificateChain(
107         Credentials &cred,
108         int commandId,
109         const RawBuffer &certificate,
110         const RawBufferVector &untrustedCertificates);
111
112     RawBuffer getCertificateChain(
113         Credentials &cred,
114         int commandId,
115         const RawBuffer &certificate,
116         const AliasVector &aliasVector);
117
118     RawBuffer  createSignature(
119         Credentials &cred,
120         int commandId,
121         const Alias &privateKeyAlias,
122         const Password &password,           // password for private_key
123         const RawBuffer &message,
124         const HashAlgorithm hash,
125         const RSAPaddingAlgorithm padding);
126
127     RawBuffer verifySignature(
128         Credentials &cred,
129         int commandId,
130         const Alias &publicKeyOrCertAlias,
131         const Password &password,           // password for public_key (optional)
132         const RawBuffer &message,
133         const RawBuffer &signature,
134         const HashAlgorithm hash,
135         const RSAPaddingAlgorithm padding);
136
137     RawBuffer setCCModeStatus(CCModeState mode_status);
138
139     RawBuffer allowAccess(
140         Credentials &cred,
141         int command,
142         int msgID,
143         const Alias &item_alias,
144         const std::string &accessor_label,
145         const AccessRight req_rights);
146
147     RawBuffer denyAccess(
148         Credentials &cred,
149         int command,
150         int msgID,
151         const Alias &item_alias,
152         const std::string &accessor_label);
153
154 private:
155
156     int saveDataHelper(
157         Credentials &cred,
158         DBDataType dataType,
159         const Alias &alias,
160         const RawBuffer &key,
161         const PolicySerializable &policy);
162
163     int getDataHelper(
164         Credentials &cred,
165         DBDataType dataType,
166         const Alias &alias,
167         const Password &password,
168         DBRow &row);
169
170     int createKeyPairHelper(
171         Credentials &cred,
172         const KeyType key_type,
173         const int additional_param,
174         const Alias &aliasPrivate,
175         const Alias &aliasPublic,
176         const PolicySerializable &policyPrivate,
177         const PolicySerializable &policyPublic);
178
179     int getKeyHelper(
180         Credentials &cred,
181         const Alias &publicKeyOrCertAlias,
182         const Password &password,           // password for public_key (optional)
183         const KeyImpl &genericKey);
184
185     std::map<uid_t, UserData> m_userDataMap;
186     CertificateStore m_certStore;
187     CCModeState cc_mode_status;
188 };
189
190 } // namespace CKM
191