Issuer and subject alternative name added to v3 extensions

certificate wizard completed and fixed.
when generating new key in req/cert dialog the new key is selected
added intelligence to NewRequest dialog
Messagebox "Key inserted" removed
This commit is contained in:
chris 2002-09-16 23:10:59 +00:00
parent ebfd53012a
commit 85cb1ababe
11 changed files with 358 additions and 91 deletions

View File

@ -56,7 +56,7 @@
#include "PassRead_UI.h"
#include "PassWrite_UI.h"
#include "NewKey_UI.h"
#include "NewX509Req_UI.h"
#include "NewX509Req.h"
#include "NewX509.h"
#include "NewX509_UI.h"
#include "Rename_UI.h"
@ -104,6 +104,8 @@
class MainWindow: public MainWindow_UI
{
Q_OBJECT
protected:
void addStr(string &str, char *add);
friend class pki_key;
db_x509 *certs;
db_x509req *reqs;
@ -166,5 +168,7 @@ class MainWindow: public MainWindow_UI
void renameKey(QListViewItem *item, int col, const QString &text);
void renameReq(QListViewItem *item, int col, const QString &text);
void renameCert(QListViewItem *item, int col, const QString &text);
signals:
void keyDone(QString name);
};
#endif

View File

@ -92,6 +92,8 @@ void MainWindow::newKey()
sizeList[sel]);
progress->cancel();
insertKey(nkey);
x=nkey->getDescription().c_str();
emit keyDone(x);
}
}
@ -208,11 +210,7 @@ void MainWindow::insertKey(pki_key *lkey)
}
}
CERR << "after findkey\n";
if (keys->insertPKI(lkey))
QMessageBox::information(this,title,
tr("The Key was successfully stored as:\n'") +
QString::fromLatin1(lkey->getDescription().c_str()) + "'", "OK");
else
if (!keys->insertPKI(lkey))
QMessageBox::warning(this,title,
tr("The key could not be stored into the database"), "OK");

View File

@ -59,7 +59,7 @@ void MainWindow::newCert()
pki_x509req *req = NULL;
pki_key *signkey = NULL, *clientkey = NULL;
int serial = 42; // :-)
int i, retval;
int i;
NewX509 *dlg = new NewX509(this, NULL, keys, reqs);
QStringList strlist = certs->getSignerDesc();
if (strlist.isEmpty()) {
@ -69,14 +69,6 @@ void MainWindow::newCert()
else {
dlg->certList->insertStringList(strlist);
}
CERR <<" Everything created A" << endl;
// preset dialogs with images
for (i=0;i<4;i++) {
CERR <<" Everything created :" << i << endl;
//dlg[i]->image->setPixmap(*certImg);
}
CERR <<" Everything created V" << endl;
i=0;
if (!dlg->exec()) return;
@ -105,14 +97,6 @@ void MainWindow::newCert()
}
// Step 2 - select Signing
/*
if (dlg->fromDataRB->isChecked())
// if we entered subjectdata, selfsigning is default
dlg->selfSignRB->setChecked(true);
else
// for PKCS#10 signing foreignKey signing is default
dlg->foreignSignRB->setChecked(true);
*/
if (dlg->foreignSignRB->isChecked()) {
signcert = (pki_x509 *)certs->getSelectedPKI(dlg->certList->currentText().latin1());
if (opensslError(signcert)) return;
@ -158,7 +142,6 @@ void MainWindow::newCert()
constraints += pathstr;
}
cert->addV3ext(NID_basic_constraints, constraints);
CERR << "B-Const:" << constraints << endl;
// Subject Key identifier
if (dlg->subKey->isChecked()) {
string subkey="hash";
@ -172,24 +155,16 @@ void MainWindow::newCert()
CERR << authkey <<endl;
}
// STEP 4
// Subject Alternative name
string subAlt = dlg->subAltURL->text().latin1();
//if (subAlt != "") {
// key usage
char *keyusage[] ={"digitalSignature", "nonRepudiation", "keyEncipherment",
"dataEncipherment", "keyAgreement", "keyCertSign",
"cRLSign", "encipherOnly", "decipherOnly"};
QListBoxItem *item;
i=0;
string keyuse, keyuse1;
while ((item = dlg->keyUsage->item(i))) {
for (i=0; (item = dlg->keyUsage->item(i)); i++) {
if (item->selected()){
if (keyuse.length() > 0) keyuse +=", ";
keyuse += keyusage[i];
addStr(keyuse, keyusage[i]);
}
i++;
}
if (keyuse.length() > 0) {
@ -198,19 +173,16 @@ void MainWindow::newCert()
cert->addV3ext(NID_key_usage, keyuse1);
CERR << "KeyUsage:" <<keyuse1<< endl;
}
if (opensslError(cert)) return;
// extended key usage
char *ekeyusage[]= {"serverAuth","clientAuth","codeSigning","emailProtection",
"timeStamping","msCodeInd","msCodeCom",
"msCTLSign","msSGC","msEFS","nsSGC"};
i=0; keyuse=""; keyuse1="";
while ((item = dlg->ekeyUsage->item(i))) {
keyuse=""; keyuse1="";
for (i=0; (item = dlg->ekeyUsage->item(i)); i++) {
if (item->selected()){
if (keyuse.length() > 0) keyuse += ", ";
keyuse += ekeyusage[i];
addStr(keyuse, ekeyusage[i]);
}
i++;
}
if (keyuse.length() > 0) {
@ -219,15 +191,77 @@ void MainWindow::newCert()
cert->addV3ext(NID_ext_key_usage, keyuse1);
CERR << "Extended Key Usage:" <<keyuse1<< endl;
}
if (opensslError(cert)) return;
// STEP 4
// Subject Alternative name
string cont="", subAltName="", issAltName="";
if (dlg->subAltCpMail->isChecked()) {
subAltName = "email:copy";
}
if ((cont = dlg->subAltURL->text().latin1()) != ""){
addStr(subAltName,"URI:");
subAltName+=cont;
}
if ((cont = dlg->subAltDNS->text().latin1()) != ""){
addStr(subAltName,"DNS:");
subAltName+=cont;
}
if ((cont = dlg->subAltIP->text().latin1()) != ""){
addStr(subAltName,"IP:");
subAltName+=cont;
}
if ((cont = dlg->subAltEMAIL->text().latin1()) != ""){
addStr(subAltName,"email:");
subAltName+=cont;
}
if (subAltName.length() > 0) {
cert->addV3ext(NID_subject_alt_name, subAltName);
CERR << "SubAltName:" << subAltName<< endl;
}
// issuer alternative name
if (dlg->issAltCopy->isChecked()) {
issAltName = "issuer:copy";
}
if ((cont = dlg->issAltURL->text().latin1()) != ""){
addStr(issAltName,"URI:");
issAltName+=cont;
}
if ((cont = dlg->issAltDNS->text().latin1()) != ""){
addStr(issAltName,"DNS:");
issAltName+=cont;
}
if ((cont = dlg->issAltIP->text().latin1()) != ""){
addStr(issAltName,"IP:");
issAltName+=cont;
}
if ((cont = dlg->issAltEMAIL->text().latin1()) != ""){
addStr(issAltName,"email:");
issAltName+=cont;
}
CERR << "HIER" << endl;
if (issAltName.length() > 0) {
cert->addV3ext(NID_issuer_alt_name, issAltName);
CERR << "IssAltName:" << issAltName<< endl;
}
if (opensslError(cert)) return;
// and finally sign the request
cert->sign(signkey);
if (opensslError(cert)) return;
CERR << "SIGNED" <<endl;
insertCert(cert);
}
void MainWindow::addStr(string &str, char *add)
{
if (str.length() >0) {
str += ", ";
}
str += add;
}
void MainWindow::showDetailsCert()
{

View File

@ -54,8 +54,7 @@
void MainWindow::newReq()
{
NewX509Req_UI *dlg = new NewX509Req_UI(this,0,true,0);
dlg->keyList->insertStringList(keys->getPrivateDesc());
NewX509Req *dlg = new NewX509Req(this, 0, keys);
dlg->image->setPixmap(*csrImg);
if (! dlg->exec()) return;
pki_key *key = (pki_key *)keys->getSelectedPKI(dlg->keyList->currentText().latin1());

View File

@ -28,6 +28,7 @@ OBJS=NewKey_UI.o NewKey_UI_MOC.o \
NewX509Req_UI.o NewX509Req_UI_MOC.o \
NewX509_UI.o NewX509_UI_MOC.o \
NewX509.o NewX509_MOC.o \
NewX509Req.o NewX509Req_MOC.o \
CertDetail_UI.o CertDetail_UI_MOC.o \
Rename_UI.o Rename_UI_MOC.o \
ExportKey.o ExportKey_MOC.o \
@ -50,7 +51,7 @@ MainWindow.h: MainWindow_UI.h KeyDetail_UI.h \
%.o: %.cpp
$(GCC) $(CPPFLAGS) -DVER=\"$(VERSION)\" -DPREFIX=\"@prefix@/share/xca\" -c $< -o $@
%_MOC.cpp: %.h
%_MOC.cpp: %.h %.cpp
$(MOC) $< -o $@
%_UI.h: %.ui

View File

@ -55,10 +55,11 @@ NewX509::NewX509(QWidget *parent , const char *name, db_key *key, db_x509req *re
:NewX509_UI(parent, name, true, 0)
{
connect( this, SIGNAL(genKey()), parent, SLOT(newKey()) );
connect( parent, SIGNAL(keyDone(QString)), this, SLOT(newKeyDone(QString)) );
keys = key;
reqs = req;
QStringList strings = keys->getPrivateDesc();
// are there any private keys to use ?
// are there any useable private keys ?
if (strings.isEmpty()) {
newKey();
}
@ -74,8 +75,43 @@ NewX509::NewX509(QWidget *parent , const char *name, db_key *key, db_x509req *re
reqList->insertStringList(strings);
}
fromDataRB->setChecked(true);
setFinishEnabled(page4,true);
setNextEnabled(page1,false);
}
void NewX509::dataChangeP1()
{
if (description->text() != "" || fromReqRB->isChecked()) {
setNextEnabled(page1,true);
}
else {
setNextEnabled(page1,false);
}
}
void NewX509::showPage(QWidget *page)
{
if ( page == page1 ) {
dataChangeP1();
}
else if ( page == page2 ) {
if (!selfSignRB->isChecked() && !foreignSignRB->isChecked()) {
if (fromDataRB->isChecked()) {
selfSignRB->setChecked(true);
serialNr->setText("00");
}
else {
foreignSignRB->setChecked(true);
}
}
}
else if (page == page4) {
}
QWizard::showPage(page);
}
void NewX509::setDisabled(int state)
{
if (state == 2) {
@ -91,31 +127,10 @@ void NewX509::setDisabled(int state)
void NewX509::newKey()
{
emit genKey();
keyList->clear();
keyList->insertStringList(keys->getPrivateDesc());
}
void NewX509::validateFields() {
QStringList fields;
if (fromReqRB->isChecked()) {
accept();
return;
}
if (description->text() == "")
fields.append(tr("Description"));
if (commonName->text() == "")
fields.append(tr("Common Name"));
if (emailAddress->text() == "")
fields.append(tr("Email Address"));
if (!fields.isEmpty()) {
QMessageBox::information(this,tr("Missing parameter"),
tr("The following fields must not be empty") +":\n'"+
fields.join("'\n'") + "'", "OK");
}
else {
accept();
}
void NewX509::newKeyDone(QString name)
{
keyList->insertItem(name,0);
keyList->setCurrentItem(0);
}

View File

@ -56,7 +56,7 @@
#include "lib/db_x509req.h"
#include <qframe.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#ifndef NEWX509_H
#define NEWX509_H
@ -68,14 +68,15 @@ class NewX509: public NewX509_UI
private:
db_x509req *reqs;
db_key *keys;
MainWindow *par;
public:
NewX509(QWidget *parent, const char *name, db_key *key, db_x509req *req);
public slots:
void setDisabled(int state);
void newKey();
void validateFields();
void dataChangeP1();
void showPage(QWidget *page);
void newKeyDone(QString name);
signals:
void genKey();
};

View File

@ -11,7 +11,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>652</width>
<width>648</width>
<height>430</height>
</rect>
</property>
@ -22,17 +22,17 @@
</property>
<property stdset="1">
<name>caption</name>
<string>Form1</string>
<string>Certificate creation</string>
</property>
<widget>
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>page</cstring>
<cstring>page1</cstring>
</property>
<attribute>
<name>title</name>
<string>Page</string>
<string>New Certificate Step 1</string>
</attribute>
<vbox>
<property stdset="1">
@ -400,11 +400,11 @@ For a SSL servercertificate choose the DNS name of the server as "Common name"</
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>page</cstring>
<cstring>page2</cstring>
</property>
<attribute>
<name>title</name>
<string>New Certificate </string>
<string>New Certificate Step 2</string>
</attribute>
<grid>
<property stdset="1">
@ -756,11 +756,11 @@ For a SSL servercertificate choose the DNS name of the server as "Common name"</
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>page</cstring>
<cstring>page3</cstring>
</property>
<attribute>
<name>title</name>
<string>Page</string>
<string>New Certificate Step 3</string>
</attribute>
<grid>
<property stdset="1">
@ -991,11 +991,11 @@ For a SSL servercertificate choose the DNS name of the server as "Common name"</
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>page</cstring>
<cstring>page4</cstring>
</property>
<attribute>
<name>title</name>
<string>Page</string>
<string>New Certificate Step 4</string>
</attribute>
<vbox>
<property stdset="1">
@ -1217,4 +1217,33 @@ For a SSL servercertificate choose the DNS name of the server as "Common name"</
</vbox>
</widget>
</widget>
<connections>
<connection>
<sender>description</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>NewX509_UI</receiver>
<slot>dataChangeP1()</slot>
</connection>
<connection>
<sender>fromReqRB</sender>
<signal>stateChanged(int)</signal>
<receiver>NewX509_UI</receiver>
<slot>dataChangeP1()</slot>
</connection>
<connection>
<sender>fromDataRB</sender>
<signal>stateChanged(int)</signal>
<receiver>NewX509_UI</receiver>
<slot>setDisabled(int)</slot>
</connection>
<connection>
<sender>genKey</sender>
<signal>clicked()</signal>
<receiver>NewX509_UI</receiver>
<slot>newKey()</slot>
</connection>
<slot access="public">dataChangeP1()</slot>
<slot access="public">newKey()</slot>
<slot access="public">setDisabled(int)</slot>
</connections>
</UI>

91
NewX509Req.cpp Normal file
View File

@ -0,0 +1,91 @@
/*
* Copyright (C) 2001 Christian Hohnstaedt.
*
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.sleepycat.com
*
* http://www.trolltech.com
*
*
*
* http://www.hohnstaedt.de/xca
* email: christian@hohnstaedt.de
*
* $Id$
*
*/
#include "NewX509Req.h"
NewX509Req::NewX509Req(QWidget *parent , const char *name, db_key *key)
:NewX509Req_UI(parent, name, true, 0)
{
connect( this, SIGNAL(genKey()), parent, SLOT(newKey()) );
connect( parent, SIGNAL(keyDone(QString)), this, SLOT(newKeyDone(QString)) );
keys = key;
QStringList strings = keys->getPrivateDesc();
// are there any useable private keys ?
if (strings.isEmpty()) {
newKey();
}
else {
keyList->insertStringList(strings);
}
generateBut->setEnabled(false);
}
void NewX509Req::dataChange()
{
if (description->text() != "" ) {
generateBut->setEnabled(true);
}
else {
generateBut->setEnabled(false);
}
}
void NewX509Req::newKey()
{
emit genKey();
}
void NewX509Req::newKeyDone(QString name)
{
keyList->insertItem(name,0);
keyList->setCurrentItem(0);
}

81
NewX509Req.h Normal file
View File

@ -0,0 +1,81 @@
/*
* Copyright (C) 2001 Christian Hohnstaedt.
*
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* This program links to software with different licenses from:
*
* http://www.openssl.org which includes cryptographic software
* written by Eric Young (eay@cryptsoft.com)"
*
* http://www.sleepycat.com
*
* http://www.trolltech.com
*
*
*
* http://www.hohnstaedt.de/xca
* email: christian@hohnstaedt.de
*
* $Id$
*
*/
#include "NewX509Req_UI.h"
#include <qcombobox.h>
#include <qradiobutton.h>
#include "lib/db_key.h"
#include "lib/db_x509req.h"
#include <qframe.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#ifndef NEWX509REQ_H
#define NEWX509REQ_H
class MainWindow;
class NewX509Req: public NewX509Req_UI
{
Q_OBJECT
private:
db_key *keys;
public:
NewX509Req(QWidget *parent, const char *name, db_key *key);
public slots:
void newKey();
void dataChange();
void newKeyDone(QString name);
signals:
void genKey();
};
#endif

View File

@ -11,7 +11,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>631</width>
<width>627</width>
<height>326</height>
</rect>
</property>
@ -393,7 +393,7 @@ For a SSL servercertificate choose the DNS name of the server</string>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout14</cstring>
<cstring>Layout4</cstring>
</property>
<hbox>
<property stdset="1">
@ -408,11 +408,11 @@ For a SSL servercertificate choose the DNS name of the server</string>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>PushButton14</cstring>
<cstring>PushButton15</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>OK</string>
<string>Cancel</string>
</property>
</widget>
<spacer>
@ -440,11 +440,11 @@ For a SSL servercertificate choose the DNS name of the server</string>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>PushButton15</cstring>
<cstring>generateBut</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Cancel</string>
<string>Generate request</string>
</property>
</widget>
</hbox>
@ -453,7 +453,7 @@ For a SSL servercertificate choose the DNS name of the server</string>
</widget>
<connections>
<connection>
<sender>PushButton14</sender>
<sender>generateBut</sender>
<signal>clicked()</signal>
<receiver>NewX509Req_UI</receiver>
<slot>accept()</slot>
@ -464,9 +464,23 @@ For a SSL servercertificate choose the DNS name of the server</string>
<receiver>NewX509Req_UI</receiver>
<slot>reject()</slot>
</connection>
<connection>
<sender>description</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>NewX509Req_UI</receiver>
<slot>dataChange()</slot>
</connection>
<connection>
<sender>genKey</sender>
<signal>clicked()</signal>
<receiver>NewX509Req_UI</receiver>
<slot>newKey()</slot>
</connection>
<slot access="public">newKey()</slot>
<slot access="public">dataChange()</slot>
</connections>
<tabstops>
<tabstop>PushButton14</tabstop>
<tabstop>generateBut</tabstop>
<tabstop>PushButton15</tabstop>
</tabstops>
</UI>