mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Better support multiple selections - Export all selected items into one PEM file - Batch Revoke/unrevoke/renew of many selected certificates of the same issuer - allow exporting templates as PEM Add Feat. Reg. #83 Option to revoke old certificate when renewing Always put all signed certificate to the newest CA. If a CA certificate is renewed, all certificates issued by the old CA are now shown as signed by the new one.
190 lines
3.7 KiB
C++
190 lines
3.7 KiB
C++
/* vi: set sw=4 ts=4:
|
|
*
|
|
* Copyright (C) 2001 - 2014 Christian Hohnstaedt.
|
|
*
|
|
* All rights reserved.
|
|
*/
|
|
|
|
|
|
#include "db_temp.h"
|
|
#include "func.h"
|
|
#include <widgets/NewX509.h>
|
|
#include <widgets/MainWindow.h>
|
|
#include <QtGui/QFileDialog>
|
|
#include <QtCore/QDir>
|
|
#include <QtGui/QContextMenuEvent>
|
|
#include <QtGui/QAction>
|
|
#include <QtGui/QInputDialog>
|
|
#include <QtGui/QMessageBox>
|
|
|
|
db_temp::db_temp(QString DBfile, MainWindow *mw)
|
|
:db_x509name(DBfile, mw)
|
|
{
|
|
class_name = "templates";
|
|
pkitype << tmpl;
|
|
|
|
updateHeaders();
|
|
loadContainer();
|
|
|
|
predefs = newPKI();
|
|
QDir dir;
|
|
if (!dir.cd(getPrefix()))
|
|
return;
|
|
dir.setFilter(QDir::Files | QDir::NoSymLinks);
|
|
QFileInfoList list = dir.entryInfoList();
|
|
load_temp l;
|
|
pki_base *tmpl;
|
|
for (int i = 0; i < list.size(); ++i) {
|
|
QFileInfo fileInfo = list.at(i);
|
|
QString name = getPrefix() + QDir::separator() +
|
|
fileInfo.fileName();
|
|
if (!name.endsWith(".xca", Qt::CaseInsensitive))
|
|
continue;
|
|
try {
|
|
tmpl = l.loadItem(name);
|
|
if (tmpl)
|
|
predefs->append(tmpl);
|
|
} catch(errorEx &err) {
|
|
XCA_WARN(tr("Bad template: %1").arg(name));
|
|
}
|
|
}
|
|
}
|
|
|
|
dbheaderList db_temp::getHeaders()
|
|
{
|
|
dbheaderList h = db_x509name::getHeaders();
|
|
h << new dbheader(HD_temp_type, true, tr("Type"));
|
|
return h;
|
|
}
|
|
|
|
db_temp::~db_temp()
|
|
{
|
|
delete predefs;
|
|
}
|
|
|
|
pki_base *db_temp::newPKI(db_header_t *)
|
|
{
|
|
return new pki_temp("");
|
|
}
|
|
|
|
QStringList db_temp::getDescPredefs()
|
|
{
|
|
QStringList x;
|
|
x.clear();
|
|
for(pki_temp *pki=(pki_temp*)predefs->iterate(); pki;
|
|
pki=(pki_temp*)pki->iterate()) {
|
|
x.append(QString("[default] ") + pki->getIntName());
|
|
}
|
|
x += getDesc();
|
|
return x;
|
|
}
|
|
|
|
pki_base *db_temp::getByName(QString desc)
|
|
{
|
|
if (!desc.startsWith("[default] "))
|
|
return db_base::getByName(desc);
|
|
desc.remove(0, 10); // "[default] "
|
|
for(pki_temp *pki=(pki_temp*)predefs->iterate(); pki;
|
|
pki=(pki_temp*)pki->iterate()) {
|
|
if (pki->getIntName() == desc)
|
|
return pki;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
bool db_temp::runTempDlg(pki_temp *temp)
|
|
{
|
|
NewX509 *dlg = new NewX509(mainwin);
|
|
emit connNewX509(dlg);
|
|
|
|
dlg->setTemp(temp);
|
|
dlg->fromTemplate(temp);
|
|
if (!dlg->exec()) {
|
|
delete dlg;
|
|
return false;
|
|
}
|
|
dlg->toTemplate(temp);
|
|
delete dlg;
|
|
return true;
|
|
}
|
|
|
|
void db_temp::newItem()
|
|
{
|
|
pki_temp *temp = NULL;
|
|
QStringList sl;
|
|
QString type;
|
|
bool ok;
|
|
int i, len;
|
|
len = predefs->childCount();
|
|
sl << tr("Nothing");
|
|
for (i=0; i<len; i++) {
|
|
sl << predefs->child(i)->getIntName();
|
|
}
|
|
type = QInputDialog::getItem(mainwin, tr(XCA_TITLE),
|
|
tr("Preset Template values"), sl, 0, false, &ok, 0 );
|
|
if (ok) {
|
|
if (type == sl[0]) {
|
|
temp = new pki_temp("");
|
|
} else {
|
|
for (i=0; i<len; i++) {
|
|
pki_temp *t = (pki_temp *)predefs->child(i);
|
|
if (type == t->getIntName()) {
|
|
temp = new pki_temp(t);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!temp)
|
|
return;
|
|
temp->setIntName("--");
|
|
if (runTempDlg(temp)) {
|
|
insertPKI(temp);
|
|
createSuccess(temp);
|
|
return;
|
|
}
|
|
}
|
|
delete temp;
|
|
}
|
|
void db_temp::showPki(pki_base *pki)
|
|
{
|
|
alterTemp(static_cast<pki_temp *>(pki));
|
|
}
|
|
|
|
void db_temp::load()
|
|
{
|
|
load_temp l;
|
|
load_default(l);
|
|
}
|
|
|
|
void db_temp::store(QModelIndex index)
|
|
{
|
|
if (!index.isValid())
|
|
return;
|
|
|
|
pki_temp *temp = static_cast<pki_temp*>(index.internalPointer());
|
|
|
|
QString fn = mainwin->getPath() + QDir::separator() +
|
|
temp->getUnderlinedName() + ".xca";
|
|
QString s = QFileDialog::getSaveFileName(mainwin,
|
|
tr("Save template as"), fn,
|
|
tr("XCA templates ( *.xca);; All files ( * )"));
|
|
if (s.isEmpty())
|
|
return;
|
|
s = QDir::convertSeparators(s);
|
|
mainwin->setPath(s.mid(0, s.lastIndexOf(QRegExp("[/\\\\]")) ));
|
|
try {
|
|
temp->writeTemp(s);
|
|
}
|
|
catch (errorEx &err) {
|
|
MainWindow::Error(err);
|
|
}
|
|
}
|
|
|
|
bool db_temp::alterTemp(pki_temp *temp)
|
|
{
|
|
if (!runTempDlg(temp))
|
|
return false;
|
|
updatePKI(temp);
|
|
return true;
|
|
}
|