//SYSTEM INCLUDES
#include <cstring>
#include <string>
+#include <sstream>
#include <dpl/assert.h>
-#include <dpl/event/nested_loop.h>
#include <appcore-common.h> //TODO is it necessary here?
#include <pcrecpp.h>
#include <widget_install/widget_install_errors.h>
#include <widget_install/widget_install_context.h>
#include <dpl/log/log.h>
-#include <wrt_error.h>
#include <dpl/wrt-dao-ro/global_config.h>
#include "wac_widget_id.h"
+#include <vcore/Certificate.h>
#include <vcore/SignatureReader.h>
#include <vcore/SignatureFinder.h>
-#include <vcore/SignatureValidator.h>
-#include <vcore/DeveloperModeValidator.h>
+#include <vcore/WrtSignatureValidator.h>
#include <dpl/utils/wrt_global_settings.h>
#include <dpl/wrt-dao-ro/global_dao_read_only.h>
+#include <ITapiModem.h>
+#include <tapi_common.h>
+
using namespace ValidationCore;
using namespace WrtDB;
namespace {
-enum ButtonId
-{
- BUTTON_ID_INSTALL,
- BUTTON_ID_RESIGN
-};
-
-const std::string LABEL_NEW_LINE = "<br>";
-const std::string LABEL_NEW_LINE_2 = "<br><br>";
WidgetCertificateData toWidgetCertificateData(const SignatureData &data,
bool root)
WidgetCertificateData result;
result.chainId = data.getSignatureNumber();
+ LogDebug("result.chainId : " << result.chainId);
result.owner = data.isAuthorSignature() ?
WidgetCertificateData::AUTHOR : WidgetCertificateData::DISTRIBUTOR;
certificate = data.getEndEntityCertificatePtr();
}
- Assert(!certificate->getCommonName().IsNull() && "CommonName is Null");
+ Assert(certificate && !certificate->getCommonName().IsNull() &&
+ "CommonName is Null");
result.strCommonName = *certificate->getCommonName();
result.strMD5Fingerprint = std::string("md5 ") +
- SignatureValidator::FingerprintToColonHex(
+ Certificate::FingerprintToColonHex(
certificate->getFingerprint(Certificate::FINGERPRINT_MD5));
result.strSHA1Fingerprint = std::string("sha-1 ") +
- SignatureValidator::FingerprintToColonHex(
+ Certificate::FingerprintToColonHex(
certificate->getFingerprint(Certificate::FINGERPRINT_SHA1));
return result;
}
+
+CertificatePtr getOldAuthorSignerCertificate(DPL::String appid)
+{
+ WidgetDAOReadOnly dao(appid);
+ CertificateChainList chainList = dao.getWidgetCertificate(SIGNATURE_AUTHOR);
+
+ FOREACH(it, chainList)
+ {
+ ValidationCore::CertificateCollection chain;
+ if (false == chain.load(*it)) {
+ LogError("Chain is broken");
+ }
+
+ if (!chain.sort()) {
+ LogError("Chain failed at sorting");
+ }
+
+ ValidationCore::CertificateList list = chain.getCertificateList();
+
+ FOREACH(cert, list)
+ {
+ if (!(*cert)->isRootCert() && !(*cert)->isCA()) {
+ return *cert;
+ }
+ }
+ }
+ return CertificatePtr(NULL);
+}
} // namespace anonymous
namespace Jobs {
namespace WidgetInstall {
TaskCertify::TaskCertify(InstallerContext &inCont) :
DPL::TaskDecl<TaskCertify>(this),
- m_contextData(inCont),
- m_cancelInstallation(false),
- m_userAgreedToInstallUntrustedWidget(false)
+ m_contextData(inCont)
{
+ AddStep(&TaskCertify::StartStep);
AddStep(&TaskCertify::stepSignature);
- AddStep(&TaskCertify::stepWarningPopup);
- AddStep(&TaskCertify::stepWarningPopupAnswer);
- AddStep(&TaskCertify::stepAuthorInfoPopup);
- AddStep(&TaskCertify::stepAuthorInfoPopupAnswer);
- AddStep(&TaskCertify::stepFinalize);
-}
-
-TaskCertify::~TaskCertify()
-{
+ // certi comparison determines whether the update.
+ if (true == m_contextData.isUpdateMode) {
+ AddStep(&TaskCertify::stepVerifyUpdate);
+ }
+ AddStep(&TaskCertify::EndStep);
}
-void TaskCertify::processDistributorSignature(const SignatureData &data,
- bool first)
+void TaskCertify::processDistributorSignature(const SignatureData &data)
{
// this signature is verified -
// no point in check domain WAC_ROOT and WAC_RECOGNIZED
- m_contextData.wacSecurity.setDistributorSigned(true);
-
- if (data.getStorageType().contains(CertStoreId::WAC_ROOT)) {
- m_contextData.wacSecurity.setWacSigned(true);
- }
+ m_contextData.widgetSecurity.setDistributorSigned(true);
CertificateCollection collection;
collection.load(data.getCertList());
- collection.sort();
+ Assert(collection.sort() &&
+ "Certificate collection can't sort");
+
Assert(collection.isChain() &&
"Certificate collection is not able to create chain. "
"It is not possible to verify this signature.");
- m_contextData.wacSecurity.getCertificateChainListRef().push_back(
- collection);
+ m_contextData.widgetSecurity.getCertificateChainListRef().push_back(
+ collection);
- if (first) {
- m_contextData.wacSecurity.getCertificateListRef().push_back(
+ if (data.getSignatureNumber() == 1) {
+ m_contextData.widgetSecurity.getCertificateListRef().push_back(
toWidgetCertificateData(data, true));
- m_contextData.wacSecurity.getCertificateListRef().push_back(
+ m_contextData.widgetSecurity.getCertificateListRef().push_back(
toWidgetCertificateData(data, false));
}
}
void TaskCertify::processAuthorSignature(const SignatureData &data)
{
using namespace ValidationCore;
- LogInfo("DNS Identity match!");
+ LogDebug("DNS Identity match!");
// this signature is verified or widget is distributor signed
- m_contextData.wacSecurity.getAuthorCertificatePtr() =
- data.getEndEntityCertificatePtr();
- m_contextData.wacSecurity.getCertificateListRef().push_back(
+ m_contextData.widgetSecurity.setAuthorCertificatePtr(data.getEndEntityCertificatePtr());
+ CertificatePtr test = m_contextData.widgetSecurity.getAuthorCertificatePtr();
+
+ m_contextData.widgetSecurity.getCertificateListRef().push_back(
toWidgetCertificateData(data, true));
- m_contextData.wacSecurity.getCertificateListRef().push_back(
+ m_contextData.widgetSecurity.getCertificateListRef().push_back(
toWidgetCertificateData(data, false));
// match widget_id with one from dns identity set
WacWidgetId widgetId(m_contextData.widgetConfig.configInfo.widget_id);
- Certificate::AltNameSet dnsIdentity =
- data.getEndEntityCertificatePtr()->getAlternativeNameDNS();
+ CertificatePtr cert = data.getEndEntityCertificatePtr();
+ Assert(cert);
+ Certificate::AltNameSet dnsIdentity = cert->getAlternativeNameDNS();
+
+ CertificateCollection collection;
+ collection.load(data.getCertList());
+ collection.sort();
+ Assert(collection.isChain() &&
+ "Certificate collection is not able to create chain. "
+ "It is not possible to verify this signature.");
+
+ m_contextData.widgetSecurity.getAuthorsCertificateChainListRef().push_back(
+ collection);
FOREACH(it, dnsIdentity){
if (widgetId.matchHost(*it)) {
- m_contextData.wacSecurity.setRecognized(true);
+ m_contextData.widgetSecurity.setRecognized(true);
return;
}
}
}
+void TaskCertify::getSignatureFiles(std::string path, SignatureFileInfoSet& file)
+{
+ LogDebug("path : " << path);
+ SignatureFileInfoSet signatureFiles;
+ SignatureFinder signatureFinder(path);
+ if (SignatureFinder::NO_ERROR != signatureFinder.find(file)) {
+ LogError("Error in Signature Finder : " << path);
+ ThrowMsg(Exceptions::SignatureNotFound,
+ "Error openig temporary widget directory");
+ }
+}
+
void TaskCertify::stepSignature()
{
- Assert(!m_contextData.tempWidgetPath.empty());
+ LogDebug("================ Step: <<Signature>> ENTER ===============");
- std::string widgetPath = m_contextData.tempWidgetPath + "/";
+ std::string widgetPath;
+ widgetPath = m_contextData.locations->getTemporaryPackageDir() + "/";
- SignatureFileInfoSet signatureFiles;
- SignatureFinder signatureFinder(widgetPath);
- if (SignatureFinder::NO_ERROR != signatureFinder.find(signatureFiles)) {
- LogError("Error in Signature Finder");
- ThrowMsg(Exceptions::InvalidPackage,
- "Error openig temporary widget directory");
+ if (m_contextData.mode.command ==
+ InstallMode::Command::REINSTALL)
+ {
+ widgetPath = m_contextData.locations->getPackageInstallationDir() + "/";
}
- SignatureFileInfoSet::reverse_iterator iter = signatureFiles.rbegin();
- LogInfo("No of signatures: " << signatureFiles.size());
+ SignatureFileInfoSet signatureFiles;
- bool firstDistributorSignature = true;
- bool testCertificate = false;
+ Try {
+ getSignatureFiles(widgetPath, signatureFiles);
- bool complianceMode = GlobalDAOReadOnly::getComplianceMode();
+ if (signatureFiles.size() <= 0) {
+ widgetPath += std::string(WrtDB::GlobalConfig::GetWidgetSrcPath())
+ + "/";
+ if (0 == access(widgetPath.c_str(), F_OK)) {
+ getSignatureFiles(widgetPath, signatureFiles);
+ }
+ }
+ } Catch(Exceptions::SignatureNotFound) {
+ ReThrowMsg(Exceptions::SignatureNotFound, widgetPath);
+ }
+
+ SignatureFileInfoSet::reverse_iterator iter = signatureFiles.rbegin();
+ LogDebug("Number of signatures: " << signatureFiles.size());
for (; iter != signatureFiles.rend(); ++iter) {
- LogInfo("Checking signature with id=" << iter->getFileNumber());
+ LogDebug("Checking signature with id=" << iter->getFileNumber());
SignatureData data(widgetPath + iter->getFileName(),
iter->getFileNumber());
SignatureReader xml;
xml.initialize(data, GlobalConfig::GetSignatureXmlSchema());
xml.read(data);
- SignatureValidator validator(GlobalConfig::IsOCSPEnabled(),
- GlobalConfig::IsCRLEnabled(),
- complianceMode);
- SignatureValidator::Result result =
- validator.check(data, widgetPath);
- if (result == SignatureValidator::SIGNATURE_REVOKED) {
+ WrtSignatureValidator::Result result;
+
+ WrtSignatureValidator validator(
+ WrtSignatureValidator::TIZEN,
+ !GlobalSettings::
+ OCSPTestModeEnabled(),
+ !GlobalSettings::
+ CrlTestModeEnabled(),
+ false);
+
+ result = validator.check(data, widgetPath);
+
+ if (m_contextData.mode.installTime
+ == InstallMode::InstallTime::PRELOAD)
+ {
+ result = WrtSignatureValidator::SIGNATURE_VERIFIED;
+ }
+
+ if (result == WrtSignatureValidator::SIGNATURE_REVOKED) {
LogWarning("Certificate is REVOKED");
- ThrowMsg(Exceptions::InvalidPackage,
+ ThrowMsg(Exceptions::CertificateExpired,
"Certificate is REVOKED");
}
- if (result == SignatureValidator::SIGNATURE_INVALID) {
+ if (result == WrtSignatureValidator::SIGNATURE_INVALID &&
+ iter->getFileNumber() <= 1) {
LogWarning("Signature is INVALID");
// TODO change exception name
- ThrowMsg(Exceptions::InvalidPackage,
+ ThrowMsg(Exceptions::SignatureInvalid,
"Invalid Package");
}
if (data.isAuthorSignature()) {
- if (result == SignatureValidator::SIGNATURE_VERIFIED ||
- m_contextData.wacSecurity.isDistributorSigned())
- {
+ if (result == WrtSignatureValidator::SIGNATURE_VERIFIED ) {
processAuthorSignature(data);
- } else if (result == SignatureValidator::SIGNATURE_DISREGARD) {
- continue;
}
} else {
- if (result == SignatureValidator::SIGNATURE_DISREGARD) {
- continue;
+ if (result != WrtSignatureValidator::SIGNATURE_INVALID) {
+ processDistributorSignature(data);
}
- // now signature _must_ be verified
- processDistributorSignature(data, firstDistributorSignature);
- firstDistributorSignature = false;
- }
-
- DeveloperModeValidator developerModeValidator(
- complianceMode,
- GlobalDAOReadOnly::getComplianceFakeImei(),
- GlobalDAOReadOnly::getComplianceFakeMeid());
-
- developerModeValidator.check(data);
-
- testCertificate |=
- data.getStorageType().contains(CertStoreId::DEVELOPER);
-
- bool developerMode = GlobalDAOReadOnly::GetDeveloperMode();
-
- if (testCertificate && !developerMode) {
- LogDebug("Widget signed by test certificate, "
- "but developer mode is off.");
- ThrowMsg(Exceptions::InvalidPackage,
- "Widget signed by test certificate, "
- "but developer mode is off.");
}
- m_contextData.widgetConfig.isTestWidget = testCertificate;
} Catch(ParserSchemaException::Base) {
- LogDebug("Error occured in ParserSchema.");
- ReThrowMsg(Exceptions::InvalidPackage,
+ LogError("Error occured in ParserSchema.");
+ ReThrowMsg(Exceptions::SignatureInvalid,
"Error occured in ParserSchema.");
}
- Catch(DeveloperModeValidator::Exception::Base) {
- LogDebug("Cannot validate developer certificate.");
- ReThrowMsg(Exceptions::InvalidPackage,
- "Cannot validate developer certificate.");
- }
}
if (signatureFiles.empty()) {
- LogInfo("No signature files has been found.");
+ LogDebug("No signature files has been found.");
}
- LogInfo("================ Step: <<CSignature>> DONE ================");
-}
+ LogDebug("================ Step: <<Signature>> DONE ================");
-void TaskCertify::stepWarningPopup()
-{
- LogInfo("Step:: <<Warning Popup>>");
- // SP-2151: If widget is not recognized (OCSP status of any of certificates
- // it is signed with is not recognized) WRT must notify user that
- // widget cannot be installed as a trusted application, and let the
- // user decide whether it should be installed as an untrusted
- // application.
- if (!m_contextData.wacSecurity.isDistributorSigned()) {
- if (GlobalSettings::GetPopupsEnabledFlag()) {
- m_contextData.job->Pause();
- std::string label = _("IDS_IM_POP_WIDGET_UNTRUSTED_WARNING") +
- LABEL_NEW_LINE +
- _("IDS_IM_WIDGET_WANT_TO_INSTALL");
- using namespace DPL::Popup;
- CtrlPopupPtr popup =
- PopupControllerSingleton::Instance().CreatePopup();
- popup->SetTitle(_("IDS_IM_POP_WIDGET_UNTRUSTED_TITLE"));
- popup->Append(new PopupObject::Label(label));
- popup->Append(new PopupObject::Button(_("IDS_IM_BUTTON_INSTALL"),
- BUTTON_ID_INSTALL));
- popup->Append(new PopupObject::Button(_("IDS_IM_BUTTON_RESIGN"),
- BUTTON_ID_RESIGN));
-
- ListenForAnswer(popup);
-
- PopupAnswerCallback cb = MakeAnswerCallback(this,
- &TaskCertify::onWarningPopupAnswer);
-
- ShowPopupEvent event(popup, cb, DPL::Event::UNDEFINED_LOOP_HANDLE);
- CONTROLLER_POST_EVENT(PopupController, event);
- } else {
- m_userAgreedToInstallUntrustedWidget = true;
- }
- }
+ m_contextData.job->UpdateProgress(
+ InstallerContext::INSTALL_DIGSIG_CHECK,
+ "Widget Signature checked");
}
-void TaskCertify::stepWarningPopupAnswer()
+bool TaskCertify::isTizenWebApp() const
{
- LogInfo("Step: <<Warning Popup Answer>>");
- if (false == m_contextData.wacSecurity.isDistributorSigned() &&
- false == m_userAgreedToInstallUntrustedWidget)
+ bool ret = FALSE;
+ if (m_contextData.widgetConfig.webAppType.appType
+ == WrtDB::AppType::APP_TYPE_TIZENWEBAPP)
{
- LogWarning("User does not agreed to install unsigned widgets!");
- ThrowMsg(Exceptions::NotAllowed, "Widget not allowed");
+ ret = TRUE;
}
-}
-void TaskCertify::stepAuthorInfoPopupAnswer()
-{
- LogInfo("Step: <<Author Info Popup Answer>>");
- if (m_cancelInstallation) {
- LogWarning("User does not agreed to install widget!");
- ThrowMsg(Exceptions::NotAllowed, "Widget not allowed");
- }
+ return ret;
}
-std::string TaskCertify::createAuthorWidgetInfo() const
+void TaskCertify::stepVerifyUpdate()
{
- std::string authorInfo;
- if (m_contextData.wacSecurity.isRecognized()) {
- authorInfo += _("IDS_IM_WIDGET_RECOGNISED");
- } else {
- authorInfo += _("IDS_IM_WIDGET_UNRECOGNISED");
- }
-
- authorInfo += LABEL_NEW_LINE_2;
- ValidationCore::CertificatePtr authorCert =
- m_contextData.wacSecurity.getAuthorCertificatePtr();
- if (!!authorCert) {
- DPL::Optional < DPL::String > organizationName =
- authorCert->getOrganizationName();
-
- authorInfo += _("IDS_IM_WIDGET_AUTHOR_ORGANIZATION_NAME");
- authorInfo += LABEL_NEW_LINE;
-
- if (!organizationName.IsNull()) {
- authorInfo += DPL::ToUTF8String(*organizationName);
- } else {
- authorInfo += _("IDS_IM_WIDGET_ORGANIZATION_UNKNOWN");
- }
-
- authorInfo += LABEL_NEW_LINE_2;
-
- DPL::Optional < DPL::String > countryName =
- authorCert->getCountryName();
-
- authorInfo += _("IDS_IM_WIDGET_COUNTRY_NAME");
- authorInfo += LABEL_NEW_LINE;
-
- if (!countryName.IsNull()) {
- authorInfo += DPL::ToUTF8String(*countryName);
- } else {
- authorInfo += _("IDS_IM_WIDGET_COUNTRY_UNKNOWN");
+ LogDebug("Step: <<Check Update>>");
+ CertificatePtr newCertificate =
+ m_contextData.widgetSecurity.getAuthorCertificatePtr();
+ CertificatePtr oldCertificate =
+ getOldAuthorSignerCertificate(m_contextData.widgetConfig.tzAppid);
+
+ if (!!newCertificate && !!oldCertificate) {
+ if (0 != newCertificate->getBase64().compare(oldCertificate->getBase64())) {
+ LogDebug("old widget's author signer certificate : " <<
+ oldCertificate->getBase64());
+ LogDebug("new widget's author signer certificate : " <<
+ newCertificate->getBase64());
+ ThrowMsg(Exceptions::NotMatchedCertification,
+ "Author signer certificates doesn't match \
+ between old widget and installing widget");
}
} else {
- authorInfo +=
- _("IDS_IM_WIDGET_DOES_NOT_CONTAIN_RECOGNIZED_AUTHOR_SIGNATURE");
+ if (!(NULL == newCertificate.Get() && NULL == oldCertificate.Get())) {
+ ThrowMsg(Exceptions::NotMatchedCertification,
+ "Author signer certificates doesn't match \
+ between old widget and installing widget");
+ }
}
- return authorInfo;
}
-void TaskCertify::stepAuthorInfoPopup()
+void TaskCertify::StartStep()
{
- LogInfo("Step:: <<Author Popup Information>>");
-
- if (!GlobalSettings::GetPopupsEnabledFlag()) {
- LogDebug("Popups are not enabled! Author information wont be shown.");
- return;
- }
-
- using namespace DPL::Popup;
- m_contextData.job->Pause();
- std::string label = createAuthorWidgetInfo() + LABEL_NEW_LINE + _("IDS_IM_WIDGET_WANT_TO_INSTALL");
-
- CtrlPopupPtr popup = PopupControllerSingleton::Instance().CreatePopup();
- popup->SetTitle(_("IDS_IM_WIDGET_HEAD"));
- popup->Append(new PopupObject::Label(label));
- popup->Append(new PopupObject::Button(_("IDS_IM_BUTTON_INSTALL"),
- BUTTON_ID_INSTALL));
- popup->Append(new PopupObject::Button(_("IDS_IM_BUTTON_RESIGN"),
- BUTTON_ID_RESIGN));
- ListenForAnswer(popup);
- ShowPopupEvent event(popup,
- MakeAnswerCallback(
- this,
- &TaskCertify::onAuthorInfoPopupAnswer),
- DPL::Event::UNDEFINED_LOOP_HANDLE);
- CONTROLLER_POST_EVENT(PopupController, event);
+ LogDebug("--------- <TaskCertify> : START ----------");
}
-void TaskCertify::stepFinalize()
+void TaskCertify::EndStep()
{
- LogInfo("Step: <<CERTYFYING DONE>>");
-}
+ LogDebug("Step: <<CERTYFYING DONE>>");
-void TaskCertify::onWarningPopupAnswer(const DPL::Popup::AnswerCallbackData& answer)
-{
- m_contextData.job->Resume();
- if (BUTTON_ID_RESIGN == answer.buttonAnswer) {
- m_userAgreedToInstallUntrustedWidget = false;
- } else if (BUTTON_ID_INSTALL == answer.buttonAnswer) {
- m_userAgreedToInstallUntrustedWidget = true;
- } else {
- Assert(false && "Unpredicted answer received.");
- }
-}
+ m_contextData.job->UpdateProgress(
+ InstallerContext::INSTALL_CERT_CHECK,
+ "Widget Certification Check Finished");
-void TaskCertify::onAuthorInfoPopupAnswer(
- const DPL::Popup::AnswerCallbackData& answer)
-{
- m_contextData.job->Resume();
- if (BUTTON_ID_RESIGN == answer.buttonAnswer) {
- m_cancelInstallation = true;
- }
+ LogDebug("--------- <TaskCertify> : END ----------");
}
} //namespace WidgetInstall
} //namespace Jobs