mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
add "validation" function for editable extensions
This commit is contained in:
parent
cd7207e74c
commit
b722ca5655
@ -1,3 +1,4 @@
|
||||
* add "validation" function for editable extensions below
|
||||
* add "edit" buttons for subject/issuer alt. name,
|
||||
crl dist. point and cert. auth. info access
|
||||
* add DB-dump function into subdirs
|
||||
|
||||
22
ui/v3ext.ui
22
ui/v3ext.ui
@ -11,7 +11,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>503</width>
|
||||
<width>499</width>
|
||||
<height>255</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -114,6 +114,17 @@
|
||||
<string>Apply</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>PushButton5</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>Validate</string>
|
||||
</property>
|
||||
</widget>
|
||||
<spacer>
|
||||
<property>
|
||||
<name>name</name>
|
||||
@ -175,8 +186,15 @@
|
||||
<receiver>v3ext_UI</receiver>
|
||||
<slot>apply()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>PushButton5</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>v3ext_UI</receiver>
|
||||
<slot>validate()</slot>
|
||||
</connection>
|
||||
<slot access="public">addEntry()</slot>
|
||||
<slot access="public">delEntry()</slot>
|
||||
<slot access="public">apply()</slot>
|
||||
<slot access="public">delEntry()</slot>
|
||||
<slot access="public">validate()</slot>
|
||||
</connections>
|
||||
</UI>
|
||||
|
||||
@ -498,12 +498,6 @@ void NewX509::showPage(QWidget *page)
|
||||
}
|
||||
else if (page == page4) {
|
||||
basicCA->setFocus();
|
||||
#if 0
|
||||
if (emailAddress->text().isEmpty() && appropriate(page1))
|
||||
subAltCp->setEnabled(false);
|
||||
else
|
||||
subAltCp->setEnabled(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -514,10 +508,7 @@ void NewX509::signerChanged()
|
||||
a1time snb, sna;
|
||||
pki_x509 *cert = getSelectedSigner();
|
||||
|
||||
// issAltCp->setEnabled(false);
|
||||
if (!cert) return;
|
||||
// if (cert->hasSubAltName() || !appropriate(page1))
|
||||
// issAltCp->setEnabled(true);
|
||||
|
||||
QString templ = cert->getTemplate();
|
||||
snb = cert->getNotBefore();
|
||||
@ -716,33 +707,55 @@ void NewX509::applyTimeDiff()
|
||||
notAfter->setDate(a.now(delta * d_fac), midnight* (-1));
|
||||
}
|
||||
|
||||
void NewX509::editV3ext(QLineEdit *le, QString types)
|
||||
void NewX509::editV3ext(QLineEdit *le, QString types, int n)
|
||||
{
|
||||
v3ext *dlg;
|
||||
pki_x509 *cert, *signcert;
|
||||
pki_x509req *req;
|
||||
|
||||
// initially create cert
|
||||
cert = new pki_x509();
|
||||
if (fromReqCB->isChecked()) {
|
||||
req = getSelectedReq();
|
||||
cert->setSubject(req->getSubject());
|
||||
} else {
|
||||
cert->setSubject(getX509name());
|
||||
}
|
||||
// Step 2 - select Signing
|
||||
if (foreignSignRB->isChecked()) {
|
||||
signcert = getSelectedSigner();
|
||||
} else {
|
||||
signcert = cert;
|
||||
}
|
||||
|
||||
dlg = new v3ext(this, NULL, true);
|
||||
dlg->addLineEdit(le);
|
||||
dlg->addTypeList(QStringList::split(',', types ));
|
||||
dlg->addInfo(le, QStringList::split(',', types ), n,
|
||||
cert->getCert(), signcert->getCert());
|
||||
dlg->exec();
|
||||
delete(dlg);
|
||||
delete(cert);
|
||||
}
|
||||
|
||||
void NewX509::editSubAltName()
|
||||
{
|
||||
editV3ext(subAltName, "email,RID,URI,DNS,IP");
|
||||
editV3ext(subAltName, "email,email:copy,RID,URI,DNS,IP",
|
||||
NID_subject_alt_name);
|
||||
}
|
||||
|
||||
void NewX509::editIssAltName()
|
||||
{
|
||||
editV3ext(issAltName, "email,RID,URI,DNS,IP");
|
||||
editV3ext(issAltName, "email,RID,URI,DNS,IP,issuer:copy",
|
||||
NID_issuer_alt_name);
|
||||
}
|
||||
|
||||
void NewX509::editCrlDist()
|
||||
{
|
||||
editV3ext(crlDist, "URI");
|
||||
editV3ext(crlDist, "URI", NID_crl_distribution_points);
|
||||
}
|
||||
|
||||
void NewX509::editAuthInfAcc()
|
||||
{
|
||||
editV3ext(authInfAcc, "email,RID,URI,DNS,IP");
|
||||
editV3ext(authInfAcc, "email,RID,URI,DNS,IP", NID_info_access);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ class NewX509: public NewX509_UI
|
||||
static int name_nid[EXPLICIT_NAME_CNT];
|
||||
QLineEdit *name_ptr[EXPLICIT_NAME_CNT];
|
||||
X509V3_CTX ext_ctx;
|
||||
void editV3ext(QLineEdit *le, QString types);
|
||||
void editV3ext(QLineEdit *le, QString types, int n);
|
||||
public:
|
||||
NewX509(QWidget *parent, const char *name, bool modal = false, WFlags f = 0);
|
||||
~NewX509();
|
||||
|
||||
@ -157,26 +157,14 @@ x509v3ext NewX509::getEkeyUsage()
|
||||
|
||||
x509v3ext NewX509::getSubAltName()
|
||||
{
|
||||
// QStringList cont;
|
||||
x509v3ext ext;
|
||||
// if (subAltCp->isChecked() && subAltCp->isEnabled())
|
||||
// cont << (QString)"email:" + emailAddress->text();
|
||||
// if (!subAltName->text().isEmpty())
|
||||
// cont << subAltName->text();
|
||||
// ext.create(NID_subject_alt_name, cont.join(", "));
|
||||
ext.create(NID_subject_alt_name, subAltName->text(), &ext_ctx);
|
||||
return ext;
|
||||
}
|
||||
|
||||
x509v3ext NewX509::getIssAltName()
|
||||
{
|
||||
// QStringList cont;
|
||||
x509v3ext ext;
|
||||
// if (issAltCp->isChecked() && issAltCp->isEnabled())
|
||||
// cont << (QString)"issuer:copy";
|
||||
// if (!issAltName->text().isEmpty())
|
||||
// cont << issAltName->text();
|
||||
// ext.create(NID_issuer_alt_name, cont.join(", "), &ext_ctx);
|
||||
ext.create(NID_issuer_alt_name, issAltName->text(), &ext_ctx);
|
||||
return ext;
|
||||
}
|
||||
|
||||
@ -57,12 +57,14 @@
|
||||
#include <qlistview.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qmessagebox.h>
|
||||
#include "MainWindow.h"
|
||||
#include "lib/exception.h"
|
||||
|
||||
v3ext::v3ext(QWidget *parent, const char *name, bool modal, WFlags f )
|
||||
:v3ext_UI(parent, name, modal, f)
|
||||
{
|
||||
setCaption(tr(XCA_TITLE));
|
||||
// image->setPixmap(*MainWindow::certImg);
|
||||
listView->addColumn(tr("Type"));
|
||||
listView->addColumn(tr("Content"));
|
||||
}
|
||||
@ -71,16 +73,17 @@ v3ext::~v3ext()
|
||||
{
|
||||
}
|
||||
|
||||
void v3ext::addLineEdit(QLineEdit *myle)
|
||||
void v3ext::addInfo(QLineEdit *myle, const QStringList &sl, int n,
|
||||
X509 *s, X509 *s1)
|
||||
{
|
||||
type->insertStringList(sl);
|
||||
nid = n;
|
||||
le = myle;
|
||||
if (le)
|
||||
addItem(le->text());
|
||||
}
|
||||
|
||||
void v3ext::addTypeList(const QStringList &sl)
|
||||
{
|
||||
type->insertStringList(sl);
|
||||
|
||||
memset(&ext_ctx, 0, sizeof(X509V3_CTX));
|
||||
X509V3_set_ctx(&ext_ctx, s, s1, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
void v3ext::addItem(QString list)
|
||||
@ -105,8 +108,11 @@ QString v3ext::toString()
|
||||
QStringList str;
|
||||
QListViewItem *lvi = listView->firstChild();
|
||||
while (lvi != NULL) {
|
||||
str += lvi->text(0).stripWhiteSpace() +
|
||||
":" + lvi->text(1).stripWhiteSpace();
|
||||
QString s;
|
||||
s = lvi->text(0).stripWhiteSpace();
|
||||
if (!s.contains(':'))
|
||||
s += ":" + lvi->text(1).stripWhiteSpace();
|
||||
str += s;
|
||||
lvi = lvi->nextSibling();
|
||||
}
|
||||
return str.join(",");
|
||||
@ -120,11 +126,49 @@ void v3ext::delEntry()
|
||||
|
||||
void v3ext::addEntry()
|
||||
{
|
||||
new QListViewItem(listView, type->currentText(), value->text());
|
||||
QString typ, cont;
|
||||
typ = type->currentText();
|
||||
if ( ! typ.contains(':') )
|
||||
cont = value->text();
|
||||
|
||||
new QListViewItem(listView, typ, cont);
|
||||
}
|
||||
|
||||
void v3ext::apply()
|
||||
{
|
||||
le->setText(toString());
|
||||
__validate();
|
||||
accept();
|
||||
}
|
||||
|
||||
bool v3ext::__validate()
|
||||
{
|
||||
x509v3ext ext;
|
||||
QString str, error;
|
||||
|
||||
if (nid==NID_info_access) {
|
||||
str = "OCSP;";
|
||||
}
|
||||
str += toString();
|
||||
|
||||
ext.create(nid, str, &ext_ctx);
|
||||
while (int i = ERR_get_error() ) {
|
||||
error += ERR_error_string(i ,NULL);
|
||||
error += "\n";
|
||||
}
|
||||
if (! error.isEmpty()) {
|
||||
QMessageBox::warning(NULL, XCA_TITLE, tr("Validation failed:\n")
|
||||
+ "'" + str + "'\n" + error,
|
||||
tr("&OK"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void v3ext::validate()
|
||||
{
|
||||
if (__validate()) {
|
||||
QMessageBox::information(NULL, XCA_TITLE, "Validation successfull",
|
||||
tr("&OK"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +57,7 @@
|
||||
#include <qlistview.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qstringlist.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#ifndef qt3
|
||||
#include <qlist.h>
|
||||
#endif
|
||||
@ -69,19 +70,23 @@ class v3ext: public v3ext_UI
|
||||
Q_OBJECT
|
||||
private:
|
||||
QLineEdit *le;
|
||||
int nid;
|
||||
X509V3_CTX ext_ctx;
|
||||
bool __validate();
|
||||
public:
|
||||
v3ext( QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0);
|
||||
~v3ext();
|
||||
void addItem(QString list);
|
||||
void addEntry(QString list);
|
||||
QString toString();
|
||||
void addLineEdit(QLineEdit *myle);
|
||||
void addTypeList(const QStringList &sl);
|
||||
void addInfo(QLineEdit *myle, const QStringList &sl, int n,
|
||||
X509 *s, X509 *s1);
|
||||
|
||||
public slots:
|
||||
void delEntry();
|
||||
void addEntry();
|
||||
void apply();
|
||||
void validate();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user