diff --git a/lib/db_base.cpp b/lib/db_base.cpp index 82e8f431..6cbe213f 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -19,13 +19,13 @@ db_base::db_base(QString db, MainWindow *mw) { dbName = db; rootItem = newPKI(); - headertext.clear(); mainwin = mw; currentIdx = QModelIndex(); view = NULL; class_name = "base"; for (size_t i =0; i(parent.internalPointer()); - } - return item->columns(); + return allHeaders.count(); } QVariant db_base::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); - + dbheader *hd = allHeaders[index.column()]; pki_base *item = static_cast(index.internalPointer()); switch (role) { case Qt::EditRole: case Qt::DisplayRole: - return item->column_data(index.column()); + return item->column_data(hd->id); case Qt::DecorationRole: - return item->getIcon(index.column()); + return item->getIcon(hd->id); } return QVariant(); } @@ -424,9 +416,14 @@ QVariant db_base::data(const QModelIndex &index, int role) const QVariant db_base::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return headertext[section]; - + if (orientation == Qt::Horizontal) { + switch (role) { + case Qt::DisplayRole: + return QVariant(allHeaders[section]->name); + case Qt::ToolTipRole: + return QVariant(allHeaders[section]->tooltip); + } + } return QVariant(); } @@ -505,3 +502,57 @@ void db_base::showItem() showItem(currentIdx); } +bool db_base::columnHidden(int col) const +{ + return !allHeaders[col]->show; +} + +void db_base::columnResetDefaults() +{ + dbheader *hd; + foreach(hd, allHeaders) { + hd->show = hd->showDefault; + if (hd->action) + hd->action->setChecked(hd->show); + } + emit resetHeader(); +} + +bool db_base::isNumericCol(int col) const +{ + return allHeaders[col]->isNumeric(); +} + +void db_base::showHeaderMenu(QContextMenuEvent *e, int sect) +{ + int shown = 0; + QMenu *menu = new QMenu(mainwin); + QMenu *dn = NULL; + QAction *a; + dbheader *hd; + menu->addAction(tr("Reset"), this, SLOT(columnResetDefaults())); + menu->addSeparator(); + foreach(hd, allHeaders) { + if (hd->isNid()) { + if (!dn) + dn = menu->addMenu(tr("Subject")); + a = dn->addAction(hd->name); + } else { + a = menu->addAction(hd->name); + } + a->setCheckable(true); + a->setChecked(hd->show); + if (!hd->tooltip.isEmpty()) + a->setToolTip(hd->tooltip); + hd->action = a; + } + menu->exec(e->globalPos()); + foreach(hd, allHeaders) { + hd->show = hd->action->isChecked(); + shown += hd->show ? 1 : 0; + hd->action = NULL; + } + if (!shown) + allHeaders[0]->show = true; + delete menu; +} diff --git a/lib/db_base.h b/lib/db_base.h index e6c81030..42bbc1ac 100644 --- a/lib/db_base.h +++ b/lib/db_base.h @@ -13,6 +13,7 @@ #include "load_obj.h" #include #include +#include #include #include #include "pki_base.h" @@ -37,11 +38,10 @@ class db_base: public QAbstractItemModel void _removePKI(pki_base *pki ); void removeItem(QString k); enum pki_type pkitype[4]; - QList headertext; MainWindow *mainwin; XcaTreeView *view; QString class_name; - + dbheaderList allHeaders; public: pki_base *rootItem; db_base(QString db, MainWindow *mw); @@ -80,11 +80,15 @@ class db_base: public QAbstractItemModel void load_default(load_base &load); void insertChild(pki_base *parent, pki_base *child); void createSuccess(pki_base *pki); + void showHeaderMenu(QContextMenuEvent *e, int sect); + bool columnHidden(int col) const; + bool isNumericCol(int col) const; public slots: void deletePKI(); void delete_ask(); void edit(); + void columnResetDefaults(); virtual void showItem(); virtual void store(){}; virtual void showPki(pki_base *) {}; @@ -93,6 +97,7 @@ class db_base: public QAbstractItemModel signals: void connNewX509(NewX509 *dlg); + void resetHeader(); }; #endif diff --git a/lib/db_crl.cpp b/lib/db_crl.cpp index 8e9d4566..a8d469a5 100644 --- a/lib/db_crl.cpp +++ b/lib/db_crl.cpp @@ -16,10 +16,15 @@ #include "ui_NewCrl.h" db_crl::db_crl(QString db, MainWindow *mw) - :db_base(db,mw) + :db_x509name(db,mw) { - headertext << tr("Name") << tr("Signer") << tr("Common name") << - tr("No. revoked") << tr("Next update"); + allHeaders << + new dbheader(HD_crl_signer, true, tr("Signer")) << + new dbheader(HD_crl_revoked, true, tr("No. revoked")) << + new dbheader(HD_crl_lastUpdate, false,tr("Last update")) << + new dbheader(HD_crl_nextUpdate, true, tr("Next update")) << + new dbheader(HD_crl_crlnumber, false,tr("CRL number")); + view = mw->crlView; class_name = "crls"; pkitype[0] = revokation; @@ -70,7 +75,7 @@ void db_crl::inToCont(pki_base *pki) revokeCerts(crl); if (crl->getIssuer() == NULL) { pki_x509 *iss = NULL, *last = NULL; - x509name issname = crl->getIssuerName(); + x509name issname = crl->getSubject(); while ((iss = mainwin->certs->getBySubject(issname, last)) != NULL) { pki_key *key = iss->getPubKey(); if (crl->verify(key)) { diff --git a/lib/db_crl.h b/lib/db_crl.h index 4f7159f4..6b5f8c60 100644 --- a/lib/db_crl.h +++ b/lib/db_crl.h @@ -15,7 +15,7 @@ #include #include -class db_crl: public db_base +class db_crl: public db_x509name { Q_OBJECT protected: diff --git a/lib/db_key.cpp b/lib/db_key.cpp index eaf55a75..dcaf0173 100644 --- a/lib/db_key.cpp +++ b/lib/db_key.cpp @@ -32,12 +32,15 @@ db_key::db_key(QString db, MainWindow *mw) :db_base(db, mw) { rootItem->setIntName("[key root]"); - headertext << tr("Name") << tr("Type") << tr("Size") - << tr("Use") << tr("Password"); view = mw->keyView; class_name = "keys"; pkitype[0] = asym_key; pkitype[1] = smartCard; + allHeaders << + new dbheader(HD_key_type, true, tr("Type")) << + new dbheader(HD_key_size, true, tr("Size")) << + new dbheader(HD_key_use, true, tr("Use")) << + new dbheader(HD_key_passwd, true, tr("Password")); loadContainer(); } diff --git a/lib/db_temp.cpp b/lib/db_temp.cpp index b6749403..efea6245 100644 --- a/lib/db_temp.cpp +++ b/lib/db_temp.cpp @@ -18,9 +18,9 @@ #include db_temp::db_temp(QString DBfile, MainWindow *mw) - :db_base(DBfile, mw) + :db_x509name(DBfile, mw) { - headertext << tr("Name") << tr("Type"); + allHeaders << new dbheader(HD_temp_type, true, tr("Type")); view = mw->tempView; class_name = "templates"; pkitype[0] = tmpl; diff --git a/lib/db_temp.h b/lib/db_temp.h index 87471a1c..2853130d 100644 --- a/lib/db_temp.h +++ b/lib/db_temp.h @@ -11,12 +11,13 @@ #include "db_base.h" #include "pki_temp.h" +#include "db_x509super.h" #include #include class Mainwin; -class db_temp: public db_base +class db_temp: public db_x509name { Q_OBJECT protected: diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index d10cde0b..2e72bf07 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -29,8 +29,17 @@ db_x509::db_x509(QString DBfile, MainWindow *mw) :db_x509super(DBfile, mw) { rootItem->setIntName("[x509 root]"); - headertext << tr("Internal name") << tr("Common name") << tr("Serial") - << tr("Expiry date") << tr("Trust state") << tr("Revocation"); + allHeaders << + new dbheader(HD_cert_ca, true, tr("CA")) << + new dbheader(HD_cert_serial, true, tr("Serial")) << + new dbheader(HD_cert_md5fp, false,tr("md5 fingerprint")) << + new dbheader(HD_cert_sha1fp, false,tr("sha1 fingerprint")) << + new dbheader(HD_cert_notBefore, false,tr("Start date"), + tr("not Before")) << + new dbheader(HD_cert_notAfter, true, tr("Expiry date"), + tr("not After")) << + new dbheader(HD_cert_trust, true, tr("Trust state")) << + new dbheader(HD_cert_revokation,true, tr("Revocation")); view = mw->certView; class_name = "certificates"; diff --git a/lib/db_x509req.cpp b/lib/db_x509req.cpp index d2d688a6..2a2d7f2f 100644 --- a/lib/db_x509req.cpp +++ b/lib/db_x509req.cpp @@ -18,7 +18,8 @@ db_x509req::db_x509req(QString DBfile, MainWindow *mw) :db_x509super(DBfile, mw) { - headertext << tr("Name") << tr("Subject") << tr("Signed"); + allHeaders << new dbheader(HD_req_signed, true, tr("Signed"), + tr("whether the request is already signed or not")); view = mw->reqView; class_name = "requests"; pkitype[0] = x509_req; diff --git a/lib/db_x509super.cpp b/lib/db_x509super.cpp index 5debdfcb..443c1ec7 100644 --- a/lib/db_x509super.cpp +++ b/lib/db_x509super.cpp @@ -10,8 +10,20 @@ #include "ui_About.h" #include -db_x509super::db_x509super(QString db, MainWindow *mw) +db_x509name::db_x509name(QString db, MainWindow *mw) :db_base(db, mw) +{ + NIDlist dn_nid = *MainWindow::dn_nid; + allHeaders << new dbheader(HD_subject_name, false, tr("Full name"), + tr("Complete distinguished name")); + for (int i=0; i < dn_nid.count(); i++) { + int nid = dn_nid[i]; + allHeaders << new dbheader(nid, nid == NID_commonName); + } +} + +db_x509super::db_x509super(QString db, MainWindow *mw) + :db_x509name(db, mw) { } diff --git a/lib/db_x509super.h b/lib/db_x509super.h index 0bf5900c..9ed425a3 100644 --- a/lib/db_x509super.h +++ b/lib/db_x509super.h @@ -12,7 +12,14 @@ #include "db_key.h" #include "pki_x509super.h" -class db_x509super: public db_base +class db_x509name: public db_base +{ + Q_OBJECT + public: + db_x509name(QString db, MainWindow *mw); +}; + +class db_x509super: public db_x509name { Q_OBJECT diff --git a/lib/headerlist.h b/lib/headerlist.h new file mode 100644 index 00000000..73d7be97 --- /dev/null +++ b/lib/headerlist.h @@ -0,0 +1,91 @@ + +#include +#include +#include +#include + +#define HD_undef NID_undef +#define HD_internal_name -2 +#define HD_subject_name -3 + +#define HD_cert_serial -10 +#define HD_cert_notBefore -11 +#define HD_cert_notAfter -12 +#define HD_cert_trust -13 +#define HD_cert_revokation -14 +#define HD_cert_ca -15 +#define HD_cert_md5fp -16 +#define HD_cert_sha1fp -17 + +#define HD_req_signed -20 +#define HD_temp_type -30 + +#define HD_crl_signer -40 +#define HD_crl_revoked -42 +#define HD_crl_lastUpdate -43 +#define HD_crl_nextUpdate -44 +#define HD_crl_crlnumber -45 + +#define HD_key_type -50 +#define HD_key_size -51 +#define HD_key_use -52 +#define HD_key_passwd -53 + +class dbheader +{ + public: + int id; + bool show; + bool showDefault; + QString name; + QString tooltip; + QAction *action; + dbheader(QString aname = QString()) + { + id = HD_undef; + name = aname; + action = NULL; + show = showDefault = false; + } + dbheader(int aid, bool ashow = false, + QString aname = QString(), QString atip = QString()) + { + id = aid; + name = aname; + tooltip = atip; + if (isNid() && name.isEmpty()) { + name = OBJ_nid2ln(aid); + tooltip = OBJ_nid2sn(aid); + } + action = NULL; + show = showDefault = ashow; + } + bool operator == (const dbheader *h) const + { + if (h->id == HD_undef) + return name == h->name; + return id == h->id; + } + bool isNid() const + { + return (id > 0); + } + static bool isNid(int i) + { + return (i > 0); + } + bool isNumeric() + { + switch (id) { + case HD_key_size: + case HD_key_use: + case HD_cert_serial: + case HD_crl_revoked: + case HD_crl_crlnumber: + return true; + } + return false; + } +}; + +typedef QList dbheaderList; diff --git a/lib/pki_base.cpp b/lib/pki_base.cpp index 921c0a5b..6700937f 100644 --- a/lib/pki_base.cpp +++ b/lib/pki_base.cpp @@ -21,7 +21,6 @@ pki_base::pki_base(const QString name, pki_base *p) childItems.clear(); dataVersion=0; pkiType=none; - cols=1; } int pki_base::getVersion() @@ -170,19 +169,20 @@ pki_base *pki_base::takeFirst() return childItems.takeFirst(); } -int pki_base::columns(void) +QVariant pki_base::column_data(int id) { - return cols; + switch (id) { + case HD_internal_name: + return QVariant(getIntName()); + } + return QVariant(); } -QVariant pki_base::column_data(int col) -{ - return QVariant("invalid"); -} QVariant pki_base::getIcon(int column) { return QVariant(); } + void pki_base::oldFromData(unsigned char *p, int size) { } diff --git a/lib/pki_base.h b/lib/pki_base.h index 204bb1a0..ffc90e8b 100644 --- a/lib/pki_base.h +++ b/lib/pki_base.h @@ -13,6 +13,7 @@ #include #include "db.h" #include "base.h" +#include "headerlist.h" #define __ME QString("(%1:%2)").arg(class_name).arg(getIntName()) #define pki_openssl_error() _openssl_error(__ME, __FILE__, __LINE__) @@ -24,7 +25,6 @@ class pki_base : public QObject private: static int pki_counter; protected: - int cols; const char *class_name; QString desc; int dataVersion; @@ -80,9 +80,8 @@ class pki_base : public QObject pki_base *iterate(pki_base *pki = NULL); void takeChild(pki_base *pki); pki_base *takeFirst(); - int columns(); - virtual QVariant column_data(int col); - virtual QVariant getIcon(int column); + virtual QVariant column_data(int id); + virtual QVariant getIcon(int id); const char *className() { return class_name; diff --git a/lib/pki_crl.cpp b/lib/pki_crl.cpp index 02e77aea..45516bf2 100644 --- a/lib/pki_crl.cpp +++ b/lib/pki_crl.cpp @@ -14,7 +14,7 @@ QPixmap *pki_crl::icon = NULL; pki_crl::pki_crl(const QString name ) - :pki_base(name) + :pki_x509name(name) { issuer = NULL; crl = X509_CRL_new(); @@ -22,7 +22,6 @@ pki_crl::pki_crl(const QString name ) pki_openssl_error(); dataVersion=1; pkiType=revokation; - cols=3; } void pki_crl::fromPEM_BIO(BIO *bio, QString name) @@ -252,7 +251,7 @@ x509rev pki_crl::getRev(int num) return ret; } -x509name pki_crl::getIssuerName() +x509name pki_crl::getSubject() const { x509name x; if (crl && crl->crl && crl->crl->issuer) { @@ -280,6 +279,19 @@ void pki_crl::setCrlNumber(a1int num) pki_openssl_error(); } +bool pki_crl::getCrlNumber(a1int *num) +{ + int j; + ASN1_INTEGER *i; + i = (ASN1_INTEGER *)X509_CRL_get_ext_d2i(crl, NID_crl_number, &j, NULL); + pki_openssl_error(); + if (j == -1) + return false; + num->set(i); + ASN1_INTEGER_free(i); + return true; +} + x509v3ext pki_crl::getExtByNid(int nid) { extList el; @@ -301,29 +313,32 @@ QString pki_crl::printV3ext() return text; } -QVariant pki_crl::column_data(int col) +QVariant pki_crl::column_data(int id) { - switch (col) { - case 0: - return QVariant(getIntName()); - case 1: + switch (id) { + case HD_crl_signer: if (issuer) return QVariant(getIssuer()->getIntName()); else - return QVariant(tr("unknown")); - case 2: - return QVariant(getIssuerName().getEntryByNid(NID_commonName)); - case 3: + return QVariant(tr("unknown")); + case HD_crl_revoked: return QVariant(numRev()); - case 4: + case HD_crl_lastUpdate: + return QVariant(getLastUpdate().toSortable()); + case HD_crl_nextUpdate: return QVariant(getNextUpdate().toSortable()); + case HD_crl_crlnumber: + a1int a; + if (getCrlNumber(&a)) + return QVariant(a.toDec()); + return QVariant(); } - return QVariant(); + return pki_x509name::column_data(id); } -QVariant pki_crl::getIcon(int column) +QVariant pki_crl::getIcon(int id) { - return column == 0 ? QVariant(*icon) : QVariant(); + return id == HD_internal_name ? QVariant(*icon) : QVariant(); } void pki_crl::oldFromData(unsigned char *p, int size) diff --git a/lib/pki_crl.h b/lib/pki_crl.h index eeced7e6..fef8da67 100644 --- a/lib/pki_crl.h +++ b/lib/pki_crl.h @@ -16,7 +16,7 @@ #include "asn1time.h" #include "asn1int.h" -class pki_crl: public pki_base +class pki_crl: public pki_x509name { Q_OBJECT friend class pki_x509; @@ -41,7 +41,7 @@ class pki_crl: public pki_base void writeCrl(const QString fname, bool pem = true); pki_x509 *getIssuer(); void setIssuer(pki_x509 *iss); - x509name getIssuerName(); + x509name getSubject() const; void setLastUpdate(const a1time &t); void setNextUpdate(const a1time &t); a1time getNextUpdate(); @@ -56,12 +56,13 @@ class pki_crl: public pki_base QString printV3ext(); x509v3ext getExtByNid(int nid); a1int getVersion(); - QVariant column_data(int col); - QVariant getIcon(int column); + QVariant column_data(int id); + QVariant getIcon(int id); virtual QString getMsg(msg_type msg); void d2i(QByteArray &ba); QByteArray i2d(); void setCrlNumber(a1int num); + bool getCrlNumber(a1int *num); }; #endif diff --git a/lib/pki_evp.cpp b/lib/pki_evp.cpp index dee88fb7..07fe0b1b 100644 --- a/lib/pki_evp.cpp +++ b/lib/pki_evp.cpp @@ -60,7 +60,6 @@ void pki_evp::init(int type) ownPass = ptCommon; dataVersion=2; pkiType=asym_key; - cols=5; } QString pki_evp::removeTypeFromIntName(QString n) @@ -666,32 +665,9 @@ const EVP_MD *pki_evp::getDefaultMD() return md; } -QVariant pki_evp::column_data(int col) +QVariant pki_evp::getIcon(int id) { - QStringList sl; - sl << tr("Common") << tr("Private") << tr("Bogus"); - switch (col) { - case 0: - return QVariant(getIntName()); - case 1: - return QVariant(getTypeString()); - case 2: - return QVariant(length()); - case 3: - return QVariant(getUcount()); - case 4: - if (isPubKey()) - return QVariant(tr("No password")); - if (ownPass<0 || ownPass>2) - return QVariant("Holla die Waldfee"); - return QVariant(sl[ownPass]); - } - return QVariant(); -} - -QVariant pki_evp::getIcon(int column) -{ - if (column != 0) + if (id != HD_internal_name) return QVariant(); int pixnum= isPubKey() ? 1 : 0; return QVariant(*icon[pixnum]); diff --git a/lib/pki_evp.h b/lib/pki_evp.h index 7f15f261..4a061309 100644 --- a/lib/pki_evp.h +++ b/lib/pki_evp.h @@ -71,8 +71,7 @@ class pki_evp: public pki_key bool isPubKey() const; int verify(); const EVP_MD *getDefaultMD(); - QVariant column_data(int col); - QVariant getIcon(int column); + QVariant getIcon(int id); }; #endif diff --git a/lib/pki_key.cpp b/lib/pki_key.cpp index c345936f..5f626ed5 100644 --- a/lib/pki_key.cpp +++ b/lib/pki_key.cpp @@ -296,26 +296,24 @@ QString pki_key::BN2QString(BIGNUM *bn) const return x; } -QVariant pki_key::column_data(int col) +QVariant pki_key::column_data(int id) { QStringList sl; sl << tr("Common") << tr("Private") << tr("Bogus") << tr("PIN"); - switch (col) { - case 0: - return QVariant(getIntName()); - case 1: + switch (id) { + case HD_key_type: return QVariant(getTypeString()); - case 2: + case HD_key_size: return QVariant(length()); - case 3: + case HD_key_use: return QVariant(getUcount()); - case 4: + case HD_key_passwd: if (isPubKey()) return QVariant(tr("No password")); if (ownPass<0 || ownPass>3) return QVariant("Holla die Waldfee"); return QVariant(sl[ownPass]); } - return QVariant(); + return pki_base::column_data(id); } diff --git a/lib/pki_key.h b/lib/pki_key.h index 7bf7aa5d..2025a427 100644 --- a/lib/pki_key.h +++ b/lib/pki_key.h @@ -77,7 +77,7 @@ class pki_key: public pki_base { return key; } - QVariant column_data(int col); + QVariant column_data(int id); QString modulus(); QString pubEx(); QString subprime(); diff --git a/lib/pki_scard.cpp b/lib/pki_scard.cpp index 7204bc89..13cb0821 100644 --- a/lib/pki_scard.cpp +++ b/lib/pki_scard.cpp @@ -137,7 +137,6 @@ void pki_scard::init(void) ownPass = ptPin; dataVersion = 2; pkiType = smartCard; - cols = 5; card_serial = card_manufacturer = card_label = ""; card_model = slot_label = ""; @@ -756,8 +755,8 @@ bool pki_scard::isToken() return true; } -QVariant pki_scard::getIcon(int column) +QVariant pki_scard::getIcon(int id) { - return column == 0 ? QVariant(*icon[0]) : QVariant(); + return id == HD_internal_name ? QVariant(*icon[0]) : QVariant(); } diff --git a/lib/pki_scard.h b/lib/pki_scard.h index c0fa6c56..215199a0 100644 --- a/lib/pki_scard.h +++ b/lib/pki_scard.h @@ -72,7 +72,7 @@ class pki_scard: public pki_key void changeSoPin(); int verify(); bool isToken(); - QVariant getIcon(int column); + QVariant getIcon(int id); QList getMech_list() { return mech_list; diff --git a/lib/pki_temp.cpp b/lib/pki_temp.cpp index f5299369..3c0cf58c 100644 --- a/lib/pki_temp.cpp +++ b/lib/pki_temp.cpp @@ -16,12 +16,11 @@ QPixmap *pki_temp::icon= NULL; pki_temp::pki_temp(const pki_temp *pk) - :pki_base(pk->desc) + :pki_x509name(pk->desc) { class_name = pk->class_name; dataVersion=pk->dataVersion; pkiType=pk->pkiType; - cols=pk->cols; xname=pk->xname; subAltName=pk->subAltName; @@ -54,12 +53,11 @@ pki_temp::pki_temp(const pki_temp *pk) } pki_temp::pki_temp(const QString d) - :pki_base(d) + :pki_x509name(d) { class_name = "pki_temp"; dataVersion=6; pkiType=tmpl; - cols=2; subAltName=""; issAltName=""; @@ -108,6 +106,11 @@ QString pki_temp::getMsg(msg_type msg) return pki_base::getMsg(msg); } +x509name pki_temp::getSubject() const +{ + return xname; +} + static int bitsToInt(extList &el, int nid, bool *crit) { int ret = 0, i = el.idxByNid(nid); @@ -419,20 +422,18 @@ bool pki_temp::compare(pki_base *) return false; } -QVariant pki_temp::column_data(int col) +QVariant pki_temp::column_data(int id) { - switch (col) { - case 0: - return QVariant(getIntName()); - case 1: + switch (id) { + case HD_temp_type: return QVariant(destination); } - return QVariant(); + return pki_x509name::column_data(id); } -QVariant pki_temp::getIcon(int column) +QVariant pki_temp::getIcon(int id) { - return column == 0 ? QVariant(*icon) : QVariant(); + return id == HD_internal_name ? QVariant(*icon) : QVariant(); } void pki_temp::oldFromData(unsigned char *p, int size) diff --git a/lib/pki_temp.h b/lib/pki_temp.h index 7c52d6cb..5d84a543 100644 --- a/lib/pki_temp.h +++ b/lib/pki_temp.h @@ -13,7 +13,7 @@ #include "asn1time.h" #include "pki_x509.h" -class pki_temp: public pki_base +class pki_temp: public pki_x509name { Q_OBJECT protected: @@ -45,10 +45,10 @@ class pki_temp: public pki_base QByteArray toData(); bool compare(pki_base *ref); void writeTemp(QString fname); - QVariant column_data(int col); - QVariant getIcon(int column); + QVariant column_data(int id); + QVariant getIcon(int id); virtual QString getMsg(msg_type msg); - + x509name getSubject() const; }; #endif diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp index 8e403560..ccaa7232 100644 --- a/lib/pki_x509.cpp +++ b/lib/pki_x509.cpp @@ -18,7 +18,7 @@ #include #include -QPixmap *pki_x509::icon[5] = { NULL, NULL, NULL, NULL, NULL }; +QPixmap *pki_x509::icon[6] = { NULL, NULL, NULL, NULL, NULL, NULL }; pki_x509::pki_x509(X509 *c) :pki_x509super() @@ -141,7 +141,6 @@ void pki_x509::init() isrevoked = false; dataVersion = 3; pkiType = x509; - cols = 6; randomSerial = false; revoke_reason = ""; } @@ -754,44 +753,82 @@ x509rev pki_x509::getRev() return a; } -QVariant pki_x509::column_data(int col) +bool pki_x509::caAndPathLen(bool *ca, a1int *pathlen, bool *hasLen) +{ + x509v3ext e = getExtByNid(NID_basic_constraints); + if (e.nid() != NID_basic_constraints) + return false; + BASIC_CONSTRAINTS *bc = (BASIC_CONSTRAINTS *)e.d2i(); + if (hasLen) + *hasLen = bc->pathlen ? true : false; + if (pathlen && bc->pathlen) + pathlen->set(bc->pathlen); + if (ca) + *ca = bc->ca; + BASIC_CONSTRAINTS_free(bc); + return true; +} + +QVariant pki_x509::column_data(int id) { QString truststatus[] = { tr("Not trusted"), tr("Trust inherited"), tr("Always Trusted") }; - switch (col) { - case 0: - return QVariant(getIntName()); - case 1: - return QVariant(getSubject().getEntryByNid(NID_commonName)); - case 2: + switch (id) { + case HD_cert_serial: return QVariant(getSerial().toHex()); - case 3: - return QVariant(getNotAfter().toSortable()); - case 4: - return QVariant(truststatus[ getTrust() ]); - case 5: + case HD_cert_notBefore: + return QVariant(getNotBefore().qDateTime()); + case HD_cert_notAfter: + return QVariant(getNotAfter().qDateTime()); + case HD_cert_trust: + return QVariant(truststatus[getTrust()]); + case HD_cert_revokation: if (isRevoked()) return QVariant(getRevoked().toSortable()); else if (canSign()) return QVariant(tr("CRL expires: %1"). arg(crlExpiry.toSortable())); + return QVariant(); + case HD_cert_md5fp: + return QVariant(fingerprint(EVP_md5())); + case HD_cert_sha1fp: + return QVariant(fingerprint(EVP_sha1())); + case HD_cert_ca: { + a1int len; + bool ca, haslen; + if (caAndPathLen(&ca, &len, &haslen)) + if (ca && haslen) + return QVariant(len.toDec()); + return QVariant(); + } } - return QVariant(); - + return pki_x509super::column_data(id); } -QVariant pki_x509::getIcon(int column) +QVariant pki_x509::getIcon(int id) { int pixnum = 0; - if (column != 0) - return QVariant(); + bool ca; - if (getRefKey()) { - pixnum += 1; - } - if (calcEffTrust() == 0){ - pixnum += 2; + switch (id) { + case HD_cert_ca: + if (!caAndPathLen(&ca, NULL, NULL)) + return QVariant(); + if (!ca) + return QVariant(); + pixnum = 5; + break; + case HD_internal_name: + if (getRefKey()) { + pixnum += 1; + } + if (calcEffTrust() == 0){ + pixnum += 2; + } + break; + default: + return QVariant(); } return QVariant(*icon[pixnum]); } diff --git a/lib/pki_x509.h b/lib/pki_x509.h index 909b0171..ccef15e0 100644 --- a/lib/pki_x509.h +++ b/lib/pki_x509.h @@ -38,7 +38,7 @@ class pki_x509 : public pki_x509super QString revoke_reason; void init(); public: - static QPixmap *icon[5]; + static QPixmap *icon[6]; pki_x509(X509 *c); pki_x509(const pki_x509 *crt); pki_x509(const QString name = ""); @@ -62,6 +62,7 @@ class pki_x509 : public pki_x509super x509name getIssuer() const; void setSubject(const x509name &n); void setIssuer(const x509name &n); + bool caAndPathLen(bool *ca, a1int *pathlen, bool *hasLen); QByteArray toData(); void fromData(const unsigned char *p, db_header_t *head); @@ -141,8 +142,8 @@ class pki_x509 : public pki_x509super QString getSigAlg(); x509v3ext getExtByNid(int nid); const EVP_MD *getDigest(); - QVariant column_data(int col); - QVariant getIcon(int column); + QVariant column_data(int id); + QVariant getIcon(int id); QByteArray i2d(); void d2i(QByteArray &ba); void deleteFromToken(); diff --git a/lib/pki_x509req.cpp b/lib/pki_x509req.cpp index a81a1da8..e07e05a2 100644 --- a/lib/pki_x509req.cpp +++ b/lib/pki_x509req.cpp @@ -28,7 +28,6 @@ pki_x509req::pki_x509req(const QString name) spki = NULL; dataVersion=1; pkiType=x509_req; - cols=3; done = false; } @@ -397,31 +396,28 @@ ASN1_IA5STRING *pki_x509req::spki_challange() return NULL; } -QVariant pki_x509req::column_data(int col) +QVariant pki_x509req::column_data(int id) { - switch (col) { - case 0: - return QVariant(getIntName()); - case 1: - return QVariant(getSubject().getEntryByNid(NID_commonName)); - case 2: + switch (id) { + case HD_req_signed: return QVariant(done ? tr("Signed") : tr("Unhandled")); } - return QVariant(); + return pki_x509super::column_data(id); } -QVariant pki_x509req::getIcon(int column) + +QVariant pki_x509req::getIcon(int id) { int pixnum = -1; - switch (column) { - case 0: + switch (id) { + case HD_internal_name: pixnum = 0; if (getRefKey() != NULL ) pixnum = 1; if (spki != NULL) pixnum = 2; break; - case 2: + case HD_req_signed: if (done) pixnum = 3; break; diff --git a/lib/pki_x509req.h b/lib/pki_x509req.h index 6376f900..dec100f2 100644 --- a/lib/pki_x509req.h +++ b/lib/pki_x509req.h @@ -61,8 +61,8 @@ class pki_x509req : public pki_x509super void setSubject(const x509name &n); /* SPKAC special functions */ ASN1_IA5STRING *spki_challange(); - QVariant column_data(int col); - QVariant getIcon(int column); + QVariant column_data(int id); + QVariant getIcon(int id); void setDone() { done = true; diff --git a/lib/pki_x509super.cpp b/lib/pki_x509super.cpp index d06d9a0e..e7e2fb9c 100644 --- a/lib/pki_x509super.cpp +++ b/lib/pki_x509super.cpp @@ -8,7 +8,7 @@ #include "pki_x509super.h" pki_x509super::pki_x509super(const QString name) - : pki_base(name) + : pki_x509name(name) { privkey = NULL; } @@ -46,8 +46,24 @@ void pki_x509super::delRefKey(pki_key *ref) privkey = NULL; } -void pki_x509super::autoIntName() +// Start class pki_x509name + +pki_x509name::pki_x509name(const QString name) + : pki_base(name) +{ +} + +void pki_x509name::autoIntName() { x509name subject = getSubject(); setIntName(subject.getMostPopular()); } + +QVariant pki_x509name::column_data(int id) +{ + if (id == HD_subject_name) + return QVariant(getSubject().oneLine(XN_FLAG_ONELINE)); + if (dbheader::isNid(id)) + return QVariant(getSubject().getEntryByNid(id)); + return pki_base::column_data(id); +} diff --git a/lib/pki_x509super.h b/lib/pki_x509super.h index 3b4bf29b..7013ab91 100644 --- a/lib/pki_x509super.h +++ b/lib/pki_x509super.h @@ -14,7 +14,19 @@ #include "x509name.h" #include "x509v3ext.h" -class pki_x509super : public pki_base +class pki_x509name : public pki_base +{ + public: + pki_x509name(const QString name = ""); + virtual x509name getSubject() const + { + return x509name(); + }; + void autoIntName(); + QVariant column_data(int id); +}; + +class pki_x509super : public pki_x509name { Q_OBJECT protected: @@ -30,7 +42,6 @@ class pki_x509super : public pki_base pki_key *getRefKey() const; void setRefKey(pki_key *ref); void delRefKey(pki_key *ref); - void autoIntName(); }; #endif diff --git a/ui/MainWindow.ui b/ui/MainWindow.ui index 8adb990b..2493b627 100644 --- a/ui/MainWindow.ui +++ b/ui/MainWindow.ui @@ -244,7 +244,7 @@ 8 - + @@ -555,11 +555,6 @@ QTreeView
widgets/XcaTreeView.h
- - CertTreeView - QTreeView -
widgets/XcaTreeView.h
-
diff --git a/widgets/CrlDetail.cpp b/widgets/CrlDetail.cpp index c30fca01..fc420a59 100644 --- a/widgets/CrlDetail.cpp +++ b/widgets/CrlDetail.cpp @@ -70,7 +70,7 @@ void CrlDetail::setCrl(pki_crl *crl) nUpdate->setText(crl->getNextUpdate().toPretty()); version->setText((++crl->getVersion()).toHex()); - issuer->setX509name(crl->getIssuerName()); + issuer->setX509name(crl->getSubject()); numc = crl->numRev(); for (i=0; i= 0x040200 + proxy = new XcaProxyModel(this); setSortingEnabled(true); proxy->setDynamicSortFilter(true); sortByColumn(0, Qt::AscendingOrder); -#else - header()->setClickable(true); - header()->setSortIndicatorShown(true); - sortByColumn(0); -#endif basemodel = NULL; } @@ -45,16 +40,39 @@ XcaTreeView::~XcaTreeView() void XcaTreeView::contextMenuEvent(QContextMenuEvent * e ) { - if (basemodel) - basemodel->showContextMenu(e, getIndex(indexAt(e->pos()))); + if (!basemodel) + return; + basemodel->showContextMenu(e, getIndex(indexAt(e->pos()))); +} + +void XcaTreeView::showHideSections() +{ + if (!basemodel) + return; + int i, max = basemodel->columnCount(QModelIndex()); + for (i=0; icolumnHidden(i)) + header()->hideSection(i); + else + header()->showSection(i); + } + columnsResize(); } void XcaTreeView::setModel(QAbstractItemModel *model) { basemodel = (db_base *)model; + if (basemodel) + connect(basemodel, SIGNAL(resetHeader()), + header(), SLOT(resetMoves())); proxy->setSourceModel(model); QTreeView::setModel(proxy); - columnsResize(); + showHideSections(); +} +void XcaTreeView::headerEvent(QContextMenuEvent *e, int col) +{ + basemodel->showHeaderMenu(e, col); + showHideSections(); } QModelIndex XcaTreeView::getIndex(const QModelIndex &index) @@ -83,21 +101,21 @@ void XcaTreeView::columnsResize() } } -CertTreeView::CertTreeView(QWidget *parent) - :XcaTreeView(parent) -{ - delete proxy; - proxy = new XcaProxyModel(this); -} - -XcaProxyModel::XcaProxyModel(QWidget *) +XcaProxyModel::XcaProxyModel(QWidget *parent) + :QSortFilterProxyModel(parent) { } bool XcaProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { - if (left.column() == 2 && right.column() == 2) { + db_base *db = (db_base *)sourceModel(); + if (!db) + return QSortFilterProxyModel::lessThan(left, right); + + if (db->isNumericCol(left.column()) && + db->isNumericCol(right.column())) + { int diff; QString l = sourceModel()->data(left).toString(); QString r = sourceModel()->data(right).toString(); @@ -111,3 +129,20 @@ bool XcaProxyModel::lessThan(const QModelIndex &left, } return QSortFilterProxyModel::lessThan(left, right); } + +void XcaHeaderView::contextMenuEvent(QContextMenuEvent * e) +{ + XcaTreeView *tv = (XcaTreeView *)parentWidget(); + if (tv) + tv->headerEvent(e, logicalIndexAt(e->pos())); +} + +void XcaHeaderView::resetMoves() +{ + for (int i=0; i #include #include +#include #include "lib/db_base.h" class db_base; + +class XcaHeaderView: public QHeaderView +{ + Q_OBJECT + public: + XcaHeaderView() + :QHeaderView(Qt::Horizontal) + { + setStretchLastSection(true); + setMovable(true); + } + void contextMenuEvent(QContextMenuEvent *e); + public slots: + void resetMoves(); +}; + class XcaTreeView: public QTreeView { Q_OBJECT @@ -23,19 +40,14 @@ class XcaTreeView: public QTreeView public: XcaTreeView(QWidget *parent = 0); ~XcaTreeView(); - void contextMenuEvent(QContextMenuEvent * e); + void contextMenuEvent(QContextMenuEvent *e); void setModel(QAbstractItemModel *model); QModelIndex getIndex(const QModelIndex &index); QModelIndex getProxyIndex(const QModelIndex &index); QModelIndexList getSelectedIndexes(); void columnsResize(); - -}; - -class CertTreeView: public XcaTreeView -{ - public: - CertTreeView(QWidget *parent = 0); + void headerEvent(QContextMenuEvent *e, int col); + void showHideSections(); }; class XcaProxyModel: public QSortFilterProxyModel @@ -46,5 +58,4 @@ class XcaProxyModel: public QSortFilterProxyModel bool lessThan(const QModelIndex &left, const QModelIndex &right) const; }; - #endif