2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 * @file task_pkg_info_update.cpp
18 * @author Soyoung Kim (sy037.kim@samsung.com)
20 * @brief Implementation file for installer task information about package
23 #include "task_pkg_info_update.h"
29 #include <dpl/wrt-dao-ro/global_config.h>
30 #include <dpl/foreach.h>
31 #include <dpl/sstream.h>
32 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
33 #include <pkgmgr_installer.h>
34 #include <pkgmgr/pkgmgr_parser.h>
35 #include <pkgmgr-info.h>
36 #include <vcore/CryptoHash.h>
38 #include <widget_install/job_widget_install.h>
39 #include <widget_install/widget_install_context.h>
40 #include <widget_install/widget_install_errors.h>
42 #include <installer_log.h>
44 using namespace WrtDB;
50 namespace WidgetInstall {
51 TaskPkgInfoUpdate::TaskPkgInfoUpdate(InstallerContext& context) :
52 DPL::TaskDecl<TaskPkgInfoUpdate>(this),
55 AddStep(&TaskPkgInfoUpdate::StartStep);
56 AddStep(&TaskPkgInfoUpdate::StepPkgInfo);
57 AddStep(&TaskPkgInfoUpdate::StepSetCertiInfo);
58 AddStep(&TaskPkgInfoUpdate::EndStep);
59 AddStep(&TaskPkgInfoUpdate::StepSetEndofInstallation);
61 AddAbortStep(&TaskPkgInfoUpdate::StepAbortCertiInfo);
62 AddAbortStep(&TaskPkgInfoUpdate::stepAbortParseManifest);
65 void TaskPkgInfoUpdate::StepPkgInfo()
68 char* updateTags[3] = {NULL, };
70 char preloadTrue[] = "preload=true";
71 char removableTrue[] = "removable=true";
72 char removableFalse[] = "removable=false";
74 if (InstallMode::InstallTime::CSC == m_context.mode.installTime) {
75 updateTags[0] = preloadTrue;
76 if (m_context.mode.removable) {
77 updateTags[1] = removableTrue;
79 updateTags[1] = removableFalse;
84 if (m_context.mode.rootPath == InstallMode::RootPath::RO) {
85 m_manifest += "/usr/share/packages/";
87 m_manifest += "/opt/share/packages/";
89 m_manifest += DPL::ToUTF8String(m_context.widgetConfig.tzPkgid) + ".xml";
90 _D("manifest file : %s", m_manifest.c_str());
92 if (m_context.isUpdateMode || (
93 m_context.mode.rootPath == InstallMode::RootPath::RO
94 && m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
95 && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
97 code = pkgmgr_parser_parse_manifest_for_upgrade(
98 m_manifest.c_str(), (updateTags[0] == NULL) ? NULL : updateTags);
101 _E("Manifest parser error: %d", code);
102 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
105 code = pkgmgr_parser_parse_manifest_for_installation(
106 m_manifest.c_str(), (updateTags[0] == NULL) ? NULL : updateTags);
109 _E("Manifest parser error: %d", code);
110 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
114 m_context.job->UpdateProgress(
115 InstallerContext::INSTALL_PKGINFO_UPDATE,
116 "Manifest Update Finished");
117 _D("Manifest parsed");
120 void TaskPkgInfoUpdate::StepSetCertiInfo()
122 _D("StepSetCertiInfo");
124 if (pkgmgr_installer_create_certinfo_set_handle(&m_pkgHandle) < 0) {
125 _E("pkgmgrInstallerCreateCertinfoSetHandle fail");
126 ThrowMsg(Exceptions::SetCertificateInfoFailed,
127 "Failed to create certificate handle");
130 SetCertiInfo(SIGNATURE_AUTHOR);
131 SetCertiInfo(SIGNATURE_DISTRIBUTOR);
133 if ((pkgmgr_installer_save_certinfo(
134 const_cast<char*>(DPL::ToUTF8String(
135 m_context.widgetConfig.tzPkgid).c_str()),
138 _E("pkgmgrInstallerSaveCertinfo fail");
139 ThrowMsg(Exceptions::SetCertificateInfoFailed,
140 "Failed to Installer Save Certinfo");
142 _D("Succeed to save Certinfo");
145 if (pkgmgr_installer_destroy_certinfo_set_handle(m_pkgHandle) < 0) {
146 _E("pkgmgrInstallerDestroyCertinfoSetHandle fail");
150 void TaskPkgInfoUpdate::SetCertiInfo(int source)
152 _D("Set CertiInfo to pkgmgr : %d", source);
153 CertificateChainList certificateChainList;
154 m_context.widgetSecurity.getCertificateChainList(certificateChainList,
155 (CertificateSource)source);
157 FOREACH(it, certificateChainList)
159 _D("Insert certinfo to pkgmgr structure");
161 ValidationCore::CertificateCollection chain;
163 if (false == chain.load(*it)) {
164 _E("Chain is broken");
165 ThrowMsg(Exceptions::SetCertificateInfoFailed,
166 "Failed to Installer Save Certinfo");
170 _E("Chain failed at sorting");
173 ValidationCore::CertificateList list = chain.getCertificateList();
175 FOREACH(certIt, list)
177 pkgmgr_instcert_type instCertType;
179 if (source == SIGNATURE_DISTRIBUTOR) {
180 bool distributor1 = false;
181 if (!(*certIt)->getCommonName().IsNull()) {
183 Name(DPL::ToUTF8String(*(*certIt)->getCommonName()));
184 std::string tizenStr("Tizen");
185 if (0 == Name.compare(0, tizenStr.length(), tizenStr)) {
191 _D("Set SIGNATURE_DISTRIBUTOR");
192 if ((*certIt)->isRootCert()) {
193 instCertType = PM_SET_DISTRIBUTOR_ROOT_CERT;
195 if ((*certIt)->isCA()) {
196 instCertType = PM_SET_DISTRIBUTOR_INTERMEDIATE_CERT;
198 instCertType = PM_SET_DISTRIBUTOR_SIGNER_CERT;
202 _D("Set SIGNATURE_DISTRIBUTOR2");
203 if ((*certIt)->isRootCert()) {
204 instCertType = PM_SET_DISTRIBUTOR2_ROOT_CERT;
206 if ((*certIt)->isCA()) {
207 instCertType = PM_SET_DISTRIBUTOR2_INTERMEDIATE_CERT;
209 instCertType = PM_SET_DISTRIBUTOR2_SIGNER_CERT;
214 _D("set SIGNATURE_AUTHOR");
215 if ((*certIt)->isRootCert()) {
216 instCertType = PM_SET_AUTHOR_ROOT_CERT;
218 if ((*certIt)->isCA()) {
219 instCertType = PM_SET_AUTHOR_INTERMEDIATE_CERT;
221 instCertType = PM_SET_AUTHOR_SIGNER_CERT;
225 _D("cert type : %d", instCertType);
226 if ((pkgmgr_installer_set_cert_value(
229 const_cast<char*>(((*certIt)->getBase64()).c_str()))) < 0)
231 _E("pkgmgrInstallerSetCertValue fail");
232 ThrowMsg(Exceptions::SetCertificateInfoFailed,
233 "Failed to Set CertValue");
239 void TaskPkgInfoUpdate::StepAbortCertiInfo()
241 if ((pkgmgr_installer_delete_certinfo(
242 const_cast<char*>(DPL::ToUTF8String(
243 m_context.widgetConfig.tzPkgid).c_str()))) <
246 _E("pkgmgr_installer_delete_certinfo fail");
250 void TaskPkgInfoUpdate::StartStep()
252 _D("--------- <TaskPkgInfoUpdate> : START ----------");
255 void TaskPkgInfoUpdate::EndStep()
257 m_context.job->UpdateProgress(
258 InstallerContext::INSTALL_SET_CERTINFO,
259 "Save certinfo to pkgmgr");
261 _D("--------- <TaskPkgInfoUpdate> : END ----------");
264 void TaskPkgInfoUpdate::stepAbortParseManifest()
266 _E("[Parse Manifest] Abroting....");
268 int code = pkgmgr_parser_parse_manifest_for_uninstallation(
269 m_manifest.c_str(), NULL);
272 _W("Manifest parser error: %d", code);
273 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
275 int ret = unlink(m_manifest.c_str());
277 _W("No manifest file found: %s", m_manifest.c_str());
281 void TaskPkgInfoUpdate::StepSetEndofInstallation()
283 m_context.job->UpdateProgress(
284 InstallerContext::INSTALL_END,
288 } //namespace WidgetInstall