mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Refactor item export: separate GUI and database
Collect all export formats in pki_export. Each export format has assigned acouple of flags, indicating, whether they are text, concatenateable, encrypted, usable for multiple selections or only for a single item.
This commit is contained in:
parent
48bed71f79
commit
6ea01e80f6
@ -10,13 +10,9 @@
|
||||
#include "exception.h"
|
||||
#include "XcaWarningCore.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QListView>
|
||||
#include <QClipboard>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QMimeData>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
|
||||
void db_base::restart_timer()
|
||||
@ -658,3 +654,22 @@ void db_base::writeVcalendar(XFile &file, QStringList vcal) const
|
||||
"END:VCALENDAR";
|
||||
file.write(ics.join("\r\n").toUtf8());
|
||||
}
|
||||
|
||||
void db_base::exportItems(const QModelIndexList &indexes,
|
||||
const pki_export *xport, XFile &file) const
|
||||
{
|
||||
foreach(QModelIndex idx, indexes)
|
||||
exportItem(idx, xport, file);
|
||||
}
|
||||
|
||||
int db_base::exportFlags(const QModelIndexList &indexes) const
|
||||
{
|
||||
int disabled_flags = 0;
|
||||
foreach(const QModelIndex &idx, indexes)
|
||||
disabled_flags |= exportFlags(idx);
|
||||
if (indexes.size() > 1)
|
||||
disabled_flags |= F_SINGLE;
|
||||
else
|
||||
disabled_flags |= F_MULTI;
|
||||
return disabled_flags;
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
|
||||
#include <typeinfo>
|
||||
#include "base.h"
|
||||
#include "load_obj.h"
|
||||
#include "pki_base.h"
|
||||
#include "headerlist.h"
|
||||
|
||||
@ -64,10 +63,20 @@ class db_base: public QAbstractItemModel
|
||||
virtual void inToCont(pki_base *pki);
|
||||
virtual void remFromCont(const QModelIndex &idx);
|
||||
void changeView();
|
||||
int exportFlags(const QModelIndexList &indexes) const;
|
||||
virtual int exportFlags(const QModelIndex &index) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual void exportItem(const QModelIndex &index,
|
||||
const pki_export *xport, XFile &file) const { };
|
||||
virtual void exportItems(const QModelIndexList &indexes,
|
||||
const pki_export *xport, XFile &file) const;
|
||||
|
||||
void dump(const QString &dirname) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent)const;
|
||||
QModelIndex index(pki_base *pki)const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent) const;
|
||||
QModelIndex index(pki_base *pki) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int allItemsCount() const
|
||||
@ -112,7 +121,6 @@ class db_base: public QAbstractItemModel
|
||||
{
|
||||
colResizing--;
|
||||
}
|
||||
virtual void store(QModelIndex index) { (void)index; };
|
||||
dbheaderList getAllHeaders() {
|
||||
return allHeaders;
|
||||
}
|
||||
|
||||
@ -12,10 +12,6 @@
|
||||
#include "exception.h"
|
||||
#include "database_model.h"
|
||||
|
||||
#warning drop UI dependencies
|
||||
#include "widgets/ExportDialog.h"
|
||||
#include "ui_ExportDialog.h"
|
||||
|
||||
db_crl::db_crl() : db_x509name("crls")
|
||||
{
|
||||
sqlHashTable = "crls";
|
||||
@ -112,37 +108,21 @@ pki_base *db_crl::insert(pki_base *item)
|
||||
return crl;
|
||||
}
|
||||
|
||||
void db_crl::store(QModelIndex index)
|
||||
void db_crl::exportItems(const QModelIndexList &indexes,
|
||||
const pki_export *xport, XFile &file) const
|
||||
{
|
||||
pki_crl *crl = fromIndex<pki_crl>(index);
|
||||
|
||||
if (!index.isValid() || !crl)
|
||||
return;
|
||||
|
||||
ExportDialog *dlg = new ExportDialog(NULL,
|
||||
tr("Revocation list export"),
|
||||
tr("CRL ( *.pem *.der *.crl )"), crl, QPixmap(":revImg"),
|
||||
pki_export::select(revocation, 0));
|
||||
if (!dlg->exec()) {
|
||||
delete dlg;
|
||||
return;
|
||||
QStringList vcal;
|
||||
foreach(QModelIndex idx, indexes) {
|
||||
pki_crl *crl = fromIndex<pki_crl>(idx);
|
||||
if (!crl)
|
||||
continue;
|
||||
if (xport->match_all(F_CAL))
|
||||
vcal << crl->icsVEVENT();
|
||||
else
|
||||
crl->writeCrl(file, xport->match_all(F_PEM));
|
||||
}
|
||||
try {
|
||||
const pki_export *xtype = dlg->export_type();
|
||||
XFile file(dlg->filename->text());
|
||||
pki_base::pem_comment = dlg->pemComment->isChecked();
|
||||
file.open_key();
|
||||
if (xtype->match_all(F_CAL)) {
|
||||
writeVcalendar(file, crl->icsVEVENT());
|
||||
} else {
|
||||
crl->writeCrl(file, xtype->match_all(F_PEM));
|
||||
}
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
XCA_ERROR(err);
|
||||
}
|
||||
pki_base::pem_comment = false;
|
||||
delete dlg;
|
||||
if (vcal.size() > 0)
|
||||
writeVcalendar(file, vcal);
|
||||
}
|
||||
|
||||
pki_crl *db_crl::newCrl(const crljob &task)
|
||||
|
||||
@ -23,8 +23,9 @@ class db_crl: public db_x509name
|
||||
void inToCont(pki_base *pki);
|
||||
pki_base *insert(pki_base *item);
|
||||
void removeSigner(pki_base *signer);
|
||||
void store(QModelIndex index);
|
||||
void updateCertView();
|
||||
pki_crl *newCrl(const crljob &crljob);
|
||||
void exportItems(const QModelIndexList &indexes,
|
||||
const pki_export *xport, XFile &file) const;
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -19,10 +19,6 @@
|
||||
#include "XcaWarningCore.h"
|
||||
#include "PwDialogCore.h"
|
||||
|
||||
#warning drop UI dependencies
|
||||
#include "widgets/ExportDialog.h"
|
||||
#include "ui_ExportDialog.h"
|
||||
|
||||
db_key::db_key() : db_base("keys")
|
||||
{
|
||||
sqlHashTable = "public_keys";
|
||||
@ -188,16 +184,14 @@ pki_key *db_key::newKey(const keyjob &task, const QString &name)
|
||||
return key;
|
||||
}
|
||||
|
||||
void db_key::store(QModelIndex index)
|
||||
int db_key::exportFlags(const QModelIndex &index) const
|
||||
{
|
||||
QString title = tr("Export public key [%1]");
|
||||
int disable_flags = 0;
|
||||
|
||||
pki_key *key = fromIndex<pki_key>(index);
|
||||
pki_evp *privkey = dynamic_cast<pki_evp *>(key);
|
||||
|
||||
if (!index.isValid() || !key)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
int keytype = key->getKeyType();
|
||||
if (keytype != EVP_PKEY_RSA && keytype != EVP_PKEY_DSA)
|
||||
@ -212,57 +206,41 @@ void db_key::store(QModelIndex index)
|
||||
if (key->isPubKey() || key->isToken())
|
||||
disable_flags |= F_PRIVATE;
|
||||
|
||||
ExportDialog *dlg = new ExportDialog(NULL,
|
||||
title.arg(key->getTypeString()),
|
||||
tr("Private Keys ( *.pem *.der *.pk8 );; "
|
||||
"SSH Public Keys ( *.pub )"), key,
|
||||
QPixmap(key->isToken() ? ":scardImg" : ":keyImg"),
|
||||
pki_export::select(asym_key, disable_flags), "keyexport");
|
||||
return disable_flags;
|
||||
}
|
||||
|
||||
if (!dlg->exec()) {
|
||||
delete dlg;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const pki_export *xport = dlg->export_type();
|
||||
pki_base::pem_comment = dlg->pemComment->isChecked();
|
||||
XFile file(dlg->filename->text());
|
||||
const EVP_CIPHER *algo = NULL;
|
||||
int(*pwCallback)(char *, int, int, void *) = NULL;
|
||||
void db_key::exportItem(const QModelIndex &index, const pki_export *xport,
|
||||
XFile &file) const
|
||||
{
|
||||
const EVP_CIPHER *algo = NULL;
|
||||
pki_key *key = fromIndex<pki_key>(index);
|
||||
pki_evp *privkey = dynamic_cast<pki_evp *>(key);
|
||||
|
||||
if (xport->match_all(F_CRYPT)) {
|
||||
algo = EVP_aes_256_cbc();
|
||||
pwCallback = PwDialogCore::pwCallback;
|
||||
}
|
||||
if (xport->match_all(F_PRIVATE))
|
||||
file.open_write();
|
||||
else
|
||||
file.open_key();
|
||||
int(*pwCallback)(char *, int, int, void *) = NULL;
|
||||
|
||||
if (xport->match_all(F_DER | F_PRIVATE))
|
||||
privkey->writeKey(file, NULL, NULL, false);
|
||||
else if (xport->match_all(F_PEM | F_PRIVATE))
|
||||
privkey->writeKey(file, algo, pwCallback, true);
|
||||
else if (xport->match_all(F_DER))
|
||||
key->writePublic(file, false);
|
||||
else if (xport->match_all(F_PEM))
|
||||
key->writePublic(file, true);
|
||||
else if (xport->match_all(F_PKCS8))
|
||||
privkey->writePKCS8(file, algo, pwCallback, true);
|
||||
else if (xport->match_all(F_SSH2 | F_PRIVATE))
|
||||
key->writeSSH2private(file, pwCallback);
|
||||
else if (xport->match_all(F_SSH2))
|
||||
key->writeSSH2public(file);
|
||||
else if (xport->match_all(F_PVK))
|
||||
privkey->writePVKprivate(file, pwCallback);
|
||||
else
|
||||
throw errorEx(tr("Internal error"));
|
||||
if (xport->match_all(F_CRYPT)) {
|
||||
algo = EVP_aes_256_cbc();
|
||||
pwCallback = PwDialogCore::pwCallback;
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
XCA_ERROR(err);
|
||||
}
|
||||
pki_base::pem_comment = false;
|
||||
delete dlg;
|
||||
|
||||
if (privkey && xport->match_all(F_DER | F_PRIVATE))
|
||||
privkey->writeKey(file, NULL, NULL, false);
|
||||
else if (privkey && xport->match_all(F_PEM | F_PRIVATE))
|
||||
privkey->writeKey(file, algo, pwCallback, true);
|
||||
else if (xport->match_all(F_DER))
|
||||
key->writePublic(file, false);
|
||||
else if (xport->match_all(F_PEM))
|
||||
key->writePublic(file, true);
|
||||
else if (privkey && xport->match_all(F_PKCS8))
|
||||
privkey->writePKCS8(file, algo, pwCallback, true);
|
||||
else if (xport->match_all(F_SSH2 | F_PRIVATE))
|
||||
key->writeSSH2private(file, pwCallback);
|
||||
else if (xport->match_all(F_SSH2))
|
||||
key->writeSSH2public(file);
|
||||
else if (privkey && xport->match_all(F_PVK))
|
||||
privkey->writePVKprivate(file, pwCallback);
|
||||
else
|
||||
throw errorEx(tr("Internal error"));
|
||||
}
|
||||
|
||||
void db_key::setOwnPass(QModelIndex idx, enum pki_key::passType x)
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "pki_export.h"
|
||||
#include "db_base.h"
|
||||
#include "pki_key.h"
|
||||
#include "xfile.h"
|
||||
|
||||
class QModelIndex;
|
||||
class QContextMenuEvent;
|
||||
@ -32,9 +33,9 @@ class db_key: public db_base
|
||||
void setOwnPass(QModelIndex idx, enum pki_key::passType);
|
||||
void loadContainer();
|
||||
pki_key *newKey(const keyjob &task, const QString &name);
|
||||
|
||||
public slots:
|
||||
void store(QModelIndex index);
|
||||
int exportFlags(const QModelIndex &index) const;
|
||||
void exportItem(const QModelIndex &index,
|
||||
const pki_export *xport, XFile &file) const;
|
||||
|
||||
signals:
|
||||
void delKey(pki_key *delkey);
|
||||
|
||||
@ -7,16 +7,13 @@
|
||||
|
||||
|
||||
#include "db_temp.h"
|
||||
#include "pki_temp.h"
|
||||
#include "load_obj.h"
|
||||
#include "func.h"
|
||||
#include "XcaWarningCore.h"
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
#warning drop UI dependencies
|
||||
#include "widgets/NewX509.h"
|
||||
#include "ui_NewX509.h"
|
||||
#include <QFileDialog>
|
||||
|
||||
db_temp::db_temp() : db_x509name("templates")
|
||||
{
|
||||
/* XCA loads templates from private space ($HOME/.local/)
|
||||
@ -107,28 +104,10 @@ bool db_temp::alterTemp(pki_temp *temp)
|
||||
return true;
|
||||
}
|
||||
|
||||
void db_temp::store(QModelIndex index)
|
||||
void db_temp::exportItem(const QModelIndex &index,
|
||||
const pki_export *, XFile &file) const
|
||||
{
|
||||
pki_temp *temp = fromIndex<pki_temp>(index);
|
||||
|
||||
if (!index.isValid() || !temp)
|
||||
return;
|
||||
|
||||
QString fn = Settings["workingdir"] +
|
||||
temp->getUnderlinedName() + ".xca";
|
||||
QString s = QFileDialog::getSaveFileName(NULL,
|
||||
tr("Save template as"), fn,
|
||||
tr("XCA templates ( *.xca );; All files ( * )"));
|
||||
if (s.isEmpty())
|
||||
return;
|
||||
|
||||
update_workingdir(s);
|
||||
try {
|
||||
XFile file(s);
|
||||
file.open_key();
|
||||
if (temp)
|
||||
temp->writeTemp(file);
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
XCA_ERROR(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,8 @@ class db_temp: public db_x509name
|
||||
pki_base *newPKI(enum pki_type type = none);
|
||||
void fillContextMenu(QMenu *menu, const QModelIndex &index);
|
||||
QList<pki_temp*> getPredefs() const;
|
||||
void store(QModelIndex index);
|
||||
bool alterTemp(pki_temp *temp);
|
||||
void exportItem(const QModelIndex &index,
|
||||
const pki_export *, XFile &file) const;
|
||||
};
|
||||
#endif
|
||||
|
||||
184
lib/db_x509.cpp
184
lib/db_x509.cpp
@ -24,7 +24,6 @@
|
||||
|
||||
#warning drop UI dependencies
|
||||
#include "widgets/CertExtend.h"
|
||||
#include "widgets/ExportDialog.h"
|
||||
#include "widgets/RevocationList.h"
|
||||
#include "widgets/NewX509.h"
|
||||
#include "widgets/MainWindow.h"
|
||||
@ -542,122 +541,93 @@ pki_x509 *db_x509::newCert(NewX509 *dlg)
|
||||
return cert;
|
||||
}
|
||||
|
||||
void db_x509::store(QModelIndex idx)
|
||||
{
|
||||
QModelIndexList l;
|
||||
l << idx;
|
||||
store(l);
|
||||
}
|
||||
|
||||
void db_x509::store(QModelIndexList list)
|
||||
int db_x509::exportFlags(const QModelIndex &idx) const
|
||||
{
|
||||
QStringList filt;
|
||||
bool single = list.size() == 1;;
|
||||
int disable_flags = 0;
|
||||
|
||||
if (list.size() == 0)
|
||||
return;
|
||||
|
||||
pki_x509 *oldcrt = nullptr, *crt = fromIndex<pki_x509>(list[0]);
|
||||
pki_x509 *crt = fromIndex<pki_x509>(idx);
|
||||
if (!crt)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
pki_key *privkey = crt->getRefKey();
|
||||
pki_evp *pkey;
|
||||
|
||||
if (!single || !crt->getSigner() || crt->getSigner() == crt)
|
||||
if (!crt->getSigner() || crt->getSigner() == crt)
|
||||
disable_flags |= F_CHAIN;
|
||||
|
||||
if (!privkey || !privkey->isPrivKey() || privkey->isToken())
|
||||
disable_flags |= F_PRIVATE;
|
||||
|
||||
if (single)
|
||||
disable_flags |= F_SELECT;
|
||||
|
||||
if (!single || !crt->isCA())
|
||||
if (!crt->isCA())
|
||||
disable_flags |= F_CA;
|
||||
|
||||
ExportDialog *dlg = new ExportDialog(NULL, tr("Certificate export"),
|
||||
tr("X509 Certificates ( *.pem *.cer *.crt *.p12 *.pfx *.p7b )"), crt,
|
||||
QPixmap(":certImg"), pki_export::select(x509, disable_flags),
|
||||
"certexport");
|
||||
if (!dlg->exec()) {
|
||||
delete dlg;
|
||||
return;
|
||||
}
|
||||
QStringList vcal;
|
||||
QList<pki_x509*> certs;
|
||||
QList<pki_base*> items;
|
||||
try {
|
||||
const pki_export *xport = dlg->export_type();
|
||||
XFile file(dlg->filename->text());
|
||||
file.open_write();
|
||||
pki_base::pem_comment = dlg->pemComment->isChecked();
|
||||
return disable_flags;
|
||||
}
|
||||
|
||||
if (xport->match_all(F_PEM | F_CHAIN)) {
|
||||
while (crt && crt != oldcrt) {
|
||||
crt->writeCert(file, true);
|
||||
oldcrt = crt;
|
||||
crt = crt->getSigner();
|
||||
}
|
||||
} else if (xport->match_all(F_PEM | F_SELECT)) {
|
||||
foreach(QModelIndex idx, list) {
|
||||
crt = fromIndex<pki_x509>(idx);
|
||||
if (crt)
|
||||
crt->writeCert(file, true);
|
||||
}
|
||||
} else if (xport->match_all(F_PEM | F_UNREVOKED)) {
|
||||
foreach(pki_x509 *pki, Store.getAll<pki_x509>())
|
||||
if (!pki->isRevoked())
|
||||
pki->writeCert(file, true);
|
||||
} else if (xport->match_all(F_PEM | F_ALL)) {
|
||||
foreach(pki_x509 *pki, Store.getAll<pki_x509>())
|
||||
pki->writeCert(file, true);
|
||||
} else if (xport->match_all(F_PEM | F_PRIVATE)) {
|
||||
pkey = (pki_evp *)crt->getRefKey();
|
||||
if (!pkey || pkey->isPubKey())
|
||||
throw errorEx(tr("There was no key found for the Certificate: '%1'").
|
||||
arg(crt->getIntName()));
|
||||
if (pkey->isToken())
|
||||
throw errorEx(tr("Not possible for a token key: '%1'").
|
||||
arg(crt->getIntName()));
|
||||
if (xport->match_all(F_PKCS8)) {
|
||||
pkey->writePKCS8(file, EVP_des_ede3_cbc(),
|
||||
PwDialogCore::pwCallback, true);
|
||||
} else {
|
||||
pkey->writeKey(file, NULL, NULL, true);
|
||||
}
|
||||
crt->writeCert(file, true);
|
||||
} else if (xport->match_all(F_PEM)) {
|
||||
crt->writeCert(file, true);
|
||||
} else if (xport->match_all(F_DER)) {
|
||||
crt->writeCert(file, false);
|
||||
} else if (xport->match_all(F_PKCS7)) {
|
||||
writePKCS7(crt, file, xport->flags, list);
|
||||
} else if (xport->match_all(F_PKCS12)) {
|
||||
writePKCS12(crt, file, xport->match_all(F_CHAIN));
|
||||
} else if (xport->match_all(F_INDEX)) {
|
||||
foreach(QModelIndex idx, list) {
|
||||
crt = fromIndex<pki_x509>(idx);
|
||||
if (crt)
|
||||
certs << crt;
|
||||
}
|
||||
writeIndex(file, certs);
|
||||
} else if (xport->match_all(F_CAL)) {
|
||||
foreach(QModelIndex idx, list) {
|
||||
crt = fromIndex<pki_x509>(idx);
|
||||
if (!crt)
|
||||
continue;
|
||||
vcal += xport->match_all(F_CHAIN) ?
|
||||
crt->icsVEVENT_ca() : crt->icsVEVENT();
|
||||
}
|
||||
writeVcalendar(file, vcal);
|
||||
}
|
||||
} catch (errorEx &err) {
|
||||
XCA_ERROR(err);
|
||||
void db_x509::exportItems(const QModelIndexList &list,
|
||||
const pki_export *xport, XFile &file) const
|
||||
{
|
||||
if (list.empty())
|
||||
return;
|
||||
|
||||
pki_x509 *oldcrt = nullptr, *crt = fromIndex<pki_x509>(list[0]);
|
||||
|
||||
QList<pki_x509*> certs;
|
||||
foreach(QModelIndex idx, list) {
|
||||
pki_x509 *x = fromIndex<pki_x509>(idx);
|
||||
if (x)
|
||||
certs << x;
|
||||
}
|
||||
|
||||
if (xport->match_all(F_PEM | F_CHAIN)) {
|
||||
while (crt && crt != oldcrt) {
|
||||
crt->writeCert(file, true);
|
||||
oldcrt = crt;
|
||||
crt = crt->getSigner();
|
||||
}
|
||||
} else if (xport->match_all(F_PEM)) {
|
||||
foreach(crt, certs)
|
||||
crt->writeCert(file, true);
|
||||
} else if (xport->match_all(F_PEM | F_UNREVOKED)) {
|
||||
foreach(pki_x509 *pki, Store.getAll<pki_x509>())
|
||||
if (!pki->isRevoked())
|
||||
pki->writeCert(file, true);
|
||||
} else if (xport->match_all(F_PEM | F_ALL)) {
|
||||
foreach(pki_x509 *pki, Store.getAll<pki_x509>())
|
||||
pki->writeCert(file, true);
|
||||
} else if (xport->match_all(F_PEM | F_PRIVATE)) {
|
||||
pki_evp *pkey = (pki_evp *)crt->getRefKey();
|
||||
if (!pkey || pkey->isPubKey())
|
||||
throw errorEx(tr("There was no key found for the Certificate: '%1'").
|
||||
arg(crt->getIntName()));
|
||||
if (pkey->isToken())
|
||||
throw errorEx(tr("Not possible for a token key: '%1'").
|
||||
arg(crt->getIntName()));
|
||||
if (xport->match_all(F_PKCS8)) {
|
||||
pkey->writePKCS8(file, EVP_des_ede3_cbc(),
|
||||
PwDialogCore::pwCallback, true);
|
||||
} else {
|
||||
pkey->writeKey(file, NULL, NULL, true);
|
||||
}
|
||||
crt->writeCert(file, true);
|
||||
} else if (xport->match_all(F_PEM)) {
|
||||
crt->writeCert(file, true);
|
||||
} else if (xport->match_all(F_DER)) {
|
||||
crt->writeCert(file, false);
|
||||
} else if (xport->match_all(F_PKCS7)) {
|
||||
writePKCS7(crt, file, xport->flags, list);
|
||||
} else if (xport->match_all(F_PKCS12)) {
|
||||
writePKCS12(crt, file, xport->match_all(F_CHAIN));
|
||||
} else if (xport->match_all(F_INDEX)) {
|
||||
writeIndex(file, certs);
|
||||
} else if (xport->match_all(F_CAL)) {
|
||||
QStringList vcal;
|
||||
foreach(crt, certs) {
|
||||
vcal += xport->match_all(F_CHAIN) ?
|
||||
crt->icsVEVENT_ca() : crt->icsVEVENT();
|
||||
}
|
||||
writeVcalendar(file, vcal);
|
||||
}
|
||||
pki_base::pem_comment = false;
|
||||
delete dlg;
|
||||
}
|
||||
|
||||
void db_x509::writeIndex(XFile &file, QList<pki_x509*> items) const
|
||||
@ -700,7 +670,7 @@ void db_x509::writePKCS12(pki_x509 *cert, XFile &file, bool chain) const
|
||||
}
|
||||
|
||||
void db_x509::writePKCS7(pki_x509 *cert, XFile &file, int flags,
|
||||
QModelIndexList list) const
|
||||
const QModelIndexList &list) const
|
||||
{
|
||||
pki_pkcs7 *p7 = new pki_pkcs7(QString());
|
||||
|
||||
@ -712,17 +682,17 @@ void db_x509::writePKCS7(pki_x509 *cert, XFile &file, int flags,
|
||||
break;
|
||||
cert = cert->getSigner();
|
||||
}
|
||||
} else if (flags & F_SELECT) {
|
||||
foreach(QModelIndex idx, list) {
|
||||
cert = fromIndex<pki_x509>(idx);
|
||||
if (cert)
|
||||
p7->append_item(cert);
|
||||
}
|
||||
} else if (flags & (F_UNREVOKED | F_ALL)) {
|
||||
foreach(pki_x509 *cer, Store.getAll<pki_x509>()) {
|
||||
if ((flags & F_ALL) || !cer->isRevoked())
|
||||
p7->append_item(cer);
|
||||
}
|
||||
} else if (flags) {
|
||||
foreach(QModelIndex idx, list) {
|
||||
cert = fromIndex<pki_x509>(idx);
|
||||
if (cert)
|
||||
p7->append_item(cert);
|
||||
}
|
||||
} else {
|
||||
p7->append_item(cert);
|
||||
}
|
||||
|
||||
@ -48,20 +48,21 @@ class db_x509: public db_x509super
|
||||
void newCert(pki_x509 *cert);
|
||||
void writePKCS12(pki_x509 *cert, XFile &file, bool chain) const;
|
||||
void writePKCS7(pki_x509 *cert, XFile &file, int flags,
|
||||
QModelIndexList list) const;
|
||||
const QModelIndexList &list) const;
|
||||
void fillContextMenu(QMenu *menu, const QModelIndex &index);
|
||||
void inToCont(pki_base *pki);
|
||||
a1int getUniqueSerial(pki_x509 *signer);
|
||||
void toToken(QModelIndex idx, bool alwaysSelect);
|
||||
void toRequest(QModelIndex idx);
|
||||
void store(QModelIndex idx);
|
||||
void store(QModelIndexList list);
|
||||
void updateCaProperties(pki_x509 *cert);
|
||||
void toCertificate(QModelIndex index);
|
||||
void certRenewal(QModelIndexList indexes);
|
||||
void revoke(QModelIndexList indexes);
|
||||
void do_revoke(QModelIndexList indexes, const x509rev &r);
|
||||
void unRevoke(QModelIndexList indexes);
|
||||
int exportFlags(const QModelIndex &idx) const;
|
||||
void exportItems(const QModelIndexList &indexes,
|
||||
const pki_export *xport, XFile &file) const;
|
||||
|
||||
public slots:
|
||||
void newItem();
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
|
||||
#warning drop UI dependencies
|
||||
#include "widgets/NewX509.h"
|
||||
#include "widgets/ExportDialog.h"
|
||||
|
||||
db_x509req::db_x509req() : db_x509super("requests")
|
||||
{
|
||||
@ -100,33 +99,12 @@ void db_x509req::newItem(pki_temp *temp, pki_x509req *orig)
|
||||
}
|
||||
}
|
||||
|
||||
void db_x509req::store(QModelIndex index)
|
||||
void db_x509req::exportItem(const QModelIndex &index,
|
||||
const pki_export *xport, XFile &file) const
|
||||
{
|
||||
pki_x509req *req = fromIndex<pki_x509req>(index);
|
||||
if (!req)
|
||||
return;
|
||||
|
||||
ExportDialog *dlg = new ExportDialog(NULL,
|
||||
tr("Certificate request export"),
|
||||
tr("Certificate request ( *.pem *.der *.csr )"),
|
||||
req, QPixmap(":csrImg"),
|
||||
pki_export::select(x509_req, 0), "csrexport");
|
||||
if (!dlg->exec()) {
|
||||
delete dlg;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const pki_export *xport = dlg->export_type();
|
||||
XFile file(dlg->filename->text());
|
||||
pki_base::pem_comment = dlg->pemComment->isChecked();
|
||||
file.open_write();
|
||||
if (req)
|
||||
req->writeReq(file, xport->match_all(F_PEM));
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
XCA_ERROR(err);
|
||||
}
|
||||
pki_base::pem_comment = false;
|
||||
delete dlg;
|
||||
}
|
||||
|
||||
void db_x509req::setSigned(QModelIndex index, bool signe)
|
||||
|
||||
@ -25,10 +25,11 @@ class db_x509req: public db_x509super
|
||||
pki_base* insert(pki_base *item);
|
||||
pki_base *newPKI(enum pki_type type = none);
|
||||
void fillContextMenu(QMenu *menu, const QModelIndex &index);
|
||||
void store(QModelIndex index);
|
||||
QList<pki_x509req*> getAllRequests();
|
||||
void resetX509count();
|
||||
void setSigned(QModelIndex index, bool signe);
|
||||
void exportItem(const QModelIndex &index,
|
||||
const pki_export *xport, XFile &file) const;
|
||||
|
||||
public slots:
|
||||
void newItem(pki_temp *temp, pki_x509req *orig = NULL);
|
||||
|
||||
@ -15,10 +15,7 @@
|
||||
#include "widgets/XcaDialog.h"
|
||||
#include "XcaWarningCore.h"
|
||||
|
||||
#include "ui_CertDetail.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QTextEdit>
|
||||
|
||||
db_x509name::db_x509name(const char *classname)
|
||||
:db_base(classname)
|
||||
@ -152,20 +149,6 @@ void db_x509super::extractPubkey(QModelIndex index)
|
||||
XCA_INFO(key->getMsg(pki_base::msg_import).arg(pki->getIntName()));
|
||||
}
|
||||
|
||||
void db_x509super::toOpenssl(QModelIndex index) const
|
||||
{
|
||||
pki_x509super *pki = fromIndex<pki_x509super>(index);
|
||||
QString fn = Settings["workingdir"] + pki->getUnderlinedName() + ".conf";
|
||||
QString fname = QFileDialog::getSaveFileName(NULL,
|
||||
tr("Save as OpenSSL config"), fn,
|
||||
tr("Config files ( *.conf *.cnf);; All files ( * )"));
|
||||
if (fname.isEmpty())
|
||||
return;
|
||||
|
||||
update_workingdir(fname);
|
||||
pki->opensslConf(fname);
|
||||
}
|
||||
|
||||
void db_x509super::toTemplate(QModelIndex index)
|
||||
{
|
||||
db_temp *temps = Database.model<db_temp>();
|
||||
|
||||
@ -36,7 +36,6 @@ class db_x509super: public db_x509name
|
||||
QList<pki_x509super *> findByPubKey(pki_key *refkey);
|
||||
void extractPubkey(QModelIndex index);
|
||||
void toTemplate(QModelIndex index);
|
||||
void toOpenssl(QModelIndex index) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -21,13 +21,13 @@ digest::digest(int nid) : md_nid(nid)
|
||||
{
|
||||
}
|
||||
|
||||
digest::digest(const EVP_MD *md) : md_nid(NID_undef)
|
||||
digest::digest(const EVP_MD *md) : md_nid(default_md)
|
||||
{
|
||||
if (!OBJ_find_sigid_algs(EVP_MD_type(md), &md_nid, NULL))
|
||||
md_nid = EVP_MD_type(md);
|
||||
}
|
||||
|
||||
digest::digest(const QString &name) : md_nid(NID_undef)
|
||||
digest::digest(const QString &name) : md_nid(default_md)
|
||||
{
|
||||
QString s(name);
|
||||
md_nid = OBJ_txt2nid(CCHAR(s.remove(QChar(' '))));
|
||||
|
||||
@ -45,6 +45,7 @@ class crljob
|
||||
{
|
||||
crlNumber++;
|
||||
}
|
||||
crljob() = delete;
|
||||
};
|
||||
|
||||
class pki_crl: public pki_x509name
|
||||
|
||||
@ -669,7 +669,7 @@ bool pki_evp::pem(BioByteArray &b)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
int keytype;
|
||||
const pki_export *xport = pki_export::default_key_format();
|
||||
const pki_export *xport = pki_export::by_id(Settings["KeyFormat"]);
|
||||
|
||||
if (xport->match_all(F_PEM | F_PRIVATE)) {
|
||||
pkey = decryptKey();
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "pki_export.h"
|
||||
#include "settings.h"
|
||||
|
||||
pki_export::pki_export(int i, enum pki_type p, const QString &e,
|
||||
const QString &d, int f, const QString &h)
|
||||
@ -40,47 +39,41 @@ const pki_export *pki_export::by_id(int id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const pki_export *pki_export::default_key_format()
|
||||
{
|
||||
return by_id(Settings["KeyFormat"]);
|
||||
}
|
||||
|
||||
QList<pki_export*> pki_export::elements {
|
||||
new pki_export( 1, x509, "crt", "PEM", F_PEM | F_USUAL, tr("PEM Text format with headers")),
|
||||
new pki_export( 2, x509, "pem", tr("PEM chain"), F_PEM | F_USUAL | F_CHAIN, tr("Concatenated text format of the complete certificate chain in one PEM file")),
|
||||
new pki_export( 3, x509, "pem", tr("PEM selected"), F_PEM | F_USUAL | F_SELECT, tr("Concatenated list of all selected items in one PEM text file")),
|
||||
new pki_export( 4, x509, "pem", tr("PEM unrevoked"), F_PEM | F_UNREVOKED, tr("Concatenated text format of all unrevoked certificates in one PEM file")),
|
||||
new pki_export( 5, x509, "pem", tr("PEM all"), F_PEM | F_MULTI | F_ALL, tr("Concatenated text format of all certificates in one PEM file")),
|
||||
new pki_export( 6, x509, "pem", tr("PEM + key"), F_PEM | F_PLUSKEY | F_PRIVATE, tr("Concatenation of the certificate and the unencrypted private key in one PEM file")),
|
||||
new pki_export( 1, x509, "crt", "PEM", F_PEM | F_USUAL | F_SINGLE, tr("PEM Text format with headers")),
|
||||
new pki_export( 3, x509, "pem", "PEM", F_PEM | F_MULTI, tr("Concatenated list of all selected items in one PEM text file")),
|
||||
new pki_export( 2, x509, "pem", tr("PEM chain"), F_PEM | F_USUAL | F_CHAIN | F_SINGLE, tr("Concatenated text format of the complete certificate chain in one PEM file")),
|
||||
new pki_export( 6, x509, "pem", tr("PEM + key"), F_PEM | F_PLUSKEY | F_PRIVATE| F_SINGLE,tr("Concatenation of the certificate and the unencrypted private key in one PEM file")),
|
||||
new pki_export( 7, x509, "pem", "PEM + PKCS#8", F_PEM | F_PKCS8 | F_PRIVATE | F_CRYPT, tr("Concatenation of the certificate and the encrypted private key in PKCS#8 format in one file")),
|
||||
new pki_export( 8, x509, "p7b", "PKCS #7", F_PKCS7 | F_USUAL, tr("PKCS#7 encoded single certificate")),
|
||||
new pki_export( 9, x509, "p7b", tr("PKCS #7 all"), F_PKCS7 | F_USUAL | F_MULTI | F_ALL, tr("All selected certificates encoded in one PKCS#7 file")),
|
||||
new pki_export(10, x509, "p7b", tr("PKCS #7 selected"), F_PKCS7 | F_USUAL | F_MULTI | F_SELECT, tr("All selected certificates encoded in one PKCS#7 file")),
|
||||
new pki_export(11, x509, "p7b", tr("PKCS #7 unrevoked"), F_PKCS7 | F_MULTI | F_UNREVOKED, tr("All unrevoked certificates encoded in one PKCS#7 file")),
|
||||
new pki_export(12, x509, "p7b", tr("PKCS #7 chain"), F_PKCS7 | F_USUAL | F_CHAIN, tr("PKCS#7 encoded complete certificate chain")),
|
||||
new pki_export(13, x509, "cer", "DER", F_DER, tr("Binary DER encoded certificate")),
|
||||
new pki_export(14, x509, "pfx", tr("PKCS #12 chain"),F_PKCS12 | F_USUAL | F_CHAIN | F_CRYPT | F_PRIVATE, tr("The complete certificate chain and the private key as encrypted PKCS#12 file")),
|
||||
new pki_export(15, x509, "pfx", tr("PKCS #12"), F_PKCS12 | F_USUAL | F_CRYPT | F_PRIVATE, tr("The certificate and the private key as encrypted PKCS#12 file")),
|
||||
new pki_export(16, x509, "txt", tr("Certificate Index file"), F_INDEX | F_CA, tr("OpenSSL specific Certificate Index file as created by the 'ca' command and required by the OCSP tool")),
|
||||
new pki_export(17, x509, "ics", tr("vCalendar"), F_CAL, tr("vCalendar expiry reminder for the selected items")),
|
||||
new pki_export(18, x509, "ics", tr("CA vCalendar"), F_CAL | F_CA, tr("vCalendar expiry reminder containing all issued, valid certificates, the CA itself and the latest CRL")),
|
||||
new pki_export( 8, x509, "p7b", "PKCS #7", F_PKCS7 | F_USUAL | F_SINGLE, tr("PKCS#7 encoded single certificate")),
|
||||
new pki_export(10, x509, "p7b", "PKCS #7", F_PKCS7 | F_USUAL | F_MULTI, tr("All selected certificates encoded in one PKCS#7 file")),
|
||||
new pki_export(12, x509, "p7b", tr("PKCS #7 chain"), F_PKCS7 | F_USUAL | F_CHAIN | F_SINGLE, tr("PKCS#7 encoded complete certificate chain")),
|
||||
new pki_export(13, x509, "cer", "DER", F_DER | F_SINGLE, tr("Binary DER encoded certificate")),
|
||||
new pki_export(14, x509, "pfx", tr("PKCS #12 chain"),F_PKCS12 | F_USUAL | F_CHAIN | F_CRYPT | F_PRIVATE | F_SINGLE, tr("The complete certificate chain and the private key as encrypted PKCS#12 file")),
|
||||
new pki_export(15, x509, "pfx", tr("PKCS #12"), F_PKCS12 | F_USUAL | F_CRYPT | F_PRIVATE | F_SINGLE, tr("The certificate and the private key as encrypted PKCS#12 file")),
|
||||
new pki_export(16, x509, "txt", tr("Certificate Index file"), F_INDEX | F_CA, tr("OpenSSL specific Certificate Index file as created by the 'ca' command and required by the OCSP tool")),
|
||||
new pki_export(17, x509, "ics", tr("vCalendar"), F_CAL, tr("vCalendar expiry reminder for the selected items")),
|
||||
new pki_export(18, x509, "ics", tr("CA vCalendar"), F_CAL | F_CA, tr("vCalendar expiry reminder containing all issued, valid certificates, the CA itself and the latest CRL")),
|
||||
|
||||
new pki_export(19, asym_key, "pem", tr("PEM public"), F_PEM | F_CLIPBOARD, tr("Text format of the public key in one PEM file")),
|
||||
new pki_export(20, asym_key, "pem", tr("PEM private"), F_PEM | F_PRIVATE | F_USUAL | F_CLIPBOARD, tr("Unencrypted private key in text format")),
|
||||
new pki_export(21, asym_key, "pem", tr("PEM encrypted"), F_PEM | F_PRIVATE | F_CRYPT | F_CLIPBOARD, tr("OpenSSL specific encrypted private key in text format")),
|
||||
new pki_export(22, asym_key, "priv",tr("SSH2 private"), F_PEM | F_PRIVATE | F_SSH2, tr("Unencrypted private key in text format")),
|
||||
new pki_export(23, asym_key, "pub" ,tr("SSH2 public"), F_SSH2, tr("The public key encoded in SSH2 format")),
|
||||
new pki_export(24, asym_key, "der", tr("DER public"), F_DER, tr("Binary DER format of the public key")),
|
||||
new pki_export(25, asym_key, "der", tr("DER private"), F_DER | F_PRIVATE, tr("Unencrypted private key in binary DER format")),
|
||||
new pki_export(26, asym_key, "pvk", tr("PVK private"), F_PVK | F_PRIVATE, tr("Private key in Microsoft PVK format not encrypted")),
|
||||
new pki_export(27, asym_key, "pvk", tr("PVK encrypted"), F_PVK | F_PRIVATE | F_CRYPT, tr("Encrypted private key in Microsoft PVK format")),
|
||||
new pki_export(28, asym_key, "pk8", tr("PKCS #8 encrypted"), F_PKCS8 | F_PRIVATE | F_CRYPT | F_USUAL | F_CLIPBOARD, tr("Encrypted private key in PKCS#8 text format")),
|
||||
new pki_export(29, asym_key, "pk8", tr("PKCS #8"), F_PKCS8 | F_PRIVATE | F_CLIPBOARD, tr("Unencrypted private key in PKCS#8 text format")),
|
||||
new pki_export(19, asym_key, "pem", tr("PEM public"), F_PEM | F_CLIPBOARD, tr("Text format of the public key in one PEM file")),
|
||||
new pki_export(20, asym_key, "pem", tr("PEM private"), F_PEM | F_PRIVATE | F_USUAL | F_CLIPBOARD, tr("Unencrypted private key in text format")),
|
||||
new pki_export(21, asym_key, "pem", tr("PEM encrypted"), F_PEM | F_PRIVATE | F_CRYPT | F_SINGLE, tr("OpenSSL specific encrypted private key in text format")),
|
||||
new pki_export(22, asym_key, "priv",tr("SSH2 private"), F_PEM | F_PRIVATE | F_SSH2 | F_SINGLE, tr("Unencrypted private key in text format")),
|
||||
new pki_export(23, asym_key, "pub" ,tr("SSH2 public"), F_SSH2, tr("The public key encoded in SSH2 format")),
|
||||
new pki_export(24, asym_key, "der", tr("DER public"), F_DER | F_SINGLE, tr("Binary DER format of the public key")),
|
||||
new pki_export(25, asym_key, "der", tr("DER private"), F_DER | F_PRIVATE | F_SINGLE, tr("Unencrypted private key in binary DER format")),
|
||||
new pki_export(26, asym_key, "pvk", tr("PVK private"), F_PVK | F_PRIVATE | F_SINGLE, tr("Private key in Microsoft PVK format not encrypted")),
|
||||
new pki_export(27, asym_key, "pvk", tr("PVK encrypted"), F_PVK | F_PRIVATE | F_CRYPT | F_SINGLE, tr("Encrypted private key in Microsoft PVK format")),
|
||||
new pki_export(28, asym_key, "pk8", tr("PKCS #8 encrypted"), F_PKCS8 | F_PRIVATE | F_CRYPT | F_USUAL | F_SINGLE, tr("Encrypted private key in PKCS#8 text format")),
|
||||
new pki_export(29, asym_key, "pk8", tr("PKCS #8"), F_PKCS8 | F_PRIVATE | F_CLIPBOARD | F_SINGLE, tr("Unencrypted private key in PKCS#8 text format")),
|
||||
|
||||
new pki_export(30, x509_req, "csr", "PEM", F_PEM, tr("PEM Text format with headers")),
|
||||
new pki_export(31, x509_req, "der", "DER", F_DER, tr("Binary DER format of the certificate request")),
|
||||
new pki_export(30, x509_req, "csr", "PEM", F_PEM, tr("PEM Text format with headers")),
|
||||
new pki_export(31, x509_req, "der", "DER", F_DER | F_SINGLE, tr("Binary DER format of the certificate request")),
|
||||
|
||||
new pki_export(32, revocation, "pem", "PEM", F_PEM, tr("PEM Text format with headers")),
|
||||
new pki_export(33, revocation, "der", "DER", F_DER, 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(32, revocation, "crl", "PEM", F_PEM, tr("PEM Text format with headers")),
|
||||
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(35, tmpl, "pem", "PEM", F_PEM | F_MULTI, tr("All selected XCA templates in PEM-like format")),
|
||||
};
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include <QList>
|
||||
|
||||
#define BIT(n) (1<<n)
|
||||
#define DEFAULT_KEY_CLIPBOARD_TYPE 19
|
||||
|
||||
enum pki_type {
|
||||
none,
|
||||
@ -32,8 +33,8 @@ enum {
|
||||
F_PRIVATE = BIT(2), /* File contains Private Key */
|
||||
F_USUAL = BIT(3), /* Usual format */
|
||||
F_SSH2 = BIT(4), /* Key is SSH2 compatible */
|
||||
F_MULTI = BIT(5), /* More than one element */
|
||||
F_SELECT = BIT(6), /* Selected elements */
|
||||
F_MULTI = BIT(5), /* Hide if only element is selected */
|
||||
F_SINGLE = BIT(6), /* Single element not suitable for selections */
|
||||
F_ALL = BIT(7), /* All elements */
|
||||
F_UNREVOKED = BIT(8), /* All unrevoked certificates */
|
||||
F_PLUSKEY = BIT(9), /* Cert plus key */
|
||||
@ -65,7 +66,6 @@ class pki_export : public QObject {
|
||||
pki_export(int i, enum pki_type p, const QString &e,
|
||||
const QString &d, int f, const QString &h);
|
||||
static QList<const pki_export*> select(enum pki_type, int);
|
||||
static const pki_export *default_key_format();
|
||||
static const pki_export *by_id(int id);
|
||||
bool match_all(int match_flags) const;
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ void pki_key::write_SSH2_ed25519_private(BIO *b,
|
||||
|
||||
bool pki_key::pem(BioByteArray &b)
|
||||
{
|
||||
const pki_export *xport = pki_export::default_key_format();
|
||||
const pki_export *xport = pki_export::by_id(Settings["KeyFormat"]);
|
||||
|
||||
if (xport->match_all(F_PRIVATE))
|
||||
return false;
|
||||
|
||||
@ -18,10 +18,7 @@
|
||||
|
||||
#include "XcaWarningCore.h"
|
||||
|
||||
#warning Drop "widgets dependency"
|
||||
|
||||
#include <QThread>
|
||||
#include <QProgressBar>
|
||||
|
||||
void pki_scard::init(void)
|
||||
{
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "sql.h"
|
||||
#include "pki_key.h"
|
||||
#include "digest.h"
|
||||
#include "pki_export.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
@ -38,7 +39,7 @@ settings::settings()
|
||||
defaul["serial_len"] = "64";
|
||||
defaul["fp_separator"] = ":";
|
||||
defaul["fp_digits"] = "2";
|
||||
defaul["KeyFormat"] = "19"; // PEM public
|
||||
defaul["KeyFormat"] = QString::number(DEFAULT_KEY_CLIPBOARD_TYPE);
|
||||
|
||||
hostspecific << "pkcs11path" << "workingdir" << "mw_geometry";
|
||||
}
|
||||
|
||||
@ -525,7 +525,7 @@
|
||||
<slots>
|
||||
<slot>newItem()</slot>
|
||||
<slot>load()</slot>
|
||||
<slot>storeItems()</slot>
|
||||
<slot>exportItems()</slot>
|
||||
<slot>showItems()</slot>
|
||||
<slot>deleteItems()</slot>
|
||||
</slots>
|
||||
@ -599,7 +599,7 @@
|
||||
<sender>BNexportKey</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>keyView</receiver>
|
||||
<slot>storeItems()</slot>
|
||||
<slot>exportItems()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>526</x>
|
||||
@ -663,7 +663,7 @@
|
||||
<sender>BNexportReq</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>reqView</receiver>
|
||||
<slot>storeItems()</slot>
|
||||
<slot>exportItems()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>489</x>
|
||||
@ -743,7 +743,7 @@
|
||||
<sender>BNexportCert</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>certView</receiver>
|
||||
<slot>storeItems()</slot>
|
||||
<slot>exportItems()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>499</x>
|
||||
@ -871,7 +871,7 @@
|
||||
<sender>BNexportTemp</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>tempView</receiver>
|
||||
<slot>storeItems()</slot>
|
||||
<slot>exportItems()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>488</x>
|
||||
@ -887,7 +887,7 @@
|
||||
<sender>BNexportCrl</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>crlView</receiver>
|
||||
<slot>storeItems()</slot>
|
||||
<slot>exportItems()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>472</x>
|
||||
|
||||
@ -11,9 +11,11 @@
|
||||
#include "XcaDialog.h"
|
||||
#include "MainWindow.h"
|
||||
#include "RevocationList.h"
|
||||
#include "ExportDialog.h"
|
||||
#include "NewCrl.h"
|
||||
#include "lib/database_model.h"
|
||||
#include "lib/db_crl.h"
|
||||
#include "lib/load_obj.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractItemView>
|
||||
@ -232,3 +234,13 @@ void CertTreeView::load()
|
||||
load_cert c;
|
||||
load_default(&c);
|
||||
}
|
||||
|
||||
ExportDialog *CertTreeView::exportDialog(const QModelIndexList &indexes)
|
||||
{
|
||||
return new ExportDialog(this,
|
||||
tr("Certificate export"),
|
||||
tr("X509 Certificates ( *.pem *.cer *.crt *.p12 *.pfx *.p7b )"),
|
||||
indexes, QPixmap(":certImg"),
|
||||
pki_export::select(x509, basemodel->exportFlags(indexes)),
|
||||
"certexport");
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ class CertTreeView: public X509SuperTreeView
|
||||
CertTreeView(QWidget *parent) : X509SuperTreeView(parent) { }
|
||||
void fillContextMenu(QMenu *menu, QMenu *subExport,
|
||||
const QModelIndex &index, QModelIndexList indexes);
|
||||
ExportDialog *exportDialog(const QModelIndexList &index);
|
||||
|
||||
public slots:
|
||||
void changeView();
|
||||
|
||||
@ -12,9 +12,11 @@
|
||||
#include "MainWindow.h"
|
||||
#include "ItemCombo.h"
|
||||
#include "XcaWarning.h"
|
||||
#include "ExportDialog.h"
|
||||
#include "lib/db_crl.h"
|
||||
#include "lib/pki_x509.h"
|
||||
#include "lib/database_model.h"
|
||||
#include "lib/load_obj.h"
|
||||
|
||||
void CrlTreeView::showPki(pki_base *pki)
|
||||
{
|
||||
@ -60,3 +62,11 @@ void CrlTreeView::load()
|
||||
load_crl l;
|
||||
load_default(&l);
|
||||
}
|
||||
|
||||
ExportDialog *CrlTreeView::exportDialog(const QModelIndexList &indexes)
|
||||
{
|
||||
return new ExportDialog(this,
|
||||
tr("Revocation list export"),
|
||||
tr("CRL ( *.pem *.der *.crl )"), indexes, QPixmap(":revImg"),
|
||||
pki_export::select(revocation, basemodel->exportFlags(indexes)));
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ class CrlTreeView: public XcaTreeView
|
||||
public:
|
||||
CrlTreeView(QWidget *parent) : XcaTreeView(parent) { }
|
||||
void showPki(pki_base *pki);
|
||||
ExportDialog *exportDialog(const QModelIndexList &index);
|
||||
|
||||
public slots:
|
||||
void newItem(pki_x509 *cert);
|
||||
|
||||
@ -20,25 +20,31 @@
|
||||
#include <QStringList>
|
||||
|
||||
ExportDialog::ExportDialog(QWidget *w, const QString &title,
|
||||
const QString &filt, pki_base *pki, const QPixmap &img,
|
||||
QList<const pki_export*> types, const QString &help_ctx)
|
||||
const QString &filt, const QModelIndexList &indexes,
|
||||
const QPixmap &img, QList<const pki_export*> types,
|
||||
const QString &help_ctx)
|
||||
: QDialog(w ? w : mainwin)
|
||||
{
|
||||
QList<const pki_export*> usual, normal;
|
||||
QString fname = "selected_items";
|
||||
setupUi(this);
|
||||
setWindowTitle(XCA_TITLE);
|
||||
if (pki)
|
||||
descr->setText(pki->getIntName());
|
||||
if (indexes.size() == 1) {
|
||||
pki_base *pki = db_base::fromIndex(indexes[0]);
|
||||
if (pki) {
|
||||
descr->setText(pki->getIntName());
|
||||
fname = pki->getUnderlinedName();
|
||||
}
|
||||
}
|
||||
descr->setReadOnly(true);
|
||||
image->setPixmap(img);
|
||||
label->setText(title);
|
||||
mainwin->helpdlg->register_ctxhelp_button(this, help_ctx);
|
||||
|
||||
if (pki) {
|
||||
QString fn = Settings["workingdir"] +
|
||||
pki->getUnderlinedName() + "." + types[0]->extension;
|
||||
filename->setText(nativeSeparator(fn));
|
||||
}
|
||||
QString fn = Settings["workingdir"] +
|
||||
fname + "." + types[0]->extension;
|
||||
filename->setText(nativeSeparator(fn));
|
||||
|
||||
filter = filt + ";;" + tr("All files ( * )");
|
||||
|
||||
foreach(const pki_export *t, types) {
|
||||
@ -58,6 +64,11 @@ ExportDialog::ExportDialog(QWidget *w, const QString &title,
|
||||
on_exportFormat_highlighted(0);
|
||||
}
|
||||
|
||||
ExportDialog::~ExportDialog()
|
||||
{
|
||||
pki_base::pem_comment = 0;
|
||||
}
|
||||
|
||||
void ExportDialog::on_fileBut_clicked()
|
||||
{
|
||||
QString s = QFileDialog::getSaveFileName(this, QString(),
|
||||
@ -102,6 +113,7 @@ bool ExportDialog::mayWriteFile(const QString &fname)
|
||||
void ExportDialog::accept()
|
||||
{
|
||||
QString fn = filename->text();
|
||||
pki_base::pem_comment = pemComment->isChecked();
|
||||
|
||||
if (!filename->isEnabled()) {
|
||||
QDialog::accept();
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include "ui_ExportDialog.h"
|
||||
#include "lib/pki_export.h"
|
||||
#include <QModelIndexList>
|
||||
|
||||
class QPixmap;
|
||||
class pki_base;
|
||||
@ -23,9 +24,10 @@ class ExportDialog: public QDialog, public Ui::ExportDialog
|
||||
|
||||
public:
|
||||
ExportDialog(QWidget *w, const QString &title, const QString &filt,
|
||||
pki_base *pki, const QPixmap &img,
|
||||
const QModelIndexList &indexes, const QPixmap &img,
|
||||
QList<const pki_export*> types,
|
||||
const QString &help_ctx = QString());
|
||||
~ExportDialog();
|
||||
static bool mayWriteFile(const QString &fname);
|
||||
const pki_export *export_type(int idx = -1) const;
|
||||
|
||||
|
||||
@ -6,10 +6,12 @@
|
||||
*/
|
||||
|
||||
#include "lib/pki_scard.h"
|
||||
#include "lib/load_obj.h"
|
||||
#include "KeyTreeView.h"
|
||||
#include "MainWindow.h"
|
||||
#include "KeyDetail.h"
|
||||
#include "NewKey.h"
|
||||
#include "ExportDialog.h"
|
||||
#include "XcaWarning.h"
|
||||
#include <QAbstractItemView>
|
||||
#include <QMenu>
|
||||
@ -209,9 +211,6 @@ void KeyTreeView::newItem(const QString &name)
|
||||
|
||||
void KeyTreeView::clipboardFormat(QAction *a)
|
||||
{
|
||||
qWarning("pki_key::default_export_type: %d %d\n",
|
||||
(int)Settings["KeyFormat"], a->data().toInt());
|
||||
|
||||
Settings["KeyFormat"] = a->data().toInt();
|
||||
}
|
||||
|
||||
@ -220,3 +219,17 @@ void KeyTreeView::load(void)
|
||||
load_key l;
|
||||
load_default(&l);
|
||||
}
|
||||
|
||||
ExportDialog *KeyTreeView::exportDialog(const QModelIndexList &indexes)
|
||||
{
|
||||
if (indexes.size() == 0)
|
||||
return NULL;
|
||||
pki_key *key = db_base::fromIndex<pki_key>(indexes[0]);
|
||||
return new ExportDialog(this,
|
||||
tr("Export public key [%1]").arg(key->getTypeString()),
|
||||
tr("Private Keys ( *.pem *.der *.pk8 );; "
|
||||
"SSH Public Keys ( *.pub )"), indexes,
|
||||
QPixmap(key->isToken() ? ":scardImg" : ":keyImg"),
|
||||
pki_export::select(asym_key, basemodel->exportFlags(indexes)),
|
||||
"keyexport");
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ class KeyTreeView: public XcaTreeView
|
||||
void fillContextMenu(QMenu *menu, QMenu *subExport,
|
||||
const QModelIndex &index, QModelIndexList indexes);
|
||||
void showPki(pki_base *pki);
|
||||
ExportDialog *exportDialog(const QModelIndexList &indexes);
|
||||
|
||||
public slots:
|
||||
void resetOwnPass();
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
#include "lib/pki_multi.h"
|
||||
#include "lib/pki_scard.h"
|
||||
#include "lib/dhgen.h"
|
||||
#include "lib/load_obj.h"
|
||||
|
||||
#include "XcaDialog.h"
|
||||
#include "XcaWarning.h"
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "lib/func.h"
|
||||
#include "lib/load_obj.h"
|
||||
#include "Options.h"
|
||||
#include "SearchPkcs11.h"
|
||||
#include "XcaWarning.h"
|
||||
|
||||
@ -6,8 +6,10 @@
|
||||
*/
|
||||
|
||||
#include "lib/pki_x509req.h"
|
||||
#include "lib/load_obj.h"
|
||||
#include "ReqTreeView.h"
|
||||
#include "MainWindow.h"
|
||||
#include "ExportDialog.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractItemView>
|
||||
#include <QMenu>
|
||||
@ -66,3 +68,13 @@ void ReqTreeView::load(void)
|
||||
load_req l;
|
||||
load_default(&l);
|
||||
}
|
||||
|
||||
ExportDialog *ReqTreeView::exportDialog(const QModelIndexList &indexes)
|
||||
{
|
||||
return new ExportDialog(this,
|
||||
tr("Certificate request export"),
|
||||
tr("Certificate request ( *.pem *.der *.csr )"),
|
||||
indexes, QPixmap(":csrImg"),
|
||||
pki_export::select(x509_req, basemodel->exportFlags(indexes)),
|
||||
"csrexport");
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ class ReqTreeView: public X509SuperTreeView
|
||||
ReqTreeView(QWidget *parent) : X509SuperTreeView(parent) { }
|
||||
void fillContextMenu(QMenu *menu, QMenu *subExport,
|
||||
const QModelIndex &index, QModelIndexList indexes);
|
||||
ExportDialog *exportDialog(const QModelIndexList &indexes);
|
||||
|
||||
public slots:
|
||||
void toRequest();
|
||||
|
||||
@ -6,7 +6,9 @@
|
||||
*/
|
||||
|
||||
#include "lib/pki_temp.h"
|
||||
#include "lib/load_obj.h"
|
||||
#include "TempTreeView.h"
|
||||
#include "ExportDialog.h"
|
||||
#include "NewX509.h"
|
||||
#include "XcaDialog.h"
|
||||
#include "MainWindow.h"
|
||||
@ -113,3 +115,13 @@ void TempTreeView::load()
|
||||
load_temp l;
|
||||
load_default(&l);
|
||||
}
|
||||
|
||||
ExportDialog *TempTreeView::exportDialog(const QModelIndexList &indexes)
|
||||
{
|
||||
return new ExportDialog(this,
|
||||
tr("Template export"),
|
||||
tr("XCA Templates ( *.xca )"),
|
||||
indexes, QPixmap(":tempImg"),
|
||||
pki_export::select(tmpl, basemodel->exportFlags(indexes)),
|
||||
"templateexport");
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ class TempTreeView: public XcaTreeView
|
||||
const QModelIndex &index, QModelIndexList indexes);
|
||||
void showPki(pki_base *pki);
|
||||
bool alterTemp(pki_temp *temp);
|
||||
ExportDialog *exportDialog(const QModelIndexList &index);
|
||||
|
||||
public slots:
|
||||
void certFromTemp();
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractItemView>
|
||||
#include <QFileDialog>
|
||||
#include <QMenu>
|
||||
|
||||
void X509SuperTreeView::fillContextMenu(QMenu *menu, QMenu *subExport,
|
||||
@ -52,8 +53,19 @@ void X509SuperTreeView::toOpenssl()
|
||||
{
|
||||
QModelIndex idx = currentIndex();
|
||||
|
||||
if (idx.isValid() && basemodel)
|
||||
x509super()->toOpenssl(idx);
|
||||
if (!idx.isValid() || !basemodel)
|
||||
return;
|
||||
|
||||
pki_x509super *pki = db_base::fromIndex<pki_x509super>(idx);
|
||||
QString fn = Settings["workingdir"] + pki->getUnderlinedName() + ".conf";
|
||||
QString fname = QFileDialog::getSaveFileName(NULL,
|
||||
tr("Save as OpenSSL config"), fn,
|
||||
tr("Config files ( *.conf *.cnf);; All files ( * )"));
|
||||
if (fname.isEmpty())
|
||||
return;
|
||||
|
||||
update_workingdir(fname);
|
||||
pki->opensslConf(fname);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __XCADIALOG_H
|
||||
#define __XCADIALOG_H
|
||||
#ifndef __XCADIALOG_H__
|
||||
#define __XCADIALOG_H__
|
||||
|
||||
#include <QDialog>
|
||||
#include "ui_XcaDialog.h"
|
||||
|
||||
@ -22,7 +22,9 @@
|
||||
#include "XcaWarning.h"
|
||||
#include "XcaDialog.h"
|
||||
#include "XcaApplication.h"
|
||||
#include "ExportDialog.h"
|
||||
#include "ImportMulti.h"
|
||||
#include "lib/load_obj.h"
|
||||
|
||||
#include "ui_ItemProperties.h"
|
||||
|
||||
@ -245,51 +247,9 @@ void XcaTreeView::deleteItems()
|
||||
TransCommit();
|
||||
}
|
||||
|
||||
void XcaTreeView::storeItems()
|
||||
void XcaTreeView::exportItems()
|
||||
{
|
||||
storeItems(getSelectedIndexes());
|
||||
}
|
||||
|
||||
void XcaTreeView::storeItems(QModelIndexList indexes)
|
||||
{
|
||||
if (!basemodel || indexes.size() == 0)
|
||||
return;
|
||||
try {
|
||||
if (indexes.size() == 1) {
|
||||
basemodel->store(indexes[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
xcaWarningBox msg(NULL,
|
||||
tr("How to export the %1 selected items").
|
||||
arg(indexes.size()));
|
||||
msg.addButton(QMessageBox::Ok, tr("All in one PEM file"));
|
||||
msg.addButton(QMessageBox::Apply, tr("Each item in one file"));
|
||||
msg.addButton(QMessageBox::Cancel);
|
||||
int ret = msg.exec();
|
||||
if (ret == QMessageBox::Apply) {
|
||||
foreach(QModelIndex i, indexes)
|
||||
basemodel->store(i);
|
||||
return;
|
||||
} else if (ret != QMessageBox::Ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString s = QFileDialog::getSaveFileName(NULL,
|
||||
tr("Save %1 items in one file as").arg(indexes.size()),
|
||||
Settings["workingdir"] + "export.pem",
|
||||
tr("PEM files ( *.pem );; All files ( * )"));
|
||||
if (s.isEmpty())
|
||||
return;
|
||||
|
||||
update_workingdir(s);
|
||||
QString pem = basemodel->pem2QString(indexes);
|
||||
XFile file(s);
|
||||
file.open_write();
|
||||
file.write(pem.toLatin1());
|
||||
} catch (errorEx &err) {
|
||||
XCA_ERROR(err);
|
||||
}
|
||||
exportItems(getSelectedIndexes());
|
||||
}
|
||||
|
||||
void XcaTreeView::showItems()
|
||||
@ -497,6 +457,36 @@ void XcaTreeView::changeView()
|
||||
show();
|
||||
}
|
||||
|
||||
void XcaTreeView::exportItems(const QModelIndexList &indexes)
|
||||
{
|
||||
if (!basemodel || indexes.empty())
|
||||
return;
|
||||
|
||||
ExportDialog *dlg = exportDialog(indexes);
|
||||
|
||||
if (dlg && dlg->exec()) {
|
||||
try {
|
||||
const pki_export *xport = dlg->export_type();
|
||||
XFile file(dlg->filename->text());
|
||||
|
||||
if (xport->match_all(F_PRIVATE))
|
||||
file.open_key();
|
||||
else
|
||||
file.open_write();
|
||||
|
||||
basemodel->exportItems(indexes, xport, file);
|
||||
} catch (errorEx &err) {
|
||||
XCA_ERROR(err);
|
||||
}
|
||||
}
|
||||
delete dlg;
|
||||
}
|
||||
|
||||
ExportDialog *XcaTreeView::exportDialog(const QModelIndexList &indexes)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void XcaTreeView::showContextMenu(QContextMenuEvent *e,
|
||||
const QModelIndex &idx)
|
||||
{
|
||||
@ -521,7 +511,7 @@ void XcaTreeView::showContextMenu(QContextMenuEvent *e,
|
||||
subExport = menu->addMenu(tr("Export"));
|
||||
subExport->addAction(tr("Clipboard"), this,
|
||||
SLOT(pem2clipboard()), QKeySequence::Copy);
|
||||
subExport->addAction(tr("File"), this, SLOT(storeItems()),
|
||||
subExport->addAction(tr("File"), this, SLOT(exportItems()),
|
||||
QKeySequence::Save);
|
||||
}
|
||||
|
||||
@ -550,7 +540,7 @@ void XcaTreeView::keyPressEvent(QKeyEvent *event)
|
||||
return;
|
||||
}
|
||||
if (event->matches(QKeySequence::Save)) {
|
||||
storeItems();
|
||||
exportItems();
|
||||
return;
|
||||
}
|
||||
if (event->matches(QKeySequence::Copy)) {
|
||||
|
||||
@ -23,6 +23,7 @@ class QKeyEvent;
|
||||
class QContextMenuEvent;
|
||||
class QMenu;
|
||||
class load_base;
|
||||
class ExportDialog;
|
||||
|
||||
class XcaTreeView: public QTreeView
|
||||
{
|
||||
@ -58,8 +59,9 @@ class XcaTreeView: public QTreeView
|
||||
QMenu *parent = NULL, int sect = -1);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
virtual void showPki(pki_base *) {};
|
||||
virtual void storeItems(QModelIndexList indexes);
|
||||
virtual void exportItems(const QModelIndexList &indexes);
|
||||
virtual void load_default(load_base *load);
|
||||
virtual ExportDialog *exportDialog(const QModelIndexList &indexes);
|
||||
|
||||
public slots:
|
||||
void changeView();
|
||||
@ -69,7 +71,7 @@ class XcaTreeView: public QTreeView
|
||||
void editIdx();
|
||||
void setFilter(const QString &pattern);
|
||||
void deleteItems();
|
||||
void storeItems();
|
||||
void exportItems();
|
||||
void showItems();
|
||||
void newItem();
|
||||
void doubleClick(const QModelIndex &m);
|
||||
|
||||
@ -13,7 +13,6 @@ hashBox::hashBox(QWidget *parent)
|
||||
:QComboBox(parent)
|
||||
{
|
||||
setupAllHashes();
|
||||
setDefaultHash();
|
||||
}
|
||||
|
||||
const digest hashBox::current() const
|
||||
@ -45,7 +44,10 @@ void hashBox::setupHashes(QList<int> nids)
|
||||
}
|
||||
setEnabled(count() > 0);
|
||||
setDefaultHash();
|
||||
setCurrent(digest(md));
|
||||
if (!md.isEmpty())
|
||||
setCurrent(digest(md));
|
||||
else
|
||||
setDefaultHash();
|
||||
}
|
||||
|
||||
void hashBox::setupAllHashes()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user