1
/***************************************************************************
3
* knetworkmanager-connection_setting_wireless_security_widget.cpp
4
* - A NetworkManager frontend for KDE
6
* Copyright (C) 2005, 2006 Novell, Inc.
8
* Author: Helmut Schaa <hschaa@suse.de>, <Helmut.Schaa@gmx.de>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
**************************************************************************/
28
#include <qlineedit.h>
29
#include <qgroupbox.h>
30
#include <qbuttongroup.h>
31
#include <qwidgetstack.h>
32
#include <qcombobox.h>
33
#include <qradiobutton.h>
35
#include <qcheckbox.h>
38
#include <kurlrequester.h>
43
/* knetworkmanager headers */
44
#include "knetworkmanager-accesspoint.h"
45
#include "knetworkmanager-wireless_device.h"
46
#include "knetworkmanager-device.h"
47
#include "knetworkmanager-connection.h"
48
#include "knetworkmanager-connection_setting_wireless_security_widget.h"
49
#include "knetworkmanager-connection_setting_wireless_security.h"
50
#include "knetworkmanager-connection_setting_wireless.h"
51
#include "knetworkmanager-connection_setting_8021x.h"
54
#include "knetworkmanager-wireless_manager.h"
56
#define WPA_PMK_LEN 32
58
using namespace ConnectionSettings;
61
class WirelessSecurityWEPImpl
63
WirelessSecurityWEPImpl::WirelessSecurityWEPImpl(WirelessSecurity* sec, QWidget* parent, const char* name, WFlags fl)
64
: ConnectionSettingWirelessSecurityWEP(parent, name, fl)
65
, _security_setting(sec)
66
, _wepKeyType( WEPKEY_TYPE_HEX )
68
cboAuthentication->insertItem(i18n("Open System"), 0);
69
cboAuthentication->insertItem(i18n("Shared Key"), 1);
70
if (_security_setting->getAuthAlg() == WirelessSecurity::AUTH_ALG_OPEN)
71
cboAuthentication->setCurrentItem(0);
72
else if (_security_setting->getAuthAlg() == WirelessSecurity::AUTH_ALG_SHARED)
73
cboAuthentication->setCurrentItem(1);
75
cbKeyType->insertItem(i18n("WEP 40/128-bit ASCII"), WEPKEY_TYPE_ASCII);
76
cbKeyType->insertItem(i18n("WEP 40/128-bit Hexadecimal"), WEPKEY_TYPE_HEX);
77
cbKeyType->insertItem(i18n("WEP 128-bit passphrase"), WEPKEY_TYPE_PASSPHRASE);
78
cbKeyType->setCurrentItem(_wepKeyType );
80
txtWEPKey0->setText(_security_setting->getWepKey(0));
81
txtWEPKey1->setText(_security_setting->getWepKey(1));
82
txtWEPKey2->setText(_security_setting->getWepKey(2));
83
txtWEPKey3->setText(_security_setting->getWepKey(3));
85
switch(_security_setting->getWepTxidx())
88
rbKeyIdx0->setChecked(true);
91
rbKeyIdx1->setChecked(true);
94
rbKeyIdx2->setChecked(true);
97
rbKeyIdx3->setChecked(true);
100
rbKeyIdx0->setChecked(true);
104
connect(cboAuthentication, SIGNAL(activated(int)), this, SLOT(slotAuthAlgChanged(int)));
105
connect(cbKeyType, SIGNAL(activated(int)), this, SLOT(slotKeyTypeChanged(int)));
106
connect(txtWEPKey0, SIGNAL(textChanged(const QString&)), this, SLOT(slotWepKey0Changed(const QString&)));
107
connect(txtWEPKey1, SIGNAL(textChanged(const QString&)), this, SLOT(slotWepKey1Changed(const QString&)));
108
connect(txtWEPKey2, SIGNAL(textChanged(const QString&)), this, SLOT(slotWepKey2Changed(const QString&)));
109
connect(txtWEPKey3, SIGNAL(textChanged(const QString&)), this, SLOT(slotWepKey3Changed(const QString&)));
111
connect(rbKeyIdx0, SIGNAL(toggled(bool)), this, SLOT(slotWepIdx0Checked(bool)));
112
connect(rbKeyIdx1, SIGNAL(toggled(bool)), this, SLOT(slotWepIdx1Checked(bool)));
113
connect(rbKeyIdx2, SIGNAL(toggled(bool)), this, SLOT(slotWepIdx2Checked(bool)));
114
connect(rbKeyIdx3, SIGNAL(toggled(bool)), this, SLOT(slotWepIdx3Checked(bool)));
117
void WirelessSecurityWEPImpl::slotAuthAlgChanged(int index)
120
_security_setting->setAuthAlg(WirelessSecurity::AUTH_ALG_OPEN);
122
_security_setting->setAuthAlg(WirelessSecurity::AUTH_ALG_SHARED);
125
void WirelessSecurityWEPImpl::slotKeyTypeChanged(int index)
127
_wepKeyType = (WEPKEY_TYPE)index;
129
// update all WEP-Keys here due to the new key_type
132
void WirelessSecurityWEPImpl::slotWepKey0Changed(const QString &key)
134
QCString hashed = getHashedWEPKey(key, _wepKeyType);
135
_security_setting->setWepKey(0, hashed);
138
void WirelessSecurityWEPImpl::slotWepKey1Changed(const QString &key)
140
QCString hashed = getHashedWEPKey(key, _wepKeyType);
141
_security_setting->setWepKey(1, hashed);
144
void WirelessSecurityWEPImpl::slotWepKey2Changed(const QString &key)
146
QCString hashed = getHashedWEPKey(key, _wepKeyType);
147
_security_setting->setWepKey(2, hashed);
150
void WirelessSecurityWEPImpl::slotWepKey3Changed(const QString& key)
152
QCString hashed = getHashedWEPKey(key, _wepKeyType);
153
_security_setting->setWepKey(3, hashed);
156
void WirelessSecurityWEPImpl::slotWepIdx0Checked(bool check)
159
_security_setting->setWepTxidx(0);
162
void WirelessSecurityWEPImpl::slotWepIdx1Checked(bool check)
165
_security_setting->setWepTxidx(1);
168
void WirelessSecurityWEPImpl::slotWepIdx2Checked(bool check)
171
_security_setting->setWepTxidx(2);
174
void WirelessSecurityWEPImpl::slotWepIdx3Checked(bool check)
177
_security_setting->setWepTxidx(3);
181
WirelessSecurityWEPImpl::getHashedWEPKey(QString key, WEPKEY_TYPE type) const
186
case WEPKEY_TYPE_HEX:
187
return QCString(key);
189
case WEPKEY_TYPE_ASCII:
190
hashed = String2Hex(QCString(key), key.length() * 2);
193
case WEPKEY_TYPE_PASSPHRASE:
194
return getWEP128PassphraseHash(QCString(key));
201
WirelessSecurityWEPImpl::getWEP128PassphraseHash(QCString input) const
208
if (input.isNull()) return input;
210
input_len = input.length();
214
/* Get at least 64 bytes */
215
for (i = 0; i < 64; i++)
216
md5_data [i] = input [i % input_len];
218
/* Null terminate md5 seed data and hash it */
220
gnome_keyring_md5_string (md5_data, (unsigned char*)digest.data());
221
return (String2Hex(QByteArray(digest), 26));
226
WirelessSecurityWEPImpl::String2Hex(QByteArray bytes, int final_len) const
228
QCString result(final_len+1);
229
static char hex_digits[] = "0123456789abcdef";
230
result.resize(bytes.size() * 2 + 1);
231
for (uint i = 0; i < bytes.size(); i++)
233
result[2*i] = hex_digits[(bytes[i] >> 4) & 0xf];
234
result[2*i+1] = hex_digits[bytes[i] & 0xf];
236
/* Cut converted key off at the correct length for this cipher type */
238
result[final_len] = '\0';
244
class WirelessSecurityWEPEncryptionImpl
246
WirelessSecurityWEPEncryptionImpl::WirelessSecurityWEPEncryptionImpl(WirelessSecurity* security_setting, QWidget* parent, const char* name, WFlags fl)
247
: ConnectionSettingWirelessSecurityWEPEncryption(parent, name, fl)
248
, _security_setting(security_setting)
250
cboEncryption->insertItem(i18n("None"));
251
cboEncryption->insertItem(i18n("Dynamic WEP"));
256
class WirelessSecurityWPAVersionImpl
258
WirelessSecurityWPAVersionImpl::WirelessSecurityWPAVersionImpl(WirelessSecurity* security_setting, QWidget* parent, const char* name, WFlags fl)
259
: ConnectionSettingWirelessSecurityWPAVersion(parent, name, fl)
260
, _security_setting(security_setting)
262
cbWPA->setChecked(_security_setting->getProto() & WirelessSecurity::PROTO_WPA);
263
cbRSN->setChecked(_security_setting->getProto() & WirelessSecurity::PROTO_RSN);
265
connect(cbWPA, SIGNAL(toggled(bool)), this, SLOT(slotWPA1(bool)));
266
connect(cbRSN, SIGNAL(toggled(bool)), this, SLOT(slotWPA2(bool)));
268
connect(grpUseWPAVersion, SIGNAL(toggled(bool)), this, SLOT(slotAuto(bool)));
272
WirelessSecurityWPAVersionImpl::slotAuto(bool on)
277
_security_setting->setProto(WirelessSecurity::PROTO_AUTO);
281
// use selected wpa-version
282
Q_UINT32 proto = WirelessSecurity::PROTO_NONE;
283
if (cbWPA->isChecked())
284
proto |= WirelessSecurity::PROTO_WPA;
285
if (cbRSN->isChecked())
286
proto |= WirelessSecurity::PROTO_RSN;
287
_security_setting->setProto(proto);
292
WirelessSecurityWPAVersionImpl::slotWPA1(bool on)
295
_security_setting->addProto(WirelessSecurity::PROTO_WPA);
297
_security_setting->delProto(WirelessSecurity::PROTO_WPA);
301
WirelessSecurityWPAVersionImpl::slotWPA2(bool on)
304
_security_setting->addProto(WirelessSecurity::PROTO_RSN);
306
_security_setting->delProto(WirelessSecurity::PROTO_RSN);
310
class WirelessSecurityWPACipherImpl
312
WirelessSecurityWPACipherImpl::WirelessSecurityWPACipherImpl(WirelessSecurity* security_setting, QWidget* parent, const char* name, WFlags fl)
313
: ConnectionSettingWirelessSecurityWPACipher(parent, name, fl)
314
, _security_setting(security_setting)
316
connect(grpUseCipher, SIGNAL(toggled(bool)), this, SLOT(slotCipherChangedAuto(bool)));
318
connect(chkGroupCipherTKIP, SIGNAL(toggled(bool)), this, SLOT(slotGroupCipherChangedTKIP(bool)));
319
connect(chkGroupCipherCCMP, SIGNAL(toggled(bool)), this, SLOT(slotGroupCipherChangedCCMP(bool)));
320
connect(chkGroupCipherWEP40, SIGNAL(toggled(bool)), this, SLOT(slotGroupCipherChangedWEP40(bool)));
321
connect(chkGroupCipherWEP104, SIGNAL(toggled(bool)), this, SLOT(slotGroupCipherChangedWEP104(bool)));
323
connect(chkPairwiseCipherTKIP, SIGNAL(toggled(bool)), this, SLOT(slotPairwiseCipherChangedTKIP(bool)));
324
connect(chkPairwiseCipherCCMP, SIGNAL(toggled(bool)), this, SLOT(slotPairwiseCipherChangedCCMP(bool)));
326
chkPairwiseCipherCCMP->setChecked(_security_setting->getPairwiseCiphers() & WirelessSecurity::CIPHER_CCMP);
327
chkPairwiseCipherTKIP->setChecked(_security_setting->getPairwiseCiphers() & WirelessSecurity::CIPHER_TKIP);
329
chkGroupCipherCCMP->setChecked(_security_setting->getGroupCiphers() & WirelessSecurity::CIPHER_CCMP);
330
chkGroupCipherTKIP->setChecked(_security_setting->getGroupCiphers() & WirelessSecurity::CIPHER_TKIP);
331
chkGroupCipherWEP40->setChecked(_security_setting->getGroupCiphers() & WirelessSecurity::CIPHER_WEP40);
332
chkGroupCipherWEP104->setChecked(_security_setting->getGroupCiphers() & WirelessSecurity::CIPHER_WEP104);
337
WirelessSecurityWPACipherImpl::slotCipherChangedAuto(bool checked)
341
// select auto for both ciphers
342
_security_setting->setGroupCiphers(WirelessSecurity::CIPHER_AUTO);
343
_security_setting->setPairwiseCiphers(WirelessSecurity::CIPHER_AUTO);
347
// use the already selected ciphers
350
Q_UINT32 cipher = WirelessSecurity::CIPHER_NONE;
351
if (chkGroupCipherTKIP->isChecked())
352
cipher |= WirelessSecurity::CIPHER_TKIP;
353
if (chkGroupCipherCCMP->isChecked())
354
cipher |= WirelessSecurity::CIPHER_CCMP;
355
if (chkGroupCipherWEP40->isChecked())
356
cipher |= WirelessSecurity::CIPHER_WEP40;
357
if (chkGroupCipherWEP104->isChecked())
358
cipher |= WirelessSecurity::CIPHER_WEP104;
359
_security_setting->setGroupCiphers(cipher);
362
cipher = WirelessSecurity::CIPHER_NONE;
363
if (chkPairwiseCipherTKIP->isChecked())
364
cipher |= WirelessSecurity::CIPHER_TKIP;
365
if (chkPairwiseCipherCCMP->isChecked())
366
cipher |= WirelessSecurity::CIPHER_CCMP;
367
_security_setting->setPairwiseCiphers(cipher);
373
WirelessSecurityWPACipherImpl::slotGroupCipherChangedTKIP(bool checked)
376
_security_setting->setGroupCiphers(_security_setting->getGroupCiphers() | WirelessSecurity::CIPHER_TKIP);
378
_security_setting->setGroupCiphers(_security_setting->getGroupCiphers() & (!WirelessSecurity::CIPHER_TKIP));
382
WirelessSecurityWPACipherImpl::slotGroupCipherChangedCCMP(bool checked)
385
_security_setting->setGroupCiphers(_security_setting->getGroupCiphers() | WirelessSecurity::CIPHER_CCMP);
387
_security_setting->setGroupCiphers(_security_setting->getGroupCiphers() & (!WirelessSecurity::CIPHER_CCMP));
391
WirelessSecurityWPACipherImpl::slotGroupCipherChangedWEP40(bool checked)
394
_security_setting->setGroupCiphers(_security_setting->getGroupCiphers() | WirelessSecurity::CIPHER_WEP40);
396
_security_setting->setGroupCiphers(_security_setting->getGroupCiphers() & (!WirelessSecurity::CIPHER_WEP40));
400
WirelessSecurityWPACipherImpl::slotGroupCipherChangedWEP104(bool checked)
403
_security_setting->setGroupCiphers(_security_setting->getGroupCiphers() | WirelessSecurity::CIPHER_WEP104);
405
_security_setting->setGroupCiphers(_security_setting->getGroupCiphers() & (!WirelessSecurity::CIPHER_WEP104));
409
WirelessSecurityWPACipherImpl::slotPairwiseCipherChangedTKIP(bool checked)
412
_security_setting->setPairwiseCiphers(_security_setting->getPairwiseCiphers() | WirelessSecurity::CIPHER_TKIP);
414
_security_setting->setPairwiseCiphers(_security_setting->getPairwiseCiphers() & (!WirelessSecurity::CIPHER_TKIP));
418
WirelessSecurityWPACipherImpl::slotPairwiseCipherChangedCCMP(bool checked)
421
_security_setting->setPairwiseCiphers(_security_setting->getPairwiseCiphers() | WirelessSecurity::CIPHER_CCMP);
423
_security_setting->setPairwiseCiphers(_security_setting->getPairwiseCiphers() & (!WirelessSecurity::CIPHER_CCMP));
427
class WirelessSecurityWPAPSK
429
WirelessSecurityWPAPSKImpl::WirelessSecurityWPAPSKImpl(WirelessSecurity* security_setting, Wireless* wireless_setting, QWidget* parent, const char* name, WFlags fl)
430
: ConnectionSettingWirelessSecurityWPAPSK(parent, name, fl)
431
, _security_setting(security_setting)
432
, _wireless_setting(wireless_setting)
434
txtPSK->setText(_security_setting->getPSK());
435
connect(txtPSK, SIGNAL(textChanged(const QString&)), this, SLOT(slotPSKChanged(const QString&)));
439
WirelessSecurityWPAPSKImpl::slotPSKChanged(const QString& psk)
442
if (_wireless_setting)
445
if (psk.length() == 64)
449
QCString buffer(WPA_PMK_LEN * 2);
450
QByteArray essid = _wireless_setting->getEssid();
451
pbkdf2_sha1 (QCString(psk).data(), essid.data(), essid.size(), 4096, (uint8_t*)buffer.data(), WPA_PMK_LEN);
452
hashed = String2Hex(buffer, WPA_PMK_LEN*2);
454
_security_setting->setPSK(hashed);
459
WirelessSecurityWPAPSKImpl::String2Hex(QByteArray bytes, int final_len) const
461
QCString result(final_len+1);
462
static char hex_digits[] = "0123456789abcdef";
463
result.resize(bytes.size() * 2 + 1);
464
for (uint i = 0; i < bytes.size(); i++)
466
result[2*i] = hex_digits[(bytes[i] >> 4) & 0xf];
467
result[2*i+1] = hex_digits[bytes[i] & 0xf];
469
/* Cut converted key off at the correct length for this cipher type */
471
result[final_len] = '\0';
476
class WirelessSecurityEAPImpl
478
WirelessSecurityEAPImpl::WirelessSecurityEAPImpl(IEEE8021x* security_setting, WirelessSecurityPhase2Impl* phase2_widget, QWidget* parent, const char* name, WFlags fl)
479
: ConnectionSettingWirelessSecurityEAP(parent, name, fl)
480
, _security_setting(security_setting)
481
, _phase2_widget(phase2_widget)
483
// insert all EAP-Methods
485
cboMethod->insertItem(i18n("None"), index);
486
_eapIndexMap[index] = IEEE8021x::EAP_PHASE1_NONE;
488
cboMethod->insertItem(i18n("TTLS"), ++index);
489
_eapIndexMap[index] = IEEE8021x::EAP_PHASE1_TTLS;
491
cboMethod->insertItem(i18n("PEAP"), ++index);
492
_eapIndexMap[index] = IEEE8021x::EAP_PHASE1_PEAP;
494
cboMethod->insertItem(i18n("TLS"), ++index);
495
_eapIndexMap[index] = IEEE8021x::EAP_PHASE1_TLS;
497
cboMethod->insertItem(i18n("Leap"), ++index);
498
_eapIndexMap[index] = IEEE8021x::EAP_PHASE1_LEAP;
500
cboMethod->insertItem(i18n("MD5"), ++index);
501
_eapIndexMap[index] = IEEE8021x::EAP_PHASE1_MD5;
503
cboMethod->insertItem(i18n("FAST"), ++index);
504
_eapIndexMap[index] = IEEE8021x::EAP_PHASE1_FAST;
506
cboMethod->insertItem(i18n("SIM"), ++index);
507
_eapIndexMap[index] = IEEE8021x::EAP_PHASE1_SIM;
509
// preselect the correct method
510
QBiDirectionalMap<int, IEEE8021x::EAP_PHASE1>::Iterator it = _eapIndexMap.findData(_security_setting->getEAP());
511
cboMethod->setCurrentItem(it.key());
513
txtIdentity->setText(_security_setting->getIdentity());
514
txtAnonIdentity->setText(_security_setting->getAnonIdentity());
515
txtPassword->setText(_security_setting->getPassword());
517
// get notified if the method changes
518
connect(cboMethod, SIGNAL(activated(int)), this, SLOT(slotMethodChanged(int)));
519
connect(txtIdentity, SIGNAL(textChanged(const QString&)), this, SLOT(slotIdentityChanged(const QString&)));
520
connect(txtAnonIdentity, SIGNAL(textChanged(const QString&)), this, SLOT(slotAnonIdentityChanged(const QString&)));
521
connect(txtPassword, SIGNAL(textChanged(const QString&)), this, SLOT(slotPasswordChanged(const QString&)));
524
void WirelessSecurityEAPImpl::slotMethodChanged(int index)
526
// new method choosen
527
IEEE8021x::EAP_PHASE1 eap = _eapIndexMap[index];
528
_security_setting->setEAP(eap);
530
_phase2_widget->setAllowedPhase2Methods(_security_setting->getAllowedPhase2Methods());
533
void WirelessSecurityEAPImpl::slotIdentityChanged(const QString& identity)
535
_security_setting->setIdentity(identity);
538
void WirelessSecurityEAPImpl::slotAnonIdentityChanged(const QString& identity)
540
_security_setting->setAnonIdentity(identity);
543
void WirelessSecurityEAPImpl::slotPasswordChanged(const QString& pwd)
545
_security_setting->setPassword(QString(txtPassword->password()));
549
class WirelessSecurityPhase2Impl
551
WirelessSecurityPhase2Impl::WirelessSecurityPhase2Impl(IEEE8021x* security_setting, QWidget* parent, const char* name, WFlags fl)
552
: ConnectionSettingWirelessSecurityPhase2(parent, name, fl)
553
, _security_setting(security_setting)
555
_allowed_methods.append(IEEE8021x::EAP_PHASE2_AUTH_NONE);
556
updateMethodComboBox();
558
connect(cboPhase2Method, SIGNAL(activated(int)), this, SLOT(slotPhase2MethodChanged(int)));
561
void WirelessSecurityPhase2Impl::updateMethodComboBox()
563
// insert all phase2 EAP-Methods
565
cboPhase2Method->clear();
566
_eapIndexMap.clear();
568
for (QValueList<IEEE8021x::EAP_PHASE2>::Iterator it = _allowed_methods.begin(); it != _allowed_methods.end(); ++it)
570
if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_NONE)
572
cboPhase2Method->insertItem(i18n("None"), index);
573
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_NONE;
576
else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_MSCHAPV2)
578
cboPhase2Method->insertItem(i18n("MSCHAPv2"), index);
579
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_MSCHAPV2;
582
else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_PAP)
584
cboPhase2Method->insertItem(i18n("PAP"), index);
585
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_PAP;
588
else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_CHAP)
590
cboPhase2Method->insertItem(i18n("CHAP"), index);
591
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_CHAP;
594
else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_MSCHAP)
596
cboPhase2Method->insertItem(i18n("MSCHAP"), index);
597
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_MSCHAP;
600
else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_GTC)
602
cboPhase2Method->insertItem(i18n("GTC"), index);
603
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_GTC;
606
else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_OTP)
608
cboPhase2Method->insertItem(i18n("OTP"), index);
609
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_OTP;
612
else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_MD5)
614
cboPhase2Method->insertItem(i18n("MD5"), index);
615
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_MD5;
618
else if ((*it) == IEEE8021x::EAP_PHASE2_AUTH_TLS)
620
cboPhase2Method->insertItem(i18n("TLS"), index);
621
_eapIndexMap[index] = IEEE8021x::EAP_PHASE2_AUTH_TLS;
626
// preselect the correct method
627
QBiDirectionalMap<int, IEEE8021x::EAP_PHASE2>::Iterator it = _eapIndexMap.findData(_security_setting->getPhase2EAP());
628
if (it != _eapIndexMap.end())
630
cboPhase2Method->setCurrentItem(it.key());
631
_security_setting->setPhase2EAP(it.data());
635
cboPhase2Method->setCurrentItem(0);
636
_security_setting->setPhase2EAP(_eapIndexMap[0]);
640
void WirelessSecurityPhase2Impl::setAllowedPhase2Methods(const QValueList<IEEE8021x::EAP_PHASE2>& list)
642
_allowed_methods = list;
643
updateMethodComboBox();
646
void WirelessSecurityPhase2Impl::slotPhase2MethodChanged(int index)
648
// new method choosen
649
IEEE8021x::EAP_PHASE2 eap = _eapIndexMap[index];
650
_security_setting->setPhase2EAP(eap);
654
class WirelessSecurityWidgetImpl
657
WirelessSecurityWidgetImpl::WirelessSecurityWidgetImpl(Connection* conn, bool new_conn, QWidget* parent, const char* name, WFlags fl)
658
: WidgetInterface(parent, name, fl)
660
_security_setting = dynamic_cast<WirelessSecurity*> (conn->getSetting(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME));
661
_wireless_setting = dynamic_cast<Wireless*> (conn->getSetting(NM_SETTING_WIRELESS_SETTING_NAME));
662
_ieee8021x_setting = dynamic_cast<IEEE8021x*> (conn->getSetting(NM_SETTING_802_1X_SETTING_NAME));
663
_new_conn = new_conn;
665
QVBoxLayout* layout = new QVBoxLayout(this, 1, 1);
666
_mainWid = new ConnectionSettingWirelessSecurityWidget(this);
667
layout->addWidget(_mainWid);
669
QTimer::singleShot(0, this, SLOT(slotInit()));
673
WirelessSecurityWidgetImpl::slotInit()
675
// create all security widgets...
676
QWidget* wep = new WirelessSecurityWEPImpl(_security_setting, _mainWid->groupUseEncryption);
677
QWidget* phase2 = new WirelessSecurityPhase2Impl(_ieee8021x_setting, _mainWid->groupUseEncryption);
678
QWidget* eap = new WirelessSecurityEAPImpl(_ieee8021x_setting, (WirelessSecurityPhase2Impl*)phase2, _mainWid->groupUseEncryption);
679
QWidget* wpaversion = new WirelessSecurityWPAVersionImpl(_security_setting, _mainWid->groupUseEncryption);
680
QWidget* wpacipher = new WirelessSecurityWPACipherImpl(_security_setting, _mainWid->groupUseEncryption);
681
QWidget* wpapsk = new WirelessSecurityWPAPSKImpl(_security_setting, _wireless_setting, _mainWid->groupUseEncryption);
682
QWidget* wepencryption = new WirelessSecurityWEPEncryptionImpl(_security_setting, _mainWid->groupUseEncryption);
684
wep->setHidden(true);
685
eap->setHidden(true);
686
wpaversion->setHidden(true);
687
wpacipher->setHidden(true);
688
phase2->setHidden(true);
689
wpapsk->setHidden(true);
690
wepencryption->setHidden(true);
692
_widgets[SECURITY_WEP].clear();
693
_widgets[SECURITY_WPA_PSK].clear();
694
_widgets[SECURITY_WPA_EAP].clear();
695
_widgets[SECURITY_IEEE8021X].clear();
697
// create WEP widget list
698
_widgets[SECURITY_WEP].append(wep);
700
// create WPA PSK widget list
701
_extra_widgets[SECURITY_WPA_PSK].append(wpaversion);
702
_extra_widgets[SECURITY_WPA_PSK].append(wpacipher);
703
_widgets[SECURITY_WPA_PSK].append(wpapsk);
705
// create WPA EAP widget list
706
_extra_widgets[SECURITY_WPA_EAP].append(wpaversion);
707
_extra_widgets[SECURITY_WPA_EAP].append(wpacipher);
708
_widgets[SECURITY_WPA_EAP].append(eap);
709
_widgets[SECURITY_WPA_EAP].append(phase2);
711
// create IEEE8021X widget list
712
_widgets[SECURITY_IEEE8021X].append(wepencryption);
713
_widgets[SECURITY_IEEE8021X].append(eap);
715
connect(_mainWid->cboSecurity, SIGNAL(activated(int)), this, SLOT(slotComboSecurityActivated(int)));
716
connect(_mainWid->groupUseEncryption, SIGNAL(toggled(bool)), this, SLOT(slotUseEncryptionToggled(bool)));
717
connect(_mainWid->pbExtra, SIGNAL(toggled(bool)), this, SLOT(slotExtraSettingsToggled(bool)));
722
WirelessSecurityWidgetImpl::Activate()
724
printf("Activate %s\n", _new_conn ? "New" : "Edit");
729
WirelessSecurityWidgetImpl::comboSecurityInit()
733
QValueList<SecurityMethods> allowed_methods;
734
_mainWid->cboSecurity->clear();
736
// TODO: Preselect the right security method
737
// We should have an Essid already, fetch all possible APs
738
QValueList<AccessPoint *> aps;
739
if (_new_conn && !_wireless_setting->getEssid().isEmpty())
741
aps = WirelessManager::getAccessPointsForEssid(_wireless_setting->getEssid());
743
printf("Hugo %s\n", QString(QCString(_wireless_setting->getEssid())).ascii());
748
// if at least one AP has this security setting show the entry in the combobox
749
for (QValueList<AccessPoint*>::Iterator it = aps.begin(); it != aps.end(); ++it)
751
if((*it)->isEncrypted())
753
printf("AP %s is encrypted\n", (*it)->getDisplaySsid().ascii());
754
if ((*it)->getRsnFlags() != NM_802_11_AP_SEC_NONE || (*it)->getWpaFlags() != NM_802_11_AP_SEC_NONE)
757
if ((*it)->getRsnFlags() & NM_802_11_AP_SEC_KEY_MGMT_PSK || (*it)->getWpaFlags() & NM_802_11_AP_SEC_KEY_MGMT_PSK)
758
if (!allowed_methods.contains(SECURITY_WPA_PSK))
759
allowed_methods.append(SECURITY_WPA_PSK);
762
if ((*it)->getRsnFlags() & NM_802_11_AP_SEC_KEY_MGMT_802_1X || (*it)->getWpaFlags() & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
763
if (!allowed_methods.contains(SECURITY_WPA_EAP))
764
allowed_methods.append(SECURITY_WPA_EAP);
767
// No WPA & RSN => WEP or dynamic WEP with 802.1x authentication
768
// TODO: an AP can provide WEP in addition to WPA
769
if (!allowed_methods.contains(SECURITY_WEP))
770
allowed_methods.append(SECURITY_WEP);
771
if (!allowed_methods.contains(SECURITY_IEEE8021X))
772
allowed_methods.append(SECURITY_IEEE8021X);
776
// insert only allowed security methods
777
if (allowed_methods.contains(SECURITY_WPA_PSK))
779
_securityComboMap.insert(index, SECURITY_WPA_PSK);
780
_mainWid->cboSecurity->insertItem(i18n("WPA Personal"), index++);
783
if (allowed_methods.contains(SECURITY_WPA_EAP))
785
_securityComboMap.insert(index, SECURITY_WPA_EAP);
786
_mainWid->cboSecurity->insertItem(i18n("WPA Enterprise"), index++);
789
if (allowed_methods.contains(SECURITY_WEP))
791
_securityComboMap.insert(index, SECURITY_WEP);
792
_mainWid->cboSecurity->insertItem(i18n("WEP"), index++);
795
if (allowed_methods.contains(SECURITY_IEEE8021X))
797
_securityComboMap.insert(index, SECURITY_IEEE8021X);
798
_mainWid->cboSecurity->insertItem(i18n("IEEE 802.1X"), index++);
803
// insert all possible authentication methods
804
_mainWid->cboSecurity->insertItem(i18n("WEP"),SECURITY_WEP );
805
_mainWid->cboSecurity->insertItem(i18n("WPA Personal"), SECURITY_WPA_PSK);
806
_mainWid->cboSecurity->insertItem(i18n("WPA Enterprise"), SECURITY_WPA_EAP);
807
_mainWid->cboSecurity->insertItem(i18n("IEEE 802.1X"), SECURITY_IEEE8021X);
808
_securityComboMap.insert(SECURITY_WEP, SECURITY_WEP);
809
_securityComboMap.insert(SECURITY_WPA_PSK, SECURITY_WPA_PSK);
810
_securityComboMap.insert(SECURITY_WPA_EAP, SECURITY_WPA_EAP);
811
_securityComboMap.insert(SECURITY_IEEE8021X, SECURITY_IEEE8021X);
816
switch(_security_setting->getKeyMgmt())
818
case WirelessSecurity::KEY_MGMT_NONE:
819
if (_security_setting->getAuthAlg() == WirelessSecurity::AUTH_ALG_SHARED ||
820
!_security_setting->getWepKey(0).isEmpty() ||
821
!_security_setting->getWepKey(1).isEmpty() ||
822
!_security_setting->getWepKey(2).isEmpty() ||
823
!_security_setting->getWepKey(3).isEmpty() )
825
_mainWid->groupUseEncryption->setChecked(true);
826
_mainWid->cboSecurity->setCurrentItem(SECURITY_WEP);
827
slotComboSecurityActivated(_securityComboMap[SECURITY_WEP]);
830
_mainWid->groupUseEncryption->setChecked(false);
832
case WirelessSecurity::KEY_MGMT_WPA_PSK:
833
_mainWid->groupUseEncryption->setChecked(true);
834
_mainWid->cboSecurity->setCurrentItem(SECURITY_WPA_PSK);
835
slotComboSecurityActivated(_securityComboMap[SECURITY_WPA_PSK]);
837
case WirelessSecurity::KEY_MGMT_WPA_EAP:
838
_mainWid->groupUseEncryption->setChecked(true);
839
_mainWid->cboSecurity->setCurrentItem(SECURITY_WPA_EAP);
840
slotComboSecurityActivated(_securityComboMap[SECURITY_WPA_EAP]);
842
case WirelessSecurity::KEY_MGMT_IEEE8021X:
843
_mainWid->groupUseEncryption->setChecked(true);
844
_mainWid->cboSecurity->setCurrentItem(SECURITY_IEEE8021X);
845
slotComboSecurityActivated(_securityComboMap[SECURITY_IEEE8021X]);
854
// select first possible security method
855
if (_mainWid->cboSecurity->count() > 0)
857
_mainWid->groupUseEncryption->setChecked(true);
858
_mainWid->groupUseEncryption->setEnabled(true);
859
_mainWid->cboSecurity->setCurrentItem(0);
860
slotComboSecurityActivated(0);
864
_mainWid->groupUseEncryption->setChecked(false);
865
_mainWid->groupUseEncryption->setEnabled(false);
871
WirelessSecurityWidgetImpl::slotUseEncryptionToggled(bool on)
873
_wireless_setting->setSecurity(on ? _security_setting->getType() : NULL);
877
WirelessSecurityWidgetImpl::slotComboSecurityActivated(int index)
879
int i = _securityComboMap[index];
881
// authentication switched, we have to show the appropriate widgets and hide some others
888
case SECURITY_WPA_PSK:
889
configureForWPAPSK();
892
case SECURITY_WPA_EAP:
893
configureForWPAEAP();
896
case SECURITY_IEEE8021X:
897
configureForIEEE8021X();
901
// should not happen, something is broken...
907
WirelessSecurityWidgetImpl::configureWidgets(SecurityMethods method)
909
// store selected method
910
_currentMethod = method;
912
for (int i = 0; i < SECURITY_COUNT; ++i)
914
// remove all current widgets that do not belong to the selected method
917
for (QValueList<QWidget*>::iterator it = _widgets[i].begin(); it != _widgets[i].end(); ++it)
919
_mainWid->groupUseEncryption->layout()->remove(*it);
922
// remove extra widgets too
923
for (QValueList<QWidget*>::iterator it = _extra_widgets[i].begin(); it != _extra_widgets[i].end(); ++it)
925
_mainWid->groupUseEncryption->layout()->remove(*it);
931
// show all widgets widgets for the selected security method
932
for (QValueList<QWidget*>::iterator it = _widgets[method].begin(); it != _widgets[method].end(); ++it)
934
_mainWid->groupUseEncryption->layout()->add(*it);
938
if (_mainWid->pbExtra->isOn())
939
for (QValueList<QWidget*>::iterator it = _extra_widgets[method].begin(); it != _extra_widgets[method].end(); ++it)
941
_mainWid->groupUseEncryption->layout()->add(*it);
945
// deactivate button if no extra settings are available
946
_mainWid->pbExtra->setEnabled(!(_extra_widgets[method].begin() == _extra_widgets[method].end()));
950
WirelessSecurityWidgetImpl::slotExtraSettingsToggled(bool on)
953
for (QValueList<QWidget*>::iterator it = _extra_widgets[_currentMethod].begin(); it != _extra_widgets[_currentMethod].end(); ++it)
955
_mainWid->groupUseEncryption->layout()->add(*it);
959
for (QValueList<QWidget*>::iterator it = _extra_widgets[_currentMethod].begin(); it != _extra_widgets[_currentMethod].end(); ++it)
961
_mainWid->groupUseEncryption->layout()->remove(*it);
967
WirelessSecurityWidgetImpl::configureForWEP()
969
_security_setting->setKeyMgmt(WirelessSecurity::KEY_MGMT_NONE);
970
configureWidgets(SECURITY_WEP);
974
WirelessSecurityWidgetImpl::configureForWPAPSK()
976
_security_setting->setKeyMgmt(WirelessSecurity::KEY_MGMT_WPA_PSK);
977
configureWidgets(SECURITY_WPA_PSK);
981
WirelessSecurityWidgetImpl::configureForWPAEAP()
983
_security_setting->setKeyMgmt(WirelessSecurity::KEY_MGMT_WPA_EAP);
984
configureWidgets(SECURITY_WPA_EAP);
988
WirelessSecurityWidgetImpl::configureForIEEE8021X()
990
_security_setting->setKeyMgmt(WirelessSecurity::KEY_MGMT_IEEE8021X);
991
configureWidgets(SECURITY_IEEE8021X);
997
#include "knetworkmanager-connection_setting_wireless_security_widget.moc"