diff --git a/MainWindow.h b/MainWindow.h index b3057e5c..e71eebdc 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -56,7 +56,7 @@ #include "PassRead_UI.h" #include "PassWrite_UI.h" #include "NewKey_UI.h" -#include "NewX509Req_UI.h" +#include "NewX509Req.h" #include "NewX509.h" #include "NewX509_UI.h" #include "Rename_UI.h" @@ -104,6 +104,8 @@ class MainWindow: public MainWindow_UI { Q_OBJECT + protected: + void addStr(string &str, char *add); friend class pki_key; db_x509 *certs; db_x509req *reqs; @@ -166,5 +168,7 @@ class MainWindow: public MainWindow_UI void renameKey(QListViewItem *item, int col, const QString &text); void renameReq(QListViewItem *item, int col, const QString &text); void renameCert(QListViewItem *item, int col, const QString &text); + signals: + void keyDone(QString name); }; #endif diff --git a/MainWindowKeys.cpp b/MainWindowKeys.cpp index 8076865f..78a1650a 100644 --- a/MainWindowKeys.cpp +++ b/MainWindowKeys.cpp @@ -92,6 +92,8 @@ void MainWindow::newKey() sizeList[sel]); progress->cancel(); insertKey(nkey); + x=nkey->getDescription().c_str(); + emit keyDone(x); } } @@ -208,11 +210,7 @@ void MainWindow::insertKey(pki_key *lkey) } } CERR << "after findkey\n"; - if (keys->insertPKI(lkey)) - QMessageBox::information(this,title, - tr("The Key was successfully stored as:\n'") + - QString::fromLatin1(lkey->getDescription().c_str()) + "'", "OK"); - else + if (!keys->insertPKI(lkey)) QMessageBox::warning(this,title, tr("The key could not be stored into the database"), "OK"); diff --git a/MainWindowX509.cpp b/MainWindowX509.cpp index affb060c..3226e9f5 100644 --- a/MainWindowX509.cpp +++ b/MainWindowX509.cpp @@ -59,7 +59,7 @@ void MainWindow::newCert() pki_x509req *req = NULL; pki_key *signkey = NULL, *clientkey = NULL; int serial = 42; // :-) - int i, retval; + int i; NewX509 *dlg = new NewX509(this, NULL, keys, reqs); QStringList strlist = certs->getSignerDesc(); if (strlist.isEmpty()) { @@ -69,14 +69,6 @@ void MainWindow::newCert() else { dlg->certList->insertStringList(strlist); } - CERR <<" Everything created A" << endl; - // preset dialogs with images - for (i=0;i<4;i++) { - CERR <<" Everything created :" << i << endl; - //dlg[i]->image->setPixmap(*certImg); - } - CERR <<" Everything created V" << endl; - i=0; if (!dlg->exec()) return; @@ -105,14 +97,6 @@ void MainWindow::newCert() } // Step 2 - select Signing - /* - if (dlg->fromDataRB->isChecked()) - // if we entered subjectdata, selfsigning is default - dlg->selfSignRB->setChecked(true); - else - // for PKCS#10 signing foreignKey signing is default - dlg->foreignSignRB->setChecked(true); - */ if (dlg->foreignSignRB->isChecked()) { signcert = (pki_x509 *)certs->getSelectedPKI(dlg->certList->currentText().latin1()); if (opensslError(signcert)) return; @@ -158,7 +142,6 @@ void MainWindow::newCert() constraints += pathstr; } cert->addV3ext(NID_basic_constraints, constraints); - CERR << "B-Const:" << constraints << endl; // Subject Key identifier if (dlg->subKey->isChecked()) { string subkey="hash"; @@ -172,24 +155,16 @@ void MainWindow::newCert() CERR << authkey <subAltURL->text().latin1(); - //if (subAlt != "") { - // key usage char *keyusage[] ={"digitalSignature", "nonRepudiation", "keyEncipherment", "dataEncipherment", "keyAgreement", "keyCertSign", "cRLSign", "encipherOnly", "decipherOnly"}; QListBoxItem *item; - i=0; string keyuse, keyuse1; - while ((item = dlg->keyUsage->item(i))) { + for (i=0; (item = dlg->keyUsage->item(i)); i++) { if (item->selected()){ - if (keyuse.length() > 0) keyuse +=", "; - keyuse += keyusage[i]; + addStr(keyuse, keyusage[i]); } - i++; } if (keyuse.length() > 0) { @@ -198,19 +173,16 @@ void MainWindow::newCert() cert->addV3ext(NID_key_usage, keyuse1); CERR << "KeyUsage:" <ekeyUsage->item(i))) { + keyuse=""; keyuse1=""; + for (i=0; (item = dlg->ekeyUsage->item(i)); i++) { if (item->selected()){ - if (keyuse.length() > 0) keyuse += ", "; - keyuse += ekeyusage[i]; + addStr(keyuse, ekeyusage[i]); } - i++; } if (keyuse.length() > 0) { @@ -219,15 +191,77 @@ void MainWindow::newCert() cert->addV3ext(NID_ext_key_usage, keyuse1); CERR << "Extended Key Usage:" <subAltCpMail->isChecked()) { + subAltName = "email:copy"; + } + if ((cont = dlg->subAltURL->text().latin1()) != ""){ + addStr(subAltName,"URI:"); + subAltName+=cont; + } + if ((cont = dlg->subAltDNS->text().latin1()) != ""){ + addStr(subAltName,"DNS:"); + subAltName+=cont; + } + if ((cont = dlg->subAltIP->text().latin1()) != ""){ + addStr(subAltName,"IP:"); + subAltName+=cont; + } + if ((cont = dlg->subAltEMAIL->text().latin1()) != ""){ + addStr(subAltName,"email:"); + subAltName+=cont; + } + if (subAltName.length() > 0) { + cert->addV3ext(NID_subject_alt_name, subAltName); + CERR << "SubAltName:" << subAltName<< endl; + } + + // issuer alternative name + if (dlg->issAltCopy->isChecked()) { + issAltName = "issuer:copy"; + } + if ((cont = dlg->issAltURL->text().latin1()) != ""){ + addStr(issAltName,"URI:"); + issAltName+=cont; + } + if ((cont = dlg->issAltDNS->text().latin1()) != ""){ + addStr(issAltName,"DNS:"); + issAltName+=cont; + } + if ((cont = dlg->issAltIP->text().latin1()) != ""){ + addStr(issAltName,"IP:"); + issAltName+=cont; + } + if ((cont = dlg->issAltEMAIL->text().latin1()) != ""){ + addStr(issAltName,"email:"); + issAltName+=cont; + } + CERR << "HIER" << endl; + if (issAltName.length() > 0) { + cert->addV3ext(NID_issuer_alt_name, issAltName); + CERR << "IssAltName:" << issAltName<< endl; + } + + + if (opensslError(cert)) return; + // and finally sign the request cert->sign(signkey); if (opensslError(cert)) return; CERR << "SIGNED" <0) { + str += ", "; + } + str += add; +} void MainWindow::showDetailsCert() { diff --git a/MainWindowX509Req.cpp b/MainWindowX509Req.cpp index 5e0bd3c6..92bc6cf6 100644 --- a/MainWindowX509Req.cpp +++ b/MainWindowX509Req.cpp @@ -54,8 +54,7 @@ void MainWindow::newReq() { - NewX509Req_UI *dlg = new NewX509Req_UI(this,0,true,0); - dlg->keyList->insertStringList(keys->getPrivateDesc()); + NewX509Req *dlg = new NewX509Req(this, 0, keys); dlg->image->setPixmap(*csrImg); if (! dlg->exec()) return; pki_key *key = (pki_key *)keys->getSelectedPKI(dlg->keyList->currentText().latin1()); diff --git a/Makefile.in b/Makefile.in index 20e8f3ac..f08ee883 100644 --- a/Makefile.in +++ b/Makefile.in @@ -28,6 +28,7 @@ OBJS=NewKey_UI.o NewKey_UI_MOC.o \ NewX509Req_UI.o NewX509Req_UI_MOC.o \ NewX509_UI.o NewX509_UI_MOC.o \ NewX509.o NewX509_MOC.o \ + NewX509Req.o NewX509Req_MOC.o \ CertDetail_UI.o CertDetail_UI_MOC.o \ Rename_UI.o Rename_UI_MOC.o \ ExportKey.o ExportKey_MOC.o \ @@ -50,7 +51,7 @@ MainWindow.h: MainWindow_UI.h KeyDetail_UI.h \ %.o: %.cpp $(GCC) $(CPPFLAGS) -DVER=\"$(VERSION)\" -DPREFIX=\"@prefix@/share/xca\" -c $< -o $@ -%_MOC.cpp: %.h +%_MOC.cpp: %.h %.cpp $(MOC) $< -o $@ %_UI.h: %.ui diff --git a/NewX509.cpp b/NewX509.cpp index 3aee742c..6b9c13c7 100644 --- a/NewX509.cpp +++ b/NewX509.cpp @@ -55,10 +55,11 @@ NewX509::NewX509(QWidget *parent , const char *name, db_key *key, db_x509req *re :NewX509_UI(parent, name, true, 0) { connect( this, SIGNAL(genKey()), parent, SLOT(newKey()) ); + connect( parent, SIGNAL(keyDone(QString)), this, SLOT(newKeyDone(QString)) ); keys = key; reqs = req; QStringList strings = keys->getPrivateDesc(); - // are there any private keys to use ? + // are there any useable private keys ? if (strings.isEmpty()) { newKey(); } @@ -74,8 +75,43 @@ NewX509::NewX509(QWidget *parent , const char *name, db_key *key, db_x509req *re reqList->insertStringList(strings); } fromDataRB->setChecked(true); + setFinishEnabled(page4,true); + setNextEnabled(page1,false); } +void NewX509::dataChangeP1() +{ + if (description->text() != "" || fromReqRB->isChecked()) { + setNextEnabled(page1,true); + } + else { + setNextEnabled(page1,false); + } +} + +void NewX509::showPage(QWidget *page) +{ + + if ( page == page1 ) { + dataChangeP1(); + } + else if ( page == page2 ) { + if (!selfSignRB->isChecked() && !foreignSignRB->isChecked()) { + if (fromDataRB->isChecked()) { + selfSignRB->setChecked(true); + serialNr->setText("00"); + } + else { + foreignSignRB->setChecked(true); + } + } + } + else if (page == page4) { + } + QWizard::showPage(page); + +} + void NewX509::setDisabled(int state) { if (state == 2) { @@ -91,31 +127,10 @@ void NewX509::setDisabled(int state) void NewX509::newKey() { emit genKey(); - keyList->clear(); - keyList->insertStringList(keys->getPrivateDesc()); } -void NewX509::validateFields() { - QStringList fields; - if (fromReqRB->isChecked()) { - accept(); - return; - } - - if (description->text() == "") - fields.append(tr("Description")); - if (commonName->text() == "") - fields.append(tr("Common Name")); - if (emailAddress->text() == "") - fields.append(tr("Email Address")); - - if (!fields.isEmpty()) { - QMessageBox::information(this,tr("Missing parameter"), - tr("The following fields must not be empty") +":\n'"+ - fields.join("'\n'") + "'", "OK"); - } - else { - accept(); - } +void NewX509::newKeyDone(QString name) +{ + keyList->insertItem(name,0); + keyList->setCurrentItem(0); } - diff --git a/NewX509.h b/NewX509.h index 19deefe9..077a84b5 100644 --- a/NewX509.h +++ b/NewX509.h @@ -56,7 +56,7 @@ #include "lib/db_x509req.h" #include #include -#include +#include #ifndef NEWX509_H #define NEWX509_H @@ -68,14 +68,15 @@ class NewX509: public NewX509_UI private: db_x509req *reqs; db_key *keys; - MainWindow *par; public: NewX509(QWidget *parent, const char *name, db_key *key, db_x509req *req); public slots: void setDisabled(int state); void newKey(); - void validateFields(); + void dataChangeP1(); + void showPage(QWidget *page); + void newKeyDone(QString name); signals: void genKey(); }; diff --git a/NewX509.ui b/NewX509.ui index 0118d8a9..214852c7 100644 --- a/NewX509.ui +++ b/NewX509.ui @@ -11,7 +11,7 @@ 0 0 - 652 + 648 430 @@ -22,17 +22,17 @@ caption - Form1 + Certificate creation QWidget name - page + page1 title - Page + New Certificate Step 1 @@ -400,11 +400,11 @@ For a SSL servercertificate choose the DNS name of the server as "Common name"QWidget name - page + page2 title - New Certificate + New Certificate Step 2 @@ -756,11 +756,11 @@ For a SSL servercertificate choose the DNS name of the server as "Common name"QWidget name - page + page3 title - Page + New Certificate Step 3 @@ -991,11 +991,11 @@ For a SSL servercertificate choose the DNS name of the server as "Common name"QWidget name - page + page4 title - Page + New Certificate Step 4 @@ -1217,4 +1217,33 @@ For a SSL servercertificate choose the DNS name of the server as "Common name" + + + description + textChanged(const QString&) + NewX509_UI + dataChangeP1() + + + fromReqRB + stateChanged(int) + NewX509_UI + dataChangeP1() + + + fromDataRB + stateChanged(int) + NewX509_UI + setDisabled(int) + + + genKey + clicked() + NewX509_UI + newKey() + + dataChangeP1() + newKey() + setDisabled(int) + diff --git a/NewX509Req.cpp b/NewX509Req.cpp new file mode 100644 index 00000000..ea61a932 --- /dev/null +++ b/NewX509Req.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2001 Christian Hohnstaedt. + * + * All rights reserved. + * + * + * 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, + * this list of conditions and the following disclaimer. + * - 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 + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * This program links to software with different licenses from: + * + * http://www.openssl.org which includes cryptographic software + * 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$ + * + */ + + +#include "NewX509Req.h" + +NewX509Req::NewX509Req(QWidget *parent , const char *name, db_key *key) + :NewX509Req_UI(parent, name, true, 0) +{ + connect( this, SIGNAL(genKey()), parent, SLOT(newKey()) ); + connect( parent, SIGNAL(keyDone(QString)), this, SLOT(newKeyDone(QString)) ); + keys = key; + QStringList strings = keys->getPrivateDesc(); + // are there any useable private keys ? + if (strings.isEmpty()) { + newKey(); + } + else { + keyList->insertStringList(strings); + } + generateBut->setEnabled(false); +} + +void NewX509Req::dataChange() +{ + if (description->text() != "" ) { + generateBut->setEnabled(true); + } + else { + generateBut->setEnabled(false); + } +} + + +void NewX509Req::newKey() +{ + emit genKey(); +} + +void NewX509Req::newKeyDone(QString name) +{ + keyList->insertItem(name,0); + keyList->setCurrentItem(0); +} diff --git a/NewX509Req.h b/NewX509Req.h new file mode 100644 index 00000000..07e9fe83 --- /dev/null +++ b/NewX509Req.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2001 Christian Hohnstaedt. + * + * All rights reserved. + * + * + * 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, + * this list of conditions and the following disclaimer. + * - 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 + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * This program links to software with different licenses from: + * + * http://www.openssl.org which includes cryptographic software + * 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$ + * + */ + + +#include "NewX509Req_UI.h" +#include +#include +#include "lib/db_key.h" +#include "lib/db_x509req.h" +#include +#include +#include + +#ifndef NEWX509REQ_H +#define NEWX509REQ_H + +class MainWindow; +class NewX509Req: public NewX509Req_UI +{ + Q_OBJECT + private: + db_key *keys; + public: + NewX509Req(QWidget *parent, const char *name, db_key *key); + + public slots: + void newKey(); + void dataChange(); + void newKeyDone(QString name); + signals: + void genKey(); +}; + +#endif diff --git a/NewX509Req.ui b/NewX509Req.ui index 1bf40f98..c9993373 100644 --- a/NewX509Req.ui +++ b/NewX509Req.ui @@ -11,7 +11,7 @@ 0 0 - 631 + 627 326 @@ -393,7 +393,7 @@ For a SSL servercertificate choose the DNS name of the server QLayoutWidget name - Layout14 + Layout4 @@ -408,11 +408,11 @@ For a SSL servercertificate choose the DNS name of the server QPushButton name - PushButton14 + PushButton15 text - OK + Cancel @@ -440,11 +440,11 @@ For a SSL servercertificate choose the DNS name of the server QPushButton name - PushButton15 + generateBut text - Cancel + Generate request @@ -453,7 +453,7 @@ For a SSL servercertificate choose the DNS name of the server - PushButton14 + generateBut clicked() NewX509Req_UI accept() @@ -464,9 +464,23 @@ For a SSL servercertificate choose the DNS name of the server NewX509Req_UI reject() + + description + textChanged(const QString&) + NewX509Req_UI + dataChange() + + + genKey + clicked() + NewX509Req_UI + newKey() + + newKey() + dataChange() - PushButton14 + generateBut PushButton15