From a656a56a669adb009acf233e780b9f0ecd9e2b2b Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 18 May 2006 23:46:03 +0200 Subject: [PATCH] - Delete unused view/ directory - readd truststate --- lib/db_base.cpp | 36 +- lib/db_x509.cpp | 171 ++++--- lib/db_x509.h | 17 +- ui/TrustState.ui | 72 ++- view/CertView.cpp | 1083 ---------------------------------------- view/CertView.h | 121 ----- view/CrlView.cpp | 277 ---------- view/CrlView.h | 88 ---- view/KeyView.cpp | 314 ------------ view/KeyView.h | 86 ---- view/Makefile | 18 - view/ReqView.cpp | 250 ---------- view/ReqView.h | 88 ---- view/TempView.cpp | 225 --------- view/TempView.h | 100 ---- view/XcaListView.cpp | 266 ---------- view/XcaListView.h | 103 ---- widgets/MainWindow.cpp | 2 +- widgets/clicklabel.h | 16 +- 19 files changed, 191 insertions(+), 3142 deletions(-) delete mode 100644 view/CertView.cpp delete mode 100644 view/CertView.h delete mode 100644 view/CrlView.cpp delete mode 100644 view/CrlView.h delete mode 100644 view/KeyView.cpp delete mode 100644 view/KeyView.h delete mode 100644 view/Makefile delete mode 100644 view/ReqView.cpp delete mode 100644 view/ReqView.h delete mode 100644 view/TempView.cpp delete mode 100644 view/TempView.h delete mode 100644 view/XcaListView.cpp delete mode 100644 view/XcaListView.h diff --git a/lib/db_base.cpp b/lib/db_base.cpp index ba0753ec..38117985 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -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_base.h" @@ -65,7 +65,7 @@ #include "widgets/MainWindow.h" #include "widgets/ImportMulti.h" -db_base::db_base(QString db, MainWindow *mw) +db_base::db_base(QString db, MainWindow *mw) :QAbstractItemModel(NULL) { dbName = db; @@ -97,7 +97,7 @@ void db_base::remFromCont(QModelIndex &idx) pki_base *parent_pki = pki->getParent(); printf("PKI=%p, parent=%p\n", pki,parent_pki); int row = pki->row(); - + beginRemoveRows(parent(idx), row, row); parent_pki->takeChild(pki); endRemoveRows(); @@ -108,7 +108,7 @@ void db_base::loadContainer() db mydb(dbName); unsigned char *p; db_header_t head; - + pki_base *pb, *pki; pb = newPKI(); while ( mydb.find(pb->getType(), NULL) == 0 ) { @@ -143,9 +143,9 @@ void db_base::insertPKI(pki_base *pki) int size; QString name; db mydb(dbName); - + p = pki->toData(&size); - + if (p) { name = mydb.uniq_name(pki->getIntName(), pki->getType()); pki->setIntName(name); @@ -165,7 +165,7 @@ void db_base::delete_ask() delete_txt + ": " + pki->getIntName() + " ?\n" , tr("Delete"), tr("Cancel")) ) return; - + deletePKI(); } @@ -174,9 +174,9 @@ void db_base::deletePKI() if (!currentIdx.isValid()) return; pki_base *pki = static_cast(currentIdx.internalPointer()); - + remFromCont(currentIdx); - + db mydb(dbName); mydb.find(pki->getType(), CCHAR(pki->getIntName())); mydb.erase(); @@ -190,7 +190,7 @@ void db_base::updatePKI(pki_base *pki) db mydb(dbName); p = pki->toData(&size); - + if (p) { mydb.set(p, size, pki->getVersion(), pki->getType(), CCHAR(pki->getIntName())); @@ -204,19 +204,19 @@ void db_base::deleteSelectedItems(QAbstractItemView* view) QModelIndexList indexes = selectionModel->selectedIndexes(); QModelIndex index; QString items; - + foreach(index, indexes) { if (index.column() != 0) continue; pki_base *pki = static_cast(index.internalPointer()); items += "'" + pki->getIntName() + "' "; } - + if (QMessageBox::information(mainwin, tr(XCA_TITLE), delete_txt + ": " + items + " ?\n" , tr("Delete"), tr("Cancel")) ) return; - + foreach(index, indexes) { if (index.column() != 0) continue; @@ -232,7 +232,7 @@ void db_base::showSelectedItems(QAbstractItemView* view) QModelIndexList indexes = selectionModel->selectedIndexes(); QModelIndex index; QString items; - + foreach(index, indexes) { if (index.column() != 0) continue; diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index 7d386296..e51f5b25 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -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 @@ -52,6 +52,7 @@ #include "pki_pkcs7.h" #include "widgets/CertDetail.h" #include "widgets/ExportCert.h" +#include "ui/TrustState.h" #include #include #include @@ -86,7 +87,7 @@ pki_x509 *db_x509::findSigner(pki_x509 *client) return client; } FOR_ALL_pki(pki, pki_x509) - if (client->verify(pki)) + if (client->verify(pki)) return pki; return NULL; } @@ -96,7 +97,7 @@ QStringList db_x509::getPrivateDesc() QStringList x; FOR_ALL_pki(pki, pki_x509) if (pki->getRefKey()) - x.append(pki->getIntName()); + x.append(pki->getIntName()); return x; } @@ -105,7 +106,7 @@ QStringList db_x509::getSignerDesc() QStringList x; FOR_ALL_pki(pki, pki_x509) if (pki->canSign()) - x.append(pki->getIntName()); + x.append(pki->getIntName()); return x; } @@ -117,14 +118,14 @@ void db_x509::remFromCont(QModelIndex &idx) pki_base *parent_pki = pki->getParent(); row = pki->row(); pki_x509 *child; - + beginRemoveRows(parent(idx), row, row); parent_pki->takeChild(pki); endRemoveRows(); row = rootItem->childCount()+1; num = pki->childCount(); - + beginInsertRows(QModelIndex(), row, row + num ); while (pki->childCount()) { printf("Insert dangling children: %d\n", pki->childCount()); @@ -142,10 +143,10 @@ void db_x509::preprocess() { FOR_ALL_pki(pki, pki_x509) { findSigner(pki); - findKey(pki); + findKey(pki); } calcEffTrust(); - + } @@ -163,29 +164,28 @@ void db_x509::insertPKI(pki_base *refpki) FOR_ALL_pki(pki, pki_x509) /* sets this cert as signer the certs */ pki->verify(x); db_base::insertPKI(refpki); -} +} #endif void db_x509::inToCont(pki_base *pki) { - static int i=0; pki_x509 *cert = (pki_x509*)pki; - + findSigner(cert); pki_base *root = cert->getSigner(); QModelIndex idx = QModelIndex(), this_idx; - + if (root == pki || root == NULL) root = rootItem; else idx = createIndex(root->row(), 0, root); - + int row = root->childCount()+1; beginInsertRows(idx, row, row); root->append(pki); endInsertRows(); this_idx = index(row, 0, idx); - + /* search for dangling certificates, which signer this is */ FOR_ALL_pki(client, pki_x509) { if (client->getSigner() == NULL) { @@ -196,7 +196,7 @@ void db_x509::inToCont(pki_base *pki) beginRemoveRows(QModelIndex(), row, row); rootItem->takeChild(client); endRemoveRows(); - + row = root->childCount()+1; beginInsertRows(this_idx, row, row); pki->append(client); @@ -224,7 +224,7 @@ pki_x509 *db_x509::getBySubject(const x509name &xname, pki_x509 *last) { bool lastfound = false; if (last == NULL) lastfound = true; - + FOR_ALL_pki(pki, pki_x509) { if ( pki->getSubject() == xname) { if (lastfound) { @@ -244,7 +244,7 @@ void db_x509::revokeCert(const x509rev &revok, const pki_x509 *iss) if (crt) crt->setRevoked(revok.getDate()); } - + pki_x509 *db_x509::getByIssSerial(const pki_x509 *issuer, const a1int &a) { if (!issuer ) return NULL; @@ -278,7 +278,7 @@ a1int db_x509::searchSerial(pki_x509 *signer) { // returns the highest certificate serial // of all certs with this signer (itself too) - a1int sserial, myserial; + a1int sserial, myserial; if (!signer) return sserial; sserial = signer->getCaSerial(); FOR_ALL_pki(pki, pki_x509) @@ -315,7 +315,7 @@ pki_base *db_x509::insert(pki_base *item) updatePKI(cert->getSigner()); } } - + // check CA serial of this cert serial = searchSerial(cert); if ( ++serial > cert->getCaSerial()) { @@ -379,9 +379,9 @@ void db_x509::newCert(NewX509 *dlg) a1time notBefore, notAfter; x509name subject; QString intname; - - try { - + + try { + // Step 1 - Subject and key if (!dlg->fromReqCB->isChecked()) { clientkey = dlg->getSelectedKey(); @@ -389,7 +389,7 @@ void db_x509::newCert(NewX509 *dlg) intname = dlg->description->text(); } else { - // A PKCS#10 Request was selected + // A PKCS#10 Request was selected req = dlg->getSelectedReq(); if (!req) return; @@ -401,13 +401,13 @@ void db_x509::newCert(NewX509 *dlg) subject = req->getSubject(); intname = req->getIntName(); } - - // initially create cert + + // initially create cert cert = new pki_x509(); cert->setIntName(intname); cert->setSubject(subject); cert->setPubKey(clientkey); - + // Step 2 - select Signing if (dlg->foreignSignRB->isChecked()) { signcert = dlg->getSelectedSigner(); @@ -419,7 +419,7 @@ void db_x509::newCert(NewX509 *dlg) } #if 0 else if (dlg->selfQASignRB->isChecked()){ - + PassWrite_UI *dlg1 = new PassWrite_UI(NULL, 0, true); dlg1->image->setPixmap( *MainWindow::keyImg ); dlg1->title->setText(XCA_TITLE); @@ -441,15 +441,15 @@ void db_x509::newCert(NewX509 *dlg) delete dlg1; if (A!=B) throw errorEx(tr("The QA process has been terminated by the user.")); - signcert = cert; - signkey = clientkey; + signcert = cert; + signkey = clientkey; serial.setHex(A); cert->setTrust(2); } #endif else { - signcert = cert; - signkey = clientkey; + signcert = cert; + signkey = clientkey; serial.setHex(dlg->serialNr->text()); cert->setTrust(2); } @@ -463,7 +463,7 @@ void db_x509::newCert(NewX509 *dlg) // set the issuers name cert->setIssuer(signcert->getSubject()); cert->setSerial(serial); - + // Step 3 - Choose the Date // Date handling cert->setNotBefore( dlg->notBefore->getDate() ); @@ -476,16 +476,16 @@ void db_x509::newCert(NewX509 *dlg) )) throw errorEx(""); } - - + + // STEP 4 handle extensions if (dlg->copyReqExtCB->isChecked() && dlg->fromReqCB->isChecked()) { extList el = req->getV3Ext(); int m = el.count(); for (int i=0; iaddV3ext(el[i]); - } - + } + cert->addV3ext(dlg->getBasicConstraints()); cert->addV3ext(dlg->getSubKeyIdent()); cert->addV3ext(dlg->getAuthKeyIdent()); @@ -500,11 +500,11 @@ void db_x509::newCert(NewX509 *dlg) int m = ne.count(); for (int i=0; iaddV3ext(ne[i]); - + const EVP_MD *hashAlgo = dlg->getHashAlgo(); if (signkey->getType() == EVP_PKEY_DSA) hashAlgo = EVP_dss1(); -#if 0 +#if 0 if (dlg->selfQASignRB->isChecked()) { // sign the request intermediately in order to finally fill @@ -514,20 +514,20 @@ void db_x509::newCert(NewX509 *dlg) cert->setSerial(cert->hashInfo(EVP_md5())); } #endif - // and finally sign the request + // and finally sign the request cert->sign(signkey, hashAlgo); insert(cert); updatePKI(signcert); if (tempkey != NULL) delete(tempkey); } - + catch (errorEx &err) { MainWindow::Error(err); delete cert; if (tempkey != NULL) delete(tempkey); } - + } void db_x509::showItem() @@ -536,7 +536,7 @@ void db_x509::showItem() return; pki_x509 *crt = static_cast(currentIdx.internalPointer()); CertDetail *dlg; - printf("Show Item x509\n"); + printf("Show Item x509\n"); dlg = new CertDetail(mainwin); if (dlg) { dlg->setCert(crt); @@ -551,11 +551,11 @@ void db_x509::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) QMenu *subExport, *subCa, *subP7; QAction *itemReq, *itemtca, *itemTemplate, *itemRevoke, *itemExtend, *itemTrust; - bool parentCanSign, canSign, hasTemplates, hasPrivkey; - currentIdx = QModelIndex(); - + bool parentCanSign, canSign, hasTemplates, hasPrivkey; + currentIdx = index; + pki_x509 *cert = static_cast(index.internalPointer()); - + menu->addAction(tr("New Certificate"), this, SLOT(newItem())); menu->addAction(tr("Import"), this, SLOT(load())); menu->addAction(tr("Import PKCS#12"), this, SLOT(loadPKCS12())); @@ -578,7 +578,7 @@ void db_x509::showContextMenu(QContextMenuEvent *e, const QModelIndex &index) itemTemplate = subCa->addAction(tr("Signing Template"), this, SLOT(setTemplate())); subCa->addAction(tr("Generate CRL"), this, SLOT(genCrl())); - + subP7 = menu->addMenu(tr("PKCS#7")); subP7->addAction(tr("Sign"), this, SLOT(signP7())); subP7->addAction(tr("Encrypt"), this, SLOT(encryptP7())); @@ -627,7 +627,7 @@ void db_x509::store() QStringList filt; if (!currentIdx.isValid()) return; - + pki_x509 *crt = static_cast(currentIdx.internalPointer()); pki_x509 *oldcrt = NULL; if (!crt) @@ -666,7 +666,7 @@ void db_x509::store() case 3: // PEM all Certificates writeAllCerts(fname,false); break; - case 4: // DER + case 4: // DER crt->writeCert(fname,false,false); break; case 5: // P7 lonely @@ -706,7 +706,7 @@ void db_x509::writePKCS12(pki_x509 *cert, QString s, bool chain) QMessageBox::warning(mainwin, tr(XCA_TITLE), tr("There was no key found for the Certificate: ") + cert->getIntName() ); - return; + return; } if (s.isEmpty()) return; @@ -732,7 +732,7 @@ void db_x509::writePKCS7(pki_x509 *cert, QString s, int type) pki_pkcs7 *p7 = NULL; QList list; pki_base *cer; - try { + try { p7 = new pki_pkcs7(""); if ( type == P7_CHAIN ) { while (cert != NULL) { @@ -743,12 +743,12 @@ void db_x509::writePKCS7(pki_x509 *cert, QString s, int type) } 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() ) { + for ( cer = list.first(); cer != NULL; cer = list.next() ) { if (((pki_x509*)cer)->getTrust() == 2) p7->addCert((pki_x509 *)cer); } @@ -762,7 +762,7 @@ void db_x509::writePKCS7(pki_x509 *cert, QString s, int type) } } } -#else +#else #warning P7_TRUSTED P7_ALL #endif p7->writeP7(s, false); @@ -772,9 +772,9 @@ void db_x509::writePKCS7(pki_x509 *cert, QString s, int type) } if (p7 != NULL ) delete p7; - + } -# if 0 +# if 0 void ::signP7() { QStringList filt; @@ -784,9 +784,9 @@ void ::signP7() pki_key *privkey = cert->getRefKey(); if (!privkey || privkey->isPubKey()) { QMessageBox::warning(this,tr(XCA_TITLE), - tr("There was no key found for the Certificate: ") + + tr("There was no key found for the Certificate: ") + cert->getIntName()); - return; + return; } filt.append("All Files ( *.* )"); QString s=""; @@ -813,7 +813,7 @@ void ::signP7() catch (errorEx &err) { Qt::SocketError(err); } -} +} void CertView::encryptP7() { @@ -826,7 +826,7 @@ void CertView::encryptP7() QMessageBox::warning(this,tr(XCA_TITLE), tr("There was no key found for the Certificate: ") + cert->getIntName()) ; - return; + return; } filt.append("All Files ( *.* )"); QString s=""; @@ -853,5 +853,52 @@ void CertView::encryptP7() catch (errorEx &err) { Qt::SocketError(err); } -} +} #endif + +void db_x509::setMultiTrust(QAbstractItemView* view) +{ + QItemSelectionModel *selectionModel = view->selectionModel(); + QModelIndexList indexes = selectionModel->selectedIndexes(); + QString items; + + foreach(currentIdx, indexes) { + setTrust(); + } + currentIdx = QModelIndex(); +} + +void db_x509::setTrust() +{ + int state, newstate; + Ui::TrustState ui; + printf("Trust UI\n"); + pki_x509 *cert = static_cast(currentIdx.internalPointer()); + if (!cert) + return; + QDialog *dlg = new QDialog(mainwin); + ui.setupUi(dlg); + + ui.image->setPixmap(*MainWindow::certImg); + state = cert->getTrust(); + if (cert->getSigner() == cert) { + if (state == 1) + state = 0; + ui.trust1->setDisabled(true); + } + if (state == 0 ) ui.trust0->setChecked(true); + if (state == 1 ) ui.trust1->setChecked(true); + if (state == 2 ) ui.trust2->setChecked(true); + ui.certName->setText(cert->getIntName()); + if (dlg->exec()) { + if (ui.trust0->isChecked()) newstate = 0; + if (ui.trust1->isChecked()) newstate = 1; + if (ui.trust2->isChecked()) newstate = 2; + if (newstate!=state) { + cert->setTrust(newstate); + updatePKI(cert); + } + } + delete dlg; +} + diff --git a/lib/db_x509.h b/lib/db_x509.h index ff95c61a..dca60f20 100644 --- a/lib/db_x509.h +++ b/lib/db_x509.h @@ -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$ * - */ + */ #ifndef DB_X509_H @@ -63,10 +63,10 @@ class db_x509: public db_x509super { Q_OBJECT - + protected: QPixmap *certicon[4]; - + public: db_x509(QString DBfile, MainWindow *mw); pki_base *newPKI(); @@ -91,7 +91,6 @@ 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); - public slots: void load(void); @@ -99,6 +98,8 @@ class db_x509: public db_x509super void revokeCert(const x509rev &revok, const pki_x509 *issuer); void store(); void showItem(); + void setMultiTrust(QAbstractItemView* view); + void setTrust(); }; #endif diff --git a/ui/TrustState.ui b/ui/TrustState.ui index 365b8057..884669ba 100644 --- a/ui/TrustState.ui +++ b/ui/TrustState.ui @@ -2,14 +2,14 @@ - TrustState_UI - + TrustState + 0 0 - 455 - 267 + 435 + 288 @@ -17,7 +17,7 @@ - 11 + 8 6 @@ -44,7 +44,7 @@ - Set Trustment of the Certificate + <html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:14pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Set trustment of the Certificate</p></body></html> @@ -93,13 +93,10 @@ Qt::Vertical - - QSizePolicy::Expanding - 20 - 20 + 40 @@ -112,25 +109,22 @@ Qt::Vertical - - QSizePolicy::Expanding - 20 - 20 + 40 - + - Select the Truststate + Trustment - 11 + 8 6 @@ -203,21 +197,47 @@ - - Q3ButtonGroup - -
Qt3Support/Q3ButtonGroup
- 1 - -
ClickLabel -
clicklabel.h
+
widgets/clicklabel.h
0
- + + + PushButton5 + clicked() + TrustState + reject() + + + 66 + 258 + + + 171 + 251 + + + + + PushButton4 + clicked() + TrustState + accept() + + + 383 + 247 + + + 238 + 247 + + + + diff --git a/view/CertView.cpp b/view/CertView.cpp deleted file mode 100644 index 2280ef05..00000000 --- a/view/CertView.cpp +++ /dev/null @@ -1,1083 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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 "CertView.h" -#include "widgets/MainWindow.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "widgets/CertExtend.h" -#include "widgets/ExportCert.h" -#include "widgets/CertDetail.h" -#include "widgets/KeyDetail.h" -#include "ui/TrustState.h" -#include "ui/PassWrite.h" -#include "widgets/ExportTinyCA.h" -#include "widgets/validity.h" -#include "widgets/clicklabel.h" -#include "lib/pki_pkcs12.h" -#include "lib/pki_pkcs7.h" - -#ifdef WIN32 -#include // to define mkdir function -#include // to define mkdir function -#else -#include -#include -#include -#endif - -CertView::CertView(QWidget * parent, const char * name, Qt::WFlags f) - :XcaListView(parent, name, f) -{ - addColumn(tr("Internal name")); - addColumn(tr("Common name")); - addColumn(tr("Serial")); - addColumn(tr("not After")); - addColumn(tr("Trust state")); - addColumn(tr("Revocation")); - viewState=1; // Tree View -} - - -void CertView::newItem() -{ - CHECK_DB - NewX509 *dlg = new NewX509(this, NULL, true); - emit connNewX509(dlg); - dlg->setCert(); - dlg->defineSigner((pki_x509*)getSelected()); - if (dlg->exec()) { - newCert(dlg); - } - delete dlg; -} - -void CertView::newCert(pki_x509req *req) -{ - NewX509 *dlg = new NewX509(this, NULL, true); - emit connNewX509(dlg); - dlg->setCert(); - dlg->defineRequest(req); - dlg->defineSigner((pki_x509*)getSelected()); - if (dlg->exec()) { - newCert(dlg); - } - delete dlg; -} - -void CertView::newCert(pki_temp *req) -{ - NewX509 *dlg = new NewX509(this, NULL, true); - emit connNewX509(dlg); - dlg->setCert(); - dlg->defineTemplate(req); - if (dlg->exec()) { - newCert(dlg); - } - delete dlg; -} - -void CertView::newCert(NewX509 *dlg) -{ - pki_x509 *cert = NULL; - pki_x509 *signcert = NULL; - pki_x509req *req = NULL; - pki_key *signkey = NULL, *clientkey = NULL, *tempkey = NULL; - a1int serial; - a1time notBefore, notAfter; - x509name subject; - QString intname; - - CHECK_DB - - try { - - // Step 1 - Subject and key - if (!dlg->fromReqCB->isChecked()) { - clientkey = dlg->getSelectedKey(); - subject = dlg->getX509name(); - intname = dlg->description->text(); - } - else { - // A PKCS#10 Request was selected - req = dlg->getSelectedReq(); - if (Qt::SocketError(req)) return; - clientkey = req->getRefKey(); - if (clientkey == NULL) { - clientkey = req->getPubKey(); - tempkey = clientkey; - } - subject = req->getSubject(); - intname = req->getIntName(); - } - - // initially create cert - cert = new pki_x509(); - cert->setIntName(intname); - cert->setSubject(subject); - cert->setPubKey(clientkey); - - // Step 2 - select Signing - if (dlg->foreignSignRB->isChecked()) { - signcert = dlg->getSelectedSigner(); - if (Qt::SocketError(signcert)) return; - serial = signcert->getIncCaSerial(); - signkey = signcert->getRefKey(); - cert->setTrust(1); - } - else if (dlg->selfQASignRB->isChecked()){ - - PassWrite_UI *dlg1 = new PassWrite_UI(NULL, 0, true); - dlg1->image->setPixmap( *MainWindow::keyImg ); - dlg1->title->setText(XCA_TITLE); - dlg1->description->setText(tr("Please enter the new hexadecimal secret number for the QA process.")); - dlg1->passA->setFocus(); -#ifdef qt3 - dlg1->passA->setValidator(new QRegExpValidator(QRegExp("[0-9a-fA-F]*"),dlg1->passA)); - dlg1->passB->setValidator(new QRegExpValidator(QRegExp("[0-9a-fA-F]*"),dlg1->passB)); -#endif - dlg1->setCaption(XCA_TITLE); - QString A = "x", B=""; - - while (dlg1->exec()) - { - A = dlg1->passA->text(); - B = dlg1->passB->text(); - if (A==B) break; - else - QMessageBox::warning(this, XCA_TITLE, tr("The two secret numbers don't match.")); - } - delete dlg1; - if (A!=B) - throw errorEx(tr("The QA process has been terminated by the user.")); - signcert = cert; - signkey = clientkey; - serial.setHex(A); - cert->setTrust(2); - } - else { - signcert = cert; - signkey = clientkey; - serial.setHex(dlg->serialNr->text()); - cert->setTrust(2); - } - - dlg->initCtx(cert, signcert); - // if we can not sign - if (! signkey || signkey->isPubKey()) { - throw errorEx(tr("The key you selected for signing is not a private one.")); - } - - // set the issuers name - cert->setIssuer(signcert->getSubject()); - cert->setSerial(serial); - - // Step 3 - Choose the Date - // Date handling - cert->setNotBefore( dlg->notBefore->getDate() ); - cert->setNotAfter( dlg->notAfter->getDate() ); - - if (cert->resetTimes(signcert) > 0) { - if (QMessageBox::information(this,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(""); - } - - - // STEP 4 handle extensions - if (dlg->copyReqExtCB->isChecked() && dlg->fromReqCB->isChecked()) { - extList el = req->getV3Ext(); - int m = el.count(); - for (int i=0; iaddV3ext(el[i]); - } - - cert->addV3ext(dlg->getBasicConstraints()); - cert->addV3ext(dlg->getSubKeyIdent()); - cert->addV3ext(dlg->getAuthKeyIdent()); - cert->addV3ext(dlg->getKeyUsage()); - cert->addV3ext(dlg->getEkeyUsage()); - cert->addV3ext(dlg->getSubAltName()); - cert->addV3ext(dlg->getIssAltName()); - cert->addV3ext(dlg->getCrlDist()); - cert->addV3ext(dlg->getAuthInfAcc()); - cert->addV3ext(dlg->getCertPol()); - extList ne = dlg->getNetscapeExt(); - int m = ne.count(); - for (int i=0; iaddV3ext(ne[i]); - - const EVP_MD *hashAlgo = dlg->getHashAlgo(); - if (signkey->getType() == EVP_PKEY_DSA) - hashAlgo = EVP_dss1(); - - if (dlg->selfQASignRB->isChecked()) - { - // sign the request intermediately in order to finally fill - // up the cert_info substructure. - cert->sign(signkey, hashAlgo); - // now set the QA serial. - cert->setSerial(cert->hashInfo(EVP_md5())); - } - - // and finally sign the request - cert->sign(signkey, hashAlgo); - db->insert(cert); - db->updatePKI(signcert); - if (tempkey != NULL) delete(tempkey); - updateView(); - return; - } // EOF try - - catch (errorEx &err) { - Qt::SocketError(err); - delete cert; - if (tempkey != NULL) delete(tempkey); - } - -} - -void CertView::extendCert() -{ - pki_x509 *oldcert = NULL, *signer = NULL, *newcert =NULL; - pki_key *signkey = NULL; - a1time time; - a1int serial; - emit init_database(); - try { - CertExtend *dlg = new CertExtend(this, NULL, true); - - if (!dlg->exec()) { - delete dlg; - return; - } - oldcert = (pki_x509 *)getSelected(); - 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 - } - db->updatePKI(signer); // FIXME::not so pretty .... - - // 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(this,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()); - db->insert(newcert); - delete dlg; - } - catch (errorEx &err) { - Qt::SocketError(err); - if (newcert) - delete newcert; - } - updateView(); -} - -void CertView::showItem(pki_base *item, bool import) -{ - if (!item) return; - CertDetail *dlg=NULL; - try { - dlg = new CertDetail(this,0,true); - dlg->setCert((pki_x509 *)item); - connect( dlg->privKey, SIGNAL( doubleClicked(QString) ), - this, SLOT( showKey(QString) )); - connect( dlg->signCert, SIGNAL( doubleClicked(QString) ), - this, SLOT( showItem(QString) )); - - dlg->exec(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (dlg) - delete dlg; - return ; -} - -void CertView::deleteItem() -{ - try { - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - if (cert->getSigner() && cert->getSigner() != cert && cert->getSigner()->canSign()) { - QMessageBox::information(this,tr(XCA_TITLE), - tr("It is actually not a good idea to delete a cert that was signed by you") +":\n'" + - cert->getIntName() + "'\n" , - tr("Ok") ); - } - deleteItem_default(tr("The certificate"), tr("is going to be deleted")); - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void CertView::load() -{ - load_cert l; - load_default(l); -} - -void CertView::loadPKCS12() -{ - load_pkcs12 l; - load_default(l); -} - -void CertView::loadPKCS7() -{ - load_pkcs7 l; - load_default(l); -} - -#define P7_ONLY 0 -#define P7_CHAIN 1 -#define P7_TRUSTED 2 -#define P7_ALL 3 - -void CertView::store() -{ - QStringList filt; - pki_x509 *crt = (pki_x509 *)getSelected(); - pki_x509 *oldcrt = NULL; - emit init_database(); - if (!crt) return; - pki_key *privkey = crt->getRefKey(); - ExportCert *dlg = new ExportCert((crt->getIntName() + ".crt"), - (privkey && privkey->isPrivKey()), MainWindow::getPath(), crt->tinyCAfname() ); - dlg->image->setPixmap(*MainWindow::certImg); - int dlgret = dlg->exec(); - - if (!dlgret) { - delete dlg; - return; - } - QString fname = dlg->filename->text(); - if (fname == "") { - delete dlg; - return; - } - try { - switch (dlg->exportFormat->currentItem()) { - case 0: // PEM - crt->writeCert(fname,true,false); - break; - case 1: // PEM with chain - while(crt && crt != oldcrt) { - crt->writeCert(fname,true,true); - oldcrt = crt; - crt = crt->getSigner(); - } - break; - case 2: // PEM all trusted Certificates - MainWindow::certs->writeAllCerts(fname,true); - break; - case 3: // PEM all Certificates - MainWindow::certs->writeAllCerts(fname,false); - break; - case 4: // DER - crt->writeCert(fname,false,false); - break; - case 5: // P7 lonely - writePKCS7(fname, P7_ONLY); - break; - case 6: // P7 - writePKCS7(fname, P7_CHAIN); - break; - case 7: // P7 - writePKCS7(fname, P7_TRUSTED); - break; - case 8: // P7 - writePKCS7(fname, P7_ALL); - break; - case 9: // P12 - writePKCS12(fname,false); - break; - case 10: // P12 + cert chain - writePKCS12(fname,true); - break; - - } - } - catch (errorEx &err) { - Qt::SocketError(err); - } - delete dlg; -} - - -void CertView::writePKCS12(QString s, bool chain) -{ - QStringList filt; - try { - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - pki_key *privkey = cert->getRefKey(); - if (!privkey || privkey->isPubKey()) { - QMessageBox::warning(this,tr(XCA_TITLE), - tr("There was no key found for the Certificate: ") + - cert->getIntName() ); - return; - } - if (s.isEmpty()) return; - s = QDir::convertSeparators(s); - pki_pkcs12 *p12 = new pki_pkcs12(cert->getIntName(), cert, privkey, &MainWindow::passWrite); - pki_x509 *signer = cert->getSigner(); - while ((signer != NULL ) && (signer != cert) && chain) { - p12->addCaCert(signer); - cert=signer; - signer=signer->getSigner(); - } - p12->writePKCS12(s); - delete p12; - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void CertView::writePKCS7(QString s, int type) -{ - pki_pkcs7 *p7 = NULL; - QList list; - pki_x509 *cert = (pki_x509 *)getSelected(); - pki_base *cer; - emit init_database(); - try { - 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 (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_ALL) { - list = db->getContainer(); - if (!list.isEmpty()) { - for ( cer = list.first(); cer != NULL; cer = list.next() ) { - p7->addCert((pki_x509 *)cer); - } - } - } - p7->writeP7(s, false); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (p7 != NULL ) delete p7; - -} - -void CertView::signP7() -{ - QStringList filt; - try { - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - pki_key *privkey = cert->getRefKey(); - if (!privkey || privkey->isPubKey()) { - QMessageBox::warning(this,tr(XCA_TITLE), - tr("There was no key found for the Certificate: ") + - cert->getIntName()); - return; - } - filt.append("All Files ( *.* )"); - QString s=""; - QStringList slist; - Q3FileDialog *dlg = new Q3FileDialog(this,0,true); - dlg->setCaption(tr("Import Certificate signing request")); - dlg->setFilters(filt); - dlg->setMode( Q3FileDialog::ExistingFiles ); - dlg->setDir(MainWindow::getPath()); - if (dlg->exec()) { - slist = dlg->selectedFiles(); - MainWindow::setPath(dlg->dirPath()); - } - delete dlg; - pki_pkcs7 * p7 = new pki_pkcs7(""); - for ( QStringList::Iterator it = slist.begin(); it != slist.end(); ++it ) { - s = *it; - s = QDir::convertSeparators(s); - p7->signFile(cert, s); - p7->writeP7((s + ".p7s"), true); - } - delete p7; - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void CertView::encryptP7() -{ - QStringList filt; - try { - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - pki_key *privkey = cert->getRefKey(); - if (!privkey || privkey->isPubKey()) { - QMessageBox::warning(this,tr(XCA_TITLE), - tr("There was no key found for the Certificate: ") + - cert->getIntName()) ; - return; - } - filt.append("All Files ( *.* )"); - QString s=""; - QStringList slist; - Q3FileDialog *dlg = new Q3FileDialog(this,0,true); - dlg->setCaption(tr("Import Certificate signing request")); - dlg->setFilters(filt); - dlg->setMode( Q3FileDialog::ExistingFiles ); - dlg->setDir(MainWindow::getPath()); - if (dlg->exec()) { - slist = dlg->selectedFiles(); - MainWindow::setPath(dlg->dirPath()); - } - delete dlg; - pki_pkcs7 * p7 = new pki_pkcs7(""); - for ( QStringList::Iterator it = slist.begin(); it != slist.end(); ++it ) { - s = *it; - s = QDir::convertSeparators(s); - p7->encryptFile(cert, s); - p7->writeP7((s + ".p7m"), true); - } - delete p7; - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void CertView::popupMenu(Q3ListViewItem *item, const QPoint &pt, int x) { - Q3PopupMenu *menu = new Q3PopupMenu(this); - Q3PopupMenu *subCa = new Q3PopupMenu(this); - Q3PopupMenu *subP7 = new Q3PopupMenu(this); - Q3PopupMenu *subExport = new Q3PopupMenu(this); - int itemExtend, itemRevoke, itemTrust, itemCA, itemTemplate, itemReq, itemP7, itemtca; - bool canSign, parentCanSign, hasTemplates, hasPrivkey; - - emit init_database(); - if (!item) { - menu->insertItem(tr("New Certificate"), this, SLOT(newItem())); - menu->insertItem(tr("Import"), this, SLOT(load())); - menu->insertItem(tr("Import PKCS#12"), this, SLOT(loadPKCS12())); - menu->insertItem(tr("Import from PKCS#7"), this, SLOT(loadPKCS7())); - } - else { - CHECK_DB - pki_x509 *cert = (pki_x509 *)db->getByName(item->text(0)); - menu->insertItem(tr("Rename"), this, SLOT(startRename())); - menu->insertItem(tr("Show Details"), this, SLOT(showItem())); - menu->insertItem(tr("Export"), subExport); - subExport->insertItem(tr("File"), this, SLOT(store())); - itemReq = subExport->insertItem(tr("Request"), this, SLOT(toRequest())); - itemtca = subExport->insertItem(tr("TinyCA"), this, SLOT(toTinyCA())); - - menu->insertItem(tr("Delete"), this, SLOT(deleteItem())); - itemTrust = menu->insertItem(tr("Trust"), this, SLOT(setTrust())); - menu->insertSeparator(); - itemCA = menu->insertItem(tr("CA"), subCa); - subCa->insertItem(tr("Serial"), this, SLOT(setSerial())); - subCa->insertItem(tr("CRL days"), this, SLOT(setCrlDays())); - itemTemplate = subCa->insertItem(tr("Signing Template"), this, SLOT(setTemplate())); - subCa->insertItem(tr("Generate CRL"), this, SLOT(genCrl())); - - itemP7 = menu->insertItem(tr("PKCS#7"), subP7); - subP7->insertItem(tr("Sign"), this, SLOT(signP7())); - subP7->insertItem(tr("Encrypt"), this, SLOT(encryptP7())); - menu->insertSeparator(); - itemExtend = menu->insertItem(tr("Renewal"), this, SLOT(extendCert())); - if (cert) { - if (cert->isRevoked()) { - itemRevoke = menu->insertItem(tr("Unrevoke"), this, SLOT(unRevoke())); - menu->setItemEnabled(itemTrust, false); - } - else - itemRevoke = menu->insertItem(tr("Revoke"), this, SLOT(revoke())); - parentCanSign = (cert->getSigner() && cert->getSigner()->canSign() && (cert->getSigner() != cert)); - canSign = cert->canSign(); - hasTemplates = MainWindow::temps->getDesc().count() > 0 ; - hasPrivkey = cert->getRefKey(); - } - menu->setItemEnabled(itemExtend, parentCanSign); - menu->setItemEnabled(itemRevoke, parentCanSign); - menu->setItemEnabled(itemCA, canSign); - subExport->setItemEnabled(itemReq, hasPrivkey); - subExport->setItemEnabled(itemtca, canSign); - menu->setItemEnabled(itemP7, hasPrivkey); - subCa->setItemEnabled(itemTemplate, hasTemplates); - - } - menu->exec(pt); - delete menu; - delete subCa; - delete subP7; - delete subExport; - - return; -} - -void CertView::setTrust() -{ - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - TrustState_UI *dlg = new TrustState_UI(this,0,true); - int state, newstate; - dlg->image->setPixmap(*MainWindow::certImg); - state = cert->getTrust(); - if (cert->getSigner() == cert) { - if (state == 1) state = 0; - dlg->trust1->setDisabled(true); - } - if (state == 0 ) dlg->trust0->setChecked(true); - if (state == 1 ) dlg->trust1->setChecked(true); - if (state == 2 ) dlg->trust2->setChecked(true); - dlg->certName->setText(cert->getIntName()); - if (dlg->exec()) { - if (dlg->trust0->isChecked()) newstate = 0; - if (dlg->trust1->isChecked()) newstate = 1; - if (dlg->trust2->isChecked()) newstate = 2; - if (newstate!=state) { - cert->setTrust(newstate); - db->updatePKI(cert); - updateView(); - } - } - delete dlg; -} - -void CertView::toRequest() -{ - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - - try { - pki_x509req *req = new pki_x509req(); - req->setIntName(cert->getIntName()); - req->createReq(cert->getRefKey(), cert->getSubject(), - cert->getRefKey()->getDefaultMD(), cert->getExt()); - MainWindow::reqs->insert(req); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - -} - -void CertView::revoke() -{ - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - cert->setRevoked(true); - db->updatePKI(cert); - updateView(); -} - -void CertView::unRevoke() -{ - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - cert->setRevoked(false); - db->updatePKI(cert); - updateView(); -} - -void CertView::setSerial() -{ - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - a1int serial = cert->getCaSerial(); - try { - bool ok; - QString s= - QInputDialog::getText (tr(XCA_TITLE), - tr("Please enter the new Serial for signing"), - QLineEdit::Normal, serial.toHex(), &ok, this ); - if (!ok) return; - a1int nserial; - nserial.setHex(s); - if (nserial > serial) { - cert->setCaSerial(nserial); - db->updatePKI(cert); - } - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void CertView::setCrlDays() -{ - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - int crlDays = cert->getCrlDays(); - bool ok; - int nCrlDays = QInputDialog::getInteger (tr(XCA_TITLE), - tr("Please enter the CRL renewal periode in days"), - crlDays, 1, 2147483647, 1, &ok, this ); - if (ok && (crlDays != nCrlDays)) { - cert->setCrlDays(nCrlDays); - db->updatePKI(cert); - } -} - -void CertView::setTemplate() -{ - pki_x509 *cert = (pki_x509 *)getSelected(); - if (!cert) return; - QString templ = cert->getTemplate(); - QStringList tempList = MainWindow::temps->getDesc(); - unsigned int i, sel=0; - bool ok; - for (i=0; isetTemplate(nTempl); - db->updatePKI(cert); - } -} - - -void CertView::changeView(QPushButton *b) -{ - CHECK_DB - if (viewState == 0) { // Plain view - viewState = 1; - b->setText(tr("Plain View")); - } - else { // Tree View - viewState = 0; - b->setText(tr("Tree View")); - } - updateView(); -} - -#define fopenerror(file) \ - QMessageBox::warning(this,tr(XCA_TITLE), \ - tr("The file '") + file + tr("' could not be opened")); - -void CertView::toTinyCA() -{ -#ifndef WIN32 - pki_x509 *crt = (pki_x509 *)getSelected(); - if (!crt) return; - pki_key *key = crt->getRefKey(); - if (!key) return; - FILE *fp, *fpr; - char buf[200]; - QList list; - pki_x509 *issuedcert; - QString dname = crt->getIntName(); - QString tcatempdir = MainWindow::settings->getString("TinyCAtempdir"); - QString tcadir = MainWindow::settings->getString("TinyCAdir"); - if (tcatempdir.isEmpty()) { - tcatempdir = "templates"; - } - if (tcadir.isEmpty()) { - tcadir = QDir::homeDirPath(); - tcadir += QDir::separator(); - tcadir += ".TinyCA"; - } - ExportTinyCA *dlg = new ExportTinyCA( tcatempdir, tcadir, this, NULL); - if (!dlg->exec()) return; - - tcatempdir = dlg->tempdir->text(); - tcadir = dlg->tinycadir->text(); - dname = dlg->dname->text(); - - MainWindow::settings->putString("TinyCAtempdir", tcatempdir); - MainWindow::settings->putString("TinyCAdir", tcadir); - - if (dname.isEmpty()) return; - const EVP_CIPHER *enc = EVP_des_ede3_cbc(); - - - // OK, we have all names now... - tcadir += QDir::separator(); - tcadir += dname; - - //create directory tree - if (! mkDir(tcadir)) return; - chdir(tcadir); - if (! mkDir("certs")) return; - if (! mkDir("crl")) return; - if (! mkDir("keys")) return; - if (! mkDir("newcerts")) return; - if (! mkDir("req")) return; - - // write the CA cert and key - crt->writeCert("cacert.pem", true, false); - key->writeKey("cacert.key", enc, &MainWindow::passWrite, true); - // write the crl - chdir("crl"); - pki_crl *crl; // FIXME: = genCrl(crt); - crl->writeCrl("crl.pem"); - delete crl; - chdir(".."); - // write the serial - fp = fopen("serial", "w"); - if (!fp) { - fopenerror("serial"); - return; - } - fprintf(fp, "%08lx", crt->getCaSerial().getLong()); - fclose(fp); - - // copy openssl.cnf - tcatempdir += QDir::separator(); - tcatempdir += "openssl.cnf"; - fpr = fopen(tcatempdir, "r"); - if (!fpr) { - fopenerror("openssl.cnf" ); - return; - } - fp = fopen("openssl.cnf", "w"); - if (!fp) { - fopenerror("openssl.cnf" ); - fclose(fpr); - return; - } - while (fgets(buf ,200, fpr) != NULL) { - char *x = strstr(buf,"%dir%"); - if (x != 0) { - x[0]='\0'; - fputs(buf, fp); - fputs(tcadir, fp); - fputs(x+5, fp); - } - else { - fputs(buf, fp); - } - } - fclose(fp); - fclose(fpr); - - // store the issued certificates - fp = fopen("index.txt", "w"); - if (!fp) return; - list = ((db_x509 *)db)->getIssuedCerts(crt); - if (!list.isEmpty()) { - for ( issuedcert = list.first(); issuedcert != NULL; issuedcert = list.next() ) { - QString fname = issuedcert->tinyCAfname(); - chdir("certs"); - crt->writeCert(fname, true, false); - chdir(".."); - key = issuedcert->getRefKey(); - if (key) { - chdir("keys"); - key->writeKey(fname, NULL, &MainWindow::passWrite, true); - chdir(".."); - } - fprintf(fp, "%c\t%s\t%s\t%s\tunknown\t%s\n", - issuedcert->isRevoked() ? 'R':'V', - issuedcert->getNotAfter().toPlain().latin1(), - issuedcert->getRevoked().toPlain().latin1(), - issuedcert->getSerial().toHex().latin1(), - issuedcert->getSubject().oneLine().latin1() ); - - } - } - fclose(fp); - -#endif -} - -void CertView::updateView() -{ - clear(); - setRootIsDecorated(true); - pki_x509 *pki, *signer; - pki_base *pkib; - Q3ListViewItem *parentitem, *current; - QList container = db->getContainer(); - if ( container.isEmpty() ) return; - QList mycont = container; - for ( pkib = container.first(); pkib != NULL; pkib = container.next() ) pkib->delLvi(); - while (! mycont.isEmpty() ) { - QListIterator it(mycont); - for ( ; it.current(); ++it ) { - pki = (pki_x509 *)it.current(); - parentitem = NULL; - signer = pki->getSigner(); - // foreign signed - if ((signer != pki) && (signer != NULL) && (viewState != 0)) - parentitem = signer->getLvi(); - if (((parentitem != NULL) || (signer == pki) || (signer == NULL) - || viewState == 0) && (pki->getLvi() == NULL )) { - // create the listview item - if (parentitem != NULL) { - current = new Q3ListViewItem(parentitem); - } - else { - current = new Q3ListViewItem(this); - } - pki->setLvi(current); - mycont.remove(pki); - pki->updateView(); - it.toFirst(); - } - } - } - return; -} - -bool CertView::mkDir(QString dir) -{ -#ifdef WIN32 - int ret = mkdir(dir.latin1()); - // in direct.h declare _CRTIMP int __cdecl mkdir(const char *); -#else - int ret = mkdir(dir.latin1(), S_IRUSR | S_IWUSR | S_IXUSR); -#endif - if (ret) { - QString desc = " ("; - desc += strerror(ret); - desc += ")"; - QMessageBox::critical(this,tr(XCA_TITLE), - tr("Error creating: ") + dir + desc); - return false; - } - return true; - -} - -void CertView::updateViewAll() -{ - emit init_database(); - QList c = db->getContainer(); - for (pki_x509 *pki = (pki_x509 *)c.first(); pki != 0; pki = (pki_x509 *)c.next() ) - pki->updateView(); - return; -} - -void CertView::genCrl() -{ - emit genCrl((pki_x509 *)getSelected()); -} - -void CertView::importKey(pki_key *key) -{ - MainWindow::keys->insert(key); -} - -void CertView::importCert(pki_x509 *cert) -{ - db->insert(cert); -} - -void CertView::showKey(QString name) -{ - pki_key *key = (pki_key *)MainWindow::keys->getByName(name); - showKey(key); -} - -void CertView::showKey(pki_key *key) -{ - KeyDetail *dlg = NULL; - if (!key) return; - try { - dlg = new KeyDetail(this, 0, true, 0 ); - dlg->setKey(key); - dlg->exec(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (dlg) - delete dlg; -} diff --git a/view/CertView.h b/view/CertView.h deleted file mode 100644 index b03d0c04..00000000 --- a/view/CertView.h +++ /dev/null @@ -1,121 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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$ - * - */ - - -#ifndef CERTVIEW_H -#define CERTVIEW_H - -#include "XcaListView.h" -/* -#include "lib/pki_x509.h" -#include "lib/pki_pkcs12.h" -#include "widgets/NewX509.h" -*/ -class pki_pkcs12; -class NewX509; -class pki_base; -class Q3ListViewItem; -class pki_x509req; -class pki_temp; - -class CertView : public XcaListView -{ - Q_OBJECT - - private: - int viewState; - bool mkDir(QString dir); - - public: - CertView(QWidget * parent = 0, const char * name = 0, Qt::WFlags f=0); - void showItem(pki_base *item, bool import); - void newItem(); - void deleteItem(); - void updateViewItem(pki_base *); - void load(); - // pki_base* insert(pki_base *item); - void store(); - void popupMenu(Q3ListViewItem *item, const QPoint &pt, int x); - void newCert(NewX509 *dlg); - void writePKCS12(QString s, bool chain); - void writePKCS7(QString s, int type); - void changeView(QPushButton *b); - - public slots: - void loadPKCS12(); - void loadPKCS7(); - void extendCert(); - void signP7(); - void encryptP7(); - void setTrust(); - void toRequest(); - void revoke(); - void unRevoke(); - void setSerial(); - void setCrlDays(); - void setTemplate(); - void toTinyCA(); - void updateView(); - void updateViewAll(); - void newCert(pki_x509req *req); - void newCert(pki_temp *req); - void genCrl(); - void importKey(pki_key *key); - void importCert(pki_x509 *cert); - void showKey(pki_key *key); - void showKey(QString name); - - signals: - void genCrl(pki_x509 *); - -}; - -#endif diff --git a/view/CrlView.cpp b/view/CrlView.cpp deleted file mode 100644 index 27f0063d..00000000 --- a/view/CrlView.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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 "CrlView.h" -#include -#include -#include -#include "widgets/CrlDetail.h" -#include "widgets/KeyDetail.h" -#include "widgets/CertDetail.h" -#include "lib/pki_crl.h" -#include "widgets/MainWindow.h" -#include "widgets/clicklabel.h" - -CrlView::CrlView(QWidget * parent, const char * name, Qt::WFlags f) - :XcaListView(parent, name, f) -{ - addColumn(tr("Internal Name")); - addColumn(tr("Issuer Common Name")); - addColumn(tr("Revoked")); -} - - -void CrlView::showCert(Q3ListViewItem *i) -{ - showCert(i->text(0)); -} - -void CrlView::showCert(QString name) -{ - pki_base *item = MainWindow::certs->getByName(name); - if (!item) return; - CertDetail *dlg=NULL; - CHECK_DB - try { - dlg = new CertDetail(this,0,true); - dlg->setCert((pki_x509 *)item); - connect( dlg->privKey, SIGNAL( doubleClicked(QString) ), - this, SLOT( showKey(QString) )); - connect( dlg->signCert, SIGNAL( doubleClicked(QString) ), - this, SLOT( showCert(QString) )); - - dlg->exec(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (dlg) - delete dlg; - return ; -} - -void CrlView::showKey(QString name) -{ - pki_key *key = (pki_key *)MainWindow::keys->getByName(name); - KeyDetail *dlg = NULL; - if (!key) return; - CHECK_DB - try { - dlg = new KeyDetail(this, 0, true, 0 ); - dlg->setKey(key); - dlg->exec(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (dlg) - delete dlg; -} - -void CrlView::showItem(pki_base *item, bool import) -{ - if (!item) return; - CrlDetail *dlg; - CHECK_DB - try { - dlg = new CrlDetail(this,0,true); - dlg->setCrl((pki_crl *)item); - connect( dlg->certList, SIGNAL( doubleClicked(Q3ListViewItem*) ), - this, SLOT( showCert(Q3ListViewItem *) )); - connect( dlg->issuerIntName, SIGNAL( doubleClicked(QString) ), - this, SLOT( showCert(QString) )); - - dlg->exec(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (dlg) - delete dlg; - - return; -} - -void CrlView::deleteItem() -{ - deleteItem_default(tr("The Revocation list"), - tr("is going to be deleted")); -} - -void CrlView::load() -{ - load_crl l; - load_default(l); -} - -void CrlView::writeCrl_pem() -{ - store(true); -} -void CrlView::writeCrl_der() -{ - store(false); -} - -void CrlView::store(bool pem) -{ - pki_crl *crl; - CHECK_DB - - try { - crl = (pki_crl *)getSelected(); - } - catch (errorEx &err) { - Qt::SocketError(err); - return; - } - - if (!crl) return; - QStringList filt; - filt.append("Revocation Lists ( *.crl *.pem)"); - filt.append("All Files ( *.* )"); - QString s=""; - Q3FileDialog *dlg = new Q3FileDialog(this,0,true); - dlg->setCaption(tr("Export Certificate revokation list")); - dlg->setFilters(filt); - dlg->setMode( Q3FileDialog::AnyFile ); - dlg->setSelection( (crl->getIntName() + ".crl") ); - dlg->setDir(MainWindow::getPath()); - - if (dlg->exec()) { - s = dlg->selectedFile(); - MainWindow::setPath(dlg->dirPath()); - } - delete dlg; - if (s.isEmpty()) return; - s=QDir::convertSeparators(s); - try { - crl->writeCrl(s.latin1(), pem); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - -} - - -void CrlView::popupMenu(Q3ListViewItem *item, const QPoint &pt, int x) { - Q3PopupMenu *menu = new Q3PopupMenu(this); - Q3PopupMenu *subExport = new Q3PopupMenu(this); - - if (!item) { - menu->insertItem(tr("Import"), this, SLOT(load())); - } - else { - CHECK_DB - menu->insertItem(tr("Rename"), this, SLOT(startRename())); - menu->insertItem(tr("Show Details"), this, SLOT(showItem())); - menu->insertItem(tr("Export"), subExport); - subExport->insertItem(tr("PEM"), this, SLOT(writeCrl_pem())); - subExport->insertItem(tr("DER"), this, SLOT(writeCrl_der())); - menu->insertItem(tr("Delete"), this, SLOT(deleteItem())); - } - menu->exec(pt); - delete menu; - delete subExport; - - return; -} - -pki_crl *CrlView::newItem(pki_x509 *cert) -{ - if (!cert) return NULL; - QList list; - a1time time; - pki_x509 *issuedcert = NULL; - pki_crl *crl = NULL; - CHECK_DB_NULL - x509v3ext e; - X509V3_CTX ext_ctx; - X509V3_set_ctx(&ext_ctx, cert->getCert() , NULL, NULL, NULL, 0); - X509V3_set_ctx_nodb((&ext_ctx)); - - try { - crl = new pki_crl(); - crl->createCrl(cert->getIntName(), cert); - - list = MainWindow::certs->getIssuedCerts(cert); - if (!list.isEmpty()) { - for ( issuedcert = list.first(); - issuedcert != NULL; issuedcert = list.next() ) - { - if (issuedcert->isRevoked() ) { - crl->addRev(issuedcert->getRev()); - } - } - } - crl->addV3ext(e.create(NID_authority_key_identifier, - "keyid,issuer", &ext_ctx)); - if (cert->hasSubAltName()) { - crl->addV3ext(e.create(NID_issuer_alt_name, - "issuer:copy", &ext_ctx)); - } - crl->setLastUpdate(time.now()); - crl->setNextUpdate(time.now(60*60*24*cert->getCrlDays())); - cert->setLastCrl(time); - crl->sign(cert->getRefKey(), EVP_md5()); - MainWindow::certs->updatePKI(cert); - // FIXME: set Last update - db->insert(crl); - updateView(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - return crl; -} - diff --git a/view/CrlView.h b/view/CrlView.h deleted file mode 100644 index fcdab89c..00000000 --- a/view/CrlView.h +++ /dev/null @@ -1,88 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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$ - * - */ - - -#ifndef CRLVIEW_H -#define CRLVIEW_H - -#include "XcaListView.h" - -class pki_crl; -class Q3ListViewItem; - -class CrlView : public XcaListView -{ - Q_OBJECT - - private: - static const int sizeList[]; - - public: - CrlView(QWidget * parent = NULL, const char * name = 0, Qt::WFlags f = 0); - void showItem(pki_base *item, bool import); - void deleteItem(); - void load(); - pki_base *loadItem(QString fname); - void store(bool); - void popupMenu(Q3ListViewItem *item, const QPoint &pt, int x); - - public slots: - pki_crl *newItem(pki_x509 *cert); - void writeCrl_pem(); - void writeCrl_der(); - - private slots: - void showCert(Q3ListViewItem *i); - void showCert(QString name); - void showKey(QString name); -}; - -#endif diff --git a/view/KeyView.cpp b/view/KeyView.cpp deleted file mode 100644 index b6a9c47c..00000000 --- a/view/KeyView.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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 "KeyView.h" -#include "ui/NewKey.h" -#include "ui/PassRead.h" -#include "ui/PassWrite.h" -#include "widgets/KeyDetail.h" -#include "widgets/ExportKey.h" -#include "widgets/MainWindow.h" -#include "widgets/clicklabel.h" -#include "lib/pki_key.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const int KeyView::sizeList[] = {512, 1024, 2048, 4096, 0 }; - -KeyView::KeyView(QWidget * parent, const char * name, Qt::WFlags f) - :XcaListView(parent, name, f) -{ - addColumn(tr("Internal name")); - addColumn(tr("Keylength")); - addColumn(tr("Use count")); - addColumn(tr("Key type")); -} - -void KeyView::newItem() -{ - CHECK_DB - NewKey_UI *dlg = new NewKey_UI(this,0,true,0); - pki_key *nkey = NULL; - QString x; - int keytypes[] = {EVP_PKEY_RSA, EVP_PKEY_DSA }; - dlg->keyLength->setEditable(true); - for (int i=0; sizeList[i] != 0; i++ ) { - dlg->keyLength->insertItem( x.number(sizeList[i]) +" bit"); - } - dlg->keyLength->setCurrentItem(1); - dlg->image->setPixmap(*MainWindow::keyImg); - if (dlg->exec()) { - try { - QString ksizes = dlg->keyLength->currentText(); - ksizes.replace( QRegExp("[^0-9]"), "" ); - int ksize = ksizes.toInt(); - if (ksize < 32) throw errorEx(tr("Key size too small !")); - if (ksize < 512 || ksize > 4096) - if (!QMessageBox::warning(this, 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(dlg->keyDesc->text()); - nkey->generate(ksize, keytypes[dlg->keyType->currentItem()] ); - - db->insert(nkey); - x = nkey->getIntNameWithType(); - emit keyDone(x); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - } - delete dlg; - updateView(); -} - -void KeyView::deleteItem() -{ - deleteItem_default(tr("The key"), tr("is going to be deleted")); -} - -void KeyView::showItem(pki_base *item, bool import) -{ - pki_key *key = (pki_key *)item; - KeyDetail *dlg = NULL; - if (!key) return; - try { - dlg = new KeyDetail(this, 0, true, 0 ); - dlg->setKey(key); - dlg->exec(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (dlg) - delete dlg; -} - -void KeyView::load() -{ - CHECK_DB - load_key l; - load_default(l); -} - -void KeyView::store() -{ - bool PEM = false; - const EVP_CIPHER *enc = NULL; - pki_key *targetKey = NULL; - targetKey = (pki_key *)getSelected(); - if (!targetKey) return; - ExportKey *dlg = new ExportKey((targetKey->getIntName() + ".pem"), - targetKey->isPubKey(), MainWindow::getPath(), this); - dlg->image->setPixmap(*MainWindow::keyImg); - - if (!dlg->exec()) { - delete dlg; - return; - } - MainWindow::setPath(dlg->dirPath); - QString fname = dlg->filename->text(); - if (fname.isEmpty()) { - delete dlg; - return; - } - try { - if (dlg->exportFormat->currentText() == "PEM") PEM = true; - if (dlg->exportFormat->currentText() == "PKCS#8") - targetKey->writePKCS8(fname, &MainWindow::passWrite); - else if (dlg->exportPrivate->isChecked()) { - if (dlg->encryptKey->isChecked()) - enc = EVP_des_ede3_cbc(); - targetKey->writeKey(fname, enc, &MainWindow::passWrite, PEM); - } - else { - targetKey->writePublic(fname, PEM); - } - } - catch (errorEx &err) { - Qt::SocketError(err); - } - delete dlg; - -} - - -void KeyView::popupMenu(Q3ListViewItem *item, const QPoint &pt, int x) { - Q3PopupMenu *menu = new Q3PopupMenu(this); - if (!item) { - menu->insertItem(tr("New Key"), this, SLOT(newItem())); - menu->insertItem(tr("Import"), this, SLOT(load())); - } - else { - CHECK_DB - menu->insertItem(tr("Rename"), this, SLOT(startRename())); - menu->insertItem(tr("Show Details"), this, SLOT(showItem())); - menu->insertItem(tr("Export"), this, SLOT(store())); - menu->insertItem(tr("Delete"), this, SLOT(deleteItem())); - menu->insertItem(tr("Change password"), this, SLOT(setOwnPass())); - menu->insertItem(tr("Reset password"), this, SLOT(resetOwnPass())); - } - menu->exec(pt); - delete menu; - return; -} - -void KeyView::importKey(pki_key *k) -{ - CHECK_DB - db->insert(k); -} - -void KeyView::setOwnPass() -{ - try { - __setOwnPass(1); - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void KeyView::resetOwnPass() -{ - try { - __setOwnPass(0); - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void KeyView::__setOwnPass(int x) -{ - pki_key *targetKey; - targetKey = (pki_key *)getSelected(); - targetKey->setOwnPass(x); - db->updatePKI(targetKey); -} - -void KeyView::changePasswd() -{ - QString passHash; - QString pass; - bool ret; - DbTxn *tid; - - CHECK_DB - - passHash = MainWindow::settings->getString("pwhash"); - PassRead_UI *dlg = new PassRead_UI(NULL, 0, true); - dlg->image->setPixmap( *MainWindow::keyImg ); - dlg->title->setText(XCA_TITLE); - dlg->description->setText(tr("Please enter the old password of the database.")); - dlg->pass->setFocus(); - dlg->setCaption(XCA_TITLE); - - ret = dlg->exec(); - if (ret) { - pass = dlg->pass->text(); - } - delete dlg; - if (!ret) return; - if (MainWindow::md5passwd(pass.latin1()) != passHash) { - QMessageBox::warning(this, XCA_TITLE, tr("Database password verify error.")); - return; - } - - PassWrite_UI *dlg1 = new PassWrite_UI(NULL, 0, true); - dlg1->image->setPixmap( *MainWindow::keyImg ); - dlg1->title->setText(XCA_TITLE); - dlg1->description->setText(tr("Please enter the new password for the database.")); - dlg1->passA->setFocus(); - dlg1->setCaption(XCA_TITLE); - QString A = "Irgendwas", B=""; - ret = dlg1->exec(); - if (ret) { - A = dlg1->passA->text(); - B = dlg1->passB->text(); - } - delete dlg1; - if (!ret) return; - if (A != B) { - QMessageBox::warning(this, XCA_TITLE, tr("Database password verify error.")); - return; - } - if (A.length() >= MAX_PASS_LENGTH) { - QMessageBox::warning(this, XCA_TITLE, tr("Database password too long: ") + - QString::number(MAX_PASS_LENGTH)); - return; - } - MainWindow::dbenv->txn_begin(NULL, &tid, 0); - B = pki_key::passwd; - strncpy(pki_key::passwd, A.latin1(), MAX_PASS_LENGTH); - try { - db->writeAll(tid); - MainWindow::settings->putString( "pwhash", MainWindow::md5passwd(pki_key::passwd), tid ); - } - catch (DbException &err) { - QString e = err.what(); - /* recover the old password */ - tid->abort(); - strncpy(pki_key::passwd, B.latin1(), MAX_PASS_LENGTH); - errorEx er(e); - Qt::SocketError(er); - } - tid->commit(0); - QMessageBox::information(this, XCA_TITLE, tr("Database password changed successfully.") ); -} - diff --git a/view/KeyView.h b/view/KeyView.h deleted file mode 100644 index c1e0910a..00000000 --- a/view/KeyView.h +++ /dev/null @@ -1,86 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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$ - * - */ - - -#ifndef KEYVIEW_H -#define KEYVIEW_H - -#include "XcaListView.h" - -class pki_base; - -class KeyView : public XcaListView -{ - Q_OBJECT - - private: - static const int sizeList[]; - void __setOwnPass(int x); - public: - KeyView(QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0); - void showItem(pki_base *item, bool import); - void newItem(); - void deleteItem(); - void load(); - // pki_base *insert(pki_base *item); - void store(); - void popupMenu(Q3ListViewItem *item, const QPoint &pt, int x); - public slots: - void importKey(pki_key *k); - void changePasswd(); - void setOwnPass(); - void resetOwnPass(); - signals: - void keyDone(QString); - -}; - -#endif diff --git a/view/Makefile b/view/Makefile deleted file mode 100644 index 9c9596c7..00000000 --- a/view/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# -# $Id$ -# -######################################################################### - -ifeq ($(TOPDIR),) -TOPDIR=.. -endif - -NAMES=CertView CrlView KeyView ReqView TempView XcaListView -OBJS=$(patsubst %, moc_%.o, $(NAMES)) $(patsubst %, %.o, $(NAMES)) -DELFILES=$(patsubst %, moc_%.cpp, $(NAMES)) - -include $(TOPDIR)/Rules.mak - -ifeq ($(DEP), yes) - sinclude .depend -endif diff --git a/view/ReqView.cpp b/view/ReqView.cpp deleted file mode 100644 index 6ab0165b..00000000 --- a/view/ReqView.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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 "ReqView.h" -#include "widgets/ReqDetail.h" -#include "widgets/KeyDetail.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "widgets/MainWindow.h" -#include "widgets/NewX509.h" -#include "widgets/distname.h" -#include "widgets/clicklabel.h" - - -ReqView::ReqView(QWidget * parent, const char * name, Qt::WFlags f) - :XcaListView(parent, name, f) -{ - addColumn(tr("Internal name")); - addColumn(tr("Common Name")); -} - -void ReqView::newItem() -{ - newItem(NULL); -} - -void ReqView::newItem(pki_temp *temp) -{ - CHECK_DB - pki_x509req *req; - NewX509 *dlg = new NewX509(this,0,true); - emit connNewX509(dlg); - - if (temp) { - dlg->defineTemplate(temp); - } - dlg->setRequest(); - if (! dlg->exec()){ - delete dlg; - return; - } - try { - const EVP_MD *hashAlgo = dlg->getHashAlgo(); - pki_key *key = dlg->getSelectedKey(); - x509name xn = dlg->getX509name(); - req = new pki_x509req(); - - req->setIntName(dlg->description->text()); - if (key->getType() == EVP_PKEY_DSA) - hashAlgo = EVP_dss1(); - - req->createReq(key, xn, hashAlgo, dlg->getAllExt()); - db->insert(req); - } - catch (errorEx &err) { - delete req; - Qt::SocketError(err); - } -} - - - -void ReqView::showItem(pki_base *item, bool import) -{ - if (!item) return; - ReqDetail *dlg = NULL; - try { - dlg = new ReqDetail(this,0,true); - dlg->setReq((pki_x509req *)item); - connect(dlg->privKey, SIGNAL(doubleClicked(QString)), - this, SLOT(showKey(QString))); - dlg->exec(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (dlg) - delete dlg; -} - -void ReqView::deleteItem() -{ - deleteItem_default(tr("The Certificate signing request"), - tr("is going to be deleted")); -} - -void ReqView::load() -{ - load_req l; - load_default(l); -} - -void ReqView::writeReq_pem() { store(true); } -void ReqView::writeReq_der() { store(false); } - -void ReqView::store(bool pem) -{ - pki_x509req *req; - try { - req = (pki_x509req *)getSelected(); - } - catch (errorEx &err) { - Qt::SocketError(err); - return; - } - - if (!req) return; - QStringList filt; - filt.append("PKCS#10 CSR ( *.pem *.der *.csr )"); - filt.append("All Files ( *.* )"); - QString s=""; - Q3FileDialog *dlg = new Q3FileDialog(this,0,true); - dlg->setCaption(tr("Export Certificate signing request")); - dlg->setFilters(filt); - dlg->setMode( Q3FileDialog::AnyFile ); - dlg->setSelection( req->getIntName() + ".csr" ); - dlg->setDir(MainWindow::getPath()); - if (dlg->exec()) { - s = dlg->selectedFile(); - MainWindow::setPath(dlg->dirPath()); - } - delete dlg; - if (s.isEmpty()) return; - s=QDir::convertSeparators(s); - try { - req->writeReq(s, pem); - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void ReqView::signReq() -{ - pki_x509req *req; - try { - req = (pki_x509req *)getSelected(); - } - catch (errorEx &err) { - Qt::SocketError(err); - return; - } - newCert(req); -} - -void ReqView::popupMenu(Q3ListViewItem *item, const QPoint &pt, int x) { - Q3PopupMenu *menu = new Q3PopupMenu(this); - Q3PopupMenu *subExport = new Q3PopupMenu(this); - int itemExport; - - if (!item) { - menu->insertItem(tr("New Request"), this, SLOT(newItem())); - menu->insertItem(tr("Import"), this, SLOT(load())); - } - else { - CHECK_DB - pki_x509req *req = (pki_x509req *)db->getByName(item->text(0)); - menu->insertItem(tr("Rename"), this, SLOT(startRename())); - menu->insertItem(tr("Show Details"), this, SLOT(showItem())); - menu->insertItem(tr("Sign"), this, SLOT(signReq())); - itemExport = menu->insertItem(tr("Export"), subExport); - subExport->insertItem(tr("PEM"), this, SLOT(writeReq_pem())); - subExport->insertItem(tr("DER"), this, SLOT(writeReq_der())); - menu->insertItem(tr("Delete"), this, SLOT(deleteItem())); - menu->setItemEnabled(itemExport, ! req->isSpki()); - } - menu->exec(pt); - delete menu; - delete subExport; - return; -} - -void ReqView::showKey(QString name) -{ - pki_key *key = (pki_key *)MainWindow::keys->getByName(name); - showKey(key); -} - -void ReqView::showKey(pki_key *key) -{ - KeyDetail *dlg = NULL; - if (!key) return; - try { - dlg = new KeyDetail(this, 0, true, 0 ); - dlg->setKey(key); - dlg->exec(); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - if (dlg) - delete dlg; -} diff --git a/view/ReqView.h b/view/ReqView.h deleted file mode 100644 index 01414b1a..00000000 --- a/view/ReqView.h +++ /dev/null @@ -1,88 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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$ - * - */ - - -#ifndef REQVIEW_H -#define REQVIEW_H - -#include "XcaListView.h" -#include "lib/pki_x509req.h" -#include "lib/pki_temp.h" -#include "widgets/NewX509.h" - - -class ReqView : public XcaListView -{ - Q_OBJECT - - public: - ReqView(QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0); - void showItem(pki_base *item, bool import); - void newItem(); - void deleteItem(); - void load(); - void updateViewItem(pki_base *); - pki_base *loadItem(QString fname); - void store(bool pem); - void popupMenu(Q3ListViewItem *item, const QPoint &pt, int x); - public slots: - void writeReq_pem(); - void writeReq_der(); - void signReq(); - void newItem(pki_temp *temp); - void showKey(pki_key *key); - void showKey(QString name); - signals: - void newCert(pki_x509req *req); - -}; - -#endif diff --git a/view/TempView.cpp b/view/TempView.cpp deleted file mode 100644 index ea5b6010..00000000 --- a/view/TempView.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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 "TempView.h" -#include "widgets/MainWindow.h" -#include "widgets/NewX509.h" -#include -#include - -TempView::TempView(QWidget * parent, const char * name, Qt::WFlags f) - :XcaListView(parent, name, f) -{ - addColumn(tr("Internal name")); - addColumn(tr("Type")); -} - -bool TempView::runTempDlg(pki_temp *temp) -{ - NewX509 *dlg = new NewX509(this, NULL, true); - emit connNewX509(dlg); - - dlg->setTemp(temp); - dlg->fromTemplate(temp); - if (!dlg->exec()) { - delete dlg; - return false; - } - dlg->toTemplate(temp); - delete dlg; - return true; -} - -void TempView::newEmptyTemp() -{ - newItem(pki_temp::EMPTY); -} - -void TempView::newCaTemp() -{ - newItem(pki_temp::CA); -} - -void TempView::newClientTemp() -{ - newItem(pki_temp::CLIENT); -} - -void TempView::newServerTemp() -{ - newItem(pki_temp::SERVER); -} - -void TempView::newItem(int type) -{ - CHECK_DB - pki_temp *temp = new pki_temp("--", type); - if (runTempDlg(temp)) { - db->insert(temp); - } - else { - delete temp; - } -} - -void TempView::alterTemp() -{ - alterTemp((pki_temp *)getSelected()); -} - -bool TempView::alterTemp(pki_temp *temp) -{ - QString oldname = temp->getIntName(); - if (!runTempDlg(temp)) return false; - QString newname = temp->getIntName(); - if (newname!= oldname) { - temp->setIntName(oldname); - MainWindow::temps->renamePKI(temp, newname); - } - MainWindow::temps->updatePKI(temp); - return true; -} - -void TempView::showItem(pki_base *item, bool import) -{ - pki_temp *temp = (pki_temp *)item; - if (!temp) return; - alterTemp(temp); -} - - -void TempView::deleteItem() -{ - deleteItem_default(tr("The Template"), tr("is going to be deleted")); -} - -void TempView::load() -{ - load_temp l; - load_default(l); -} - -void TempView::store() -{ - pki_temp *temp; - try { - temp = (pki_temp *)getSelected(); - } - catch (errorEx &err) { - Qt::SocketError(err); - return; - } - - if (!temp) return; - QStringList filt; - filt.append("XCA Templates ( *.xca )"); - filt.append("All Files ( *.* )"); - QString s=""; - Q3FileDialog *dlg = new Q3FileDialog(this,0,true); - dlg->setCaption(tr("Export Template")); - dlg->setFilters(filt); - dlg->setMode( Q3FileDialog::AnyFile ); - dlg->setSelection( temp->getIntName() + ".xca" ); - dlg->setDir(MainWindow::getPath()); - if (dlg->exec()) { - s = dlg->selectedFile(); - MainWindow::setPath(dlg->dirPath()); - } - delete dlg; - if (s.isEmpty()) return; - s=QDir::convertSeparators(s); - try { - temp->writeTemp(s); - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void TempView::certFromTemp() -{ - pki_temp *temp = (pki_temp *)getSelected(); - newCert(temp); -} - -void TempView::reqFromTemp() -{ - pki_temp *temp = (pki_temp *)getSelected(); - newReq(temp); -} - -void TempView::popupMenu(Q3ListViewItem *item, const QPoint &pt, int x) -{ - Q3PopupMenu *menu = new Q3PopupMenu(this); - Q3PopupMenu *subMenu = new Q3PopupMenu(this); - if (!item) { - menu->insertItem(tr("New Template"), subMenu); - subMenu->insertItem(tr("Empty"), this, SLOT(newEmptyTemp())); - subMenu->insertItem(tr("CA"), this, SLOT(newCaTemp())); - subMenu->insertItem(tr("Client"), this, SLOT(newClientTemp())); - subMenu->insertItem(tr("Server"), this, SLOT(newServerTemp())); - menu->insertItem(tr("Import"), this, SLOT(load())); - - } - else { - menu->insertItem(tr("Rename"), this, SLOT(startRename())); - menu->insertItem(tr("Export"), this, SLOT(store())); - menu->insertItem(tr("Change"), this, SLOT(alterTemp())); - menu->insertItem(tr("Delete"), this, SLOT(deleteItem())); - menu->insertItem(tr("Create certificate"), this, SLOT(certFromTemp())); - menu->insertItem(tr("Create request"), this, SLOT(reqFromTemp())); - } - menu->exec(pt); - delete menu; - delete subMenu; - return; -} diff --git a/view/TempView.h b/view/TempView.h deleted file mode 100644 index dc161d93..00000000 --- a/view/TempView.h +++ /dev/null @@ -1,100 +0,0 @@ - -//Added by the Qt porting tool: -#include - -/* vi: set sw=4 ts=4: */ -/* - * 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$ - * - */ - - -#ifndef TEMPVIEW_H -#define TEMPVIEW_H - -#include "XcaListView.h" -#include "lib/pki_temp.h" -#ifdef qt4 -#include -#else -#include -#endif - - -class TempView : public XcaListView -{ - Q_OBJECT - - private: - QPixmap *keyicon; - bool runTempDlg(pki_temp *); - public: - TempView(QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0); - void showItem(pki_base *item, bool import); - void newItem(int type); - void updateViewItem(pki_base *); - bool alterTemp(pki_temp *); - void popupMenu(Q3ListViewItem *item, const QPoint &pt, int x); - pki_base *loadItem(QString fname); - public slots: - void newEmptyTemp(); - void newCaTemp(); - void newClientTemp(); - void newServerTemp(); - void certFromTemp(); - void reqFromTemp(); - void alterTemp(); - void deleteItem(); - void store(); - void load(); - signals: - void newReq(pki_temp *); - void newCert(pki_temp *); -}; - -#endif diff --git a/view/XcaListView.cpp b/view/XcaListView.cpp deleted file mode 100644 index 9cd2d07b..00000000 --- a/view/XcaListView.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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 "XcaListView.h" -#include "widgets/MainWindow.h" -#include "widgets/ImportMulti.h" -#include -#include -#include - -XcaListView::XcaListView( QWidget * parent, const char * name, Qt::WFlags f) - :Q3ListView(parent, name, f) -{ -#ifdef qt3 - connect( this, SIGNAL(itemRenamed(Q3ListViewItem *, int, const QString &)), - this, SLOT(rename(Q3ListViewItem *, int, const QString &))); -#endif - connect( this, SIGNAL(rightButtonPressed(Q3ListViewItem *, const QPoint &, int)), - this, SLOT(popupMenu(Q3ListViewItem *, const QPoint &, int))) ; - - connect( this, SIGNAL(doubleClicked(Q3ListViewItem *)), - this, SLOT(showItem(Q3ListViewItem *))) ; -} - -void XcaListView::setDB(db_base *mydb) -{ - db = mydb; - updateView(); -} - -void XcaListView::rmDB(db_base *mydb) -{ - db = NULL; - clear(); -} - -void XcaListView::loadCont() -{ - CHECK_DB - db->loadContainer(); - updateView(); -} - -pki_base *XcaListView::getSelected() -{ - CHECK_DB_NULL - Q3ListViewItem *lvi = selectedItem(); - if (!lvi) return NULL; - QString name = lvi->text(0); - return db->getByName(name); -} - -void XcaListView::showItem() -{ - showItem(getSelected(), false); -} - -void XcaListView::showItem(QString name) -{ - showItem(db->getByName(name), false); -} - -void XcaListView::showItem(Q3ListViewItem *item) -{ - showItem(db->getByName(item->text(0)), false); -} - -void XcaListView::rename(Q3ListViewItem *item, int col, const QString &text) -{ - CHECK_DB - try { - pki_base *pki = db->getByPtr(item); - db->renamePKI(pki, text); - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void XcaListView::startRename() -{ - CHECK_DB - try { -#ifdef qt3 - Q3ListViewItem *item = selectedItem(); - if (item == NULL) return; - item->startRename(0); -#else - renameDialog(); -#endif - } - catch (errorEx &err) { - Qt::SocketError(err); - } -} - -void XcaListView::renameDialog() -{ - pki_base * pki = getSelected(); - if (!pki) return; - QString name= pki->getIntName(); - bool ok; - QString nname = QInputDialog::getText (XCA_TITLE, "Please enter the new name", - QLineEdit::Normal, name, &ok, this ); - if (ok && name != nname) { - db->renamePKI(pki, nname); - pki->getLvi()->setText(0, pki->getIntName()); - - } -} - -void XcaListView::deleteItem_default(QString t1, QString t2) -{ - pki_base *del = getSelected(); - if (!del) return; - if (QMessageBox::information(this,tr(XCA_TITLE), - t1 + ": '" + del->getIntName() + "'\n" + t2, - tr("Delete"), tr("Cancel")) - ) return; - try { - db->deletePKI(del); - } - catch (errorEx &err) { - Qt::SocketError(err); - } - updateView(); -} - -void XcaListView::load_default(load_base &load) -{ -#if 0 - CRYPTO_remove_all_info(); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - fprintf(stderr, "loadContainer:\n"); - CRYPTO_mem_leaks_fp(stderr); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF); -#endif - QStringList slist; - - Q3FileDialog *dlg = new Q3FileDialog(this,0,true); - CHECK_DB - - dlg->setCaption(load.caption); - dlg->setFilters(load.filter); - dlg->setMode( Q3FileDialog::ExistingFiles ); - dlg->setDir(MainWindow::getPath()); - if (dlg->exec()) { - slist = dlg->selectedFiles(); - MainWindow::setPath(dlg->dirPath()); - } - delete dlg; - - ImportMulti *dlgi = NULL; - dlgi = new ImportMulti(this, NULL, true); - for ( QStringList::Iterator it = slist.begin(); it != slist.end(); ++it ) { - QString s = *it; - s = QDir::convertSeparators(s); - pki_base *item = NULL; - try { - item = load.loadItem(s); - } - catch (errorEx &err) { - Qt::SocketError(err); - if (item) { - delete item; - item = NULL; - } - } - dlgi->addItem(item); - } - dlgi->execute(); - delete dlgi; - updateView(); -} - -void XcaListView::Error(errorEx &err) -{ - MainWindow::Error(err); -} - -bool XcaListView::Error(pki_base *pki) -{ - if (!pki) { - QMessageBox::warning(this,tr(XCA_TITLE), tr("The system detected a NULL pointer, maybe the system is out of memory" )); - qFatal("NULL pointer detected - Exiting"); - } - - return false; -} - -void XcaListView::updateView() -{ - CHECK_DB - clear(); - QList container; - pki_base *pki; - container = db->getContainer(); - if (container.isEmpty()) return; - for ( pki = container.first(); pki != NULL; pki = container.next() ) pki->delLvi(); - QListIterator it(container); - for ( ; it.current(); ++it ) { - pki = it.current(); - Q3ListViewItem *lvi = new Q3ListViewItem(this, pki->getIntName()); - insertItem(lvi); - pki->setLvi(lvi); - pki->updateView(); - } -} - -void XcaListView::newItem(void) { } -void XcaListView::deleteItem(void) { } -void XcaListView::load(void) { } -void XcaListView::store(void) { } -void XcaListView::popupMenu(Q3ListViewItem *, QPoint const &, int) { } -void XcaListView::showItem(pki_base *, bool) { } - diff --git a/view/XcaListView.h b/view/XcaListView.h deleted file mode 100644 index 1abed3e1..00000000 --- a/view/XcaListView.h +++ /dev/null @@ -1,103 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * 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$ - * - */ - - -#ifndef XCALISTVIEW_H -#define XCALISTVIEW_H -#include -#include "lib/db_base.h" -#include "lib/load_obj.h" -#include "lib/exception.h" -#include "widgets/NewX509.h" - -#define CHECK_DB emit init_database(); if (!MainWindow::dbenv) return; -#define CHECK_DB_NULL emit init_database(); if (!MainWindow::dbenv) return NULL; - -class XcaListView : public Q3ListView -{ - Q_OBJECT - - protected: - db_base *db; - - public: - XcaListView(QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0); - void setDB(db_base *mydb); - void rmDB(db_base *mydb); - virtual pki_base *getSelected(); - virtual void showItem(pki_base *item, bool import); - void deleteItem_default(QString t1, QString t2); - void load_default(QStringList &filter, QString caption); - void load_default(load_base &load); - void setDB(db_base *mydb, QPixmap *myimage); - void Qt::SocketError(errorEx &err); - bool Qt::SocketError(pki_base *pki); - void loadCont(); - public slots: - virtual void newItem(); - virtual void deleteItem(); - void showItem(); - void showItem(QString name); - void showItem(Q3ListViewItem *item); - virtual void load(); - virtual void store(); - virtual void popupMenu(Q3ListViewItem *item, const QPoint &pt, int x); - void startRename(); - void renameDialog(); - void rename(Q3ListViewItem *item, int col, const QString &text); - virtual void updateView(); - signals: - void init_database(); - void connNewX509(NewX509 *); - void showKey(QString name); -}; - -#endif diff --git a/widgets/MainWindow.cpp b/widgets/MainWindow.cpp index 5686c130..0a16a239 100644 --- a/widgets/MainWindow.cpp +++ b/widgets/MainWindow.cpp @@ -423,7 +423,7 @@ int MainWindow::passWrite(char *buf, int size, int rwflag, void *userdata) dlg->show(); dlg->activateWindow(); ui.passA->setFocus(); - + if (dlg->exec()) { QString A = ui.passA->text(); QString B = ui.passB->text(); diff --git a/widgets/clicklabel.h b/widgets/clicklabel.h index 86d71c58..e747798a 100644 --- a/widgets/clicklabel.h +++ b/widgets/clicklabel.h @@ -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,12 +34,12 @@ * 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 @@ -47,7 +47,7 @@ * * $Id$ * - */ + */ #ifndef CLICKLABEL_H #define CLICKLABEL_H @@ -57,18 +57,18 @@ class QMouseEvent; class ClickLabel : public QLabel -{ +{ Q_OBJECT public: ClickLabel(QWidget *parent); void setRed(); void setGreen(); - + protected: void mouseDoubleClickEvent ( QMouseEvent * e ); void setColor(const QColor &col); - + signals: void doubleClicked(QString text); };