Close #287: template don't save/restore correctly

Use the probably modified internal name of the template
in the template-details dialog before import.

Therefore the name of the qlineedit of the internal name of
all other details dialogs changed from "descr" to "description"
to match the name in the NewX509 dialog and to be found
by the "XcaDetails" class.

When exporting the template data, add the internal name and the comment
to the exported data.
The XCA template data is defined by us and can be modified.
This change is backwards and upwards compatible:
  New versions of XCA can read an old Template export and vice-versa.
This commit is contained in:
Christian Hohnstaedt 2024-08-31 00:35:29 +02:00
parent a2ea166cac
commit 7f5bdb7dec
12 changed files with 48 additions and 26 deletions

View File

@ -100,7 +100,7 @@ new pki_export(32, revocation, "crl", "PEM", F_PEM, tr("PEM
new pki_export(33, revocation, "der", "DER", F_DER | F_SINGLE, tr("Binary DER format of the revocation list")),
new pki_export(34, revocation, "ics", tr("vCalendar"), F_CAL, tr("vCalendar reminder for the CRL expiry date")),
new pki_export(35, tmpl, "xca", "PEM", F_PEM | F_SINGLE, tr("XCA template in PEM-like format")),
new pki_export(36, tmpl, "pem", "PEM", F_PEM | F_MULTI, tr("All selected XCA templates in PEM-like format")),
new pki_export(35, tmpl, "xca", "PEM", F_PEM | F_SINGLE, tr("XCA template in PEM-like format. Templates include the internal name and comment")),
new pki_export(36, tmpl, "pem", "PEM", F_PEM | F_MULTI, tr("All selected XCA templates in PEM-like format. Templates include the internal name and comment")),
};
}

View File

@ -363,7 +363,7 @@ void pki_temp::old_fromData(const unsigned char *p, int size, int version)
}
}
QByteArray pki_temp::toData() const
QByteArray pki_temp::toData(bool for_export) const
{
QByteArray ba;
@ -373,6 +373,12 @@ QByteArray pki_temp::toData() const
buf.open(QIODevice::WriteOnly | QIODevice::Append);
QDataStream out(&buf);
out.setVersion(TEMPLATE_DS_VERSION);
if (for_export) {
out << QMap<QString, QString>{
{ "internal_name", getIntName() },
{ "internal_comment", getComment() }
};
}
out << settings;
buf.close();
return ba;
@ -394,6 +400,14 @@ void pki_temp::fromData(QByteArray &ba, int version)
if (settings.contains(key))
settings[translate[key]] = settings.take(key);
}
if (settings.contains("internal_name")) {
qDebug() << "Import internal_name" << settings["internal_name"];
setIntName(settings.take("internal_name"));
}
if (settings.contains("internal_comment")) {
qDebug() << "Import internal_comment" << settings["internal_comment"];
setComment(settings.take("internal_comment"));
}
buf.close();
(void)version;
//if (version < 11) ....
@ -414,7 +428,7 @@ QByteArray pki_temp::toExportData() const
QByteArray data, header;
BioByteArray b;
data = toData();
data = toData(true);
header = db::intToData(data.size());
header += db::intToData(TMPL_VERSION);
header += data;
@ -485,7 +499,7 @@ void pki_temp::fload(const QString &fname)
}
}
void pki_temp::fromPEM_BIO(BIO *bio, const QString &name)
void pki_temp::fromPEM_BIO(BIO *bio, const QString &)
{
QByteArray ba;
QString msg;
@ -502,7 +516,6 @@ void pki_temp::fromPEM_BIO(BIO *bio, const QString &name)
if (!strcmp(nm, PEM_STRING_XCA_TEMPLATE)) {
ba = QByteArray::fromRawData((char*)data, len);
fromExportData(ba);
setIntName(rmslashdot(name));
} else {
msg = tr("Not an XCA Template, but '%1'").arg(nm);
}
@ -529,3 +542,11 @@ QVariant pki_temp::getIcon(const dbheader *hd) const
return hd->id == HD_internal_name ?
QVariant(QPixmap(":templateIco")) : QVariant();
}
void pki_temp::autoIntName(const QString &file)
{
if (getIntName().isEmpty())
setIntName(rmslashdot(file));
if (getIntName().isEmpty())
pki_x509name::autoIntName(file);
}

View File

@ -70,7 +70,7 @@ class pki_temp: public pki_x509name
pre_defined = true;
}
QString comboText() const;
QByteArray toData() const;
QByteArray toData(bool for_export = false) const;
QString toB64Data()
{
return QString::fromLatin1(toData().toBase64());
@ -92,6 +92,7 @@ class pki_temp: public pki_x509name
QSqlError insertSqlData();
QSqlError deleteSqlData();
void restoreSql(const QSqlRecord &rec);
void autoIntName(const QString &file);
};
Q_DECLARE_METATYPE(pki_temp *);

View File

@ -108,7 +108,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="descr">
<widget class="QLineEdit" name="description">
<property name="toolTip">
<string>The internal name of the certificate in the database</string>
</property>

View File

@ -179,7 +179,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="descr">
<widget class="QLineEdit" name="description">
<property name="toolTip">
<string>The internal name of the CRL in the database</string>
</property>

View File

@ -77,7 +77,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="descr">
<widget class="QLineEdit" name="description">
<property name="toolTip">
<string>The internal name of the CRL in the database</string>
</property>

View File

@ -84,7 +84,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="descr">
<widget class="QLineEdit" name="description">
<property name="toolTip">
<string>The internal name of the key used by xca</string>
</property>

View File

@ -41,7 +41,7 @@ void CertDetail::on_showExt_clicked()
void CertDetail::setX509super(pki_x509super *x)
{
descr->setText(x->getIntName());
description->setText(x->getIntName());
thisSqlId = x->getSqlItemId();
connect_pki(x);
@ -262,7 +262,7 @@ void CertDetail::itemChanged(pki_base *pki)
if (pkiSqlId == issuerSqlId)
signature->setText(pki->getIntName());
if (pkiSqlId == thisSqlId)
descr->setText(pki->getIntName());
description->setText(pki->getIntName());
}
void CertDetail::showPubKey()

View File

@ -62,7 +62,7 @@ void CrlDetail::setCrl(pki_crl *crl)
connect(issuerIntName, SIGNAL(doubleClicked(QString)),
this, SLOT(showIssuer()));
descr->setText(crl->getIntName());
description->setText(crl->getIntName());
lUpdate->setText(crl->getLastUpdate().toPretty());
lUpdate->setToolTip(crl->getLastUpdate().toPrettyGMT());
nUpdate->setText(crl->getNextUpdate().toPretty());
@ -85,7 +85,7 @@ void CrlDetail::itemChanged(pki_base *pki)
if (pkiSqlId == issuerSqlId)
issuerIntName->setText(pki->getIntName());
if (pkiSqlId == crlSqlId)
descr->setText(pki->getIntName());
description->setText(pki->getIntName());
}
void CrlDetail::showIssuer()

View File

@ -32,11 +32,11 @@ ExportDialog::ExportDialog(QWidget *w, const QString &title,
if (indexes.size() == 1) {
pki_base *pki = db_base::fromIndex(indexes[0]);
if (pki) {
descr->setText(pki->getIntName());
description->setText(pki->getIntName());
fname = pki->getUnderlinedName();
}
}
descr->setReadOnly(true);
description->setReadOnly(true);
image->setPixmap(img);
label->setText(title);
mainwin->helpdlg->register_ctxhelp_button(this, help_ctx);

View File

@ -73,7 +73,7 @@ void KeyDetail::setupFingerprints(pki_key *key)
void KeyDetail::setKey(pki_key *key, bool import)
{
keySqlId = key->getSqlItemId();
descr->setText(key->getIntName());
description->setText(key->getIntName());
keyLength->setText(key->length());
if (import)
connect_pki(key);
@ -147,7 +147,7 @@ void KeyDetail::setKey(pki_key *key, bool import)
void KeyDetail::itemChanged(pki_base *pki)
{
if (pki->getSqlItemId() == keySqlId)
descr->setText(pki->getIntName());
description->setText(pki->getIntName());
}
void KeyDetail::showKey(QWidget *parent, pki_key *key, bool import)
@ -157,7 +157,7 @@ void KeyDetail::showKey(QWidget *parent, pki_key *key, bool import)
KeyDetail *dlg = new KeyDetail(parent);
bool ro = !key->getSqlItemId().isValid();
dlg->setKey(key, import);
dlg->descr->setReadOnly(ro);
dlg->description->setReadOnly(ro);
dlg->comment->setReadOnly(ro);
dlg->exec();

View File

@ -56,9 +56,9 @@ void XcaDetail::updateNameComment()
{
if (!pki)
return;
QLineEdit *descr = findChild<QLineEdit*>("descr");
if (descr)
pki->setIntName(descr->text());
QLineEdit *description = findChild<QLineEdit*>("description");
if (description)
pki->setIntName(description->text());
QTextEdit *comment = findChild<QTextEdit*>("comment");
if (comment)
pki->setComment(comment->toPlainText());
@ -79,9 +79,9 @@ void XcaDetail::import()
if (buttonBox && !pki && importbut) {
buttonBox->removeButton(importbut);
importbut = nullptr;
QLineEdit *descr = findChild<QLineEdit*>("descr");
if (descr)
descr->setReadOnly(true);
QLineEdit *description = findChild<QLineEdit*>("description");
if (description)
description->setReadOnly(true);
QTextEdit *comment = findChild<QTextEdit*>("comment");
if (comment)
comment->setReadOnly(true);