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_certify.cpp
18 * @author Pawel Sikorski (p.sikorski@samgsung.com)
26 #include <dpl/assert.h>
27 #include <appcore-common.h> //TODO is it necessary here?
31 #include <widget_install/task_certify.h>
32 #include <widget_install/job_widget_install.h>
33 #include <widget_install/widget_install_errors.h>
34 #include <widget_install/widget_install_context.h>
35 #include <dpl/log/log.h>
36 #include <wrt_error.h>
37 #include <dpl/wrt-dao-ro/global_config.h>
38 #include "wac_widget_id.h"
40 #include <vcore/Certificate.h>
41 #include <vcore/SignatureReader.h>
42 #include <vcore/SignatureFinder.h>
43 #include <vcore/WrtSignatureValidator.h>
44 #include <vcore/DeveloperModeValidator.h>
45 #include <dpl/utils/wrt_global_settings.h>
46 #include <dpl/wrt-dao-ro/global_dao_read_only.h>
48 #include <ITapiModem.h>
49 #include <tapi_common.h>
51 using namespace ValidationCore;
52 using namespace WrtDB;
55 const std::string LABEL_NEW_LINE = "<br>";
56 const std::string LABEL_NEW_LINE_2 = "<br><br>";
57 const std::string UNTRUSTED_WIDGET ="It is an Untrusted Widget";
58 const char *QUESTION ="Do you wanto to install?";
60 WidgetCertificateData toWidgetCertificateData(const SignatureData &data,
63 WidgetCertificateData result;
65 result.chainId = data.getSignatureNumber();
67 result.owner = data.isAuthorSignature() ?
68 WidgetCertificateData::AUTHOR : WidgetCertificateData::DISTRIBUTOR;
71 WidgetCertificateData::ROOT : WidgetCertificateData::ENDENTITY;
73 CertificatePtr certificate;
76 certificate = data.getRootCaCertificatePtr();
78 certificate = data.getEndEntityCertificatePtr();
81 Assert(certificate && !certificate->getCommonName().IsNull() &&
82 "CommonName is Null");
84 result.strCommonName = *certificate->getCommonName();
86 result.strMD5Fingerprint = std::string("md5 ") +
87 Certificate::FingerprintToColonHex(
88 certificate->getFingerprint(Certificate::FINGERPRINT_MD5));
90 result.strSHA1Fingerprint = std::string("sha-1 ") +
91 Certificate::FingerprintToColonHex(
92 certificate->getFingerprint(Certificate::FINGERPRINT_SHA1));
96 } // namespace anonymous
99 namespace WidgetInstall {
100 TaskCertify::TaskCertify(InstallerContext &inCont) :
101 DPL::TaskDecl<TaskCertify>(this),
102 m_contextData(inCont),
103 WidgetInstallPopup(inCont)
105 /* This is temporary comment for certi error
106 After security-server, cert-svc release, should remove comment
107 AddStep(&TaskCertify::stepSignature);
110 // Block until fixed popup issues
111 if (!GlobalSettings::PopupsTestModeEnabled()
112 && !m_installContext.m_quiet && !isTizenWebApp()) {
113 AddStep(&TaskCertify::stepWarningPopup);
114 AddStep(&TaskCertify::stepWarningPopupAnswer);
115 AddStep(&TaskCertify::stepAuthorInfoPopup);
116 AddStep(&TaskCertify::stepAuthorInfoPopupAnswer);
117 AddStep(&TaskCertify::StepDeletePopupWin);
119 AddStep(&TaskCertify::stepFinalize);
122 void TaskCertify::processDistributorSignature(const SignatureData &data,
125 // this signature is verified -
126 // no point in check domain WAC_ROOT and WAC_RECOGNIZED
127 m_contextData.wacSecurity.setDistributorSigned(true);
129 if (data.getStorageType().contains(CertStoreId::WAC_ROOT)) {
130 m_contextData.wacSecurity.setWacSigned(true);
133 CertificateCollection collection;
134 collection.load(data.getCertList());
136 Assert(collection.isChain() &&
137 "Certificate collection is not able to create chain. "
138 "It is not possible to verify this signature.");
140 m_contextData.wacSecurity.getCertificateChainListRef().push_back(
144 m_contextData.wacSecurity.getCertificateListRef().push_back(
145 toWidgetCertificateData(data, true));
146 m_contextData.wacSecurity.getCertificateListRef().push_back(
147 toWidgetCertificateData(data, false));
151 void TaskCertify::processAuthorSignature(const SignatureData &data)
153 using namespace ValidationCore;
154 LogInfo("DNS Identity match!");
155 // this signature is verified or widget is distributor signed
156 m_contextData.wacSecurity.getAuthorCertificatePtr() =
157 data.getEndEntityCertificatePtr();
158 m_contextData.wacSecurity.getCertificateListRef().push_back(
159 toWidgetCertificateData(data, true));
160 m_contextData.wacSecurity.getCertificateListRef().push_back(
161 toWidgetCertificateData(data, false));
163 // match widget_id with one from dns identity set
164 WacWidgetId widgetId(m_contextData.widgetConfig.configInfo.widget_id);
166 CertificatePtr cert = data.getEndEntityCertificatePtr();
168 Certificate::AltNameSet dnsIdentity = cert->getAlternativeNameDNS();
170 CertificateCollection collection;
171 collection.load(data.getCertList());
173 Assert(collection.isChain() &&
174 "Certificate collection is not able to create chain. "
175 "It is not possible to verify this signature.");
177 m_contextData.wacSecurity.getAuthorsCertificateChainListRef().push_back(
180 FOREACH(it, dnsIdentity){
181 if (widgetId.matchHost(*it)) {
182 m_contextData.wacSecurity.setRecognized(true);
188 void TaskCertify::stepSignature()
190 LogInfo("================ Step: <<Signature>> ENTER ===============");
192 std::string widgetPath = m_contextData.locations->getTemporaryRootDir() + "/";
194 SignatureFileInfoSet signatureFiles;
195 SignatureFinder signatureFinder(widgetPath);
196 if (SignatureFinder::NO_ERROR != signatureFinder.find(signatureFiles)) {
197 LogError("Error in Signature Finder");
198 ThrowMsg(Exceptions::InvalidPackage,
199 "Error openig temporary widget directory");
202 SignatureFileInfoSet::reverse_iterator iter = signatureFiles.rbegin();
203 LogInfo("Number of signatures: " << signatureFiles.size());
205 bool firstDistributorSignature = true;
206 bool testCertificate = false;
208 bool complianceMode = GlobalDAOReadOnly::getComplianceMode();
210 for (; iter != signatureFiles.rend(); ++iter) {
211 LogInfo("Checking signature with id=" << iter->getFileNumber());
212 SignatureData data(widgetPath + iter->getFileName(),
213 iter->getFileNumber());
217 xml.initialize(data, GlobalConfig::GetSignatureXmlSchema());
220 WrtSignatureValidator::AppType appType = WrtSignatureValidator::WAC20;
222 if (m_installContext.widgetConfig.webAppType == APP_TYPE_TIZENWEBAPP) {
223 appType = WrtSignatureValidator::TIZEN;
226 WrtSignatureValidator validator(
228 !GlobalSettings::OCSPTestModeEnabled(),
229 !GlobalSettings::CrlTestModeEnabled(),
232 WrtSignatureValidator::Result result =
233 validator.check(data, widgetPath);
235 if (result == WrtSignatureValidator::SIGNATURE_REVOKED) {
236 LogWarning("Certificate is REVOKED");
237 ThrowMsg(Exceptions::InvalidPackage,
238 "Certificate is REVOKED");
241 if (result == WrtSignatureValidator::SIGNATURE_INVALID) {
242 LogWarning("Signature is INVALID");
243 // TODO change exception name
244 ThrowMsg(Exceptions::InvalidPackage,
248 if (data.isAuthorSignature()) {
249 if (result == WrtSignatureValidator::SIGNATURE_VERIFIED ||
250 m_contextData.wacSecurity.isDistributorSigned())
252 processAuthorSignature(data);
253 } else if (result == WrtSignatureValidator::SIGNATURE_DISREGARD) {
257 if (result == WrtSignatureValidator::SIGNATURE_DISREGARD) {
260 // now signature _must_ be verified
261 processDistributorSignature(data, firstDistributorSignature);
262 firstDistributorSignature = false;
265 bool developerMode = GlobalDAOReadOnly::GetDeveloperMode();
267 std::string realMEID;
268 TapiHandle *tapiHandle = tel_init(NULL);
269 char *meid = tel_get_misc_me_sn_sync(tapiHandle);
275 tel_deinit(tapiHandle);
277 DeveloperModeValidator developerModeValidator(
280 GlobalDAOReadOnly::getComplianceFakeImei(),
281 GlobalDAOReadOnly::getComplianceFakeMeid(),
284 developerModeValidator.check(data);
287 data.getStorageType().contains(CertStoreId::DEVELOPER);
289 if (testCertificate && !developerMode) {
290 LogError("Widget signed by test certificate, "
291 "but developer mode is off.");
292 ThrowMsg(Exceptions::InvalidPackage,
293 "Widget signed by test certificate, "
294 "but developer mode is off.");
296 m_contextData.widgetConfig.isTestWidget = testCertificate;
297 } Catch(ParserSchemaException::Base) {
298 LogError("Error occured in ParserSchema.");
299 ReThrowMsg(Exceptions::InvalidPackage,
300 "Error occured in ParserSchema.");
302 Catch(DeveloperModeValidator::Exception::Base) {
303 LogError("Cannot validate developer certificate.");
304 ReThrowMsg(Exceptions::InvalidPackage,
305 "Cannot validate developer certificate.");
309 if (signatureFiles.empty()) {
310 LogInfo("No signature files has been found.");
313 LogInfo("================ Step: <<Signature>> DONE ================");
315 m_contextData.job->UpdateProgress(
316 InstallerContext::INSTALL_DIGSIG_CHECK,
317 "Widget Signature checked");
320 void TaskCertify::createInstallPopup(PopupType type, const std::string &label)
322 m_contextData.job->Pause();
325 bool ret = createPopup();
328 loadPopup(type, label);
332 void TaskCertify::StepDeletePopupWin()
337 void TaskCertify::stepWarningPopup()
339 LogInfo("Step:: <<Warning Popup>>");
340 // SP-2151: If widget is not recognized (OCSP status of any of certificates
341 // it is signed with is not recognized) WRT must notify user that
342 // widget cannot be installed as a trusted application, and let the
343 // user decide whether it should be installed as an untrusted
345 if (!m_contextData.wacSecurity.isDistributorSigned()) {
346 std::string label = UNTRUSTED_WIDGET +
349 createInstallPopup(PopupType::WIDGET_UNRECOGNIZED, label);
353 std::string TaskCertify::createAuthorWidgetInfo() const
355 std::string authorInfo;
356 if (m_contextData.wacSecurity.isRecognized()) {
357 //authorInfo += _("IDS_IM_WIDGET_RECOGNISED");
358 authorInfo += _("WIDGET RECOGNISED");
360 //authorInfo += _("IDS_IM_WIDGET_UNRECOGNISED");
361 authorInfo += _("WIDGET UNRECOGNISED");
364 authorInfo += LABEL_NEW_LINE_2;
365 ValidationCore::CertificatePtr authorCert =
366 m_contextData.wacSecurity.getAuthorCertificatePtr();
368 DPL::Optional < DPL::String > organizationName =
369 authorCert->getOrganizationName();
371 //authorInfo += _("IDS_IM_WIDGET_AUTHOR_ORGANIZATION_NAME");
372 authorInfo += _("AUTHOR ORGANIZATION NAME");
373 authorInfo += LABEL_NEW_LINE;
375 if (!organizationName.IsNull()) {
376 authorInfo += DPL::ToUTF8String(*organizationName);
378 //authorInfo += _("IDS_IM_WIDGET_ORGANIZATION_UNKNOWN");
379 authorInfo += _("WIDGET ORGANIZATION UNKNOWN");
382 authorInfo += LABEL_NEW_LINE_2;
384 DPL::Optional < DPL::String > countryName =
385 authorCert->getCountryName();
387 //authorInfo += _("IDS_IM_WIDGET_COUNTRY_NAME");
388 authorInfo += _("WIDGET COUNTRY NAME");
389 authorInfo += LABEL_NEW_LINE;
391 if (!countryName.IsNull()) {
392 authorInfo += DPL::ToUTF8String(*countryName);
394 //authorInfo += _("IDS_IM_WIDGET_COUNTRY_UNKNOWN");
395 authorInfo += _("WIDGET COUNTRY UNKNOWN");
399 //_("IDS_IM_WIDGET_DOES_NOT_CONTAIN_RECOGNIZED_AUTHOR_SIGNATURE");
400 _("Widget does not contain recognized author signature");
405 void TaskCertify::stepAuthorInfoPopup()
407 LogInfo("Step:: <<Author Popup Information>>");
409 = createAuthorWidgetInfo() + LABEL_NEW_LINE_2 + QUESTION;
410 createInstallPopup(PopupType::WIDGET_AUTHOR_INFO, label);
413 void TaskCertify::stepFinalize()
415 LogInfo("Step: <<CERTYFYING DONE>>");
417 m_contextData.job->UpdateProgress(
418 InstallerContext::INSTALL_CERT_CHECK,
419 "Widget Certification Check Finished");
423 void TaskCertify::stepWarningPopupAnswer()
425 LogInfo("Step: <<Warning Popup Answer>>");
426 if (false == m_contextData.wacSecurity.isDistributorSigned() &&
427 WRT_POPUP_BUTTON_CANCEL == m_installCancel)
429 LogWarning("User does not agreed to install unsigned widgets!");
430 m_installCancel = WRT_POPUP_BUTTON;
432 ThrowMsg(Exceptions::NotAllowed, "Widget not allowed");
436 void TaskCertify::stepAuthorInfoPopupAnswer()
438 LogInfo("Step: <<Author Info Popup Answer>>");
439 if ( WRT_POPUP_BUTTON_CANCEL == m_installCancel) {
440 LogWarning("User does not agreed to install widget!");
441 m_installCancel = WRT_POPUP_BUTTON;
443 ThrowMsg(Exceptions::NotAllowed, "Widget not allowed");
447 bool TaskCertify::isTizenWebApp() const
450 if (m_installContext.widgetConfig.webAppType.appType
451 == WrtDB::AppType::APP_TYPE_TIZENWEBAPP)
456 } //namespace WidgetInstall