Use SafeBuffer in C++ api. Rename SafeBuffer to RawBuffer.
[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 std::string &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 std::string &oldPassword,
62         const std::string &newPassword);
63
64     RawBuffer resetUserPassword(
65         uid_t user,
66         const std::string &newPassword);
67
68     RawBuffer saveData(
69         Credentials &cred,
70         int commandId,
71         DBDataType dataType,
72         const Alias &alias,
73         const RawBuffer &key,
74         const PolicySerializable &policy);
75
76     RawBuffer removeData(
77         Credentials &cred,
78         int commandId,
79         DBDataType dataType,
80         const Alias &alias);
81
82     RawBuffer getData(
83         Credentials &cred,
84         int commandId,
85         DBDataType dataType,
86         const Alias &alias,
87         const std::string &password);
88
89     RawBuffer getDataList(
90         Credentials &cred,
91         int commandId,
92         DBDataType dataType);
93
94     RawBuffer createKeyPairRSA(
95         Credentials &cred,
96         int commandId,
97         int size,
98         const Alias &aliasPrivate,
99         const Alias &alaisPublic,
100         const PolicySerializable &policyPrivate,
101         const PolicySerializable &policyPublic);
102
103     RawBuffer createKeyPairECDSA(
104         Credentials &cred,
105         int commandId,
106         int type,
107         const Alias &aliasPrivate,
108         const Alias &aliasPublic,
109         const PolicySerializable &policyPrivate,
110         const PolicySerializable &policyPublic);
111
112     RawBuffer getCertificateChain(
113         Credentials &cred,
114         int commandId,
115         const RawBuffer &certificate,
116         const RawBufferVector &untrustedCertificates);
117
118     RawBuffer getCertificateChain(
119         Credentials &cred,
120         int commandId,
121         const RawBuffer &certificate,
122         const AliasVector &aliasVector);
123
124     RawBuffer  createSignature(
125         Credentials &cred,
126         int commandId,
127         const Alias &privateKeyAlias,
128         const std::string &password,           // password for private_key
129         const RawBuffer &message,
130         const HashAlgorithm hash,
131         const RSAPaddingAlgorithm padding);
132
133     RawBuffer verifySignature(
134         Credentials &cred,
135         int commandId,
136         const Alias &publicKeyOrCertAlias,
137         const std::string &password,           // password for public_key (optional)
138         const RawBuffer &message,
139         const RawBuffer &signature,
140         const HashAlgorithm hash,
141         const RSAPaddingAlgorithm padding);
142
143 private:
144
145     int saveDataHelper(
146         Credentials &cred,
147         DBDataType dataType,
148         const Alias &alias,
149         const RawBuffer &key,
150         const PolicySerializable &policy);
151
152     int getDataHelper(
153         Credentials &cred,
154         DBDataType dataType,
155         const Alias &alias,
156         const std::string &password,
157         DBRow &row);
158
159     int createKeyPairRSAHelper(
160         Credentials &cred,
161         int size,
162         const Alias &aliasPrivate,
163         const Alias &aliasPublic,
164         const PolicySerializable &policyPrivate,
165         const PolicySerializable &policyPublic);
166
167     int createKeyPairECDSAHelper(
168         Credentials &cred,
169         int type,
170         const Alias &aliasPrivate,
171         const Alias &aliasPublic,
172         const PolicySerializable &policyPrivate,
173         const PolicySerializable &policyPublic);
174
175     int getKeyHelper(
176         Credentials &cred,
177         const Alias &publicKeyOrCertAlias,
178         const std::string &password,           // password for public_key (optional)
179         const GenericKey &genericKey);
180
181     std::map<uid_t, UserData> m_userDataMap;
182     CertificateStore m_certStore;
183 };
184
185 } // namespace CKM
186