ksslkeygen.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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);
00070
00071
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
00078
00079
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
00127
00128
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
00138
00139
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.0.