| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# ksslkeygen.cc

    00001 /* This file is part of the KDE project
    00002  *
    00003  * Copyright (C) 2001 George Staikos <staikos@kde.org>
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public
    00007  * License as published by the Free Software Foundation; either
    00008  * version 2 of the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful,
    00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public License
    00016  * along with this library; see the file COPYING.LIB.  If not, write to
    00017  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  * Boston, MA 02111-1307, USA.
    00019  */
    00020
    00021
    00022 #include "ksslkeygen.h"
    00023 #include <klocale.h>
    00024 #include <kdebug.h>
    00025 #include "keygenwizard.h"
    00026 #include "keygenwizard2.h"
    00027 #include <qlineedit.h>
    00028 #include <qpushbutton.h>
    00029 #include <kmessagebox.h>
    00030
    00031 #include <assert.h>
    00032
    00033 #include <kopenssl.h>
    00034
    00035
    00036
    00037 KSSLKeyGen::KSSLKeyGen(QWidget *parent, const char *name, bool modal)
    00038 :KWizard(parent,name,modal) {
    00039         _idx = -1;
    00040
    00041 #ifdef KSSL_HAVE_SSL
    00042         page1 = new KGWizardPage1(this, "Wizard Page 1");
    00043         addPage(page1, i18n("KDE Certificate Request"));
    00044         page2 = new KGWizardPage2(this, "Wizard Page 2");
    00045         addPage(page2, i18n("KDE Certificate Request - Password"));
    00046         setHelpEnabled(page1, false);
    00047         setHelpEnabled(page2, false);
    00048         setFinishEnabled(page2, false);
    00049         connect(page2->_password1, SIGNAL(textChanged(const QString&)), this, SLOT(slotPassChanged()));
    00050         connect(page2->_password2, SIGNAL(textChanged(const QString&)), this, SLOT(slotPassChanged()));
    00051         connect(finishButton(), SIGNAL(clicked()), SLOT(slotGenerate()));
    00052 #else
    00053         // tell him he doesn't have SSL
    00054 #endif
    00055 }
    00056
    00057
    00058 KSSLKeyGen::~KSSLKeyGen() {
    00059
    00060 }
    00061
    00062
    00063 void KSSLKeyGen::slotPassChanged() {
    00064         setFinishEnabled(page2, page2->_password1->text() == page2->_password2->text() && page2->_password1->text().length() >= 4);
    00065 }
    00066
    00067
    00068 void KSSLKeyGen::slotGenerate() {
    00069         assert(_idx >= 0 && _idx < 3);   // for now
    00070
    00071 // FOR NOW, it's DISABLED
    00072
    00073         KMessageBox::sorry(NULL, i18n("Certificate request generation has been disabled for this release due to incomplete code."), i18n("KDE SSL Information"));
    00074         return;
    00075
    00076
    00077         // Show a progress box
    00078
    00079         // Generate the CSR
    00080         int bits;
    00081         switch (_idx) {
    00082         case 0:
    00083                 bits = 1024;
    00084                 break;
    00085         case 1:
    00086                 bits = 768;
    00087                 break;
    00088         case 2:
    00089                 bits = 512;
    00090                 break;
    00091         default:
    00092                 return;
    00093         }
    00094
    00095         generateCSR("This CSR", page2->_password1->text(), bits, 0x10001);
    00096 }
    00097
    00098
    00099 int KSSLKeyGen::generateCSR(QString name, QString pass, int bits, int e) {
    00100 #ifdef KSSL_HAVE_SSL
    00101 KOSSL *kossl = KOSSL::self();
    00102 X509_REQ *req;
    00103 int rc;
    00104
    00105         req = kossl->X509_REQ_new();
    00106         if (!req)
    00107                 return -2;
    00108
    00109         EVP_PKEY *pkey = kossl->EVP_PKEY_new();
    00110         if (!pkey) {
    00111                 kossl->X509_REQ_free(req);
    00112                 return -4;
    00113         }
    00114
    00115         RSA *rsakey = kossl->RSA_generate_key(bits, e, NULL, NULL);
    00116         if (!rsakey) {
    00117                 kossl->X509_REQ_free(req);
    00118                 kossl->EVP_PKEY_free(pkey);
    00119                 return -3;
    00120         }
    00121
    00122         rc = kossl->EVP_PKEY_assign(pkey, EVP_PKEY_RSA, (char *)rsakey);
    00123
    00124         rc = kossl->X509_REQ_set_pubkey(req, pkey);
    00125
    00126         // We write it to the database and then the caller can obtain it
    00127         // back from there.  Yes it's inefficient, but it doesn't happen
    00128         // often and this way things are uniform.
    00129
    00130         FILE *fp;
    00131         fp = fopen("keygencsrtest.der", "w");
    00132
    00133         kossl->i2d_X509_REQ_fp(fp, req);
    00134
    00135         fclose(fp);
    00136
    00137         // FIXME: private key!
    00138
    00139         // FIXME: do we have to free "rsakey" ourself?  Small leak anyways..
    00140
    00141         kossl->X509_REQ_free(req);
    00142
    00143 return 0;
    00144 #else
    00145 return -1;
    00146 #endif
    00147 }
    00148
    00149
    00150 QStringList KSSLKeyGen::supportedKeySizes() {
    00151 QStringList x;
    00152
    00153 #ifdef KSSL_HAVE_SSL
    00154    x << "1024"
    00155      << "768"
    00156      << "512";
    00157 #else
    00158    x << i18n("No SSL support.");
    00159 #endif
    00160
    00161 return x;
    00162 }
    00163
    00164
    00165 #include "ksslkeygen.moc"
    00166

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:26 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001