fixed user cert install failed issue
[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) CertServer_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 certType)
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         SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
116         SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
117
118         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_CloseCertificateStore(certType, &ret));
119         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
120
121         r = __pIpcClient->SendRequest(pMessage.get());
122         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
123         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
124
125         return r;
126 }
127
128 result
129 _CertServiceProxy::OpenCertificateStoreByType(int type, int& count)
130 {
131         result r = E_SUCCESS;
132         result ret = E_SUCCESS;
133
134         ClearLastResult();
135
136         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
137         SysTryReturnResult(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
138         SysTryReturnResult(NID_SEC_CERT, type < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
139
140         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_OpenCertificateStoreByType(type, &count, &ret));
141         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
142
143         r = __pIpcClient->SendRequest(pMessage.get());
144         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
145         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
146
147         return r;
148 }
149
150 result
151 _CertServiceProxy::GetCertificateCount(int certType, int& totalCertCount)
152 {
153         result r = E_SUCCESS;
154         result ret = E_SUCCESS;
155
156         ClearLastResult();
157
158         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
159         SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
160         SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
161
162         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetCertificateCount(certType, &totalCertCount, &ret));
163         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
164
165         r = __pIpcClient->SendRequest(pMessage.get());
166         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
167         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
168
169         return r;
170 }
171
172 result
173 _CertServiceProxy::GetNextCertificate(int certType, int& curPos, byte* pBuffer, int& bufferLen)
174 {
175         result r = E_SUCCESS;
176         result ret = E_SUCCESS;
177
178         Tizen::Io::_IpcBuffer certBufferIpc;
179
180         ClearLastResult();
181
182         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
183         SysTryReturnResult(NID_SEC_CERT, pBuffer != null, E_INVALID_ARG, "Invalid parameter.");
184         SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
185         SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
186
187         certBufferIpc.pBuffer = null;
188         certBufferIpc.size = 0;
189
190         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetNextCertificate(certType, curPos, bufferLen, &certBufferIpc, &curPos, &ret));
191         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
192
193         r = __pIpcClient->SendRequest(pMessage.get());
194         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
195         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
196
197         memcpy(pBuffer, certBufferIpc.pBuffer, certBufferIpc.size);
198         bufferLen = certBufferIpc.size;
199
200         return r;
201 }
202
203 result
204 _CertServiceProxy::UpdateCaCertificate(int type, byte* pOldCert, int oldCertLen, byte* pNewCert, int newCertLen)
205 {
206         result r = E_SUCCESS;
207         result ret = E_SUCCESS;
208
209         Tizen::Io::_IpcBuffer oldBufferIpc = {0, };
210         Tizen::Io::_IpcBuffer newBufferIpc = {0, };
211
212         ClearLastResult();
213
214         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
215         SysTryReturnResult(NID_SEC_CERT, ((pOldCert != null) && (oldCertLen > 0)), E_INVALID_ARG, "Invalid input old certificate parameter.");
216         SysTryReturnResult(NID_SEC_CERT, ((pNewCert != null) && (newCertLen > 0)), E_INVALID_ARG, "Invalid input new certificate parameter.");
217         SysTryReturnResult(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
218         SysTryReturnResult(NID_SEC_CERT, type < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
219
220         oldBufferIpc.pBuffer = pOldCert;
221         oldBufferIpc.size = oldCertLen;
222
223         newBufferIpc.pBuffer = pNewCert;
224         newBufferIpc.size = newCertLen;
225
226         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_UpdateRootCa(type, oldBufferIpc, newBufferIpc, &ret));
227         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
228
229         r = __pIpcClient->SendRequest(pMessage.get());
230         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
231         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
232
233         return r;
234 }
235
236 result
237 _CertServiceProxy::RemoveCaCertificate(int type, byte* pBuffer, int bufLen)
238 {
239         result r = E_SUCCESS;
240         result ret = E_SUCCESS;
241         Tizen::Io::_IpcBuffer certBufferIpc;
242
243         ClearLastResult();
244
245         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
246         SysTryReturnResult(NID_SEC_CERT, ((pBuffer != null) && (bufLen > 0)), E_INVALID_ARG, "Invalid input parameters.");
247
248         certBufferIpc.pBuffer = pBuffer;
249         certBufferIpc.size = bufLen;
250
251         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_RemoveRootCa(type, certBufferIpc, bufLen, &ret));
252         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
253
254         r = __pIpcClient->SendRequest(pMessage.get());
255         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
256         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
257
258         return r;
259 }
260
261 result
262 _CertServiceProxy::RemoveUserCaCertificateByCertId(int certId)
263 {
264         result r = E_SUCCESS;
265         result ret = E_SUCCESS;
266
267         ClearLastResult();
268
269         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
270         SysTryReturnResult(NID_SEC_CERT, certId >= 1, E_INVALID_ARG, "Invalid input parameter.");
271
272         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_UninstallUserRootCertificateByCertId(certId, &ret));
273         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
274
275         r = __pIpcClient->SendRequest(pMessage.get());
276         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
277         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
278
279         return r;
280 }
281
282 result
283 _CertServiceProxy::InsertCaCertificate(int type, int format, byte* pCert, long certLen)
284 {
285         result r = E_SUCCESS;
286         result ret = E_SUCCESS;
287         Tizen::Io::_IpcBuffer certBufferIpc;
288
289         ClearLastResult();
290
291         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
292         SysTryReturnResult(NID_SEC_CERT, ((pCert != null) && (certLen > 0)), E_INVALID_ARG, "Invalid input parameter.");
293
294         certBufferIpc.pBuffer = pCert;
295         certBufferIpc.size = certLen;
296
297         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertCaCertificate(type, format, certBufferIpc, certLen, &ret));
298         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
299
300         r = __pIpcClient->SendRequest(pMessage.get());
301         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
302         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
303
304         return r;
305 }
306
307 result
308 _CertServiceProxy::InsertUserCaCertificate(int format, char* pCert, int certLen)
309 {
310         result r = E_SUCCESS;
311         result ret = E_SUCCESS;
312         Tizen::Io::_IpcBuffer certBufferIpc;
313
314         ClearLastResult();
315
316         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
317         SysTryReturnResult(NID_SEC_CERT, ((pCert != null) && (certLen > 0)), E_INVALID_ARG, "Invalid input parameter.");
318
319         certBufferIpc.pBuffer = pCert;
320         certBufferIpc.size = certLen;
321
322         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertUserCaCertificate(format, certBufferIpc, certLen, &ret));
323         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
324
325         r = __pIpcClient->SendRequest(pMessage.get());
326         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
327         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
328
329         return r;
330 }
331
332 result
333 _CertServiceProxy::InsertUserCaCertificate(byte* pFilePath)
334 {
335         result r = E_SUCCESS;
336         result ret = E_SUCCESS;
337         Tizen::Io::_IpcBuffer certBufferIpc;
338
339         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
340         SysTryReturnResult(NID_SEC_CERT, pFilePath != null, E_INVALID_ARG, "Invalid input parameter.");
341
342         certBufferIpc.pBuffer = pFilePath;
343         certBufferIpc.size = strlen(reinterpret_cast< char* >(pFilePath)) + 1;
344
345         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InstallUserRootCertificate(certBufferIpc, &ret));
346         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
347
348         r = __pIpcClient->SendRequest(pMessage.get());
349         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
350         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
351
352         return r;
353 }
354
355
356 //User Certificate APIs
357
358 result
359 _CertServiceProxy::InsertUserCertChainPrivateKey(char* pCertchainBuffer, int certChainLen, char* pUserPrivateKey, int userPrivateKeyLen)
360 {
361         result r = E_SUCCESS;
362         result ret = E_SUCCESS;
363         Tizen::Io::_IpcBuffer certPackBufferIPC;
364         Tizen::Io::_IpcBuffer privateKeyBufferIpc;
365
366         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
367         SysTryReturnResult(NID_SEC_CERT, ((pCertchainBuffer != null) && (certChainLen > 0)), E_INVALID_ARG, "Invalid input parameter.");
368
369         certPackBufferIPC.pBuffer = pCertchainBuffer;
370         certPackBufferIPC.size = certChainLen;
371
372         privateKeyBufferIpc.pBuffer = pUserPrivateKey;
373         privateKeyBufferIpc.size = userPrivateKeyLen;
374
375         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertUserCertChainPrivateKey(certPackBufferIPC, certChainLen, privateKeyBufferIpc, userPrivateKeyLen, &ret));
376         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
377
378         r = __pIpcClient->SendRequest(pMessage.get());
379         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
380         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
381
382         return r;
383 }
384
385 result
386 _CertServiceProxy::InsertCertificateChainWithPrivateKey(char* pCertchainPrivateKeyBuffer, int certChainPrivateKeyLength)
387 {
388         result r = E_SUCCESS;
389         result ret = E_SUCCESS;
390         Tizen::Io::_IpcBuffer certChainPriKeyBufferIpc;
391
392         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
393         SysTryReturnResult(NID_SEC_CERT, ((pCertchainPrivateKeyBuffer != null) && (certChainPrivateKeyLength > 0)), E_INVALID_ARG, "Invalid input parameter.");
394
395         certChainPriKeyBufferIpc.pBuffer = pCertchainPrivateKeyBuffer;
396         certChainPriKeyBufferIpc.size = certChainPrivateKeyLength;
397
398         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertCertificateChainWithPrivateKey(certChainPriKeyBufferIpc, certChainPrivateKeyLength, &ret));
399         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
400
401         r = __pIpcClient->SendRequest(pMessage.get());
402         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
403         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
404
405         return r;
406 }
407
408 result
409 _CertServiceProxy::InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12ImportPassword, bool checkPrivilege)
410 {
411         result r = E_SUCCESS;
412         result ret = E_SUCCESS;
413         Tizen::Io::_IpcBuffer pkcs12FileBufferIpc;
414         Tizen::Io::_IpcBuffer pkcs12PasswdBufferIpc;
415
416         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
417         SysTryReturnResult(NID_SEC_CERT, pPkcs12FilePath != null, E_INVALID_ARG, "Invalid input parameter.");
418
419         pkcs12FileBufferIpc.pBuffer = pPkcs12FilePath;
420         pkcs12FileBufferIpc.size = strlen(reinterpret_cast< char* >(pPkcs12FilePath)) + 1;
421
422         pkcs12PasswdBufferIpc.pBuffer = pPkcs12ImportPassword;
423         pkcs12PasswdBufferIpc.size = strlen(reinterpret_cast< char* >(pPkcs12ImportPassword)) + 1;
424
425         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InstallPkcs12Content(pkcs12FileBufferIpc, pkcs12PasswdBufferIpc, checkPrivilege, &ret));
426         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
427
428         r = __pIpcClient->SendRequest(pMessage.get());
429         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
430         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
431
432         return r;
433 }
434
435 result
436 _CertServiceProxy::RemoveUserCertChainByCertId(int certId)
437 {
438         result r = E_SUCCESS;
439         result ret = E_SUCCESS;
440
441         ClearLastResult();
442
443         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "Instance is not constructed.");
444         SysTryReturnResult(NID_SEC_CERT, certId >= 1, E_INVALID_ARG, "Invalid input parameter.");
445
446         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_DeleteUserCertChainByCertId(certId, &ret));
447         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
448
449         r = __pIpcClient->SendRequest(pMessage.get());
450         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
451         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
452
453         return r;
454 }
455
456 result
457 _CertServiceProxy::GetUserCertChainByIssuerAndSubjectNameN(char* pIssuerName, int issuerNameLen, char* pSubjectName, int subNameLen, _CertificateListInfo*& pUserCertListInfoTypesRef)
458 {
459         result r = E_SUCCESS;
460         result ret = E_SUCCESS;
461         _CertificateListInfo* pRetNode = null;
462         Tizen::Io::_IpcBuffer issuerBufferIpc;
463         Tizen::Io::_IpcBuffer subjectBufferIpc;
464
465         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPCInstance is not constructed.");
466         SysTryReturnResult(NID_SEC_CERT, pIssuerName != null, E_INVALID_ARG, "Invalid Parameters");
467         SysTryReturnResult(NID_SEC_CERT, pSubjectName != null, E_INVALID_ARG, "Invalid Parameters");
468
469         issuerBufferIpc.pBuffer = pIssuerName;
470         issuerBufferIpc.size = issuerNameLen;
471
472         subjectBufferIpc.pBuffer = pSubjectName;
473         subjectBufferIpc.size = subNameLen;
474
475         pRetNode = new (std::nothrow) _CertificateListInfo();
476         SysTryReturnResult(NID_SEC_CERT, pRetNode != null, E_OUT_OF_MEMORY, "Unable to allocate");
477
478         memset(pRetNode, 0, sizeof(*pRetNode));
479
480         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertChainByIssuerAndSubjectNameN(issuerBufferIpc, issuerNameLen, subjectBufferIpc, subNameLen, pRetNode, &ret));
481         SysTryReturn(NID_SEC_CERT, pMessage != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
482
483         r = __pIpcClient->SendRequest(pMessage.get());
484         SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Failed to send message.", GetErrorMessage(r));
485         SysTryCatch(NID_SEC_CERT, !IsFailed(ret), r = ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
486
487         pUserCertListInfoTypesRef = pRetNode;
488
489 CATCH:
490         if (IsFailed(r))
491         {
492                 _CertService::FreeCertList(pRetNode);
493                 pRetNode = null;
494         }
495
496
497         return r;
498 }
499
500 _CertInfo*
501 _CertServiceProxy::GetUserCertificateByCertIdN(int certId, int encodingType)
502 {
503         result r = E_SUCCESS;
504         result ret = E_SUCCESS;
505
506         _CertInfo* pRetNode = null;
507
508         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, null, "IPC instance is not constructed.");
509
510         pRetNode = new (std::nothrow) _CertInfo();
511         SysTryReturnResult(NID_SEC_CERT, pRetNode != null, null, "Unable to allocate");
512
513         memset(pRetNode, 0, sizeof(*pRetNode));
514
515         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertificateByCertIdN(certId, encodingType, pRetNode, &ret));
516         SysTryCatch(NID_SEC_CERT, pMessage != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
517
518         r = __pIpcClient->SendRequest(pMessage.get());
519         SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Failed to send message.", GetErrorMessage(r));
520         SysTryCatch(NID_SEC_CERT, !IsFailed(ret), r = ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
521
522 CATCH:
523         if (IsFailed(r))
524         {
525                 _CertService::FreeCertificateInfo(pRetNode);
526                 pRetNode = null;
527         }
528
529         return pRetNode;
530 }
531
532 result
533 _CertServiceProxy::GetUserCertFieldInfoByCertId(int certId, _CertFieldInfos* pCertFieldInfos)
534 {
535         result r = E_SUCCESS;
536         result ret = E_SUCCESS;
537
538         ClearLastResult();
539
540         SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
541         SysTryReturnResult(NID_SEC_CERT, pCertFieldInfos != null, E_INVALID_ARG, "Invalid input parameter.");
542
543         std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertFieldInfoByCertId(certId, pCertFieldInfos, &ret));
544         SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
545
546         r = __pIpcClient->SendRequest(pMessage.get());
547         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
548         SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
549
550         return r;
551 }
552 } } }