diff options
Diffstat (limited to 'src/application-lib/installationreport.cpp')
-rw-r--r-- | src/application-lib/installationreport.cpp | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/src/application-lib/installationreport.cpp b/src/application-lib/installationreport.cpp index 0b4e5c67..b52d772c 100644 --- a/src/application-lib/installationreport.cpp +++ b/src/application-lib/installationreport.cpp @@ -4,7 +4,7 @@ ** Copyright (C) 2018 Pelagicore AG ** Contact: https://www.qt.io/licensing/ ** -** This file is part of the Luxoft Application Manager. +** This file is part of the Qt Application Manager. ** ** $QT_BEGIN_LICENSE:LGPL-QTAS$ ** Commercial License Usage @@ -50,7 +50,7 @@ #include "global.h" #include "qtyaml.h" -#include "applicationinfo.h" +#include "packageinfo.h" #include "utilities.h" #include "exception.h" #include "installationreport.h" @@ -69,28 +69,18 @@ static const unsigned char privateHmacKeyData[64] = { }; -InstallationReport::InstallationReport(const QString &applicationId) - : m_applicationId(applicationId) +InstallationReport::InstallationReport(const QString &packageId) + : m_packageId(packageId) { } -QString InstallationReport::applicationId() const +QString InstallationReport::packageId() const { - return m_applicationId; + return m_packageId; } -void InstallationReport::setApplicationId(const QString &applicationId) +void InstallationReport::setPackageId(const QString &packageId) { - m_applicationId = applicationId; -} - -QString InstallationReport::installationLocationId() const -{ - return m_installationLocationId; -} - -void InstallationReport::setInstallationLocationId(const QString &installationLocationId) -{ - m_installationLocationId = installationLocationId; + m_packageId = packageId; } QVariantMap InstallationReport::extraMetaData() const @@ -170,7 +160,7 @@ void InstallationReport::addFiles(const QStringList &files) bool InstallationReport::isValid() const { - return AbstractApplicationInfo::isValidApplicationId(m_applicationId) && !m_digest.isEmpty() && !m_files.isEmpty(); + return PackageInfo::isValidApplicationId(m_packageId) && !m_digest.isEmpty() && !m_files.isEmpty(); } bool InstallationReport::deserialize(QIODevice *from) @@ -188,7 +178,7 @@ bool InstallationReport::deserialize(QIODevice *from) return false; try { - checkYamlFormat(docs, 3 /*number of expected docs*/, { "am-installation-report" }, 1); + checkYamlFormat(docs, 3 /*number of expected docs*/, { "am-installation-report" }, 3 /*version*/); } catch (const Exception &) { return false; } @@ -196,15 +186,14 @@ bool InstallationReport::deserialize(QIODevice *from) const QVariantMap &root = docs.at(1).toMap(); try { - if (m_applicationId.isEmpty()) { - m_applicationId = root[qSL("applicationId")].toString(); - if (m_applicationId.isEmpty()) + if (m_packageId.isEmpty()) { + m_packageId = root[qSL("packageId")].toString(); + if (m_packageId.isEmpty()) throw false; - } else if (root[qSL("applicationId")].toString() != m_applicationId) { + } else if (root[qSL("packageId")].toString() != m_packageId) { throw false; } - m_installationLocationId = root[qSL("installationLocationId")].toString(); m_diskSpaceUsed = root[qSL("diskSpaceUsed")].toULongLong(); m_digest = QByteArray::fromHex(root[qSL("digest")].toString().toLatin1()); if (m_digest.isEmpty()) @@ -240,7 +229,8 @@ bool InstallationReport::deserialize(QIODevice *from) // see if the file has been tampered with by checking the hmac QByteArray hmacFile = QByteArray::fromHex(docs[2].toMap().value(qSL("hmac")).toString().toLatin1()); - QByteArray hmacKey = QByteArray::fromRawData((const char *) privateHmacKeyData, sizeof(privateHmacKeyData)); + QByteArray hmacKey = QByteArray::fromRawData(reinterpret_cast<const char *>(privateHmacKeyData), + sizeof(privateHmacKeyData)); QByteArray hmacCalc= QMessageAuthenticationCode::hash(QtYaml::yamlFromVariantDocuments({ docs[0], docs[1] }, QtYaml::BlockStyle), hmacKey, QCryptographicHash::Sha256); @@ -264,12 +254,11 @@ bool InstallationReport::serialize(QIODevice *to) const return false; QVariantMap header { - { "formatVersion", 1 }, + { "formatVersion", 3 }, { "formatType", "am-installation-report" } }; QVariantMap root { - { qSL("applicationId"), applicationId() }, - { qSL("installationLocationId"), installationLocationId() }, + { qSL("packageId"), packageId() }, { qSL("diskSpaceUsed"), diskSpaceUsed() }, { qSL("digest"), QLatin1String(digest().toHex()) } }; @@ -289,7 +278,8 @@ bool InstallationReport::serialize(QIODevice *to) const docs << root; // generate hmac to prevent tampering - QByteArray hmacKey = QByteArray::fromRawData((const char *) privateHmacKeyData, sizeof(privateHmacKeyData)); + QByteArray hmacKey = QByteArray::fromRawData(reinterpret_cast<const char *>(privateHmacKeyData), + sizeof(privateHmacKeyData)); QByteArray hmacCalc= QMessageAuthenticationCode::hash(QtYaml::yamlFromVariantDocuments({ docs[0], docs[1] }, QtYaml::BlockStyle), hmacKey, QCryptographicHash::Sha256); |