33#include <tqsortedlist.h>
35#include "ksslsettings.h"
37#include <kstandarddirs.h>
43#define crypt _openssl_crypt
44#include <openssl/ssl.h>
52 CipherNode(
const char *_name,
int _keylen) :
53 name(_name), keylen(_keylen) {}
56 inline int operator==(CipherNode &x)
57 {
return ((x.keylen == keylen) && (x.name == name)); }
58 inline int operator< (CipherNode &x) {
return keylen < x.keylen; }
59 inline int operator<=(CipherNode &x) {
return keylen <= x.keylen; }
60 inline int operator> (CipherNode &x) {
return keylen > x.keylen; }
61 inline int operator>=(CipherNode &x) {
return keylen >= x.keylen; }
65class KSSLSettingsPrivate {
67 KSSLSettingsPrivate() {
70 ~KSSLSettingsPrivate() {
89 d =
new KSSLSettingsPrivate;
90 m_cfg =
new TDEConfig(
"cryptodefaults",
false,
false);
92 if (!TDEGlobal::dirs()->addResourceType(
"kssl", TDEStandardDirs::kde_default(
"data") +
"kssl")) {
96 if (readConfig)
load();
129 bool firstcipher =
true;
130 SSL_METHOD *meth = 0L;
131 TQPtrList<CipherNode> cipherList;
133 cipherList.setAutoDelete(
true);
136 d->kossl = KOSSL::self();
138 if (m_bUseSSLv3 && m_bUseSSLv2)
139 meth = d->kossl->TLS_client_method();
141 meth = d->kossl->SSLv3_client_method();
142 else if (m_bUseSSLv2)
143 meth = d->kossl->SSLv2_client_method();
145 SSL_CTX *ctx = d->kossl->SSL_CTX_new(meth);
146 SSL* ssl = d->kossl->SSL_new(ctx);
147 STACK_OF(SSL_CIPHER)* sk = d->kossl->SSL_get_ciphers(ssl);
148 int cnt = d->kossl->OPENSSL_sk_num(sk);
149 for (
int i=0; i< cnt; i++) {
150 SSL_CIPHER *sc =
reinterpret_cast<SSL_CIPHER*
>(d->kossl->OPENSSL_sk_value(sk,i));
154 if(!strcmp(
"SSLv2", d->kossl->SSL_CIPHER_get_version(sc)))
155 m_cfg->setGroup(
"SSLv2");
157 m_cfg->setGroup(
"SSLv3");
159 tcipher.sprintf(
"cipher_%s", d->kossl->SSL_CIPHER_get_name(sc));
160 int bits = d->kossl->SSL_CIPHER_get_bits(sc, NULL);
161 if (m_cfg->readBoolEntry(tcipher, bits >= 56)) {
162 CipherNode *xx =
new CipherNode(d->kossl->SSL_CIPHER_get_name(sc),bits);
163 if (!cipherList.contains(xx))
164 cipherList.prepend(xx);
169 d->kossl->SSL_free(ssl);
170 d->kossl->SSL_CTX_free(ctx);
174 for (
unsigned int i = 0; i < cipherList.count(); i++) {
176 while ((j = cipherList.at(i)) != 0L) {
177 if (j->name.contains(
"ADH-") || j->name.contains(
"NULL-") || j->name.contains(
"DES-CBC3-SHA") || j->name.contains(
"FZA")) {
178 cipherList.remove(j);
186 while (!cipherList.isEmpty()) {
189 else clist.append(
":");
190 clist.append(cipherList.getLast()->name);
191 cipherList.removeLast();
194 kdDebug(7029) <<
"Cipher list is: " << clist << endl;
202 m_cfg->reparseConfiguration();
204 m_cfg->setGroup(
"TLS");
205 m_bUseTLSv1 = m_cfg->readBoolEntry(
"Enabled",
true);
209#if defined(OPENSSL_NO_SSL3)
212 m_cfg->setGroup(
"SSLv3");
213 m_bUseSSLv3 = m_cfg->readBoolEntry(
"Enabled",
true);
216 m_cfg->setGroup(
"Warnings");
217 m_bWarnOnEnter = m_cfg->readBoolEntry(
"OnEnter",
false);
218 m_bWarnOnLeave = m_cfg->readBoolEntry(
"OnLeave",
true);
219 m_bWarnOnUnencrypted = m_cfg->readBoolEntry(
"OnUnencrypted",
true);
220 m_bWarnOnMixed = m_cfg->readBoolEntry(
"OnMixed",
true);
222 m_cfg->setGroup(
"Validation");
223 m_bWarnSelfSigned = m_cfg->readBoolEntry(
"WarnSelfSigned",
true);
224 m_bWarnExpired = m_cfg->readBoolEntry(
"WarnExpired",
true);
225 m_bWarnRevoked = m_cfg->readBoolEntry(
"WarnRevoked",
true);
227 m_cfg->setGroup(
"EGD");
228 d->m_bUseEGD = m_cfg->readBoolEntry(
"UseEGD",
false);
229 d->m_bUseEFile = m_cfg->readBoolEntry(
"UseEFile",
false);
230 d->m_EGDPath = m_cfg->readPathEntry(
"EGDPath");
232 m_cfg->setGroup(
"Auth");
233 d->m_bSendX509 = (
"send" == m_cfg->readEntry(
"AuthMethod",
""));
234 d->m_bPromptX509 = (
"prompt" == m_cfg->readEntry(
"AuthMethod",
""));
248 m_bWarnOnEnter =
false;
249 m_bWarnOnLeave =
true;
250 m_bWarnOnUnencrypted =
true;
251 m_bWarnOnMixed =
true;
252 m_bWarnSelfSigned =
true;
253 m_bWarnExpired =
true;
254 m_bWarnRevoked =
true;
255 d->m_bUseEGD =
false;
256 d->m_bUseEFile =
false;
262 m_cfg->setGroup(
"TLS");
263 m_cfg->writeEntry(
"Enabled", m_bUseTLSv1);
265 m_cfg->setGroup(
"SSLv2");
266 m_cfg->writeEntry(
"Enabled", m_bUseSSLv2);
268 m_cfg->setGroup(
"SSLv3");
269 m_cfg->writeEntry(
"Enabled", m_bUseSSLv3);
271 m_cfg->setGroup(
"Warnings");
272 m_cfg->writeEntry(
"OnEnter", m_bWarnOnEnter);
273 m_cfg->writeEntry(
"OnLeave", m_bWarnOnLeave);
274 m_cfg->writeEntry(
"OnUnencrypted", m_bWarnOnUnencrypted);
275 m_cfg->writeEntry(
"OnMixed", m_bWarnOnMixed);
277 m_cfg->setGroup(
"Validation");
278 m_cfg->writeEntry(
"WarnSelfSigned", m_bWarnSelfSigned);
279 m_cfg->writeEntry(
"WarnExpired", m_bWarnExpired);
280 m_cfg->writeEntry(
"WarnRevoked", m_bWarnRevoked);
282 m_cfg->setGroup(
"EGD");
283 m_cfg->writeEntry(
"UseEGD", d->m_bUseEGD);
284 m_cfg->writeEntry(
"UseEFile", d->m_bUseEFile);
285 m_cfg->writePathEntry(
"EGDPath", d->m_EGDPath);
291 m_cfg->setGroup(
"SSLv2");
292 for (
unsigned int i = 0; i < v2ciphers.count(); i++) {
294 ciphername.sprintf(
"cipher_%s", v2ciphers[i].ascii());
295 if (v2selectedciphers.contains(v2ciphers[i])) {
296 m_cfg->writeEntry(ciphername,
true);
297 }
else m_cfg->writeEntry(ciphername,
false);
300 m_cfg->setGroup(
"SSLv3");
301 for (
unsigned int i = 0; i < v3ciphers.count(); i++) {
303 ciphername.sprintf(
"cipher_%s", v3ciphers[i].ascii());
304 if (v3selectedciphers.contains(v3ciphers[i])) {
305 m_cfg->writeEntry(ciphername,
true);
306 }
else m_cfg->writeEntry(ciphername,
false);
313 TQString cfgName(TDEGlobal::dirs()->findResource(
"config",
"cryptodefaults"));
314 if (!cfgName.isEmpty())
315 ::chmod(TQFile::encodeName(cfgName), 0600);
TQString getCipherList()
Get the OpenSSL cipher list for selecting the list of ciphers to use in a connection.
bool warnOnMixed() const
Does the user want to be warned during mixed SSL/non-SSL mode.
bool autoSendX509() const
Does the user want X.509 client certificates to always be sent when possible?
void defaults()
Revert to default settings.
bool warnOnRevoked() const TDE_DEPRECATED
Do not use this.
KSSLSettings(bool readConfig=true)
Construct a KSSL Settings object.
bool sslv2() const
Does the user allow SSLv2.
void setWarnOnUnencrypted(bool x)
Change the user's warnOnUnencrypted() setting.
bool sslv3() const
Does the user allow SSLv3.
bool warnOnExpired() const TDE_DEPRECATED
Do not use this.
bool warnOnSelfSigned() const TDE_DEPRECATED
Do not use this.
bool tlsv1() const
Does the user allow TLSv1.
void load()
Load the user's settings.
void setSSLv3(bool enabled)
Change the user's SSLv3 preference.
bool warnOnEnter() const
Does the user want to be warned on entering SSL mode.
bool useEFile() const
Does the user want to use an entropy file?
void setSSLv2(bool enabled)
Change the user's SSLv2 preference.
void setWarnOnLeave(bool x)
Change the user's warnOnLeave() setting.
bool warnOnUnencrypted() const
Does the user want to be warned on sending unencrypted data.
bool promptSendX509() const
Does the user want to be prompted to send X.509 client certificates when possible?
void setTLSv1(bool enabled)
Change the user's TLSv1 preference.
TQString & getEGDPath()
Get the configured path to the entropy gathering daemon or entropy file.
void save()
Save the current settings.
~KSSLSettings()
Destroy this KSSL Settings object.
bool useEGD() const
Does the user want to use the Entropy Gathering Daemon?
void setWarnOnEnter(bool x)
Change the user's warnOnEnter() setting.
bool warnOnLeave() const
Does the user want to be warned on leaving SSL mode.