2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSecCertX509CertificateStore.cpp
19 * @brief This is the implementation file for X509CertificateStore class.
24 #include <FBaseResult.h>
25 #include <FSecCertX509CertificateStore.h>
26 #include <FSecCertX509Certificate.h>
27 #include <FBaseSysLog.h>
28 #include <FSecCert_X509CertificateStoreImpl.h>
29 #include <FSec_AccessController.h>
30 #include <FSec_AccessControlTypes.h>
31 #include <FApp_AppInfo.h>
33 using namespace Tizen::Base;
34 using namespace Tizen::App;
36 namespace Tizen { namespace Security { namespace Cert
39 X509CertificateStore::X509CertificateStore(void)
40 : __pX509CertificateStoreImpl(null)
42 __pX509CertificateStoreImpl = new (std::nothrow) _X509CertificateStoreImpl();
43 SysTryReturnVoidResult(NID_SEC_CERT, __pX509CertificateStoreImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
47 X509CertificateStore::~X509CertificateStore(void)
50 delete __pX509CertificateStoreImpl;
54 X509CertificateStore::GetName(String& name) const
58 SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
60 r = _AccessController::CheckUserPrivilege(_PRV_CERTIFICATE_READ);
61 SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
63 r = __pX509CertificateStoreImpl->GetName(name);
64 SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
70 X509CertificateStore::SetCertificateSelector(const Tizen::Security::Cert::ICertificateSelector& selector)
74 SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Re-construct the object.");
76 if (selector.GetType() != USER_CERT)
78 r = _AccessController::CheckUserPrivilege(_PRV_CERTIFICATE_READ);
79 SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
81 r = __pX509CertificateStoreImpl->SetCertificateSelector(selector);
82 SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
89 X509CertificateStore::GetCertificateCount(int& count) const
93 SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
95 r = __pX509CertificateStoreImpl->GetCertificateCount(count);
96 SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
103 Tizen::Security::Cert::ICertificate*
104 X509CertificateStore::GetNextCertificateN(void) const
106 result r = E_SUCCESS;
107 ICertificate* pCert = null;
110 SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
112 pCert = __pX509CertificateStoreImpl->GetNextCertificateN();
114 SysTryReturn(NID_SEC_CERT, pCert != null, null, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
121 X509CertificateStore::Insert(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& certificate)
123 result r = E_SUCCESS;
125 SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
127 r = __pX509CertificateStoreImpl->Insert(certificateType, certificate);
128 SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
135 X509CertificateStore::InsertPkcs12(const String& filePath, const String& password)
137 result r = E_SUCCESS;
139 SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
141 r = __pX509CertificateStoreImpl->InsertPkcs12(filePath, password);
142 SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
149 X509CertificateStore::Update(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& oldCert, const Tizen::Security::Cert::ICertificate& newCert)
151 result r = E_SUCCESS;
153 SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
155 r = __pX509CertificateStoreImpl->Update(certificateType, oldCert, newCert);
156 SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
164 X509CertificateStore::Remove(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& certificate)
166 result r = E_SUCCESS;
168 SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
170 r = __pX509CertificateStoreImpl->Remove(certificateType, certificate);
171 SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
176 } } } // Tizen::Security::Cert