Installer SignatureValidator implementation
[platform/framework/native/installer.git] / src / Context / InstallationContext.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  * @file        InstallationContext.cpp
19  * @brief       This is the implementation for the InstallerContext class.
20  */
21
22 #include "InstallationContext.h"
23 #include "SystemCheckStep.h"
24 #include "PackageCheckStep.h"
25 #include "ManifestXmlStep.h"
26 #include "LicenseStep.h"
27 #include "SignatureStep.h"
28 #include "DrmStep.h"
29 #include "UninstallStep.h"
30 #include "UnpackStep.h"
31 #include "RdsStep.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Io;
36 using namespace Tizen::Security::Cert;
37 using namespace Tizen::App;
38
39 InstallationContext::InstallationContext(void)
40 :__pStep(null)
41 ,__pDrmLicense(null)
42 ,__error(INSTALLER_ERROR_NONE)
43 ,__step(INSTALLER_STEP_NONE)
44 ,__attributeType(0)
45 ,__state(INSTALLER_STATE_RUNNING)
46 ,__stepChanged(true)
47 ,__continue(true)
48 ,__pAppDataList(null)
49 ,__isOspCompat(false)
50 ,__isPreloaded(false)
51 ,__isHybridService(false)
52 ,__isVerificationMode(false)
53 ,__isUpdated(false)
54 ,__isAppSetting(false)
55 ,__operation(INSTALLER_OPERATION_INSTALL)
56 ,__storage(INSTALLATION_STORAGE_INTERNAL)
57 ,__rootCertType(ROOT_CERTIFICATE_NONE)
58 ,__privilegeLevel(PRIVILEGE_LEVEL_PUBLIC)
59 ,__pApp2ExtHandle(null)
60 ,__pPrivilegeList(null)
61 ,__pStringPrivilegeList(null)
62 ,__pContentDataList(null)
63 ,__pAuthorCertPath(null)
64 ,__pDistributorCertPath(null)
65 ,__pAuthorCertList(null)
66 ,__pDistributorCertList(null)
67 ,__certType(0)
68 {
69 }
70
71 InstallationContext::~InstallationContext(void)
72 {
73         delete __pStep;
74         __pStep = null;
75
76         delete __pDrmLicense;
77         __pDrmLicense = null;
78
79         delete __pAuthorCertPath;
80         __pAuthorCertPath = null;
81
82         delete __pDistributorCertPath;
83         __pDistributorCertPath = null;
84
85         if (__pPrivilegeList)
86         {
87                 __pPrivilegeList->RemoveAll();
88                 delete __pPrivilegeList;
89                 __pPrivilegeList = null;
90         }
91
92         if (__pStringPrivilegeList)
93         {
94                 __pStringPrivilegeList->RemoveAll(true);
95                 delete __pStringPrivilegeList;
96                 __pStringPrivilegeList = null;
97         }
98
99         if (__pAppDataList)
100         {
101                 __pAppDataList->RemoveAll();
102                 delete __pAppDataList;
103         }
104
105         if (__pAuthorCertList)
106         {
107                 __pAuthorCertList->RemoveAll();
108                 delete __pAuthorCertList;
109                 __pAuthorCertList = null;
110         }
111
112         if (__pDistributorCertList)
113         {
114                 __pDistributorCertList->RemoveAll();
115                 delete __pDistributorCertList;
116                 __pDistributorCertList = null;
117         }
118 }
119
120 InstallerError
121 InstallationContext::Construct(void)
122 {
123         __pAppDataList = new (std::nothrow) ArrayListT<AppData*>;
124         TryReturn(__pAppDataList, INSTALLER_ERROR_OUT_OF_MEMORY, "__pAppDataList is null");
125
126         __pAuthorCertList = new (std::nothrow) ArrayListT<String*>;
127         TryReturn(__pAuthorCertList, INSTALLER_ERROR_OUT_OF_MEMORY, "__pAuthorCertList is null.");
128
129         __pDistributorCertList = new (std::nothrow) ArrayListT<String*>;
130         TryReturn(__pDistributorCertList, INSTALLER_ERROR_OUT_OF_MEMORY, "__pDistributorCertList is null.");
131
132         return INSTALLER_ERROR_NONE;
133 }
134
135 bool
136 InstallationContext::ChangeStep(InstallationStep step)
137 {
138         delete __pStep;
139         __pStep = null;
140
141         switch (step)
142         {
143         case INSTALLER_STEP_NONE:
144                 break;
145
146         case INSTALLER_STEP_INIT:
147                 break;
148
149         case INSTALLER_STEP_CHECK_SYSTEM:
150                 __pStep = new (std::nothrow) SystemCheckStep();
151                 TryReturn(__pStep, false, "SystemCheckStep is failed.");
152                 break;
153
154         case INSTALLER_STEP_CHECK_PACKAGE:
155                 __pStep = new (std::nothrow) PackageCheckStep();
156                 TryReturn(__pStep, false, "PackageCheckStep is failed.");
157                 break;
158
159         case INSTALLER_STEP_UNPACK:
160                 __pStep = new (std::nothrow) UnpackStep();
161                 TryReturn(__pStep, false, "UnpackStep is failed.");
162                 break;
163
164         case INSTALLER_STEP_PARSE_MANIFEST:
165                 __pStep = new (std::nothrow) ManifestXmlStep();
166                 TryReturn(__pStep, false, "ManifestXmlStep is failed.");
167                 break;
168
169         case INSTALLER_STEP_PARSE_SIGNATURE:
170                 __pStep = new (std::nothrow) SignatureStep();
171                 TryReturn(__pStep, false, "SignatureStep is failed.");
172                 break;
173
174         case INSTALLER_STEP_UNINSTALL:
175                 __pStep = new (std::nothrow) UninstallStep();
176                 TryReturn(__pStep, false, "UninstallStep is failed.");
177                 break;
178
179         case INSTALLER_STEP_LICENSE:
180                 __pStep = new (std::nothrow) LicenseStep();
181                 TryReturn(__pStep, false, "LicenseStep is failed.");
182                 break;
183
184         case INSTALLER_STEP_DRM:
185                 __pStep = new (std::nothrow) DrmStep();
186                 TryReturn(__pStep, false, "DrmStep is failed.");
187                 break;
188
189         case INSTALLER_STEP_RDS:
190                 __pStep = new (std::nothrow) RdsStep();
191                 TryReturn(__pStep, false, "DrmStep is failed.");
192                 break;
193
194         case INSTALLER_STEP_END:
195                 break;
196
197         default:
198                 break;
199         }
200
201         __step = step;
202         return true;
203 }
204
205 InstallerError
206 InstallationContext::Run(void)
207 {
208         InstallerError error = INSTALLER_ERROR_NONE;
209         AppLog("InstallationContext::Run()");
210         return error;
211 }
212
213 InstallationStep
214 InstallationContext::GetCurrentInstallationStep(void)
215 {
216         return __step;
217 }
218
219 void
220 InstallationContext::SetCurrentInstallationStep(InstallationStep step)
221 {
222         __step = step;
223 }
224
225 InstallerError
226 InstallationContext::GetError(void)
227 {
228         return __error;
229 }
230
231 void
232 InstallationContext::SetError(InstallerError installerError)
233 {
234         __error = installerError;
235 }
236
237 InstallationState
238 InstallationContext::GetState(void)
239 {
240         return __state;
241 }
242
243 void
244 InstallationContext::SetState(InstallationState installationState)
245 {
246         __state = installationState;
247 }
248
249 IInstallationStep*
250 InstallationContext::GetStep(void)
251 {
252         return __pStep;
253 }
254
255 void
256 InstallationContext::SetInstallerOperation(InstallerOperation op)
257 {
258         __operation = op;
259 }
260
261 InstallerOperation
262 InstallationContext::GetInstallerOperation(void) const
263 {
264         return __operation;
265 }
266
267 bool
268 InstallationContext::IsContinue(void)
269 {
270         return __continue;
271 }
272
273 void
274 InstallationContext::SetContinue(bool cont)
275 {
276         __continue = cont;
277 }
278
279 String
280 InstallationContext::GetSignatureXmlPath(void)
281 {
282         String  path;
283
284         path = __installDir + SIGNATURE1_XML_FILE;
285
286         return path;
287 }
288
289 String
290 InstallationContext::GetAuthorSignatureXmlPath(void)
291 {
292         String  path;
293
294         path = __installDir + AUTHOR_SIGNATURE_XML_FILE;
295
296         return path;
297 }
298
299 const ArrayList*
300 InstallationContext::GetPrivilegeList(void) const
301 {
302         return __pPrivilegeList;
303 }
304
305 void
306 InstallationContext::SetPrivilegeList(ArrayList* privilegeList)
307 {
308         __pPrivilegeList = privilegeList;
309 }
310
311 ArrayList*
312 InstallationContext::GetContentDataList(void) const
313 {
314         return __pContentDataList;
315 }
316
317 void
318 InstallationContext::SetContentDataList(ArrayList* pContentDataList)
319 {
320         __pContentDataList = pContentDataList;
321 }
322