mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
SF Bug #87: Unable to set default key length
Added a "Remember as default" checkbox to the key input dialog. The default key size is now 2048 for RSA and DSA keys.
This commit is contained in:
parent
8168ca5181
commit
df78e4380e
@ -161,6 +161,11 @@ void db_key::newItem(QString name)
|
||||
delete key;
|
||||
mainwin->Error(err);
|
||||
}
|
||||
if (dlg->rememberDefault->isChecked()) {
|
||||
QString def = dlg->getAsString();
|
||||
if (dlg->setDefault(def) == 0)
|
||||
mainwin->setDefaultKey(def);
|
||||
}
|
||||
status->removeWidget(bar);
|
||||
delete bar;
|
||||
delete dlg;
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>449</width>
|
||||
<height>297</height>
|
||||
<height>320</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -182,6 +182,13 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="rememberDefault">
|
||||
<property name="text">
|
||||
<string>Remember as default</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "lib/db_base.h"
|
||||
#include "lib/func.h"
|
||||
#include "widgets/ImportMulti.h"
|
||||
#include "widgets/NewKey.h"
|
||||
|
||||
int MainWindow::init_database()
|
||||
{
|
||||
@ -145,6 +146,13 @@ int MainWindow::init_database()
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
mydb.first();
|
||||
if (!mydb.find(setting, "defaultkey")) {
|
||||
if ((p = (char *)mydb.load(NULL))) {
|
||||
NewKey::setDefault((QString(p)));
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt));
|
||||
mydb.first();
|
||||
if (!mydb.find(setting, "mw_geometry")) {
|
||||
|
||||
@ -827,6 +827,12 @@ void MainWindow::setPath(QString str)
|
||||
mydb.set((const unsigned char *)CCHAR(str), str.length()+1, 1, setting, "workingdir");
|
||||
}
|
||||
|
||||
void MainWindow::setDefaultKey(QString str)
|
||||
{
|
||||
db mydb(dbfile);
|
||||
mydb.set((const unsigned char *)CCHAR(str), str.length()+1, 1, setting, "defaultkey");
|
||||
}
|
||||
|
||||
void MainWindow::connNewX509(NewX509 *nx)
|
||||
{
|
||||
connect( nx, SIGNAL(genKey(QString)), keys, SLOT(newItem(QString)) );
|
||||
|
||||
@ -100,6 +100,7 @@ class MainWindow: public QMainWindow, public Ui::MainWindow
|
||||
void dropEvent(QDropEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
int open_default_db();
|
||||
void setDefaultKey(QString def);
|
||||
|
||||
public slots:
|
||||
int init_database();
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
struct typelist {
|
||||
const char *name;
|
||||
@ -29,6 +30,10 @@ static const struct typelist typeList[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
int NewKey::defaultType = EVP_PKEY_RSA;
|
||||
int NewKey::defaultEcNid = NID_undef;
|
||||
int NewKey::defaultSize = 2048;
|
||||
|
||||
class keyListItem
|
||||
{
|
||||
protected:
|
||||
@ -71,6 +76,10 @@ class keyListItem
|
||||
{
|
||||
return tl->type;
|
||||
}
|
||||
QString typeName()
|
||||
{
|
||||
return QString(tl->name);
|
||||
}
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(keyListItem);
|
||||
@ -100,6 +109,7 @@ NewKey::NewKey(QWidget *parent, QString name)
|
||||
keytypes << gk;
|
||||
}
|
||||
#ifndef OPENSSL_NO_EC
|
||||
QString ec_default;
|
||||
for (i = 0; i<pki_evp::num_curves; i++) {
|
||||
const char *desc = pki_evp::curves[i].comment;
|
||||
const char *sn = OBJ_nid2sn(pki_evp::curves[i].nid);
|
||||
@ -109,6 +119,8 @@ NewKey::NewKey(QWidget *parent, QString name)
|
||||
if (desc == NULL)
|
||||
desc = "---";
|
||||
QString p = QString(sn) + ": " + desc;
|
||||
if (pki_evp::curves[i].nid == defaultEcNid)
|
||||
ec_default = p;
|
||||
switch (pki_evp::curve_flags[i]) {
|
||||
case CURVE_X962: curve_x962 << p; break;
|
||||
case CURVE_OTHER: curve_other << p; break;
|
||||
@ -117,8 +129,11 @@ NewKey::NewKey(QWidget *parent, QString name)
|
||||
}
|
||||
curveBox->addItems(curve_x962);
|
||||
curveBox->addItems(curve_other);
|
||||
curveBox->setCurrentIndex(curveBox->findText(ec_default));
|
||||
if (curveBox->currentIndex() == -1)
|
||||
curveBox->setCurrentIndex(0);
|
||||
#endif
|
||||
keyLength->setCurrentIndex(0);
|
||||
keyLength->setEditText(QString::number(defaultSize) + " bit");
|
||||
keyDesc->setFocus();
|
||||
if (pkcs11::loaded()) try {
|
||||
pkcs11 p11;
|
||||
@ -138,6 +153,8 @@ NewKey::NewKey(QWidget *parent, QString name)
|
||||
QVariant q;
|
||||
q.setValue(keytypes[i]);
|
||||
keyType->addItem(keytypes[i].printname, q);
|
||||
if (!keytypes[i].card && keytypes[i].type() == defaultType)
|
||||
keyType->setCurrentIndex(i);
|
||||
}
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Create"));
|
||||
}
|
||||
@ -194,3 +211,47 @@ slotid NewKey::getKeyCardSlot()
|
||||
keyListItem k = currentKey(keyType);
|
||||
return k.slot;
|
||||
}
|
||||
|
||||
QString NewKey::getAsString()
|
||||
{
|
||||
keyListItem k = currentKey(keyType);
|
||||
QString data;
|
||||
|
||||
if (k.card)
|
||||
return QString();
|
||||
if (k.type() == EVP_PKEY_EC) {
|
||||
data = OBJ_obj2QString(OBJ_nid2obj(getKeyCurve_nid()), 1);
|
||||
} else {
|
||||
data = QString::number(getKeysize());
|
||||
}
|
||||
return QString("%1:%2").arg(currentKey(keyType).typeName()).arg(data);
|
||||
}
|
||||
|
||||
int NewKey::setDefault(QString def)
|
||||
{
|
||||
int type = -1, size = 0, nid = NID_undef;
|
||||
QStringList sl = def.split(':');
|
||||
|
||||
if (sl.size() != 2)
|
||||
return -1;
|
||||
for (unsigned i=0; i < ARRAY_SIZE(typeList); i++ ) {
|
||||
if (sl[0] == typeList[i].name) {
|
||||
type = typeList[i].type;
|
||||
}
|
||||
}
|
||||
if (type == -1)
|
||||
return -2;
|
||||
if (type == EVP_PKEY_EC) {
|
||||
nid = OBJ_txt2nid(sl[1].toAscii());
|
||||
if (nid == NID_undef)
|
||||
return -3;
|
||||
defaultEcNid = nid;
|
||||
} else {
|
||||
size = sl[1].toInt();
|
||||
if (size <= 0)
|
||||
return -4;
|
||||
defaultSize = size;
|
||||
}
|
||||
defaultType = type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -15,7 +15,10 @@
|
||||
class NewKey: public QDialog, public Ui::NewKey
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
static int defaultType;
|
||||
static int defaultEcNid;
|
||||
static int defaultSize;
|
||||
public:
|
||||
NewKey(QWidget *parent, QString name);
|
||||
int getKeytype();
|
||||
@ -23,6 +26,8 @@ class NewKey: public QDialog, public Ui::NewKey
|
||||
int getKeyCurve_nid();
|
||||
slotid getKeyCardSlot();
|
||||
bool isToken();
|
||||
QString getAsString();
|
||||
static int setDefault(QString def);
|
||||
public slots:
|
||||
void on_keyType_currentIndexChanged(int);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user