Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/desktop/networkviews.py
diff options
context:
space:
mode:
authorSascha Silbe <silbe@activitycentral.com>2012-04-02 12:18:41 (GMT)
committer Sascha Silbe <silbe@activitycentral.com>2012-04-23 18:35:13 (GMT)
commit117b2855241377e774382054a13246cd487448a8 (patch)
tree5ea530c498f7f6df1f289aa713756df159d51392 /src/jarabe/desktop/networkviews.py
parent93800b812256a8eb39b66812c0ff58238cb02cc5 (diff)
Don't treat SSID as UTF-8 character sequence (fixes SL#2023)
This is a backport of 7f8ba95a66780828531eba0494e004757bf45c71. IEEE 802.11 [2] defines the SSID as a sequence of octets (i.e. bytes), but Sugar treated it as UTF-8 character data. While in most cases the SSID is actually some human-readable string, there's neither a guarantee for that nor does any (de-facto or de-jure) standard specify the encoding to use. As a result, we'll encounter SSIDs in a large variety of encodings and will also need to cope with arbitrary byte strings. Any assumption of a single (or in fact any) character encoding is incorrect. The D-Bus API of NetworkManager 0.9 [3] passes SSIDs as uninterpreted byte strings (D-Bus signature "ay"). Before SSIDs can be displayed on screen, some kind of interpretation must happen. NetworkManager has a rather elaborate heuristic that takes the user locale into account. In the future (i.e. when the NetworkManager client code in Sugar has been ported to gobject-introspection) we may use nm_utils_ssid_to_utf8() [4], but for now we're doing the following to allow the user to use non-UTF-8 APs at all: 1. If the SSID is a valid character string consisting only of printable characters in one of the following encodings (tried in the given order), decode it accordingly: UTF-8, ISO-8859-1, Windows-1251. 2. Return a hex dump of the SSID. The first rule should cover the majority of current Sugar users and hopefully all AP vendors will switch to UTF-8 eventually. In the meantime, the second rule allows users to distinguish between several APs with SSIDs in unknown encodings (or even using arbitrary byte sequences that don't _have_ a character representation). Tested: - filtering on ASCII and non-ASCII parts of the name of and connecting to: - an unsecured AP with a UTF-8 SSID ("äöü߀sugartest", HostAP) - an unsecured AP with an ISO-8859-1 SSID ("äöüßsugartest", HostAP) - an unsecured AP with a non-character SSID (0d:06:f0:0d, HostAP) - a WEP-secured AP with a UTF-8 name ("äöü߀sugartest2", HostAP) - a WEP-secured AP with an ISO-8859-1 name ("äöüßsugartest2", HostAP) - a WEP-secured AP with a non-character SSID (0d:06:f0:0d, HostAP) In each case the name was displayed correctly in a) the palette of the AP icon in the Neighbourhood, b) the palette of the wireless network Frame device and c) the title of the WLAN credentials (WEP/WPA passphrase) dialog (for the WEP cases). [1] https://bugs.sugarlabs.org/ticket/2023 [2] http://standards.ieee.org/getieee802/download/802.11-2007.pdf [3] http://projects.gnome.org/NetworkManager/developers/api/09/spec.html [4] http://projects.gnome.org/NetworkManager/developers/libnm-util/09/libnm-util-nm-utils.html#nm-utils-ssid-to-utf8 Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
Diffstat (limited to 'src/jarabe/desktop/networkviews.py')
-rw-r--r--src/jarabe/desktop/networkviews.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/jarabe/desktop/networkviews.py b/src/jarabe/desktop/networkviews.py
index 677452d..66e34b8 100644
--- a/src/jarabe/desktop/networkviews.py
+++ b/src/jarabe/desktop/networkviews.py
@@ -69,7 +69,8 @@ class WirelessNetworkView(CanvasPulsingIcon):
self._disconnect_item = None
self._connect_item = None
self._filtered = False
- self._name = initial_ap.name
+ self._ssid = initial_ap.ssid
+ self._display_name = network.ssid_to_display_name(self._ssid)
self._mode = initial_ap.mode
self._strength = initial_ap.strength
self._flags = initial_ap.flags
@@ -80,11 +81,11 @@ class WirelessNetworkView(CanvasPulsingIcon):
self._color = None
if self._mode == network.NM_802_11_MODE_ADHOC and \
- network.is_sugar_adhoc_network(self._name):
+ network.is_sugar_adhoc_network(self._ssid):
self._color = profile.get_color()
else:
sha_hash = hashlib.sha1()
- data = self._name + hex(self._flags)
+ data = self._ssid + hex(self._flags)
sha_hash.update(data)
digest = hash(sha_hash.digest())
index = digest % len(xocolor.colors)
@@ -130,8 +131,8 @@ class WirelessNetworkView(CanvasPulsingIcon):
icon_size=style.STANDARD_ICON_SIZE,
badge_name=self.props.badge_name)
- p = palette.Palette(primary_text=glib.markup_escape_text(self._name),
- icon=self._palette_icon)
+ label = glib.markup_escape_text(self._display_name)
+ p = palette.Palette(primary_text=label, icon=self._palette_icon)
self._connect_item = MenuItem(_('Connect'), 'dialog-ok')
self._connect_item.connect('activate', self.__connect_activate_cb)
@@ -189,7 +190,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
def _update_icon(self):
if self._mode == network.NM_802_11_MODE_ADHOC and \
- network.is_sugar_adhoc_network(self._name):
+ network.is_sugar_adhoc_network(self._ssid):
channel = max([1] + [ap.channel for ap in
self._access_points.values()])
if self._device_state == network.DEVICE_STATE_ACTIVATED and \
@@ -215,7 +216,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
def _update_badge(self):
if self._mode != network.NM_802_11_MODE_ADHOC:
- if network.find_connection_by_ssid(self._name) is not None:
+ if network.find_connection_by_ssid(self._ssid) is not None:
self.props.badge_name = 'emblem-favorite'
self._palette_icon.props.badge_name = 'emblem-favorite'
elif self._flags == network.NM_802_11_AP_FLAGS_PRIVACY:
@@ -244,7 +245,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
self._palette.props.secondary_text = _('Connecting...')
self.props.pulsing = True
elif state == network.DEVICE_STATE_ACTIVATED:
- connection = network.find_connection_by_ssid(self._name)
+ connection = network.find_connection_by_ssid(self._ssid)
if connection is not None:
if self._mode == network.NM_802_11_MODE_INFRA:
connection.set_connected()
@@ -270,7 +271,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
def _disconnect_activate_cb(self, item):
if self._mode == network.NM_802_11_MODE_INFRA:
- connection = network.find_connection_by_ssid(self._name)
+ connection = network.find_connection_by_ssid(self._ssid)
if connection:
connection.disable_autoconnect()
@@ -347,13 +348,13 @@ class WirelessNetworkView(CanvasPulsingIcon):
self._connect()
def _connect(self):
- connection = network.find_connection_by_ssid(self._name)
+ connection = network.find_connection_by_ssid(self._ssid)
if connection is None:
settings = Settings()
- settings.connection.id = 'Auto ' + self._name
+ settings.connection.id = 'Auto ' + self._display_name
uuid = settings.connection.uuid = unique_id()
settings.connection.type = '802-11-wireless'
- settings.wireless.ssid = self._name
+ settings.wireless.ssid = self._ssid
if self._mode == network.NM_802_11_MODE_INFRA:
settings.wireless.mode = 'infrastructure'
@@ -387,12 +388,12 @@ class WirelessNetworkView(CanvasPulsingIcon):
logging.error('Failed to activate connection: %s', err)
def set_filter(self, query):
- self._filtered = self._name.lower().find(query) == -1
+ self._filtered = self._display_name.lower().find(query) == -1
self._update_icon()
self._update_color()
def create_keydialog(self, settings, response):
- keydialog.create(self._name, self._flags, self._wpa_flags,
+ keydialog.create(self._ssid, self._flags, self._wpa_flags,
self._rsn_flags, self._device_caps, settings,
response)
@@ -433,7 +434,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
def is_olpc_mesh(self):
return self._mode == network.NM_802_11_MODE_ADHOC \
- and self.name == 'olpc-mesh'
+ and self._ssid == 'olpc-mesh'
def remove_all_aps(self):
for ap in self._access_points.values():
@@ -601,7 +602,6 @@ class OlpcMeshView(CanvasPulsingIcon):
self._disconnect_item = None
self._connect_item = None
self._filtered = False
- self._name = ''
self._device_state = None
self._active = False
device = mesh_mgr.mesh_device