Modify to check verification mode
[framework/osp/installer.git] / src / Step / PackageCheckStep.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                PackageCheckStep.cpp
19  * @brief       This is the implementation file for %PackageCheckStep class.
20  */
21
22 #include <FIoFile.h>
23 #include <FIoDirectory.h>
24
25 #include "InstallationContext.h"
26 #include "PackageCheckStep.h"
27 #include "InstallerUtil.h"
28
29 using namespace Osp::Base;
30 using namespace Osp::Base::Utility;
31 using namespace Osp::Io;
32
33 PackageCheckStep::PackageCheckStep(void)
34 :__state(STATE_PACKAGE_CHECK)
35 ,__pContext(null)
36 {
37 }
38
39 PackageCheckStep::~PackageCheckStep(void)
40 {
41 }
42
43 InstallerError
44 PackageCheckStep::Run(InstallationContext* pContext)
45 {
46         InstallerError error = INSTALLER_ERROR_NONE;
47         AppLogTag(OSP_INSTALLER, "------------------------------------------");
48         AppLogTag(OSP_INSTALLER, " PackageCheckStep - START");
49         AppLogTag(OSP_INSTALLER, "------------------------------------------");
50
51         __pContext = pContext;
52
53         while (true)
54         {
55                 switch (__state)
56                 {
57                 case STATE_PACKAGE_CHECK:
58                         AppLogTag(OSP_INSTALLER, "[STATE_PACKAGE_CHECK]");
59                         error = OnStatePackageCheck();
60                         break;
61
62                 case STATE_DONE:
63                         AppLogTag(OSP_INSTALLER, "[STATE_DONE]");
64                         error = OnStateDone();
65                         break;
66
67                 default:
68                         break;
69                 }
70
71                 if (error != INSTALLER_ERROR_NONE)
72                 {
73                         fprintf(stderr, "PackageCheckStep::Run - ErrorType [%d]\n", error);
74                         break;
75                 }
76
77                 if (__state > STATE_DONE)
78                 {
79                         AppLogTag(OSP_INSTALLER, "------------------------------------------");
80                         AppLogTag(OSP_INSTALLER, " PackageCheckStep - END");
81                         AppLogTag(OSP_INSTALLER, "------------------------------------------");
82                         break;
83                 }
84         }
85
86         return error;
87 }
88
89 void
90 PackageCheckStep::GoNextState(void)
91 {
92         __state++;
93 }
94
95 InstallerError
96 PackageCheckStep::OnStatePackageCheck(void)
97 {
98         InstallerError error = INSTALLER_ERROR_NONE;
99         String tempDir;
100
101         if (__pContext->GetInstallationStorage() == InstallationContext::INSTALLATION_STORAGE_INTERNAL)
102         {
103                 tempDir = DIR_OSP_APPLICATIONS_TEMP;
104         }
105         else
106         {
107                 tempDir = DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP;
108         }
109
110         __pContext->SetTemporaryDir(tempDir);
111         __pContext->SetInstallDir(tempDir);
112
113         if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == false)
114         {
115                 result r = E_SUCCESS;
116                 r = Directory::Create(DIR_OSP_APPLICATIONS_TEMP, false);
117                 TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed");
118         }
119
120         String packagePath = __pContext->GetPackagePath();
121         if (InstallerUtil::IsDrmFile(packagePath) == true)
122         {
123                 bool res = false;
124                 res = InstallerUtil::DecryptPackage(packagePath);
125                 TryReturn(res == true, INSTALLER_ERROR_DRM, "[osp-installer] InstallerUtil::DecryptPackage() failed");
126         }
127
128         FileUnzipper unzipper;
129         unzipper.Construct(packagePath);
130
131         AppLogTag(OSP_INSTALLER, "UnzipTo(manifest.xml) - START");
132         unzipper.UnzipTo(tempDir, L"info/manifest.xml");
133         unzipper.UnzipTo(tempDir, L"signature1.xml");
134         unzipper.UnzipTo(tempDir, L"author-signature.xml");
135         AppLogTag(OSP_INSTALLER, "UnzipTo(manifest.xml) - END");
136
137         if ((File::IsFileExist(__pContext->GetSignatureXmlPath()) == true) &&
138                         (File::IsFileExist(__pContext->GetAuthorSignatureXmlPath()) == true))
139         {
140                 AppLogTag(OSP_INSTALLER, "[VerifySignature] VerificationMode ON");
141                 __pContext->SetVerificationMode(true);
142         }
143
144         GoNextState();
145         return error;
146 }
147
148 InstallerError
149 PackageCheckStep::OnStateDone(void)
150 {
151         InstallerError error = INSTALLER_ERROR_NONE;
152
153         GoNextState();
154         return error;
155 }