changeset 1371:23df332b2a4c

(issue179) Read install signature timestamp from config This also changes the way the sigDt is propgated to the MainWindow. It no longer uses the settings but hands it over as a parameter directly.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 24 Nov 2014 15:48:49 +0100
parents 289cb3554c55
children 96f640c88d10
files ui/main.cpp ui/mainwindow.cpp ui/mainwindow.h ui/processhelp.h ui/processhelp_linux.cpp
diffstat 5 files changed, 83 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ui/main.cpp	Mon Nov 24 14:43:36 2014 +0100
+++ b/ui/main.cpp	Mon Nov 24 15:48:49 2014 +0100
@@ -189,13 +189,20 @@
         app.setFont(font);
     }
 
+
+    QDateTime sigDt;
+#ifndef Q_OS_WIN
+    /* Read it from the install config. */
+    sigDt = ProcessHelp::getSigDtFromInstSettings();
+    Q_UNUSED(signed_time);
+#else
     if (signed_time != 0 && signed_time != -1) {
-        QDateTime sigTime = QDateTime::fromTime_t(signed_time);
-        QSettings settigs;
-        settings.setValue("Software/currentSigDt", sigTime);
+        /* Take it from the selftest result. */
+        sigDt = QDateTime::fromTime_t(signed_time);
     }
+#endif
 
-    MainWindow mainWin(trayMode);
+    MainWindow mainWin(trayMode, sigDt);
 
     return app.exec();
 }
--- a/ui/mainwindow.cpp	Mon Nov 24 14:43:36 2014 +0100
+++ b/ui/mainwindow.cpp	Mon Nov 24 15:48:49 2014 +0100
@@ -124,10 +124,11 @@
     return -1;
 }
 
-MainWindow::MainWindow(bool trayMode):
+MainWindow::MainWindow(bool trayMode, const QDateTime& sigDt):
     mTrayMode(trayMode),
     mManualDetailsShown(false),
-    mFailedConnections(0)
+    mFailedConnections(0),
+    mSigDt(sigDt)
 {
     createActions();
     createTrayIcon();
@@ -281,15 +282,14 @@
     bin_verify_result verifyResult = verify_binary(swFileName.toUtf8().constData(),
             swFileName.toUtf8().size());
     QDateTime sigDt = QDateTime::fromTime_t (verifyResult.sig_time);
-    QDateTime currentSigDt = mSettings.value("Software/currentSigDt").toDateTime();
 
-    if (verifyResult.result != VerifyValid || (currentSigDt.isValid() && sigDt <= currentSigDt)) {
+    if (verifyResult.result != VerifyValid || (mSigDt.isValid() && sigDt <= mSigDt)) {
         handleLTE(lteInvalidSoftware);
         if (verifyResult.result != VerifyValid) {
             qDebug() << "Failed to verify downloaded data.";
         } else {
             qDebug() << "Software update was signed at: " << sigDt;
-            qDebug() << "But the installed software was signed on: " << currentSigDt;
+            qDebug() << "But the installed software was signed on: " << mSigDt;
             if (verifyResult.fptr) {
                 fclose(verifyResult.fptr);
             }
@@ -425,15 +425,14 @@
             filePath.toUtf8().size());
 
     QDateTime sigDt = QDateTime::fromTime_t (vres.sig_time);
-    QDateTime currentSigDt = mSettings.value("Software/currentSigDt").toDateTime();
 
-    if (vres.result != VerifyValid || (currentSigDt.isValid() && sigDt <= currentSigDt)) {
+    if (vres.result != VerifyValid || (mSigDt.isValid() && sigDt <= mSigDt)) {
         handleLTE(lteInvalidSoftware);
         if (vres.result != VerifyValid) {
             qDebug() << "Failed to verify installer.";
         } else {
             qDebug() << "Software update was signed at: " << sigDt;
-            qDebug() << "But the installed software was signed on: " << currentSigDt;
+            qDebug() << "But the installed software was signed on: " << mSigDt;
             if (vres.fptr) {
                 fclose(vres.fptr);
             }
--- a/ui/mainwindow.h	Mon Nov 24 14:43:36 2014 +0100
+++ b/ui/mainwindow.h	Mon Nov 24 15:48:49 2014 +0100
@@ -23,6 +23,7 @@
 #include <QCheckBox>
 #include <QScrollArea>
 #include <QProcess>
+#include <QDateTime>
 
 #include "downloader.h"
 #include "certificatelist.h"
@@ -54,9 +55,13 @@
      * reached. If tray mode is true it also exits after
      * an update check.
      *
+     * The sigDt parameter is used to determine if a software
+     * update should be installed.
+     *
      * @param[in] trayMode set the tray mode
+     * @param[in] sigDt the datetime when the binary was signed.
      * */
-    MainWindow(bool trayMode);
+    MainWindow(bool trayMode, const QDateTime& sigDt = QDateTime());
 
     /**@brief set the current message to be shown
      *
@@ -380,6 +385,7 @@
     int mChangeCount;
     bool mManualDetailsShown;
     int mFailedConnections;
+    QDateTime mSigDt;
 };
 
 #endif // MAINWINDOW_H
--- a/ui/processhelp.h	Mon Nov 24 14:43:36 2014 +0100
+++ b/ui/processhelp.h	Mon Nov 24 15:48:49 2014 +0100
@@ -13,6 +13,7 @@
 
 #include <QList>
 #include <QString>
+#include <QDateTime>
 
 /**
  * @file processhelp.h
@@ -54,6 +55,15 @@
 * @brief Clean up internaly used infrastructure like pid/lock files.
 */
 static void cleanUp(void);
+
+#ifndef WIN32
+/**
+* @brief Read the signature timestamp from settings.
+*
+* @returns The signature timestamp as qdatetime or an invalid dt on error.
+*/
+static QDateTime getSigDtFromInstSettings();
+#endif
 };
 
 #endif // PROCESSHELP_H
--- a/ui/processhelp_linux.cpp	Mon Nov 24 14:43:36 2014 +0100
+++ b/ui/processhelp_linux.cpp	Mon Nov 24 15:48:49 2014 +0100
@@ -9,6 +9,7 @@
 
 #include "processhelp.h"
 #include "linuxlockfile.h"
+#include "util.h"
 
 #include <fcntl.h>
 #include <semaphore.h>
@@ -16,6 +17,7 @@
 #include <QDebug>
 #include <QDir>
 #include <QStandardPaths>
+#include <QApplication>
 
 int lockFileFD = -1;
 
@@ -47,4 +49,50 @@
     close_lockfile(lockFileFD);
 }
 
+QDateTime ProcessHelp::getSigDtFromInstSettings() {
+    QString pathCandidate;
+    QDateTime retval;
+    if (is_system_install()) {
+        pathCandidate = "/etc/" + qApp->applicationName() + "/" +
+          qApp->applicationName() + "-inst.cfg";
+    } else {
+        qDebug() << "Application name is : " << qApp->applicationName();
+        pathCandidate = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) +
+          + "/" + qApp->organizationName() + "/" +  qApp->applicationName() + "-inst.cfg";
+    }
+    QFileInfo fi(pathCandidate);
+    if (!fi.isReadable()) {
+        qDebug() << "Failed to find install config: " << pathCandidate;
+        return retval;
+    }
+    QFile instcfg(pathCandidate);
+    if (!instcfg.open(QIODevice::ReadOnly)) {
+        qDebug() << "Failed to open install config";
+        return retval;
+    }
+    QByteArray data;
+    int readLines = 0;
+    while (readLines < 100) {
+        readLines++;
+        data = instcfg.readLine();
+        if (data.isEmpty()) {
+            qDebug() << "Failed to read install config";
+            break;
+        }
+        QString line = QString::fromLocal8Bit(data);
+        if (line.startsWith("SIG_DATE=")) {
+            bool ok = false;
+            QString sigDate = line.replace("SIG_DATE=","");
+            long sigSecs = sigDate.toLong(&ok);
+            if (!ok) {
+                qDebug() << "Failed to convert sig date to long";
+            }
+            retval = QDateTime::fromTime_t(sigSecs);
+            break;
+        }
+    }
+    qDebug() << "Sig time is: " << retval;
+    instcfg.close();
+    return retval;
+}
 #endif /* Not WIN32 */

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