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
16NetworkManager::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
29NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting()
30 : Setting(Setting::WirelessSecurity)
31 , d_ptr(new WirelessSecuritySettingPrivate())
32{
33}
34
35NetworkManager::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
58NetworkManager::WirelessSecuritySetting::~WirelessSecuritySetting()
59{
60 delete d_ptr;
61}
62
63QString NetworkManager::WirelessSecuritySetting::name() const
64{
65 Q_D(const WirelessSecuritySetting);
66
67 return d->name;
68}
69
70void NetworkManager::WirelessSecuritySetting::setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt mgmt)
71{
72 Q_D(WirelessSecuritySetting);
73
74 d->keyMgmt = mgmt;
75}
76
77NetworkManager::WirelessSecuritySetting::KeyMgmt NetworkManager::WirelessSecuritySetting::keyMgmt() const
78{
79 Q_D(const WirelessSecuritySetting);
80
81 return d->keyMgmt;
82}
83
84void NetworkManager::WirelessSecuritySetting::setWepTxKeyindex(quint32 index)
85{
86 Q_D(WirelessSecuritySetting);
87
88 d->wepTxKeyidx = index;
89}
90
91quint32 NetworkManager::WirelessSecuritySetting::wepTxKeyindex() const
92{
93 Q_D(const WirelessSecuritySetting);
94
95 return d->wepTxKeyidx;
96}
97
98void NetworkManager::WirelessSecuritySetting::setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg alg)
99{
100 Q_D(WirelessSecuritySetting);
101
102 d->authAlg = alg;
103}
104
105NetworkManager::WirelessSecuritySetting::AuthAlg NetworkManager::WirelessSecuritySetting::authAlg() const
106{
107 Q_D(const WirelessSecuritySetting);
108
109 return d->authAlg;
110}
111
112void NetworkManager::WirelessSecuritySetting::setProto(const QList<NetworkManager::WirelessSecuritySetting::WpaProtocolVersion> &list)
113{
114 Q_D(WirelessSecuritySetting);
115
116 d->proto = list;
117}
118
119QList<NetworkManager::WirelessSecuritySetting::WpaProtocolVersion> NetworkManager::WirelessSecuritySetting::proto() const
120{
121 Q_D(const WirelessSecuritySetting);
122
123 return d->proto;
124}
125
126void NetworkManager::WirelessSecuritySetting::setPairwise(const QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> &list)
127{
128 Q_D(WirelessSecuritySetting);
129
130 d->pairwise = list;
131}
132
133QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> NetworkManager::WirelessSecuritySetting::pairwise() const
134{
135 Q_D(const WirelessSecuritySetting);
136
137 return d->pairwise;
138}
139
140void NetworkManager::WirelessSecuritySetting::setGroup(const QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> &list)
141{
142 Q_D(WirelessSecuritySetting);
143
144 d->group = list;
145}
146
147QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> NetworkManager::WirelessSecuritySetting::group() const
148{
149 Q_D(const WirelessSecuritySetting);
150
151 return d->group;
152}
153
154void NetworkManager::WirelessSecuritySetting::setLeapUsername(const QString &username)
155{
156 Q_D(WirelessSecuritySetting);
157
158 d->leapUsername = username;
159}
160
161QString NetworkManager::WirelessSecuritySetting::leapUsername() const
162{
163 Q_D(const WirelessSecuritySetting);
164
165 return d->leapUsername;
166}
167
168void NetworkManager::WirelessSecuritySetting::setWepKey0(const QString key)
169{
170 Q_D(WirelessSecuritySetting);
171
172 d->wepKey0 = key;
173}
174
175QString NetworkManager::WirelessSecuritySetting::wepKey0() const
176{
177 Q_D(const WirelessSecuritySetting);
178
179 return d->wepKey0;
180}
181
182void NetworkManager::WirelessSecuritySetting::setWepKey1(const QString key)
183{
184 Q_D(WirelessSecuritySetting);
185
186 d->wepKey1 = key;
187}
188
189QString NetworkManager::WirelessSecuritySetting::wepKey1() const
190{
191 Q_D(const WirelessSecuritySetting);
192
193 return d->wepKey1;
194}
195
196void NetworkManager::WirelessSecuritySetting::setWepKey2(const QString key)
197{
198 Q_D(WirelessSecuritySetting);
199
200 d->wepKey2 = key;
201}
202
203QString NetworkManager::WirelessSecuritySetting::wepKey2() const
204{
205 Q_D(const WirelessSecuritySetting);
206
207 return d->wepKey2;
208}
209
210void NetworkManager::WirelessSecuritySetting::setWepKey3(const QString key)
211{
212 Q_D(WirelessSecuritySetting);
213
214 d->wepKey3 = key;
215}
216
217QString NetworkManager::WirelessSecuritySetting::wepKey3() const
218{
219 Q_D(const WirelessSecuritySetting);
220
221 return d->wepKey3;
222}
223
224void NetworkManager::WirelessSecuritySetting::setWepKeyFlags(NetworkManager::Setting::SecretFlags type)
225{
226 Q_D(WirelessSecuritySetting);
227
228 d->wepKeyFlags = type;
229}
230
231NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::wepKeyFlags() const
232{
233 Q_D(const WirelessSecuritySetting);
234
235 return d->wepKeyFlags;
236}
237
238void NetworkManager::WirelessSecuritySetting::setWepKeyType(NetworkManager::WirelessSecuritySetting::WepKeyType type)
239{
240 Q_D(WirelessSecuritySetting);
241
242 d->wepKeyType = type;
243}
244
245NetworkManager::WirelessSecuritySetting::WepKeyType NetworkManager::WirelessSecuritySetting::wepKeyType() const
246{
247 Q_D(const WirelessSecuritySetting);
248
249 return d->wepKeyType;
250}
251
252void NetworkManager::WirelessSecuritySetting::setPsk(const QString &key)
253{
254 Q_D(WirelessSecuritySetting);
255
256 d->psk = key;
257}
258
259QString NetworkManager::WirelessSecuritySetting::psk() const
260{
261 Q_D(const WirelessSecuritySetting);
262
263 return d->psk;
264}
265
266void NetworkManager::WirelessSecuritySetting::setPskFlags(NetworkManager::Setting::SecretFlags type)
267{
268 Q_D(WirelessSecuritySetting);
269
270 d->pskFlags = type;
271}
272
273NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::pskFlags() const
274{
275 Q_D(const WirelessSecuritySetting);
276
277 return d->pskFlags;
278}
279
280void NetworkManager::WirelessSecuritySetting::setLeapPassword(const QString &password)
281{
282 Q_D(WirelessSecuritySetting);
283
284 d->leapPassword = password;
285}
286
287QString NetworkManager::WirelessSecuritySetting::leapPassword() const
288{
289 Q_D(const WirelessSecuritySetting);
290
291 return d->leapPassword;
292}
293
294void NetworkManager::WirelessSecuritySetting::setLeapPasswordFlags(NetworkManager::Setting::SecretFlags type)
295{
296 Q_D(WirelessSecuritySetting);
297
298 d->leapPasswordFlags = type;
299}
300
301NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::leapPasswordFlags() const
302{
303 Q_D(const WirelessSecuritySetting);
304
305 return d->leapPasswordFlags;
306}
307
308void NetworkManager::WirelessSecuritySetting::setPmf(NetworkManager::WirelessSecuritySetting::Pmf pmf)
309{
310 Q_D(WirelessSecuritySetting);
311
312 d->pmf = pmf;
313}
314
315NetworkManager::WirelessSecuritySetting::Pmf NetworkManager::WirelessSecuritySetting::pmf() const
316{
317 Q_D(const WirelessSecuritySetting);
318
319 return d->pmf;
320}
321
322void 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
349QVariantMap 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
380QStringList 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
436void 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 }
455 }
456
457 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX))) {
458 setWepTxKeyindex(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX)).toUInt());
459 }
460
461 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG))) {
462 const QString alg = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG)).toString();
463 if (alg == "open") {
464 setAuthAlg(Open);
465 } else if (alg == "shared") {
466 setAuthAlg(Shared);
467 } else if (alg == "leap") {
468 setAuthAlg(Leap);
469 }
470 }
471
472 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO))) {
473 const QStringList strList = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO)).toStringList();
474 QList<WpaProtocolVersion> list;
475 for (const QString &str : strList) {
476 if (str == "wpa") {
477 list.push_back(t: Wpa);
478 } else if (str == "rsn") {
479 list.push_back(t: Rsn);
480 }
481 }
482 setProto(list);
483 }
484
485 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE))) {
486 const QStringList strList = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE)).toStringList();
487 QList<WpaEncryptionCapabilities> list;
488 for (const QString &str : strList) {
489 if (str == "wep40") {
490 list.push_back(t: Wep40);
491 } else if (str == "wep104") {
492 list.push_back(t: Wep104);
493 } else if (str == "tkip") {
494 list.push_back(t: Tkip);
495 } else if (str == "ccmp") {
496 list.push_back(t: Ccmp);
497 }
498 }
499 setPairwise(list);
500 }
501
502 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP))) {
503 const QStringList strList = map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP)).toStringList();
504 QList<WpaEncryptionCapabilities> list;
505 for (const QString &str : strList) {
506 if (str == "wep40") {
507 list.push_back(t: Wep40);
508 } else if (str == "wep104") {
509 list.push_back(t: Wep104);
510 } else if (str == "tkip") {
511 list.push_back(t: Tkip);
512 } else if (str == "ccmp") {
513 list.push_back(t: Ccmp);
514 }
515 }
516 setGroup(list);
517 }
518
519 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME))) {
520 setLeapUsername(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME)).toString());
521 }
522
523 // Secrets
524 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) {
525 setWepKey0(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).toString());
526 }
527
528 // Secrets
529 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) {
530 setWepKey1(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).toString());
531 }
532
533 // Secrets
534 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) {
535 setWepKey2(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).toString());
536 }
537
538 // Secrets
539 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) {
540 setWepKey3(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).toString());
541 }
542
543 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS))) {
544 setWepKeyFlags((SecretFlags)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS)).toInt());
545 }
546
547 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE))) {
548 setWepKeyType((WepKeyType)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE)).toUInt());
549 }
550
551 // Secrets
552 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) {
553 setPsk(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).toString());
554 }
555
556 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS))) {
557 setPskFlags((SecretFlags)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS)).toInt());
558 }
559
560 // Secrets
561 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) {
562 setLeapPassword(map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).toString());
563 }
564
565 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS))) {
566 setLeapPasswordFlags((SecretFlags)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS)).toInt());
567 }
568
569 if (map.contains(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF))) {
570 setPmf((Pmf)map.value(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF)).toInt());
571 }
572}
573
574QVariantMap NetworkManager::WirelessSecuritySetting::toMap() const
575{
576 QVariantMap setting;
577
578 if (keyMgmt() == Wep) {
579 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "none");
580 } else if (keyMgmt() == Ieee8021x) {
581 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "ieee8021x");
582 } else if (keyMgmt() == WpaNone) {
583 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "wpa-none");
584 } else if (keyMgmt() == WpaPsk) {
585 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "wpa-psk");
586 } else if (keyMgmt() == WpaEap) {
587 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "wpa-eap");
588 } else if (keyMgmt() == SAE) {
589 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "sae");
590 } else if (keyMgmt() == WpaEapSuiteB192) {
591 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), value: "wpa-eap-suite-b-192");
592 }
593
594 if (wepTxKeyindex()) {
595 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), value: wepTxKeyindex());
596 }
597
598 if (authAlg() != None) {
599 if (authAlg() == Open) {
600 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), value: "open");
601 } else if (authAlg() == Shared) {
602 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), value: "shared");
603 } else if (authAlg() == Leap) {
604 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), value: "leap");
605 }
606 }
607
608 if (!proto().isEmpty()) {
609 QStringList strList;
610 const auto protoList = proto();
611 for (const WpaProtocolVersion &version : protoList) {
612 if (version == Wpa) {
613 strList << "wpa";
614 } else if (version == Rsn) {
615 strList << "rsn";
616 }
617 }
618 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO), value: strList);
619 }
620
621 if (!pairwise().isEmpty()) {
622 QStringList strList;
623 const auto encryptions = pairwise();
624 for (const WpaEncryptionCapabilities &capability : encryptions) {
625 if (capability == Wep40) {
626 strList << "wep40";
627 } else if (capability == Wep104) {
628 strList << "wep104";
629 } else if (capability == Tkip) {
630 strList << "tkip";
631 } else if (capability == Ccmp) {
632 strList << "ccmp";
633 }
634 }
635 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE), value: strList);
636 }
637
638 if (!group().isEmpty()) {
639 QStringList strList;
640 const auto encryptions = group();
641 for (const WpaEncryptionCapabilities &capability : encryptions) {
642 if (capability == Wep40) {
643 strList << "wep40";
644 } else if (capability == Wep104) {
645 strList << "wep104";
646 } else if (capability == Tkip) {
647 strList << "tkip";
648 } else if (capability == Ccmp) {
649 strList << "ccmp";
650 }
651 }
652 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP), value: strList);
653 }
654
655 if (!leapUsername().isEmpty()) {
656 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), value: leapUsername());
657 }
658
659 // Secrets
660 if (!wepKey0().isEmpty()) {
661 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), value: wepKey0());
662 }
663
664 // Secrets
665 if (!wepKey1().isEmpty()) {
666 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), value: wepKey1());
667 }
668
669 // Secrets
670 if (!wepKey2().isEmpty()) {
671 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), value: wepKey2());
672 }
673
674 // Secrets
675 if (!wepKey3().isEmpty()) {
676 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), value: wepKey3());
677 }
678
679 if (wepKeyFlags()) {
680 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), value: (int)wepKeyFlags());
681 }
682
683 if (wepKeyType()) {
684 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), value: wepKeyType());
685 }
686
687 // Secrets
688 if (!psk().isEmpty()) {
689 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), value: psk());
690 }
691
692 if (pskFlags()) {
693 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), value: (int)pskFlags());
694 }
695
696 // Secrets
697 if (!leapPassword().isEmpty()) {
698 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), value: leapPassword());
699 }
700
701 if (leapPasswordFlags()) {
702 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), value: (int)leapPasswordFlags());
703 }
704
705 if (pmf()) {
706 setting.insert(key: QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF), value: (int)pmf());
707 }
708
709 return setting;
710}
711
712QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::WirelessSecuritySetting &setting)
713{
714 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
715 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
716
717 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_KEY_MGMT << ": " << setting.keyMgmt() << '\n';
718 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX << ": " << setting.wepTxKeyindex() << '\n';
719 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_AUTH_ALG << ": " << setting.authAlg() << '\n';
720 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PROTO << ": " << setting.proto() << '\n';
721 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PAIRWISE << ": " << setting.pairwise() << '\n';
722 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_GROUP << ": " << setting.group() << '\n';
723 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME << ": " << setting.leapUsername() << '\n';
724 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY0 << ": " << setting.wepKey0() << '\n';
725 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY1 << ": " << setting.wepKey1() << '\n';
726 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY2 << ": " << setting.wepKey2() << '\n';
727 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY3 << ": " << setting.wepKey3() << '\n';
728 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS << ": " << setting.wepKeyFlags() << '\n';
729 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE << ": " << setting.wepKeyType() << '\n';
730 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PSK << ": " << setting.psk() << '\n';
731 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS << ": " << setting.pskFlags() << '\n';
732 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD << ": " << setting.leapPassword() << '\n';
733 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS << ": " << setting.leapPasswordFlags() << '\n';
734 dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PMF << ": " << setting.pmf() << '\n';
735
736 return dbg.maybeSpace();
737}
738

source code of networkmanager-qt/src/settings/wirelesssecuritysetting.cpp