comparison 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
comparison
equal deleted inserted replaced
453:6dec8101793c 454:efd1bd85112f
4 * This file is Free Software under the GNU GPL (v>=2) 4 * This file is Free Software under the GNU GPL (v>=2)
5 * and comes with ABSOLUTELY NO WARRANTY! 5 * and comes with ABSOLUTELY NO WARRANTY!
6 * See LICENSE.txt for details. 6 * See LICENSE.txt for details.
7 */ 7 */
8 #include "createcertlistdialog.h" 8 #include "createcertlistdialog.h"
9 #include "sslhelp.h"
10 #include "administratorwindow.h"
11
9 #include <QDebug> 12 #include <QDebug>
13 #include <QMessageBox>
10 #include <QDir> 14 #include <QDir>
11 #include <QPushButton> 15 #include <QPushButton>
12 #include <QGroupBox> 16 #include <QGroupBox>
13 #include <QHBoxLayout> 17 #include <QHBoxLayout>
14 #include <QVBoxLayout> 18 #include <QVBoxLayout>
15 #include <QLabel> 19 #include <QLabel>
16 #include <QFileDialog> 20 #include <QFileDialog>
17 #include <QStandardPaths> 21 #include <QStandardPaths>
18 22
19 CreateCertListDialog::CreateCertListDialog(QMainWindow *parent) : 23 #include <polarssl/pk.h>
20 QDialog(parent) 24
25 CreateCertListDialog::CreateCertListDialog(AdministratorWindow *parent) :
26 QDialog(parent),
27 mAdminWindow(parent),
28 mPk(NULL)
21 { 29 {
22 setWindowTitle(tr("Save certificate list")); 30 setWindowTitle(tr("Save certificate list"));
23 setupGUI(); 31 setupGUI();
24 resize(500, 200); 32 resize(500, 200);
33 mCertFile->setText(mAdminWindow->settings()->value("LastCert", QString()).toString());
25 } 34 }
26 35
27 void CreateCertListDialog::setupGUI() 36 void CreateCertListDialog::setupGUI()
28 { 37 {
29 /* Top level layout / widgets */ 38 /* Top level layout / widgets */
68 buttonLayout->addWidget(certSelect); 77 buttonLayout->addWidget(certSelect);
69 buttonLayout->addWidget(saveSelect); 78 buttonLayout->addWidget(saveSelect);
70 79
71 QString footerText = tr("In addition, each certificate list will be saved " 80 QString footerText = tr("In addition, each certificate list will be saved "
72 "automatically in the archive directory:\n"); 81 "automatically in the archive directory:\n");
73 // TODO print out the path, not the displayName.
74 footerText.append(QStandardPaths::writableLocation( 82 footerText.append(QStandardPaths::writableLocation(
75 QStandardPaths::DataLocation)); 83 QStandardPaths::DataLocation));
76 //footerText.append(QStandardPaths::displayName(QStandardPaths::DataLocation));
77 QLabel *footer = new QLabel(footerText); 84 QLabel *footer = new QLabel(footerText);
78 85
79 centerLayout->addLayout(labelLayout); 86 centerLayout->addLayout(labelLayout);
80 centerLayout->addLayout(fieldLayout); 87 centerLayout->addLayout(fieldLayout);
81 centerLayout->addLayout(buttonLayout); 88 centerLayout->addLayout(buttonLayout);
103 setLayout(topLayout); 110 setLayout(topLayout);
104 111
105 return; 112 return;
106 } 113 }
107 114
115 void CreateCertListDialog::showErrorMessage(const QString &msg)
116 {
117 QMessageBox::warning(this, tr("Error!"), msg);
118 }
119
108 void CreateCertListDialog::openCertificateSelect() 120 void CreateCertListDialog::openCertificateSelect()
109 { 121 {
110 QString certFile = QFileDialog::getOpenFileName( 122 QString certFile = QFileDialog::getOpenFileName(
111 this, tr("Select certificate"), QDir::homePath(), "*.pem *.der *.crt"); 123 this, tr("Select certificate"), mCertFile->text().isEmpty() ?
124 QDir::homePath() : mCertFile->text(), "*.pem");
112 mCertFile->setText(certFile); 125 mCertFile->setText(certFile);
126
127 mAdminWindow->settings()->setValue("LastCert", certFile);
128
129 if (mPk != NULL) {
130 pk_free(mPk);
131 delete mPk;
132 mPk = NULL;
133 }
134
135 mPk = new pk_context;
136 pk_init(mPk);
137 int ret = pk_parse_keyfile(mPk, mCertFile->text().toLocal8Bit().constData(), "");
138
139 if (ret != 0) {
140 showErrorMessage(tr("Failed to load certificate: %1")
141 .arg(getPolarSSLErrorMsg(ret)));
142 return;
143 }
113 } 144 }
114 145
115 void CreateCertListDialog::openSaveLocation() 146 void CreateCertListDialog::openSaveLocation()
116 { 147 {
117 QString saveFile = QFileDialog::getExistingDirectory( 148 QString saveFile = QFileDialog::getExistingDirectory(
119 mSaveFile->setText(saveFile); 150 mSaveFile->setText(saveFile);
120 } 151 }
121 152
122 void CreateCertListDialog::createList() 153 void CreateCertListDialog::createList()
123 { 154 {
155 //entropy_context mEntropy;
156 //ctr_drbg_context mCtr_drbg;
157
124 qDebug() << "and now create the certificate list using:"; 158 qDebug() << "and now create the certificate list using:";
125 qDebug() << "certificate: " << mCertFile->text(); 159 qDebug() << "certificate: " << mCertFile->text();
126 qDebug() << "target" << mSaveFile->text(); 160 qDebug() << "target" << mSaveFile->text();
127 // TODO 161 // TODO
128 } 162 }

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