sync with tizen_2.0
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_CertMgrMessages.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FSecCert_CertMgrMessages.h
20  * @brief       This is the header file for the CertMgr IPC message types.
21  *
22  * This is the header file for the CertMgr IPC message types.
23  */
24
25 #include <ipc/ipc_message_macros.h>
26 #include <FIo_IpcCommonParamTraits.h>
27 #include <FIo_IpcMessageStart.h>
28 #include "FSecCert_CertTypes.h"
29
30 #define IPC_MESSAGE_START CertMgrServiceStart
31
32 #ifndef _FSEC_CERT_INTERNAL_CERT_MANAGER_MESSAGES_H_
33 #define _FSEC_CERT_INTERNAL_CERT_MANAGER_MESSAGES_H_
34
35 namespace IPC
36 {
37 template< >
38 struct ParamTraits< Tizen::Security::Cert::_CertFieldInfos >
39 {
40         typedef Tizen::Security::Cert::_CertFieldInfos param_type;
41         static void Write(Message* pMesg, const param_type& params)
42         {
43                 pMesg->WriteInt(params.certType);
44                 pMesg->WriteInt(params.certFileId);
45                 pMesg->WriteBytes(static_cast< const void* >(params.serialNo), Tizen::Security::Cert::_MAX_SERIAL_NUMBER_SIZE + 1);
46                 pMesg->WriteBytes(static_cast< const void* >(params.sigAlgorithm), Tizen::Security::Cert::_MAX_CERT_ALGORITHM_SIZE + 1);
47                 pMesg->WriteBytes(static_cast< const void* >(params.validityFrom), Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
48                 pMesg->WriteBytes(static_cast< const void* >(params.validityTo), Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
49                 pMesg->WriteBytes(static_cast< const void* >(params.subjectName), Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
50                 pMesg->WriteBytes(static_cast< const void* >(params.issuerName), Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
51                 pMesg->WriteBytes(static_cast< const void* >(params.fingerPrint), Tizen::Security::Cert::_MAX_CERT_FINGERPRINT_SIZE + 1);
52                 pMesg->WriteInt(params.fingerPrintLen);
53                 pMesg->WriteBytes(static_cast< const void* >(params.publicKey), Tizen::Security::Cert::_MAX_CERT_PUBLIC_KEY_SIZE + 1);
54                 pMesg->WriteBytes(static_cast< const void* >(params.certTypeFormat), Tizen::Security::Cert::_MAX_CERT_TYPE_SIZE + 1);
55                 pMesg->WriteInt(params.certVersion);
56                 pMesg->WriteBytes(static_cast< const void* >(params.certTitle), Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
57                 pMesg->WriteBytes(static_cast< const void* >(params.certSubTitle), Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
58
59         }
60         static bool Read(const Message* pMesg, void** ppIter, param_type* pParam)
61         {
62                 const char* pBuffer = null;
63                 int value = 0;
64
65                 pMesg->ReadInt(ppIter, &value);
66                 pParam->certType = static_cast< Tizen::Security::Cert::_CaCertType >(value);
67
68                 pMesg->ReadInt(ppIter, &value);
69                 pParam->certFileId = value;
70
71                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_SERIAL_NUMBER_SIZE + 1);
72                 memcpy(pParam->serialNo, pBuffer, Tizen::Security::Cert::_MAX_SERIAL_NUMBER_SIZE + 1);
73
74                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_ALGORITHM_SIZE + 1);
75                 memcpy(pParam->sigAlgorithm, pBuffer, Tizen::Security::Cert::_MAX_CERT_ALGORITHM_SIZE + 1);
76
77                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
78                 memcpy(pParam->validityFrom, pBuffer, Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
79
80                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
81                 memcpy(pParam->validityTo, pBuffer, Tizen::Security::Cert::_MAX_CERT_VALIDITY_SIZE + 1);
82
83                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
84                 memcpy(pParam->subjectName, pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
85
86                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
87                 memcpy(pParam->issuerName, pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
88
89                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_FINGERPRINT_SIZE + 1);
90                 memcpy(pParam->fingerPrint, pBuffer, Tizen::Security::Cert::_MAX_CERT_FINGERPRINT_SIZE + 1);
91
92                 pMesg->ReadInt(ppIter, &value);
93                 pParam->fingerPrintLen = value;
94
95                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_PUBLIC_KEY_SIZE + 1);
96                 memcpy(pParam->publicKey, pBuffer, Tizen::Security::Cert::_MAX_CERT_PUBLIC_KEY_SIZE + 1);
97
98                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_TYPE_SIZE + 1);
99                 memcpy(pParam->certTypeFormat, pBuffer, Tizen::Security::Cert::_MAX_CERT_TYPE_SIZE + 1);
100
101                 pMesg->ReadInt(ppIter, &value);
102                 pParam->certVersion = value;
103
104                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
105                 memcpy(pParam->certTitle, pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
106
107                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
108                 memcpy(pParam->certSubTitle, pBuffer, Tizen::Security::Cert::_MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
109
110                 return true;
111         }
112         static void Log(const param_type& p, std::string* l)
113         {
114
115         }
116 };
117
118 template< >
119 struct ParamTraits< Tizen::Security::Cert::_CertificateListInfo >
120 {
121         typedef Tizen::Security::Cert::_CertificateListInfo param_type;
122         static void Write(Message* pMesg, const param_type& params)
123         {
124                 int count = 0;
125                 int index = 0;
126
127                 param_type* pTemp = const_cast< param_type* >(&params);
128
129                 while (pTemp)
130                 {
131                         pTemp = pTemp->pNext;
132                         count++;
133                 }
134
135                 pMesg->WriteInt(count);
136
137                 pTemp = const_cast< param_type* >(&params);
138                 for (index = 0; index < count; index++)
139                 {
140                         pMesg->WriteInt(pTemp->certFileId);
141                         pMesg->WriteInt(pTemp->format);
142                         pMesg->WriteInt(pTemp->certType);
143                         pMesg->WriteInt(pTemp->length);
144                         pMesg->WriteInt(pTemp->priKeyLen);
145                         pMesg->WriteBytes(static_cast< const void* >(pTemp->certificate), Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
146                         pMesg->WriteBytes(static_cast< const void* >(pTemp->privatekey), Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
147
148                         pTemp = pTemp->pNext;
149
150
151                 }
152
153         }
154         static bool Read(const Message* pMesg, void** ppIter, param_type* pParam)
155         {
156                 const char* pBuffer = null;
157                 int value = 0;
158                 int count = 0;
159                 int index = 1;
160                 param_type* pCurrentNode = pParam;
161                 param_type* pNewNode = null;
162
163                 pMesg->ReadInt(ppIter, &count);
164
165                 if (count <= 0)
166                 {
167                         return true;
168                 }
169
170                 pMesg->ReadInt(ppIter, &value);
171                 pCurrentNode->certFileId = value;
172
173                 pMesg->ReadInt(ppIter, &value);
174                 pCurrentNode->format = static_cast< Tizen::Security::Cert::_CertFormat >(value);
175
176                 pMesg->ReadInt(ppIter, &value);
177                 pCurrentNode->certType = static_cast< Tizen::Security::Cert::_CaCertType >(value);
178
179                 pMesg->ReadInt(ppIter, &value);
180                 pCurrentNode->length = value;
181
182                 pMesg->ReadInt(ppIter, &value);
183                 pCurrentNode->priKeyLen = value;
184
185                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
186                 memcpy(pCurrentNode->certificate, pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
187
188                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
189                 memcpy(pCurrentNode->privatekey, pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
190
191                 pCurrentNode->pNext = null;
192
193                 for (index = 1; index < count; index++)
194                 {
195                         pNewNode = new (std::nothrow) param_type();
196                         SysTryReturn(NID_SEC_CERT, pNewNode != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] failed to allocate memory");
197
198                         pMesg->ReadInt(ppIter, &value);
199                         pNewNode->certFileId = value;
200
201                         pMesg->ReadInt(ppIter, &value);
202                         pNewNode->format = static_cast< Tizen::Security::Cert::_CertFormat >(value);
203
204                         pMesg->ReadInt(ppIter, &value);
205                         pNewNode->certType = static_cast< Tizen::Security::Cert::_CaCertType >(value);
206
207                         pMesg->ReadInt(ppIter, &value);
208                         pNewNode->length = value;
209
210                         pMesg->ReadInt(ppIter, &value);
211                         pNewNode->priKeyLen = value;
212
213                         pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
214                         memcpy(pNewNode->certificate, pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
215
216                         pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
217                         memcpy(pNewNode->privatekey, pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
218
219                         pNewNode->pNext = null;
220
221                         pCurrentNode->pNext = pNewNode;
222
223                         pCurrentNode = pNewNode;
224                 }
225
226                 return true;
227         }
228         static void Log(const param_type& p, std::string* l)
229         {
230
231         }
232 };
233
234 template< >
235 struct ParamTraits< Tizen::Security::Cert::_CertInfo >
236 {
237         typedef Tizen::Security::Cert::_CertInfo param_type;
238
239         static void Write(Message* pMesg, const param_type& params)
240         {
241                 pMesg->WriteInt(params.certId);
242                 pMesg->WriteInt(params.certFormat);
243                 pMesg->WriteInt(params.certType);
244                 pMesg->WriteInt(params.certLength);
245                 pMesg->WriteInt(params.privateKeyLen);
246                 pMesg->WriteBytes(static_cast< const void* >(params.certificate), Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
247                 pMesg->WriteBytes(static_cast< const void* >(params.privatekey), Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
248
249         }
250
251         static bool Read(const Message* pMesg, void** ppIter, param_type* pParam)
252         {
253                 const char* pBuffer = null;
254                 int value = 0;
255
256                 pMesg->ReadInt(ppIter, &value);
257                 pParam->certId = value;
258
259                 pMesg->ReadInt(ppIter, &value);
260                 pParam->certFormat = static_cast< Tizen::Security::Cert::_CertFormat >(value);
261
262                 pMesg->ReadInt(ppIter, &value);
263                 pParam->certType = static_cast< Tizen::Security::Cert::_CaCertType >(value);
264
265                 pMesg->ReadInt(ppIter, &value);
266                 pParam->certLength = value;
267
268                 pMesg->ReadInt(ppIter, &value);
269                 pParam->privateKeyLen = value;
270
271                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
272                 memcpy(pParam->certificate, pBuffer, Tizen::Security::Cert::_MAX_CERTIFICATE_SIZE);
273
274                 pMesg->ReadBytes(ppIter, &pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
275                 memcpy(pParam->privatekey, pBuffer, Tizen::Security::Cert::_MAX_CERT_PRIVATE_KEY_SIZE);
276
277                 return true;
278         }
279         static void Log(const param_type& p, std::string* l)
280         {
281
282         }
283 };
284 }
285
286 #endif // _FSEC_CERT_INTERNAL_CERT_MANAGER_MESSAGES_H_
287
288 IPC_SYNC_MESSAGE_CONTROL0_1(CertService_GetName, result);
289 IPC_SYNC_MESSAGE_CONTROL1_1(CertService_CloseCertificateStore, int, result);
290 IPC_SYNC_MESSAGE_CONTROL1_3(CertService_OpenCertificateStoreByType, int, int, int, result);
291 IPC_SYNC_MESSAGE_CONTROL1_2(CertService_GetCertificateCount, int, int, result);
292 IPC_SYNC_MESSAGE_CONTROL2_2(CertService_GetNextCertificate, int, int, Tizen::Io::_IpcBuffer, result);
293 IPC_SYNC_MESSAGE_CONTROL3_1(CertService_InsertRootCa, int, Tizen::Io::_IpcBuffer, int, result);
294 IPC_SYNC_MESSAGE_CONTROL3_1(CertService_UpdateRootCa, int, Tizen::Io::_IpcBuffer, Tizen::Io::_IpcBuffer, result);
295 IPC_SYNC_MESSAGE_CONTROL3_1(CertService_RemoveRootCa, int, Tizen::Io::_IpcBuffer, int, result);
296 IPC_SYNC_MESSAGE_CONTROL1_1(CertService_UninstallUserRootCertificateByCertId, int, result);
297 IPC_SYNC_MESSAGE_CONTROL4_1(CertService_InsertCaCertificate, int, int, Tizen::Io::_IpcBuffer, long, result);
298 IPC_SYNC_MESSAGE_CONTROL3_1(CertService_InsertUserCaCertificate, int, Tizen::Io::_IpcBuffer, int, result);
299 IPC_SYNC_MESSAGE_CONTROL1_1(CertService_InstallUserRootCertificate, Tizen::Io::_IpcBuffer, result);
300 IPC_SYNC_MESSAGE_CONTROL4_1(CertService_InsertUserCertChainPrivateKey, Tizen::Io::_IpcBuffer, int, Tizen::Io::_IpcBuffer, int, result);
301 IPC_SYNC_MESSAGE_CONTROL2_1(CertService_InsertCertificateChainWithPrivateKey, Tizen::Io::_IpcBuffer, int, result);
302 IPC_SYNC_MESSAGE_CONTROL2_1(CertService_InstallPkcs12Content, Tizen::Io::_IpcBuffer, Tizen::Io::_IpcBuffer, result);
303 IPC_SYNC_MESSAGE_CONTROL1_1(CertService_DeleteUserCertificateByCertId, int, result);
304 IPC_SYNC_MESSAGE_CONTROL1_1(CertService_DeleteUserCertChainByCertId, int, result);
305 IPC_SYNC_MESSAGE_CONTROL4_2(CertService_GetUserCertChainByIssuerAndSubjectNameN, Tizen::Io::_IpcBuffer, int, Tizen::Io::_IpcBuffer, int, Tizen::Security::Cert::_CertificateListInfo, result);
306 IPC_SYNC_MESSAGE_CONTROL2_2(CertService_GetUserCertificateByCertIdN, int, int, Tizen::Security::Cert::_CertInfo, result);
307 IPC_SYNC_MESSAGE_CONTROL1_2(CertService_GetUserCertFieldInfoByCertId, int, Tizen::Security::Cert::_CertFieldInfos, result);