modify ipcbuffer to remove memory leak
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_CertServiceProxy.cpp
index f62207e..56f5ca1 100755 (executable)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -92,7 +91,7 @@ _CertServiceProxy::GetName()
 
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_GetName(&ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetName(&ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -104,7 +103,7 @@ _CertServiceProxy::GetName()
 
 
 result
-_CertServiceProxy::CloseCertificateStore(int certificateStoreCtx)
+_CertServiceProxy::CloseCertificateStore(int certType)
 {
        result r = E_SUCCESS;
        result ret = E_SUCCESS;
@@ -112,8 +111,10 @@ _CertServiceProxy::CloseCertificateStore(int certificateStoreCtx)
        ClearLastResult();
 
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
+       SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
+       SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_CloseCertificateStore(certificateStoreCtx, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_CloseCertificateStore(certType, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -124,7 +125,7 @@ _CertServiceProxy::CloseCertificateStore(int certificateStoreCtx)
 }
 
 result
-_CertServiceProxy::OpenCertificateStoreByType(int type, int& count, int& certificateStoreCtx)
+_CertServiceProxy::OpenCertificateStoreByType(int type, int& count)
 {
        result r = E_SUCCESS;
        result ret = E_SUCCESS;
@@ -132,8 +133,10 @@ _CertServiceProxy::OpenCertificateStoreByType(int type, int& count, int& certifi
        ClearLastResult();
 
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
+       SysTryReturnResult(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
+       SysTryReturnResult(NID_SEC_CERT, type < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_OpenCertificateStoreByType(type, &count, &certificateStoreCtx, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_OpenCertificateStoreByType(type, &count, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -144,7 +147,7 @@ _CertServiceProxy::OpenCertificateStoreByType(int type, int& count, int& certifi
 }
 
 result
-_CertServiceProxy::GetCertificateCount(int certificateStoreCtx, int& totalCertCount)
+_CertServiceProxy::GetCertificateCount(int certType, int& totalCertCount)
 {
        result r = E_SUCCESS;
        result ret = E_SUCCESS;
@@ -152,8 +155,10 @@ _CertServiceProxy::GetCertificateCount(int certificateStoreCtx, int& totalCertCo
        ClearLastResult();
 
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
+       SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
+       SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_GetCertificateCount(certificateStoreCtx, &totalCertCount, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetCertificateCount(certType, &totalCertCount, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -164,30 +169,29 @@ _CertServiceProxy::GetCertificateCount(int certificateStoreCtx, int& totalCertCo
 }
 
 result
-_CertServiceProxy::GetNextCertificate(int certificateStoreCtx, byte* pBuffer, int& bufferLen)
+_CertServiceProxy::GetNextCertificate(int certType, int& curPos, byte* pBuffer, int& bufferLen)
 {
        result r = E_SUCCESS;
        result ret = E_SUCCESS;
 
-       Tizen::Io::_IpcBuffer certBufferIpc;
+       Tizen::Base::ByteBuffer certBufferIpc;
 
        ClearLastResult();
 
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
        SysTryReturnResult(NID_SEC_CERT, pBuffer != null, E_INVALID_ARG, "Invalid parameter.");
+       SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
+       SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
 
-       certBufferIpc.pBuffer = null;
-       certBufferIpc.size = 0;
-
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_GetNextCertificate(certificateStoreCtx, bufferLen, &certBufferIpc, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetNextCertificate(certType, curPos, bufferLen, &certBufferIpc, &curPos, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
        SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
 
-       memcpy(pBuffer, certBufferIpc.pBuffer, certBufferIpc.size);
-       bufferLen = certBufferIpc.size;
+       memcpy(pBuffer, certBufferIpc.GetPointer(), certBufferIpc.GetRemaining());
+       bufferLen = certBufferIpc.GetRemaining();
 
        return r;
 }
@@ -206,6 +210,8 @@ _CertServiceProxy::UpdateCaCertificate(int type, byte* pOldCert, int oldCertLen,
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
        SysTryReturnResult(NID_SEC_CERT, ((pOldCert != null) && (oldCertLen > 0)), E_INVALID_ARG, "Invalid input old certificate parameter.");
        SysTryReturnResult(NID_SEC_CERT, ((pNewCert != null) && (newCertLen > 0)), E_INVALID_ARG, "Invalid input new certificate parameter.");
+       SysTryReturnResult(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
+       SysTryReturnResult(NID_SEC_CERT, type < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
 
        oldBufferIpc.pBuffer = pOldCert;
        oldBufferIpc.size = oldCertLen;
@@ -213,7 +219,7 @@ _CertServiceProxy::UpdateCaCertificate(int type, byte* pOldCert, int oldCertLen,
        newBufferIpc.pBuffer = pNewCert;
        newBufferIpc.size = newCertLen;
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_UpdateRootCa(type, oldBufferIpc, newBufferIpc, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_UpdateRootCa(type, oldBufferIpc, newBufferIpc, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -238,7 +244,7 @@ _CertServiceProxy::RemoveCaCertificate(int type, byte* pBuffer, int bufLen)
        certBufferIpc.pBuffer = pBuffer;
        certBufferIpc.size = bufLen;
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_RemoveRootCa(type, certBufferIpc, bufLen, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_RemoveRootCa(type, certBufferIpc, bufLen, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -259,7 +265,7 @@ _CertServiceProxy::RemoveUserCaCertificateByCertId(int certId)
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
        SysTryReturnResult(NID_SEC_CERT, certId >= 1, E_INVALID_ARG, "Invalid input parameter.");
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_UninstallUserRootCertificateByCertId(certId, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_UninstallUserRootCertificateByCertId(certId, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -284,7 +290,7 @@ _CertServiceProxy::InsertCaCertificate(int type, int format, byte* pCert, long c
        certBufferIpc.pBuffer = pCert;
        certBufferIpc.size = certLen;
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_InsertCaCertificate(type, format, certBufferIpc, certLen, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertCaCertificate(type, format, certBufferIpc, certLen, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -309,7 +315,7 @@ _CertServiceProxy::InsertUserCaCertificate(int format, char* pCert, int certLen)
        certBufferIpc.pBuffer = pCert;
        certBufferIpc.size = certLen;
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_InsertUserCaCertificate(format, certBufferIpc, certLen, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertUserCaCertificate(format, certBufferIpc, certLen, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -332,7 +338,7 @@ _CertServiceProxy::InsertUserCaCertificate(byte* pFilePath)
        certBufferIpc.pBuffer = pFilePath;
        certBufferIpc.size = strlen(reinterpret_cast< char* >(pFilePath)) + 1;
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_InstallUserRootCertificate(certBufferIpc, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InstallUserRootCertificate(certBufferIpc, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -362,7 +368,7 @@ _CertServiceProxy::InsertUserCertChainPrivateKey(char* pCertchainBuffer, int cer
        privateKeyBufferIpc.pBuffer = pUserPrivateKey;
        privateKeyBufferIpc.size = userPrivateKeyLen;
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_InsertUserCertChainPrivateKey(certPackBufferIPC, certChainLen, privateKeyBufferIpc, userPrivateKeyLen, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertUserCertChainPrivateKey(certPackBufferIPC, certChainLen, privateKeyBufferIpc, userPrivateKeyLen, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -385,7 +391,7 @@ _CertServiceProxy::InsertCertificateChainWithPrivateKey(char* pCertchainPrivateK
        certChainPriKeyBufferIpc.pBuffer = pCertchainPrivateKeyBuffer;
        certChainPriKeyBufferIpc.size = certChainPrivateKeyLength;
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_InsertCertificateChainWithPrivateKey(certChainPriKeyBufferIpc, certChainPrivateKeyLength, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InsertCertificateChainWithPrivateKey(certChainPriKeyBufferIpc, certChainPrivateKeyLength, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -396,7 +402,7 @@ _CertServiceProxy::InsertCertificateChainWithPrivateKey(char* pCertchainPrivateK
 }
 
 result
-_CertServiceProxy::InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12ImportPassword)
+_CertServiceProxy::InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12ImportPassword, bool checkPrivilege)
 {
        result r = E_SUCCESS;
        result ret = E_SUCCESS;
@@ -412,27 +418,7 @@ _CertServiceProxy::InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12Impor
        pkcs12PasswdBufferIpc.pBuffer = pPkcs12ImportPassword;
        pkcs12PasswdBufferIpc.size = strlen(reinterpret_cast< char* >(pPkcs12ImportPassword)) + 1;
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_InstallPkcs12Content(pkcs12FileBufferIpc, pkcs12PasswdBufferIpc, &ret));
-       SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
-
-       r = __pIpcClient->SendRequest(pMessage.get());
-       SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
-       SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
-
-       return r;
-}
-result
-_CertServiceProxy::RemoveUserCertificateByCertId(int certId)
-{
-       result r = E_SUCCESS;
-       result ret = E_SUCCESS;
-
-       ClearLastResult();
-
-       SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "Instance is not constructed.");
-       SysTryReturnResult(NID_SEC_CERT, certId >= 1, E_INVALID_ARG, "Invalid input parameter.");
-
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_DeleteUserCertificateByCertId(certId, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InstallPkcs12Content(pkcs12FileBufferIpc, pkcs12PasswdBufferIpc, checkPrivilege, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -453,7 +439,7 @@ _CertServiceProxy::RemoveUserCertChainByCertId(int certId)
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "Instance is not constructed.");
        SysTryReturnResult(NID_SEC_CERT, certId >= 1, E_INVALID_ARG, "Invalid input parameter.");
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_DeleteUserCertChainByCertId(certId, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_DeleteUserCertChainByCertId(certId, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -487,7 +473,7 @@ _CertServiceProxy::GetUserCertChainByIssuerAndSubjectNameN(char* pIssuerName, in
 
        memset(pRetNode, 0, sizeof(*pRetNode));
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_GetUserCertChainByIssuerAndSubjectNameN(issuerBufferIpc, issuerNameLen, subjectBufferIpc, subNameLen, pRetNode, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertChainByIssuerAndSubjectNameN(issuerBufferIpc, issuerNameLen, subjectBufferIpc, subNameLen, pRetNode, &ret));
        SysTryReturn(NID_SEC_CERT, pMessage != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -522,7 +508,7 @@ _CertServiceProxy::GetUserCertificateByCertIdN(int certId, int encodingType)
 
        memset(pRetNode, 0, sizeof(*pRetNode));
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_GetUserCertificateByCertIdN(certId, encodingType, pRetNode, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertificateByCertIdN(certId, encodingType, pRetNode, &ret));
        SysTryCatch(NID_SEC_CERT, pMessage != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -550,7 +536,7 @@ _CertServiceProxy::GetUserCertFieldInfoByCertId(int certId, _CertFieldInfos* pCe
        SysTryReturnResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "IPC instance is not constructed.");
        SysTryReturnResult(NID_SEC_CERT, pCertFieldInfos != null, E_INVALID_ARG, "Invalid input parameter.");
 
-       std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) CertService_GetUserCertFieldInfoByCertId(certId, pCertFieldInfos, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetUserCertFieldInfoByCertId(certId, pCertFieldInfos, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -559,4 +545,21 @@ _CertServiceProxy::GetUserCertFieldInfoByCertId(int certId, _CertFieldInfos* pCe
 
        return r;
 }
+
+void
+_CertServiceProxy::RestoreRootCaIntegrity(void)
+{
+       result r = E_SUCCESS;
+
+       ClearLastResult();
+
+       SysTryReturnVoidResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "[%s] IPC instance is not constructed.", GetErrorMessage(E_SYSTEM));
+
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_RestoreRootCaIntegrity());
+       SysTryReturnVoidResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "[%s] Failed to allocate memory.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = __pIpcClient->SendRequest(pMessage.get());
+       SysTryReturnVoidResult(NID_SEC_CERT, !IsFailed(r), r, "[%s] Failed to send message.", GetErrorMessage(r));
+}
+
 } } }