diff --git a/encryption/templates/active_wired b/encryption/templates/active_wired new file mode 100644 index 0000000..3234857 --- /dev/null +++ b/encryption/templates/active_wired @@ -0,0 +1 @@ +wired_8021x diff --git a/encryption/templates/wired_8021x b/encryption/templates/wired_8021x new file mode 100644 index 0000000..2c66529 --- /dev/null +++ b/encryption/templates/wired_8021x @@ -0,0 +1,16 @@ +name = 802.1x +author = Joe MacMahon +version = 1 +requre identity *Identity password *Password +protected password *Password +----- +eapol_version=1 +fast_reauth=0 +network={ + key_mgmt=IEEE8021X + eap=PEAP + phase1="peaplabel=1" + phase2="auth=MSCHAPV2" + identity="$_IDENTITY" + password="$_PASSWORD" +} diff --git a/gtk/netentry.py b/gtk/netentry.py index 4a27a83..62d4187 100644 --- a/gtk/netentry.py +++ b/gtk/netentry.py @@ -236,6 +236,12 @@ class AdvancedSettingsDialog(gtk.Dialog): for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain, self.txt_search_dom]: w.set_sensitive(not self.chkbox_global_dns.get_active()) + + def toggle_encryption(self, widget=None): + """ Toggle the encryption combobox based on the encryption checkbox. """ + active = self.chkbox_encryption.get_active() + self.vbox_encrypt_info.set_sensitive(active) + self.combo_encryption.set_sensitive(active) def destroy_called(self, *args): """ Clean up everything. """ @@ -279,11 +285,81 @@ class AdvancedSettingsDialog(gtk.Dialog): self.chkbox_use_dhcp_hostname.get_active()) self.set_net_prop("dhcphostname",noneToString(self.txt_dhcp_hostname.get_text())) + def change_encrypt_method(self, widget=None): + """ Load all the entries for a given encryption method. """ + for z in self.vbox_encrypt_info: + z.destroy() # Remove stuff in there already + ID = self.combo_encryption.get_active() + methods = self.encrypt_types + self.encryption_info = {} + + # If nothing is selected, select the first entry. + if ID == -1: + self.combo_encryption.set_active(0) + ID = 0 + + for type_ in ['required', 'optional']: + fields = methods[ID][type_] + for field in fields: + try: + field_text = language[field[1].lower().replace(' ','_')] + except KeyError: + field_text = field[1].replace(' ','_') + + if field in methods[ID]['protected']: + box = ProtectedLabelEntry(field_text) + else: + box = LabelEntry(field_text) + + self.vbox_encrypt_info.pack_start(box) + # Add the data to a dict, so that the information + # can be easily accessed by giving the name of the wanted + # data. + self.encryption_info[field[0]] = [box, type_] + + if self.wired: + box.entry.set_text(noneToBlankString( + wired.GetWiredProperty(self.networkID, field[0]))) + else: + box.entry.set_text(noneToBlankString( + wireless.GetWirelessProperty(self.networkID, field[0]))) + self.vbox_encrypt_info.show_all() + class WiredSettingsDialog(AdvancedSettingsDialog): def __init__(self, name): """ Build the wired settings dialog. """ AdvancedSettingsDialog.__init__(self, _('Wired Network')) + + # So we can test if we are wired or wireless (for change_encrypt_method()) + self.wired = True + + ## This section is largely copied from WirelessSettingsDialog, but with some changes + # Set up encryption stuff + self.networkID = networkID + self.combo_encryption = gtk.combo_box_new_text() + self.chkbox_encryption = gtk.CheckButton(_('Use Encryption')) + # Make the vbox to hold the encryption stuff. + self.vbox_encrypt_info = gtk.VBox(False, 0) + self.toggle_encryption() + self.chkbox_encryption.set_active(False) + self.combo_encryption.set_sensitive(False) + self.encrypt_types = misc.LoadEncryptionMethods(wired = True) + + # Build the encryption menu + for x, enc_type in enumerate(self.encrypt_types): + self.combo_encryption.append_text(enc_type['name']) + self.combo_encryption.set_active(0) + self.change_encrypt_method() + + self.cvbox.pack_start(self.chkbox_encryption, False, False) + self.cvbox.pack_start(self.combo_encryption, False, False) + self.cvbox.pack_start(self.vbox_encrypt_info, False, False) + + # Connect signals. + self.chkbox_encryption.connect("toggled", self.toggle_encryption) + self.combo_encryption.connect("changed", self.change_encrypt_method) + self.des = self.connect("destroy", self.destroy_called) self.script_button.connect("clicked", self.edit_scripts) self.prof_name = name @@ -350,6 +426,9 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): def __init__(self, networkID): """ Build the wireless settings dialog. """ AdvancedSettingsDialog.__init__(self, wireless.GetWirelessProperty(networkID, 'essid')) + # So we can test if we are wired or wireless (for change_encrypt_method()) + self.wired = False + # Set up encryption stuff self.networkID = networkID self.combo_encryption = gtk.combo_box_new_text() @@ -513,48 +592,6 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): def format_entry(self, networkid, label): """ Helper method for fetching/formatting wireless properties. """ return noneToBlankString(wireless.GetWirelessProperty(networkid, label)) - - def toggle_encryption(self, widget=None): - """ Toggle the encryption combobox based on the encryption checkbox. """ - active = self.chkbox_encryption.get_active() - self.vbox_encrypt_info.set_sensitive(active) - self.combo_encryption.set_sensitive(active) - - def change_encrypt_method(self, widget=None): - """ Load all the entries for a given encryption method. """ - for z in self.vbox_encrypt_info: - z.destroy() # Remove stuff in there already - ID = self.combo_encryption.get_active() - methods = self.encrypt_types - self.encryption_info = {} - - # If nothing is selected, select the first entry. - if ID == -1: - self.combo_encryption.set_active(0) - ID = 0 - - for type_ in ['required', 'optional']: - fields = methods[ID][type_] - for field in fields: - try: - field_text = language[field[1].lower().replace(' ','_')] - except KeyError: - field_text = field[1].replace(' ','_') - - if field in methods[ID]['protected']: - box = ProtectedLabelEntry(field_text) - else: - box = LabelEntry(field_text) - - self.vbox_encrypt_info.pack_start(box) - # Add the data to a dict, so that the information - # can be easily accessed by giving the name of the wanted - # data. - self.encryption_info[field[0]] = [box, type_] - - box.entry.set_text(noneToBlankString( - wireless.GetWirelessProperty(self.networkID, field[0]))) - self.vbox_encrypt_info.show_all() class NetworkEntry(gtk.HBox): diff --git a/wicd/misc.py b/wicd/misc.py index c749eda..1c868f3 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -271,7 +271,10 @@ def ParseEncryption(network): """ enctemplate = open(wpath.encryption + network["enctype"]) template = enctemplate.readlines() - config_file = "ap_scan=1\n" + if network.get('essid'): + config_file = "ap_scan=1\n" + else: + config_file = "ap_scan=0\n" should_replace = False for index, line in enumerate(template): if not should_replace: @@ -303,8 +306,11 @@ def ParseEncryption(network): # Write the data to the files then chmod them so they can't be read # by normal users. - file_loc = os.path.join(wpath.networks, - network['bssid'].replace(":", "").lower()) + if network.get('bssid'): + file_name = network['bssid'].replace(":", "").lower() + else: + file_name = 'wired' + file_loc = os.path.join(wpath.networks, file_name) f = open(file_loc, "w") os.chmod(file_loc, 0600) os.chown(file_loc, 0, 0) @@ -313,7 +319,7 @@ def ParseEncryption(network): f.write(config_file) f.close() -def LoadEncryptionMethods(): +def LoadEncryptionMethods(wired = False): """ Load encryption methods from configuration files Loads all the encryption methods from the template files @@ -321,8 +327,12 @@ def LoadEncryptionMethods(): loaded, the template must be listed in the "active" file. """ + if wired: + active_fname = "active_wired" + else: + active_fname = "active" try: - enctypes = open(wpath.encryption + "active","r").readlines() + enctypes = open(wpath.encryption + active_fname,"r").readlines() except IOError, e: print "Fatal Error: template index file is missing." raise IOError(e) diff --git a/wicd/networking.py b/wicd/networking.py index 7140fcd..ea35758 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -1148,6 +1148,10 @@ class WiredConnectThread(ConnectThread): # Bring up interface. self.put_iface_up(liface) + # Manage encryption. + if self.network.get('encryption'): + liface.Authenticate(self.network) + # Set gateway, IP adresses, and DNS servers. self.set_broadcast_address(liface) self.set_ip_address(liface) diff --git a/wicd/wnettools.py b/wicd/wnettools.py index 0f7f0d4..8cec435 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -892,6 +892,13 @@ class BaseWiredInterface(BaseInterface): else: return False + def Authenticate(self, network): + misc.ParseEncryption(network) + cmd = ['wpa_supplicant', '-B', '-i', self.iface, '-c', + os.path.join(wpath.networks, 'wired'), + '-Dwired'] + if self.verbose: print cmd + misc.Run(cmd) class BaseWirelessInterface(BaseInterface): """ Control a wireless network interface. """