mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
add DH param generation
This commit is contained in:
parent
577c81d2ef
commit
984798659c
@ -1,4 +1,5 @@
|
||||
|
||||
* add DH param generation menu entry
|
||||
* improve token handling and PIN changing dialogs
|
||||
* improve key-value table input for "additional DN entries"
|
||||
* PIN and PUK changing implemented
|
||||
|
||||
@ -45,5 +45,10 @@ class errorEx
|
||||
}
|
||||
};
|
||||
|
||||
#define check_oom(ptr) if(!ptr){throw errorEx(QObject::tr("Out of Memory"));}
|
||||
#define check_oom(ptr) \
|
||||
if(!ptr) { \
|
||||
throw errorEx(QObject::tr("Out of Memory at %1:%2").\
|
||||
arg(__FILE__).arg(__LINE__)); \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
13
lib/func.cpp
13
lib/func.cpp
@ -23,6 +23,7 @@
|
||||
#include <qfile.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qprogressbar.h>
|
||||
#if defined(Q_WS_MAC)
|
||||
#include <qdesktopservices.h>
|
||||
#endif
|
||||
@ -339,3 +340,15 @@ bool _ign_openssl_error(const char *file, int line)
|
||||
return !errtxt.isEmpty();
|
||||
}
|
||||
|
||||
void inc_progress_bar(int, int, void *p)
|
||||
{
|
||||
QProgressBar *bar = (QProgressBar *)p;
|
||||
int value = bar->value();
|
||||
|
||||
if (value == bar->maximum()) {
|
||||
bar->reset();
|
||||
} else {
|
||||
bar->setValue(value +1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ QString changeFilenameSuffix(QString fn, const QStringList &suffixlist,
|
||||
int selected);
|
||||
|
||||
bool mayWriteFile(const QString &fname);
|
||||
void inc_progress_bar(int, int, void *p);
|
||||
|
||||
#define openssl_error(x) _openssl_error(QString(x), __FILE__, __LINE__)
|
||||
#define ign_openssl_error() _ign_openssl_error(__FILE__, __LINE__)
|
||||
|
||||
@ -61,12 +61,6 @@ void pki_evp::init(int type)
|
||||
cols=5;
|
||||
}
|
||||
|
||||
static void incProgress(int, int, void *progress)
|
||||
{
|
||||
int i = ((QProgressBar *)progress)->value();
|
||||
((QProgressBar *)progress)->setValue(++i);
|
||||
}
|
||||
|
||||
QString pki_evp::removeTypeFromIntName(QString n)
|
||||
{
|
||||
if (n.right(1) != ")" )
|
||||
@ -114,14 +108,15 @@ void pki_evp::generate(int bits, int type, QProgressBar *progress, int curve_nid
|
||||
|
||||
switch (type) {
|
||||
case EVP_PKEY_RSA:
|
||||
rsakey = RSA_generate_key(bits, 0x10001, &incProgress,progress);
|
||||
rsakey = RSA_generate_key(bits, 0x10001, inc_progress_bar,
|
||||
progress);
|
||||
if (rsakey)
|
||||
EVP_PKEY_assign_RSA(key, rsakey);
|
||||
break;
|
||||
case EVP_PKEY_DSA:
|
||||
progress->setMaximum(500);
|
||||
dsakey = DSA_generate_parameters(bits, NULL, 0, NULL, NULL,
|
||||
&incProgress, progress);
|
||||
inc_progress_bar, progress);
|
||||
DSA_generate_key(dsakey);
|
||||
if (dsakey)
|
||||
EVP_PKEY_assign_DSA(key, dsakey);
|
||||
|
||||
@ -175,6 +175,4 @@ void pki_multi::probeAnything(const QString fname)
|
||||
}
|
||||
while (!lbs.isEmpty())
|
||||
delete lbs.takeFirst();
|
||||
|
||||
#warning delete lbs
|
||||
}
|
||||
|
||||
@ -541,12 +541,7 @@ void pki_scard::generateKey_card(unsigned long slot, int size, QProgressBar *bar
|
||||
kt.p11 = &p11;
|
||||
kt.start();
|
||||
while (!kt.wait(20)) {
|
||||
int value = bar->value();
|
||||
if (value == bar->maximum()) {
|
||||
bar->reset();
|
||||
} else {
|
||||
bar->setValue(value +1);
|
||||
}
|
||||
inc_progress_bar(0, 0, bar);
|
||||
}
|
||||
if (!kt.err.isEmpty())
|
||||
throw errorEx(kt.err);
|
||||
|
||||
@ -25,10 +25,12 @@ void MainWindow::init_menu()
|
||||
QMenu *file, *help, *import, *token;
|
||||
|
||||
file = menuBar()->addMenu(tr("&File"));
|
||||
file->addAction(tr("&New DataBase"), this, SLOT(new_database()));
|
||||
file->addAction(tr("&Open DataBase"), this, SLOT(load_database()));
|
||||
file->addAction(tr("&New DataBase"), this, SLOT(new_database()));
|
||||
file->addAction(tr("&Open DataBase"), this, SLOT(load_database()));
|
||||
file->addAction(tr("Generate DH parameter"), this,
|
||||
SLOT(generateDHparam()));
|
||||
acList += file->addAction(tr("&Close DataBase"), this,
|
||||
SLOT(close_database()));
|
||||
SLOT(close_database()));
|
||||
acList += file->addAction(tr("&Dump DataBase"), this,
|
||||
SLOT(dump_database()));
|
||||
acList += file->addAction(tr("C&hange DataBase password"), this,
|
||||
|
||||
@ -860,3 +860,48 @@ pki_multi *MainWindow::probeAnything(QString file)
|
||||
return pki;
|
||||
}
|
||||
|
||||
void MainWindow::generateDHparam()
|
||||
{
|
||||
DH *dh = NULL;
|
||||
FILE *fp = NULL;
|
||||
QProgressBar *bar = NULL;
|
||||
bool ok;
|
||||
int num = QInputDialog::getInt(this, XCA_TITLE, tr("DH parameter bits"),
|
||||
1024, 1024, 4096, 1024, &ok);
|
||||
|
||||
if (!ok)
|
||||
return;
|
||||
try {
|
||||
QStatusBar *status = statusBar();
|
||||
bar = new QProgressBar();
|
||||
check_oom(bar);
|
||||
bar->setMinimum(0);
|
||||
bar->setMaximum(100);
|
||||
status->addPermanentWidget(bar, 1);
|
||||
dh = DH_generate_parameters(num, 2, inc_progress_bar, bar);
|
||||
status->removeWidget(bar);
|
||||
openssl_error();
|
||||
|
||||
QString fname = QString("%1/dh%2.pem").arg(homedir).arg(num);
|
||||
fname = QFileDialog::getSaveFileName(this, QString(),
|
||||
fname, "All files ( * )", NULL);
|
||||
if (fname == "")
|
||||
throw errorEx("");
|
||||
fp = fopen(QString2filename(fname), "w");
|
||||
if (fp == NULL) {
|
||||
throw errorEx(tr("Error opening file: '%1': %2").
|
||||
arg(fname).arg(strerror(errno)));
|
||||
}
|
||||
PEM_write_DHparams(fp, dh);
|
||||
openssl_error();
|
||||
} catch (errorEx &err) {
|
||||
Error(err);
|
||||
}
|
||||
if (dh)
|
||||
DH_free(dh);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (bar)
|
||||
delete bar;
|
||||
}
|
||||
|
||||
|
||||
@ -108,6 +108,7 @@ class MainWindow: public QMainWindow, public Ui::MainWindow
|
||||
void changePin(bool so=false);
|
||||
void changeSoPin();
|
||||
void initPin();
|
||||
void generateDHparam();
|
||||
|
||||
void on_keyView_doubleClicked(const QModelIndex &m);
|
||||
void on_reqView_doubleClicked(const QModelIndex &m);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user