Class naming scheme re-factoring: move towards better consistency.
[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 createKeyPairRSA(
97         Credentials &cred,
98         int commandId,
99         int size,
100         const Alias &aliasPrivate,
101         const Alias &alaisPublic,
102         const PolicySerializable &policyPrivate,
103         const PolicySerializable &policyPublic);
104
105     RawBuffer createKeyPairECDSA(
106         Credentials &cred,
107         int commandId,
108         int type,
109         const Alias &aliasPrivate,
110         const Alias &aliasPublic,
111         const PolicySerializable &policyPrivate,
112         const PolicySerializable &policyPublic);
113
114     RawBuffer getCertificateChain(
115         Credentials &cred,
116         int commandId,
117         const RawBuffer &certificate,
118         const RawBufferVector &untrustedCertificates);
119
120     RawBuffer getCertificateChain(
121         Credentials &cred,
122         int commandId,
123         const RawBuffer &certificate,
124         const AliasVector &aliasVector);
125
126     RawBuffer  createSignature(
127         Credentials &cred,
128         int commandId,
129         const Alias &privateKeyAlias,
130         const Password &password,           // password for private_key
131         const RawBuffer &message,
132         const HashAlgorithm hash,
133         const RSAPaddingAlgorithm padding);
134
135     RawBuffer verifySignature(
136         Credentials &cred,
137         int commandId,
138         const Alias &publicKeyOrCertAlias,
139         const Password &password,           // password for public_key (optional)
140         const RawBuffer &message,
141         const RawBuffer &signature,
142         const HashAlgorithm hash,
143         const RSAPaddingAlgorithm padding);
144
145 private:
146
147     int saveDataHelper(
148         Credentials &cred,
149         DBDataType dataType,
150         const Alias &alias,
151         const RawBuffer &key,
152         const PolicySerializable &policy);
153
154     int getDataHelper(
155         Credentials &cred,
156         DBDataType dataType,
157         const Alias &alias,
158         const Password &password,
159         DBRow &row);
160
161     int createKeyPairRSAHelper(
162         Credentials &cred,
163         int size,
164         const Alias &aliasPrivate,
165         const Alias &aliasPublic,
166         const PolicySerializable &policyPrivate,
167         const PolicySerializable &policyPublic);
168
169     int createKeyPairECDSAHelper(
170         Credentials &cred,
171         int type,
172         const Alias &aliasPrivate,
173         const Alias &aliasPublic,
174         const PolicySerializable &policyPrivate,
175         const PolicySerializable &policyPublic);
176
177     int getKeyHelper(
178         Credentials &cred,
179         const Alias &publicKeyOrCertAlias,
180         const Password &password,           // password for public_key (optional)
181         const KeyImpl &genericKey);
182
183     std::map<uid_t, UserData> m_userDataMap;
184     CertificateStore m_certStore;
185 };
186
187 } // namespace CKM
188