diff --git a/lib/db_key.cpp b/lib/db_key.cpp index 05e0664d..25fd7755 100644 --- a/lib/db_key.cpp +++ b/lib/db_key.cpp @@ -185,9 +185,9 @@ void db_key::newItem() status->removeWidget(bar); delete bar; status->showMessage(m); - insert(nkey); - - emit keyDone(nkey); + nkey = (pki_key*)insert(nkey); + printf("Emit KeyDone\n"); + emit keyDone(nkey->getIntNameWithType()); } delete dlg; } diff --git a/lib/db_key.h b/lib/db_key.h index bd6fb3aa..e418363b 100644 --- a/lib/db_key.h +++ b/lib/db_key.h @@ -85,7 +85,7 @@ class db_key: public db_base signals: void delKey(pki_key *delkey); void newKey(pki_key *newkey); - void keyDone(pki_key *newkey); + void keyDone(QString name); }; #endif diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index 93560e31..3fd6d0a1 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -51,6 +51,7 @@ #include "pki_pkcs12.h" #include "pki_pkcs7.h" #include "widgets/CertDetail.h" +#include "widgets/CertExtend.h" #include "widgets/ExportCert.h" #include "ui/TrustState.h" #include @@ -747,39 +748,30 @@ void db_x509::writePKCS7(pki_x509 *cert, QString s, int type) QList list; pki_base *cer; try { - p7 = new pki_pkcs7(""); - if ( type == P7_CHAIN ) { - while (cert != NULL) { + p7 = new pki_pkcs7(""); + if ( type == P7_CHAIN ) { + while (cert != NULL) { + p7->addCert(cert); + if (cert->getSigner() == cert) + cert = NULL; + else + cert = cert->getSigner(); + } + } + if ( type == P7_ONLY ) { p7->addCert(cert); - if (cert->getSigner() == cert) cert = NULL; - else cert = cert->getSigner(); } - } - if ( type == P7_ONLY ) { - p7->addCert(cert); - } -#if 0 - if (type == P7_TRUSTED) { - list = db->getContainer(); - if (!list.isEmpty()) { - for ( cer = list.first(); cer != NULL; cer = list.next() ) { - if (((pki_x509*)cer)->getTrust() == 2) - p7->addCert((pki_x509 *)cer); + if (type == P7_TRUSTED) { + FOR_ALL_pki(cer, pki_x509) { + if (cer->getTrust() == 2) + p7->addCert(cer); } } - } - if (type == P7_ALL) { - list = db->getContainer(); - if (!list.isEmpty()) { - for ( cer = list.first(); cer != NULL; cer = list.next() ) { + if (type == P7_ALL) { + FOR_ALL_pki(cer, pki_x509) p7->addCert((pki_x509 *)cer); - } } - } -#else -#warning P7_TRUSTED P7_ALL -#endif - p7->writeP7(s, false); + p7->writeP7(s, false); } catch (errorEx &err) { MainWindow::Error(err); @@ -916,3 +908,55 @@ void db_x509::setTrust() delete dlg; } +void db_x509::extendCert() +{ + pki_x509 *oldcert = NULL, *signer = NULL, *newcert =NULL; + pki_key *signkey = NULL; + a1time time; + a1int serial; + try { + CertExtend *dlg = new CertExtend(mainwin); + if (!dlg->exec()) { + delete dlg; + return; + } + oldcert = static_cast(currentIdx.internalPointer()); + if (!oldcert || + !(signer = oldcert->getSigner()) || + !(signkey = signer->getRefKey()) || + signkey->isPubKey()) + return; + newcert = new pki_x509(oldcert); + serial = signer->getIncCaSerial(); + + // get signers own serial to avoid having the same + if (serial == signer->getSerial()) { + serial = signer->getIncCaSerial(); // just take the next one + } + updatePKI(signer); + + // change date and serial + newcert->setSerial(serial); + newcert->setNotBefore(dlg->notBefore->getDate()); + newcert->setNotAfter(dlg->notAfter->getDate()); + + if (newcert->resetTimes(signer) > 0) { + if (QMessageBox::information(mainwin, tr(XCA_TITLE), + tr("The validity times for the certificate need to get adjusted to not exceed those of the signer"), + tr("Continue creation"), tr("Abort") + )) + throw errorEx(""); + } + + // and finally sign the request + newcert->sign(signkey, oldcert->getDigest()); + insert(newcert); + delete dlg; + } + catch (errorEx &err) { + MainWindow::Error(err); + if (newcert) + delete newcert; + } +} + diff --git a/lib/db_x509.h b/lib/db_x509.h index 04f4a2b9..59ab6ae1 100644 --- a/lib/db_x509.h +++ b/lib/db_x509.h @@ -102,6 +102,7 @@ class db_x509: public db_x509super void showItem(); void setMultiTrust(QAbstractItemView* view); void setTrust(); + void extendCert(); signals: void connNewX509(NewX509 *dlg); }; diff --git a/lib/db_x509req.cpp b/lib/db_x509req.cpp index ab05c0e8..a4f6db78 100644 --- a/lib/db_x509req.cpp +++ b/lib/db_x509req.cpp @@ -128,15 +128,12 @@ void db_x509req::load(void) load_default(l); } -void db_x509req::showItem() +void db_x509req::showItem(pki_x509req *req) { - if (!currentIdx.isValid()) + if (!req) return; - pki_x509req *req = static_cast(currentIdx.internalPointer()); ReqDetail *dlg; - - printf("ShowItem req\n"); dlg = new ReqDetail(mainwin); if (dlg) { dlg->setReq(req); @@ -145,6 +142,21 @@ void db_x509req::showItem() } } +void db_x509req::showItem() +{ + if (!currentIdx.isValid()) + return; + + pki_x509req *req = static_cast(currentIdx.internalPointer()); + showItem(req); +} + +void db_x509req::showItem(QString descr) +{ + pki_x509req *req = (pki_x509req*)getByName(descr); + showItem(req); +} + void db_x509req::store(bool pem) { if (!currentIdx.isValid()) diff --git a/lib/db_x509req.h b/lib/db_x509req.h index 7986d9eb..181b6dcf 100644 --- a/lib/db_x509req.h +++ b/lib/db_x509req.h @@ -72,6 +72,8 @@ class db_x509req: public db_x509super void store_der() {store(false);} void load(void); void showItem(); + void showItem(QString descr); + void showItem(pki_x509req *req); signals: void connNewX509(NewX509 *dlg); }; diff --git a/lib/pki_base.cpp b/lib/pki_base.cpp index 0d31a502..aebafaec 100644 --- a/lib/pki_base.cpp +++ b/lib/pki_base.cpp @@ -76,17 +76,6 @@ enum pki_type pki_base::getType() return pkiType; } -#if 0 -// FIXME: remove if unneeded -void pki_base::fload(const QString fname) -{ -} - -void pki_base::writeDefault(const QString fname) -{ -} -#endif - pki_base::~pki_base(void) { pki_counter--; @@ -164,18 +153,6 @@ QString pki_base::rmslashdot(const QString &s) return s.mid(l+1,r-l-1); } -#if 0 -// FIXME: remove if unneeded -void pki_base::updateView() -{ - if (pointer == NULL) return; -#ifdef qt3 - pointer->setRenameEnabled(0,true); -#endif - pointer->setText(0, getIntName()); -} -#endif - pki_base *pki_base::getParent() { return parent; diff --git a/ui/NewX509.ui b/ui/NewX509.ui index d21f4910..78ae188f 100644 --- a/ui/NewX509.ui +++ b/ui/NewX509.ui @@ -145,7 +145,7 @@ Of course you need the private key of the CSR if you want to create a self-signe - + Show request @@ -916,7 +916,7 @@ URI:http://www.my.com/my.crl, URI:http://www.oth.com/my.crl - can be altered by the file "aia.txt" + can be altered by the file "aia.txt" @@ -955,7 +955,7 @@ caIssuers;URI:http://my.ca/ca.html DNS: IP: URI: email: RID: - The subject alternative name extension allows various literal values to be used. These include "email" (an email address) , "URI" a uniform resource indicator, "DNS" (a DNS domain name) , RID (a registered ID: OBJECT IDENTIFIER) and IP (an IP address). + The subject alternative name extension allows various literal values to be used. These include "email" (an email address) , "URI" a uniform resource indicator, "DNS" (a DNS domain name) , RID (a registered ID: OBJECT IDENTIFIER) and IP (an IP address). Examples: email:my@other.address, IP: 1.1.1.1 , URI:http://my.url.here/ email:my@other.address, RID:1.2.3.4, DNS: ns.server.tld @@ -989,7 +989,7 @@ email:my@other.address, RID:1.2.3.4, DNS: ns.server.tld DNS: IP: URI: email: RID: - The issuer alternative name extension allows various literal values to be used. These include "email" (an email address) , "URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a registered ID: OBJECT IDENTIFIER) and IP (an IP address). + The issuer alternative name extension allows various literal values to be used. These include "email" (an email address) , "URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a registered ID: OBJECT IDENTIFIER) and IP (an IP address). Examples: email:my@other.address, IP: 1.1.1.1 , URI:http://my.url.here/ email:my@other.address, RID:1.2.3.4, DNS: ns.server.tld @@ -1453,8 +1453,8 @@ Example: accept() - 510 - 576 + 485 + 509 96 @@ -1469,8 +1469,8 @@ Example: reject() - 98 - 576 + 86 + 509 179 diff --git a/widgets/CertExtend.h b/widgets/CertExtend.h index 99a92ceb..27067adc 100644 --- a/widgets/CertExtend.h +++ b/widgets/CertExtend.h @@ -52,7 +52,7 @@ class pki_key; -class CertExtend: public QDialog, private Ui::CertExtend +class CertExtend: public QDialog, public Ui::CertExtend { Q_OBJECT diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index 5771b24f..205f2f4c 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -499,9 +499,9 @@ NewX509 *MainWindow::newX509() void MainWindow::connNewX509(NewX509 *nx) { printf("CONNECTING NewX509\n"); - connect( (const QObject *)nx->genKeyBUT, SIGNAL(clicked()), keys, SLOT(newItem()) ); connect( nx, SIGNAL(genKey()), keys, SLOT(newItem()) ); connect( keys, SIGNAL(keyDone(QString)), nx, SLOT(newKeyDone(QString)) ); + connect( nx, SIGNAL(showReq(QString)), reqs, SLOT(showItem(QString))); } void MainWindow::changeView() diff --git a/widgets/NewX509.cpp b/widgets/NewX509.cpp index 3d3dc2ab..0d1174b5 100644 --- a/widgets/NewX509.cpp +++ b/widgets/NewX509.cpp @@ -68,9 +68,10 @@ #include "lib/oid.h" #include "lib/func.h" +#if 0 #define TRACE printf("File: "__FILE__" Func: %s Line: %d\n",__func__, __LINE__); #define TRACE - +#endif int NewX509::name_nid[] = { NID_commonName, NID_countryName, @@ -90,19 +91,13 @@ NewX509::NewX509(QWidget *parent) aia_nid = *MainWindow::aia_nid; QStringList sl; - TRACE setupUi(this); - TRACE sl << "Type" << "Content"; printf("Set Ext DN list\n"); - TRACE extDNlist->setColumnCount(2); - TRACE extDNlist->setHorizontalHeaderLabels(sl); - TRACE setWindowTitle(tr(XCA_TITLE)); - TRACE fixtemp = NULL; nsImg->setPixmap(*MainWindow::nsImg); @@ -111,84 +106,61 @@ NewX509::NewX509(QWidget *parent) QStringList strings; // are there any useable private keys ? - TRACE strings = MainWindow::keys->get0PrivateDesc(); keyList->insertItems(0, strings); - TRACE hashAlgo->setCurrentIndex(2); - TRACE if (!strings.isEmpty()) on_keyList_highlighted(strings[0]); - TRACE // any PKCS#10 requests to be used ? - TRACE strings = MainWindow::reqs->getDesc(); if (strings.isEmpty()) { fromReqCB->setDisabled(true); - TRACE - reqList->setDisabled(true); + fromReqCB->setChecked(false); } else { reqList->insertItems(0, strings); - TRACE } + on_fromReqCB_clicked(); // How about signing certificates ? - TRACE strings = MainWindow::certs->getSignerDesc(); if (strings.isEmpty()) { foreignSignRB->setDisabled(true); - TRACE certList->setDisabled(true); - TRACE - } - else { + } else { certList->insertItems(0, strings); - TRACE } // set dates to now and now + 1 year a1time a; notBefore->setDate(a.now()); - TRACE notAfter->setDate(a.now(60*60*24*365)); - TRACE // settings for the templates .... strings.clear(); - TRACE strings = MainWindow::temps->getDesc(); strings.prepend(tr("Server Template")); strings.prepend(tr("Client Template")); - TRACE strings.prepend(tr("CA Template")); - TRACE strings.prepend(tr("Empty Template")); tempList->insertItems(0, strings); - TRACE // setup Extended keyusage - TRACE for (i=0; i < eku_nid.count(); i++) ekeyUsage->insertItem(0, OBJ_nid2ln(eku_nid[i])); // setup Distinguished Name - TRACE for (i=0; i < dn_nid.count(); i++) extDNobj->insertItem(0, OBJ_nid2ln(dn_nid[i])); // setup Authority Info Access - TRACE for (i=0; i < aia_nid.count(); i++) aiaOid->insertItem(0, OBJ_nid2ln(aia_nid[i])); // init the X509 v3 context - TRACE X509V3_set_ctx(&ext_ctx, NULL , NULL, NULL, NULL, 0); - TRACE X509V3_set_ctx_nodb((&ext_ctx)); - TRACE // setup the list of x509nameEntrys name_ptr[0] = commonName; @@ -201,9 +173,8 @@ NewX509::NewX509(QWidget *parent) // last polish signerChanged(); - TRACE checkAuthKeyId(); - TRACE + toggleOkBut(); pt = none; } @@ -385,20 +356,15 @@ void NewX509::toTemplate(pki_temp *temp) void NewX509::on_fromReqCB_clicked() { - if (fromReqCB->isChecked()) { - reqList->setEnabled(true); - distNameBox->setEnabled(false); - //privKeyBox->setEnabled(false); - //keyIdentBox->setEnabled(false); - //tabWidget->setTabEnabled(1,false); - } - else { - reqList->setEnabled(false); - distNameBox->setEnabled(true); - //privKeyBox->setEnabled(true); - //keyIdentBox->setEnabled(true); - //tabWidget->setTabEnabled(1,true); - } + bool request = fromReqCB->isChecked(); + + reqList->setEnabled(request); + distNameBox->setEnabled( ! request); + privKeyBox->setEnabled( ! request); + copyReqExtCB->setEnabled(request); + showReqBut->setEnabled(request); + //keyIdentBox->setEnabled(false); + //tabWidget->setTabEnabled(1,false); } @@ -410,12 +376,35 @@ void NewX509::on_keyList_highlighted(const QString &keyname) hashAlgo->setDisabled(false); } -void NewX509::dataChangeP2() +void NewX509::toggleOkBut() { - if (description->text() != "" && countryName->text().length() !=1 && - (keyList->count() > 0 || !keyList->isEnabled())){ - } + bool ok = description->text() != "" && + countryName->text().length() !=1 && + (keyList->count() > 0 || !keyList->isEnabled()); + okButton->setEnabled(ok); } + +void NewX509::on_description_textChanged(QString text) +{ + toggleOkBut(); +} + +void NewX509::on_countryName_textChanged(QString text) +{ + toggleOkBut(); +} + +void NewX509::on_showReqBut_clicked() +{ + QString req = reqList->currentText(); + emit showReq(req); +} + +void NewX509::on_genKeyBUT_clicked() +{ + emit genKey(); +} + #if 0 void NewX509::showPage(QWidget *page) { @@ -429,7 +418,7 @@ void NewX509::showPage(QWidget *page) if (keyList->isEnabled() && keyList->count() == 0 ) { emit genKey(); } - dataChangeP2(); + toggleOkBut(); } if (page == page7) { @@ -534,22 +523,7 @@ void NewX509::templateChanged() #endif } -#if 0 -void NewX509::switchExtended() -{ - if ( !appropriate(page1) ) return; - if (changeDefault->isChecked() || !templateBox->isEnabled()) { - setAppropriate(page4, true); - setAppropriate(page5, true); - setAppropriate(page6, true); - } - else { - setAppropriate(page4, false); - setAppropriate(page5, false); - setAppropriate(page6, false); - } -} -#endif + void NewX509::checkAuthKeyId() { bool enabled = false; @@ -576,7 +550,9 @@ void NewX509::newKeyDone(QString name) { keyList->insertItem(0, name); keyList->setCurrentIndex(0); - dataChangeP2(); + on_keyList_highlighted(name); + toggleOkBut(); + printf("NEW KEY DONE\n"); } void NewX509::helpClicked() diff --git a/widgets/NewX509.h b/widgets/NewX509.h index 8c435487..5b103463 100644 --- a/widgets/NewX509.h +++ b/widgets/NewX509.h @@ -129,7 +129,7 @@ class NewX509: public QDialog, public Ui::NewX509 public slots: void on_fromReqCB_clicked(); void on_keyList_highlighted(const QString &keyname); - void dataChangeP2(); + void toggleOkBut(); void newKeyDone(QString name); //void switchExtended(); void templateChanged(); @@ -144,8 +144,13 @@ class NewX509: public QDialog, public Ui::NewX509 void on_editAuthInfAcc_clicked(); void on_foreignSignRB_clicked(); void on_subKey_clicked(); + void on_genKeyBUT_clicked(); + void on_showReqBut_clicked(); + void on_description_textChanged(QString text); + void on_countryName_textChanged(QString); signals: void genKey(); + void showReq(QString req); }; #endif