Create CRL by providing a crljob, describing the parameters

The GUI will prepare such a job and the cmdline can do so, too.
This commit is contained in:
Christian Hohnstaedt 2020-02-22 07:31:54 +01:00
parent 089c7d39ef
commit 9da73073c8
8 changed files with 96 additions and 36 deletions

View File

@ -220,17 +220,20 @@ void db_crl::newItem()
void db_crl::newItem(pki_x509 *cert)
{
if (!cert)
return;
pki_crl *crl = NULL;
NewCrl *widget = new NewCrl(NULL, cert);
crljob task(cert);
NewCrl *widget = new NewCrl(NULL, task);
XcaDialog *dlg = new XcaDialog(mainwin, revocation, widget,
tr("Create CRL"), QString());
if (!dlg->exec()) {
delete dlg;
return;
if (dlg->exec()) {
newItem(widget->getCrlJob());
}
delete dlg;
}
void db_crl::newItem(const crljob &task)
{
pki_crl *crl = NULL;
pki_x509 *cert = task.issuer;
QSqlDatabase db = QSqlDatabase::database();
try {
x509v3ext e;
@ -243,38 +246,35 @@ void db_crl::newItem(pki_x509 *cert)
crl->createCrl(cert->getIntName(), cert);
crl->pkiSource = generated;
bool withReason = widget->revocationReasons->isChecked();
foreach(x509rev rev, cert->getRevList())
crl->addRev(rev, withReason);
crl->addRev(rev, task.withReason);
if (widget->authKeyId->isChecked()) {
if (task.authKeyId) {
crl->addV3ext(e.create(NID_authority_key_identifier,
"keyid,issuer", &ext_ctx));
}
if (widget->subAltName->isChecked()) {
if (task.subAltName) {
if (cert->hasExtension(NID_subject_alt_name)) {
crl->addV3ext(e.create(NID_issuer_alt_name,
"issuer:copy", &ext_ctx));
}
}
if (widget->setCrlNumber->isChecked()) {
a1int num;
num.setDec(widget->crlNumber->text());
crl->setCrlNumber(num);
cert->setCrlNumber(num);
if (task.setCrlNumber) {
crl->setCrlNumber(task.crlNumber);
cert->setCrlNumber(task.crlNumber);
}
crl->setIssuer(cert);
crl->setLastUpdate(widget->lastUpdate->getDate());
crl->setNextUpdate(widget->nextUpdate->getDate());
crl->sign(cert->getRefKey(), widget->hashAlgo->currentHash());
crl->setLastUpdate(task.lastUpdate);
crl->setNextUpdate(task.nextUpdate);
crl->sign(cert->getRefKey(), task.hashAlgo);
Transaction;
if (!TransBegin())
throw errorEx(tr("Failed to initiate DB transaction"));
cert->setCrlExpire(widget->nextUpdate->getDate());
cert->setCrlExpire(task.nextUpdate);
SQL_PREPARE(q, "UPDATE authority set crlNo=?, crlExpire=? WHERE item=?");
q.bindValue(0, (uint)cert->getCrlNumber().getLong());
q.bindValue(1, widget->nextUpdate->getDate().toPlain());
q.bindValue(1, task.nextUpdate.toPlain());
q.bindValue(2, cert->getSqlItemId());
AffectedItems(cert->getSqlItemId());
q.exec();
@ -302,6 +302,5 @@ void db_crl::newItem(pki_x509 *cert)
delete crl;
crl = NULL;
}
delete dlg;
return;
}

View File

@ -30,6 +30,7 @@ class db_crl: public db_x509name
void load();
void showPki(pki_base *pki);
void updateCertView();
void newItem(const crljob &crljob);
public slots:
void newItem();

View File

@ -386,7 +386,8 @@ void pki_base::selfComment(QString msg)
void pki_base::print(FILE *fp) const
{
fprintf(fp, "File: %s\n", CCHAR(getFilename()));
fprintf(fp, "File: %s [%s]\n", CCHAR(getFilename()),
CCHAR(getIntName()));
}
static QString icsValue(QString s)

View File

@ -20,6 +20,35 @@
#define VIEW_crls_issuer 7
#define VIEW_crls_crl 8
#include "widgets/hashBox.h"
class crljob
{
public:
pki_x509 *issuer;
bool withReason;
bool authKeyId;
bool subAltName;
bool setCrlNumber;
a1int crlNumber;
int crlDays;
const EVP_MD *hashAlgo;
a1time lastUpdate;
a1time nextUpdate;
crljob(pki_x509 *x) : issuer(x)
{
withReason = true;
authKeyId = true;
subAltName = true;
setCrlNumber = issuer->getCrlNumber().getLong() > 0;
crlNumber = issuer->getCrlNumber();
crlNumber++;
crlDays = issuer->getCrlDays();
hashAlgo = hashBox::getDefaultMD();
nextUpdate = lastUpdate.addDays(crlDays);
}
};
class pki_crl: public pki_x509name
{
Q_OBJECT

View File

@ -17,27 +17,44 @@
#include <QCheckBox>
#include <QMessageBox>
NewCrl::NewCrl(QWidget *parent, pki_x509 *signer)
:QWidget(parent)
NewCrl::NewCrl(QWidget *parent, const crljob &j)
:QWidget(parent), task(j)
{
pki_x509 *issuer = task.issuer;
pki_key *key = issuer->getRefKey();
setupUi(this);
dateBox->setTitle(signer->getIntName());
validNumber->setText(QString::number(signer->getCrlDays()));
dateBox->setTitle(issuer->getIntName());
validNumber->setText(QString::number(task.crlDays));
validRange->setCurrentIndex(0);
on_applyTime_clicked();
nextUpdate->setEndDate(true);
pki_key *key = signer->getRefKey();
hashAlgo->setKeyType(key->getKeyType());
hashAlgo->setupHashes(key->possibleHashNids());
hashAlgo->setCurrentMD(task.hashAlgo);
a1int num = signer->getCrlNumber();
num++;
crlNumber->setText(num.toDec());
if (signer->hasExtension(NID_subject_alt_name))
crlNumber->setText(task.crlNumber.toDec());
if (issuer->hasExtension(NID_subject_alt_name)) {
subAltName->setEnabled(true);
else
subAltName->setChecked(task.subAltName);
} else {
subAltName->setEnabled(false);
}
revocationReasons->setChecked(task.withReason);
authKeyId->setChecked(task.authKeyId);
}
crljob NewCrl::getCrlJob() const
{
crljob t = task;
t.withReason = revocationReasons->isChecked();
t.authKeyId = authKeyId->isChecked();
t.subAltName = subAltName->isChecked();
t.setCrlNumber = setCrlNumber->isChecked();
t.lastUpdate = lastUpdate->getDate();
t.nextUpdate = nextUpdate->getDate();
return t;
}
void NewCrl::on_applyTime_clicked()
@ -46,3 +63,7 @@ void NewCrl::on_applyTime_clicked()
validRange->currentIndex());
}
NewCrl::~NewCrl()
{
qDebug() << "NewCrl::~NewCrl() -- DELETED";
}

View File

@ -9,7 +9,7 @@
#define __NEWCRL_H
#include "ui_NewCrl.h"
#include "lib/pki_x509.h"
#include "lib/pki_crl.h"
class pki_key;
@ -17,8 +17,11 @@ class NewCrl: public QWidget, public Ui::NewCrl
{
Q_OBJECT
crljob task;
public:
NewCrl(QWidget *parent, pki_x509 *signer);
NewCrl(QWidget *parent, const crljob &task);
~NewCrl();
crljob getCrlJob() const;
public slots:
void on_applyTime_clicked();

View File

@ -214,3 +214,8 @@ QString hashBox::getDefault()
{
return QString(hashalgos[default_md].name);
}
const EVP_MD *hashBox::getDefaultMD()
{
return EVP_get_digestbynid(hashalgos[default_md].nid);
}

View File

@ -33,6 +33,7 @@ class hashBox: public QComboBox
void setCurrentString(QString md);
static void setDefault(QString def);
static QString getDefault();
static const EVP_MD *getDefaultMD();
};
#endif