7#include "wirelesssecuritysetting.h"
8#include "wirelesssecuritysetting_p.h"
12#if !NM_CHECK_VERSION(1, 10, 0)
13#define NM_SETTING_WIRELESS_SECURITY_PMF "pmf"
16NetworkManager::WirelessSecuritySettingPrivate::WirelessSecuritySettingPrivate()
17 : name(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)
22 , wepKeyType(
NetworkManager::WirelessSecuritySetting::NotSpecified)
29NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting()
30 : Setting(Setting::WirelessSecurity)
31 , d_ptr(new WirelessSecuritySettingPrivate())
35NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting(
const Ptr &other)
37 , d_ptr(new WirelessSecuritySettingPrivate())
39 setKeyMgmt(other->keyMgmt());
40 setWepTxKeyindex(other->wepTxKeyindex());
41 setAuthAlg(other->authAlg());
42 setProto(other->proto());
43 setPairwise(other->pairwise());
44 setGroup(other->group());
45 setWepKey0(other->wepKey0());
46 setWepKey1(other->wepKey1());
47 setWepKey2(other->wepKey2());
48 setWepKey3(other->wepKey3());
49 setWepKeyFlags(other->wepKeyFlags());
50 setWepKeyType(other->wepKeyType());
52 setPskFlags(other->pskFlags());
53 setLeapPassword(other->leapPassword());
54 setLeapPasswordFlags(other->leapPasswordFlags());
58NetworkManager::WirelessSecuritySetting::~WirelessSecuritySetting()
70void NetworkManager::WirelessSecuritySetting::setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt mgmt)
77NetworkManager::WirelessSecuritySetting::KeyMgmt NetworkManager::WirelessSecuritySetting::keyMgmt()
const
79 Q_D(
const WirelessSecuritySetting);
84void NetworkManager::WirelessSecuritySetting::setWepTxKeyindex(quint32 index)
86 Q_D(WirelessSecuritySetting);
88 d->wepTxKeyidx = index;
91quint32 NetworkManager::WirelessSecuritySetting::wepTxKeyindex()
const
93 Q_D(
const WirelessSecuritySetting);
95 return d->wepTxKeyidx;
98void NetworkManager::WirelessSecuritySetting::setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg alg)
100 Q_D(WirelessSecuritySetting);
105NetworkManager::WirelessSecuritySetting::AuthAlg NetworkManager::WirelessSecuritySetting::authAlg()
const
107 Q_D(
const WirelessSecuritySetting);
114 Q_D(WirelessSecuritySetting);
121 Q_D(
const WirelessSecuritySetting);
128 Q_D(WirelessSecuritySetting);
135 Q_D(
const WirelessSecuritySetting);
142 Q_D(WirelessSecuritySetting);
149 Q_D(
const WirelessSecuritySetting);
154void NetworkManager::WirelessSecuritySetting::setLeapUsername(
const QString &username)
156 Q_D(WirelessSecuritySetting);
158 d->leapUsername = username;
161QString NetworkManager::WirelessSecuritySetting::leapUsername()
const
163 Q_D(
const WirelessSecuritySetting);
165 return d->leapUsername;
168void NetworkManager::WirelessSecuritySetting::setWepKey0(
const QString key)
170 Q_D(WirelessSecuritySetting);
175QString NetworkManager::WirelessSecuritySetting::wepKey0()
const
177 Q_D(
const WirelessSecuritySetting);
182void NetworkManager::WirelessSecuritySetting::setWepKey1(
const QString key)
184 Q_D(WirelessSecuritySetting);
189QString NetworkManager::WirelessSecuritySetting::wepKey1()
const
191 Q_D(
const WirelessSecuritySetting);
196void NetworkManager::WirelessSecuritySetting::setWepKey2(
const QString key)
198 Q_D(WirelessSecuritySetting);
203QString NetworkManager::WirelessSecuritySetting::wepKey2()
const
205 Q_D(
const WirelessSecuritySetting);
210void NetworkManager::WirelessSecuritySetting::setWepKey3(
const QString key)
212 Q_D(WirelessSecuritySetting);
217QString NetworkManager::WirelessSecuritySetting::wepKey3()
const
219 Q_D(
const WirelessSecuritySetting);
226 Q_D(WirelessSecuritySetting);
228 d->wepKeyFlags =
type;
233 Q_D(
const WirelessSecuritySetting);
235 return d->wepKeyFlags;
238void NetworkManager::WirelessSecuritySetting::setWepKeyType(NetworkManager::WirelessSecuritySetting::WepKeyType type)
240 Q_D(WirelessSecuritySetting);
242 d->wepKeyType =
type;
245NetworkManager::WirelessSecuritySetting::WepKeyType NetworkManager::WirelessSecuritySetting::wepKeyType()
const
247 Q_D(
const WirelessSecuritySetting);
249 return d->wepKeyType;
252void NetworkManager::WirelessSecuritySetting::setPsk(
const QString &key)
254 Q_D(WirelessSecuritySetting);
259QString NetworkManager::WirelessSecuritySetting::psk()
const
261 Q_D(
const WirelessSecuritySetting);
268 Q_D(WirelessSecuritySetting);
275 Q_D(
const WirelessSecuritySetting);
280void NetworkManager::WirelessSecuritySetting::setLeapPassword(
const QString &password)
282 Q_D(WirelessSecuritySetting);
284 d->leapPassword = password;
287QString NetworkManager::WirelessSecuritySetting::leapPassword()
const
289 Q_D(
const WirelessSecuritySetting);
291 return d->leapPassword;
296 Q_D(WirelessSecuritySetting);
298 d->leapPasswordFlags =
type;
303 Q_D(
const WirelessSecuritySetting);
305 return d->leapPasswordFlags;
308void NetworkManager::WirelessSecuritySetting::setPmf(NetworkManager::WirelessSecuritySetting::Pmf pmf)
310 Q_D(WirelessSecuritySetting);
315NetworkManager::WirelessSecuritySetting::Pmf NetworkManager::WirelessSecuritySetting::pmf()
const
317 Q_D(
const WirelessSecuritySetting);
322void NetworkManager::WirelessSecuritySetting::secretsFromMap(
const QVariantMap &secrets)
324 if (secrets.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) {
328 if (secrets.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) {
332 if (secrets.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) {
336 if (secrets.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) {
340 if (secrets.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) {
344 if (secrets.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) {
345 setLeapPassword(secrets.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).
toString());
349QVariantMap NetworkManager::WirelessSecuritySetting::secretsToMap()
const
353 if (!wepKey0().isEmpty()) {
354 secrets.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), wepKey0());
357 if (!wepKey1().isEmpty()) {
358 secrets.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), wepKey1());
361 if (!wepKey2().isEmpty()) {
362 secrets.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), wepKey2());
365 if (!wepKey3().isEmpty()) {
366 secrets.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), wepKey3());
369 if (!psk().isEmpty()) {
370 secrets.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), psk());
373 if (!leapPassword().isEmpty()) {
374 secrets.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), leapPassword());
380QStringList NetworkManager::WirelessSecuritySetting::needSecrets(
bool requestNew)
const
384 if (keyMgmt() == Wep) {
385 if (!wepKeyFlags().testFlag(Setting::NotRequired)) {
386 switch (wepTxKeyindex()) {
388 if (wepKey0().isEmpty() || requestNew) {
389 secrets <<
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
394 if (wepKey1().isEmpty() || requestNew) {
395 secrets <<
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
400 if (wepKey2().isEmpty() || requestNew) {
401 secrets <<
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
406 if (wepKey3().isEmpty() || requestNew) {
407 secrets <<
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3);
415 if (keyMgmt() == WpaNone || keyMgmt() == WpaPsk || keyMgmt() == SAE) {
416 if (!pskFlags().testFlag(Setting::NotRequired)) {
417 if (psk().isEmpty() || requestNew) {
424 if (authAlg() == Leap && keyMgmt() == Ieee8021x) {
425 if (!leapPasswordFlags().testFlag(Setting::NotRequired)) {
426 if (leapPassword().isEmpty() || requestNew) {
427 secrets <<
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD);
438 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT))) {
442 }
else if (key ==
"ieee8021x") {
443 setKeyMgmt(Ieee8021x);
444 }
else if (key ==
"wpa-none") {
446 }
else if (key ==
"wpa-psk") {
448 }
else if (key ==
"wpa-eap") {
450 }
else if (key ==
"sae") {
452 }
else if (key ==
"wpa-eap-suite-b-192") {
453 setKeyMgmt(WpaEapSuiteB192);
454 }
else if (key ==
"owe") {
459 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX))) {
460 setWepTxKeyindex(map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX)).toUInt());
463 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG))) {
467 }
else if (alg ==
"shared") {
469 }
else if (alg ==
"leap") {
474 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO))) {
477 for (
const QString &str : strList) {
480 }
else if (str ==
"rsn") {
487 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE))) {
490 for (
const QString &str : strList) {
491 if (str ==
"wep40") {
493 }
else if (str ==
"wep104") {
495 }
else if (str ==
"tkip") {
497 }
else if (str ==
"ccmp") {
504 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP))) {
507 for (
const QString &str : strList) {
508 if (str ==
"wep40") {
510 }
else if (str ==
"wep104") {
512 }
else if (str ==
"tkip") {
514 }
else if (str ==
"ccmp") {
521 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME))) {
522 setLeapUsername(map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME)).toString());
526 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) {
527 setWepKey0(map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).toString());
531 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) {
532 setWepKey1(map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).toString());
536 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) {
537 setWepKey2(map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).toString());
541 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) {
542 setWepKey3(map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).toString());
545 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS))) {
549 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE))) {
550 setWepKeyType((WepKeyType)map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE)).toUInt());
554 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) {
555 setPsk(map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).toString());
558 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS))) {
563 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) {
564 setLeapPassword(map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).toString());
567 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS))) {
568 setLeapPasswordFlags((
SecretFlags)map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS)).toInt());
571 if (map.contains(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF))) {
572 setPmf((Pmf)map.value(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF)).toInt());
580 if (keyMgmt() == Wep) {
581 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"none");
582 }
else if (keyMgmt() == Ieee8021x) {
583 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"ieee8021x");
584 }
else if (keyMgmt() == WpaNone) {
585 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"wpa-none");
586 }
else if (keyMgmt() == WpaPsk) {
587 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"wpa-psk");
588 }
else if (keyMgmt() == WpaEap) {
589 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"wpa-eap");
590 }
else if (keyMgmt() == SAE) {
591 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"sae");
592 }
else if (keyMgmt() == WpaEapSuiteB192) {
593 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"wpa-eap-suite-b-192");
594 }
else if (keyMgmt() == OWE) {
595 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT),
"owe");
598 if (wepTxKeyindex()) {
599 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), wepTxKeyindex());
602 if (authAlg() != None) {
603 if (authAlg() == Open) {
604 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG),
"open");
605 }
else if (authAlg() == Shared) {
606 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG),
"shared");
607 }
else if (authAlg() == Leap) {
608 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG),
"leap");
612 if (!proto().isEmpty()) {
614 const auto protoList = proto();
615 for (
const WpaProtocolVersion &
version : protoList) {
622 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO), strList);
625 if (!pairwise().isEmpty()) {
627 const auto encryptions = pairwise();
628 for (
const WpaEncryptionCapabilities &capability : encryptions) {
629 if (capability == Wep40) {
631 }
else if (capability == Wep104) {
633 }
else if (capability == Tkip) {
635 }
else if (capability == Ccmp) {
639 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE), strList);
642 if (!group().isEmpty()) {
644 const auto encryptions = group();
645 for (
const WpaEncryptionCapabilities &capability : encryptions) {
646 if (capability == Wep40) {
648 }
else if (capability == Wep104) {
650 }
else if (capability == Tkip) {
652 }
else if (capability == Ccmp) {
656 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP), strList);
659 if (!leapUsername().isEmpty()) {
660 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), leapUsername());
664 if (!wepKey0().isEmpty()) {
665 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), wepKey0());
669 if (!wepKey1().isEmpty()) {
670 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), wepKey1());
674 if (!wepKey2().isEmpty()) {
675 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), wepKey2());
679 if (!wepKey3().isEmpty()) {
680 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), wepKey3());
684 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), (
int)wepKeyFlags());
688 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), wepKeyType());
692 if (!psk().isEmpty()) {
693 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), psk());
697 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), (
int)pskFlags());
701 if (!leapPassword().isEmpty()) {
702 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), leapPassword());
705 if (leapPasswordFlags()) {
706 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), (
int)leapPasswordFlags());
710 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF), (
int)pmf());
718 dbg.
nospace() <<
"type: " << setting.typeAsString(setting.type()) <<
'\n';
719 dbg.
nospace() <<
"initialized: " << !setting.isNull() <<
'\n';
721 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_KEY_MGMT <<
": " << setting.keyMgmt() <<
'\n';
722 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX <<
": " << setting.wepTxKeyindex() <<
'\n';
723 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_AUTH_ALG <<
": " << setting.authAlg() <<
'\n';
724 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_PROTO <<
": " << setting.proto() <<
'\n';
725 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_PAIRWISE <<
": " << setting.pairwise() <<
'\n';
726 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_GROUP <<
": " << setting.group() <<
'\n';
727 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME <<
": " << setting.leapUsername() <<
'\n';
728 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY0 <<
": " << setting.wepKey0() <<
'\n';
729 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY1 <<
": " << setting.wepKey1() <<
'\n';
730 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY2 <<
": " << setting.wepKey2() <<
'\n';
731 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY3 <<
": " << setting.wepKey3() <<
'\n';
732 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS <<
": " << setting.wepKeyFlags() <<
'\n';
733 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE <<
": " << setting.wepKeyType() <<
'\n';
734 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_PSK <<
": " << setting.psk() <<
'\n';
735 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS <<
": " << setting.pskFlags() <<
'\n';
736 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD <<
": " << setting.leapPassword() <<
'\n';
737 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS <<
": " << setting.leapPasswordFlags() <<
'\n';
738 dbg.
nospace() << NM_SETTING_WIRELESS_SECURITY_PMF <<
": " << setting.pmf() <<
'\n';
Represents wireless security setting.
QString name() const override
Must be reimplemented, default implementationd does nothing.
void fromMap(const QVariantMap &map) override
Must be reimplemented, default implementation does nothing.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
char * toString(const EngineQuery &query)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
This class allows querying the underlying system to discover the available network interfaces and rea...
NETWORKMANAGERQT_EXPORT QString version()
Get the NetworkManager version.
void push_back(parameter_type value)