# HG changeset patch # User Andre Heinecke # Date 1421317367 -3600 # Node ID c8a6a3e6bdeb2556858bd12247deda072fb26966 # Parent fdef94da2d7065d062e143930557ec956769b4df (issue178) Show checksums after installer creation diff -r fdef94da2d70 -r c8a6a3e6bdeb ui/createinstallerdialog.cpp --- a/ui/createinstallerdialog.cpp Thu Dec 04 14:32:16 2014 +0100 +++ b/ui/createinstallerdialog.cpp Thu Jan 15 11:22:47 2015 +0100 @@ -32,10 +32,10 @@ #define SIGN_HASH "sha256" #endif #ifndef SIGN_URL -#define SIGN_URL "http://wald.intevation.org/projects/trustbridge/" +#define SIGN_URL "https://www.trustbridge.de" #endif #ifndef SIGN_PUBLISHER -#define SIGN_PUBLISHER "TrustBridge Test with ümlaut" +#define SIGN_PUBLISHER "Bundesamt für Sicherheit in der Informationstechnik" #endif CreateInstallerDialog::CreateInstallerDialog(QMainWindow *parent) : @@ -185,16 +185,65 @@ delete mCurrentWorkingDir; mCurrentWorkingDir = NULL; } - FinishedDialog *fin = new FinishedDialog(0, tr("Created installer in %1.") - .arg(mSaveFile->text()), mNSISProc.readAll(), false); - qDebug() << "Finished: " << mNSISProc.readAll(); + mProgress.setLabelText(tr("Signing installer package...")); if (!signFile(mInstallerPath)) { showErrorMessage(tr("Failed to sign installer package.")); QFile::remove(mInstallerPath); + mProgress.cancel(); + } else { + mProgress.setLabelText(tr("Calculating checksums...")); + QString checksums = QString::fromLatin1("

") + tr("Checksums:") + "

"; + QDir outDir(mSaveFile->text()); + bool checksumErr = false; + QStringList filters; + filters << "TrustBridge-*.sh" << "TrustBridge-*.exe"; + qDebug() << "Entries: " << outDir.entryList(filters); + qDebug() << "Entries unfiltered: " << outDir.entryList(); + foreach (const QString &file, outDir.entryList(filters)) { + QFile f(outDir.filePath(file)); + if (!f.open(QIODevice::ReadOnly)) { + showErrorMessage (tr("Failed to open file \"%1\".").arg(file)); + checksumErr = true; + break; + } + const QByteArray fileData = f.readAll(); + if (fileData.isEmpty()) { + showErrorMessage (tr("Failed to read file \"%1\".").arg(file)); + checksumErr = true; + break; + } + const QByteArray theSha256sum = sha256sum(fileData); + const QByteArray theSha1sum = sha1sum(fileData); + if (theSha1sum.isEmpty() || theSha256sum.isEmpty()) { + showErrorMessage (tr("Failed to calculate checksums for \"%1\".").arg(file)); + checksumErr = true; + break; + } + checksums += QString::fromLatin1("
%1:
").arg(file);
+            checksums += "    SHA1: ";
+            for (int i=0; i < theSha1sum.size(); i++) {
+                checksums += QString("%1").arg(
+                    (unsigned char)(theSha1sum[i]), 0, 16).rightJustified(2, '0');
+            }
+
+            checksums += "\n    SHA256: ";
+            for (int i=0; i < theSha256sum.size(); i++) {
+                checksums += QString("%1").arg(
+                    (unsigned char)(theSha256sum[i]), 0, 16).rightJustified(2, '0');
+            }
+            checksums += "
"; + + } + + mProgress.cancel(); + if (!checksumErr) { + FinishedDialog *fin = new FinishedDialog(0, tr("Successfully created the installation packages in \"%1\".") + .arg(mSaveFile->text()) + checksums, mNSISProc.readAll(), false); + qDebug() << "Finished: " << mNSISProc.readAll(); + fin->show(); + } } - mProgress.cancel(); - fin->show(); close(); } @@ -552,6 +601,9 @@ QStyle::SP_MessageBoxCritical).pixmap(16, 16)); } msgLabel->setText(msg); + msgLabel->setTextInteractionFlags( + Qt::TextSelectableByMouse | + Qt::TextSelectableByKeyboard); topLayout->addWidget(msgLabel); topLayout->addWidget(detailsWindow); diff -r fdef94da2d70 -r c8a6a3e6bdeb ui/sslhelp.cpp --- a/ui/sslhelp.cpp Thu Dec 04 14:32:16 2014 +0100 +++ b/ui/sslhelp.cpp Thu Jan 15 11:22:47 2015 +0100 @@ -7,6 +7,7 @@ */ #include "sslhelp.h" #include +#include #include #include #include @@ -29,6 +30,13 @@ return QByteArray((const char *)output, 32); } +QByteArray sha1sum(const QByteArray& data) +{ + unsigned char output[20]; + sha1((unsigned char *)data.constData(), (size_t)data.size(), output); + return QByteArray((const char *)output, 20); +} + QByteArray rsaSignSHA256Hash(const QByteArray& hash, pk_context *pk) { int ret = 0; diff -r fdef94da2d70 -r c8a6a3e6bdeb ui/sslhelp.h --- a/ui/sslhelp.h Thu Dec 04 14:32:16 2014 +0100 +++ b/ui/sslhelp.h Thu Jan 15 11:22:47 2015 +0100 @@ -32,6 +32,13 @@ */ QByteArray sha256sum(const QByteArray& data); +/** @brief calculate the sha1 of the bytearray data + * + * @param [in] data The data to hash + * @returns the sha1sum of the data + */ +QByteArray sha1sum(const QByteArray& data); + /** @brief Create a RSA signature fur a sha256 hashsum * * @param [in] hash the hash to sign.