| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 | */ |
| 6 | |
| 7 | #include "wirelesssecuritysetting.h" |
| 8 | #include "wirelesssecuritysetting_p.h" |
| 9 | |
| 10 | #include <QDebug> |
| 11 | |
| 12 | #if !NM_CHECK_VERSION(1, 10, 0) |
| 13 | #define NM_SETTING_WIRELESS_SECURITY_PMF "pmf" |
| 14 | #endif |
| 15 | |
| 16 | NetworkManager::WirelessSecuritySettingPrivate::WirelessSecuritySettingPrivate() |
| 17 | : name(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) |
| 18 | , keyMgmt(NetworkManager::WirelessSecuritySetting::Unknown) |
| 19 | , wepTxKeyidx(0) |
| 20 | , authAlg(NetworkManager::WirelessSecuritySetting::None) |
| 21 | , wepKeyFlags(NetworkManager::Setting::None) |
| 22 | , wepKeyType(NetworkManager::WirelessSecuritySetting::NotSpecified) |
| 23 | , pskFlags(NetworkManager::Setting::None) |
| 24 | , leapPasswordFlags(NetworkManager::Setting::None) |
| 25 | , pmf(NetworkManager::WirelessSecuritySetting::DefaultPmf) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting() |
| 30 | : Setting(Setting::WirelessSecurity) |
| 31 | , d_ptr(new WirelessSecuritySettingPrivate()) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting(const Ptr &other) |
| 36 | : Setting(other) |
| 37 | , d_ptr(new WirelessSecuritySettingPrivate()) |
| 38 | { |
| 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()); |
| 51 | setPsk(other->psk()); |
| 52 | setPskFlags(other->pskFlags()); |
| 53 | setLeapPassword(other->leapPassword()); |
| 54 | setLeapPasswordFlags(other->leapPasswordFlags()); |
| 55 | setPmf(other->pmf()); |
| 56 | } |
| 57 | |
| 58 | NetworkManager::WirelessSecuritySetting::~WirelessSecuritySetting() |
| 59 | { |
| 60 | delete d_ptr; |
| 61 | } |
| 62 | |
| 63 | QString NetworkManager::WirelessSecuritySetting::name() const |
| 64 | { |
| 65 | Q_D(const WirelessSecuritySetting); |
| 66 | |
| 67 | return d->name; |
| 68 | } |
| 69 | |
| 70 | void NetworkManager::WirelessSecuritySetting::setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt mgmt) |
| 71 | { |
| 72 | Q_D(WirelessSecuritySetting); |
| 73 | |
| 74 | d->keyMgmt = mgmt; |
| 75 | } |
| 76 | |
| 77 | NetworkManager::WirelessSecuritySetting::KeyMgmt NetworkManager::WirelessSecuritySetting::keyMgmt() const |
| 78 | { |
| 79 | Q_D(const WirelessSecuritySetting); |
| 80 | |
| 81 | return d->keyMgmt; |
| 82 | } |
| 83 | |
| 84 | void NetworkManager::WirelessSecuritySetting::setWepTxKeyindex(quint32 index) |
| 85 | { |
| 86 | Q_D(WirelessSecuritySetting); |
| 87 | |
| 88 | d->wepTxKeyidx = index; |
| 89 | } |
| 90 | |
| 91 | quint32 NetworkManager::WirelessSecuritySetting::wepTxKeyindex() const |
| 92 | { |
| 93 | Q_D(const WirelessSecuritySetting); |
| 94 | |
| 95 | return d->wepTxKeyidx; |
| 96 | } |
| 97 | |
| 98 | void NetworkManager::WirelessSecuritySetting::setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg alg) |
| 99 | { |
| 100 | Q_D(WirelessSecuritySetting); |
| 101 | |
| 102 | d->authAlg = alg; |
| 103 | } |
| 104 | |
| 105 | NetworkManager::WirelessSecuritySetting::AuthAlg NetworkManager::WirelessSecuritySetting::authAlg() const |
| 106 | { |
| 107 | Q_D(const WirelessSecuritySetting); |
| 108 | |
| 109 | return d->authAlg; |
| 110 | } |
| 111 | |
| 112 | void NetworkManager::WirelessSecuritySetting::setProto(const QList<NetworkManager::WirelessSecuritySetting::WpaProtocolVersion> &list) |
| 113 | { |
| 114 | Q_D(WirelessSecuritySetting); |
| 115 | |
| 116 | d->proto = list; |
| 117 | } |
| 118 | |
| 119 | QList<NetworkManager::WirelessSecuritySetting::WpaProtocolVersion> NetworkManager::WirelessSecuritySetting::proto() const |
| 120 | { |
| 121 | Q_D(const WirelessSecuritySetting); |
| 122 | |
| 123 | return d->proto; |
| 124 | } |
| 125 | |
| 126 | void NetworkManager::WirelessSecuritySetting::setPairwise(const QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> &list) |
| 127 | { |
| 128 | Q_D(WirelessSecuritySetting); |
| 129 | |
| 130 | d->pairwise = list; |
| 131 | } |
| 132 | |
| 133 | QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> NetworkManager::WirelessSecuritySetting::pairwise() const |
| 134 | { |
| 135 | Q_D(const WirelessSecuritySetting); |
| 136 | |
| 137 | return d->pairwise; |
| 138 | } |
| 139 | |
| 140 | void NetworkManager::WirelessSecuritySetting::setGroup(const QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> &list) |
| 141 | { |
| 142 | Q_D(WirelessSecuritySetting); |
| 143 | |
| 144 | d->group = list; |
| 145 | } |
| 146 | |
| 147 | QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> NetworkManager::WirelessSecuritySetting::group() const |
| 148 | { |
| 149 | Q_D(const WirelessSecuritySetting); |
| 150 | |
| 151 | return d->group; |
| 152 | } |
| 153 | |
| 154 | void NetworkManager::WirelessSecuritySetting::setLeapUsername(const QString &username) |
| 155 | { |
| 156 | Q_D(WirelessSecuritySetting); |
| 157 | |
| 158 | d->leapUsername = username; |
| 159 | } |
| 160 | |
| 161 | QString NetworkManager::WirelessSecuritySetting::leapUsername() const |
| 162 | { |
| 163 | Q_D(const WirelessSecuritySetting); |
| 164 | |
| 165 | return d->leapUsername; |
| 166 | } |
| 167 | |
| 168 | void NetworkManager::WirelessSecuritySetting::setWepKey0(const QString key) |
| 169 | { |
| 170 | Q_D(WirelessSecuritySetting); |
| 171 | |
| 172 | d->wepKey0 = key; |
| 173 | } |
| 174 | |
| 175 | QString NetworkManager::WirelessSecuritySetting::wepKey0() const |
| 176 | { |
| 177 | Q_D(const WirelessSecuritySetting); |
| 178 | |
| 179 | return d->wepKey0; |
| 180 | } |
| 181 | |
| 182 | void NetworkManager::WirelessSecuritySetting::setWepKey1(const QString key) |
| 183 | { |
| 184 | Q_D(WirelessSecuritySetting); |
| 185 | |
| 186 | d->wepKey1 = key; |
| 187 | } |
| 188 | |
| 189 | QString NetworkManager::WirelessSecuritySetting::wepKey1() const |
| 190 | { |
| 191 | Q_D(const WirelessSecuritySetting); |
| 192 | |
| 193 | return d->wepKey1; |
| 194 | } |
| 195 | |
| 196 | void NetworkManager::WirelessSecuritySetting::setWepKey2(const QString key) |
| 197 | { |
| 198 | Q_D(WirelessSecuritySetting); |
| 199 | |
| 200 | d->wepKey2 = key; |
| 201 | } |
| 202 | |
| 203 | QString NetworkManager::WirelessSecuritySetting::wepKey2() const |
| 204 | { |
| 205 | Q_D(const WirelessSecuritySetting); |
| 206 | |
| 207 | return d->wepKey2; |
| 208 | } |
| 209 | |
| 210 | void NetworkManager::WirelessSecuritySetting::setWepKey3(const QString key) |
| 211 | { |
| 212 | Q_D(WirelessSecuritySetting); |
| 213 | |
| 214 | d->wepKey3 = key; |
| 215 | } |
| 216 | |
| 217 | QString NetworkManager::WirelessSecuritySetting::wepKey3() const |
| 218 | { |
| 219 | Q_D(const WirelessSecuritySetting); |
| 220 | |
| 221 | return d->wepKey3; |
| 222 | } |
| 223 | |
| 224 | void NetworkManager::WirelessSecuritySetting::setWepKeyFlags(NetworkManager::Setting::SecretFlags type) |
| 225 | { |
| 226 | Q_D(WirelessSecuritySetting); |
| 227 | |
| 228 | d->wepKeyFlags = type; |
| 229 | } |
| 230 | |
| 231 | NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::wepKeyFlags() const |
| 232 | { |
| 233 | Q_D(const WirelessSecuritySetting); |
| 234 | |
| 235 | return d->wepKeyFlags; |
| 236 | } |
| 237 | |
| 238 | void NetworkManager::WirelessSecuritySetting::setWepKeyType(NetworkManager::WirelessSecuritySetting::WepKeyType type) |
| 239 | { |
| 240 | Q_D(WirelessSecuritySetting); |
| 241 | |
| 242 | d->wepKeyType = type; |
| 243 | } |
| 244 | |
| 245 | NetworkManager::WirelessSecuritySetting::WepKeyType NetworkManager::WirelessSecuritySetting::wepKeyType() const |
| 246 | { |
| 247 | Q_D(const WirelessSecuritySetting); |
| 248 | |
| 249 | return d->wepKeyType; |
| 250 | } |
| 251 | |
| 252 | void NetworkManager::WirelessSecuritySetting::setPsk(const QString &key) |
| 253 | { |
| 254 | Q_D(WirelessSecuritySetting); |
| 255 | |
| 256 | d->psk = key; |
| 257 | } |
| 258 | |
| 259 | QString NetworkManager::WirelessSecuritySetting::psk() const |
| 260 | { |
| 261 | Q_D(const WirelessSecuritySetting); |
| 262 | |
| 263 | return d->psk; |
| 264 | } |
| 265 | |
| 266 | void NetworkManager::WirelessSecuritySetting::setPskFlags(NetworkManager::Setting::SecretFlags type) |
| 267 | { |
| 268 | Q_D(WirelessSecuritySetting); |
| 269 | |
| 270 | d->pskFlags = type; |
| 271 | } |
| 272 | |
| 273 | NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::pskFlags() const |
| 274 | { |
| 275 | Q_D(const WirelessSecuritySetting); |
| 276 | |
| 277 | return d->pskFlags; |
| 278 | } |
| 279 | |
| 280 | void NetworkManager::WirelessSecuritySetting::setLeapPassword(const QString &password) |
| 281 | { |
| 282 | Q_D(WirelessSecuritySetting); |
| 283 | |
| 284 | d->leapPassword = password; |
| 285 | } |
| 286 | |
| 287 | QString NetworkManager::WirelessSecuritySetting::leapPassword() const |
| 288 | { |
| 289 | Q_D(const WirelessSecuritySetting); |
| 290 | |
| 291 | return d->leapPassword; |
| 292 | } |
| 293 | |
| 294 | void NetworkManager::WirelessSecuritySetting::setLeapPasswordFlags(NetworkManager::Setting::SecretFlags type) |
| 295 | { |
| 296 | Q_D(WirelessSecuritySetting); |
| 297 | |
| 298 | d->leapPasswordFlags = type; |
| 299 | } |
| 300 | |
| 301 | NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::leapPasswordFlags() const |
| 302 | { |
| 303 | Q_D(const WirelessSecuritySetting); |
| 304 | |
| 305 | return d->leapPasswordFlags; |
| 306 | } |
| 307 | |
| 308 | void NetworkManager::WirelessSecuritySetting::setPmf(NetworkManager::WirelessSecuritySetting::Pmf pmf) |
| 309 | { |
| 310 | Q_D(WirelessSecuritySetting); |
| 311 | |
| 312 | d->pmf = pmf; |
| 313 | } |
| 314 | |
| 315 | NetworkManager::WirelessSecuritySetting::Pmf NetworkManager::WirelessSecuritySetting::pmf() const |
| 316 | { |
| 317 | Q_D(const WirelessSecuritySetting); |
| 318 | |
| 319 | return d->pmf; |
| 320 | } |
| 321 | |
| 322 | void NetworkManager::WirelessSecuritySetting::secretsFromMap(const QVariantMap &secrets) |
| 323 | { |
| 324 | if (secrets.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) { |
| 325 | setWepKey0(secrets.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).toString()); |
| 326 | } |
| 327 | |
| 328 | if (secrets.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) { |
| 329 | setWepKey1(secrets.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).toString()); |
| 330 | } |
| 331 | |
| 332 | if (secrets.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) { |
| 333 | setWepKey2(secrets.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).toString()); |
| 334 | } |
| 335 | |
| 336 | if (secrets.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) { |
| 337 | setWepKey3(secrets.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).toString()); |
| 338 | } |
| 339 | |
| 340 | if (secrets.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) { |
| 341 | setPsk(secrets.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).toString()); |
| 342 | } |
| 343 | |
| 344 | if (secrets.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) { |
| 345 | setLeapPassword(secrets.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).toString()); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | QVariantMap NetworkManager::WirelessSecuritySetting::secretsToMap() const |
| 350 | { |
| 351 | QVariantMap secrets; |
| 352 | |
| 353 | if (!wepKey0().isEmpty()) { |
| 354 | secrets.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), value: wepKey0()); |
| 355 | } |
| 356 | |
| 357 | if (!wepKey1().isEmpty()) { |
| 358 | secrets.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), value: wepKey1()); |
| 359 | } |
| 360 | |
| 361 | if (!wepKey2().isEmpty()) { |
| 362 | secrets.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), value: wepKey2()); |
| 363 | } |
| 364 | |
| 365 | if (!wepKey3().isEmpty()) { |
| 366 | secrets.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), value: wepKey3()); |
| 367 | } |
| 368 | |
| 369 | if (!psk().isEmpty()) { |
| 370 | secrets.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), value: psk()); |
| 371 | } |
| 372 | |
| 373 | if (!leapPassword().isEmpty()) { |
| 374 | secrets.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), value: leapPassword()); |
| 375 | } |
| 376 | |
| 377 | return secrets; |
| 378 | } |
| 379 | |
| 380 | QStringList NetworkManager::WirelessSecuritySetting::needSecrets(bool requestNew) const |
| 381 | { |
| 382 | QStringList secrets; |
| 383 | |
| 384 | if (keyMgmt() == Wep) { |
| 385 | if (!wepKeyFlags().testFlag(flag: Setting::NotRequired)) { |
| 386 | switch (wepTxKeyindex()) { |
| 387 | case 0: |
| 388 | if (wepKey0().isEmpty() || requestNew) { |
| 389 | secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); |
| 390 | return secrets; |
| 391 | } |
| 392 | break; |
| 393 | case 1: |
| 394 | if (wepKey1().isEmpty() || requestNew) { |
| 395 | secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1); |
| 396 | return secrets; |
| 397 | } |
| 398 | break; |
| 399 | case 2: |
| 400 | if (wepKey2().isEmpty() || requestNew) { |
| 401 | secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2); |
| 402 | return secrets; |
| 403 | } |
| 404 | break; |
| 405 | case 3: |
| 406 | if (wepKey3().isEmpty() || requestNew) { |
| 407 | secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3); |
| 408 | return secrets; |
| 409 | } |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | if (keyMgmt() == WpaNone || keyMgmt() == WpaPsk || keyMgmt() == SAE) { |
| 416 | if (!pskFlags().testFlag(flag: Setting::NotRequired)) { |
| 417 | if (psk().isEmpty() || requestNew) { |
| 418 | secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK); |
| 419 | return secrets; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | if (authAlg() == Leap && keyMgmt() == Ieee8021x) { |
| 425 | if (!leapPasswordFlags().testFlag(flag: Setting::NotRequired)) { |
| 426 | if (leapPassword().isEmpty() || requestNew) { |
| 427 | secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD); |
| 428 | return secrets; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | return secrets; |
| 434 | } |
| 435 | |
| 436 | void NetworkManager::WirelessSecuritySetting::fromMap(const QVariantMap &map) |
| 437 | { |
| 438 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT))) { |
| 439 | const QString key = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)).toString(); |
| 440 | if (key == "none" ) { |
| 441 | setKeyMgmt(Wep); |
| 442 | } else if (key == "ieee8021x" ) { |
| 443 | setKeyMgmt(Ieee8021x); |
| 444 | } else if (key == "wpa-none" ) { |
| 445 | setKeyMgmt(WpaNone); |
| 446 | } else if (key == "wpa-psk" ) { |
| 447 | setKeyMgmt(WpaPsk); |
| 448 | } else if (key == "wpa-eap" ) { |
| 449 | setKeyMgmt(WpaEap); |
| 450 | } else if (key == "sae" ) { |
| 451 | setKeyMgmt(SAE); |
| 452 | } else if (key == "wpa-eap-suite-b-192" ) { |
| 453 | setKeyMgmt(WpaEapSuiteB192); |
| 454 | } else if (key == "owe" ) { |
| 455 | setKeyMgmt(OWE); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX))) { |
| 460 | setWepTxKeyindex(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX)).toUInt()); |
| 461 | } |
| 462 | |
| 463 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG))) { |
| 464 | const QString alg = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG)).toString(); |
| 465 | if (alg == "open" ) { |
| 466 | setAuthAlg(Open); |
| 467 | } else if (alg == "shared" ) { |
| 468 | setAuthAlg(Shared); |
| 469 | } else if (alg == "leap" ) { |
| 470 | setAuthAlg(Leap); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO))) { |
| 475 | const QStringList strList = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO)).toStringList(); |
| 476 | QList<WpaProtocolVersion> list; |
| 477 | for (const QString &str : strList) { |
| 478 | if (str == "wpa" ) { |
| 479 | list.push_back(t: Wpa); |
| 480 | } else if (str == "rsn" ) { |
| 481 | list.push_back(t: Rsn); |
| 482 | } |
| 483 | } |
| 484 | setProto(list); |
| 485 | } |
| 486 | |
| 487 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE))) { |
| 488 | const QStringList strList = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE)).toStringList(); |
| 489 | QList<WpaEncryptionCapabilities> list; |
| 490 | for (const QString &str : strList) { |
| 491 | if (str == "wep40" ) { |
| 492 | list.push_back(t: Wep40); |
| 493 | } else if (str == "wep104" ) { |
| 494 | list.push_back(t: Wep104); |
| 495 | } else if (str == "tkip" ) { |
| 496 | list.push_back(t: Tkip); |
| 497 | } else if (str == "ccmp" ) { |
| 498 | list.push_back(t: Ccmp); |
| 499 | } |
| 500 | } |
| 501 | setPairwise(list); |
| 502 | } |
| 503 | |
| 504 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP))) { |
| 505 | const QStringList strList = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP)).toStringList(); |
| 506 | QList<WpaEncryptionCapabilities> list; |
| 507 | for (const QString &str : strList) { |
| 508 | if (str == "wep40" ) { |
| 509 | list.push_back(t: Wep40); |
| 510 | } else if (str == "wep104" ) { |
| 511 | list.push_back(t: Wep104); |
| 512 | } else if (str == "tkip" ) { |
| 513 | list.push_back(t: Tkip); |
| 514 | } else if (str == "ccmp" ) { |
| 515 | list.push_back(t: Ccmp); |
| 516 | } |
| 517 | } |
| 518 | setGroup(list); |
| 519 | } |
| 520 | |
| 521 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME))) { |
| 522 | setLeapUsername(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME)).toString()); |
| 523 | } |
| 524 | |
| 525 | // Secrets |
| 526 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) { |
| 527 | setWepKey0(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).toString()); |
| 528 | } |
| 529 | |
| 530 | // Secrets |
| 531 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) { |
| 532 | setWepKey1(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).toString()); |
| 533 | } |
| 534 | |
| 535 | // Secrets |
| 536 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) { |
| 537 | setWepKey2(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).toString()); |
| 538 | } |
| 539 | |
| 540 | // Secrets |
| 541 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) { |
| 542 | setWepKey3(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).toString()); |
| 543 | } |
| 544 | |
| 545 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS))) { |
| 546 | setWepKeyFlags((SecretFlags)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS)).toInt()); |
| 547 | } |
| 548 | |
| 549 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE))) { |
| 550 | setWepKeyType((WepKeyType)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE)).toUInt()); |
| 551 | } |
| 552 | |
| 553 | // Secrets |
| 554 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) { |
| 555 | setPsk(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).toString()); |
| 556 | } |
| 557 | |
| 558 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS))) { |
| 559 | setPskFlags((SecretFlags)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS)).toInt()); |
| 560 | } |
| 561 | |
| 562 | // Secrets |
| 563 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) { |
| 564 | setLeapPassword(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).toString()); |
| 565 | } |
| 566 | |
| 567 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS))) { |
| 568 | setLeapPasswordFlags((SecretFlags)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS)).toInt()); |
| 569 | } |
| 570 | |
| 571 | if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF))) { |
| 572 | setPmf((Pmf)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF)).toInt()); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | QVariantMap NetworkManager::WirelessSecuritySetting::toMap() const |
| 577 | { |
| 578 | QVariantMap setting; |
| 579 | |
| 580 | if (keyMgmt() == Wep) { |
| 581 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "none" ); |
| 582 | } else if (keyMgmt() == Ieee8021x) { |
| 583 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "ieee8021x" ); |
| 584 | } else if (keyMgmt() == WpaNone) { |
| 585 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "wpa-none" ); |
| 586 | } else if (keyMgmt() == WpaPsk) { |
| 587 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "wpa-psk" ); |
| 588 | } else if (keyMgmt() == WpaEap) { |
| 589 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "wpa-eap" ); |
| 590 | } else if (keyMgmt() == SAE) { |
| 591 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "sae" ); |
| 592 | } else if (keyMgmt() == WpaEapSuiteB192) { |
| 593 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "wpa-eap-suite-b-192" ); |
| 594 | } else if (keyMgmt() == OWE) { |
| 595 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "owe" ); |
| 596 | } |
| 597 | |
| 598 | if (wepTxKeyindex()) { |
| 599 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), value: wepTxKeyindex()); |
| 600 | } |
| 601 | |
| 602 | if (authAlg() != None) { |
| 603 | if (authAlg() == Open) { |
| 604 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), value: "open" ); |
| 605 | } else if (authAlg() == Shared) { |
| 606 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), value: "shared" ); |
| 607 | } else if (authAlg() == Leap) { |
| 608 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), value: "leap" ); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | if (!proto().isEmpty()) { |
| 613 | QStringList strList; |
| 614 | const auto protoList = proto(); |
| 615 | for (const WpaProtocolVersion &version : protoList) { |
| 616 | if (version == Wpa) { |
| 617 | strList << "wpa" ; |
| 618 | } else if (version == Rsn) { |
| 619 | strList << "rsn" ; |
| 620 | } |
| 621 | } |
| 622 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO), value: strList); |
| 623 | } |
| 624 | |
| 625 | if (!pairwise().isEmpty()) { |
| 626 | QStringList strList; |
| 627 | const auto encryptions = pairwise(); |
| 628 | for (const WpaEncryptionCapabilities &capability : encryptions) { |
| 629 | if (capability == Wep40) { |
| 630 | strList << "wep40" ; |
| 631 | } else if (capability == Wep104) { |
| 632 | strList << "wep104" ; |
| 633 | } else if (capability == Tkip) { |
| 634 | strList << "tkip" ; |
| 635 | } else if (capability == Ccmp) { |
| 636 | strList << "ccmp" ; |
| 637 | } |
| 638 | } |
| 639 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE), value: strList); |
| 640 | } |
| 641 | |
| 642 | if (!group().isEmpty()) { |
| 643 | QStringList strList; |
| 644 | const auto encryptions = group(); |
| 645 | for (const WpaEncryptionCapabilities &capability : encryptions) { |
| 646 | if (capability == Wep40) { |
| 647 | strList << "wep40" ; |
| 648 | } else if (capability == Wep104) { |
| 649 | strList << "wep104" ; |
| 650 | } else if (capability == Tkip) { |
| 651 | strList << "tkip" ; |
| 652 | } else if (capability == Ccmp) { |
| 653 | strList << "ccmp" ; |
| 654 | } |
| 655 | } |
| 656 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP), value: strList); |
| 657 | } |
| 658 | |
| 659 | if (!leapUsername().isEmpty()) { |
| 660 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), value: leapUsername()); |
| 661 | } |
| 662 | |
| 663 | // Secrets |
| 664 | if (!wepKey0().isEmpty()) { |
| 665 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), value: wepKey0()); |
| 666 | } |
| 667 | |
| 668 | // Secrets |
| 669 | if (!wepKey1().isEmpty()) { |
| 670 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), value: wepKey1()); |
| 671 | } |
| 672 | |
| 673 | // Secrets |
| 674 | if (!wepKey2().isEmpty()) { |
| 675 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), value: wepKey2()); |
| 676 | } |
| 677 | |
| 678 | // Secrets |
| 679 | if (!wepKey3().isEmpty()) { |
| 680 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), value: wepKey3()); |
| 681 | } |
| 682 | |
| 683 | if (wepKeyFlags()) { |
| 684 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), value: (int)wepKeyFlags()); |
| 685 | } |
| 686 | |
| 687 | if (wepKeyType()) { |
| 688 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), value: wepKeyType()); |
| 689 | } |
| 690 | |
| 691 | // Secrets |
| 692 | if (!psk().isEmpty()) { |
| 693 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), value: psk()); |
| 694 | } |
| 695 | |
| 696 | if (pskFlags()) { |
| 697 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), value: (int)pskFlags()); |
| 698 | } |
| 699 | |
| 700 | // Secrets |
| 701 | if (!leapPassword().isEmpty()) { |
| 702 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), value: leapPassword()); |
| 703 | } |
| 704 | |
| 705 | if (leapPasswordFlags()) { |
| 706 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), value: (int)leapPasswordFlags()); |
| 707 | } |
| 708 | |
| 709 | if (pmf()) { |
| 710 | setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF), value: (int)pmf()); |
| 711 | } |
| 712 | |
| 713 | return setting; |
| 714 | } |
| 715 | |
| 716 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::WirelessSecuritySetting &setting) |
| 717 | { |
| 718 | dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n'; |
| 719 | dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; |
| 720 | |
| 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'; |
| 739 | |
| 740 | return dbg.maybeSpace(); |
| 741 | } |
| 742 | |