changeset 1377:c8a6a3e6bdeb

(issue178) Show checksums after installer creation
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 15 Jan 2015 11:22:47 +0100
parents fdef94da2d70
children 3c61ab983f9b
files ui/createinstallerdialog.cpp ui/sslhelp.cpp ui/sslhelp.h
diffstat 3 files changed, 74 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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("<br/><h3>") + tr("Checksums:") + "</h3>";
+        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("<br/><b>%1:</b><br/><pre>").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 += "</pre>";
+
+        }
+
+        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);
--- 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 <polarssl/sha256.h>
+#include <polarssl/sha1.h>
 #include <polarssl/pk.h>
 #include <polarssl/entropy.h>
 #include <polarssl/ctr_drbg.h>
@@ -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;
--- 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.

http://wald.intevation.org/projects/trustbridge/