Allow editing of revocations

This commit is contained in:
Christian Hohnstaedt 2018-03-10 15:56:10 +01:00
parent 0ed9f6926c
commit d22cfb0b53
6 changed files with 102 additions and 27 deletions

View File

@ -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);
}

View File

@ -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<size(); i++) {
x509rev r = at(i);
foreach(x509rev r, *this) {
if (r.getCrlNo() == 0) {
int idx = oldList.indexOf(r);
if (idx != -1) {
x509rev old = oldList.takeAt(idx);
r.setCrlNo(old.getCrlNo());
qDebug() << "RECOVER OLD CRL NO" << r ;
}
}
r.executeQuery(q);
if (q.lastError().isValid())
return false;
}
merged = false;
TransCommit();
return true;

View File

@ -85,6 +85,10 @@ class x509rev
{
reason_idx = crlreasons().indexOf(reason);
}
void setCrlNo(int n)
{
crlNo = n;
}
a1int getSerial() const
{
return serial;

View File

@ -104,6 +104,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editRev">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@ -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; i<cols; i++)
certList->resizeColumnToContents(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());
}

View File

@ -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