34#include "ksslsettings.h"
36#include <tdestandarddirs.h>
42#define crypt _openssl_crypt
43#include <openssl/ssl.h>
51 CipherNode(
const char *_name,
int _keylen) :
52 name(_name), keylen(_keylen) {}
55 inline int operator==(CipherNode &x)
56 {
return ((x.keylen == keylen) && (x.name == name)); }
57 inline int operator< (CipherNode &x) {
return keylen < x.keylen; }
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; }
64class KSSLSettingsPrivate {
66 KSSLSettingsPrivate() {
69 ~KSSLSettingsPrivate() {
88 d =
new KSSLSettingsPrivate;
89 m_cfg =
new TDEConfig(
"cryptodefaults",
false,
false);
91 if (!TDEGlobal::dirs()->addResourceType(
"kssl", TDEStandardDirs::kde_default(
"data") +
"kssl")) {
95 if (readConfig)
load();
128 bool firstcipher =
true;
129 SSL_METHOD *meth = 0L;
130 TQPtrList<CipherNode> cipherList;
132 cipherList.setAutoDelete(
true);
135 d->kossl = KOSSL::self();
137 if (m_bUseSSLv3 && m_bUseSSLv2)
138 meth = d->kossl->TLS_client_method();
140 meth = d->kossl->SSLv3_client_method();
141 else if (m_bUseSSLv2)
142 meth = d->kossl->SSLv2_client_method();
144 SSL_CTX *ctx = d->kossl->SSL_CTX_new(meth);
145 SSL* ssl = d->kossl->SSL_new(ctx);
146 STACK_OF(SSL_CIPHER)* sk = d->kossl->SSL_get_ciphers(ssl);
147 int cnt = d->kossl->OPENSSL_sk_num(sk);
148 for (
int i=0; i< cnt; i++) {
149 SSL_CIPHER *sc =
reinterpret_cast<SSL_CIPHER*
>(d->kossl->OPENSSL_sk_value(sk,i));
153 if(!strcmp(
"SSLv2", d->kossl->SSL_CIPHER_get_version(sc)))
154 m_cfg->setGroup(
"SSLv2");
156 m_cfg->setGroup(
"SSLv3");
158 tcipher.sprintf(
"cipher_%s", d->kossl->SSL_CIPHER_get_name(sc));
159 int bits = d->kossl->SSL_CIPHER_get_bits(sc, NULL);
160 if (m_cfg->readBoolEntry(tcipher, bits >= 56)) {
161 CipherNode *xx =
new CipherNode(d->kossl->SSL_CIPHER_get_name(sc),bits);
162 if (!cipherList.contains(xx))
163 cipherList.prepend(xx);
168 d->kossl->SSL_free(ssl);
169 d->kossl->SSL_CTX_free(ctx);
173 for (
unsigned int i = 0; i < cipherList.count(); i++) {
175 while ((j = cipherList.at(i)) != 0L) {
176 if (j->name.contains(
"ADH-") || j->name.contains(
"NULL-") || j->name.contains(
"DES-CBC3-SHA") || j->name.contains(
"FZA")) {
177 cipherList.remove(j);
185 while (!cipherList.isEmpty()) {
188 else clist.append(
":");
189 clist.append(cipherList.getLast()->name);
190 cipherList.removeLast();
193 kdDebug(7029) <<
"Cipher list is: " << clist << endl;
201 m_cfg->reparseConfiguration();
203 m_cfg->setGroup(
"TLS");
204 m_bUseTLSv1 = m_cfg->readBoolEntry(
"Enabled",
true);
208#if defined(OPENSSL_NO_SSL3)
211 m_cfg->setGroup(
"SSLv3");
212 m_bUseSSLv3 = m_cfg->readBoolEntry(
"Enabled",
true);
215 m_cfg->setGroup(
"Warnings");
216 m_bWarnOnEnter = m_cfg->readBoolEntry(
"OnEnter",
false);
217 m_bWarnOnLeave = m_cfg->readBoolEntry(
"OnLeave",
true);
218 m_bWarnOnUnencrypted = m_cfg->readBoolEntry(
"OnUnencrypted",
true);
219 m_bWarnOnMixed = m_cfg->readBoolEntry(
"OnMixed",
true);
221 m_cfg->setGroup(
"Validation");
222 m_bWarnSelfSigned = m_cfg->readBoolEntry(
"WarnSelfSigned",
true);
223 m_bWarnExpired = m_cfg->readBoolEntry(
"WarnExpired",
true);
224 m_bWarnRevoked = m_cfg->readBoolEntry(
"WarnRevoked",
true);
226 m_cfg->setGroup(
"EGD");
227 d->m_bUseEGD = m_cfg->readBoolEntry(
"UseEGD",
false);
228 d->m_bUseEFile = m_cfg->readBoolEntry(
"UseEFile",
false);
229 d->m_EGDPath = m_cfg->readPathEntry(
"EGDPath");
231 m_cfg->setGroup(
"Auth");
232 d->m_bSendX509 = (
"send" == m_cfg->readEntry(
"AuthMethod",
""));
233 d->m_bPromptX509 = (
"prompt" == m_cfg->readEntry(
"AuthMethod",
""));
247 m_bWarnOnEnter =
false;
248 m_bWarnOnLeave =
true;
249 m_bWarnOnUnencrypted =
true;
250 m_bWarnOnMixed =
true;
251 m_bWarnSelfSigned =
true;
252 m_bWarnExpired =
true;
253 m_bWarnRevoked =
true;
254 d->m_bUseEGD =
false;
255 d->m_bUseEFile =
false;
261 m_cfg->setGroup(
"TLS");
262 m_cfg->writeEntry(
"Enabled", m_bUseTLSv1);
264 m_cfg->setGroup(
"SSLv2");
265 m_cfg->writeEntry(
"Enabled", m_bUseSSLv2);
267 m_cfg->setGroup(
"SSLv3");
268 m_cfg->writeEntry(
"Enabled", m_bUseSSLv3);
270 m_cfg->setGroup(
"Warnings");
271 m_cfg->writeEntry(
"OnEnter", m_bWarnOnEnter);
272 m_cfg->writeEntry(
"OnLeave", m_bWarnOnLeave);
273 m_cfg->writeEntry(
"OnUnencrypted", m_bWarnOnUnencrypted);
274 m_cfg->writeEntry(
"OnMixed", m_bWarnOnMixed);
276 m_cfg->setGroup(
"Validation");
277 m_cfg->writeEntry(
"WarnSelfSigned", m_bWarnSelfSigned);
278 m_cfg->writeEntry(
"WarnExpired", m_bWarnExpired);
279 m_cfg->writeEntry(
"WarnRevoked", m_bWarnRevoked);
281 m_cfg->setGroup(
"EGD");
282 m_cfg->writeEntry(
"UseEGD", d->m_bUseEGD);
283 m_cfg->writeEntry(
"UseEFile", d->m_bUseEFile);
284 m_cfg->writePathEntry(
"EGDPath", d->m_EGDPath);
290 m_cfg->setGroup(
"SSLv2");
291 for (
unsigned int i = 0; i < v2ciphers.count(); i++) {
293 ciphername.sprintf(
"cipher_%s", v2ciphers[i].ascii());
294 if (v2selectedciphers.contains(v2ciphers[i])) {
295 m_cfg->writeEntry(ciphername,
true);
296 }
else m_cfg->writeEntry(ciphername,
false);
299 m_cfg->setGroup(
"SSLv3");
300 for (
unsigned int i = 0; i < v3ciphers.count(); i++) {
302 ciphername.sprintf(
"cipher_%s", v3ciphers[i].ascii());
303 if (v3selectedciphers.contains(v3ciphers[i])) {
304 m_cfg->writeEntry(ciphername,
true);
305 }
else m_cfg->writeEntry(ciphername,
false);
312 TQString cfgName(TDEGlobal::dirs()->findResource(
"config",
"cryptodefaults"));
313 if (!cfgName.isEmpty())
314 ::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.