File indexing completed on 2024-12-01 08:10:04

0001 /*
0002     SPDX-FileCopyrightText: 2013 Lukas Tinkl <ltinkl@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "wifisecurity.h"
0008 #include "ui_wifisecurity.h"
0009 
0010 #include <NetworkManagerQt/Device>
0011 #include <NetworkManagerQt/Manager>
0012 #include <NetworkManagerQt/Utils>
0013 #include <NetworkManagerQt/WirelessDevice>
0014 
0015 WifiSecurity::WifiSecurity(const NetworkManager::Setting::Ptr &setting,
0016                            const NetworkManager::Security8021xSetting::Ptr &setting8021x,
0017                            QWidget *parent,
0018                            Qt::WindowFlags f)
0019     : SettingWidget(setting, parent, f)
0020     , m_ui(new Ui::WifiSecurity)
0021     , m_wifiSecurity(setting.staticCast<NetworkManager::WirelessSecuritySetting>())
0022 {
0023     m_ui->setupUi(this);
0024 
0025     m_ui->leapPassword->setPasswordOptionsEnabled(true);
0026     m_ui->psk->setPasswordOptionsEnabled(true);
0027     m_ui->wepKey->setPasswordOptionsEnabled(true);
0028 
0029     m_8021xWidget = new Security8021x(setting8021x, Security8021x::WirelessWpaEap, this); // Dynamic WEP
0030     m_WPA2Widget = new Security8021x(setting8021x, Security8021x::WirelessWpaEap, this); // WPA(2) Enterprise
0031     m_WPA3SuiteB192Widget = new Security8021x(setting8021x, Security8021x::WirelessWpaEapSuiteB192, this); // WPA3 Enterprise Suite B 192
0032     m_ui->stackedWidget->insertWidget(3, m_8021xWidget);
0033     m_ui->stackedWidget->insertWidget(5, m_WPA2Widget);
0034     m_ui->stackedWidget->insertWidget(6, m_WPA3SuiteB192Widget);
0035 
0036     // WPA3 Enterprise is available in NM 1.30+
0037     if (!NetworkManager::checkVersion(1, 30, 0)) {
0038         m_ui->securityCombo->removeItem(8);
0039     }
0040 
0041     // WPA3 Personal is available in NM 1.16+
0042     if (!NetworkManager::checkVersion(1, 16, 0)) {
0043         m_ui->securityCombo->removeItem(7);
0044     }
0045 
0046     connect(m_ui->securityCombo, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::securityChanged);
0047     connect(m_ui->wepIndex, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::setWepKey);
0048 
0049     // Connect for setting check
0050     watchChangedSetting();
0051 
0052     // Connect for validity check
0053     connect(m_ui->wepKey, &PasswordField::textChanged, this, &WifiSecurity::slotWidgetChanged);
0054     connect(m_ui->wepKey, &PasswordField::passwordOptionChanged, this, &WifiSecurity::slotWidgetChanged);
0055     connect(m_ui->leapUsername, &KLineEdit::textChanged, this, &WifiSecurity::slotWidgetChanged);
0056     connect(m_ui->leapPassword, &PasswordField::textChanged, this, &WifiSecurity::slotWidgetChanged);
0057     connect(m_ui->leapPassword, &PasswordField::passwordOptionChanged, this, &WifiSecurity::slotWidgetChanged);
0058     connect(m_ui->psk, &PasswordField::textChanged, this, &WifiSecurity::slotWidgetChanged);
0059     connect(m_ui->psk, &PasswordField::passwordOptionChanged, this, &WifiSecurity::slotWidgetChanged);
0060     connect(m_ui->wepIndex, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::slotWidgetChanged);
0061     connect(m_ui->securityCombo, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::slotWidgetChanged);
0062     connect(m_8021xWidget, &Security8021x::validChanged, this, &WifiSecurity::slotWidgetChanged);
0063     connect(m_WPA2Widget, &Security8021x::validChanged, this, &WifiSecurity::slotWidgetChanged);
0064     connect(m_WPA3SuiteB192Widget, &Security8021x::validChanged, this, &WifiSecurity::slotWidgetChanged);
0065 
0066     KAcceleratorManager::manage(this);
0067 
0068     if (setting && !setting->isNull()) {
0069         loadConfig(setting);
0070     }
0071 }
0072 
0073 WifiSecurity::~WifiSecurity()
0074 {
0075     delete m_ui;
0076 }
0077 
0078 bool WifiSecurity::enabled() const
0079 {
0080     return m_ui->securityCombo->currentIndex() > 0;
0081 }
0082 
0083 bool WifiSecurity::enabled8021x() const
0084 {
0085     if (m_ui->securityCombo->currentIndex() == 4 || m_ui->securityCombo->currentIndex() == 6 || m_ui->securityCombo->currentIndex() == 8) {
0086         return true;
0087     }
0088 
0089     return false;
0090 }
0091 
0092 bool WifiSecurity::isValid() const
0093 {
0094     const int securityIndex = m_ui->securityCombo->currentIndex();
0095 
0096     if (securityIndex == WepHex) { // WEP Hex
0097         return NetworkManager::wepKeyIsValid(m_ui->wepKey->text(), NetworkManager::WirelessSecuritySetting::Hex)
0098             || m_ui->wepKey->passwordOption() == PasswordField::AlwaysAsk;
0099     } else if (securityIndex == WepPassphrase) { // WEP Passphrase
0100         return NetworkManager::wepKeyIsValid(m_ui->wepKey->text(), NetworkManager::WirelessSecuritySetting::Passphrase)
0101             || m_ui->wepKey->passwordOption() == PasswordField::AlwaysAsk;
0102         ;
0103     } else if (securityIndex == Leap) { // LEAP
0104         return !m_ui->leapUsername->text().isEmpty()
0105             && (!m_ui->leapPassword->text().isEmpty() || m_ui->leapPassword->passwordOption() == PasswordField::AlwaysAsk);
0106     } else if (securityIndex == WpaPsk) { // WPA
0107         return NetworkManager::wpaPskIsValid(m_ui->psk->text()) || m_ui->psk->passwordOption() == PasswordField::AlwaysAsk;
0108     } else if (securityIndex == DynamicWep) {
0109         return m_8021xWidget->isValid();
0110     } else if (securityIndex == WpaEap) {
0111         return m_WPA2Widget->isValid();
0112     } else if (securityIndex == Wpa3SuiteB192) {
0113         return m_WPA3SuiteB192Widget->isValid();
0114     } else if (securityIndex == SAE) {
0115         return !m_ui->psk->text().isEmpty() || m_ui->psk->passwordOption() == PasswordField::AlwaysAsk;
0116     }
0117 
0118     return true;
0119 }
0120 
0121 void WifiSecurity::setStoreSecretsSystemWide(bool system)
0122 {
0123     if (system) {
0124         m_ui->wepKey->setPasswordOption(PasswordField::StoreForAllUsers);
0125         m_ui->leapPassword->setPasswordOption(PasswordField::StoreForAllUsers);
0126         m_ui->psk->setPasswordOption(PasswordField::StoreForAllUsers);
0127         m_8021xWidget->setPasswordOption(PasswordField::StoreForAllUsers);
0128         m_WPA2Widget->setPasswordOption(PasswordField::StoreForAllUsers);
0129     } else {
0130         m_ui->wepKey->setPasswordOption(PasswordField::StoreForUser);
0131         m_ui->leapPassword->setPasswordOption(PasswordField::StoreForUser);
0132         m_ui->psk->setPasswordOption(PasswordField::StoreForUser);
0133         m_8021xWidget->setPasswordOption(PasswordField::StoreForUser);
0134         m_WPA2Widget->setPasswordOption(PasswordField::StoreForUser);
0135     }
0136 }
0137 
0138 void WifiSecurity::loadConfig(const NetworkManager::Setting::Ptr &setting)
0139 {
0140     NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = setting.staticCast<NetworkManager::WirelessSecuritySetting>();
0141 
0142     const NetworkManager::WirelessSecuritySetting::KeyMgmt keyMgmt = wifiSecurity->keyMgmt();
0143     const NetworkManager::WirelessSecuritySetting::AuthAlg authAlg = wifiSecurity->authAlg();
0144 
0145     if (keyMgmt == NetworkManager::WirelessSecuritySetting::Unknown) {
0146         m_ui->securityCombo->setCurrentIndex(None); // None
0147     } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Wep) {
0148         if (wifiSecurity->wepKeyType() == NetworkManager::WirelessSecuritySetting::Hex
0149             || wifiSecurity->wepKeyType() == NetworkManager::WirelessSecuritySetting::NotSpecified) {
0150             m_ui->securityCombo->setCurrentIndex(WepHex); // WEP Hex
0151         } else {
0152             m_ui->securityCombo->setCurrentIndex(WepPassphrase);
0153         }
0154         const int keyIndex = static_cast<int>(wifiSecurity->wepTxKeyindex());
0155         m_ui->wepIndex->setCurrentIndex(keyIndex);
0156 
0157         if (wifiSecurity->authAlg() == NetworkManager::WirelessSecuritySetting::Open) {
0158             m_ui->wepAuth->setCurrentIndex(0);
0159         } else {
0160             m_ui->wepAuth->setCurrentIndex(1);
0161         }
0162 
0163         if (wifiSecurity->wepKeyFlags().testFlag(NetworkManager::Setting::None)) {
0164             m_ui->wepKey->setPasswordOption(PasswordField::StoreForAllUsers);
0165         } else if (wifiSecurity->wepKeyFlags().testFlag(NetworkManager::Setting::AgentOwned)) {
0166             m_ui->wepKey->setPasswordOption(PasswordField::StoreForUser);
0167         } else {
0168             m_ui->wepKey->setPasswordOption(PasswordField::AlwaysAsk);
0169         }
0170     } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x && authAlg == NetworkManager::WirelessSecuritySetting::Leap) {
0171         m_ui->securityCombo->setCurrentIndex(Leap); // LEAP
0172         m_ui->leapUsername->setText(wifiSecurity->leapUsername());
0173         m_ui->leapPassword->setText(wifiSecurity->leapPassword());
0174 
0175         if (wifiSecurity->leapPasswordFlags().testFlag(NetworkManager::Setting::None)) {
0176             m_ui->leapPassword->setPasswordOption(PasswordField::StoreForAllUsers);
0177         } else if (wifiSecurity->leapPasswordFlags().testFlag(NetworkManager::Setting::AgentOwned)) {
0178             m_ui->leapPassword->setPasswordOption(PasswordField::StoreForUser);
0179         } else {
0180             m_ui->leapPassword->setPasswordOption(PasswordField::AlwaysAsk);
0181         }
0182     } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x) {
0183         m_ui->securityCombo->setCurrentIndex(DynamicWep); // Dynamic WEP
0184         // done in the widget
0185 
0186     } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaPsk) {
0187         m_ui->securityCombo->setCurrentIndex(WpaPsk); // WPA
0188 
0189         if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::None)) {
0190             m_ui->psk->setPasswordOption(PasswordField::StoreForAllUsers);
0191         } else if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::AgentOwned)) {
0192             m_ui->psk->setPasswordOption(PasswordField::StoreForUser);
0193         } else {
0194             m_ui->psk->setPasswordOption(PasswordField::AlwaysAsk);
0195         }
0196     } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEap) {
0197         m_ui->securityCombo->setCurrentIndex(WpaEap); // WPA2 Enterprise
0198         // done in the widget
0199     } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::SAE) {
0200         m_ui->securityCombo->setCurrentIndex(SAE); // WPA3
0201 
0202         if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::None)) {
0203             m_ui->psk->setPasswordOption(PasswordField::StoreForAllUsers);
0204         } else if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::AgentOwned)) {
0205             m_ui->psk->setPasswordOption(PasswordField::StoreForUser);
0206         } else {
0207             m_ui->psk->setPasswordOption(PasswordField::AlwaysAsk);
0208         }
0209     } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEapSuiteB192) {
0210         m_ui->securityCombo->setCurrentIndex(Wpa3SuiteB192); // WPA3 Enterprise Suite B 192
0211         // done in the widget
0212     }
0213 
0214     if (keyMgmt != NetworkManager::WirelessSecuritySetting::Ieee8021x && keyMgmt != NetworkManager::WirelessSecuritySetting::WpaEap
0215         && keyMgmt != NetworkManager::WirelessSecuritySetting::WpaEapSuiteB192) {
0216         loadSecrets(setting);
0217     }
0218 }
0219 
0220 void WifiSecurity::loadSecrets(const NetworkManager::Setting::Ptr &setting)
0221 {
0222     const NetworkManager::WirelessSecuritySetting::KeyMgmt keyMgmt = m_wifiSecurity->keyMgmt();
0223     const NetworkManager::WirelessSecuritySetting::AuthAlg authAlg = m_wifiSecurity->authAlg();
0224 
0225     if ((keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x && authAlg != NetworkManager::WirelessSecuritySetting::Leap)
0226         || keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEap || keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEapSuiteB192) {
0227         NetworkManager::Security8021xSetting::Ptr security8021xSetting = setting.staticCast<NetworkManager::Security8021xSetting>();
0228         if (security8021xSetting) {
0229             if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x) {
0230                 m_8021xWidget->loadSecrets(security8021xSetting);
0231             } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEap) {
0232                 m_WPA2Widget->loadSecrets(security8021xSetting);
0233             } else {
0234                 m_WPA3SuiteB192Widget->loadSecrets(security8021xSetting);
0235             }
0236         }
0237     } else {
0238         NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = setting.staticCast<NetworkManager::WirelessSecuritySetting>();
0239         if (wifiSecurity) {
0240             if (keyMgmt == NetworkManager::WirelessSecuritySetting::Wep) {
0241                 m_wifiSecurity->secretsFromMap(wifiSecurity->secretsToMap());
0242                 const int keyIndex = static_cast<int>(m_wifiSecurity->wepTxKeyindex());
0243                 setWepKey(keyIndex);
0244             } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x && authAlg == NetworkManager::WirelessSecuritySetting::Leap) {
0245                 const QString leapPassword = wifiSecurity->leapPassword();
0246                 if (!leapPassword.isEmpty()) {
0247                     m_ui->leapPassword->setText(leapPassword);
0248                 }
0249             } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaPsk || keyMgmt == NetworkManager::WirelessSecuritySetting::SAE) {
0250                 const QString psk = wifiSecurity->psk();
0251                 if (!psk.isEmpty()) {
0252                     m_ui->psk->setText(psk);
0253                 }
0254             }
0255         }
0256     }
0257 }
0258 
0259 QVariantMap WifiSecurity::setting() const
0260 {
0261     NetworkManager::WirelessSecuritySetting wifiSecurity;
0262 
0263     const int securityIndex = m_ui->securityCombo->currentIndex();
0264     if (securityIndex == None) {
0265         wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::Unknown);
0266     } else if (securityIndex == WepHex || securityIndex == WepPassphrase) { // WEP
0267         wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::Wep);
0268         if (securityIndex == WepHex) {
0269             wifiSecurity.setWepKeyType(NetworkManager::WirelessSecuritySetting::Hex);
0270         } else {
0271             wifiSecurity.setWepKeyType(NetworkManager::WirelessSecuritySetting::Passphrase);
0272         }
0273         const int keyIndex = m_ui->wepIndex->currentIndex();
0274         const QString wepKey = m_ui->wepKey->text();
0275         wifiSecurity.setWepTxKeyindex(keyIndex);
0276         if (keyIndex == 0) {
0277             wifiSecurity.setWepKey0(wepKey);
0278         } else if (keyIndex == 1) {
0279             wifiSecurity.setWepKey1(wepKey);
0280         } else if (keyIndex == 2) {
0281             wifiSecurity.setWepKey2(wepKey);
0282         } else if (keyIndex == 3) {
0283             wifiSecurity.setWepKey3(wepKey);
0284         }
0285 
0286         if (m_ui->wepKey->passwordOption() == PasswordField::StoreForAllUsers) {
0287             wifiSecurity.setWepKeyFlags(NetworkManager::Setting::None);
0288         } else if (m_ui->wepKey->passwordOption() == PasswordField::StoreForUser) {
0289             wifiSecurity.setWepKeyFlags(NetworkManager::Setting::AgentOwned);
0290         } else {
0291             wifiSecurity.setWepKeyFlags(NetworkManager::Setting::NotSaved);
0292         }
0293 
0294         if (m_ui->wepAuth->currentIndex() == 0) {
0295             wifiSecurity.setAuthAlg(NetworkManager::WirelessSecuritySetting::Open);
0296         } else {
0297             wifiSecurity.setAuthAlg(NetworkManager::WirelessSecuritySetting::Shared);
0298         }
0299     } else if (securityIndex == Leap) { // LEAP
0300         wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::Ieee8021x);
0301         wifiSecurity.setAuthAlg(NetworkManager::WirelessSecuritySetting::Leap);
0302         wifiSecurity.setLeapUsername(m_ui->leapUsername->text());
0303         wifiSecurity.setLeapPassword(m_ui->leapPassword->text());
0304 
0305         if (m_ui->leapPassword->passwordOption() == PasswordField::StoreForAllUsers) {
0306             wifiSecurity.setLeapPasswordFlags(NetworkManager::Setting::None);
0307         } else if (m_ui->leapPassword->passwordOption() == PasswordField::StoreForUser) {
0308             wifiSecurity.setLeapPasswordFlags(NetworkManager::Setting::AgentOwned);
0309         } else {
0310             wifiSecurity.setLeapPasswordFlags(NetworkManager::Setting::NotSaved);
0311         }
0312     } else if (securityIndex == DynamicWep) { // Dynamic WEP
0313         wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::Ieee8021x);
0314     } else if (securityIndex == WpaPsk) { // WPA
0315         wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk);
0316         wifiSecurity.setPsk(m_ui->psk->text());
0317 
0318         if (m_ui->psk->passwordOption() == PasswordField::StoreForAllUsers) {
0319             wifiSecurity.setPskFlags(NetworkManager::Setting::None);
0320         } else if (m_ui->psk->passwordOption() == PasswordField::StoreForUser) {
0321             wifiSecurity.setPskFlags(NetworkManager::Setting::AgentOwned);
0322         } else {
0323             wifiSecurity.setPskFlags(NetworkManager::Setting::NotSaved);
0324         }
0325     } else if (securityIndex == WpaEap) { // WPA2 Enterprise
0326         wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap);
0327     } else if (securityIndex == SAE) { // WPA3 Personal
0328         wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::SAE);
0329         wifiSecurity.setPsk(m_ui->psk->text());
0330 
0331         if (m_ui->psk->passwordOption() == PasswordField::StoreForAllUsers) {
0332             wifiSecurity.setPskFlags(NetworkManager::Setting::None);
0333         } else if (m_ui->psk->passwordOption() == PasswordField::StoreForUser) {
0334             wifiSecurity.setPskFlags(NetworkManager::Setting::AgentOwned);
0335         } else {
0336             wifiSecurity.setPskFlags(NetworkManager::Setting::NotSaved);
0337         }
0338     } else if (securityIndex == Wpa3SuiteB192) { // WPA3 Enterprise Suite B 192
0339         wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEapSuiteB192);
0340         wifiSecurity.setPmf(NetworkManager::WirelessSecuritySetting::RequiredPmf);
0341     }
0342 
0343     return wifiSecurity.toMap();
0344 }
0345 
0346 QVariantMap WifiSecurity::setting8021x() const
0347 {
0348     if (m_ui->securityCombo->currentIndex() == DynamicWep) { // Dynamic WEP
0349         return m_8021xWidget->setting();
0350     } else if (m_ui->securityCombo->currentIndex() == WpaEap) { // WPA2 Enterprise
0351         return m_WPA2Widget->setting();
0352     } else if (m_ui->securityCombo->currentIndex() == Wpa3SuiteB192) { // WPA3 Enterprise Suite B 192
0353         return m_WPA3SuiteB192Widget->setting();
0354     }
0355 
0356     return {};
0357 }
0358 
0359 void WifiSecurity::onSsidChanged(const QString &ssid)
0360 {
0361     for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) {
0362         if (device->type() == NetworkManager::Device::Wifi) {
0363             NetworkManager::WirelessDevice::Ptr wifiDevice = device.staticCast<NetworkManager::WirelessDevice>();
0364             if (wifiDevice) {
0365                 for (const NetworkManager::WirelessNetwork::Ptr &wifiNetwork : wifiDevice->networks()) {
0366                     if (wifiNetwork && wifiNetwork->ssid() == ssid) {
0367                         NetworkManager::AccessPoint::Ptr ap = wifiNetwork->referenceAccessPoint();
0368                         NetworkManager::WirelessSecurityType securityType =
0369                             NetworkManager::findBestWirelessSecurity(wifiDevice->wirelessCapabilities(),
0370                                                                      true,
0371                                                                      (wifiDevice->mode() == NetworkManager::WirelessDevice::Adhoc),
0372                                                                      ap->capabilities(),
0373                                                                      ap->wpaFlags(),
0374                                                                      ap->rsnFlags());
0375                         switch (securityType) {
0376                         case NetworkManager::WirelessSecurityType::StaticWep:
0377                             m_ui->securityCombo->setCurrentIndex(WepHex);
0378                             break;
0379                         case NetworkManager::WirelessSecurityType::DynamicWep:
0380                             m_ui->securityCombo->setCurrentIndex(DynamicWep);
0381                             break;
0382                         case NetworkManager::WirelessSecurityType::Leap:
0383                             m_ui->securityCombo->setCurrentIndex(Leap);
0384                             break;
0385                         case NetworkManager::WirelessSecurityType::WpaPsk:
0386                             m_ui->securityCombo->setCurrentIndex(WpaPsk);
0387                             break;
0388                         case NetworkManager::WirelessSecurityType::Wpa2Psk:
0389                             m_ui->securityCombo->setCurrentIndex(WpaPsk);
0390                             break;
0391                         case NetworkManager::WirelessSecurityType::WpaEap:
0392                             m_ui->securityCombo->setCurrentIndex(WpaEap);
0393                             break;
0394                         case NetworkManager::WirelessSecurityType::Wpa2Eap:
0395                             m_ui->securityCombo->setCurrentIndex(WpaEap);
0396                             break;
0397                         case NetworkManager::WirelessSecurityType::SAE:
0398                             m_ui->securityCombo->setCurrentIndex(SAE);
0399                             break;
0400                         case NetworkManager::WirelessSecurityType::Wpa3SuiteB192:
0401                             m_ui->securityCombo->setCurrentIndex(Wpa3SuiteB192);
0402                             break;
0403                         default:
0404                             m_ui->securityCombo->setCurrentIndex(None);
0405                         }
0406 
0407                         return;
0408                     }
0409                 }
0410             }
0411         }
0412     }
0413 
0414     // Reset to none security if we don't find any AP or Wifi device
0415     m_ui->securityCombo->setCurrentIndex(None);
0416 }
0417 
0418 void WifiSecurity::setWepKey(int keyIndex)
0419 {
0420     if (keyIndex == 0) {
0421         m_ui->wepKey->setText(m_wifiSecurity->wepKey0());
0422     } else if (keyIndex == 1) {
0423         m_ui->wepKey->setText(m_wifiSecurity->wepKey1());
0424     } else if (keyIndex == 2) {
0425         m_ui->wepKey->setText(m_wifiSecurity->wepKey2());
0426     } else if (keyIndex == 3) {
0427         m_ui->wepKey->setText(m_wifiSecurity->wepKey3());
0428     }
0429 }
0430 
0431 void WifiSecurity::securityChanged(int index)
0432 {
0433     if (index == None) {
0434         m_ui->stackedWidget->setCurrentIndex(0);
0435     } else if (index == WepHex || index == WepPassphrase) {
0436         m_ui->stackedWidget->setCurrentIndex(1);
0437     } else if (index == Leap) {
0438         m_ui->stackedWidget->setCurrentIndex(2);
0439     } else if (index == DynamicWep) {
0440         m_ui->stackedWidget->setCurrentIndex(3);
0441     } else if (index == WpaPsk || index == SAE) {
0442         m_ui->stackedWidget->setCurrentIndex(4);
0443     } else if (index == WpaEap) {
0444         m_ui->stackedWidget->setCurrentIndex(5);
0445     } else if (index == Wpa3SuiteB192) {
0446         m_ui->stackedWidget->setCurrentIndex(6);
0447     }
0448 
0449     KAcceleratorManager::manage(m_ui->stackedWidget->currentWidget());
0450 }
0451 
0452 #include "moc_wifisecurity.cpp"