From 11df3e4eb2bfc8c52306f19b044531a3df067e8f Mon Sep 17 00:00:00 2001 From: Bert Freudenberg Date: Tue, 25 Sep 2007 16:07:48 +0200 Subject: [PATCH 1/2] Support dbus introspection in sugar-native-factory (#2477) --- NEWS | 1 + bin/sugar-native-factory.c | 42 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 47c999a5..55157895 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ +* #2477 Support dbus introspection in sugar-native-factory (bertf) * #2674 Add arrows to hint about the frame corner activation (marco) * #2665 Re-arrange device icons in a line at the bottom (marco) * #3378 Support changes in activity scope (incomplete!) (smcv, marco) diff --git a/bin/sugar-native-factory.c b/bin/sugar-native-factory.c index e4913dd2..858249a2 100644 --- a/bin/sugar-native-factory.c +++ b/bin/sugar-native-factory.c @@ -137,6 +137,40 @@ create_instance(int argc) +/* handle dbus Introspect() call */ + +static DBusHandlerResult +handle_introspect(DBusConnection *connection, DBusMessage* message) +{ + DBusMessage *reply; + const char *introspect_xml = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; + + reply = dbus_message_new_method_return(message); + dbus_message_append_args(reply, + DBUS_TYPE_STRING, &introspect_xml, + DBUS_TYPE_INVALID); + + dbus_connection_send(connection, reply, NULL); + dbus_message_unref(reply); + + return DBUS_HANDLER_RESULT_HANDLED; +} + + + /* handle dbus create() call */ static DBusHandlerResult @@ -212,8 +246,12 @@ factory_message_func(DBusConnection *connection, void *user_data) { if (dbus_message_is_method_call(message, - "org.laptop.ActivityFactory", - "create")) + "org.freedesktop.DBus.Introspectable", + "Introspect")) + return handle_introspect(connection, message); + else if (dbus_message_is_method_call(message, + "org.laptop.ActivityFactory", + "create")) return handle_create(connection, message); else return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; From 88e8bba22bea952900aac75ec76616e4f32f9416 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Tue, 25 Sep 2007 19:41:42 +0200 Subject: [PATCH 2/2] #948 Accept ascii passphrases for WEP networks. --- NEWS | 3 +++ shell/hardware/keydialog.py | 43 +++++++++++++++++++++++++++++++++---- shell/hardware/nminfo.py | 2 +- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 55157895..dcbfc8ee 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +* #948 Accept ascii passphrases for WEP networks. '$:1a2b3c4d' for hex keys, + 's:my passphrase' for 5 or 13 characters ascii passphrases, or just the plain + key for ascii passphrases of any other length. (tomeu) * #2477 Support dbus introspection in sugar-native-factory (bertf) * #2674 Add arrows to hint about the frame corner activation (marco) * #2665 Re-arrange device icons in a line at the bottom (marco) diff --git a/shell/hardware/keydialog.py b/shell/hardware/keydialog.py index 409c8506..6c660066 100644 --- a/shell/hardware/keydialog.py +++ b/shell/hardware/keydialog.py @@ -16,7 +16,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import md5 from gettext import gettext as _ + import gobject, gtk IW_AUTH_ALG_OPEN_SYSTEM = 0x00000001 @@ -55,6 +57,29 @@ def string_is_hex(key): is_hex = False return is_hex +def string_is_ascii(string): + try: + string.encode('ascii') + return True + except: + return False + +def string_to_hex(passphrase): + key = '' + for c in passphrase: + key += hex(ord(c))[2:] + return key + +def hash_passphrase(passphrase): + # passphrase must have a length of 64 + if len(passphrase) > 64: + passphrase = passphrase[:64] + elif len(passphrase) < 64: + while len(passphrase) < 64: + passphrase += passphrase[:64 - len(passphrase)] + passphrase = md5.new(passphrase).digest() + return string_to_hex(passphrase)[:26] + class KeyDialog(gtk.Dialog): def __init__(self, net, async_cb, async_err_cb): gtk.Dialog.__init__(self, flags=gtk.DIALOG_MODAL) @@ -73,6 +98,7 @@ class KeyDialog(gtk.Dialog): self._entry = gtk.Entry() #self._entry.props.visibility = False self._entry.connect('changed', self._update_response_sensitivity) + self._entry.connect('activate', self._entry_activate_cb) self.vbox.pack_start(self._entry) self.vbox.set_spacing(6) self.vbox.show_all() @@ -86,6 +112,9 @@ class KeyDialog(gtk.Dialog): self._entry.grab_focus() self.set_has_separator(True) + def _entry_activate_cb(self, entry): + self.response(gtk.RESPONSE_OK) + def create_security(self): raise NotImplementedError @@ -119,6 +148,13 @@ class WEPKeyDialog(KeyDialog): def create_security(self): key = self._entry.get_text() + if key.startswith('$:'): + key = key[2:] + elif key.startswith('s:') and ((len(key) - 2) in [5, 13]): + key = string_to_hex(key[2:]) + else: + key = hash_passphrase(key) + it = self.combo.get_active_iter() (auth_alg, ) = self.store.get(it, 1) @@ -132,10 +168,9 @@ class WEPKeyDialog(KeyDialog): return Security.new_from_args(we_cipher, (key, auth_alg)) def _update_response_sensitivity(self, ignored=None): - key = self._entry.get_text() - is_hex = string_is_hex(key) - valid_len = (len(key) == 10 or len(key) == 26) - self.set_response_sensitive(gtk.RESPONSE_OK, is_hex and valid_len) + # As the md5 passphrase can be of any length and has no indicator, we + # cannot check for the validity of the input. + self.set_response_sensitive(gtk.RESPONSE_OK, True) class WPAKeyDialog(KeyDialog): def __init__(self, net, async_cb, async_err_cb): diff --git a/shell/hardware/nminfo.py b/shell/hardware/nminfo.py index 09226cf7..c1a6326c 100644 --- a/shell/hardware/nminfo.py +++ b/shell/hardware/nminfo.py @@ -506,7 +506,7 @@ class NMInfo(object): self._key_dialog = None widget.destroy() - if response_id == gtk.RESPONSE_CANCEL: + if response_id in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_NONE]: # key dialog dialog was canceled; send the error back to NM async_err_cb(CanceledKeyRequestError()) elif response_id == gtk.RESPONSE_OK: