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