status/network: Use NM utility function for classifying security

Interpreting the different flags is better left to the domain
experts at NetworkManager. It is also much more likely that
NM's own functions will handle newly added flags than our own
code.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2406>
This commit is contained in:
Florian Müllner 2022-07-23 21:56:04 +02:00
parent 54a1c34f6e
commit 1aa01fc8ca

View File

@ -40,8 +40,6 @@ var MAX_DEVICE_ITEMS = 4;
// small optimization, to avoid using [] all the time // small optimization, to avoid using [] all the time
const NM80211Mode = NM['80211Mode']; const NM80211Mode = NM['80211Mode'];
const NM80211ApFlags = NM['80211ApFlags'];
const NM80211ApSecurityFlags = NM['80211ApSecurityFlags'];
var PortalHelperResult = { var PortalHelperResult = {
CANCELLED: 0, CANCELLED: 0,
@ -742,6 +740,9 @@ var NMWirelessDialogItem = GObject.registerClass({
var NMWirelessDialog = GObject.registerClass( var NMWirelessDialog = GObject.registerClass(
class NMWirelessDialog extends ModalDialog.ModalDialog { class NMWirelessDialog extends ModalDialog.ModalDialog {
static _securityTypes =
Object.values(NM.UtilsSecurityType).sort((a, b) => b - a);
_init(client, device) { _init(client, device) {
super._init({ styleClass: 'nm-dialog' }); super._init({ styleClass: 'nm-dialog' });
@ -1007,32 +1008,16 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
if (accessPoint._secType) if (accessPoint._secType)
return accessPoint._secType; return accessPoint._secType;
let flags = accessPoint.flags; const {wirelessCapabilities: caps} = this._device;
let wpaFlags = accessPoint.wpa_flags; const {flags, wpaFlags, rsnFlags} = accessPoint;
let rsnFlags = accessPoint.rsn_flags; const haveAp = true;
let type; const adHoc = accessPoint.mode === NM80211Mode.ADHOC;
if (rsnFlags != NM80211ApSecurityFlags.NONE) { const bestType = NMWirelessDialog._securityTypes
/* RSN check first so that WPA+WPA2 APs are treated as RSN/WPA2 */ .find(t => NM.utils_security_valid(t, caps, haveAp, adHoc, flags, wpaFlags, rsnFlags));
if (rsnFlags & NM80211ApSecurityFlags.KEY_MGMT_802_1X)
type = NMAccessPointSecurity.WPA2_ENT;
else if (rsnFlags & NM80211ApSecurityFlags.KEY_MGMT_PSK)
type = NMAccessPointSecurity.WPA2_PSK;
} else if (wpaFlags != NM80211ApSecurityFlags.NONE) {
if (wpaFlags & NM80211ApSecurityFlags.KEY_MGMT_802_1X)
type = NMAccessPointSecurity.WPA_ENT;
else if (wpaFlags & NM80211ApSecurityFlags.KEY_MGMT_PSK)
type = NMAccessPointSecurity.WPA_PSK;
} else {
// eslint-disable-next-line no-lonely-if
if (flags & NM80211ApFlags.PRIVACY)
type = NMAccessPointSecurity.WEP;
else
type = NMAccessPointSecurity.NONE;
}
// cache the found value to avoid checking flags all the time // cache the found value to avoid checking flags all the time
accessPoint._secType = type; accessPoint._secType = bestType ?? NM.UtilsSecurityType.INVALID;
return type; return accessPoint._secType;
} }
_networkSortFunction(one, two) { _networkSortFunction(one, two) {