diff --git a/lib/asn1time.cpp b/lib/asn1time.cpp index bef5081a..d79c7297 100644 --- a/lib/asn1time.cpp +++ b/lib/asn1time.cpp @@ -165,6 +165,15 @@ QString a1time::toPlain() const return toUTC().toString(GEN_FORMAT); } +QString a1time::toPlainUTC() const +{ + if (isUndefined()) + return QString(UNDEFINED_DATE); + if (!isValid()) + return QString("Broken-InvalidZ"); + return toUTC().toString(UTC_FORMAT); +} + QString a1time::toSortable() const { if (isUndefined()) diff --git a/lib/asn1time.h b/lib/asn1time.h index 70593c64..cb3ebc06 100644 --- a/lib/asn1time.h +++ b/lib/asn1time.h @@ -34,6 +34,7 @@ class a1time : public QDateTime QString toPretty() const; QString toPrettyGMT() const; QString toPlain() const; + QString toPlainUTC() const; QString toSortable() const; ASN1_TIME *get(); ASN1_TIME *get_utc(); diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index 849e9acd..5d5c0aa7 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -307,12 +307,28 @@ QList db_x509::getCerts(bool onlyTrusted) return c; } -void db_x509::writeIndex(const QString fname) +void db_x509::writeIndex(const QString fname, bool hierarchy) { bool append = false; - FOR_ALL_pki(pki, pki_x509) { - pki->writeIndexEntry(fname, append); - append = true; + if (hierarchy) { + FOR_ALL_pki(pki, pki_x509) { + if (pki->childCount()) { + + QString newfname = fname + "." + pki->getIntName().replace(QRegExp("[^a-zA-Z0-9]"),QString(""));; + + append = false; + foreach(pki_base *_child, pki->childItems) { + pki_x509 *child = static_cast(_child); + child->writeIndexEntry(newfname, append); + append = true; + } + } + } + } else { + FOR_ALL_pki(pki, pki_x509) { + pki->writeIndexEntry(fname, append); + append = true; + } } } diff --git a/lib/db_x509.h b/lib/db_x509.h index 2f1ec759..f7554e6a 100644 --- a/lib/db_x509.h +++ b/lib/db_x509.h @@ -46,7 +46,7 @@ class db_x509: public db_x509super QList getCerts(bool onlyTrusted); a1int searchSerial(pki_x509 *signer); void writeAllCerts(const QString fname, bool onlyTrusted); - void writeIndex(const QString fname); + void writeIndex(const QString fname, bool hierarchy); pki_x509 *getByIssSerial(const pki_x509 *issuer, const a1int &a); pki_x509 *getBySubject(const x509name &xname, pki_x509 *last = NULL); pki_base *insert(pki_base *item); diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp index 21a0da83..557f710d 100644 --- a/lib/pki_x509.cpp +++ b/lib/pki_x509.cpp @@ -596,8 +596,8 @@ void pki_x509::writeIndexEntry(FILE *fp) flag = "E"; QString line = QString("%1\t%2\t%3\t%4\tunknown\t%5\n").arg( - flag, getNotAfter().toPlain(), (revoked ? revocation.getDate().toPlain() : ""), - getSerial().toHex(), getSubject().oneLine(XN_FLAG_ONELINE)); + flag, getNotAfter().toPlainUTC(), (revoked ? revocation.getDate().toPlainUTC() : ""), + getSerial().toHex(), QString(X509_NAME_oneline(getSubject().get(), NULL, 0))); QByteArray ba = line.toUtf8(); fwrite(ba.constData(), ba.size(), 1, fp); diff --git a/widgets/MW_help.cpp b/widgets/MW_help.cpp index fe4b36b7..b99daa3b 100644 --- a/widgets/MW_help.cpp +++ b/widgets/MW_help.cpp @@ -33,6 +33,7 @@ void MainWindow::cmd_help(const char* msg) { " -e : extract entry.\n" " -d expect the following argument to be the database name to use\n" " -i expect the following argument to be the index file to generate\n" + " -I expect the following argument to be the base name the index file hierarchy to generate\n" " -x Exit after processing all commandline options\n\n"); if(msg) { diff --git a/widgets/MW_menu.cpp b/widgets/MW_menu.cpp index c866a716..67adf4bd 100644 --- a/widgets/MW_menu.cpp +++ b/widgets/MW_menu.cpp @@ -140,6 +140,8 @@ void MainWindow::init_menu() SLOT(dump_database())); acList += extra->addAction(tr("&Export Certificate Index"), this, SLOT(exportIndex())); + acList += extra->addAction(tr("&Export Certificate Index hierarchy"), this, + SLOT(exportIndexHierarchy())); acList += extra->addAction(tr("C&hange DataBase password"), this, SLOT(changeDbPass())); acList += extra->addAction(tr("&Import old db_dump"), this, diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index d3eeb820..1c3b0f24 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -281,6 +281,9 @@ void MainWindow::read_cmdline(int argc, char *argv[]) case 'i': export_index=1; break; + case 'I': + export_index=2; + break; case 'v': cmd_version(); opt=0; @@ -309,7 +312,7 @@ void MainWindow::read_cmdline(int argc, char *argv[]) exitApp = 1; force_load = 0; } else if (export_index) { - if (exportIndex(file) == 2) + if (exportIndex(file, (export_index == 2)) == 2) exitApp = 1; export_index = 0; } else { @@ -866,10 +869,15 @@ pki_multi *MainWindow::probeAnything(QString file, int *ret) void MainWindow::exportIndex() { - exportIndex(NULL); + exportIndex(NULL, false); } -int MainWindow::exportIndex(QString fname) +void MainWindow::exportIndexHierarchy() +{ + exportIndex(NULL, true); +} + +int MainWindow::exportIndex(QString fname, bool hierarchy) { if (fname == NULL || fname.isEmpty()) { @@ -889,7 +897,17 @@ int MainWindow::exportIndex(QString fname) return 2; } - certs->writeIndex(fname); + bool needChangeView = hierarchy && !certs->treeview; + if (needChangeView) { + certView->changeView(); + } + + certs->writeIndex(fname, hierarchy); + + if (needChangeView) { + certView->changeView(); + } + return 0; } diff --git a/widgets/MainWindow.h b/widgets/MainWindow.h index ae551c07..a720ed69 100644 --- a/widgets/MainWindow.h +++ b/widgets/MainWindow.h @@ -86,7 +86,7 @@ class MainWindow: public QMainWindow, public Ui::MainWindow QStringList urlsToOpen; int checkOldGetNewPass(Passwd &pass); QString updateDbPassword(QString newdb, Passwd pass); - int exportIndex(QString fname); + int exportIndex(QString fname, bool hierarchy); protected: void init_images(); @@ -167,6 +167,7 @@ class MainWindow: public QMainWindow, public Ui::MainWindow void openURLs(); void changeEvent(QEvent *event); void exportIndex(); + void exportIndexHierarchy(); protected slots: void closeEvent(QCloseEvent * event);