diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp index eb6288f1..b8543d90 100644 --- a/lib/pki_x509.cpp +++ b/lib/pki_x509.cpp @@ -124,7 +124,10 @@ void pki_x509::restoreSql(QSqlRecord &rec) crlNumber.set(rec.value(VIEW_x509_auth_crlNo).toUInt()); crlExpire.fromPlain(rec.value(VIEW_x509_auth_crlExpire).toString()); caTemplateSqlId = rec.value(VIEW_x509_auth_template); - crlDays = rec.value(VIEW_x509_auth_crlDays).toInt(); + if (!rec.isNull(VIEW_x509_auth_crlDays)) + crlDays = rec.value(VIEW_x509_auth_crlDays).toInt(); + else + crlDays = 30; if (!rec.isNull(VIEW_x509_revocation)) revocation = x509rev(rec, VIEW_x509_revocation); } diff --git a/lib/x509rev.cpp b/lib/x509rev.cpp index 487e5f5d..1eabe1e1 100644 --- a/lib/x509rev.cpp +++ b/lib/x509rev.cpp @@ -147,6 +147,7 @@ void x509rev::set(const x509rev &x) date = x.date; ivalDate = x.ivalDate; reason_idx = x.reason_idx; + crlNo = x.crlNo; } bool x509rev::identical(const x509rev &x) const @@ -181,7 +182,8 @@ void x509rev::executeQuery(XSqlQuery &q) q.bindValue(1, serial.toHex()); q.bindValue(2, date.toPlain()); q.bindValue(3, ivalDate.toPlain()); - q.bindValue(4, crl_reasons[reason_idx].bitnum); + q.bindValue(4, crlNo ? QVariant(crlNo) : QVariant()); + q.bindValue(5, crl_reasons[reason_idx].bitnum); q.exec(); } @@ -260,6 +262,8 @@ bool x509revList::sqlUpdate(QVariant caId) if (!TransBegin()) return false; + x509revList oldList = fromSql(caId); + SQL_PREPARE(q, "DELETE FROM revocations WHERE caId=?"); q.bindValue(0, caId); q.exec(); @@ -267,15 +271,23 @@ bool x509revList::sqlUpdate(QVariant caId) return false; SQL_PREPARE(q, "INSERT INTO revocations " - "(caId, serial, date, invaldate, reasonBit) " - "VALUES (?,?,?,?,?)"); + "(caId, serial, date, invaldate, crlNo, reasonBit) " + "VALUES (?,?,?,?,?,?)"); q.bindValue(0, caId); - for (int i=0; i + + + + Edit + + + diff --git a/widgets/RevocationList.cpp b/widgets/RevocationList.cpp index 85b3cc9b..528a4901 100644 --- a/widgets/RevocationList.cpp +++ b/widgets/RevocationList.cpp @@ -35,29 +35,33 @@ class revListItem : public QTreeWidgetItem } }; +static void setup_revRevItem(QTreeWidgetItem *item, const x509rev &revit, + const pki_x509 *iss) +{ + pki_x509 *rev = iss ? iss->getBySerial(revit.getSerial()) : NULL; + if (rev != NULL) { + for (int i = 0; i < Cmax; i++) + item->setToolTip(i, rev->getIntName()); + } + item->setText(Cserial, revit.getSerial().toHex()); + item->setText(Cdate, revit.getDate().toSortable()); + item->setText(Creason, revit.getReason()); + + item->setTextAlignment(Cnumber, Qt::AlignRight); + item->setTextAlignment(Cserial, Qt::AlignRight); + + a1time a = revit.getInvalDate(); + if (!a.isUndefined()) + item->setText(CiDate, a.toSortable()); +} + static void addRevItem(QTreeWidget *certList, const x509rev &revit, int no, const pki_x509 *iss) { revListItem *current; - pki_x509 *rev; - a1time a; - rev = iss ? iss->getBySerial(revit.getSerial()) : NULL; current = new revListItem(certList); - if (rev != NULL) { - for (int i = 0; i < Cmax; i++) - current->setToolTip(i, rev->getIntName()); - } current->setText(Cnumber, QString("%1").arg(no)); - current->setText(Cserial, revit.getSerial().toHex()); - current->setText(Cdate, revit.getDate().toSortable()); - current->setText(Creason, revit.getReason()); - - current->setTextAlignment(Cnumber, Qt::AlignRight); - current->setTextAlignment(Cserial, Qt::AlignRight); - - a = revit.getInvalDate(); - if (!a.isUndefined()) - current->setText(CiDate, a.toSortable()); + setup_revRevItem(current, revit, iss); } void RevocationList::setupRevocationView(QTreeWidget *certList, @@ -85,6 +89,8 @@ void RevocationList::setupRevocationView(QTreeWidget *certList, for (i=0; iresizeColumnToContents(i); certList->setSortingEnabled(true); + certList->setSelectionBehavior(QAbstractItemView::SelectRows); + certList->setSelectionMode(QAbstractItemView::ExtendedSelection); } RevocationList::RevocationList(QWidget *w) : QDialog(w) @@ -97,6 +103,9 @@ RevocationList::RevocationList(QWidget *w) : QDialog(w) genCrl = buttonBox->addButton(tr("Generate CRL"), QDialogButtonBox::ActionRole); connect(genCrl, SIGNAL(clicked(void)), this, SLOT(gencrl(void))); + + connect(certList, SIGNAL(doubleClicked(const QModelIndex &)), + this, SLOT(on_editRev_clicked(const QModelIndex &))); } void RevocationList::gencrl(void) @@ -145,6 +154,36 @@ void RevocationList::on_delRev_clicked(void) revList.takeAt(idx); } +void RevocationList::on_editRev_clicked() +{ + QTreeWidgetItem *current = certList->currentItem(); + x509rev rev; + int idx; + a1int a1_serial; + + if (!current) + return; + + a1_serial.setHex(current->text(Cserial)); + rev.setSerial(a1_serial); + idx = revList.indexOf(rev); + if (idx == -1) + return; + + rev = revList[idx]; + + Revocation *revoke = new Revocation(this, QModelIndexList()); + revoke->setRevocation(rev); + if (revoke->exec()) { + a1time a1 = rev.getDate(); + rev = revoke->getRevocation(); + rev.setDate(a1); + revList[idx] = rev; + setup_revRevItem(current, rev, issuer); + } + delete revoke; +} + Revocation::Revocation(QWidget *w, QModelIndexList indexes) : QDialog(w) { setupUi(this); @@ -181,12 +220,20 @@ Revocation::Revocation(QWidget *w, QModelIndexList indexes) : QDialog(w) x509rev Revocation::getRevocation() { x509rev r; - a1int i; - i.setHex(serial->text()); - r.setSerial(i); - r.setDate(a1time::now()); + r.setSerial(a1int().setHex(serial->text())); r.setInvalDate(invalid->getDate()); + r.setDate(a1time()); + r.setCrlNo(0); r.setReason(reason->currentText()); return r; } + +void Revocation::setRevocation(x509rev r) +{ + a1int i; + + serial->setText(r.getSerial().toHex()); + invalid->setDate(r.getInvalDate()); + reason->setCurrentText(r.getReason()); +} diff --git a/widgets/RevocationList.h b/widgets/RevocationList.h index ff517872..8b5dee9a 100644 --- a/widgets/RevocationList.h +++ b/widgets/RevocationList.h @@ -32,6 +32,7 @@ class RevocationList: public QDialog, public Ui::RevocationList public slots: void on_addRev_clicked(void); void on_delRev_clicked(void); + void on_editRev_clicked(void); void gencrl(void); signals: @@ -45,5 +46,6 @@ class Revocation: public QDialog, public Ui::Revoke public: Revocation(QWidget *w, QModelIndexList indexes); x509rev getRevocation(); + void setRevocation(x509rev r); }; #endif