From 86f52eba508caed660bdc6d26836790bfc37e07e Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 6 Mar 2002 23:05:49 +0000 Subject: [PATCH] Certificates are now generated well, they can be loaded and stored. --- MainWindow.h | 3 + MainWindow.ui | 126 +++++++++------- MainWindowX509.cpp | 29 ++-- MainWindowX509Req.cpp | 1 + Makefile | 2 +- ReqDetail.ui | 334 +++++++++++++++++++++++++----------------- lib/pki_x509.cpp | 27 +++- lib/pki_x509.h | 3 +- 8 files changed, 318 insertions(+), 207 deletions(-) diff --git a/MainWindow.h b/MainWindow.h index 1caa67ac..74621d71 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -54,6 +54,7 @@ class MainWindow: public MainWindow_UI public slots: void loadKey(); void loadReq(); + void loadCert(); void newKey(); void newReq(); void newCert(); @@ -61,7 +62,9 @@ class MainWindow: public MainWindow_UI void showDetailsReq(); void deleteKey(); void deleteReq(); + void deleteCert(); void writeKey(); void writeReq(); + void writeCert(); }; #endif diff --git a/MainWindow.ui b/MainWindow.ui index 7375f655..12d35dc7 100644 --- a/MainWindow.ui +++ b/MainWindow.ui @@ -11,7 +11,7 @@ 0 0 - 600 + 596 533 @@ -261,7 +261,7 @@ title - Signing Request + Unterschriftsanfrage QFrame @@ -461,26 +461,6 @@ frameShadow Sunken - - QPushButton - - name - PushButton26_2 - - - geometry - - 20 - 180 - 190 - 32 - - - - text - Löschen - - QLabel @@ -505,26 +485,6 @@ true - - QPushButton - - name - PushButton47_2 - - - geometry - - 20 - 60 - 190 - 32 - - - - text - Exportieren - - QPushButton @@ -585,6 +545,46 @@ Neues Zertifikat erstellen + + QPushButton + + name + PushButton47_2 + + + geometry + + 20 + 60 + 190 + 32 + + + + text + Exportieren + + + + QPushButton + + name + PushButton26_2 + + + geometry + + 20 + 180 + 190 + 32 + + + + text + Löschen + + QListBox @@ -637,12 +637,6 @@ MainWindow_UI newKey() - - renameKey - clicked() - MainWindow_UI - deleteKey() - detailsKey clicked() @@ -709,15 +703,49 @@ MainWindow_UI newCert() + + PushButton47_2 + clicked() + MainWindow_UI + writeCert() + + + PushButton46_2 + clicked() + MainWindow_UI + loadCert() + + + PushButton25_2 + clicked() + MainWindow_UI + showDetailsCert() + + + PushButton26_2 + clicked() + MainWindow_UI + deleteCert() + + + renameKey + clicked() + MainWindow_UI + deleteKey() + + deleteCert() deleteKey() deleteReq() + loadCert() loadKey() loadReq() + newCert() newKey() newReq() - newCert() + showDetailsCert() showDetailsKey() showDetailsReq() + writeCert() writeKey() writeReq() diff --git a/MainWindowX509.cpp b/MainWindowX509.cpp index 7d698920..703920d7 100644 --- a/MainWindowX509.cpp +++ b/MainWindowX509.cpp @@ -74,13 +74,13 @@ void MainWindow::showDetailsReq() certs->updatePKI(cert, ndesc); } } - -void MainWindow::deleteReq() +*/ +void MainWindow::deleteCert() { pki_x509 *cert = (pki_x509 *)certs->getSelectedPKI(); if (!cert) return; - if (QMessageBox::information(this,"Zertifikatsanfrage löschen", - ("Möchten Sie die Zertifikatsanfrage: '" + + if (QMessageBox::information(this,"Zertifikat löschen", + ("Möchten Sie das Zertifikat: '" + cert->getDescription() + "'\nwirklich löschen ?\n").c_str(), "Löschen", "Abbrechen") @@ -88,14 +88,14 @@ void MainWindow::deleteReq() certs->deletePKI(cert); } -void MainWindow::loadReq() +void MainWindow::loadCert() { QStringList filt; - filt.append( "Zertifikatsanfragen ( *.pem *.der )"); + filt.append( "Zertifikate ( *.pem *.der )"); filt.append("Alle Dateien ( *.* )"); string s; QFileDialog *dlg = new QFileDialog(this,0,true); - dlg->setCaption("Anfrage importieren"); + dlg->setCaption("Zertifikat importieren"); dlg->setFilters(filt); if (dlg->exec()) s = dlg->selectedFile().latin1(); @@ -104,14 +104,14 @@ void MainWindow::loadReq() string errtxt; if ((errtxt = cert->getError()) != "") { QMessageBox::warning(this,"Datei Fehler", - ("Die Zertifikatsanfrage: '" + s + + ("Das Zertifikat: '" + s + "'\nkonnte nicht geladen werden:\n" + errtxt).c_str()); return; } pki_x509 *oldcert = (pki_x509 *)certs->findPKI(cert); if (oldcert) { - QMessageBox::information(this,"Zertifikatsanfragen import", - ("Die Zertifikatsanfrage ist bereits vorhanden als:\n'" + + QMessageBox::information(this,"Zertifikats import", + ("Das Zertifikat ist bereits vorhanden als:\n'" + oldcert->getDescription() + "'\nund wurde daher nicht importiert").c_str(), "OK"); delete(oldcert); @@ -120,14 +120,14 @@ void MainWindow::loadReq() certs->insertPKI(cert); } -void MainWindow::writeReq() +void MainWindow::writeCert() { QStringList filt; - filt.append( "Zertifikatsanfragen ( *.pem *.der )"); + filt.append( "Zertifikat ( *.pem *.der )"); filt.append("Alle Dateien ( *.* )"); string s; QFileDialog *dlg = new QFileDialog(this,0,true); - dlg->setCaption("Anfrage exportieren"); + dlg->setCaption("Zertifikat exportieren"); dlg->setFilters(filt); if (dlg->exec()) s = dlg->selectedFile().latin1(); @@ -138,10 +138,9 @@ void MainWindow::writeReq() string errtxt; if ((errtxt = cert->getError()) != "") { QMessageBox::warning(this,"Datei Fehler", - ("Die Zertifikatsanfrage: '" + s + + ("Das Zertifikat: '" + s + "'\nkonnte nicht gespeichert werden:\n" + errtxt).c_str()); return; } } } -*/ diff --git a/MainWindowX509Req.cpp b/MainWindowX509Req.cpp index b22b2f3b..60ac047f 100644 --- a/MainWindowX509Req.cpp +++ b/MainWindowX509Req.cpp @@ -51,6 +51,7 @@ void MainWindow::showDetailsReq() { dlg->keyPubEx->setText(key->pubEx().c_str()); dlg->keyModulus->setText(key->modulus().c_str()); + dlg->keySize->setText(key->length().c_str()); pki_key *existkey = (pki_key *)keys->findPKI(key); if (existkey) { if (!existkey->isPubKey()) { diff --git a/Makefile b/Makefile index 971d9500..f03e1897 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VERSION=0.1.7 -TAG=$(shell echo "V.$(VERSION)" |sed "s/\./_/g") +TAG=$(shell echo "V.$(VERSION)" |sed "s/\./_/g" ) TARGET=xca-$(VERSION) GCC=g++ -Wall INC=-I$(QTDIR)/include diff --git a/ReqDetail.ui b/ReqDetail.ui index d4dd3bff..f185836c 100644 --- a/ReqDetail.ui +++ b/ReqDetail.ui @@ -11,7 +11,7 @@ 0 0 - 526 + 518 660 @@ -34,6 +34,14 @@ 100 + + frameShape + Box + + + frameShadow + Sunken + title Allgemeines @@ -850,62 +858,6 @@ - - QLabel - - name - dnL - - - geometry - - 50 - 60 - 160 - 20 - - - - frameShape - Panel - - - frameShadow - Sunken - - - text - - - - - QLabel - - name - dnCN - - - geometry - - 50 - 90 - 160 - 20 - - - - frameShape - Panel - - - frameShadow - Sunken - - - text - - - QLabel @@ -990,6 +942,114 @@ + + QLabel + + name + dnCN + + + geometry + + 50 + 90 + 160 + 20 + + + + frameShape + Panel + + + frameShadow + Sunken + + + text + + + + + QLabel + + name + dnL + + + geometry + + 50 + 60 + 160 + 20 + + + + frameShape + Panel + + + frameShadow + Sunken + + + text + + + + + + QLabel + + name + TextLabel1 + + + geometry + + 20 + 10 + 250 + 30 + + + + font + + 14 + 1 + 1 + + + + text + Details der Unterschriftsanfrage + + + + QLabel + + name + PixmapLabel2 + + + geometry + + 400 + 10 + 100 + 47 + + + + pixmap + image0 + + + scaledContents + true + QGroupBox @@ -1010,34 +1070,6 @@ title Schlüssel - - QLabel - - name - keyPubEx - - - geometry - - 120 - 30 - 350 - 20 - - - - frameShape - Panel - - - frameShadow - Sunken - - - text - - - QLabel @@ -1105,6 +1137,10 @@ text + + alignment + WordBreak|AlignTop|AlignLeft + vAlign @@ -1112,58 +1148,82 @@ wordwrap - - - QLabel - - name - TextLabel1 - - - geometry - - 20 - 10 - 250 - 30 - - - - font - - 14 - 1 - 1 - - - - text - Details der Unterschriftsanfrage - - - - QLabel - - name - PixmapLabel2 - - - geometry - - 400 - 10 - 100 - 47 - - - - pixmap - image0 - - - scaledContents - true - + + QLabel + + name + keyPubEx + + + geometry + + 120 + 30 + 130 + 20 + + + + frameShape + Panel + + + frameShadow + Sunken + + + text + + + + + QLabel + + name + keySize + + + geometry + + 360 + 30 + 110 + 20 + + + + frameShape + Panel + + + frameShadow + Sunken + + + text + + + + + QLabel + + name + TextLabel1_2 + + + geometry + + 270 + 30 + 90 + 20 + + + + text + Schlüssellänge: + + diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp index f870578f..a2b9c386 100644 --- a/lib/pki_x509.cpp +++ b/lib/pki_x509.cpp @@ -6,7 +6,7 @@ pki_x509::pki_x509(pki_key *key, const string cn, const string c, const string l, const string st,const string o, const string ou,const string email, - const string d) + const string d,int days=365) :pki_base( d ) { cert = X509_new(); @@ -38,7 +38,26 @@ pki_x509::pki_x509(pki_key *key, const string cn, (unsigned char*)email.c_str() , -1, -1, 0); const EVP_MD *digest = EVP_md5(); - X509_sign(cert, key->key, digest); + + /* Set version to V3 */ + if(!X509_set_version(cert, 2)) { + error="set Version faoiled"; + return; + } + ASN1_INTEGER_set(X509_get_serialNumber(cert),0L); + + X509_set_issuer_name(cert,subj); + X509_gmtime_adj(X509_get_notBefore(cert),0); + X509_gmtime_adj(X509_get_notAfter(cert), (long)60*60*24*days); + + /* Set up V3 context struct */ + X509V3_CTX ext_ctx; + + X509V3_set_ctx(&ext_ctx, cert, cert, NULL, NULL, 0); + + if (!X509_sign(cert, key->key, digest)) { + error="Error signing the request"; + } openssl_error(); } @@ -60,12 +79,12 @@ pki_x509::pki_x509(const string fname) if (!cert) { openssl_error(); rewind(fp); - printf("Fallback to private key DER\n"); + printf("Fallback to certificate DER\n"); cert = d2i_X509_fp(fp, NULL); } int r = fname.rfind('.'); int l = fname.rfind('/'); - desc = fname.substr(l,r); + desc = fname.substr(l+1,r-l-1); if (desc == "") desc = fname; openssl_error(); } diff --git a/lib/pki_x509.h b/lib/pki_x509.h index b6cc8c7a..ce065b71 100644 --- a/lib/pki_x509.h +++ b/lib/pki_x509.h @@ -1,5 +1,6 @@ #include #include +#include #include #include "pki_key.h" @@ -14,7 +15,7 @@ class pki_x509 : public pki_base const string c, const string l, const string st,const string o, const string ou,const string email, - const string d); + const string d, int days=365); pki_x509(); pki_x509(const string fname); virtual void fromData(unsigned char *p, int size);