modify ipcbuffer to remove memory leak
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_CertServiceProxy.cpp
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_CertServiceProxy.cpp
19  * @brief       This is the implementation file for the _CertServiceProxy class.
20  */
21
22 #include <unique_ptr.h>
23 #include <string.h>
24 #include <iostream>
25 #include <new>
26 #include <pthread.h>
27 #include <FBaseSysLog.h>
28 #include <FIo_IpcClient.h>
29 #include "FSecCert_CertMgrMessages.h"
30 #include "FSecCert_CertServiceProxy.h"
31 #include "FSecCert_CertService.h"
32
33 using namespace std;
34
35 using namespace Tizen::Io;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Runtime;
39
40 namespace Tizen { namespace Security { namespace Cert
41 {
42
43 _IpcClient* _CertServiceProxy::__pIpcClient = null;
44 _CertServiceProxy* _CertServiceProxy::__pCertServiceProxy = null;
45
46 _CertServiceProxy::_CertServiceProxy(void)
47 {
48         // Empty Body
49 }
50
51 _CertServiceProxy::~_CertServiceProxy(void)
52 {
53         // Empty Body
54 }
55
56 _CertServiceProxy*
57 _CertServiceProxy::GetInstance(void)
58 {
59
60         static pthread_once_t once_block = PTHREAD_ONCE_INIT;
61         if (__pCertServiceProxy == null)
62         {
63                 pthread_once(&once_block, Construct);
64         }
65
66         return __pCertServiceProxy;
67 }
68
69
70 void
71 _CertServiceProxy::Construct(void)
72 {
73         static _CertServiceProxy certServiceProxy;
74         static _IpcClient ipcClient;
75
76         result r = ipcClient.Construct(L"osp.security.ipcserver.certmanager", null);
77         SysTryReturnVoidResult(NID_SEC_CERT, !IsFailed(r), r, "[%s] Failed to construct IPC client(Cert-Mgr)", GetErrorMessage(r));
78
79         __pIpcClient = &ipcClient;
80         __pCertServiceProxy = &certServiceProxy;
81 }
82
83
84 result
85 _CertServiceProxy::GetName()
86 {
87         result r = E_SUCCESS;
88         result ret = E_SUCCESS;
89
90         ClearLastResult();
91
92         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
93
94         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetName(&ret));
95         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
96
97         r = __pIpcClient->SendRequest(pMessage.get());
98         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
99         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
100
101         return r;
102 }
103
104
105 result
106 _CertServiceProxy::CloseCertificateStore(int certType)
107 {
108         result r = E_SUCCESS;
109         result ret = E_SUCCESS;
110
111         ClearLastResult();
112
113         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
114         SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
115         SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
116
117         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_CloseCertificateStore(certType, &ret));
118         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
119
120         r = __pIpcClient->SendRequest(pMessage.get());
121         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
122         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
123
124         return r;
125 }
126
127 result
128 _CertServiceProxy::OpenCertificateStoreByType(int type, int& count)
129 {
130         result r = E_SUCCESS;
131         result ret = E_SUCCESS;
132
133         ClearLastResult();
134
135         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
136         SysTryReturnResult(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
137         SysTryReturnResult(NID_SEC_CERT, type < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
138
139         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_OpenCertificateStoreByType(type, &count, &ret));
140         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
141
142         r = __pIpcClient->SendRequest(pMessage.get());
143         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
144         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
145
146         return r;
147 }
148
149 result
150 _CertServiceProxy::GetCertificateCount(int certType, int& totalCertCount)
151 {
152         result r = E_SUCCESS;
153         result ret = E_SUCCESS;
154
155         ClearLastResult();
156
157         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
158         SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
159         SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
160
161         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetCertificateCount(certType, &totalCertCount, &ret));
162         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
163
164         r = __pIpcClient->SendRequest(pMessage.get());
165         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
166         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
167
168         return r;
169 }
170
171 result
172 _CertServiceProxy::GetNextCertificate(int certType, int& curPos, byte* pBuffer, int& bufferLen)
173 {
174         result r = E_SUCCESS;
175         result ret = E_SUCCESS;
176
177         Tizen::Base::ByteBuffer certBufferIpc;
178
179         ClearLastResult();
180
181         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
182         SysTryReturnResult(NID_SEC_CERT, pBuffer != null, E_INVALID_ARG, "Invalid parameter.");
183         SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
184         SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
185
186         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetNextCertificate(certType, curPos, bufferLen, &certBufferIpc, &curPos, &ret));
187         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
188
189         r = __pIpcClient->SendRequest(pMessage.get());
190         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
191         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
192
193         memcpy(pBuffer, certBufferIpc.GetPointer(), certBufferIpc.GetRemaining());
194         bufferLen = certBufferIpc.GetRemaining();
195
196         return r;
197 }
198
199 result
200 _CertServiceProxy::UpdateCaCertificate(int type, byte* pOldCert, int oldCertLen, byte* pNewCert, int newCertLen)
201 {
202         result r = E_SUCCESS;
203         result ret = E_SUCCESS;
204
205         Tizen::Io::_IpcBuffer oldBufferIpc = {0, };
206         Tizen::Io::_IpcBuffer newBufferIpc = {0, };
207
208         ClearLastResult();
209
210         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
211         SysTryReturnResult(NID_SEC_CERT, ((pOldCert != null) && (oldCertLen > 0)), E_INVALID_ARG, "Invalid input old certificate parameter.");
212         SysTryReturnResult(NID_SEC_CERT, ((pNewCert != null) && (newCertLen > 0)), E_INVALID_ARG, "Invalid input new certificate parameter.");
213         SysTryReturnResult(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
214         SysTryReturnResult(NID_SEC_CERT, type < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
215
216         oldBufferIpc.pBuffer = pOldCert;
217         oldBufferIpc.size = oldCertLen;
218
219         newBufferIpc.pBuffer = pNewCert;
220         newBufferIpc.size = newCertLen;
221
222         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_UpdateRootCa(type, oldBufferIpc, newBufferIpc, &ret));
223         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
224
225         r = __pIpcClient->SendRequest(pMessage.get());
226         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
227         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
228
229         return r;
230 }
231
232 result
233 _CertServiceProxy::RemoveCaCertificate(int type, byte* pBuffer, int bufLen)
234 {
235         result r = E_SUCCESS;
236         result ret = E_SUCCESS;
237         Tizen::Io::_IpcBuffer certBufferIpc;
238
239         ClearLastResult();
240
241         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
242         SysTryReturnResult(NID_SEC_CERT, ((pBuffer != null) && (bufLen > 0)), E_INVALID_ARG, "Invalid input parameters.");
243
244         certBufferIpc.pBuffer = pBuffer;
245         certBufferIpc.size = bufLen;
246
247         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_RemoveRootCa(type, certBufferIpc, bufLen, &ret));
248         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
249
250         r = __pIpcClient->SendRequest(pMessage.get());
251         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
252         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
253
254         return r;
255 }
256
257 result
258 _CertServiceProxy::RemoveUserCaCertificateByCertId(int certId)
259 {
260         result r = E_SUCCESS;
261         result ret = E_SUCCESS;
262
263         ClearLastResult();
264
265         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
266         SysTryReturnResult(NID_SEC_CERT, certId >= 1, E_INVALID_ARG, "Invalid input parameter.");
267
268         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_UninstallUserRootCertificateByCertId(certId, &ret));
269         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
270
271         r = __pIpcClient->SendRequest(pMessage.get());
272         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
273         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
274
275         return r;
276 }
277
278 result
279 _CertServiceProxy::InsertCaCertificate(int type, int format, byte* pCert, long certLen)
280 {
281         result r = E_SUCCESS;
282         result ret = E_SUCCESS;
283         Tizen::Io::_IpcBuffer certBufferIpc;
284
285         ClearLastResult();
286
287         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
288         SysTryReturnResult(NID_SEC_CERT, ((pCert != null) && (certLen > 0)), E_INVALID_ARG, "Invalid input parameter.");
289
290         certBufferIpc.pBuffer = pCert;
291         certBufferIpc.size = certLen;
292
293         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertCaCertificate(type, format, certBufferIpc, certLen, &ret));
294         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
295
296         r = __pIpcClient->SendRequest(pMessage.get());
297         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
298         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
299
300         return r;
301 }
302
303 result
304 _CertServiceProxy::InsertUserCaCertificate(int format, char* pCert, int certLen)
305 {
306         result r = E_SUCCESS;
307         result ret = E_SUCCESS;
308         Tizen::Io::_IpcBuffer certBufferIpc;
309
310         ClearLastResult();
311
312         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
313         SysTryReturnResult(NID_SEC_CERT, ((pCert != null) && (certLen > 0)), E_INVALID_ARG, "Invalid input parameter.");
314
315         certBufferIpc.pBuffer = pCert;
316         certBufferIpc.size = certLen;
317
318         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertUserCaCertificate(format, certBufferIpc, certLen, &ret));
319         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
320
321         r = __pIpcClient->SendRequest(pMessage.get());
322         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
323         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
324
325         return r;
326 }
327
328 result
329 _CertServiceProxy::InsertUserCaCertificate(byte* pFilePath)
330 {
331         result r = E_SUCCESS;
332         result ret = E_SUCCESS;
333         Tizen::Io::_IpcBuffer certBufferIpc;
334
335         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
336         SysTryReturnResult(NID_SEC_CERT, pFilePath != null, E_INVALID_ARG, "Invalid input parameter.");
337
338         certBufferIpc.pBuffer = pFilePath;
339         certBufferIpc.size = strlen(reinterpret_cast< char* >(pFilePath)) + 1;
340
341         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InstallUserRootCertificate(certBufferIpc, &ret));
342         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
343
344         r = __pIpcClient->SendRequest(pMessage.get());
345         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
346         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
347
348         return r;
349 }
350
351
352 //User Certificate APIs
353
354 result
355 _CertServiceProxy::InsertUserCertChainPrivateKey(char* pCertchainBuffer, int certChainLen, char* pUserPrivateKey, int userPrivateKeyLen)
356 {
357         result r = E_SUCCESS;
358         result ret = E_SUCCESS;
359         Tizen::Io::_IpcBuffer certPackBufferIPC;
360         Tizen::Io::_IpcBuffer privateKeyBufferIpc;
361
362         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
363         SysTryReturnResult(NID_SEC_CERT, ((pCertchainBuffer != null) && (certChainLen > 0)), E_INVALID_ARG, "Invalid input parameter.");
364
365         certPackBufferIPC.pBuffer = pCertchainBuffer;
366         certPackBufferIPC.size = certChainLen;
367
368         privateKeyBufferIpc.pBuffer = pUserPrivateKey;
369         privateKeyBufferIpc.size = userPrivateKeyLen;
370
371         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertUserCertChainPrivateKey(certPackBufferIPC, certChainLen, privateKeyBufferIpc, userPrivateKeyLen, &ret));
372         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
373
374         r = __pIpcClient->SendRequest(pMessage.get());
375         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
376         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
377
378         return r;
379 }
380
381 result
382 _CertServiceProxy::InsertCertificateChainWithPrivateKey(char* pCertchainPrivateKeyBuffer, int certChainPrivateKeyLength)
383 {
384         result r = E_SUCCESS;
385         result ret = E_SUCCESS;
386         Tizen::Io::_IpcBuffer certChainPriKeyBufferIpc;
387
388         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
389         SysTryReturnResult(NID_SEC_CERT, ((pCertchainPrivateKeyBuffer != null) && (certChainPrivateKeyLength > 0)), E_INVALID_ARG, "Invalid input parameter.");
390
391         certChainPriKeyBufferIpc.pBuffer = pCertchainPrivateKeyBuffer;
392         certChainPriKeyBufferIpc.size = certChainPrivateKeyLength;
393
394         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertCertificateChainWithPrivateKey(certChainPriKeyBufferIpc, certChainPrivateKeyLength, &ret));
395         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
396
397         r = __pIpcClient->SendRequest(pMessage.get());
398         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
399         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
400
401         return r;
402 }
403
404 result
405 _CertServiceProxy::InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12ImportPassword, bool checkPrivilege)
406 {
407         result r = E_SUCCESS;
408         result ret = E_SUCCESS;
409         Tizen::Io::_IpcBuffer pkcs12FileBufferIpc;
410         Tizen::Io::_IpcBuffer pkcs12PasswdBufferIpc;
411
412         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
413         SysTryReturnResult(NID_SEC_CERT, pPkcs12FilePath != null, E_INVALID_ARG, "Invalid input parameter.");
414
415         pkcs12FileBufferIpc.pBuffer = pPkcs12FilePath;
416         pkcs12FileBufferIpc.size = strlen(reinterpret_cast< char* >(pPkcs12FilePath)) + 1;
417
418         pkcs12PasswdBufferIpc.pBuffer = pPkcs12ImportPassword;
419         pkcs12PasswdBufferIpc.size = strlen(reinterpret_cast< char* >(pPkcs12ImportPassword)) + 1;
420
421         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InstallPkcs12Content(pkcs12FileBufferIpc, pkcs12PasswdBufferIpc, checkPrivilege, &ret));
422         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
423
424         r = __pIpcClient->SendRequest(pMessage.get());
425         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
426         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
427
428         return r;
429 }
430
431 result
432 _CertServiceProxy::RemoveUserCertChainByCertId(int certId)
433 {
434         result r = E_SUCCESS;
435         result ret = E_SUCCESS;
436
437         ClearLastResult();
438
439         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "Instance is not constructed.");
440         SysTryReturnResult(NID_SEC_CERT, certId >= 1, E_INVALID_ARG, "Invalid input parameter.");
441
442         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_DeleteUserCertChainByCertId(certId, &ret));
443         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
444
445         r = __pIpcClient->SendRequest(pMessage.get());
446         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
447         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
448
449         return r;
450 }
451
452 result
453 _CertServiceProxy::GetUserCertChainByIssuerAndSubjectNameN(char* pIssuerName, int issuerNameLen, char* pSubjectName, int subNameLen, _CertificateListInfo*& pUserCertListInfoTypesRef)
454 {
455         result r = E_SUCCESS;
456         result ret = E_SUCCESS;
457         _CertificateListInfo* pRetNode = null;
458         Tizen::Io::_IpcBuffer issuerBufferIpc;
459         Tizen::Io::_IpcBuffer subjectBufferIpc;
460
461         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPCInstance is not constructed.");
462         SysTryReturnResult(NID_SEC_CERT, pIssuerName != null, E_INVALID_ARG, "Invalid Parameters");
463         SysTryReturnResult(NID_SEC_CERT, pSubjectName != null, E_INVALID_ARG, "Invalid Parameters");
464
465         issuerBufferIpc.pBuffer = pIssuerName;
466         issuerBufferIpc.size = issuerNameLen;
467
468         subjectBufferIpc.pBuffer = pSubjectName;
469         subjectBufferIpc.size = subNameLen;
470
471         pRetNode = new (std::nothrow) _CertificateListInfo();
472         SysTryReturnResult(NID_SEC_CERT, pRetNode != null, E_OUT_OF_MEMORY, "Unable to allocate");
473
474         memset(pRetNode, 0, sizeof(*pRetNode));
475
476         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertChainByIssuerAndSubjectNameN(issuerBufferIpc, issuerNameLen, subjectBufferIpc, subNameLen, pRetNode, &ret));
477         SysTryReturn(NID_SEC_CERT, pMessage != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
478
479         r = __pIpcClient->SendRequest(pMessage.get());
480         SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Failed to send message.", GetErrorMessage(r));
481         SysTryCatch(NID_SEC_CERT, !IsFailed(ret), r = ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
482
483         pUserCertListInfoTypesRef = pRetNode;
484
485 CATCH:
486         if (IsFailed(r))
487         {
488                 _CertService::FreeCertList(pRetNode);
489                 pRetNode = null;
490         }
491
492
493         return r;
494 }
495
496 _CertInfo*
497 _CertServiceProxy::GetUserCertificateByCertIdN(int certId, int encodingType)
498 {
499         result r = E_SUCCESS;
500         result ret = E_SUCCESS;
501
502         _CertInfo* pRetNode = null;
503
504         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, null, "IPC instance is not constructed.");
505
506         pRetNode = new (std::nothrow) _CertInfo();
507         SysTryReturnResult(NID_SEC_CERT, pRetNode != null, null, "Unable to allocate");
508
509         memset(pRetNode, 0, sizeof(*pRetNode));
510
511         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertificateByCertIdN(certId, encodingType, pRetNode, &ret));
512         SysTryCatch(NID_SEC_CERT, pMessage != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
513
514         r = __pIpcClient->SendRequest(pMessage.get());
515         SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Failed to send message.", GetErrorMessage(r));
516         SysTryCatch(NID_SEC_CERT, !IsFailed(ret), r = ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
517
518 CATCH:
519         if (IsFailed(r))
520         {
521                 _CertService::FreeCertificateInfo(pRetNode);
522                 pRetNode = null;
523         }
524
525         return pRetNode;
526 }
527
528 result
529 _CertServiceProxy::GetUserCertFieldInfoByCertId(int certId, _CertFieldInfos* pCertFieldInfos)
530 {
531         result r = E_SUCCESS;
532         result ret = E_SUCCESS;
533
534         ClearLastResult();
535
536         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
537         SysTryReturnResult(NID_SEC_CERT, pCertFieldInfos != null, E_INVALID_ARG, "Invalid input parameter.");
538
539         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertFieldInfoByCertId(certId, pCertFieldInfos, &ret));
540         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
541
542         r = __pIpcClient->SendRequest(pMessage.get());
543         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
544         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
545
546         return r;
547 }
548
549 void
550 _CertServiceProxy::RestoreRootCaIntegrity(void)
551 {
552         result r = E_SUCCESS;
553
554         ClearLastResult();
555
556         SysTryReturnVoidResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "[%s] IPC instance is not constructed.", GetErrorMessage(E_SYSTEM));
557
558         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_RestoreRootCaIntegrity());
559         SysTryReturnVoidResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "[%s] Failed to allocate memory.", GetErrorMessage(E_OUT_OF_MEMORY));
560
561         r = __pIpcClient->SendRequest(pMessage.get());
562         SysTryReturnVoidResult(NID_SEC_CERT, !IsFailed(r), r, "[%s] Failed to send message.", GetErrorMessage(r));
563 }
564
565 } } }