# HG changeset patch # User Andre Heinecke # Date 1395252254 0 # Node ID 1f27d6db5ee342b1f31387723a3a409507c44d91 # Parent 112228bd7e4b07bbd0f72e5180beb2e6cd5a1d48 Polarssl based certificate handling diff -r 112228bd7e4b -r 1f27d6db5ee3 ui/certificate.cpp --- a/ui/certificate.cpp Wed Mar 19 16:50:59 2014 +0000 +++ b/ui/certificate.cpp Wed Mar 19 18:04:14 2014 +0000 @@ -1,12 +1,45 @@ #include "certificate.h" +#include #include const QString& Certificate::shortDescription() const { return mShortDescription; } + Certificate::Certificate(const QByteArray& asn1data) : mValid(false), mShortDescription(QObject::tr("Invalid Certificate")) { + int ret = -1; + char buf[2000]; + x509_crt_init(&mX509Cert); + ret = x509_crt_parse(&mX509Cert, + (const unsigned char*) asn1data.constData(), + asn1data.size()); + if (ret != 0) { + qDebug() << "Parsing certificate failed with error: " << ret; + return; + } + + ret = x509_crt_info(buf, 2000, "", &mX509Cert); + + if (ret <= 0) { + qDebug() << "Getting certificate info failed with error: " << ret; + return; + } + + /* In case of success the return value is the size of the information + * written into buf + * + * TODO: This is currently not short description but all x509 information + * */ + mShortDescription = QString::fromUtf8(buf, ret); + + mValid = true; } + +Certificate::~Certificate() +{ + x509_crt_free(&mX509Cert); +} diff -r 112228bd7e4b -r 1f27d6db5ee3 ui/certificate.h --- a/ui/certificate.h Wed Mar 19 16:50:59 2014 +0000 +++ b/ui/certificate.h Wed Mar 19 18:04:14 2014 +0000 @@ -14,6 +14,8 @@ #include #endif +#include + class Certificate { public: @@ -38,8 +40,6 @@ bool mValid; QString mShortDescription; -#ifdef Q_OS_WIN - PCCERT_CONTEXT mPCertContext; -#endif + x509_crt mX509Cert; }; #endif diff -r 112228bd7e4b -r 1f27d6db5ee3 ui/certificatelist.cpp --- a/ui/certificatelist.cpp Wed Mar 19 16:50:59 2014 +0000 +++ b/ui/certificatelist.cpp Wed Mar 19 18:04:14 2014 +0000 @@ -16,6 +16,7 @@ mStatus = read_and_verify_list(fileName, &data, &size); if (!isValid()) { + qDebug() << "Invalid list! " << mStatus; return mStatus; } @@ -27,6 +28,7 @@ for (int i = 0; i < lines.size(); ++i) { QString curLine = lines[i].trimmed(); + qDebug() << "Reading line: " << curLine; if (curLine.startsWith("F:")) { if (curLine.right(1) != PARSER_VERSION) { qDebug() << "Invalid Format Version"; diff -r 112228bd7e4b -r 1f27d6db5ee3 ui/listupdatedialog.cpp --- a/ui/listupdatedialog.cpp Wed Mar 19 16:50:59 2014 +0000 +++ b/ui/listupdatedialog.cpp Wed Mar 19 18:04:14 2014 +0000 @@ -25,16 +25,27 @@ /* The remove groups */ QVBoxLayout *removeGroupLayout = new QVBoxLayout; - QListWidget *removeListWidget = new QListWidget; - removeGroupLayout->addWidget(removeListWidget); + mRemoveListWidget = new QListWidget; + removeGroupLayout->addWidget(mRemoveListWidget); QGroupBox *removeGroup = new QGroupBox(tr("Select certificates to be removed")); removeGroup->setLayout(removeGroupLayout); + foreach (const Certificate& cert, mCertificateList.getRemoveCertificates()) { + if (!cert.isValid()) { + qWarning() << "Invalid certificate in list"; + continue; + } + QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + item->setCheckState(Qt::Checked); + mRemoveListWidget->addItem(item); + } + /* The install group */ QVBoxLayout *installGroupLayout = new QVBoxLayout; - QListWidget *installListWidget = new QListWidget; + mInstallListWidget = new QListWidget; QGroupBox *installGroup = new QGroupBox(tr("Select certificates to install")); - installGroupLayout->addWidget(installListWidget); + installGroupLayout->addWidget(mInstallListWidget); installGroup->setLayout(installGroupLayout); foreach (const Certificate& cert, mCertificateList.getInstallCertificates()) { @@ -45,7 +56,7 @@ QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setCheckState(Qt::Checked); - installListWidget->addItem(item); + mInstallListWidget->addItem(item); } /* Add groups to layout */ @@ -60,3 +71,7 @@ return; } + +void ListUpdateDialog::executeUpdate() { + +} diff -r 112228bd7e4b -r 1f27d6db5ee3 ui/listupdatedialog.h --- a/ui/listupdatedialog.h Wed Mar 19 16:50:59 2014 +0000 +++ b/ui/listupdatedialog.h Wed Mar 19 18:04:14 2014 +0000 @@ -8,6 +8,8 @@ * @brief The dialog for certificate selection. */ +class QListWidget; + class ListUpdateDialog : public QDialog { public: @@ -17,6 +19,12 @@ private: CertificateList mCertificateList; void setupGUI(); + + QListWidget *mInstallListWidget; + QListWidget *mRemoveListWidget; + +private slots: + void executeUpdate(); }; #endif // LISTUPDATEDIALOG_H diff -r 112228bd7e4b -r 1f27d6db5ee3 ui/mainwindow.cpp --- a/ui/mainwindow.cpp Wed Mar 19 16:50:59 2014 +0000 +++ b/ui/mainwindow.cpp Wed Mar 19 18:04:14 2014 +0000 @@ -79,6 +79,7 @@ if (!listFileName.isEmpty()) { mListToInstall.readList(listFileName.toLocal8Bit().constData()); if (!mListToInstall.isValid()) { + mCurState = TransferError; // Probably a bug when Qt fileName is encoded and cFileName // fails because of this. This needs a unit test! // Maybe check that the file is in our data directory @@ -112,10 +113,11 @@ /* Retry the download again in 10 - 20 minutes */ QTimer::singleShot(600000 + (qrand() % 60000), this, SLOT(checkUpdates())); + } else { + mCurMessage = tr("An updated certificate list is available. Click here to install."); + setState(NewListAvailable); + showMessage(); } - mCurMessage = tr("An updated certificate list is available. Click here to install."); - setState(NewListAvailable); - showMessage(); } void MainWindow::handleNewSW(const QString& fileName, const QDateTime& modDate) {