diff ui/createcertlistdialog.cpp @ 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 d1819cd56dee
children 88dfe16a0bb9
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();

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