From f585e8fd07ce4cc99246dd0d4238baf056b95a16 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 24 Nov 2006 00:40:22 +0100 Subject: [PATCH] Export and Context menu for CRLs added Export for CSRs --- lib/db_crl.cpp | 47 +++++++ lib/db_crl.h | 7 +- lib/db_x509.cpp | 8 +- lib/db_x509req.cpp | 33 ++++- lib/db_x509req.h | 4 +- lib/load_obj.cpp | 2 +- lib/pki_crl.cpp | 2 +- lib/x509name.cpp | 2 +- misc/Local.mak.w32 | 24 ++-- ui/ExportDer.ui | 293 ++++++++++++++++++++++++++++++++++++++++ widgets/ExportDer.cpp | 106 +++++++++++++++ widgets/ExportDer.h | 71 ++++++++++ widgets/MW_database.cpp | 5 + widgets/MainWindow.h | 1 + widgets/Makefile | 2 +- 15 files changed, 574 insertions(+), 33 deletions(-) create mode 100644 ui/ExportDer.ui create mode 100644 widgets/ExportDer.cpp create mode 100644 widgets/ExportDer.h diff --git a/lib/db_crl.cpp b/lib/db_crl.cpp index 26cde254..73817b85 100644 --- a/lib/db_crl.cpp +++ b/lib/db_crl.cpp @@ -53,6 +53,8 @@ #include "widgets/MainWindow.h" #include "widgets/CrlDetail.h" #include +#include + db_crl::db_crl(QString db, MainWindow *mw) :db_base(db,mw) @@ -142,6 +144,35 @@ void db_crl::showItem(const QModelIndex &index) } } +void db_crl::store() +{ + if (!currentIdx.isValid()) + return; + + pki_crl *crl = static_cast(currentIdx.internalPointer()); + if (!crl) + return; + + ExportDer *dlg = new ExportDer(mainwin, crl->getUnderlinedName() + ".pem", + mainwin->getPath(), tr("CRL ( *.pem *.der *.crl )") ); + dlg->image->setPixmap(*MainWindow::csrImg); + dlg->label->setText(tr("Revokation list export")); + int dlgret = dlg->exec(); + + if (!dlgret) { + delete dlg; + return; + } + mainwin->setPath(dlg->dirPath); + QString fname = dlg->filename->text(); + bool pem = dlg->exportFormat->currentIndex() == 0 ? true : false; + delete dlg; + if (fname == "") { + return; + } + crl->writeCrl(fname, pem); +} + pki_crl *db_crl::newItem(pki_x509 *cert) { if (!cert) @@ -186,3 +217,19 @@ pki_crl *db_crl::newItem(pki_x509 *cert) return crl; } +void db_crl::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) +{ + QMenu *menu = new QMenu(mainwin); + currentIdx = index; + + menu->addAction(tr("Import"), this, SLOT(load())); + if (index != QModelIndex()) { + menu->addAction(tr("Rename"), this, SLOT(edit())); + menu->addAction(tr("Export"), this, SLOT(store())); + menu->addAction(tr("Delete"), this, SLOT(delete_ask())); + } + menu->exec(e->globalPos()); + delete menu; + currentIdx = QModelIndex(); + return; +} diff --git a/lib/db_crl.h b/lib/db_crl.h index 21aeb3ae..a58a1dae 100644 --- a/lib/db_crl.h +++ b/lib/db_crl.h @@ -48,8 +48,10 @@ #include "db_x509.h" #include "pki_crl.h" +#include "widgets/ExportDer.h" #include #include +#include #ifndef DB_CRL_H #define DB_CRL_H @@ -68,9 +70,12 @@ class db_crl: public db_base void preprocess(); void inToCont(pki_base *pki); pki_base *insert(pki_base *item); - void load(); void showItem(const QModelIndex &index); pki_crl *newItem(pki_x509 *cert); + void showContextMenu(QContextMenuEvent *e, const QModelIndex &index); + public slots: + void store(); + void load(); signals: void updateCertView(); }; diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index 74c72e21..39c61411 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -651,10 +651,10 @@ void db_x509::store() } mainwin->setPath(dlg->dirPath); QString fname = dlg->filename->text(); - if (fname == "") { - delete dlg; - return; - } + if (fname == "") { + delete dlg; + return; + } try { switch (dlg->exportFormat->currentIndex()) { case 0: // PEM diff --git a/lib/db_x509req.cpp b/lib/db_x509req.cpp index de43508e..845df84d 100644 --- a/lib/db_x509req.cpp +++ b/lib/db_x509req.cpp @@ -157,16 +157,37 @@ void db_x509req::showItem(QString descr) showItem(req); } -void db_x509req::store(bool pem) + +void db_x509req::store() { if (!currentIdx.isValid()) return; pki_x509req *req = static_cast(currentIdx.internalPointer()); + if (!req) + return; - req->writeReq(req->getUnderlinedName(), pem); + ExportDer *dlg = new ExportDer(mainwin, req->getUnderlinedName() + ".pem", + mainwin->getPath(), tr("Certificate request ( *.pem *.der *.crl )") ); + dlg->image->setPixmap(*MainWindow::csrImg); + dlg->label->setText(tr("Certificate request export")); + int dlgret = dlg->exec(); + + if (!dlgret) { + delete dlg; + return; + } + mainwin->setPath(dlg->dirPath); + QString fname = dlg->filename->text(); + bool pem = dlg->exportFormat->currentIndex() == 0 ? true : false; + delete dlg; + if (fname == "") { + return; + } + req->writeReq(fname, pem); } + void db_x509req::signReq() { if (!currentIdx.isValid()) @@ -179,7 +200,7 @@ void db_x509req::signReq() void db_x509req::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) { QMenu *menu = new QMenu(mainwin); - QMenu *subExport; + QAction *expItem; currentIdx = index; pki_x509req *req = static_cast(index.internalPointer()); @@ -190,11 +211,9 @@ void db_x509req::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) menu->addAction(tr("Rename"), this, SLOT(edit())); menu->addAction(tr("Show Details"), this, SLOT(showItem())); menu->addAction(tr("Sign"), this, SLOT(signReq())); - subExport = menu->addMenu(tr("Export")); - subExport->addAction(tr("PEM"), this, SLOT(store_pem())); - subExport->addAction(tr("DER"), this, SLOT(store_der())); + expItem = menu->addAction(tr("Export"), this, SLOT(store())); + expItem->setEnabled(! req->isSpki()); menu->addAction(tr("Delete"), this, SLOT(delete_ask())); - subExport->setEnabled(! req->isSpki()); } menu->exec(e->globalPos()); delete menu; diff --git a/lib/db_x509req.h b/lib/db_x509req.h index c7f71869..4b371a51 100644 --- a/lib/db_x509req.h +++ b/lib/db_x509req.h @@ -64,14 +64,12 @@ class db_x509req: public db_x509super db_x509req(QString DBfile, MainWindow *mw); pki_base* insert(pki_base *item); pki_base *newPKI(); - void store(bool pem); void showContextMenu(QContextMenuEvent *e, const QModelIndex &index); public slots: void newItem(pki_temp *temp = NULL); - void store_pem() {store(true);} - void store_der() {store(false);} void load(); + void store(); void showItem(QString descr); void showItem(pki_x509req *req); void showItem(const QModelIndex &index); diff --git a/lib/load_obj.cpp b/lib/load_obj.cpp index 439f16ad..de7732dd 100644 --- a/lib/load_obj.cpp +++ b/lib/load_obj.cpp @@ -190,7 +190,7 @@ pki_base * load_temp::loadItem(QString s) load_crl::load_crl() :load_base() { - filter.prepend(QObject::tr("Revocation lists ( *.pem *.crl )")); + filter.prepend(QObject::tr("Revocation lists ( *.pem *.der *.crl )")); caption = QObject::tr("Import Certificate Revocation List"); } diff --git a/lib/pki_crl.cpp b/lib/pki_crl.cpp index 4ff5f38c..65318910 100644 --- a/lib/pki_crl.cpp +++ b/lib/pki_crl.cpp @@ -194,7 +194,7 @@ void pki_crl::sign(pki_key *key, const EVP_MD *md) void pki_crl::writeDefault(const QString fname) { - writeCrl(fname + QDir::separator() + getIntName() + ".crl", true); + writeCrl(fname + QDir::separator() + getUnderlinedName() + ".crl", true); } void pki_crl::writeCrl(const QString fname, bool pem) diff --git a/lib/x509name.cpp b/lib/x509name.cpp index b245384e..0ec8e9da 100644 --- a/lib/x509name.cpp +++ b/lib/x509name.cpp @@ -252,7 +252,7 @@ void x509name::write_fp(FILE *fp) const int cnt = entryCount(); for (int i=0; i + ExportDer + + + + 0 + 0 + 378 + 238 + + + + + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + + Arial + 14 + 50 + false + false + false + false + + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Arial'; font-size:14pt; font-weight:400; font-style:normal; text-decoration:none;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Export</p></body></html> + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + + 95 + 40 + + + + + 95 + 40 + + + + true + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 61 + 21 + + + + + + + + QFrame::Box + + + QFrame::Sunken + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + + 0 + 1 + 0 + 0 + + + + Filename + + + + + + + + + + + 0 + 1 + 0 + 0 + + + + ... + + + + + + + + + 0 + + + 6 + + + + + Export Format + + + + + + + + 7 + 0 + 0 + 0 + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 61 + 21 + + + + + + + + 0 + + + 6 + + + + + Cancel + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + OK + + + + + + + + qPixmapFromMimeSource + + filename + PushButton7 + PushButton9 + + + + + PushButton9 + clicked() + ExportDer + reject() + + + 81 + 227 + + + 180 + 237 + + + + + PushButton7 + clicked() + ExportDer + accept() + + + 367 + 227 + + + 304 + 237 + + + + + diff --git a/widgets/ExportDer.cpp b/widgets/ExportDer.cpp new file mode 100644 index 00000000..6765294b --- /dev/null +++ b/widgets/ExportDer.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2001 Christian Hohnstaedt. + * + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the author nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * This program links to software with different licenses from: + * + * http://www.openssl.org which includes cryptographic software + * written by Eric Young (eay@cryptsoft.com)" + * + * http://www.trolltech.com + * + * + * + * http://www.hohnstaedt.de/xca + * email: christian@hohnstaedt.de + * + * $Id$ + * + */ + + +#include "ExportDer.h" +#include "lib/base.h" + +#include +#include +#include + +ExportDer::ExportDer(QWidget *parent, QString fname, QString dpath, + QString _filter) + :QDialog(parent) +{ + setupUi(this); + filename->setText(fname); + setWindowTitle(tr(XCA_TITLE)); + QStringList sl; + sl << "PEM" << "DER"; + + exportFormat->addItems(sl); + dirPath = dpath; + filter = _filter; +} + +void ExportDer::on_fileBut_clicked() +{ + QStringList filt; + filt.append(filter); + filt.append(tr("All Files ( *.* )")); + QString s = "", fn; + QFileDialog *dlg = new QFileDialog(this); + dlg->setWindowTitle(tr("Save as")); + dlg->setFilters(filt); + dlg->setFileMode( QFileDialog::AnyFile ); + fn = filename->text(); + fn = fn.mid(fn.lastIndexOf(QDir::separator()) +1, -1); + dlg->selectFile( fn ); + dlg->setDirectory(dirPath); + if (dlg->exec()) + if (!dlg->selectedFiles().isEmpty()) + s = dlg->selectedFiles()[0]; + if (! s.isEmpty()) { + QDir::convertSeparators(s); + filename->setText(s); + } + dirPath = dlg->directory().path(); + on_exportFormat_activated(0); + delete dlg; +} + +void ExportDer::on_exportFormat_activated(int) +{ + char *suffix[] = { "pem", "der" }; + int selected = exportFormat->currentIndex(); + QString fn = filename->text(); + QString nfn = fn.left(fn.lastIndexOf('.')+1) + suffix[selected]; + filename->setText(nfn); +} + diff --git a/widgets/ExportDer.h b/widgets/ExportDer.h new file mode 100644 index 00000000..bfaf819c --- /dev/null +++ b/widgets/ExportDer.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2001 Christian Hohnstaedt. + * + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the author nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * This program links to software with different licenses from: + * + * http://www.openssl.org which includes cryptographic software + * written by Eric Young (eay@cryptsoft.com)" + * + * http://www.trolltech.com + * + * + * + * http://www.hohnstaedt.de/xca + * email: christian@hohnstaedt.de + * + * $Id$ + * + */ + +#ifndef __EXPORTDER_H +#define __EXPORTDER_H + +#include "ui/ExportDer.h" + +class ExportDer: public QDialog, public Ui::ExportDer +{ + Q_OBJECT + + private: + QString filter; + + public: + ExportDer(QWidget *parent, QString fname, QString dpath, + QString _filter); + QString dirPath; + + public slots: + void on_fileBut_clicked(); + void on_exportFormat_activated(int); +}; + +#endif diff --git a/widgets/MW_database.cpp b/widgets/MW_database.cpp index a4593024..2bf113ff 100644 --- a/widgets/MW_database.cpp +++ b/widgets/MW_database.cpp @@ -357,6 +357,11 @@ void MainWindow::on_BNimportCrl_clicked(void) if (crls) crls->load(); } +void MainWindow::on_BNexportCrl_clicked(void) +{ + if (crls) + crls->storeSelectedItems(crlView); +} void MainWindow::on_BNdetailsCrl_clicked(void) { if(crls) diff --git a/widgets/MainWindow.h b/widgets/MainWindow.h index 86993378..a4e536d8 100644 --- a/widgets/MainWindow.h +++ b/widgets/MainWindow.h @@ -155,5 +155,6 @@ class MainWindow: public QMainWindow, public Ui::MainWindow void on_BNdeleteCrl_clicked(void); void on_BNdetailsCrl_clicked(void); void on_BNimportCrl_clicked(void); + void on_BNexportCrl_clicked(void); }; #endif diff --git a/widgets/Makefile b/widgets/Makefile index cf0cdf84..bd5a314e 100644 --- a/widgets/Makefile +++ b/widgets/Makefile @@ -13,7 +13,7 @@ endif MOC_NAMES=MainWindow KeyDetail clicklabel XcaTreeView ExportKey NewX509 \ validity v3ext ReqDetail distname CertDetail CertExtend ExportCert \ - ImportMulti CrlDetail + ImportMulti CrlDetail ExportDer #NAMES=$(MOC_NAMES) NewX509_ext MW_menu MW_help MW_database NAMES=$(MOC_NAMES) NewX509_ext MW_menu MW_help MW_database