Added PKCS12 and PKCS7 import

clicklabel colorized
Database password improvement
This commit is contained in:
Christian 2006-05-20 02:57:58 +02:00
parent 7a0e7cee5d
commit 4e550c4f66
12 changed files with 327 additions and 262 deletions

View File

@ -5,7 +5,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -13,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -34,10 +34,10 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.trolltech.com
*
*
*
*
* http://www.hohnstaedt.de/xca
@ -45,7 +45,7 @@
*
* $Id$
*
*/
*/
#include "db_key.h"
@ -81,7 +81,7 @@ QStringList db_key::getPrivateDesc()
x.clear();
FOR_ALL_pki(pki, pki_key)
if (pki->isPrivKey())
x.append(pki->getIntName());
x.append(pki->getIntName());
return x;
}
@ -91,8 +91,8 @@ QStringList db_key::get0PrivateDesc()
x.clear();
FOR_ALL_pki(pki, pki_key) {
//printf("0Privatre desc: %s: priv:%d, cnt:%d\n", CCHAR(pki->getIntName()), pki->isPrivKey() ,pki->getUcount());
if (pki->isPrivKey() && pki->getUcount() == 0)
x.append(pki->getIntNameWithType());
if (pki->isPrivKey() && pki->getUcount() == 0)
x.append(pki->getIntNameWithType());
}
return x;
}
@ -104,7 +104,7 @@ void db_key::remFromCont(QModelIndex &idx)
emit delKey((pki_key *)pki);
}
void db_key::inToCont(pki_base *pki)
void db_key::inToCont(pki_base *pki)
{
db_base::inToCont(pki);
emit newKey((pki_key *)pki);
@ -123,7 +123,7 @@ pki_base* db_key::insert(pki_base *item)
oldkey->getIntName() +
"'\n" + tr("and is not going to be imported"), "OK");
delete(lkey);
return oldkey;
return oldkey;
}
else {
QMessageBox::information(NULL,tr(XCA_TITLE),
@ -137,7 +137,7 @@ pki_base* db_key::insert(pki_base *item)
}
}
insertPKI(lkey);
return lkey;
}
@ -151,22 +151,22 @@ void db_key::newItem()
ui.setupUi(dlg);
QProgressBar *bar = new QProgressBar();
QStatusBar *status = mainwin->statusBar();
pki_key *nkey = NULL;
QString x;
int keytypes[] = {EVP_PKEY_RSA, EVP_PKEY_DSA };
ui.keyLength->setEditable(true);
ui.keyLength->setEditable(true);
for (int i=0; sizeList[i] != 0; i++ ) {
ui.keyLength->addItem( x.number(sizeList[i]) +" bit");
ui.keyLength->addItem( x.number(sizeList[i]) +" bit");
}
ui.keyLength->setCurrentIndex(1);
ui.keyDesc->setFocus();
ui.image->setPixmap(*MainWindow::keyImg);
if (dlg->exec()) {
db mydb(dbName);
QString ksizes = ui.keyLength->currentText();
ksizes.replace( QRegExp("[^0-9]"), "" );
int ksize = ksizes.toInt();
@ -175,9 +175,9 @@ void db_key::newItem()
if (!QMessageBox::warning(NULL, XCA_TITLE, tr("You are sure to create a key of the size: ")
+QString::number(ksize) + " ?", tr("Cancel"), tr("Create") ))
return;
nkey = new pki_key(ui.keyDesc->text());
QString m = status->currentMessage();
status->clearMessage();
status->addPermanentWidget(bar,1);
@ -186,7 +186,7 @@ void db_key::newItem()
delete bar;
status->showMessage(m);
insert(nkey);
emit keyDone(nkey);
}
delete dlg;
@ -205,8 +205,6 @@ void db_key::showItem()
pki_key *key = static_cast<pki_key*>(currentIdx.internalPointer());
KeyDetail *dlg;
printf("Key detail: %p\n", key);
dlg = new KeyDetail(mainwin);
if (dlg) {
dlg->setKey(key);
@ -218,7 +216,7 @@ void db_key::showItem()
void db_key::showContextMenu(QContextMenuEvent *e, const QModelIndex &index)
{
QMenu *menu = new QMenu(mainwin);
currentIdx = index;
menu->addAction(tr("New Key"), this, SLOT(newItem()));
@ -240,18 +238,18 @@ void db_key::store()
{
bool PEM = false;
const EVP_CIPHER *enc = NULL;
if (!currentIdx.isValid())
return;
pki_key *targetKey = static_cast<pki_key*>(currentIdx.internalPointer());
QString fn = targetKey->getIntName() + ".pem";
ExportKey *dlg = new ExportKey(mainwin, fn,
targetKey->isPubKey(), mainwin->getPath() );
dlg->image->setPixmap(*MainWindow::keyImg);
if (!dlg->exec()) {
delete dlg;
return;
@ -276,9 +274,39 @@ void db_key::store()
}
}
catch (errorEx &err) {
MainWindow::Error(err);
mainwin->Error(err);
}
delete dlg;
}
void db_key::setOwnPass()
{
try {
__setOwnPass(1);
}
catch (errorEx &err) {
mainwin->Error(err);
}
}
void db_key::resetOwnPass()
{
try {
__setOwnPass(0);
}
catch (errorEx &err) {
mainwin->Error(err);
}
}
void db_key::__setOwnPass(int x)
{
pki_key *targetKey;
if (!currentIdx.isValid())
return;
targetKey = static_cast<pki_key*>(currentIdx.internalPointer());
targetKey->setOwnPass(x);
updatePKI(targetKey);
}

View File

@ -4,7 +4,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -12,7 +12,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -33,10 +33,10 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.trolltech.com
*
*
*
*
* http://www.hohnstaedt.de/xca
@ -44,7 +44,7 @@
*
* $Id$
*
*/
*/
#ifndef DB_KEY_H
#define DB_KEY_H
@ -61,7 +61,8 @@ class QContextMenuEvent;
class db_key: public db_base
{
Q_OBJECT
private:
void __setOwnPass(int x);
public:
db_key(QString db, MainWindow *mw);
pki_base *newPKI();
@ -72,12 +73,14 @@ class db_key: public db_base
pki_base* insert(pki_base *item);
void writeAll();
void showContextMenu(QContextMenuEvent * e, const QModelIndex &index);
public slots:
void newItem(void);
void load(void);
void store();
void showItem();
void setOwnPass();
void resetOwnPass();
signals:
void delKey(pki_key *delkey);

View File

@ -331,12 +331,26 @@ void db_x509::load(void)
load_default(c);
}
void db_x509::loadPKCS12()
{
load_pkcs12 l;
load_default(l);
}
void db_x509::loadPKCS7()
{
load_pkcs7 l;
load_default(l);
}
void db_x509::newItem()
{
NewX509 *dlg = new NewX509(mainwin);
//emit connNewX509(dlg);
dlg->setCert();
//dlg->defineSigner((pki_x509*)getSelected());
pki_x509 *sigcert = static_cast<pki_x509*>(currentIdx.internalPointer());
dlg->defineSigner((pki_x509*)sigcert);
if (dlg->exec()) {
newCert(dlg);
}

View File

@ -91,6 +91,8 @@ class db_x509: public db_x509super
void writePKCS7(pki_x509 *cert, QString s, int type);
void showContextMenu(QContextMenuEvent *e, const QModelIndex &index);
void inToCont(pki_base *pki);
void loadPKCS12();
void loadPKCS7();
public slots:
void load(void);

View File

@ -4,7 +4,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -12,7 +12,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -33,10 +33,10 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.trolltech.com
*
*
*
*
* http://www.hohnstaedt.de/xca
@ -44,7 +44,7 @@
*
* $Id$
*
*/
*/
#include "db_x509super.h"

View File

@ -5,7 +5,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -13,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -34,17 +34,17 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.trolltech.com
*
*
*
* http://www.hohnstaedt.de/xca
* email: christian@hohnstaedt.de
*
* $Id$
*
*/
*/
#include "load_obj.h"
@ -65,7 +65,7 @@ load_base::load_base()
pki_base * load_base::loadItem(QString s)
{
return NULL;
}
}
load_base::~load_base()
{
@ -78,7 +78,7 @@ load_key::load_key()
filter.prepend( "PKCS#8 Keys ( *.p8 *.pk8 )");
filter.prepend( "PKI Keys ( *.pem *.der *.key )");
caption = QObject::tr("Import RSA key");
}
}
pki_base * load_key::loadItem(QString s)
{
@ -94,7 +94,7 @@ load_req::load_req()
filter.prepend( QObject::tr("Netscape Request ( *.spkac *.spc )"));
filter.prepend( QObject::tr("PKCS#10 CSR ( *.pem *.der *.csr )"));
caption = QObject::tr("Import Request");
}
}
pki_base * load_req::loadItem(QString s)
{
@ -115,7 +115,7 @@ load_cert::load_cert()
{
filter.prepend(QObject::tr("Certificates ( *.pem *.der *.crt *.cer )"));
caption = QObject::tr("Import X.509 Certificate");
}
}
pki_base * load_cert::loadItem(QString s)
{
@ -136,7 +136,7 @@ load_pkcs7::load_pkcs7()
{
filter.prepend(QObject::tr("PKCS#7 data ( *.p7s *.p7m *.p7b )"));
caption = QObject::tr("Import PKCS#7 Certificates");
}
}
pki_base * load_pkcs7::loadItem(QString s)
{
@ -157,7 +157,7 @@ load_pkcs12::load_pkcs12()
{
filter.prepend(QObject::tr("PKCS#12 Certificates ( *.p12 *.pfx )"));
caption = QObject::tr("Import PKCS#12 Private Certificate");
}
}
pki_base * load_pkcs12::loadItem(QString s)
{
@ -171,7 +171,7 @@ load_temp::load_temp()
{
filter.prepend(QObject::tr("XCA templates ( *.xca )"));
caption = QObject::tr("Import XCA Templates");
}
}
pki_base * load_temp::loadItem(QString s)
{
@ -192,7 +192,7 @@ load_crl::load_crl()
{
filter.prepend(QObject::tr("Revocation lists ( *.pem *.crl )"));
caption = QObject::tr("Import Certificate Revocation List");
}
}
pki_base * load_crl::loadItem(QString s)
{
@ -213,4 +213,4 @@ load_db::load_db()
{
filter.prepend(QObject::tr("XCA Databases ( *.db )"));
caption = QObject::tr("Open XCA Database");
}
}

View File

@ -5,7 +5,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -13,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -34,10 +34,10 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.trolltech.com
*
*
*
*
* http://www.hohnstaedt.de/xca
@ -45,7 +45,7 @@
*
* $Id$
*
*/
*/
#include "pki_key.h"
@ -130,10 +130,10 @@ void pki_key::setOwnPass(int x)
EVP_PKEY *pk;
if (x) x=1;
if (ownPass == x) return;
pk = decryptKey();
if (pk == NULL) return;
EVP_PKEY_free(key);
key = pk;
ownPass = x;
@ -144,31 +144,31 @@ void pki_key::generate(int bits, int type, QProgressBar *progress)
{
RSA *rsakey = NULL;
DSA *dsakey = NULL;
progress->setMinimum(0);
progress->setMaximum(100);
progress->setValue(50);
progress->setValue(50);
if (type == EVP_PKEY_RSA) {
rsakey = RSA_generate_key(bits, 0x10001, &incProgress, progress);
if (rsakey) EVP_PKEY_set1_RSA(key, rsakey);
} else if (type == EVP_PKEY_DSA) {
progress->setMaximum(500);
dsakey = DSA_generate_parameters(bits,NULL,0,NULL,NULL,&incProgress, progress);
dsakey = DSA_generate_parameters(bits,NULL,0,NULL,NULL,&incProgress, progress);
DSA_generate_key(dsakey);
if(dsakey) EVP_PKEY_set1_DSA(key,dsakey);
}
openssl_error();
encryptKey();
printf("encryption DONE\n");
printf("encryption DONE\n");
}
pki_key::pki_key(const pki_key *pk)
pki_key::pki_key(const pki_key *pk)
:pki_base(pk->desc)
{
init();
openssl_error();
openssl_error();
if (pk == NULL) return;
printf("EVP_PKEY_COPY (no error)\n");
if (pk->key->type == EVP_PKEY_RSA)
@ -184,43 +184,43 @@ pki_key::pki_key(const pki_key *pk)
if (key->type == EVP_PKEY_DSA) {
key->pkey.dsa=((DSA *)ASN1_dup( (int(*)())i2d_DSAPrivateKey, (char *(*)())d2i_DSAPrivateKey,(char *)pk->key->pkey.dsa));
}
#endif
#endif
openssl_error();
encryptKey();
}
pki_key::pki_key(const QString name, int type )
:pki_base(name)
{
{
init(type);
openssl_error();
}
}
pki_key::pki_key(EVP_PKEY *pkey)
:pki_base()
{
{
init();
if (key) {
EVP_PKEY_free(key);
}
key = pkey;
}
}
void pki_key::fload(const QString fname)
{
{
pass_info p(XCA_TITLE, qApp->translate("MainWindow", "Please enter the password to decrypt the private key.")
+ "\n'" + fname + "'");
pem_password_cb *cb = MainWindow::passRead;
FILE *fp = fopen(CCHAR(fname), "r");
EVP_PKEY *pkey = NULL;
bool priv = true;
if (fp != NULL) {
pkey = PEM_read_PrivateKey(fp, NULL, cb, &p);
if (!pkey) {
ign_openssl_error();
rewind(fp);
pkey = d2i_PrivateKey_fp(fp, NULL);
pkey = d2i_PrivateKey_fp(fp, NULL);
}
if (!pkey) {
ign_openssl_error();
@ -242,11 +242,11 @@ void pki_key::fload(const QString fname)
encryptKey();
setIntName(rmslashdot(fname));
}
openssl_error();
} else
fopen_error(fname);
fclose(fp);
}
@ -266,14 +266,14 @@ void pki_key::fromData(const unsigned char *p, db_header_t *head )
type = db::intFromData(&p1);
ownPass = db::intFromData(&p1);
D2I_CLASHT(d2i_PublicKey, type, &key, &p1, size - (2*sizeof(int)));
openssl_error();
openssl_error();
encKey_len = size - (p1-p);
encKey_len = size - (p1-p);
if (encKey_len) {
encKey = (unsigned char *)OPENSSL_malloc(encKey_len);
memcpy(encKey, p1 ,encKey_len);
}
}
#if 0
void pki_key::oldFromData(const unsigned char *p, int size )
@ -334,38 +334,41 @@ EVP_PKEY *pki_key::decryptKey()
int outl, decsize;
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char ckey[EVP_MAX_KEY_LENGTH];
EVP_PKEY *tmpkey;
EVP_CIPHER_CTX ctx;
const EVP_CIPHER *cipher = EVP_des_ede3_cbc();
char ownPassBuf[MAX_PASS_LENGTH];
/* This key has its own password */
if (ownPass == 1) {
pass_info pi(XCA_TITLE, qApp->translate("MainWindow", "Please enter the password to decrypt the private key: '") + getIntName() + "'");
MainWindow::passRead(ownPassBuf, MAX_PASS_LENGTH, 0, &pi);
}
else {
int retlen = 0;
pass_info p(XCA_TITLE, qApp->translate("MainWindow",
"Please enter the default password for decrypting keys"));
while (strlen(passwd) == 0 && retlen == 0) {
retlen = MainWindow::passRead(passwd, MAX_PASS_LENGTH, 0, &p);
if (strlen(passwd) != 0)
memcpy(ownPassBuf, passwd, MAX_PASS_LENGTH);
else {
int retlen = 0;
pass_info p(XCA_TITLE, qApp->translate("MainWindow",
"Please enter the default password"));
while (strlen(passwd) == 0 && retlen == 0) {
retlen = MainWindow::passRead(passwd, MAX_PASS_LENGTH, 0, &p);
}
}
memcpy(ownPassBuf, passwd, MAX_PASS_LENGTH);
}
p = (unsigned char *)OPENSSL_malloc(encKey_len);
openssl_error();
p1 = p;
memset(iv, 0, EVP_MAX_IV_LENGTH);
memcpy(iv, encKey, 8); /* recover the iv */
/* generate the key */
EVP_BytesToKey(cipher, EVP_sha1(), iv, (unsigned char *)ownPassBuf,
strlen(ownPassBuf), 1, ckey,NULL);
/* we use sha1 as message digest,
* because an md5 version of the password is
/* we use sha1 as message digest,
* because an md5 version of the password is
* stored in the database...
*/
EVP_CIPHER_CTX_init (&ctx);
@ -383,11 +386,11 @@ EVP_PKEY *pki_key::decryptKey()
return tmpkey;
}
unsigned char *pki_key::toData(int *size)
unsigned char *pki_key::toData(int *size)
{
unsigned char *p, *p1;
int pubsize;
pubsize = i2d_PublicKey(key, NULL);
*size = pubsize + encKey_len + (2*sizeof(int));
p = (unsigned char *)OPENSSL_malloc(*size);
@ -400,12 +403,12 @@ unsigned char *pki_key::toData(int *size)
if (encKey_len) {
memcpy(p1, encKey, encKey_len);
}
printf("To data: pubsize=%d, encKey_len: %d, *size=%d\n",
printf("To data: pubsize=%d, encKey_len: %d, *size=%d\n",
pubsize, encKey_len, *size);
return p;
}
void pki_key::encryptKey()
void pki_key::encryptKey()
{
int outl, keylen;
EVP_PKEY *pkey1 = NULL;
@ -432,15 +435,15 @@ void pki_key::encryptKey()
}
memcpy(ownPassBuf, passwd, MAX_PASS_LENGTH);
}
/* Prepare Encryption */
memset(iv, 0, EVP_MAX_IV_LENGTH);
RAND_pseudo_bytes(iv,8); /* Generate a salt */
EVP_BytesToKey(cipher, EVP_sha1(), iv, (unsigned char *)ownPassBuf,
strlen(ownPassBuf), 1, ckey, NULL);
strlen(ownPassBuf), 1, ckey, NULL);
EVP_CIPHER_CTX_init (&ctx);
openssl_error();
if (encKey)
if (encKey)
OPENSSL_free(encKey);
encKey_len = 0;
@ -453,12 +456,12 @@ void pki_key::encryptKey()
memcpy(encKey, iv, 8); /* store the iv */
/* convert rsa/dsa to Pubkey */
i2d_PublicKey(key, &punenc);
punenc = punenc1;
punenc = punenc1;
D2I_CLASHT(d2i_PublicKey, key->type, &pkey1, &punencc, keylen);
openssl_error();
i2d_PrivateKey(key, &punenc);
punenc = punenc1;
/*
punenc = punenc1;
/*
* Now DER version of privkey is in punenc, pubkey is in pkey1
* and privkey is still in key
*/
@ -476,14 +479,14 @@ void pki_key::encryptKey()
/* wipe out the memory */
memset(punenc, 0, keylen);
OPENSSL_free(punenc);
openssl_error();
openssl_error();
EVP_PKEY_free(key);
key = pkey1;
openssl_error();
//CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF);
printf("Encrypt: encKey_len=%d\n", encKey_len);
return;
}
@ -507,7 +510,7 @@ void pki_key::writePKCS8(const QString fname, pem_password_cb *cb)
if (fp != NULL) {
if (key){
pkey = decryptKey();
PEM_write_PKCS8PrivateKey_nid(fp, pkey,
PEM_write_PKCS8PrivateKey_nid(fp, pkey,
NID_pbeWithMD5AndDES_CBC, NULL, 0, cb, &p);
EVP_PKEY_free(pkey);
openssl_error();
@ -529,7 +532,7 @@ void pki_key::writeDefault(const QString fname)
EVP_des_ede3_cbc(), mycb, true);
}
void pki_key::writeKey(const QString fname, const EVP_CIPHER *enc,
void pki_key::writeKey(const QString fname, const EVP_CIPHER *enc,
pem_password_cb *cb, bool PEM)
{
EVP_PKEY *pkey;
@ -551,7 +554,7 @@ void pki_key::writeKey(const QString fname, const EVP_CIPHER *enc,
i2d_PrivateKey_fp(fp, pkey);
}
EVP_PKEY_free(pkey);
openssl_error();
openssl_error();
}
fclose(fp);
}
@ -631,7 +634,7 @@ bool pki_key::compare(pki_base *ref)
if (kref==NULL || kref->key==NULL || kref->key->pkey.rsa->n==NULL)
return false;
if (key == NULL || key->pkey.rsa->n == NULL)
return false;
return false;
if (
BN_cmp(key->pkey.rsa->n, kref->key->pkey.rsa->n) ||
BN_cmp(key->pkey.rsa->e, kref->key->pkey.rsa->e)
@ -643,15 +646,15 @@ bool pki_key::compare(pki_base *ref)
if(kref==NULL || kref->key==NULL || kref->key->pkey.dsa->pub_key==NULL)
return false;
if(key==NULL || key->pkey.dsa->pub_key==NULL)
return false;
return false;
if(BN_cmp(key->pkey.dsa->pub_key,kref->key->pkey.dsa->pub_key)){
openssl_error();
return false;
}
}
}
openssl_error();
return true;
}
}
bool pki_key::isPubKey()
@ -678,7 +681,7 @@ int pki_key::verify()
openssl_error();
return veri;
}
int pki_key::getType()
{
return key->type;
@ -687,13 +690,11 @@ int pki_key::getType()
int pki_key::incUcount()
{
ucount++;
// updateView();
return ucount;
}
int pki_key::decUcount()
{
ucount--;
// updateView();
return ucount;
}
@ -710,29 +711,7 @@ const EVP_MD *pki_key::getDefaultMD(){
default: md = NULL; break;
}
return md;
}
#if 0
void pki_key::updateView()
{
QString type_str = "";
pki_base::updateView();
int pixnum = 0;
if (!pointer) return;
if (isPubKey()) pixnum += 1;
switch (key->type) {
case EVP_PKEY_RSA: type_str = "RSA"; break;
case EVP_PKEY_DSA: type_str = "DSA"; break;
default: type_str = "???"; break;
}
pointer->setPixmap(0, *icon[pixnum]);
pointer->setText(1, length());
pointer->setText(2, QString::number(getUcount()));
pointer->setText(3, type_str);
}
#endif
QVariant pki_key::column_data(int col)
{

View File

@ -351,13 +351,6 @@
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="but_cancel" >
<property name="text" >
<string>&amp;Cancel</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
@ -368,32 +361,47 @@
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
<width>81</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="but_ok" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>&amp;OK</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
<widget class="QWidget" name="" />
</widget>
<pixmapfunction></pixmapfunction>
<customwidgets>
<customwidget>
<class>ClickLabel</class>
<extends>QWidget</extends>
<header>widgets/clicklabel.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>DistName</class>
<extends></extends>
@ -401,6 +409,13 @@
<container>1</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>ClickLabel</class>
<extends>QWidget</extends>
<header>widgets/clicklabel.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@ -5,7 +5,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -13,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -34,25 +34,26 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.trolltech.com
*
*
*
* http://www.hohnstaedt.de/xca
* email: christian@hohnstaedt.de
*
* $Id$
* $Id$
*
*/
*/
#include "MainWindow.h"
#include <Qt/qdir.h>
#include <Qt/qstatusbar.h>
void MainWindow::init_database() {
void MainWindow::init_database()
{
initPass();
fprintf(stderr, "Opening database: %s\n", CCHAR(dbfile));
keys = new db_key(dbfile, this);
reqs = new db_x509req(dbfile, this);
@ -65,13 +66,14 @@ void MainWindow::init_database() {
crls = new db_crl(dbenv, dbfile, global_tid, crlList);
reqs->setKeyDb(keys);
certs->setKeyDb(keys);
keyList->setDB(keys);
reqList->setDB(reqs);
certList->setDB(certs);
tempList->setDB(temps);
crlList->setDB(crls);
#endif
connect( keys, SIGNAL(newKey(pki_key *)),
certs, SLOT(newKey(pki_key *)) );
connect( keys, SIGNAL(delKey(pki_key *)),
@ -80,17 +82,14 @@ void MainWindow::init_database() {
reqs, SLOT(newKey(pki_key *)) );
connect( keys, SIGNAL(delKey(pki_key *)),
reqs, SLOT(delKey(pki_key *)) );
// connect( crls, SIGNAL(updateCertView()),
// certList, SLOT(updateView()) );
#endif
statusBar()->showMessage(tr("Database") + ":" + dbfile);
keyView->setModel(keys);
reqView->setModel(reqs);
certView->setModel(certs);
tempView->setModel(temps);
crlView->setModel(crls);
connect( certs, SIGNAL(connNewX509(NewX509 *)), this,
SLOT(connNewX509(NewX509 *)) );
connect( reqs, SIGNAL(connNewX509(NewX509 *)), this,
@ -100,7 +99,7 @@ void MainWindow::init_database() {
void MainWindow::dump_database()
{
QString dirname;
QFileDialog *dlg = new QFileDialog(this);
dlg->setWindowTitle(tr("Dump to directory"));
dlg->setFileMode(QFileDialog::AnyFile);
@ -108,10 +107,10 @@ void MainWindow::dump_database()
dirname = dlg->selectedFiles()[0];
}
delete dlg;
if (dirname.isEmpty())
return;
QDir d(dirname);
if ( ! d.exists() && !d.mkdir(dirname)) {
errorEx err("Could not create '" + dirname + "'");
@ -130,8 +129,8 @@ void MainWindow::dump_database()
MainWindow::Error(err);
}
}
void MainWindow::close_database()
{
delete(crls);
@ -147,7 +146,7 @@ void MainWindow::close_database()
temps = NULL;
keys = NULL;
settings = NULL;
db mydb(dbfile);
mydb.shrink( DBFLAG_OUTDATED | DBFLAG_DELETED );
}
@ -181,9 +180,14 @@ void MainWindow::on_BNexportKey_clicked(void)
void MainWindow::on_keyView_doubleClicked(QModelIndex &m)
{
printf("Key View double clicked\n");
if (keys)
if (keys)
keys->showItem();
}
void MainWindow::on_BNimportPFX_clicked(void)
{
if(certs)
certs->loadPKCS12();
}
/* Certificate request buttons */
void MainWindow::on_BNnewReq_clicked(void)
{
@ -238,6 +242,18 @@ void MainWindow::on_BNexportCert_clicked(void)
certs->storeSelectedItems(certView);
}
void MainWindow::on_BNimportPKCS12_clicked(void)
{
if(certs)
certs->loadPKCS12();
}
void MainWindow::on_BNimportPKCS7_clicked(void)
{
if(certs)
certs->loadPKCS7();
}
/* Template buttons */
void MainWindow::on_BNdeleteTemp_clicked(void)
{

View File

@ -5,7 +5,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -13,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -34,23 +34,23 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.trolltech.com
*
*
*
*
* http://www.hohnstaedt.de/xca
* email: christian@hohnstaedt.de
*
* $Id$
* $Id$
*
*/
*/
//#define MDEBUG
#include "MainWindow.h"
//#include "ImportMulti.h"
#include "ImportMulti.h"
#include <Qt/qapplication.h>
#include <Qt/qclipboard.h>
#include <Qt/qmessagebox.h>
@ -86,11 +86,11 @@ NIDlist *MainWindow::dn_nid = NULL;
NIDlist *MainWindow::aia_nid = NULL;
MainWindow::MainWindow(QWidget *parent )
MainWindow::MainWindow(QWidget *parent )
:QMainWindow(parent)
{
statusBar()->clearMessage();
setWindowTitle(tr(XCA_TITLE));
dbfile = DBFILE;
force_load = 0;
@ -100,11 +100,11 @@ MainWindow::MainWindow(QWidget *parent )
setupUi(this);
init_menu();
init_images();
do_connections();
#ifdef MDEBUG
#ifdef MDEBUG
CRYPTO_malloc_debug_init();
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
fprintf(stderr, "malloc() debugging on.\n");
@ -115,9 +115,9 @@ MainWindow::MainWindow(QWidget *parent )
read_cmdline();
if (exitApp) return;
init_baseDir();
dbfile = baseDir + QDir::separator() + dbfile;
char *p;
db mydb(dbfile);
@ -136,7 +136,7 @@ NIDlist *MainWindow::read_nidlist(QString name)
NIDlist nl;
QString prefix = getPrefix();
name = QDir::separator() + name;
/* first try $HOME/xca/ */
nl = readNIDlist(baseDir + name);
@ -146,10 +146,10 @@ NIDlist *MainWindow::read_nidlist(QString name)
nl = readNIDlist(unix_etc + name);
}
#endif
if (nl.count() == 0) /* look at /usr/(local/)share/xca/ */
nl = readNIDlist(prefix + name);
return new NIDlist(nl);
}
@ -157,7 +157,7 @@ void MainWindow::init_baseDir()
{
static bool done = false;
if (done) return;
fprintf(stderr, "base Dir: %s\n", CCHAR(baseDir));
fprintf(stderr, "base Dir: %s\n", CCHAR(baseDir));
QDir d(baseDir);
if ( ! d.exists() && !d.mkdir(baseDir)) {
QMessageBox::warning(this,tr(XCA_TITLE),
@ -168,7 +168,7 @@ void MainWindow::init_baseDir()
/* read in all our own OIDs */
initOIDs(baseDir);
eku_nid = read_nidlist("eku.txt");
dn_nid = read_nidlist("dn.txt");
aia_nid = read_nidlist("aia.txt");
@ -177,7 +177,7 @@ void MainWindow::init_baseDir()
void MainWindow::do_connections()
{
#if 0
#if 0
connect( keyList, SIGNAL(init_database()), this, SLOT(init_database()));
connect( reqList, SIGNAL(init_database()), this, SLOT(init_database()));
connect( certList, SIGNAL(init_database()), this, SLOT(init_database()));
@ -205,7 +205,7 @@ void MainWindow::do_connections()
connect( BNimportPFX, SIGNAL(clicked()), certList, SLOT(loadPKCS12()));
connect( BNimportPKCS7, SIGNAL(clicked()), certList, SLOT(loadPKCS7()));
connect( BNviewState, SIGNAL(clicked()), this, SLOT(changeView()));
connect( BNemptyTemp, SIGNAL(clicked()), tempList, SLOT(newEmptyTemp()));
connect( BNcaTemp, SIGNAL(clicked()), tempList, SLOT(newCaTemp()));
connect( BNclientTemp, SIGNAL(clicked()), tempList, SLOT(newClientTemp()));
@ -258,8 +258,8 @@ void MainWindow::init_images()
pki_x509::icon[4] = loadImg("revoked.png");
pki_temp::icon = loadImg("template.png");
pki_crl::icon = loadImg("crl.png");
}
}
void MainWindow::read_cmdline()
{
int cnt = 1, opt = 0 , type = 1;
@ -267,17 +267,14 @@ void MainWindow::read_cmdline()
pki_base *item = NULL;
load_base *lb = NULL;
exitApp = 0;
#if 0
ImportMulti *dlgi = NULL;
dlgi = new ImportMulti(this, NULL, true);
#endif
dlgi = new ImportMulti(this);
while (cnt < qApp->argc()) {
arg = qApp->argv()[cnt];
if (arg[0] == '-') { // option
if (lb) delete lb;
opt = 1; lb = NULL; type = 1;
switch (arg[1]) {
#if 0
case 'c' : lb = new load_cert(); break;
case 'r' : lb = new load_req(); break;
case 'k' : lb = new load_key(); break;
@ -285,10 +282,9 @@ void MainWindow::read_cmdline()
case '7' : lb = new load_pkcs7(); break;
case 'l' : lb = new load_crl(); break;
case 't' : lb = new load_temp(); break;
#endif
case 'd' : type = 1; force_load=1; break;
case 'b' : type = 2; break;
case 'v' : fprintf(stderr, XCA_TITLE " Version " VER "\n");
case 'v' : fprintf(stderr, XCA_TITLE " Version " VER "\n");
opt=0; exitApp=1; break;
case 'x' : exitApp = 1; opt=0; break;
default : cmd_help((char*)(QString(tr("no such option: ")) + arg).data() );
@ -305,7 +301,7 @@ void MainWindow::read_cmdline()
item = NULL;
try {
item = lb->loadItem(arg);
//dlgi->addItem(item);
dlgi->addItem(item);
}
catch (errorEx &err) {
if (item) {
@ -321,18 +317,15 @@ void MainWindow::read_cmdline()
default : cmd_help("I'm puzzled: this should not happen ! " );
}
}
cnt++;
}
#if 0
connect( dlgi, SIGNAL(init_database()), this, SLOT(init_database()));
dlgi->execute(1); /* force showing of import dialog */
delete dlgi;
#endif
}
}
MainWindow::~MainWindow()
MainWindow::~MainWindow()
{
close_database();
ERR_free_strings();
@ -344,7 +337,7 @@ MainWindow::~MainWindow()
delete dn_nid;
if (aia_nid)
delete aia_nid;
#ifdef MDEBUG
#ifdef MDEBUG
fprintf(stderr, "Memdebug:\n");
CRYPTO_mem_leaks_fp(stderr);
#endif
@ -352,32 +345,44 @@ MainWindow::~MainWindow()
int MainWindow::initPass()
{
pass_info p(tr("New Password"),
db mydb(dbfile);
char *pass;
pass_info p(tr("New Password"),
tr("Please enter a password, that will be used to encrypt your private keys in the database-file"));
QString passHash;// = settings->getString("pwhash");
#warning Keep a Passwd in DB ??
QString passHash;
if (!mydb.find(setting, "pwhash")) {
if ((pass = (char *)mydb.load(NULL))) {
passHash = pass;
free(pass);
}
}
if (passHash.isEmpty()) {
int keylen = passWrite((char *)pki_key::passwd, 25, 0, &p);
if (keylen == 0) return 0;
if (keylen == 0)
return 0;
pki_key::passwd[keylen]='\0';
//settings->putString( "pwhash", md5passwd(pki_key::passwd) );
passHash = md5passwd(pki_key::passwd);
mydb.set((const unsigned char *)CCHAR(passHash),
passHash.length()+1, 1, setting, "pwhash");
}
else {
int keylen=0;
int keylen=0;
while (md5passwd(pki_key::passwd) != passHash) {
if (keylen !=0) QMessageBox::warning(this,tr(XCA_TITLE),
tr("Password verify error, please try again"));
tr("Password verify error, please try again"));
p.setTitle(tr("Password"));
p.setDescription(tr("Please enter the password for unlocking the database"));
keylen = passRead(pki_key::passwd, 25, 0, &p);
if (keylen == 0) return 0;
if (keylen == 0)
return 0;
pki_key::passwd[keylen]='\0';
}
}
return 1;
}
// Static Password Callback functions
// Static Password Callback functions
int MainWindow::passRead(char *buf, int size, int rwflag, void *userdata)
{
@ -387,14 +392,14 @@ int MainWindow::passRead(char *buf, int size, int rwflag, void *userdata)
QDialog *dlg = new QDialog(qApp->activeWindow());
ui.setupUi(dlg);
if (p != NULL) {
//ui.image->setPixmap( *keyImg );
ui.image->setPixmap( *keyImg );
ui.description->setText(p->getDescription());
dlg->setWindowTitle(p->getTitle());
}
dlg->show();
//dlg->activateWindow();
dlg->activateWindow();
ui.pass->setFocus();
buf[0] = '-'; /* if this remains the dialog was aborted */
if (dlg->exec()) {
QString x = ui.pass->text();
@ -439,7 +444,7 @@ int MainWindow::passWrite(char *buf, int size, int rwflag, void *userdata)
}
}
QString MainWindow::md5passwd(const char *pass)
QString MainWindow::md5passwd(const char *pass, char *md5, int *len)
{
EVP_MD_CTX mdctx;
@ -455,9 +460,13 @@ QString MainWindow::md5passwd(const char *pass)
sprintf(zs, "%02X%c",m[j], (j+1 == (int)n) ?'\0':':');
str += zs;
}
if (md5 && len) {
*len = (*len>n) ? n : *len;
memcpy(md5, m, *len);
}
return str;
}
void MainWindow::Error(errorEx &err)
{
if (err.isEmpty()) return;

View File

@ -5,7 +5,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -13,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -34,18 +34,18 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.trolltech.com
*
*
*
*
* http://www.hohnstaedt.de/xca
* email: christian@hohnstaedt.de
*
* $Id$
* $Id$
*
*/
*/
#ifndef _MAINWINDOW_H
#define _MAINWINDOW_H
@ -71,7 +71,7 @@ class MainWindow: public QMainWindow, private Ui::MainWindow
private:
QString workingdir;
protected:
void init_images();
void read_cmdline();
@ -79,7 +79,7 @@ class MainWindow: public QMainWindow, private Ui::MainWindow
void do_connections();
void init_baseDir();
int force_load;
NIDlist *read_nidlist(QString name);
NIDlist *read_nidlist(QString name);
QLabel *statusLabel;
public:
@ -93,25 +93,26 @@ class MainWindow: public QMainWindow, private Ui::MainWindow
static NIDlist *eku_nid, *dn_nid, *aia_nid;
int exitApp;
QString baseDir, dbfile, dbdir;
MainWindow(QWidget *parent);
virtual ~MainWindow();
virtual ~MainWindow();
void loadSettings();
void saveSettings();
int initPass();
static int passRead(char *buf, int size, int rwflag, void *userdata);
static int passWrite(char *buf, int size, int rwflag, void *userdata);
static NewX509 *newX509();
static QString md5passwd(const char *pass);
static QString md5passwd(const char *pass,
char *md5 = NULL, int *len = NULL);
//static void Qt::SocketError(errorEx &err);
static void Error(errorEx &err);
void cmd_help(const char* msg);
QString getPath();
void setPath(QString path);
bool mkDir(QString dir);
public slots:
public slots:
void init_database();
void load_database();
void load_def_database();
@ -124,25 +125,28 @@ class MainWindow: public QMainWindow, private Ui::MainWindow
private slots:
void on_keyView_doubleClicked(QModelIndex &m);
void on_BNnewKey_clicked(void);
void on_BNdeleteKey_clicked(void);
void on_BNdetailsKey_clicked(void);
void on_BNimportKey_clicked(void);
void on_BNexportKey_clicked(void);
void on_BNimportPFX_clicked(void);
void on_BNnewReq_clicked(void);
void on_BNdeleteReq_clicked(void);
void on_BNdetailsReq_clicked(void);
void on_BNimportReq_clicked(void);
void on_BNexportReq_clicked(void);
void on_BNnewCert_clicked(void);
void on_BNdeleteCert_clicked(void);
void on_BNdetailsCert_clicked(void);
void on_BNimportCert_clicked(void);
void on_BNexportCert_clicked(void);
void on_BNimportPKCS12_clicked(void);
void on_BNimportPKCS7_clicked(void);
void on_BNdeleteTemp_clicked(void);
void on_BNchangeTemp_clicked(void);
void on_BNimportTemp_clicked(void);
@ -151,7 +155,7 @@ class MainWindow: public QMainWindow, private Ui::MainWindow
void on_BNcaTemp_clicked(void);
void on_BNserverTemp_clicked(void);
void on_BNclientTemp_clicked(void);
void on_BNdeleteCrl_clicked(void);
void on_BNdetailsCrl_clicked(void);
void on_BNimportCrl_clicked(void);

View File

@ -5,7 +5,7 @@
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
@ -13,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
@ -34,20 +34,20 @@
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.sleepycat.com
*
* http://www.trolltech.com
*
*
*
*
* http://www.hohnstaedt.de/xca
* email: christian@hohnstaedt.de
*
* $Id$
* $Id$
*
*/
*/
#include "clicklabel.h"
@ -75,15 +75,10 @@ void ClickLabel::mouseDoubleClickEvent ( QMouseEvent * e )
void ClickLabel::setColor(const QColor &col)
{
#if 0
QPalette pal = palette();
QColorGroup cg = pal.active();
cg.setColor( QColorGroup::Foreground, col );
pal.setActive( cg );
pal.setInactive( cg );
pal.setDisabled( cg );
pal.setColor(QPalette::Normal, QPalette::Foreground, col );
pal.setColor(QPalette::Inactive, QPalette::Foreground, col );
setPalette( pal );
#endif
}
void ClickLabel::setRed()