Merge "Update deprecated libprivilege-control API functions." into tizen
[platform/framework/native/appfw.git] / src / security / inc / FSecCert_CertMgrMessages.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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 /**
18  * @file        FSecCert_CertMgrMessages.h
19  * @brief       This is the header file for the CertMgr IPC message types.
20  *
21  * This is the header file for the CertMgr IPC message types.
22  */
23
24 #include <ipc/ipc_message_macros.h>
25 #include <FIo_IpcCommonParamTraits.h>
26 #include <FIo_IpcMessageStart.h>
27 #include "FSecCert_CertTypes.h"
28
29 #define IPC_MESSAGE_START CertMgrServiceStart
30
31 #ifndef _FSEC_CERT_INTERNAL_CERT_MANAGER_MESSAGES_H_
32 #define _FSEC_CERT_INTERNAL_CERT_MANAGER_MESSAGES_H_
33
34 namespace IPC
35 {
36 template< >
37 struct ParamTraits< Tizen::Security::Cert::_CertFieldInfos >
38 {
39         typedef Tizen::Security::Cert::_CertFieldInfos param_type;
40         static void Write(Message* pMesg, const param_type& params)
41         {
42                 pMesg->WriteInt(params.certType);
43                 pMesg->WriteInt(params.certFileId);
44                 pMesg->WriteBytes(static_cast< const void* >(params.serialNo), Tizen::Security::Cert::_MAX_SERIAL_NUMBER_SIZE + 1);
45                 pMesg->WriteBytes(static_cast< const void* >(params.sigAlgorithm), Tizen::Security::Cert::_MAX_CERT_ALGORITHM_SIZE + 1);
46                 pMesg->WriteBytes(static_cast< const void* >(params.validityFrom), Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
47                 pMesg->WriteBytes(static_cast< const void* >(params.validityTo), Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
48                 pMesg->WriteBytes(static_cast< const void* >(params.subjectName), Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
49                 pMesg->WriteBytes(static_cast< const void* >(params.issuerName), Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
50                 pMesg->WriteBytes(static_cast< const void* >(params.fingerPrint), Tizen::Security::Cert::_MAX_CERT_FINGERPRINT_SIZE + 1);
51                 pMesg->WriteInt(params.fingerPrintLen);
52                 pMesg->WriteBytes(static_cast< const void* >(params.publicKey), Tizen::Security::Cert::_MAX_CERT_PUBLIC_KEY_SIZE + 1);
53                 pMesg->WriteBytes(static_cast< const void* >(params.certTypeFormat), Tizen::Security::Cert::_MAX_CERT_TYPE_SIZE + 1);
54                 pMesg->WriteInt(params.certVersion);
55                 pMesg->WriteBytes(static_cast< const void* >(params.certTitle), Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
56                 pMesg->WriteBytes(static_cast< const void* >(params.certSubTitle), Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
57
58         }
59         static bool Read(const Message* pMesg, void** ppIter, param_type* pParam)
60         {
61                 const char* pBuffer = null;
62                 int value = 0;
63
64                 pMesg->ReadInt(ppIter, &value);
65                 pParam->certType = static_cast< Tizen::Security::Cert::_CaCertType >(value);
66
67                 pMesg->ReadInt(ppIter, &value);
68                 pParam->certFileId = value;
69
70                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_SERIAL_NUMBER_SIZE + 1);
71                 memcpy(pParam->serialNo, pBuffer, Tizen::Security::Cert::_MAX_SERIAL_NUMBER_SIZE + 1);
72
73                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_ALGORITHM_SIZE + 1);
74                 memcpy(pParam->sigAlgorithm, pBuffer, Tizen::Security::Cert::_MAX_CERT_ALGORITHM_SIZE + 1);
75
76                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
77                 memcpy(pParam->validityFrom, pBuffer, Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
78
79                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
80                 memcpy(pParam->validityTo, pBuffer, Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
81
82                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
83                 memcpy(pParam->subjectName, pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
84
85                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
86                 memcpy(pParam->issuerName, pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
87
88                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_FINGERPRINT_SIZE + 1);
89                 memcpy(pParam->fingerPrint, pBuffer, Tizen::Security::Cert::_MAX_CERT_FINGERPRINT_SIZE + 1);
90
91                 pMesg->ReadInt(ppIter, &value);
92                 pParam->fingerPrintLen = value;
93
94                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_PUBLIC_KEY_SIZE + 1);
95                 memcpy(pParam->publicKey, pBuffer, Tizen::Security::Cert::_MAX_CERT_PUBLIC_KEY_SIZE + 1);
96
97                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_TYPE_SIZE + 1);
98                 memcpy(pParam->certTypeFormat, pBuffer, Tizen::Security::Cert::_MAX_CERT_TYPE_SIZE + 1);
99
100                 pMesg->ReadInt(ppIter, &value);
101                 pParam->certVersion = value;
102
103                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
104                 memcpy(pParam->certTitle, pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
105
106                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
107                 memcpy(pParam->certSubTitle, pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
108
109                 return true;
110         }
111         static void Log(const param_type& p, std::string* l)
112         {
113
114         }
115 };
116
117 template< >
118 struct ParamTraits< Tizen::Security::Cert::_CertificateListInfo >
119 {
120         typedef Tizen::Security::Cert::_CertificateListInfo param_type;
121         static void Write(Message* pMesg, const param_type& params)
122         {
123                 int count = 0;
124                 int index = 0;
125
126                 param_type* pTemp = const_cast< param_type* >(&params);
127
128                 while (pTemp)
129                 {
130                         pTemp = pTemp->pNext;
131                         count++;
132                 }
133
134                 pMesg->WriteInt(count);
135
136                 pTemp = const_cast< param_type* >(&params);
137                 for (index = 0; index < count; index++)
138                 {
139                         pMesg->WriteInt(pTemp->certFileId);
140                         pMesg->WriteInt(pTemp->format);
141                         pMesg->WriteInt(pTemp->certType);
142                         pMesg->WriteInt(pTemp->length);
143                         pMesg->WriteInt(pTemp->priKeyLen);
144                         pMesg->WriteBytes(static_cast< const void* >(pTemp->certificate), Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
145                         pMesg->WriteBytes(static_cast< const void* >(pTemp->privatekey), Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
146
147                         pTemp = pTemp->pNext;
148
149
150                 }
151
152         }
153         static bool Read(const Message* pMesg, void** ppIter, param_type* pParam)
154         {
155                 const char* pBuffer = null;
156                 int value = 0;
157                 int count = 0;
158                 int index = 1;
159                 param_type* pCurrentNode = pParam;
160                 param_type* pNewNode = null;
161
162                 pMesg->ReadInt(ppIter, &count);
163
164                 if (count <= 0)
165                 {
166                         return true;
167                 }
168
169                 pMesg->ReadInt(ppIter, &value);
170                 pCurrentNode->certFileId = value;
171
172                 pMesg->ReadInt(ppIter, &value);
173                 pCurrentNode->format = static_cast< Tizen::Security::Cert::_CertFormat >(value);
174
175                 pMesg->ReadInt(ppIter, &value);
176                 pCurrentNode->certType = static_cast< Tizen::Security::Cert::_CaCertType >(value);
177
178                 pMesg->ReadInt(ppIter, &value);
179                 pCurrentNode->length = value;
180
181                 pMesg->ReadInt(ppIter, &value);
182                 pCurrentNode->priKeyLen = value;
183
184                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
185                 memcpy(pCurrentNode->certificate, pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
186
187                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
188                 memcpy(pCurrentNode->privatekey, pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
189
190                 pCurrentNode->pNext = null;
191
192                 for (index = 1; index < count; index++)
193                 {
194                         pNewNode = new (std::nothrow) param_type();
195                         SysTryReturn(NID_SEC_CERT, pNewNode != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] failed to allocate memory");
196
197                         pMesg->ReadInt(ppIter, &value);
198                         pNewNode->certFileId = value;
199
200                         pMesg->ReadInt(ppIter, &value);
201                         pNewNode->format = static_cast< Tizen::Security::Cert::_CertFormat >(value);
202
203                         pMesg->ReadInt(ppIter, &value);
204                         pNewNode->certType = static_cast< Tizen::Security::Cert::_CaCertType >(value);
205
206                         pMesg->ReadInt(ppIter, &value);
207                         pNewNode->length = value;
208
209                         pMesg->ReadInt(ppIter, &value);
210                         pNewNode->priKeyLen = value;
211
212                         pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
213                         memcpy(pNewNode->certificate, pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
214
215                         pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
216                         memcpy(pNewNode->privatekey, pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
217
218                         pNewNode->pNext = null;
219
220                         pCurrentNode->pNext = pNewNode;
221
222                         pCurrentNode = pNewNode;
223                 }
224
225                 return true;
226         }
227         static void Log(const param_type& p, std::string* l)
228         {
229
230         }
231 };
232
233 template< >
234 struct ParamTraits< Tizen::Security::Cert::_CertInfo >
235 {
236         typedef Tizen::Security::Cert::_CertInfo param_type;
237
238         static void Write(Message* pMesg, const param_type& params)
239         {
240                 pMesg->WriteInt(params.certId);
241                 pMesg->WriteInt(params.certFormat);
242                 pMesg->WriteInt(params.certType);
243                 pMesg->WriteInt(params.certLength);
244                 pMesg->WriteInt(params.privateKeyLen);
245                 pMesg->WriteBytes(static_cast< const void* >(params.certificate), Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
246                 pMesg->WriteBytes(static_cast< const void* >(params.privatekey), Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
247
248         }
249
250         static bool Read(const Message* pMesg, void** ppIter, param_type* pParam)
251         {
252                 const char* pBuffer = null;
253                 int value = 0;
254
255                 pMesg->ReadInt(ppIter, &value);
256                 pParam->certId = value;
257
258                 pMesg->ReadInt(ppIter, &value);
259                 pParam->certFormat = static_cast< Tizen::Security::Cert::_CertFormat >(value);
260
261                 pMesg->ReadInt(ppIter, &value);
262                 pParam->certType = static_cast< Tizen::Security::Cert::_CaCertType >(value);
263
264                 pMesg->ReadInt(ppIter, &value);
265                 pParam->certLength = value;
266
267                 pMesg->ReadInt(ppIter, &value);
268                 pParam->privateKeyLen = value;
269
270                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
271                 memcpy(pParam->certificate, pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
272
273                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
274                 memcpy(pParam->privatekey, pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
275
276                 return true;
277         }
278         static void Log(const param_type& p, std::string* l)
279         {
280
281         }
282 };
283 }
284
285 #endif // _FSEC_CERT_INTERNAL_CERT_MANAGER_MESSAGES_H_
286
287 IPC_SYNC_MESSAGE_CONTROL0_1(CertServer_GetName, result);
288 IPC_SYNC_MESSAGE_CONTROL1_1(CertServer_CloseCertificateStore, int, result);
289 IPC_SYNC_MESSAGE_CONTROL1_2(CertServer_OpenCertificateStoreByType, int, int, result);
290 IPC_SYNC_MESSAGE_CONTROL1_2(CertServer_GetCertificateCount, int, int, result);
291 IPC_SYNC_MESSAGE_CONTROL3_3(CertServer_GetNextCertificate, int, int, int, Tizen::Base::ByteBuffer, int , result);
292 IPC_SYNC_MESSAGE_CONTROL3_1(CertServer_InsertRootCa, int, Tizen::Io::_IpcBuffer, int, result);
293 IPC_SYNC_MESSAGE_CONTROL3_1(CertServer_UpdateRootCa, int, Tizen::Io::_IpcBuffer, Tizen::Io::_IpcBuffer, result);
294 IPC_SYNC_MESSAGE_CONTROL3_1(CertServer_RemoveRootCa, int, Tizen::Io::_IpcBuffer, int, result);
295 IPC_SYNC_MESSAGE_CONTROL1_1(CertServer_UninstallUserRootCertificateByCertId, int, result);
296 IPC_SYNC_MESSAGE_CONTROL4_1(CertServer_InsertCaCertificate, int, int, Tizen::Io::_IpcBuffer, long, result);
297 IPC_SYNC_MESSAGE_CONTROL3_1(CertServer_InsertUserCaCertificate, int, Tizen::Io::_IpcBuffer, int, result);
298 IPC_SYNC_MESSAGE_CONTROL1_1(CertServer_InstallUserRootCertificate, Tizen::Io::_IpcBuffer, result);
299 IPC_SYNC_MESSAGE_CONTROL4_1(CertServer_InsertUserCertChainPrivateKey, Tizen::Io::_IpcBuffer, int, Tizen::Io::_IpcBuffer, int, result);
300 IPC_SYNC_MESSAGE_CONTROL2_1(CertServer_InsertCertificateChainWithPrivateKey, Tizen::Io::_IpcBuffer, int, result);
301 IPC_SYNC_MESSAGE_CONTROL3_1(CertServer_InstallPkcs12Content, Tizen::Io::_IpcBuffer, Tizen::Io::_IpcBuffer, bool, result);
302 IPC_SYNC_MESSAGE_CONTROL1_1(CertServer_DeleteUserCertChainByCertId, int, result);
303 IPC_SYNC_MESSAGE_CONTROL4_2(CertServer_GetUserCertChainByIssuerAndSubjectNameN, Tizen::Io::_IpcBuffer, int, Tizen::Io::_IpcBuffer, int, Tizen::Security::Cert::_CertificateListInfo, result);
304 IPC_SYNC_MESSAGE_CONTROL2_2(CertServer_GetUserCertificateByCertIdN, int, int, Tizen::Security::Cert::_CertInfo, result);
305 IPC_SYNC_MESSAGE_CONTROL1_2(CertServer_GetUserCertFieldInfoByCertId, int, Tizen::Security::Cert::_CertFieldInfos, result);
306 IPC_SYNC_MESSAGE_CONTROL0_0(CertServer_RestoreRootCaIntegrity);