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