# HG changeset patch # User Sascha Wilde # Date 1395736251 -3600 # Node ID fb3b2d77518f7bf12516ae5ad097e078a9f9eed3 # Parent a46a4b443410edf77dbf1cffef975e9390865946# Parent f09a0817e3bcc553c152158e0dacb4e3a215bd4e Merged diff -r a46a4b443410 -r fb3b2d77518f cinst/main.c --- a/cinst/main.c Tue Mar 25 09:30:42 2014 +0100 +++ b/cinst/main.c Tue Mar 25 09:30:51 2014 +0100 @@ -30,6 +30,7 @@ #include #include #include +#include #include "strhelp.h" #include "listutil.h" @@ -49,10 +50,17 @@ * The caller needs to free the memory allocated by this function * even when an error is returned. * + * Uninstall certificates are all certificates that are pa + * + * @param[out] certificate_list the parsed certificate list + * @param[out] to_install strv of installation instructions or NULL + * @param[out] to_remove strv of remove instructions or NULL + * @param[out] all_certs strv of uninstallation instructions or NULL + * * @returns: 0 on success. An error code otherwise. */ int readInput(char **certificate_list, char ***to_install, - char ***to_remove) + char ***to_remove, char ***all_certs) { int lines_read = 0; int readingList = 0; @@ -96,55 +104,84 @@ } if (readingList) { str_append_str(certificate_list, &list_size, buf, len); + } else if (strcmp("UNINSTALL\r\n", buf) == 0) { + /* Remove trailing \r\n */ + strv_append(to_remove, buf, len - 2); continue; } if (*buf == 'I') { /* Remove leading I: and trailing \r\n */ - strv_append(to_install, buf+2, len - 4); + strv_append(readingList ? all_certs : to_install, + buf+2, len - 4); continue; } if (*buf == 'R') { /* Remove leading R: and trailing \r\n */ - strv_append(to_remove, buf+2, len - 4); + strv_append(readingList ? all_certs : to_remove, + buf+2, len - 4); continue; } - if (strcmp("UNINSTALL", buf) == 0) { - /* Remove trailing \r\n */ - strv_append(to_remove, buf, len - 2); - } } return 0; } -/* -int validate_instructions(const char *certificate_list, - const size_t list_len, - const char **to_install, - const char **to_remove) + +/** @brief Check that the insturctions match to the list + * + * Only certificates part of the certificate_list are allowed + * for installation. + * + * @param[in] all_certs strv of all valid certificates in a list + * @param[in] to_validate strv of instructions + * + * @returns 0 on success, an error otherwise + */ +int validate_instructions(char **all_certs, + char **to_validate) { - TODO - (void *) certificate_list; - (void **) to_install; - (void **) to_remove; - (void) list_len; + int i = 0, + j = 0; + + if (!all_certs || strv_length(all_certs) < 1) { + /* Invalid parameters */ + return -1; + } + + if (to_validate == NULL) { + /* Nothing is valid */ + return 0; + } + + for (i=0; to_validate[i]; i++) { + bool found = false; + for (j=0; all_certs[j]; j++) { + if (strncmp(to_validate[i], all_certs[j], MAX_LINE_LENGTH - 2) == 0) { + found = true; + break; + } + } + if (!found) { + printf("Install instruction with invalid certificate\n."); + return ERR_INVALID_INSTRUCTIONS; + } + } return 0; } -*/ + int main() { char **to_install = NULL; char **to_remove = NULL; + char **all_certs = NULL; char *certificate_list = NULL; size_t list_len = 0; int ret = -1; - /* - i = 0 , - uninstall = 0; - */ - ret = readInput(&certificate_list, &to_install, &to_remove); + bool uninstall = false; - if (ret != 0) { + ret = readInput(&certificate_list, &to_install, &to_remove, &all_certs); + + if (ret) { return ret; } @@ -156,7 +193,7 @@ ret = verify_list(certificate_list, list_len); - if (ret != 0) { + if (ret) { return ERR_INVALID_SIGNATURE; } @@ -165,29 +202,38 @@ } - /* Check that the instructions are ok to execute - ret = validate_instructions(certificate_list, list_len, to_install, - to_remove); - if (ret != 0) { - return ERR_INVALID_INSTRUCTIONS; + /* Check that the instructions are ok to execute */ + if (to_install) { + ret = validate_instructions(all_certs, to_install); + if (ret) { + return ret; + } } if (to_remove) { - for (i=0; to_remove[i]; i++) { - if (strncmp("UNINSTALL", to_remove[i], MAX_LINE_LENGTH)) { - uninstall = 1; - break; + if (to_remove[0] && strncmp("UNINSTALL", to_remove[0], MAX_LINE_LENGTH) == 0) { + uninstall = true; + strv_free(to_remove); + to_remove = NULL; + } else { + ret = validate_instructions(all_certs, to_remove); + if (ret) { + return ret; } } } if (uninstall) { - + /* To uninstall does not have to be verified as it part of the + * signed list.*/ + to_remove = all_certs; + } else { + strv_free(all_certs); + all_certs = NULL; } -*/ #ifdef WIN32 - return install_certificates_win((const char**) to_install, 1); + return install_certificates_win((const char**) to_install, true); //remove_certificates_win((const char**) to_remove, 1); #endif diff -r a46a4b443410 -r fb3b2d77518f cinst/windowsstore.c --- a/cinst/windowsstore.c Tue Mar 25 09:30:42 2014 +0100 +++ b/cinst/windowsstore.c Tue Mar 25 09:30:51 2014 +0100 @@ -25,17 +25,15 @@ return bufPtr; } -int install_certificates_win(const char **to_install, int user_store) +int install_certificates_win(const char **to_install, bool user_store) { int i = 0; HCERTSTORE hStore = NULL; if (user_store) { - // Access user store hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root"); } else { - // Access machine store hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"Root"); } @@ -85,6 +83,7 @@ i++; free(buf); } + if(hStore) { CertCloseStore(hStore, 0); } diff -r a46a4b443410 -r fb3b2d77518f common/errorcodes.h --- a/common/errorcodes.h Tue Mar 25 09:30:42 2014 +0100 +++ b/common/errorcodes.h Tue Mar 25 09:30:51 2014 +0100 @@ -1,6 +1,8 @@ #ifndef ERRORCODES_H #define ERRORCODES_H +/* No error */ +#define NO_ERROR 0 /* No begin certificate / end certificate could be found */ #define ERR_INVALID_INPUT_NO_LIST 2 /* Too much input for the installer process */ diff -r a46a4b443410 -r fb3b2d77518f ui/listupdatedialog.cpp --- a/ui/listupdatedialog.cpp Tue Mar 25 09:30:42 2014 +0100 +++ b/ui/listupdatedialog.cpp Tue Mar 25 09:30:51 2014 +0100 @@ -11,7 +11,7 @@ #include #include "certificate.h" -ListUpdateDialog::ListUpdateDialog(QDialog *parent, +ListUpdateDialog::ListUpdateDialog(QMainWindow *parent, const CertificateList &listToInstall) : QDialog(parent), mCertificateList(listToInstall) diff -r a46a4b443410 -r fb3b2d77518f ui/listupdatedialog.h --- a/ui/listupdatedialog.h Tue Mar 25 09:30:42 2014 +0100 +++ b/ui/listupdatedialog.h Tue Mar 25 09:30:51 2014 +0100 @@ -3,6 +3,7 @@ #include "certificatelist.h" #include +#include /** * @file listupdatedialog.h * @brief The dialog for certificate selection. @@ -14,7 +15,7 @@ { public: /** @brief Create a list update dialog for the listToInstall */ - ListUpdateDialog(QDialog *parent, const CertificateList &listToInstall); + ListUpdateDialog(QMainWindow *parent, const CertificateList &listToInstall); private: CertificateList mCertificateList; diff -r a46a4b443410 -r fb3b2d77518f ui/main.cpp --- a/ui/main.cpp Tue Mar 25 09:30:42 2014 +0100 +++ b/ui/main.cpp Tue Mar 25 09:30:51 2014 +0100 @@ -28,6 +28,9 @@ { QApplication app (argc, argv); + QStringList arguments = QApplication::arguments(); + bool trayMode = arguments.contains("--tray"); + if (!QSystemTrayIcon::isSystemTrayAvailable() || !QSystemTrayIcon::supportsMessages()) { QMessageBox::critical(0, QString::fromLatin1(APPNAME), @@ -44,6 +47,9 @@ QSettings::setDefaultFormat(QSettings::IniFormat); MainWindow mainWin; + if (!trayMode) { + mainWin.show(); + } return app.exec(); } diff -r a46a4b443410 -r fb3b2d77518f ui/mainwindow.cpp --- a/ui/mainwindow.cpp Tue Mar 25 09:30:42 2014 +0100 +++ b/ui/mainwindow.cpp Tue Mar 25 09:30:51 2014 +0100 @@ -25,6 +25,7 @@ MainWindow::MainWindow() { createActions(); createTrayIcon(); + createMenuBar(); qRegisterMetaType("SSLConnection::ErrorCode"); connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), @@ -191,3 +192,37 @@ connect(mTrayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); } + +void MainWindow::createMenuBar() +{ + mMenuBar = new QMenuBar(this); + QMenu *mMenu = new QMenu(tr("Menu"), mMenuBar); + mMenuBar->addMenu(mMenu); + QAction *update = mMenu->addAction(tr("Force Update")); + QAction *settings = mMenu->addAction(tr("Settings")); + mMenu->addSeparator(); + QAction *help = mMenu->addAction(tr("Help")); + QAction *about = mMenu->addAction(tr("About")); + mMenu->addSeparator(); + QAction *quit = mMenu->addAction(tr("Quit")); + connect(update, SIGNAL(triggered()), this, SLOT(checkUpdates())); + connect(settings, SIGNAL(triggered()), this, SLOT(showSettings())); + connect(help, SIGNAL(triggered()), this, SLOT(showHelp())); + connect(about, SIGNAL(triggered()), this, SLOT(showAbout())); + connect(quit, SIGNAL(triggered()), qApp, SLOT(quit())); + setMenuBar(mMenuBar); +} + +void MainWindow::showSettings() { + qDebug() << "show settingsdialog"; +} + +void MainWindow::showHelp() +{ + qDebug() << "show helpdialog"; +} + +void MainWindow::showAbout() +{ + qDebug() << "show aboutdialog"; +} diff -r a46a4b443410 -r fb3b2d77518f ui/mainwindow.h --- a/ui/mainwindow.h Tue Mar 25 09:30:42 2014 +0100 +++ b/ui/mainwindow.h Tue Mar 25 09:30:51 2014 +0100 @@ -7,8 +7,9 @@ */ #include -#include +#include #include +#include #include "downloader.h" #include "certificatelist.h" @@ -16,7 +17,7 @@ class QAction; class QTimer; -class MainWindow : public QDialog +class MainWindow : public QMainWindow { Q_OBJECT @@ -45,6 +46,9 @@ void downloaderError(const QString &message, SSLConnection::ErrorCode error); /** @brief Trigger the appropiate action depending on the state */ void messageClicked(); + void showSettings(); + void showHelp(); + void showAbout(); private: /** @brief check the integrity of available files. @@ -58,6 +62,7 @@ void verifyAvailableData(); void createTrayIcon(); void createActions(); + void createMenuBar(); QString mCurMessage; QString mInstalledSWVersion; @@ -71,6 +76,7 @@ QAction *mCheckUpdates; QAction *mQuitAction; CurrentState mCurState; + QMenuBar *mMenuBar; CertificateList mListToInstall; }; diff -r a46a4b443410 -r fb3b2d77518f ui/tests/cinstprocesstest.cpp --- a/ui/tests/cinstprocesstest.cpp Tue Mar 25 09:30:42 2014 +0100 +++ b/ui/tests/cinstprocesstest.cpp Tue Mar 25 09:30:51 2014 +0100 @@ -17,11 +17,19 @@ return installerProcess; } +#define VERIFY_PROC_DEBUG(x) \ + if (! x ) { \ + qDebug() << "Stdout:" << proc->readAllStandardOutput(); \ + qDebug() << "Stderr:" << proc->readAllStandardError(); \ + qDebug() << "Exit code: " << proc->exitCode(); \ + } \ + QVERIFY(x) + void finishVerify(QProcess *proc, int exitCode) { proc->closeWriteChannel(); proc->waitForFinished(); - QVERIFY(proc->exitStatus() == QProcess::NormalExit); - QVERIFY(proc->exitCode() == exitCode); + VERIFY_PROC_DEBUG(proc->exitStatus() == QProcess::NormalExit); + VERIFY_PROC_DEBUG(proc->exitCode() == exitCode); delete proc; } @@ -38,7 +46,7 @@ installerProcess->write("\r\n"); } - finishVerify(installerProcess, 0); + finishVerify(installerProcess, NO_ERROR); } void CinstProcessTest::initTestCase() { @@ -106,14 +114,26 @@ QProcess* installerProcess = startCinstProcess(); QVERIFY(installerProcess->state() == QProcess::Running); - /* I: as instruction */ installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); installerProcess->write(validList.rawData().toLatin1()); installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); - installerProcess->write("I:ABCDEF"); + installerProcess->write("I:ABCDEF\r\n"); finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS); } +void CinstProcessTest::testUninstall() { + QProcess* installerProcess = startCinstProcess(); + QVERIFY(installerProcess->state() == QProcess::Running); + + installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); + installerProcess->write(validList.rawData().toLatin1()); + installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); + + installerProcess->write("UNINSTALL\r\n"); + + finishVerify(installerProcess, NO_ERROR); +} + QTEST_GUILESS_MAIN (CinstProcessTest); diff -r a46a4b443410 -r fb3b2d77518f ui/tests/cinstprocesstest.h --- a/ui/tests/cinstprocesstest.h Tue Mar 25 09:30:42 2014 +0100 +++ b/ui/tests/cinstprocesstest.h Tue Mar 25 09:30:51 2014 +0100 @@ -28,6 +28,7 @@ void testNoList(); void testGarbageInput(); void testNoInstructions(); + void testUninstall(); }; #endif