22 #include "ksslkeygen.h" 23 #include "keygenwizard.h" 24 #include "keygenwizard2.h" 26 #include <tdeapplication.h> 28 #include <tdelocale.h> 29 #include <tdemessagebox.h> 31 #include <kprogress.h> 32 #include <kstandarddirs.h> 33 #include <tdetempfile.h> 34 #include <tdewallet.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(
"TDE Certificate Request"));
49 page2 =
new KGWizardPage2(
this,
"Wizard Page 2");
50 addPage(page2, i18n(
"TDE Certificate Request - Password"));
51 setHelpEnabled(page1,
false);
52 setHelpEnabled(page2,
false);
53 setFinishEnabled(page2,
false);
54 connect(page2->_password1, TQ_SIGNAL(textChanged(
const TQString&)),
this, TQ_SLOT(slotPassChanged()));
55 connect(page2->_password2, TQ_SIGNAL(textChanged(
const TQString&)),
this, TQ_SLOT(slotPassChanged()));
56 connect(finishButton(), TQ_SIGNAL(clicked()), TQ_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(
"TDE 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 && TDEWallet::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 TDEWallet::Wallet *w = TDEWallet::Wallet::openWallet(TDEWallet::Wallet::LocalWallet(), winId());
124 KOSSL *kossl = KOSSL::self();
126 X509_REQ *req = kossl->X509_REQ_new();
131 EVP_PKEY *pkey = kossl->EVP_PKEY_new();
133 kossl->X509_REQ_free(req);
137 RSA *rsakey = kossl->RSA_generate_key(bits, e, NULL, NULL);
139 kossl->X509_REQ_free(req);
140 kossl->EVP_PKEY_free(pkey);
144 kossl->EVP_PKEY_assign(pkey, EVP_PKEY_RSA, (
char *)rsakey);
146 kossl->X509_REQ_set_pubkey(req, pkey);
149 X509_NAME *n = kossl->X509_NAME_new();
151 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_countryName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
152 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_organizationName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
153 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_organizationalUnitName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
154 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_localityName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
155 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_stateOrProvinceName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
156 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_commonName, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
157 kossl->X509_NAME_add_entry_by_txt(n, (
char*)LN_pkcs9_emailAddress, MBSTRING_UTF8, (
unsigned char*)name.local8Bit().data(), -1, -1, 0);
159 kossl->X509_REQ_set_subject_name(req, n);
162 kossl->X509_REQ_sign(req, pkey, kossl->EVP_md5());
168 TDEGlobal::dirs()->addResourceType(
"kssl", TDEStandardDirs::kde_default(
"data") +
"kssl");
170 TQString path = TDEGlobal::dirs()->saveLocation(
"kssl");
171 KTempFile csrFile(path +
"csr_",
".der");
173 if (!csrFile.fstream()) {
174 kossl->X509_REQ_free(req);
175 kossl->EVP_PKEY_free(pkey);
179 KTempFile p8File(path +
"pkey_",
".p8");
181 if (!p8File.fstream()) {
182 kossl->X509_REQ_free(req);
183 kossl->EVP_PKEY_free(pkey);
187 kossl->i2d_X509_REQ_fp(csrFile.fstream(), req);
189 kossl->i2d_PKCS8PrivateKey_fp(p8File.fstream(), pkey,
190 kossl->EVP_bf_cbc(), pass.local8Bit().data(),
191 pass.length(), 0L, 0L);
195 kossl->X509_REQ_free(req);
196 kossl->EVP_PKEY_free(pkey);
209 x << i18n(
"2048 (High Grade)")
210 << i18n(
"1024 (Medium Grade)")
211 << i18n(
"768 (Low Grade)")
212 << i18n(
"512 (Low Grade)");
214 x << i18n(
"No SSL support.");
221 #include "ksslkeygen.moc" static TQStringList supportedKeySizes()
List the supported key sizes.
virtual ~KSSLKeyGen()
Destroy this dialog.
KSSLKeyGen(TQWidget *parent=0L, const char *name=0L, bool modal=false)
Construct a keygen dialog.
int generateCSR(const TQString &name, const TQString &pass, int bits, int e=0x10001)
Generate the certificate signing request.