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_certificates.cpp
18 * @author Leerang Song(leerang.song@samsung.com)
20 * @brief Implementation file for installer task certificates
22 #include <widget_install/task_certificates.h>
23 #include <widget_install/widget_install_context.h>
24 #include <widget_install/widget_install_errors.h>
25 #include <widget_install/job_widget_install.h>
26 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
27 #include <pkgmgr_installer.h>
28 #include <vcore/CryptoHash.h>
30 #include <dpl/log/log.h>
33 #include <dpl/foreach.h>
34 #include <dpl/sstream.h>
36 using namespace WrtDB;
39 namespace WidgetInstall {
41 TaskCertificates::TaskCertificates(InstallerContext& context) :
42 DPL::TaskDecl<TaskCertificates>(this),
45 AddStep(&TaskCertificates::StepSetCertiInfo);
46 AddAbortStep(&TaskCertificates::StepAbortCertiInfo);
49 void TaskCertificates::StepSetCertiInfo()
51 LogDebug("StepSetCertiInfo");
53 if (pkgmgr_installer_create_certinfo_set_handle(&m_pkgHandle) < 0) {
54 LogError("pkgmgrInstallerCreateCertinfoSetHandle fail");
55 ThrowMsg(Exceptions::SetCertificateInfoFailed,
56 "Failed to create certificate handle");
59 SetCertiInfo(SIGNATURE_AUTHOR);
60 SetCertiInfo(SIGNATURE_DISTRIBUTOR);
62 if ((pkgmgr_installer_save_certinfo(
63 const_cast<char*>(DPL::ToUTF8String(
64 *m_context.widgetConfig.pkgname).c_str()),
66 LogError("pkgmgrInstallerSaveCertinfo fail");
67 ThrowMsg(Exceptions::SetCertificateInfoFailed,
68 "Failed to Installer Save Certinfo");
70 LogDebug("Succeed to save Certinfo");
73 if (pkgmgr_installer_destroy_certinfo_set_handle(m_pkgHandle) < 0) {
74 LogError("pkgmgrInstallerDestroyCertinfoSetHandle fail");
78 void TaskCertificates::SetCertiInfo(CertificateSource source)
80 LogDebug("Set CertiInfo to pkgmgr : " << source);
81 CertificateChainList certificateChainList;
82 m_context.wacSecurity.getCertificateChainList(certificateChainList, source);
84 FOREACH(it, certificateChainList)
86 LogDebug("Insert certinfo to pkgmgr db");
88 ValidationCore::CertificateCollection chain;
89 if (false == chain.load(*it)) {
90 LogError("Chain is broken");
95 ValidationCore::CertificateList list = chain.getCertificateList();
100 ValidationCore::Crypto::Hash::SHA1 sha1;
101 sha1.Append((*certIt)->getDER());
103 std::string sha1String = sha1.ToBase64String();
105 if ((*certIt)->isRootCert()) {
106 if (source == SIGNATURE_DISTRIBUTOR) {
107 LogDebug("Set SIGNATURE_DISTRIBUTOR ");
108 if((pkgmgr_installer_set_cert_value(
110 PM_SET_DISTRIBUTOR_ROOT_CERT,
111 const_cast<char*>(sha1String.c_str()))) < 0) {
112 LogError("pkgmgrInstallerSetCertValue fail");
113 ThrowMsg(Exceptions::SetCertificateInfoFailed,
114 "Failed to Set CertValue");
118 LogDebug("set SIGNATURE_AUTHOR");
119 if((pkgmgr_installer_set_cert_value(
121 PM_SET_AUTHOR_ROOT_CERT,
122 const_cast<char*>(sha1String.c_str()))) < 0) {
123 LogError("pkgmgrInstallerSetCertValue fail");
124 ThrowMsg(Exceptions::SetCertificateInfoFailed,
125 "Failed to Installer Set CertValue");
133 void TaskCertificates::StepAbortCertiInfo()
135 if ((pkgmgr_installer_delete_certinfo(
136 const_cast<char*>(DPL::ToUTF8String(
137 *m_context.widgetConfig.pkgname).c_str()))) < 0) {
138 LogError("pkgmgr_installer_delete_certinfo fail");
142 } //namespace WidgetInstall