Merge "Update GetPackageAppInfoN() API" into tizen_2.1
[platform/framework/native/appfw.git] / src / security / cert / FSecCertX509CertificateStore.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                FSecCertX509CertificateStore.cpp
20  * @brief               This is the implementation file for X509CertificateStore class.
21  */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <new>
25 #include <FBaseResult.h>
26 #include <FSecCertX509CertificateStore.h>
27 #include <FSecCertX509Certificate.h>
28 #include <FBaseSysLog.h>
29 #include <FSecCert_X509CertificateStoreImpl.h>
30 #include <FSec_AccessController.h>
31 #include <FSec_AccessControlTypes.h>
32 #include <FApp_AppInfo.h>
33
34 using namespace Tizen::Base;
35 using namespace Tizen::App;
36
37 namespace Tizen { namespace Security { namespace Cert
38 {
39
40 X509CertificateStore::X509CertificateStore(void)
41         : __pX509CertificateStoreImpl(null)
42 {
43         __pX509CertificateStoreImpl = new (std::nothrow) _X509CertificateStoreImpl();
44         SysTryReturnVoidResult(NID_SEC_CERT, __pX509CertificateStoreImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
45
46 }
47
48 X509CertificateStore::~X509CertificateStore(void)
49 {
50
51         delete __pX509CertificateStoreImpl;
52 }
53
54 result
55 X509CertificateStore::GetName(String& name) const
56 {
57         result r = E_SUCCESS;
58
59         SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
60
61         r = __pX509CertificateStoreImpl->GetName(name);
62         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
63
64         return r;
65 }
66
67 result
68 X509CertificateStore::SetCertificateSelector(const Tizen::Security::Cert::ICertificateSelector& selector)
69 {
70         result r = E_SUCCESS;
71
72         SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Re-construct the object.");
73
74         r = __pX509CertificateStoreImpl->SetCertificateSelector(selector);
75         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
76
77         return r;
78
79 }
80
81 result
82 X509CertificateStore::GetCertificateCount(int& count) const
83 {
84         result r = E_SUCCESS;
85
86         SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
87
88         r = __pX509CertificateStoreImpl->GetCertificateCount(count);
89         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
90
91         return r;
92
93 }
94
95
96 Tizen::Security::Cert::ICertificate*
97 X509CertificateStore::GetNextCertificateN(void) const
98 {
99         result r = E_SUCCESS;
100         ICertificate* pCert = null;
101         ClearLastResult();
102
103         SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
104
105         pCert = __pX509CertificateStoreImpl->GetNextCertificateN();
106         r = GetLastResult();
107         SysTryReturn(NID_SEC_CERT, pCert != null, null, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
108
109         return pCert;
110 }
111
112
113 result
114 X509CertificateStore::Insert(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& certificate)
115 {
116         result r = E_SUCCESS;
117
118         SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
119
120         r = __pX509CertificateStoreImpl->Insert(certificateType, certificate);
121         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
122
123         return r;
124 }
125
126
127 result
128 X509CertificateStore::InsertPkcs12(const String& filePath, const String& password)
129 {
130         result r = E_SUCCESS;
131
132         SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
133
134         r = __pX509CertificateStoreImpl->InsertPkcs12(filePath, password);
135         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
136
137         return r;
138 }
139
140
141 result
142 X509CertificateStore::Update(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& oldCert, const Tizen::Security::Cert::ICertificate& newCert)
143 {
144         result r = E_SUCCESS;
145
146         SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
147
148         r = __pX509CertificateStoreImpl->Update(certificateType, oldCert, newCert);
149         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
150
151         return r;
152
153 }
154
155
156 result
157 X509CertificateStore::Remove(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& certificate)
158 {
159         result r = E_SUCCESS;
160
161         SysAssertf(__pX509CertificateStoreImpl != null, "Not yet constructed. Reconstructor the object.");
162
163         r = __pX509CertificateStoreImpl->Remove(certificateType, certificate);
164         SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] An internal system error occurred.", GetErrorMessage(r));
165
166         return r;
167 }
168
169 } } }       // Tizen::Security::Cert