changeset 454:efd1bd85112f

Save selected certificate in settings and parse it.
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 23 Apr 2014 10:36:22 +0000
parents 6dec8101793c
children c17c1da7108d
files ui/createcertlistdialog.cpp ui/createcertlistdialog.h ui/l10n/administrator_de_DE.ts
diffstat 3 files changed, 78 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ui/createcertlistdialog.cpp	Wed Apr 23 10:34:56 2014 +0000
+++ b/ui/createcertlistdialog.cpp	Wed Apr 23 10:36:22 2014 +0000
@@ -6,7 +6,11 @@
  * See LICENSE.txt for details.
  */
 #include "createcertlistdialog.h"
+#include "sslhelp.h"
+#include "administratorwindow.h"
+
 #include <QDebug>
+#include <QMessageBox>
 #include <QDir>
 #include <QPushButton>
 #include <QGroupBox>
@@ -16,12 +20,17 @@
 #include <QFileDialog>
 #include <QStandardPaths>
 
-CreateCertListDialog::CreateCertListDialog(QMainWindow *parent) :
-    QDialog(parent)
+#include <polarssl/pk.h>
+
+CreateCertListDialog::CreateCertListDialog(AdministratorWindow *parent) :
+    QDialog(parent),
+    mAdminWindow(parent),
+    mPk(NULL)
 {
     setWindowTitle(tr("Save certificate list"));
     setupGUI();
     resize(500, 200);
+    mCertFile->setText(mAdminWindow->settings()->value("LastCert", QString()).toString());
 }
 
 void CreateCertListDialog::setupGUI()
@@ -70,10 +79,8 @@
 
     QString footerText = tr("In addition, each certificate list will be saved "
         "automatically in the archive directory:\n");
-    // TODO print out the path, not the displayName.
     footerText.append(QStandardPaths::writableLocation(
         QStandardPaths::DataLocation));
-    //footerText.append(QStandardPaths::displayName(QStandardPaths::DataLocation));
     QLabel *footer = new QLabel(footerText);
 
     centerLayout->addLayout(labelLayout);
@@ -105,11 +112,35 @@
     return;
 }
 
+void CreateCertListDialog::showErrorMessage(const QString &msg)
+{
+    QMessageBox::warning(this, tr("Error!"), msg);
+}
+
 void CreateCertListDialog::openCertificateSelect()
 {
     QString certFile = QFileDialog::getOpenFileName(
-        this, tr("Select certificate"), QDir::homePath(), "*.pem *.der *.crt");
+        this, tr("Select certificate"), mCertFile->text().isEmpty() ?
+        QDir::homePath() : mCertFile->text(), "*.pem");
     mCertFile->setText(certFile);
+
+    mAdminWindow->settings()->setValue("LastCert", certFile);
+
+    if (mPk != NULL) {
+        pk_free(mPk);
+        delete mPk;
+        mPk = NULL;
+    }
+
+    mPk = new pk_context;
+    pk_init(mPk);
+    int ret = pk_parse_keyfile(mPk, mCertFile->text().toLocal8Bit().constData(), "");
+
+    if (ret != 0) {
+        showErrorMessage(tr("Failed to load certificate: %1")
+                .arg(getPolarSSLErrorMsg(ret)));
+        return;
+    }
 }
 
 void CreateCertListDialog::openSaveLocation()
@@ -121,6 +152,9 @@
 
 void CreateCertListDialog::createList()
 {
+    //entropy_context mEntropy;
+    //ctr_drbg_context mCtr_drbg;
+
     qDebug() << "and now create the certificate list using:";
     qDebug() << "certificate: " << mCertFile->text();
     qDebug() << "target" << mSaveFile->text();
--- a/ui/createcertlistdialog.h	Wed Apr 23 10:34:56 2014 +0000
+++ b/ui/createcertlistdialog.h	Wed Apr 23 10:36:22 2014 +0000
@@ -11,12 +11,15 @@
 #include <QDialog>
 #include <QMainWindow>
 #include <QLineEdit>
+
+#include <polarssl/pk.h>
 /**
  * @file createinstallerdialog.h
  * @brief The dialog to show settings and create an installer.
  */
 
 class QListWidget;
+class AdministratorWindow;
 
 class CreateCertListDialog : public QDialog
 {
@@ -25,18 +28,35 @@
     /** @brief Create a dialog showing settings for the create certificate list
      * process
      * */
-    CreateCertListDialog(QMainWindow *parent);
+    CreateCertListDialog(AdministratorWindow *parent);
 
 private:
     void setupGUI();
 
     QLineEdit *mCertFile;
     QLineEdit *mSaveFile;
+    AdministratorWindow *mAdminWindow;
+
+    pk_context *mPk;
 
 private slots:
+    /** @brief Open the certificate selection dialog and parse the certificate
+     *
+     * If the certificate can be parsed mPk is replaced by the new key
+     * otherwise an error message is shown to the user.
+     */
     void openCertificateSelect();
     void openSaveLocation();
+    /** @brief create a valid certificate list file
+     *
+     * The contents of the certificate list is the certificatelist
+     * of the adminWindow. It is signed with the currently
+     * loaded certificate in mPk. On errors the user is
+     * informed with showErrorMessage */
     void createList();
+
+    /** @brief show an error message with QMessageBox */
+    void showErrorMessage(const QString&msg);
 };
 
 #endif // CREATECERTLISTDIALOG_H
--- a/ui/l10n/administrator_de_DE.ts	Wed Apr 23 10:34:56 2014 +0000
+++ b/ui/l10n/administrator_de_DE.ts	Wed Apr 23 10:36:22 2014 +0000
@@ -176,8 +176,8 @@
 <context>
     <name>CreateCertListDialog</name>
     <message>
-        <location filename="../createcertlistdialog.cpp" line="22"/>
-        <location filename="../createcertlistdialog.cpp" line="39"/>
+        <location filename="../createcertlistdialog.cpp" line="30"/>
+        <location filename="../createcertlistdialog.cpp" line="48"/>
         <source>Save certificate list</source>
         <translation>Zertifikatsliste speichern</translation>
     </message>
@@ -195,33 +195,43 @@
         <translation type="obsolete">Liste signieren</translation>
     </message>
     <message>
-        <location filename="../createcertlistdialog.cpp" line="41"/>
+        <location filename="../createcertlistdialog.cpp" line="50"/>
         <source>Save all managed root certificates in a new, signed certificate list.</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../createcertlistdialog.cpp" line="71"/>
+        <location filename="../createcertlistdialog.cpp" line="80"/>
         <source>In addition, each certificate list will be saved automatically in the archive directory:
 </source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../createcertlistdialog.cpp" line="83"/>
+        <location filename="../createcertlistdialog.cpp" line="90"/>
         <source>Save list</source>
         <translation type="unfinished">Liste speichern</translation>
     </message>
     <message>
-        <location filename="../createcertlistdialog.cpp" line="85"/>
+        <location filename="../createcertlistdialog.cpp" line="92"/>
         <source>Cancel</source>
         <translation>Abbrechen</translation>
     </message>
     <message>
-        <location filename="../createcertlistdialog.cpp" line="111"/>
+        <location filename="../createcertlistdialog.cpp" line="117"/>
+        <source>Error!</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createcertlistdialog.cpp" line="123"/>
         <source>Select certificate</source>
         <translation type="unfinished">Zertifikat auswählen</translation>
     </message>
     <message>
-        <location filename="../createcertlistdialog.cpp" line="118"/>
+        <location filename="../createcertlistdialog.cpp" line="140"/>
+        <source>Failed to load certificate: %1</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createcertlistdialog.cpp" line="149"/>
         <source>Select target location</source>
         <translation type="unfinished"></translation>
     </message>

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