diff --git a/ExportCert.cpp b/ExportCert.cpp
index 9e234761..a5bfb224 100644
--- a/ExportCert.cpp
+++ b/ExportCert.cpp
@@ -53,7 +53,7 @@
ExportCert::ExportCert(QString fname, bool hasKey, QString dpath,
- QWidget *parent, const char *name )
+ const QString tcafn, QWidget *parent, const char *name )
:ExportCert_UI(parent,name,true,0)
{
filename->setText(fname);
@@ -69,6 +69,7 @@ ExportCert::ExportCert(QString fname, bool hasKey, QString dpath,
exportFormat->insertItem("PKCS #12 with Certificate chain");
}
dirPath = dpath;
+ tinyCAfname = tcafn;
}
void ExportCert::chooseFile()
@@ -104,3 +105,9 @@ void ExportCert::formatChanged()
CERR(nfn);
filename->setText(nfn);
}
+
+void ExportCert::setTinyCAfname()
+{
+ filename->setText(tinyCAfname);
+}
+
diff --git a/ExportCert.h b/ExportCert.h
index d766b552..e792cba5 100644
--- a/ExportCert.h
+++ b/ExportCert.h
@@ -63,13 +63,19 @@
class ExportCert: public ExportCert_UI
{
Q_OBJECT
+
+ private:
+ QString tinyCAfname;
+
public:
ExportCert(QString fname, bool hasKey, QString dpath,
- QWidget *parent = 0, const char *name = 0);
+ const QString tcafn, QWidget *parent = 0, const char *name = 0);
QString dirPath;
+
public slots:
- virtual void chooseFile();
- virtual void formatChanged();
+ void chooseFile();
+ void formatChanged();
+ void setTinyCAfname();
};
#endif
diff --git a/ExportCert_UI.ui b/ExportCert_UI.ui
index b404f49d..eb58be31 100644
--- a/ExportCert_UI.ui
+++ b/ExportCert_UI.ui
@@ -11,8 +11,8 @@
0
0
- 492
- 306
+ 527
+ 319
@@ -111,22 +111,57 @@
- QLabel
+ QLayoutWidget
name
- TextLabel13
-
-
- text
- Please enter the filename for the certificate.
-
-
- alignment
- WordBreak|AlignVCenter|AlignLeft
-
-
- wordwrap
+ Layout3
+
+
+ margin
+ 0
+
+
+ spacing
+ 6
+
+
+ QLabel
+
+ name
+ TextLabel13
+
+
+ sizePolicy
+
+ 7
+ 5
+
+
+
+ text
+ Please enter the filename for the certificate.
+
+
+
+ QPushButton
+
+ name
+ PushButton3
+
+
+ sizePolicy
+
+ 1
+ 0
+
+
+
+ text
+ TinyCA filename
+
+
+
QFrame
@@ -346,8 +381,15 @@ PKCS#12 is an encrypted official Key-Certificate exchange format
ExportCert_UI
formatChanged()
+
+ PushButton3
+ clicked()
+ ExportCert_UI
+ setTinyCAfname()
+
chooseFile()
formatChanged()
+ setTinyCAfname()
filename
diff --git a/ExportTinyCA.cpp b/ExportTinyCA.cpp
new file mode 100644
index 00000000..6f88aada
--- /dev/null
+++ b/ExportTinyCA.cpp
@@ -0,0 +1,94 @@
+/*
+ * 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 "ExportTinyCA.h"
+
+
+ExportTinyCA::ExportTinyCA(const QString tmpdir, const QString tcadir,
+ QWidget *parent, const char *name )
+ :ExportTinyCA_UI(parent,name,true,0)
+{
+ tempdir->setText(tmpdir);
+ tinycadir->setText(tcadir);
+ setCaption(tr(XCA_TITLE));
+}
+
+void ExportTinyCA::chooseTempDir()
+{
+ QString s = "";
+ QFileDialog *dlg = new QFileDialog(this,0,true);
+ dlg->setCaption(tr("TinyCA Template directory"));
+ dlg->setMode( QFileDialog::DirectoryOnly );
+ dlg->setSelection( tempdir->text() );
+ if (dlg->exec())
+ s = dlg->selectedFile();
+ if (! s.isEmpty()) {
+ QDir::convertSeparators(s);
+ tempdir->setText(s);
+ }
+ delete dlg;
+}
+
+void ExportTinyCA::chooseTinyCaDir()
+{
+ QString s = "";
+ QFileDialog *dlg = new QFileDialog(this,0,true);
+ dlg->setCaption(tr("TinyCA Directory "));
+ dlg->setMode( QFileDialog::DirectoryOnly );
+ dlg->setSelection( tinycadir->text() );
+ if (dlg->exec())
+ s = dlg->selectedFile();
+ if (! s.isEmpty()) {
+ QDir::convertSeparators(s);
+ tinycadir->setText(s);
+ }
+ delete dlg;
+}
diff --git a/ExportTinyCA.h b/ExportTinyCA.h
new file mode 100644
index 00000000..46ef216e
--- /dev/null
+++ b/ExportTinyCA.h
@@ -0,0 +1,76 @@
+/*
+ * 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 "ExportTinyCA_UI.h"
+#include
+#include
+#include
+#include
+#include "lib/base.h"
+#include
+
+#ifndef EXPORTTINY_H
+#define EXPORTTINY_H
+
+class ExportTinyCA: public ExportTinyCA_UI
+{
+ Q_OBJECT
+
+ public:
+ ExportTinyCA(const QString tmpdir, const QString tcadir,
+ QWidget *parent = 0, const char *name = 0);
+
+ public slots:
+ void chooseTempDir();
+ void chooseTinyCaDir();
+};
+
+#endif
diff --git a/ExportTinyCA_UI.ui b/ExportTinyCA_UI.ui
new file mode 100644
index 00000000..658049d8
--- /dev/null
+++ b/ExportTinyCA_UI.ui
@@ -0,0 +1,428 @@
+
+ExportTinyCA_UI
+
+ QDialog
+
+ name
+ ExportTinyCA_UI
+
+
+ geometry
+
+ 0
+ 0
+ 589
+ 300
+
+
+
+ caption
+ CA export
+
+
+
+ margin
+ 11
+
+
+ spacing
+ 6
+
+
+ QLayoutWidget
+
+ name
+ Layout9_2
+
+
+
+ margin
+ 0
+
+
+ spacing
+ 6
+
+
+ QLabel
+
+ name
+ TextLabel12_2
+
+
+ font
+
+ 14
+ 1
+ 1
+
+
+
+ text
+ TinyCA export
+
+
+
+
+ name
+ Spacer6_2
+
+
+ orientation
+ Horizontal
+
+
+ sizeType
+ Expanding
+
+
+ sizeHint
+
+ 20
+ 20
+
+
+
+
+ QLabel
+
+ name
+ image_2
+
+
+ minimumSize
+
+ 95
+ 40
+
+
+
+ maximumSize
+
+ 95
+ 40
+
+
+
+ scaledContents
+ true
+
+
+
+
+
+
+ name
+ Spacer10
+
+
+ orientation
+ Vertical
+
+
+ sizeType
+ Expanding
+
+
+ sizeHint
+
+ 20
+ 20
+
+
+
+
+ QFrame
+
+ name
+ Frame5_2
+
+
+ frameShape
+ Box
+
+
+ frameShadow
+ Sunken
+
+
+
+ margin
+ 11
+
+
+ spacing
+ 6
+
+
+ QLabel
+
+ name
+ TextLabel14
+
+
+ text
+ Templatedir:
+
+
+
+ QLineEdit
+
+ name
+ tempdir
+
+
+
+ QToolButton
+
+ name
+ ToolButton1
+
+
+ sizePolicy
+
+ 1
+ 0
+
+
+
+ text
+ ...
+
+
+
+
+
+ QFrame
+
+ name
+ Frame5_2_2
+
+
+ frameShape
+ Box
+
+
+ frameShadow
+ Sunken
+
+
+
+ margin
+ 11
+
+
+ spacing
+ 6
+
+
+ QLabel
+
+ name
+ TextLabel14_2
+
+
+ text
+ TinyCA Directory:
+
+
+
+ QLineEdit
+
+ name
+ tinycadir
+
+
+
+ QToolButton
+
+ name
+ ToolButton1_2
+
+
+ sizePolicy
+
+ 1
+ 0
+
+
+
+ text
+ ...
+
+
+
+
+
+ QFrame
+
+ name
+ Frame5_2_2_2
+
+
+ frameShape
+ Box
+
+
+ frameShadow
+ Sunken
+
+
+
+ margin
+ 11
+
+
+ spacing
+ 6
+
+
+ QLabel
+
+ name
+ TextLabel14_2_2
+
+
+ text
+ Name:
+
+
+
+ QLineEdit
+
+ name
+ dname
+
+
+
+ QToolButton
+
+ name
+ ToolButton1_2_2
+
+
+ sizePolicy
+
+ 1
+ 0
+
+
+
+ text
+ ...
+
+
+
+
+
+
+ name
+ Spacer8
+
+
+ orientation
+ Vertical
+
+
+ sizeType
+ Expanding
+
+
+ sizeHint
+
+ 20
+ 20
+
+
+
+
+ QLayoutWidget
+
+ name
+ Layout6
+
+
+
+ margin
+ 0
+
+
+ spacing
+ 6
+
+
+ QPushButton
+
+ name
+ PushButton9
+
+
+ text
+ Cancel
+
+
+
+
+ name
+ Spacer7
+
+
+ orientation
+ Horizontal
+
+
+ sizeType
+ Expanding
+
+
+ sizeHint
+
+ 20
+ 20
+
+
+
+
+ QPushButton
+
+ name
+ PushButton7
+
+
+ text
+ OK
+
+
+
+
+
+
+
+
+ PushButton9
+ clicked()
+ ExportTinyCA_UI
+ reject()
+
+
+ PushButton7
+ clicked()
+ ExportTinyCA_UI
+ accept()
+
+
+ ToolButton1_2
+ clicked()
+ ExportTinyCA_UI
+ chooseTinyCaDir()
+
+
+ ToolButton1
+ clicked()
+ ExportTinyCA_UI
+ chooseTempDir()
+
+ chooseTempDir()
+ chooseTinyCaDir()
+
+
diff --git a/MainWindow.cpp b/MainWindow.cpp
index 366c4ff7..99b8832f 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -458,3 +458,18 @@ void MainWindow::newPath(QString str)
{
settings->putString("workingdir", str.latin1());
}
+
+bool MainWindow::mkDir(QString dir)
+{
+ int ret = mkdir(dir.latin1(), S_IRUSR | S_IWUSR | S_IXUSR);
+ if (ret) {
+ QString desc = " (";
+ desc += strerror(ret);
+ desc += ")";
+ QMessageBox::critical(this,tr(XCA_TITLE),
+ tr("Error creating: ") + dir + desc);
+ return false;
+ }
+ return true;
+}
+
diff --git a/MainWindow.h b/MainWindow.h
index 92804041..620cbbd3 100644
--- a/MainWindow.h
+++ b/MainWindow.h
@@ -66,6 +66,7 @@
#include "TrustState.h"
#include "ExportCert.h"
#include "ExportKey.h"
+#include "ExportTinyCA.h"
#include
#include
#include
@@ -99,6 +100,9 @@
#include "lib/db_x509req.h"
#include "lib/db_x509.h"
#include "lib/db_temp.h"
+#include
+#include
+#include
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
@@ -159,6 +163,7 @@ class MainWindow: public MainWindow_UI
QString getPath();
void newPath(QFileDialog *dlg);
void newPath(QString str);
+ bool mkDir(QString dir);
public slots:
void loadKey();
void loadReq();
@@ -219,6 +224,7 @@ class MainWindow: public MainWindow_UI
void signP7();
void encryptP7();
void changeView();
+ void toTinyCA();
signals:
void keyDone(QString name);
};
diff --git a/MainWindowX509.cpp b/MainWindowX509.cpp
index 1d61fad1..d3d7c065 100644
--- a/MainWindowX509.cpp
+++ b/MainWindowX509.cpp
@@ -744,7 +744,8 @@ void MainWindow::writeCert()
if (!crt) return;
pki_key *privkey = crt->getKey();
ExportCert *dlg = new ExportCert((crt->getDescription() + ".crt").c_str(),
- (privkey && privkey->isPrivKey()), getPath() );
+ (privkey && privkey->isPrivKey()), getPath(), crt->tinyCAfname().c_str() );
+ dlg->image->setPixmap(*certImg);
int dlgret = dlg->exec();
newPath(dlg->dirPath);
@@ -920,7 +921,7 @@ void MainWindow::showPopupCert(QListViewItem *item, const QPoint &pt, int x) {
QPopupMenu *subCa = new QPopupMenu(this);
QPopupMenu *subP7 = new QPopupMenu(this);
QPopupMenu *subExport = new QPopupMenu(this);
- int itemExtend, itemRevoke, itemTrust, itemCA, itemTemplate, itemReq, itemP7;
+ int itemExtend, itemRevoke, itemTrust, itemCA, itemTemplate, itemReq, itemP7, itemtca;
bool canSign, parentCanSign, hasTemplates, hasPrivkey;
if (!item) {
@@ -936,6 +937,7 @@ void MainWindow::showPopupCert(QListViewItem *item, const QPoint &pt, int x) {
menu->insertItem(tr("Export"), subExport);
subExport->insertItem(tr("File"), this, SLOT(writeCert()));
itemReq = subExport->insertItem(tr("Request"), this, SLOT(toRequest()));
+ itemtca = subExport->insertItem(tr("TinyCA"), this, SLOT(toTinyCA()));
menu->insertItem(tr("Delete"), this, SLOT(deleteCert()));
itemTrust = menu->insertItem(tr("Trust"), this, SLOT(setTrust()));
@@ -967,6 +969,7 @@ void MainWindow::showPopupCert(QListViewItem *item, const QPoint &pt, int x) {
menu->setItemEnabled(itemRevoke, parentCanSign);
menu->setItemEnabled(itemCA, canSign);
subExport->setItemEnabled(itemReq, hasPrivkey);
+ subExport->setItemEnabled(itemtca, canSign);
menu->setItemEnabled(itemP7, hasPrivkey);
subCa->setItemEnabled(itemTemplate, hasTemplates);
@@ -1168,6 +1171,61 @@ void MainWindow::changeView()
certs->updateView();
}
+void MainWindow::toTinyCA()
+{
+ pki_x509 *crt = (pki_x509 *)certs->getSelectedPKI();
+ if (!crt) return;
+ pki_key *key = crt->getKey();
+ if (!key) return;
+ FILE *fp;
+
+ QString dname = crt->getDescription().c_str();
+ QString tcatempdir = settings->getString("TinyCAtempdir").c_str();
+ QString tcadir = settings->getString("TinyCAdir").c_str();
+ 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();
+
+ 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.latin1());
+ if (! mkDir("certs")) return;
+ if (! mkDir("crl")) return;
+ if (! mkDir("keys")) return;
+ if (! mkDir("newcerts")) return;
+ if (! mkDir("req")) return;
+
+ crt->writeCert("cacert.pem", true, false);
+ key->writeKey("cacert.key", enc, &MainWindow::passWrite, true);
+ fp = fopen("serial", "w");
+ if (!fp) return;
+ fprintf(fp, "%x", crt->getCaSerial());
+ fclose(fp);
+
+ settings->putString("TinyCAtempdir", tcatempdir.latin1());
+ settings->putString("TinyCAdir", tcadir.latin1());
+
+}
+
+
void MainWindow::startRenameCert()
{
try {
diff --git a/Makefile.in b/Makefile.in
index 77053a38..bfecb957 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -24,9 +24,10 @@ UIC=@UIC@
###################################
UINAMES=CertDetail ExportKey_UI ExportCert_UI KeyDetail MainWindow_UI \
- NewKey NewX509_UI PassRead PassWrite ReqDetail TrustState CertExtend
+ NewKey NewX509_UI PassRead PassWrite ReqDetail TrustState \
+ CertExtend ExportTinyCA_UI
-MOCNAMES=NewX509 ExportKey MainWindow ExportCert $(UINAMES)
+MOCNAMES=ExportTinyCA NewX509 ExportKey MainWindow ExportCert $(UINAMES)
MOBJS=MainWindowKeys.o MainWindowX509Req.o MainWindowX509.o MainWindowTemps.o
OOBJS=$(patsubst %,moc_%.o,$(MOCNAMES)) $(patsubst %,%.o,$(MOCNAMES))
diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp
index e5fe476b..a8d01a9c 100644
--- a/lib/pki_x509.cpp
+++ b/lib/pki_x509.cpp
@@ -768,6 +768,7 @@ string pki_x509::tinyCAfname()
EVP_EncodeBlock(buf, (unsigned char *)col.c_str(), len );
col = (char *)buf;
OPENSSL_free(buf);
+ col += ".pem";
CERR("base64 Encoding: " <