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