22 #include "ksslkeygen.h"
23 #include "keygenwizard.h"
24 #include "keygenwizard2.h"
26 #include <kapplication.h>
29 #include <kmessagebox.h>
31 #include <kprogress.h>
32 #include <kstandarddirs.h>
33 #include <ktempfile.h>
36 #include <tqlineedit.h>
37 #include <tqpushbutton.h>
43 :KWizard(parent,name,modal) {
47 page1 =
new KGWizardPage1(
this,
"Wizard Page 1");
48 addPage(page1, i18n(
"KDE Certificate Request"));
49 page2 =
new KGWizardPage2(
this,
"Wizard Page 2");
50 addPage(page2, i18n(
"KDE Certificate Request - Password"));
51 setHelpEnabled(page1,
false);
52 setHelpEnabled(page2,
false);
53 setFinishEnabled(page2,
false);
54 connect(page2->_password1, TQT_SIGNAL(textChanged(
const TQString&)),
this, TQT_SLOT(slotPassChanged()));
55 connect(page2->_password2, TQT_SIGNAL(textChanged(
const TQString&)),
this, TQT_SLOT(slotPassChanged()));
56 connect(finishButton(), TQT_SIGNAL(clicked()), TQT_SLOT(slotGenerate()));
68 void KSSLKeyGen::slotPassChanged() {
69 setFinishEnabled(page2, page2->_password1->text() == page2->_password2->text() && page2->_password1->text().length() >= 4);
73 void KSSLKeyGen::slotGenerate() {
74 assert(_idx >= 0 && _idx <= 3);
93 KMessageBox::sorry(NULL, i18n(
"Unsupported key size."), i18n(
"KDE SSL Information"));
97 KProgressDialog *kpd =
new KProgressDialog(
this,
"progress dialog", i18n(
"TDE"), i18n(
"Please wait while the encryption keys are generated..."));
98 kpd->progressBar()->setProgress(0);
102 int rc =
generateCSR(
"This CSR" , page2->_password1->text(), bits, 0x10001 );
103 kpd->progressBar()->setProgress(100);
105 #ifndef Q_OS_WIN //TODO: reenable for WIN32
106 if (rc == 0 && KWallet::Wallet::isEnabled()) {
107 rc = KMessageBox::questionYesNo(
this, i18n(
"Do you wish to store the passphrase in your wallet file?"), TQString::null, i18n(
"Store"), i18n(
"Do Not Store"));
108 if (rc == KMessageBox::Yes) {
109 KWallet::Wallet *w = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), winId());
124 KOSSL *kossl = KOSSL::self();
127 X509_REQ *req = kossl->X509_REQ_new();
132 EVP_PKEY *pkey = kossl->EVP_PKEY_new();
134 kossl->X509_REQ_free(req);
138 RSA *rsakey = kossl->RSA_generate_key(bits, e, NULL, NULL);
140 kossl->X509_REQ_free(req);
141 kossl->EVP_PKEY_free(pkey);
145 rc = kossl->EVP_PKEY_assign(pkey, EVP_PKEY_RSA, (
char *)rsakey);
147 rc = kossl->X509_REQ_set_pubkey(req, pkey);
150 X509_NAME *n = kossl->X509_NAME_new();
152 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_countryName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
153 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_organizationName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
154 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_organizationalUnitName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
155 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_localityName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
156 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_stateOrProvinceName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
157 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_commonName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
158 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_pkcs9_emailAddress, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
160 rc = kossl->X509_REQ_set_subject_name(req, n);
163 rc = kossl->X509_REQ_sign(req, pkey, kossl->EVP_md5());
169 KGlobal::dirs()->addResourceType(
"kssl", KStandardDirs::kde_default(
"data") +
"kssl");
171 TQString path = KGlobal::dirs()->saveLocation(
"kssl");
172 KTempFile csrFile(path +
"csr_",
".der");
174 if (!csrFile.fstream()) {
175 kossl->X509_REQ_free(req);
176 kossl->EVP_PKEY_free(pkey);
180 KTempFile p8File(path +
"pkey_",
".p8");
182 if (!p8File.fstream()) {
183 kossl->X509_REQ_free(req);
184 kossl->EVP_PKEY_free(pkey);
188 kossl->i2d_X509_REQ_fp(csrFile.fstream(), req);
190 kossl->i2d_PKCS8PrivateKey_fp(p8File.fstream(), pkey,
191 kossl->EVP_bf_cbc(), pass.local8Bit().data(),
192 pass.length(), 0L, 0L);
196 kossl->X509_REQ_free(req);
197 kossl->EVP_PKEY_free(pkey);
210 x << i18n(
"2048 (High Grade)")
211 << i18n(
"1024 (Medium Grade)")
212 << i18n(
"768 (Low Grade)")
213 << i18n(
"512 (Low Grade)");
215 x << i18n(
"No SSL support.");
222 #include "ksslkeygen.moc"