Skip to content

Commit

Permalink
Close #287: template don't save/restore correctly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chris2511 committed Aug 31, 2024
1 parent a2ea166 commit 7f5bdb7
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 26 deletions.
4 changes: 2 additions & 2 deletions lib/pki_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
};
}
29 changes: 25 additions & 4 deletions lib/pki_temp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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) ....
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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);
}
3 changes: 2 additions & 1 deletion lib/pki_temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 *);
Expand Down
2 changes: 1 addition & 1 deletion ui/CertDetail.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion ui/CrlDetail.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion ui/ExportDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion ui/KeyDetail.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions widgets/CertDetail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions widgets/CrlDetail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions widgets/ExportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions widgets/KeyDetail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions widgets/XcaDetail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down

0 comments on commit 7f5bdb7

Please sign in to comment.