• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/kssl
 

tdeio/kssl

  • tdeio
  • kssl
ksslkeygen.cpp
1/* This file is part of the KDE project
2 *
3 * Copyright (C) 2001 George Staikos <staikos@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21
22#include "ksslkeygen.h"
23#include "keygenwizard.h"
24#include "keygenwizard2.h"
25
26#include <tdeapplication.h>
27#include <kdebug.h>
28#include <tdelocale.h>
29#include <tdemessagebox.h>
30#include <kopenssl.h>
31#include <kprogress.h>
32#include <tdestandarddirs.h>
33#include <tdetempfile.h>
34#include <tdewallet.h>
35
36#include <tqlineedit.h>
37#include <tqpushbutton.h>
38
39#include <assert.h>
40
41
42KSSLKeyGen::KSSLKeyGen(TQWidget *parent, const char *name, bool modal)
43:KWizard(parent,name,modal) {
44 _idx = -1;
45
46#ifdef KSSL_HAVE_SSL
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()));
57#else
58 // tell him he doesn't have SSL
59#endif
60}
61
62
63KSSLKeyGen::~KSSLKeyGen() {
64
65}
66
67
68void KSSLKeyGen::slotPassChanged() {
69 setFinishEnabled(page2, page2->_password1->text() == page2->_password2->text() && page2->_password1->text().length() >= 4);
70}
71
72
73void KSSLKeyGen::slotGenerate() {
74 assert(_idx >= 0 && _idx <= 3); // for now
75
76
77 // Generate the CSR
78 int bits;
79 switch (_idx) {
80 case 0:
81 bits = 2048;
82 break;
83 case 1:
84 bits = 1024;
85 break;
86 case 2:
87 bits = 768;
88 break;
89 case 3:
90 bits = 512;
91 break;
92 default:
93 KMessageBox::sorry(NULL, i18n("Unsupported key size."), i18n("TDE SSL Information"));
94 return;
95 }
96
97 KProgressDialog *kpd = new KProgressDialog(this, "progress dialog", i18n("TDE"), i18n("Please wait while the encryption keys are generated..."));
98 kpd->progressBar()->setProgress(0);
99 kpd->show();
100 // FIXME - progress dialog won't show this way
101
102 int rc = generateCSR("This CSR" /*FIXME */, page2->_password1->text(), bits, 0x10001 /* This is the traditional exponent used */);
103 kpd->progressBar()->setProgress(100);
104
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());
110 if (w) {
111 // FIXME: store passphrase in wallet
112 delete w;
113 }
114 }
115 }
116#endif
117
118 kpd->deleteLater();
119}
120
121
122int KSSLKeyGen::generateCSR(const TQString& name, const TQString& pass, int bits, int e) {
123#ifdef KSSL_HAVE_SSL
124 KOSSL *kossl = KOSSL::self();
125
126 X509_REQ *req = kossl->X509_REQ_new();
127 if (!req) {
128 return -2;
129 }
130
131 EVP_PKEY *pkey = kossl->EVP_PKEY_new();
132 if (!pkey) {
133 kossl->X509_REQ_free(req);
134 return -4;
135 }
136
137 RSA *rsakey = kossl->RSA_generate_key(bits, e, NULL, NULL);
138 if (!rsakey) {
139 kossl->X509_REQ_free(req);
140 kossl->EVP_PKEY_free(pkey);
141 return -3;
142 }
143
144 kossl->EVP_PKEY_assign(pkey, EVP_PKEY_RSA, (char *)rsakey);
145
146 kossl->X509_REQ_set_pubkey(req, pkey);
147
148 // Set the subject
149 X509_NAME *n = kossl->X509_NAME_new();
150
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);
158
159 kossl->X509_REQ_set_subject_name(req, n);
160
161
162 kossl->X509_REQ_sign(req, pkey, kossl->EVP_md5());
163
164 // We write it to the database and then the caller can obtain it
165 // back from there. Yes it's inefficient, but it doesn't happen
166 // often and this way things are uniform.
167
168 TDEGlobal::dirs()->addResourceType("kssl", TDEStandardDirs::kde_default("data") + "kssl");
169
170 TQString path = TDEGlobal::dirs()->saveLocation("kssl");
171 KTempFile csrFile(path + "csr_", ".der");
172
173 if (!csrFile.fstream()) {
174 kossl->X509_REQ_free(req);
175 kossl->EVP_PKEY_free(pkey);
176 return -5;
177 }
178
179 KTempFile p8File(path + "pkey_", ".p8");
180
181 if (!p8File.fstream()) {
182 kossl->X509_REQ_free(req);
183 kossl->EVP_PKEY_free(pkey);
184 return -5;
185 }
186
187 kossl->i2d_X509_REQ_fp(csrFile.fstream(), req);
188
189 kossl->i2d_PKCS8PrivateKey_fp(p8File.fstream(), pkey,
190 kossl->EVP_bf_cbc(), pass.local8Bit().data(),
191 pass.length(), 0L, 0L);
192
193 // FIXME Write tdeconfig entry to store the filenames under the md5 hash
194
195 kossl->X509_REQ_free(req);
196 kossl->EVP_PKEY_free(pkey);
197
198 return 0;
199#else
200 return -1;
201#endif
202}
203
204
205TQStringList KSSLKeyGen::supportedKeySizes() {
206 TQStringList x;
207
208#ifdef KSSL_HAVE_SSL
209 x << i18n("2048 (High Grade)")
210 << i18n("1024 (Medium Grade)")
211 << i18n("768 (Low Grade)")
212 << i18n("512 (Low Grade)");
213#else
214 x << i18n("No SSL support.");
215#endif
216
217 return x;
218}
219
220
221#include "ksslkeygen.moc"
222
KSSLKeyGen::~KSSLKeyGen
virtual ~KSSLKeyGen()
Destroy this dialog.
Definition: ksslkeygen.cpp:63
KSSLKeyGen::generateCSR
int generateCSR(const TQString &name, const TQString &pass, int bits, int e=0x10001)
Generate the certificate signing request.
Definition: ksslkeygen.cpp:122
KSSLKeyGen::KSSLKeyGen
KSSLKeyGen(TQWidget *parent=0L, const char *name=0L, bool modal=false)
Construct a keygen dialog.
Definition: ksslkeygen.cpp:42
KSSLKeyGen::supportedKeySizes
static TQStringList supportedKeySizes()
List the supported key sizes.
Definition: ksslkeygen.cpp:205

tdeio/kssl

Skip menu "tdeio/kssl"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/kssl

Skip menu "tdeio/kssl"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/kssl by doxygen 1.9.4
This website is maintained by Timothy Pearson.