mirror of
https://github.com/chris2511/xca.git
synced 2026-09-14 11:06:19 +05:00
started to export and import templates
This commit is contained in:
parent
4929031af3
commit
cbc44c591d
@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2001 Christian Hohnstaedt.
|
||||
*
|
||||
|
||||
@ -243,7 +243,70 @@ unsigned char *pki_temp::toData(int *size)
|
||||
return p;
|
||||
}
|
||||
|
||||
void pki_temp::writeTemp(QString fname)
|
||||
{
|
||||
FILE *fp = fopen(fname,"w");
|
||||
if (fp == NULL) {
|
||||
fopen_error(fname);
|
||||
return;
|
||||
}
|
||||
fprintf(fp, "version=%d\ntype=%d\n", version, type);
|
||||
fprintf(fp, "Bool=%d,%d,%d,%d,%d,%d,%d\n", bcCrit, keyUseCrit, eKeyUseCrit,
|
||||
subKey, authKey, subAltCp, issAltCp);
|
||||
fprintf(fp, "Int=%d,%d,%d,%d,%d,%d,%d\n", ca, pathLen, validN, validM,
|
||||
keyUse, eKeyUse, nsCertType);
|
||||
fprintf(fp, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", subAltName.latin1(),
|
||||
issAltName.latin1(), crlDist.latin1(), nsComment.latin1(),
|
||||
nsBaseUrl.latin1(), nsRevocationUrl.latin1(),
|
||||
nsCARevocationUrl.latin1(), nsRenewalUrl.latin1(),
|
||||
nsCaPolicyUrl.latin1(), nsSslServerName.latin1());
|
||||
|
||||
xname.write_fp(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void pki_temp::loadTemp(QString fname)
|
||||
{
|
||||
char buf[180];
|
||||
int i[7];
|
||||
FILE *fp = fopen(fname,"r");
|
||||
if (fp == NULL) {
|
||||
fopen_error(fname);
|
||||
return;
|
||||
}
|
||||
|
||||
fscanf(fp, " version=%d\ntype=%d ", &version, &type);
|
||||
if (version != 2 || type<0 || type>3) {
|
||||
openssl_error("Template version or type error");
|
||||
return;
|
||||
}
|
||||
|
||||
fscanf(fp, "Bool = %d , %d , %d , %d , %d , %d , %d ", &bcCrit, &keyUseCrit,
|
||||
&eKeyUseCrit, &subKey, &authKey, &subAltCp, &issAltCp);
|
||||
fscanf(fp, "Int = %d , %d , %d , %d , %d , %d , %d\n", &ca, &pathLen, &validN, &validM,
|
||||
&keyUse, &eKeyUse, &nsCertType);
|
||||
#define LONG_ERR openssl_error("String too long error")
|
||||
QString subAltName = fgets(buf, 180, fp);
|
||||
QString issAltName = fgets(buf, 180, fp);
|
||||
QString crlDist = fgets(buf, 180, fp);
|
||||
QString nsComment = fgets(buf, 180, fp);
|
||||
QString nsBaseUrl = fgets(buf, 180, fp);
|
||||
QString nsRevocationUrl = fgets(buf, 180, fp);
|
||||
QString nsCARevocationUrl = fgets(buf, 180, fp);
|
||||
QString nsRenewalUrl = fgets(buf, 180, fp);
|
||||
QString nsCaPolicyUrl = fgets(buf, 180, fp);
|
||||
QString nsSslServerName = fgets(buf, 180, fp);
|
||||
if (subAltName.length() >= 179) LONG_ERR;
|
||||
if (issAltName.length() >= 179) LONG_ERR;
|
||||
if (crlDist.length() >= 179) LONG_ERR;
|
||||
if (nsComment.length() >= 179) LONG_ERR;
|
||||
if (nsBaseUrl.length() >= 179) LONG_ERR;
|
||||
if (nsRevocationUrl.length() >= 179) LONG_ERR;
|
||||
if (nsCARevocationUrl.length() >= 179) LONG_ERR;
|
||||
if (nsRenewalUrl.length() >= 179) LONG_ERR;
|
||||
if (nsCaPolicyUrl.length() >= 179) LONG_ERR;
|
||||
if (nsSslServerName.length() >= 179) LONG_ERR;
|
||||
}
|
||||
|
||||
pki_temp::~pki_temp()
|
||||
{
|
||||
|
||||
@ -75,6 +75,7 @@ class pki_temp: public pki_base
|
||||
|
||||
pki_temp(const pki_temp *pk);
|
||||
pki_temp(const QString d, int atype=0);
|
||||
void loadTemp(const QString fname);
|
||||
/* destructor */
|
||||
~pki_temp();
|
||||
void fromData(unsigned char *p, int size);
|
||||
@ -82,6 +83,7 @@ class pki_temp: public pki_base
|
||||
bool compare(pki_base *ref);
|
||||
int dataSize();
|
||||
void updateView();
|
||||
void writeTemp(QString fname);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -188,3 +188,21 @@ int x509name::derSize() const
|
||||
{
|
||||
return i2d_X509_NAME(xn, NULL);
|
||||
}
|
||||
|
||||
void x509name::write_fp(FILE *fp) const
|
||||
{
|
||||
int cnt = entryCount();
|
||||
for (int i=0; i<cnt; i++) {
|
||||
QStringList sl = entryList(i);
|
||||
fprintf(fp, "%s=%s\n",sl[0].latin1(), sl[2].latin1());
|
||||
}
|
||||
}
|
||||
|
||||
void x509name::read_fp(FILE *fp)
|
||||
{
|
||||
char buf[180];
|
||||
QStringList sl;
|
||||
QString line = fgets(buf, 180, fp);
|
||||
sl.split('=', line),
|
||||
addEntryByNid(OBJ_sn2nid(sl[0].latin1()), sl[1]);
|
||||
}
|
||||
|
||||
@ -80,6 +80,9 @@ class x509name
|
||||
void delEntry(int i);
|
||||
X509_NAME *get() const;
|
||||
int derSize() const;
|
||||
void write_fp(FILE *fp) const;
|
||||
void read_fp(FILE *fp);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>618</width>
|
||||
<width>614</width>
|
||||
<height>543</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -642,6 +642,28 @@
|
||||
<string>&Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>BNimportTemp</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>Import</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>BNexportTemp</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
<spacer>
|
||||
<property>
|
||||
<name>name</name>
|
||||
|
||||
@ -132,7 +132,55 @@ void TempView::deleteItem()
|
||||
deleteItem_default(tr("The Template"), tr("is going to be deleted"));
|
||||
}
|
||||
|
||||
void TempView::load()
|
||||
{
|
||||
QStringList filter;
|
||||
filter.append( "XCA templates ( *.xca )");
|
||||
load_default(filter, tr("Import key"));
|
||||
}
|
||||
|
||||
pki_base *TempView::loadItem(QString fname)
|
||||
{
|
||||
pki_temp *temp = new pki_temp(fname);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void TempView::store()
|
||||
{
|
||||
pki_temp *temp;
|
||||
try {
|
||||
temp = (pki_temp *)getSelected();
|
||||
}
|
||||
catch (errorEx &err) {
|
||||
Error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!temp) return;
|
||||
QStringList filt;
|
||||
filt.append("XCA Templates ( *.xca )");
|
||||
filt.append("All Files ( *.* )");
|
||||
QString s="";
|
||||
QFileDialog *dlg = new QFileDialog(this,0,true);
|
||||
dlg->setCaption(tr("Export Template"));
|
||||
dlg->setFilters(filt);
|
||||
dlg->setMode( QFileDialog::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) {
|
||||
Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
pki_base *TempView::insert(pki_base *temp)
|
||||
{
|
||||
@ -167,6 +215,8 @@ void TempView::popupMenu(QListViewItem *item, const QPoint &pt, int x)
|
||||
}
|
||||
else {
|
||||
menu->insertItem(tr("Rename"), this, SLOT(startRename()));
|
||||
menu->insertItem(tr("Import"), this, SLOT(load()));
|
||||
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()));
|
||||
@ -177,4 +227,3 @@ void TempView::popupMenu(QListViewItem *item, const QPoint &pt, int x)
|
||||
delete subMenu;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -74,6 +74,7 @@ class TempView : public XcaListView
|
||||
//void store();
|
||||
bool alterTemp(pki_temp *);
|
||||
void popupMenu(QListViewItem *item, const QPoint &pt, int x);
|
||||
pki_base *loadItem(QString fname);
|
||||
public slots:
|
||||
void newEmptyTemp();
|
||||
void newCaTemp();
|
||||
@ -83,6 +84,8 @@ class TempView : public XcaListView
|
||||
void reqFromTemp();
|
||||
void alterTemp();
|
||||
void deleteItem();
|
||||
void store();
|
||||
void load();
|
||||
signals:
|
||||
void newReq(pki_temp *);
|
||||
void newCert(pki_temp *);
|
||||
|
||||
@ -140,6 +140,8 @@ MainWindow::MainWindow(QWidget *parent, const char *name )
|
||||
connect( BNserverTemp, SIGNAL(clicked()), tempList, SLOT(newServerTemp()));
|
||||
connect( BNdeleteTemp, SIGNAL(clicked()), tempList, SLOT(deleteItem()));
|
||||
connect( BNchangeTemp, SIGNAL(clicked()), tempList, SLOT(alterTemp()));
|
||||
connect( BNimportTemp, SIGNAL(clicked()), tempList, SLOT(load()));
|
||||
connect( BNexportTemp, SIGNAL(clicked()), tempList, SLOT(store()));
|
||||
|
||||
connect( BNimportCrl, SIGNAL(clicked()), crlList, SLOT(load()));
|
||||
connect( BNdetailsCrl, SIGNAL(clicked()), crlList, SLOT(showItem()));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user